-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / transport_api.c
index 41ef306b731a23ba9b442ff9f49b2ca11302e5d6..9ff5cec88ff5a2bf97ed2bc883c7e22fdeb71e27 100644 (file)
@@ -29,6 +29,7 @@
  * - test test test
  */
 #include "platform.h"
+#include "gnunet_constants.h"
 #include "gnunet_bandwidth_lib.h"
 #include "gnunet_client_lib.h"
 #include "gnunet_constants.h"
@@ -404,6 +405,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
   const struct GNUNET_MessageHeader *imm;
   const struct SendOkMessage *okm;
   const struct QuotaSetMessage *qm;
+  const struct GNUNET_ATS_Information *ats;
   struct GNUNET_TRANSPORT_GetHelloHandle *hwl;
   struct GNUNET_TRANSPORT_GetHelloHandle *next_hwl;
   struct Neighbour *n;
@@ -471,6 +473,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
       GNUNET_break (0);
       break;
     }
+    ats = (const struct GNUNET_ATS_Information *) &cim[1];
 #if DEBUG_TRANSPORT_API
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
          "CONNECT", GNUNET_i2s (&cim->id));
@@ -483,7 +486,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
     }
     n = neighbour_add (h, &cim->id);
     if (h->nc_cb != NULL)
-      h->nc_cb (h->cls, &n->id, &cim->ats, ats_count);
+      h->nc_cb (h->cls, &n->id, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
     if (size != sizeof (struct DisconnectInfoMessage))
@@ -544,8 +547,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
     }
     im = (const struct InboundMessage *) msg;
     ats_count = ntohl (im->ats_count);
-    imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]);
-
+    ats = (const struct GNUNET_ATS_Information *) &im[1];
+    imm = (const struct GNUNET_MessageHeader *) &ats[ats_count];
     if (ntohs (imm->size) + sizeof (struct InboundMessage) +
         ats_count * sizeof (struct GNUNET_ATS_Information) != size)
     {
@@ -563,7 +566,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
       break;
     }
     if (h->rec != NULL)
-      h->rec (h->cls, &im->peer, imm, &im->ats, ats_count);
+      h->rec (h->cls, &im->peer, imm, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA:
 #if DEBUG_TRANSPORT_API
@@ -577,10 +580,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
     qm = (const struct QuotaSetMessage *) msg;
     n = neighbour_find (h, &qm->peer);
     if (n == NULL)
-    {
-      GNUNET_break (0);
       break;
-    }
     GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota);
     break;
   default:
@@ -861,6 +861,7 @@ send_start (void *cls, size_t size, void *buf)
 {
   struct GNUNET_TRANSPORT_Handle *h = cls;
   struct StartMessage s;
+  uint32_t options;
 
   if (buf == NULL)
   {
@@ -877,7 +878,12 @@ send_start (void *cls, size_t size, void *buf)
   GNUNET_assert (size >= sizeof (struct StartMessage));
   s.header.size = htons (sizeof (struct StartMessage));
   s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
-  s.do_check = htonl (h->check_self);
+  options = 0;
+  if (h->check_self)
+    options |= 1;
+  if (h->rec != NULL)
+    options |= 2;
+  s.options = htonl (options);
   s.self = h->self;
   memcpy (buf, &s, sizeof (struct StartMessage));
   GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
@@ -927,8 +933,6 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
   struct GNUNET_TRANSPORT_TransmitHandle *th;
 
   GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
-  /* Forget about all neighbours that we used to be connected to */
-  GNUNET_CONTAINER_multihashmap_iterate (h->neighbours, &neighbour_delete, h);
   if (NULL != h->cth)
   {
     GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
@@ -939,6 +943,8 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
     GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
     h->client = NULL;
   }
+  /* Forget about all neighbours that we used to be connected to */
+  GNUNET_CONTAINER_multihashmap_iterate (h->neighbours, &neighbour_delete, h);
   if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel (h->quota_task);
@@ -970,105 +976,6 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
 }
 
 
-/**
- * Closure for 'send_set_quota'.
- */
-struct SetQuotaContext
-{
-
-  /**
-   * Identity of the peer impacted by the quota change.
-   */
-  struct GNUNET_PeerIdentity target;
-
-  /**
-   * Quota to transmit.
-   */
-  struct GNUNET_BANDWIDTH_Value32NBO quota_in;
-};
-
-
-/**
- * Send SET_QUOTA message to the service.
- *
- * @param cls the 'struct SetQuotaContext'
- * @param size number of bytes available in buf
- * @param buf where to copy the message
- * @return number of bytes copied to buf
- */
-static size_t
-send_set_quota (void *cls, size_t size, void *buf)
-{
-  struct SetQuotaContext *sqc = cls;
-  struct QuotaSetMessage msg;
-
-  if (buf == NULL)
-  {
-    GNUNET_free (sqc);
-    return 0;
-  }
-#if DEBUG_TRANSPORT_API
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Transmitting `%s' request with respect to `%4s'.\n", "SET_QUOTA",
-       GNUNET_i2s (&sqc->target));
-#endif
-  GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
-  msg.header.size = htons (sizeof (struct QuotaSetMessage));
-  msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
-  msg.quota = sqc->quota_in;
-  msg.peer = sqc->target;
-  memcpy (buf, &msg, sizeof (msg));
-  GNUNET_free (sqc);
-  return sizeof (struct QuotaSetMessage);
-}
-
-
-/**
- * Set the share of incoming bandwidth for the given
- * peer to the specified amount.
- *
- * @param handle connection to transport service
- * @param target who's bandwidth quota is being changed
- * @param quota_in incoming bandwidth quota in bytes per ms
- * @param quota_out outgoing bandwidth quota in bytes per ms
- */
-void
-GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
-                            const struct GNUNET_PeerIdentity *target,
-                            struct GNUNET_BANDWIDTH_Value32NBO quota_in,
-                            struct GNUNET_BANDWIDTH_Value32NBO quota_out)
-{
-  struct Neighbour *n;
-  struct SetQuotaContext *sqc;
-
-  n = neighbour_find (handle, target);
-  if (NULL == n)
-  {
-    LOG (GNUNET_ERROR_TYPE_ERROR,
-         "Quota changed to %u for peer `%s', but I have no such neighbour!\n",
-         (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
-    return;
-  }
-  GNUNET_assert (NULL != handle->client);
-#if DEBUG_TRANSPORT_API
-  if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Quota changed from %u to %u for peer `%s'\n",
-         (unsigned int) n->out_tracker.available_bytes_per_s__,
-         (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
-  else
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Quota remains at %u for peer `%s'\n",
-         (unsigned int) n->out_tracker.available_bytes_per_s__,
-         GNUNET_i2s (target));
-#endif
-  GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, quota_out);
-  sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
-  sqc->target = *target;
-  sqc->quota_in = quota_in;
-  schedule_control_transmit (handle, sizeof (struct QuotaSetMessage),
-                             &send_set_quota, sqc);
-}
-
-
 /**
  * Send REQUEST_CONNECT message to the service.
  *