gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13856 - in gnunet/src: core include


From: gnunet
Subject: [GNUnet-SVN] r13856 - in gnunet/src: core include
Date: Wed, 1 Dec 2010 10:23:14 +0100

Author: grothoff
Date: 2010-12-01 10:23:14 +0100 (Wed, 01 Dec 2010)
New Revision: 13856

Modified:
   gnunet/src/core/core_api_iterate_peers.c
   gnunet/src/core/gnunet-service-core.c
   gnunet/src/include/gnunet_protocols.h
Log:
fixing iteration code to handle ATS structs

Modified: gnunet/src/core/core_api_iterate_peers.c
===================================================================
--- gnunet/src/core/core_api_iterate_peers.c    2010-12-01 09:14:31 UTC (rev 
13855)
+++ gnunet/src/core/core_api_iterate_peers.c    2010-12-01 09:23:14 UTC (rev 
13856)
@@ -67,12 +67,14 @@
 {
   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 */
+  msize = ntohs (msg->size);
   if ( (msg == NULL) ||
-      ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) &&
-      (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) )
+      ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) &&
+      (msize == sizeof (struct GNUNET_MessageHeader))) )
     {
       if (request_context->peer_cb != NULL)
        request_context->peer_cb (request_context->cb_cls,
@@ -84,7 +86,7 @@
 
   /* 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)
@@ -94,15 +96,28 @@
       GNUNET_free (request_context);
       return;
     }
-
+  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 */
-  connect_message = (const struct ConnectNotifyMessage *) msg;
   if (request_context->peer_cb != NULL)
     request_context->peer_cb (request_context->cb_cls,
                               &connect_message->peer,
-                              NULL);
-
-  GNUNET_CLIENT_receive(request_context->client, &receive_info, 
request_context, GNUNET_TIME_relative_get_forever());
+                              &connect_message->ats);
+  GNUNET_CLIENT_receive(request_context->client, 
+                       &receive_info, 
+                       request_context,
+                       GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 /**

Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c       2010-12-01 09:14:31 UTC (rev 
13855)
+++ gnunet/src/core/gnunet-service-core.c       2010-12-01 09:23:14 UTC (rev 
13856)
@@ -1452,7 +1452,7 @@
       n = n->next;
     }
   done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
-  done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
+  done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
   GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
   GNUNET_SERVER_transmit_context_run (tc,
                                       GNUNET_TIME_UNIT_FOREVER_REL);

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2010-12-01 09:14:31 UTC (rev 
13855)
+++ gnunet/src/include/gnunet_protocols.h       2010-12-01 09:23:14 UTC (rev 
13856)
@@ -383,6 +383,11 @@
 #define GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS 78
 
 /**
+ * Last reply from core to request for peer iteration from CORE service.
+ */
+#define GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END 79
+
+/**
  * Session key exchange between peers.
  */
 #define GNUNET_MESSAGE_TYPE_CORE_SET_KEY 80




reply via email to

[Prev in Thread] Current Thread [Next in Thread]