fix usage of mesh_api
[oweals/gnunet.git] / src / core / core_api_iterate_peers.c
index aeef67f888618242ebb0f47fedd820d59ce473e2..fb9c01fee3bb36506339f374cafcbb429f0ad953 100644 (file)
@@ -67,43 +67,57 @@ receive_info (void *cls,
 {
   struct GNUNET_CORE_RequestContext *request_context = cls;
   const struct ConnectNotifyMessage *connect_message;
-
+  uint32_t ats_count;
+  uint16_t msize;
 
   /* Handle last message or error case, disconnect and clean up */
   if ( (msg == NULL) ||
-      ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) &&
+      ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) &&
       (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) )
     {
       if (request_context->peer_cb != NULL)
        request_context->peer_cb (request_context->cb_cls,
-                               NULL, GNUNET_TIME_relative_get_zero(), 0);
+                                  NULL, NULL);
       GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
       GNUNET_free (request_context);
       return;
     }
 
+  msize = ntohs (msg->size);
   /* Handle incorrect message type or size, disconnect and clean up */
   if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
-       (ntohs (msg->size) != sizeof (struct ConnectNotifyMessage)) )
+       (msize < sizeof (struct ConnectNotifyMessage)) )
     {
       GNUNET_break (0);
       if (request_context->peer_cb != NULL)
         request_context->peer_cb (request_context->cb_cls,
-                               NULL, GNUNET_TIME_relative_get_zero(), 0);
+                                  NULL, NULL);
       GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
       GNUNET_free (request_context);
       return;
     }
-
-  /* Normal case */
   connect_message = (const struct ConnectNotifyMessage *) msg;
+  ats_count = ntohl (connect_message->ats_count);
+  if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
+       (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&connect_message->ats)[ats_count].type)) )
+    {
+      GNUNET_break (0);
+      if (request_context->peer_cb != NULL)
+        request_context->peer_cb (request_context->cb_cls,
+                                  NULL, NULL);
+      GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
+      GNUNET_free (request_context);
+      return;
+    }
+  /* Normal case */
   if (request_context->peer_cb != NULL)
     request_context->peer_cb (request_context->cb_cls,
-                           &connect_message->peer,
-                           GNUNET_TIME_relative_ntoh(connect_message->latency),
-                           ntohl (connect_message->distance));
-
-  GNUNET_CLIENT_receive(request_context->client, &receive_info, request_context, GNUNET_TIME_relative_get_forever());
+                              &connect_message->peer,
+                              &connect_message->ats);
+  GNUNET_CLIENT_receive(request_context->client, 
+                       &receive_info, 
+                       request_context,
+                       GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 /**
@@ -155,13 +169,13 @@ GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
   request_context->peer_cb = peer_cb;
   request_context->cb_cls = cb_cls;
 
-  /*GNUNET_assert (GNUNET_OK == GNUNET_CLIENT_transmit_and_get_response (client,
-                                                                      &request_message,
-                                                                      GNUNET_TIME_relative_get_forever(),
-                                                                      GNUNET_YES,
-                                                                      &receive_info,
-                                                                      request_context));*/
-  request_context->th = GNUNET_CLIENT_notify_transmit_ready(client, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_relative_get_forever(), GNUNET_YES, &transmit_request, NULL);
+  request_context->th = GNUNET_CLIENT_notify_transmit_ready(client,
+                                                            sizeof(struct GNUNET_MessageHeader),
+                                                            GNUNET_TIME_relative_get_forever(),
+                                                            GNUNET_YES,
+                                                            &transmit_request,
+                                                            NULL);
+
   GNUNET_CLIENT_receive(client, &receive_info, request_context, GNUNET_TIME_relative_get_forever());
   return GNUNET_OK;
 }