aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api_iterate_peers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-12-01 09:23:14 +0000
committerChristian Grothoff <christian@grothoff.org>2010-12-01 09:23:14 +0000
commit901d3f2df5795415ae833315b9f510597992da45 (patch)
tree5924147152abd82297583cc63f72a503cd1940fa /src/core/core_api_iterate_peers.c
parent36d33c337a0e1343eeafaf44428f8264d3da2cc8 (diff)
downloadgnunet-901d3f2df5795415ae833315b9f510597992da45.tar.gz
gnunet-901d3f2df5795415ae833315b9f510597992da45.zip
fixing iteration code to handle ATS structs
Diffstat (limited to 'src/core/core_api_iterate_peers.c')
-rw-r--r--src/core/core_api_iterate_peers.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index 657768363..d1c3828bb 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -67,12 +67,14 @@ receive_info (void *cls,
67{ 67{
68 struct GNUNET_CORE_RequestContext *request_context = cls; 68 struct GNUNET_CORE_RequestContext *request_context = cls;
69 const struct ConnectNotifyMessage *connect_message; 69 const struct ConnectNotifyMessage *connect_message;
70 70 uint32_t ats_count;
71 uint16_t msize;
71 72
72 /* Handle last message or error case, disconnect and clean up */ 73 /* Handle last message or error case, disconnect and clean up */
74 msize = ntohs (msg->size);
73 if ( (msg == NULL) || 75 if ( (msg == NULL) ||
74 ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) && 76 ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END) &&
75 (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader))) ) 77 (msize == sizeof (struct GNUNET_MessageHeader))) )
76 { 78 {
77 if (request_context->peer_cb != NULL) 79 if (request_context->peer_cb != NULL)
78 request_context->peer_cb (request_context->cb_cls, 80 request_context->peer_cb (request_context->cb_cls,
@@ -84,7 +86,7 @@ receive_info (void *cls,
84 86
85 /* Handle incorrect message type or size, disconnect and clean up */ 87 /* Handle incorrect message type or size, disconnect and clean up */
86 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) || 88 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT) ||
87 (ntohs (msg->size) != sizeof (struct ConnectNotifyMessage)) ) 89 (msize < sizeof (struct ConnectNotifyMessage)) )
88 { 90 {
89 GNUNET_break (0); 91 GNUNET_break (0);
90 if (request_context->peer_cb != NULL) 92 if (request_context->peer_cb != NULL)
@@ -94,15 +96,28 @@ receive_info (void *cls,
94 GNUNET_free (request_context); 96 GNUNET_free (request_context);
95 return; 97 return;
96 } 98 }
97
98 /* Normal case */
99 connect_message = (const struct ConnectNotifyMessage *) msg; 99 connect_message = (const struct ConnectNotifyMessage *) msg;
100 ats_count = ntohl (connect_message->ats_count);
101 if ( (msize != sizeof (struct ConnectNotifyMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)) ||
102 (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR != ntohl ((&connect_message->ats)[ats_count].type)) )
103 {
104 GNUNET_break (0);
105 if (request_context->peer_cb != NULL)
106 request_context->peer_cb (request_context->cb_cls,
107 NULL, NULL);
108 GNUNET_CLIENT_disconnect (request_context->client, GNUNET_NO);
109 GNUNET_free (request_context);
110 return;
111 }
112 /* Normal case */
100 if (request_context->peer_cb != NULL) 113 if (request_context->peer_cb != NULL)
101 request_context->peer_cb (request_context->cb_cls, 114 request_context->peer_cb (request_context->cb_cls,
102 &connect_message->peer, 115 &connect_message->peer,
103 NULL); 116 &connect_message->ats);
104 117 GNUNET_CLIENT_receive(request_context->client,
105 GNUNET_CLIENT_receive(request_context->client, &receive_info, request_context, GNUNET_TIME_relative_get_forever()); 118 &receive_info,
119 request_context,
120 GNUNET_TIME_UNIT_FOREVER_REL);
106} 121}
107 122
108/** 123/**