-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / transport_api.c
index ab29930477edf5018c405128e9be78d0a6c49f36..9ff5cec88ff5a2bf97ed2bc883c7e22fdeb71e27 100644 (file)
@@ -405,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;
@@ -472,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));
@@ -484,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))
@@ -545,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)
     {
@@ -564,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
@@ -578,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:
@@ -862,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)
   {
@@ -878,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,
@@ -928,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);
@@ -940,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);