aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-04 14:00:32 +0000
commit83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch)
treed0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/core
parent28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff)
downloadgnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz
gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip
curly wars / auto-indentation
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core_api.c29
-rw-r--r--src/core/core_api_iterate_peers.c6
-rw-r--r--src/core/gnunet-core-list-connections.c2
-rw-r--r--src/core/gnunet-service-core.c8
-rw-r--r--src/core/gnunet-service-core.h2
-rw-r--r--src/core/gnunet-service-core_clients.c281
-rw-r--r--src/core/gnunet-service-core_clients.h39
-rw-r--r--src/core/gnunet-service-core_kx.c378
-rw-r--r--src/core/gnunet-service-core_kx.h25
-rw-r--r--src/core/gnunet-service-core_neighbours.c58
-rw-r--r--src/core/gnunet-service-core_neighbours.h6
-rw-r--r--src/core/gnunet-service-core_sessions.c242
-rw-r--r--src/core/gnunet-service-core_sessions.h25
-rw-r--r--src/core/gnunet-service-core_typemap.c60
-rw-r--r--src/core/gnunet-service-core_typemap.h20
-rw-r--r--src/core/test_core_api.c23
-rw-r--r--src/core/test_core_api_reliability.c19
-rw-r--r--src/core/test_core_api_send_to_self.c4
-rw-r--r--src/core/test_core_api_start_only.c15
-rw-r--r--src/core/test_core_quota_compliance.c76
20 files changed, 618 insertions, 700 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 57c2932a2..f3f4cea54 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -781,7 +781,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
781 const struct GNUNET_MessageHeader *em; 781 const struct GNUNET_MessageHeader *em;
782 const struct SendMessageReady *smr; 782 const struct SendMessageReady *smr;
783 const struct GNUNET_CORE_MessageHandler *mh; 783 const struct GNUNET_CORE_MessageHandler *mh;
784 const struct GNUNET_ATS_Information* ats; 784 const struct GNUNET_ATS_Information *ats;
785 GNUNET_CORE_StartupCallback init; 785 GNUNET_CORE_StartupCallback init;
786 struct PeerRecord *pr; 786 struct PeerRecord *pr;
787 struct GNUNET_CORE_TransmitHandle *th; 787 struct GNUNET_CORE_TransmitHandle *th;
@@ -864,8 +864,8 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
864 cnm = (const struct ConnectNotifyMessage *) msg; 864 cnm = (const struct ConnectNotifyMessage *) msg;
865 ats_count = ntohl (cnm->ats_count); 865 ats_count = ntohl (cnm->ats_count);
866 if (msize != 866 if (msize !=
867 sizeof (struct ConnectNotifyMessage) + 867 sizeof (struct ConnectNotifyMessage) +
868 ats_count * sizeof (struct GNUNET_ATS_Information)) 868 ats_count * sizeof (struct GNUNET_ATS_Information))
869 { 869 {
870 GNUNET_break (0); 870 GNUNET_break (0);
871 reconnect_later (h); 871 reconnect_later (h);
@@ -896,11 +896,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
896 GNUNET_CONTAINER_multihashmap_put (h->peers, 896 GNUNET_CONTAINER_multihashmap_put (h->peers,
897 &cnm->peer.hashPubKey, pr, 897 &cnm->peer.hashPubKey, pr,
898 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 898 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
899 ats = (const struct GNUNET_ATS_Information*) &cnm[1]; 899 ats = (const struct GNUNET_ATS_Information *) &cnm[1];
900 if (NULL != h->connects) 900 if (NULL != h->connects)
901 h->connects (h->cls, &cnm->peer, 901 h->connects (h->cls, &cnm->peer, ats, ats_count);
902 ats,
903 ats_count);
904 break; 902 break;
905 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT: 903 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
906 if (msize != sizeof (struct DisconnectNotifyMessage)) 904 if (msize != sizeof (struct DisconnectNotifyMessage))
@@ -949,8 +947,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
949 sizeof (struct NotifyTrafficMessage) + 947 sizeof (struct NotifyTrafficMessage) +
950 ats_count * sizeof (struct GNUNET_ATS_Information) + 948 ats_count * sizeof (struct GNUNET_ATS_Information) +
951 sizeof (struct GNUNET_MessageHeader)) || 949 sizeof (struct GNUNET_MessageHeader)) ||
952 (GNUNET_ATS_ARRAY_TERMINATOR != 950 (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
953 ntohl ((&ntm->ats)[ats_count].type)))
954 { 951 {
955 GNUNET_break (0); 952 GNUNET_break (0);
956 reconnect_later (h); 953 reconnect_later (h);
@@ -986,23 +983,22 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
986 continue; 983 continue;
987 if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0)) 984 if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
988 { 985 {
989 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 986 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
990 "Unexpected message size for message of type %u\n", 987 "Unexpected message size for message of type %u\n",
991 mh->type); 988 mh->type);
992 GNUNET_break_op (0); 989 GNUNET_break_op (0);
993 continue; 990 continue;
994 } 991 }
995 if (GNUNET_OK != 992 if (GNUNET_OK !=
996 h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats, 993 h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats,
997 ats_count)) 994 ats_count))
998 { 995 {
999 /* error in processing, do not process other messages! */ 996 /* error in processing, do not process other messages! */
1000 break; 997 break;
1001 } 998 }
1002 } 999 }
1003 if (NULL != h->inbound_notify) 1000 if (NULL != h->inbound_notify)
1004 h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, 1001 h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
1005 ats_count);
1006 break; 1002 break;
1007 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND: 1003 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
1008 if (msize < sizeof (struct NotifyTrafficMessage)) 1004 if (msize < sizeof (struct NotifyTrafficMessage))
@@ -1023,8 +1019,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1023 sizeof (struct NotifyTrafficMessage) + 1019 sizeof (struct NotifyTrafficMessage) +
1024 ats_count * sizeof (struct GNUNET_ATS_Information) + 1020 ats_count * sizeof (struct GNUNET_ATS_Information) +
1025 sizeof (struct GNUNET_MessageHeader)) || 1021 sizeof (struct GNUNET_MessageHeader)) ||
1026 (GNUNET_ATS_ARRAY_TERMINATOR != 1022 (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
1027 ntohl ((&ntm->ats)[ats_count].type)))
1028 { 1023 {
1029 GNUNET_break (0); 1024 GNUNET_break (0);
1030 reconnect_later (h); 1025 reconnect_later (h);
diff --git a/src/core/core_api_iterate_peers.c b/src/core/core_api_iterate_peers.c
index 7bf40a678..7b28842fd 100644
--- a/src/core/core_api_iterate_peers.c
+++ b/src/core/core_api_iterate_peers.c
@@ -101,7 +101,7 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
101 ats_count = ntohl (connect_message->ats_count); 101 ats_count = ntohl (connect_message->ats_count);
102 if (msize != 102 if (msize !=
103 sizeof (struct ConnectNotifyMessage) + 103 sizeof (struct ConnectNotifyMessage) +
104 ats_count * sizeof (struct GNUNET_ATS_Information)) 104 ats_count * sizeof (struct GNUNET_ATS_Information))
105 { 105 {
106 GNUNET_break (0); 106 GNUNET_break (0);
107 if (request_context->peer_cb != NULL) 107 if (request_context->peer_cb != NULL)
@@ -113,8 +113,8 @@ receive_info (void *cls, const struct GNUNET_MessageHeader *msg)
113 /* Normal case */ 113 /* Normal case */
114 if (request_context->peer_cb != NULL) 114 if (request_context->peer_cb != NULL)
115 request_context->peer_cb (request_context->cb_cls, &connect_message->peer, 115 request_context->peer_cb (request_context->cb_cls, &connect_message->peer,
116 (const struct GNUNET_ATS_Information *) &connect_message[1], 116 (const struct GNUNET_ATS_Information *)
117 ats_count); 117 &connect_message[1], ats_count);
118 GNUNET_CLIENT_receive (request_context->client, &receive_info, 118 GNUNET_CLIENT_receive (request_context->client, &receive_info,
119 request_context, GNUNET_TIME_UNIT_FOREVER_REL); 119 request_context, GNUNET_TIME_UNIT_FOREVER_REL);
120} 120}
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c
index 9665110a3..79490bcc5 100644
--- a/src/core/gnunet-core-list-connections.c
+++ b/src/core/gnunet-core-list-connections.c
@@ -124,7 +124,7 @@ process_resolved_address (void *cls, const char *address)
124static void 124static void
125connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, 125connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
126 const struct GNUNET_ATS_Information *atsi, 126 const struct GNUNET_ATS_Information *atsi,
127 unsigned int atsi_count) 127 unsigned int atsi_count)
128{ 128{
129 struct PrintContext *pc; 129 struct PrintContext *pc;
130 130
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 5bec671ec..2eb71c257 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -57,8 +57,7 @@ static void
57cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 57cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
58{ 58{
59#if DEBUG_CORE 59#if DEBUG_CORE
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
61 "Core service shutting down.\n");
62#endif 61#endif
63 GSC_CLIENTS_done (); 62 GSC_CLIENTS_done ();
64 GSC_NEIGHBOURS_done (); 63 GSC_NEIGHBOURS_done ();
@@ -85,13 +84,12 @@ static void
85run (void *cls, struct GNUNET_SERVER_Handle *server, 84run (void *cls, struct GNUNET_SERVER_Handle *server,
86 const struct GNUNET_CONFIGURATION_Handle *c) 85 const struct GNUNET_CONFIGURATION_Handle *c)
87{ 86{
88 GSC_cfg = c; 87 GSC_cfg = c;
89 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); 88 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
90 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, 89 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task,
91 NULL); 90 NULL);
92 GSC_TYPEMAP_init (); 91 GSC_TYPEMAP_init ();
93 if ( (GNUNET_OK != GSC_KX_init ()) || 92 if ((GNUNET_OK != GSC_KX_init ()) || (GNUNET_OK != GSC_NEIGHBOURS_init ()))
94 (GNUNET_OK != GSC_NEIGHBOURS_init ()) )
95 { 93 {
96 GNUNET_SCHEDULER_shutdown (); 94 GNUNET_SCHEDULER_shutdown ();
97 return; 95 return;
diff --git a/src/core/gnunet-service-core.h b/src/core/gnunet-service-core.h
index d4e43a457..e48ad8bad 100644
--- a/src/core/gnunet-service-core.h
+++ b/src/core/gnunet-service-core.h
@@ -37,7 +37,7 @@ struct GSC_Client;
37 37
38/** 38/**
39 * Record kept for each request for transmission issued by a 39 * Record kept for each request for transmission issued by a
40 * client that is still pending. (This struct is used by 40 * client that is still pending. (This struct is used by
41 * both the 'CLIENTS' and 'SESSIONS' subsystems.) 41 * both the 'CLIENTS' and 'SESSIONS' subsystems.)
42 */ 42 */
43struct GSC_ClientActiveRequest 43struct GSC_ClientActiveRequest
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c
index 22201514a..3201b71f0 100644
--- a/src/core/gnunet-service-core_clients.c
+++ b/src/core/gnunet-service-core_clients.c
@@ -146,9 +146,8 @@ find_client (struct GNUNET_SERVER_Client *client)
146 * client's queue is getting too large? 146 * client's queue is getting too large?
147 */ 147 */
148static void 148static void
149send_to_client (struct GSC_Client *client, 149send_to_client (struct GSC_Client *client,
150 const struct GNUNET_MessageHeader *msg, 150 const struct GNUNET_MessageHeader *msg, int can_drop)
151 int can_drop)
152{ 151{
153#if DEBUG_CORE 152#if DEBUG_CORE
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -171,8 +170,8 @@ send_to_client (struct GSC_Client *client,
171 */ 170 */
172void 171void
173GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, 172GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
174 const struct GNUNET_MessageHeader *msg, 173 const struct GNUNET_MessageHeader *msg,
175 int can_drop) 174 int can_drop)
176{ 175{
177 struct GSC_Client *c; 176 struct GSC_Client *c;
178 177
@@ -194,14 +193,13 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
194 * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not. 193 * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not.
195 */ 194 */
196static int 195static int
197type_match (uint16_t type, 196type_match (uint16_t type, struct GSC_Client *c)
198 struct GSC_Client *c)
199{ 197{
200 unsigned int i; 198 unsigned int i;
201 199
202 if (c->tcnt == 0) 200 if (c->tcnt == 0)
203 return GNUNET_YES; /* peer without handlers matches ALL */ 201 return GNUNET_YES; /* peer without handlers matches ALL */
204 for (i=0;i<c->tcnt;i++) 202 for (i = 0; i < c->tcnt; i++)
205 if (type == c->types[i]) 203 if (type == c->types[i])
206 return GNUNET_YES; 204 return GNUNET_YES;
207 return GNUNET_NO; 205 return GNUNET_NO;
@@ -219,30 +217,27 @@ type_match (uint16_t type,
219 */ 217 */
220static void 218static void
221send_to_all_clients (const struct GNUNET_PeerIdentity *sender, 219send_to_all_clients (const struct GNUNET_PeerIdentity *sender,
222 const struct GNUNET_MessageHeader *msg, 220 const struct GNUNET_MessageHeader *msg, int can_drop,
223 int can_drop, 221 int options, uint16_t type)
224 int options,
225 uint16_t type)
226{ 222{
227 struct GSC_Client *c; 223 struct GSC_Client *c;
228 224
229 for (c = client_head; c != NULL; c = c->next) 225 for (c = client_head; c != NULL; c = c->next)
230 { 226 {
231 if ( (0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) && 227 if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
232 (GNUNET_YES == type_match (type, c)) ) 228 (GNUNET_YES == type_match (type, c)))
233 continue; /* not the full message, but we'd like the full one! */ 229 continue; /* not the full message, but we'd like the full one! */
234 if ( (0 == (c->options & options)) && 230 if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c)))
235 (GNUNET_YES != type_match (type, c)) ) 231 continue; /* neither options nor type match permit the message */
236 continue; /* neither options nor type match permit the message */
237#if DEBUG_CORE 232#if DEBUG_CORE
238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "Sending message to client interested in messages of type %u.\n", 234 "Sending message to client interested in messages of type %u.\n",
240 (unsigned int) type); 235 (unsigned int) type);
241#endif 236#endif
242#if DEBUG_CONNECTS 237#if DEBUG_CONNECTS
243 GNUNET_assert (GNUNET_YES == 238 GNUNET_assert (GNUNET_YES ==
244 GNUNET_CONTAINER_multihashmap_contains (c->connectmap, 239 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
245 &sender->hashPubKey)); 240 &sender->hashPubKey));
246#endif 241#endif
247 send_to_client (c, msg, can_drop); 242 send_to_client (c, msg, can_drop);
248 } 243 }
@@ -295,22 +290,20 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
295#if DEBUG_CONNECTS 290#if DEBUG_CONNECTS
296 c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); 291 c->connectmap = GNUNET_CONTAINER_multihashmap_create (16);
297 GNUNET_assert (GNUNET_YES == 292 GNUNET_assert (GNUNET_YES ==
298 GNUNET_CONTAINER_multihashmap_put (c->connectmap, 293 GNUNET_CONTAINER_multihashmap_put (c->connectmap,
299 &GSC_my_identity.hashPubKey, 294 &GSC_my_identity.hashPubKey,
300 NULL, 295 NULL,
301 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 296 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
302#endif 297#endif
303 298
304 wtypes = (uint16_t *) & c[1]; 299 wtypes = (uint16_t *) & c[1];
305 for (i = 0; i < c->tcnt; i++) 300 for (i = 0; i < c->tcnt; i++)
306 wtypes[i] = ntohs (types[i]); 301 wtypes[i] = ntohs (types[i]);
307 GSC_TYPEMAP_add (wtypes, c->tcnt); 302 GSC_TYPEMAP_add (wtypes, c->tcnt);
308 GNUNET_CONTAINER_DLL_insert (client_head, 303 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
309 client_tail,
310 c);
311#if DEBUG_CORE 304#if DEBUG_CORE
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Client connecting to core service is interested in %u message types\n", 306 "Client connecting to core service is interested in %u message types\n",
314 (unsigned int) c->tcnt); 307 (unsigned int) c->tcnt);
315#endif 308#endif
316 /* send init reply message */ 309 /* send init reply message */
@@ -352,8 +345,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
352 c->requests = GNUNET_CONTAINER_multihashmap_create (16); 345 c->requests = GNUNET_CONTAINER_multihashmap_create (16);
353#if DEBUG_CORE 346#if DEBUG_CORE
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
355 "Client asked for transmission to `%s'\n", 348 "Client asked for transmission to `%s'\n",
356 GNUNET_i2s (&req->peer)); 349 GNUNET_i2s (&req->peer));
357#endif 350#endif
358 car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey); 351 car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey);
359 if (car == NULL) 352 if (car == NULL)
@@ -378,7 +371,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
378 car->smr_id = req->smr_id; 371 car->smr_id = req->smr_id;
379 car->was_solicited = GNUNET_NO; 372 car->was_solicited = GNUNET_NO;
380 if (0 == 373 if (0 ==
381 memcmp (&req->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 374 memcmp (&req->peer, &GSC_my_identity,
375 sizeof (struct GNUNET_PeerIdentity)))
382 GSC_CLIENTS_solicit_request (car); 376 GSC_CLIENTS_solicit_request (car);
383 else 377 else
384 GSC_SESSIONS_queue_request (car); 378 GSC_SESSIONS_queue_request (car);
@@ -394,7 +388,7 @@ struct TokenizerContext
394 388
395 /** 389 /**
396 * Active request handle for the message. 390 * Active request handle for the message.
397 */ 391 */
398 struct GSC_ClientActiveRequest *car; 392 struct GSC_ClientActiveRequest *car;
399 393
400 /** 394 /**
@@ -440,42 +434,39 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
440 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 434 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
441 return; 435 return;
442 } 436 }
443 tc.car = GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey); 437 tc.car =
438 GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey);
444 if (NULL == tc.car) 439 if (NULL == tc.car)
445 { 440 {
446 /* Must have been that we first approved the request, then got disconnected 441 /* Must have been that we first approved the request, then got disconnected
447 (which triggered removal of the 'car') and now the client gives us a message 442 * (which triggered removal of the 'car') and now the client gives us a message
448 just *before* the client learns about the disconnect. Theoretically, we 443 * just *before* the client learns about the disconnect. Theoretically, we
449 might also now be *again* connected. So this can happen (but should be 444 * might also now be *again* connected. So this can happen (but should be
450 rare). If it does happen, the message is discarded. */ 445 * rare). If it does happen, the message is discarded. */
451 GNUNET_STATISTICS_update (GSC_stats, 446 GNUNET_STATISTICS_update (GSC_stats,
452 gettext_noop ("# messages discarded (session disconnected)"), 447 gettext_noop
453 1, 448 ("# messages discarded (session disconnected)"),
454 GNUNET_NO); 449 1, GNUNET_NO);
455 GNUNET_SERVER_receive_done (client, GNUNET_OK); 450 GNUNET_SERVER_receive_done (client, GNUNET_OK);
456 return; 451 return;
457 } 452 }
458 GNUNET_assert (GNUNET_YES == 453 GNUNET_assert (GNUNET_YES ==
459 GNUNET_CONTAINER_multihashmap_remove (c->requests, 454 GNUNET_CONTAINER_multihashmap_remove (c->requests,
460 &sm->peer.hashPubKey, 455 &sm->peer.hashPubKey,
461 tc.car)); 456 tc.car));
462 tc.cork = ntohl (sm->cork); 457 tc.cork = ntohl (sm->cork);
463#if DEBUG_CORE 458#if DEBUG_CORE
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
465 "Client asked for transmission of %u bytes to `%s' %s\n", 460 "Client asked for transmission of %u bytes to `%s' %s\n", msize,
466 msize, 461 GNUNET_i2s (&sm->peer), tc.cork ? "now" : "");
467 GNUNET_i2s (&sm->peer),
468 tc.cork ? "now" : "");
469#endif 462#endif
470 GNUNET_SERVER_mst_receive (client_mst, 463 GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize,
471 &tc, 464 GNUNET_YES, GNUNET_NO);
472 (const char*) &sm[1], msize,
473 GNUNET_YES,
474 GNUNET_NO);
475 if (0 != 465 if (0 !=
476 memcmp (&tc.car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 466 memcmp (&tc.car->target, &GSC_my_identity,
467 sizeof (struct GNUNET_PeerIdentity)))
477 GSC_SESSIONS_dequeue_request (tc.car); 468 GSC_SESSIONS_dequeue_request (tc.car);
478 GNUNET_free (tc.car); 469 GNUNET_free (tc.car);
479 GNUNET_SERVER_receive_done (client, GNUNET_OK); 470 GNUNET_SERVER_receive_done (client, GNUNET_OK);
480} 471}
481 472
@@ -492,37 +483,35 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
492 */ 483 */
493static void 484static void
494client_tokenizer_callback (void *cls, void *client, 485client_tokenizer_callback (void *cls, void *client,
495 const struct GNUNET_MessageHeader *message) 486 const struct GNUNET_MessageHeader *message)
496{ 487{
497 struct TokenizerContext *tc = client; 488 struct TokenizerContext *tc = client;
498 struct GSC_ClientActiveRequest *car = tc->car; 489 struct GSC_ClientActiveRequest *car = tc->car;
499 490
500 if (0 == 491 if (0 ==
501 memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 492 memcmp (&car->target, &GSC_my_identity,
493 sizeof (struct GNUNET_PeerIdentity)))
502 { 494 {
503#if DEBUG_CORE 495#if DEBUG_CORE
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "Delivering message of type %u to myself\n", 497 "Delivering message of type %u to myself\n",
506 ntohs (message->type)); 498 ntohs (message->type));
507#endif 499#endif
508 GSC_CLIENTS_deliver_message (&GSC_my_identity, 500 GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
509 NULL, 0, 501 ntohs (message->size),
510 message, 502 GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
511 ntohs (message->size), 503 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
512 GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 504 GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
513 GSC_CLIENTS_deliver_message (&GSC_my_identity, 505 sizeof (struct GNUNET_MessageHeader),
514 NULL, 0, 506 GNUNET_CORE_OPTION_SEND_HDR_INBOUND |
515 message, 507 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
516 sizeof (struct GNUNET_MessageHeader),
517 GNUNET_CORE_OPTION_SEND_HDR_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
518 } 508 }
519 else 509 else
520 { 510 {
521#if DEBUG_CORE 511#if DEBUG_CORE
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Delivering message of type %u to %s\n", 513 "Delivering message of type %u to %s\n", ntohs (message->type),
524 ntohs (message->type), 514 GNUNET_i2s (&car->target));
525 GNUNET_i2s (&car->target));
526#endif 515#endif
527 GSC_SESSIONS_transmit (car, message, tc->cork); 516 GSC_SESSIONS_transmit (car, message, tc->cork);
528 } 517 }
@@ -544,9 +533,10 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
544 struct GSC_ClientActiveRequest *car = value; 533 struct GSC_ClientActiveRequest *car = value;
545 534
546 GNUNET_assert (GNUNET_YES == 535 GNUNET_assert (GNUNET_YES ==
547 GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, 536 GNUNET_CONTAINER_multihashmap_remove (car->
548 &car->target.hashPubKey, 537 client_handle->requests,
549 car)); 538 &car->target.hashPubKey,
539 car));
550 GSC_SESSIONS_dequeue_request (car); 540 GSC_SESSIONS_dequeue_request (car);
551 GNUNET_free (car); 541 GNUNET_free (car);
552 return GNUNET_YES; 542 return GNUNET_YES;
@@ -560,8 +550,7 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
560 * @param client identification of the client 550 * @param client identification of the client
561 */ 551 */
562static void 552static void
563handle_client_disconnect (void *cls, 553handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
564 struct GNUNET_SERVER_Client *client)
565{ 554{
566 struct GSC_Client *c; 555 struct GSC_Client *c;
567 556
@@ -573,10 +562,8 @@ handle_client_disconnect (void *cls,
573#endif 562#endif
574 c = find_client (client); 563 c = find_client (client);
575 if (c == NULL) 564 if (c == NULL)
576 return; /* client never sent INIT */ 565 return; /* client never sent INIT */
577 GNUNET_CONTAINER_DLL_remove (client_head, 566 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
578 client_tail,
579 c);
580 if (c->requests != NULL) 567 if (c->requests != NULL)
581 { 568 {
582 GNUNET_CONTAINER_multihashmap_iterate (c->requests, 569 GNUNET_CONTAINER_multihashmap_iterate (c->requests,
@@ -613,8 +600,9 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
613 smr.peer = car->target; 600 smr.peer = car->target;
614#if DEBUG_CONNECTS 601#if DEBUG_CONNECTS
615 GNUNET_assert (GNUNET_YES == 602 GNUNET_assert (GNUNET_YES ==
616 GNUNET_CONTAINER_multihashmap_contains (c->connectmap, 603 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
617 &car->target.hashPubKey)); 604 &car->
605 target.hashPubKey));
618#endif 606#endif
619 send_to_client (c, &smr.header, GNUNET_NO); 607 send_to_client (c, &smr.header, GNUNET_NO);
620} 608}
@@ -632,9 +620,10 @@ void
632GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) 620GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
633{ 621{
634 GNUNET_assert (GNUNET_YES == 622 GNUNET_assert (GNUNET_YES ==
635 GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, 623 GNUNET_CONTAINER_multihashmap_remove (car->
636 &car->target.hashPubKey, 624 client_handle->requests,
637 car)); 625 &car->target.hashPubKey,
626 car));
638 GNUNET_free (car); 627 GNUNET_free (car);
639} 628}
640 629
@@ -654,11 +643,12 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
654 */ 643 */
655void 644void
656GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, 645GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
657 const struct GNUNET_PeerIdentity *neighbour, 646 const struct GNUNET_PeerIdentity
658 const struct GNUNET_ATS_Information *atsi, 647 *neighbour,
659 unsigned int atsi_count, 648 const struct GNUNET_ATS_Information
660 const struct GSC_TypeMap *tmap_old, 649 *atsi, unsigned int atsi_count,
661 const struct GSC_TypeMap *tmap_new) 650 const struct GSC_TypeMap *tmap_old,
651 const struct GSC_TypeMap *tmap_new)
662{ 652{
663 struct ConnectNotifyMessage *cnm; 653 struct ConnectNotifyMessage *cnm;
664 size_t size; 654 size_t size;
@@ -673,43 +663,41 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
673 if (old_match == new_match) 663 if (old_match == new_match)
674 { 664 {
675 GNUNET_assert (old_match == 665 GNUNET_assert (old_match ==
676 GNUNET_CONTAINER_multihashmap_contains (client->connectmap, 666 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
677 &neighbour->hashPubKey)); 667 &neighbour->hashPubKey));
678 return; /* no change */ 668 return; /* no change */
679 } 669 }
680 if (old_match == GNUNET_NO) 670 if (old_match == GNUNET_NO)
681 { 671 {
682 /* send connect */ 672 /* send connect */
683#if DEBUG_CONNECTS 673#if DEBUG_CONNECTS
684 GNUNET_assert (GNUNET_NO == 674 GNUNET_assert (GNUNET_NO ==
685 GNUNET_CONTAINER_multihashmap_contains (client->connectmap, 675 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
686 &neighbour->hashPubKey)); 676 &neighbour->hashPubKey));
687 GNUNET_assert (GNUNET_YES == 677 GNUNET_assert (GNUNET_YES ==
688 GNUNET_CONTAINER_multihashmap_put (client->connectmap, 678 GNUNET_CONTAINER_multihashmap_put (client->connectmap,
689 &neighbour->hashPubKey, 679 &neighbour->hashPubKey,
690 NULL, 680 NULL,
691 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 681 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
692#endif 682#endif
693 size = 683 size =
694 sizeof (struct ConnectNotifyMessage) + 684 sizeof (struct ConnectNotifyMessage) +
695 (atsi_count) * sizeof (struct GNUNET_ATS_Information); 685 (atsi_count) * sizeof (struct GNUNET_ATS_Information);
696 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 686 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
697 { 687 {
698 GNUNET_break (0); 688 GNUNET_break (0);
699 /* recovery strategy: throw away performance data */ 689 /* recovery strategy: throw away performance data */
700 atsi_count = 0; 690 atsi_count = 0;
701 size = sizeof (struct ConnectNotifyMessage); 691 size = sizeof (struct ConnectNotifyMessage);
702 } 692 }
703 cnm = (struct ConnectNotifyMessage *) buf; 693 cnm = (struct ConnectNotifyMessage *) buf;
704 cnm->header.size = htons (size); 694 cnm->header.size = htons (size);
705 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 695 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
706 cnm->ats_count = htonl (atsi_count); 696 cnm->ats_count = htonl (atsi_count);
707 a = (struct GNUNET_ATS_Information* ) &cnm[1]; 697 a = (struct GNUNET_ATS_Information *) &cnm[1];
708 memcpy (a, atsi, 698 memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
709 sizeof (struct GNUNET_ATS_Information) * atsi_count);
710#if DEBUG_CORE 699#if DEBUG_CORE
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
712 "Sending `%s' message to client.\n",
713 "NOTIFY_CONNECT"); 701 "NOTIFY_CONNECT");
714#endif 702#endif
715 cnm->peer = *neighbour; 703 cnm->peer = *neighbour;
@@ -720,12 +708,12 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
720 /* send disconnect */ 708 /* send disconnect */
721#if DEBUG_CONNECTS 709#if DEBUG_CONNECTS
722 GNUNET_assert (GNUNET_YES == 710 GNUNET_assert (GNUNET_YES ==
723 GNUNET_CONTAINER_multihashmap_contains (client->connectmap, 711 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
724 &neighbour->hashPubKey)); 712 &neighbour->hashPubKey));
725 GNUNET_assert (GNUNET_YES == 713 GNUNET_assert (GNUNET_YES ==
726 GNUNET_CONTAINER_multihashmap_remove (client->connectmap, 714 GNUNET_CONTAINER_multihashmap_remove (client->connectmap,
727 &neighbour->hashPubKey, 715 &neighbour->hashPubKey,
728 NULL)); 716 NULL));
729#endif 717#endif
730 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); 718 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
731 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); 719 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
@@ -748,27 +736,27 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
748 * @param tmap_new updated type map for the neighbour, NULL for disconnect 736 * @param tmap_new updated type map for the neighbour, NULL for disconnect
749 */ 737 */
750void 738void
751GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, 739GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
752 const struct GNUNET_ATS_Information *atsi, 740 *neighbour,
753 unsigned int atsi_count, 741 const struct GNUNET_ATS_Information
754 const struct GSC_TypeMap *tmap_old, 742 *atsi, unsigned int atsi_count,
755 const struct GSC_TypeMap *tmap_new) 743 const struct GSC_TypeMap *tmap_old,
744 const struct GSC_TypeMap *tmap_new)
756{ 745{
757 struct GSC_Client *c; 746 struct GSC_Client *c;
758 747
759 for (c = client_head; c != NULL; c = c->next) 748 for (c = client_head; c != NULL; c = c->next)
760 GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, 749 GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, atsi_count,
761 atsi_count, 750 tmap_old, tmap_new);
762 tmap_old, tmap_new);
763} 751}
764 752
765 753
766/** 754/**
767 * Deliver P2P message to interested clients. Caller must have checked 755 * Deliver P2P message to interested clients. Caller must have checked
768 * that the sending peer actually lists the given message type as one 756 * that the sending peer actually lists the given message type as one
769 * of its types. 757 * of its types.
770 * 758 *
771 * @param sender peer who sent us the message 759 * @param sender peer who sent us the message
772 * @param atsi performance information about neighbour 760 * @param atsi performance information about neighbour
773 * @param atsi_count number of entries in 'ats' array 761 * @param atsi_count number of entries in 'ats' array
774 * @param msg the message 762 * @param msg the message
@@ -778,13 +766,13 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne
778 */ 766 */
779void 767void
780GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, 768GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
781 const struct GNUNET_ATS_Information *atsi, 769 const struct GNUNET_ATS_Information *atsi,
782 unsigned int atsi_count, 770 unsigned int atsi_count,
783 const struct GNUNET_MessageHeader *msg, 771 const struct GNUNET_MessageHeader *msg,
784 uint16_t msize, 772 uint16_t msize, int options)
785 int options)
786{ 773{
787 size_t size = msize + sizeof (struct NotifyTrafficMessage) + 774 size_t size =
775 msize + sizeof (struct NotifyTrafficMessage) +
788 atsi_count * sizeof (struct GNUNET_ATS_Information); 776 atsi_count * sizeof (struct GNUNET_ATS_Information);
789 char buf[size]; 777 char buf[size];
790 struct NotifyTrafficMessage *ntm; 778 struct NotifyTrafficMessage *ntm;
@@ -793,8 +781,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
793 if (0 == options) 781 if (0 == options)
794 { 782 {
795 GNUNET_snprintf (buf, sizeof (buf), 783 GNUNET_snprintf (buf, sizeof (buf),
796 gettext_noop ("# bytes of messages of type %u received"), 784 gettext_noop ("# bytes of messages of type %u received"),
797 (unsigned int) ntohs (msg->type)); 785 (unsigned int) ntohs (msg->type));
798 GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO); 786 GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO);
799 } 787 }
800 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 788 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
@@ -807,8 +795,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
807#if DEBUG_CORE 795#if DEBUG_CORE
808 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
809 "Core service passes message from `%4s' of type %u to client.\n", 797 "Core service passes message from `%4s' of type %u to client.\n",
810 GNUNET_i2s (sender), 798 GNUNET_i2s (sender), (unsigned int) ntohs (msg->type));
811 (unsigned int) ntohs (msg->type));
812#endif 799#endif
813 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); 800 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
814 ntm = (struct NotifyTrafficMessage *) buf; 801 ntm = (struct NotifyTrafficMessage *) buf;
@@ -817,14 +804,12 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
817 ntm->ats_count = htonl (atsi_count); 804 ntm->ats_count = htonl (atsi_count);
818 ntm->peer = *sender; 805 ntm->peer = *sender;
819 a = &ntm->ats; 806 a = &ntm->ats;
820 memcpy (a, atsi, 807 memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
821 sizeof (struct GNUNET_ATS_Information) * atsi_count);
822 a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); 808 a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
823 a[atsi_count].value = htonl (0); 809 a[atsi_count].value = htonl (0);
824 memcpy (&a[atsi_count + 1], msg, msize); 810 memcpy (&a[atsi_count + 1], msg, msize);
825 send_to_all_clients (sender, 811 send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
826 &ntm->header, GNUNET_YES, 812 ntohs (msg->type));
827 options, ntohs (msg->type));
828} 813}
829 814
830 815
@@ -871,7 +856,7 @@ GSC_CLIENTS_done ()
871{ 856{
872 struct GSC_Client *c; 857 struct GSC_Client *c;
873 858
874 while (NULL != (c = client_head)) 859 while (NULL != (c = client_head))
875 handle_client_disconnect (NULL, c->client_handle); 860 handle_client_disconnect (NULL, c->client_handle);
876 if (NULL != notifier) 861 if (NULL != notifier)
877 { 862 {
diff --git a/src/core/gnunet-service-core_clients.h b/src/core/gnunet-service-core_clients.h
index 2385efc05..bdad20da8 100644
--- a/src/core/gnunet-service-core_clients.h
+++ b/src/core/gnunet-service-core_clients.h
@@ -41,8 +41,8 @@
41 */ 41 */
42void 42void
43GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, 43GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
44 const struct GNUNET_MessageHeader *msg, 44 const struct GNUNET_MessageHeader *msg,
45 int can_drop); 45 int can_drop);
46 46
47 47
48/** 48/**
@@ -59,11 +59,12 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
59 */ 59 */
60void 60void
61GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, 61GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
62 const struct GNUNET_PeerIdentity *neighbour, 62 const struct GNUNET_PeerIdentity
63 const struct GNUNET_ATS_Information *atsi, 63 *neighbour,
64 unsigned int atsi_count, 64 const struct GNUNET_ATS_Information
65 const struct GSC_TypeMap *tmap_old, 65 *atsi, unsigned int atsi_count,
66 const struct GSC_TypeMap *tmap_new); 66 const struct GSC_TypeMap *tmap_old,
67 const struct GSC_TypeMap *tmap_new);
67 68
68 69
69/** 70/**
@@ -78,19 +79,20 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
78 * @param tmap_new updated type map for the neighbour, NULL for disconnect 79 * @param tmap_new updated type map for the neighbour, NULL for disconnect
79 */ 80 */
80void 81void
81GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, 82GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
82 const struct GNUNET_ATS_Information *atsi, 83 *neighbour,
83 unsigned int atsi_count, 84 const struct GNUNET_ATS_Information
84 const struct GSC_TypeMap *tmap_old, 85 *atsi, unsigned int atsi_count,
85 const struct GSC_TypeMap *tmap_new); 86 const struct GSC_TypeMap *tmap_old,
87 const struct GSC_TypeMap *tmap_new);
86 88
87 89
88/** 90/**
89 * Deliver P2P message to interested clients. Caller must have checked 91 * Deliver P2P message to interested clients. Caller must have checked
90 * that the sending peer actually lists the given message type as one 92 * that the sending peer actually lists the given message type as one
91 * of its types. 93 * of its types.
92 * 94 *
93 * @param sender peer who sent us the message 95 * @param sender peer who sent us the message
94 * @param atsi performance information about neighbour 96 * @param atsi performance information about neighbour
95 * @param atsi_count number of entries in 'ats' array 97 * @param atsi_count number of entries in 'ats' array
96 * @param msg the message 98 * @param msg the message
@@ -100,11 +102,10 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *ne
100 */ 102 */
101void 103void
102GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, 104GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
103 const struct GNUNET_ATS_Information *atsi, 105 const struct GNUNET_ATS_Information *atsi,
104 unsigned int atsi_count, 106 unsigned int atsi_count,
105 const struct GNUNET_MessageHeader *msg, 107 const struct GNUNET_MessageHeader *msg,
106 uint16_t msize, 108 uint16_t msize, int options);
107 int options);
108 109
109 110
110/** 111/**
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index 7d27378ac..d49e06e2a 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -112,7 +112,7 @@ struct PongMessage
112 * first field after header (this is where we start to encrypt!). 112 * first field after header (this is where we start to encrypt!).
113 */ 113 */
114 uint32_t challenge GNUNET_PACKED; 114 uint32_t challenge GNUNET_PACKED;
115 115
116 /** 116 /**
117 * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'. 117 * Reserved, always 'GNUNET_BANDWIDTH_VALUE_MAX'.
118 */ 118 */
@@ -495,8 +495,8 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx,
495 "Encrypted %u bytes for `%4s' using key %u, IV %u\n", 495 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
496 (unsigned int) size, GNUNET_i2s (&kx->peer), 496 (unsigned int) size, GNUNET_i2s (&kx->peer),
497 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, 497 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
498 sizeof 498 sizeof
499 (iv))); 499 (iv)));
500#endif 500#endif
501 return GNUNET_OK; 501 return GNUNET_OK;
502} 502}
@@ -526,14 +526,14 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx,
526 GNUNET_break (0); 526 GNUNET_break (0);
527 return GNUNET_NO; 527 return GNUNET_NO;
528 } 528 }
529 if ((kx->status != KX_STATE_KEY_RECEIVED) && 529 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
530 (kx->status != KX_STATE_UP))
531 { 530 {
532 GNUNET_break_op (0); 531 GNUNET_break_op (0);
533 return GNUNET_SYSERR; 532 return GNUNET_SYSERR;
534 } 533 }
535 if (size != 534 if (size !=
536 GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv, out)) 535 GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv,
536 out))
537 { 537 {
538 GNUNET_break (0); 538 GNUNET_break (0);
539 return GNUNET_SYSERR; 539 return GNUNET_SYSERR;
@@ -545,8 +545,8 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx,
545 "Decrypted %u bytes from `%4s' using key %u, IV %u\n", 545 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
546 (unsigned int) size, GNUNET_i2s (&kx->peer), 546 (unsigned int) size, GNUNET_i2s (&kx->peer),
547 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv, 547 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
548 sizeof 548 sizeof
549 (*iv))); 549 (*iv)));
550#endif 550#endif
551 return GNUNET_OK; 551 return GNUNET_OK;
552} 552}
@@ -573,7 +573,8 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
573 struct GSC_KeyExchangeInfo *kx = cls; 573 struct GSC_KeyExchangeInfo *kx = cls;
574 574
575 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; 575 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
576 kx->set_key_retry_frequency = GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2); 576 kx->set_key_retry_frequency =
577 GNUNET_TIME_relative_multiply (kx->set_key_retry_frequency, 2);
577 send_key (kx); 578 send_key (kx);
578} 579}
579 580
@@ -590,8 +591,7 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
590 */ 591 */
591static void 592static void
592process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, 593process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
593 const struct GNUNET_HELLO_Message *hello, 594 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
594 const char *err_msg)
595{ 595{
596 struct GSC_KeyExchangeInfo *kx = cls; 596 struct GSC_KeyExchangeInfo *kx = cls;
597 struct SetKeyMessage *skm; 597 struct SetKeyMessage *skm;
@@ -607,19 +607,19 @@ process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
607 { 607 {
608 kx->pitr = NULL; 608 kx->pitr = NULL;
609 if (kx->public_key != NULL) 609 if (kx->public_key != NULL)
610 return; /* done here */ 610 return; /* done here */
611#if DEBUG_CORE 611#if DEBUG_CORE
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", 613 "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n",
614 GNUNET_i2s (&kx->peer)); 614 GNUNET_i2s (&kx->peer));
615#endif 615#endif
616 GNUNET_STATISTICS_update (GSC_stats, 616 GNUNET_STATISTICS_update (GSC_stats,
617 gettext_noop 617 gettext_noop
618 ("# Delayed connecting due to lack of public key"), 618 ("# Delayed connecting due to lack of public key"),
619 1, GNUNET_NO); 619 1, GNUNET_NO);
620 kx->retry_set_key_task = 620 kx->retry_set_key_task =
621 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, 621 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
622 &set_key_retry_task, kx); 622 &set_key_retry_task, kx);
623 return; 623 return;
624 } 624 }
625 if (kx->public_key != NULL) 625 if (kx->public_key != NULL)
@@ -661,22 +661,19 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
661 struct GSC_KeyExchangeInfo *kx; 661 struct GSC_KeyExchangeInfo *kx;
662 662
663#if DEBUG_CORE 663#if DEBUG_CORE
664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initiating key exchange with `%s'\n",
665 "Initiating key exchange with `%s'\n", 665 GNUNET_i2s (pid));
666 GNUNET_i2s (pid));
667#endif 666#endif
668 GNUNET_STATISTICS_update (GSC_stats, 667 GNUNET_STATISTICS_update (GSC_stats,
669 gettext_noop ("# key exchanges initiated"), 668 gettext_noop ("# key exchanges initiated"), 1,
670 1, 669 GNUNET_NO);
671 GNUNET_NO);
672 kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo)); 670 kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
673 kx->peer = *pid; 671 kx->peer = *pid;
674 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; 672 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
675 kx->pitr = GNUNET_PEERINFO_iterate (peerinfo, 673 kx->pitr =
676 pid, 674 GNUNET_PEERINFO_iterate (peerinfo, pid,
677 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, 675 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
678 &process_hello, 676 &process_hello, kx);
679 kx);
680 return kx; 677 return kx;
681} 678}
682 679
@@ -689,10 +686,8 @@ GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
689void 686void
690GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) 687GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
691{ 688{
692 GNUNET_STATISTICS_update (GSC_stats, 689 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"),
693 gettext_noop ("# key exchanges stopped"), 690 1, GNUNET_NO);
694 1,
695 GNUNET_NO);
696 if (kx->pitr != NULL) 691 if (kx->pitr != NULL)
697 { 692 {
698 GNUNET_PEERINFO_iterate_cancel (kx->pitr); 693 GNUNET_PEERINFO_iterate_cancel (kx->pitr);
@@ -726,7 +721,7 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
726 */ 721 */
727void 722void
728GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, 723GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
729 const struct GNUNET_MessageHeader *msg) 724 const struct GNUNET_MessageHeader *msg)
730{ 725{
731 const struct SetKeyMessage *m; 726 const struct SetKeyMessage *m;
732 struct GNUNET_TIME_Absolute t; 727 struct GNUNET_TIME_Absolute t;
@@ -735,16 +730,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
735 struct PongMessage *pong; 730 struct PongMessage *pong;
736 enum KxStateMachine sender_status; 731 enum KxStateMachine sender_status;
737 uint16_t size; 732 uint16_t size;
738 733
739 size = ntohs (msg->size); 734 size = ntohs (msg->size);
740 if (size != sizeof (struct SetKeyMessage)) 735 if (size != sizeof (struct SetKeyMessage))
741 { 736 {
742 GNUNET_break_op (0); 737 GNUNET_break_op (0);
743 return; 738 return;
744 } 739 }
745 m = (const struct SetKeyMessage*) msg; 740 m = (const struct SetKeyMessage *) msg;
746 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"), 741 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# session keys received"),
747 1, GNUNET_NO); 742 1, GNUNET_NO);
748 743
749#if DEBUG_CORE 744#if DEBUG_CORE
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -754,15 +749,16 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
754 if (kx->public_key == NULL) 749 if (kx->public_key == NULL)
755 { 750 {
756 GNUNET_free_non_null (kx->skm_received); 751 GNUNET_free_non_null (kx->skm_received);
757 kx->skm_received = (struct SetKeyMessage*) GNUNET_copy_message (msg); 752 kx->skm_received = (struct SetKeyMessage *) GNUNET_copy_message (msg);
758 return; 753 return;
759 } 754 }
760 if (0 != 755 if (0 !=
761 memcmp (&m->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 756 memcmp (&m->target, &GSC_my_identity,
757 sizeof (struct GNUNET_PeerIdentity)))
762 { 758 {
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 _("`%s' is for `%s', not for me. Ignoring.\n"), 760 _("`%s' is for `%s', not for me. Ignoring.\n"), "SET_KEY",
765 "SET_KEY", GNUNET_i2s (&m->target)); 761 GNUNET_i2s (&m->target));
766 return; 762 return;
767 } 763 }
768 if ((ntohl (m->purpose.size) != 764 if ((ntohl (m->purpose.size) !=
@@ -779,8 +775,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
779 return; 775 return;
780 } 776 }
781 t = GNUNET_TIME_absolute_ntoh (m->creation_time); 777 t = GNUNET_TIME_absolute_ntoh (m->creation_time);
782 if (((kx->status == KX_STATE_KEY_RECEIVED) || 778 if (((kx->status == KX_STATE_KEY_RECEIVED) || (kx->status == KX_STATE_UP)) &&
783 (kx->status == KX_STATE_UP)) &&
784 (t.abs_value < kx->decrypt_key_created.abs_value)) 779 (t.abs_value < kx->decrypt_key_created.abs_value))
785 { 780 {
786 /* this could rarely happen due to massive re-ordering of 781 /* this could rarely happen due to massive re-ordering of
@@ -803,9 +798,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
803 gettext_noop ("# SET_KEY messages decrypted"), 1, 798 gettext_noop ("# SET_KEY messages decrypted"), 1,
804 GNUNET_NO); 799 GNUNET_NO);
805#if DEBUG_CORE 800#if DEBUG_CORE
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_KEY from `%s'\n",
807 "Received SET_KEY from `%s'\n", 802 GNUNET_i2s (&kx->peer));
808 GNUNET_i2s (&kx->peer));
809#endif 803#endif
810 kx->decrypt_key = k; 804 kx->decrypt_key = k;
811 if (kx->decrypt_key_created.abs_value != t.abs_value) 805 if (kx->decrypt_key_created.abs_value != t.abs_value)
@@ -831,9 +825,9 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
831 /* we're not up, so we are already doing 'send_key' */ 825 /* we're not up, so we are already doing 'send_key' */
832 break; 826 break;
833 case KX_STATE_UP: 827 case KX_STATE_UP:
834 if ( (sender_status == KX_STATE_DOWN) || 828 if ((sender_status == KX_STATE_DOWN) ||
835 (sender_status == KX_STATE_KEY_SENT) ) 829 (sender_status == KX_STATE_KEY_SENT))
836 send_key (kx); /* we are up, but other peer is not! */ 830 send_key (kx); /* we are up, but other peer is not! */
837 break; 831 break;
838 default: 832 default:
839 GNUNET_break (0); 833 GNUNET_break (0);
@@ -865,7 +859,7 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
865 */ 859 */
866void 860void
867GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, 861GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
868 const struct GNUNET_MessageHeader *msg) 862 const struct GNUNET_MessageHeader *msg)
869{ 863{
870 const struct PingMessage *m; 864 const struct PingMessage *m;
871 struct PingMessage t; 865 struct PingMessage t;
@@ -876,22 +870,21 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
876 870
877 msize = ntohs (msg->size); 871 msize = ntohs (msg->size);
878 if (msize != sizeof (struct PingMessage)) 872 if (msize != sizeof (struct PingMessage))
879 { 873 {
880 GNUNET_break_op (0); 874 GNUNET_break_op (0);
881 return; 875 return;
882 } 876 }
883 GNUNET_STATISTICS_update (GSC_stats, 877 GNUNET_STATISTICS_update (GSC_stats,
884 gettext_noop ("# PING messages received"), 878 gettext_noop ("# PING messages received"), 1,
885 1, GNUNET_NO); 879 GNUNET_NO);
886 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 880 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
887 (kx->status != KX_STATE_UP) ) 881 {
888 { 882 /* defer */
889 /* defer */ 883 GNUNET_free_non_null (kx->ping_received);
890 GNUNET_free_non_null (kx->ping_received); 884 kx->ping_received = (struct PingMessage *) GNUNET_copy_message (msg);
891 kx->ping_received = (struct PingMessage*) GNUNET_copy_message (msg); 885 return;
892 return; 886 }
893 } 887 m = (const struct PingMessage *) msg;
894 m = (const struct PingMessage*) msg;
895#if DEBUG_CORE 888#if DEBUG_CORE
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
897 "Core service receives `%s' request from `%4s'.\n", "PING", 890 "Core service receives `%s' request from `%4s'.\n", "PING",
@@ -915,15 +908,15 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
915 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer)); 908 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer));
916 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); 909 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target));
917 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 910 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
918 _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), 911 _
912 ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
919 sender, GNUNET_i2s (&GSC_my_identity), peer); 913 sender, GNUNET_i2s (&GSC_my_identity), peer);
920 GNUNET_break_op (0); 914 GNUNET_break_op (0);
921 return; 915 return;
922 } 916 }
923#if DEBUG_CORE 917#if DEBUG_CORE
924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PING from `%s'\n",
925 "Received PING from `%s'\n", 919 GNUNET_i2s (&kx->peer));
926 GNUNET_i2s (&kx->peer));
927#endif 920#endif
928 /* construct PONG */ 921 /* construct PONG */
929 tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX; 922 tx.reserved = GNUNET_BANDWIDTH_VALUE_MAX;
@@ -937,12 +930,10 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
937 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge, 930 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
938 sizeof (struct PongMessage) - ((void *) &tp.challenge - 931 sizeof (struct PongMessage) - ((void *) &tp.challenge -
939 (void *) &tp)); 932 (void *) &tp));
940 GNUNET_STATISTICS_update (GSC_stats, 933 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"),
941 gettext_noop ("# PONG messages created"), 1, 934 1, GNUNET_NO);
942 GNUNET_NO); 935 GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header,
943 GSC_NEIGHBOURS_transmit (&kx->peer, 936 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ );
944 &tp.header,
945 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */);
946} 937}
947 938
948 939
@@ -963,21 +954,22 @@ setup_fresh_setkey (struct GSC_KeyExchangeInfo *kx)
963 skm->header.size = htons (sizeof (struct SetKeyMessage)); 954 skm->header.size = htons (sizeof (struct SetKeyMessage));
964 skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); 955 skm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY);
965 skm->purpose.size = 956 skm->purpose.size =
966 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 957 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
967 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 958 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
968 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + 959 sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) +
969 sizeof (struct GNUNET_PeerIdentity)); 960 sizeof (struct GNUNET_PeerIdentity));
970 skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); 961 skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY);
971 skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created); 962 skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created);
972 skm->target = kx->peer; 963 skm->target = kx->peer;
973 GNUNET_assert (GNUNET_OK == 964 GNUNET_assert (GNUNET_OK ==
974 GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key, 965 GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key,
975 sizeof (struct 966 sizeof (struct
976 GNUNET_CRYPTO_AesSessionKey), 967 GNUNET_CRYPTO_AesSessionKey),
977 kx->public_key, &skm->encrypted_key)); 968 kx->public_key,
969 &skm->encrypted_key));
978 GNUNET_assert (GNUNET_OK == 970 GNUNET_assert (GNUNET_OK ==
979 GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose, 971 GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose,
980 &skm->signature)); 972 &skm->signature));
981} 973}
982 974
983 975
@@ -997,13 +989,13 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
997 pm->header.size = htons (sizeof (struct PingMessage)); 989 pm->header.size = htons (sizeof (struct PingMessage));
998 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); 990 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
999 pm->iv_seed = 991 pm->iv_seed =
1000 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 992 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1001 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer); 993 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
1002 pp.challenge = kx->ping_challenge; 994 pp.challenge = kx->ping_challenge;
1003 pp.target = kx->peer; 995 pp.target = kx->peer;
1004 do_encrypt (kx, &iv, &pp.target, &pm->target, 996 do_encrypt (kx, &iv, &pp.target, &pm->target,
1005 sizeof (struct PingMessage) - ((void *) &pm->target - 997 sizeof (struct PingMessage) - ((void *) &pm->target -
1006 (void *) pm)); 998 (void *) pm));
1007} 999}
1008 1000
1009 1001
@@ -1024,33 +1016,29 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1024 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; 1016 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1025 left = GNUNET_TIME_absolute_get_remaining (kx->timeout); 1017 left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
1026 if (left.rel_value == 0) 1018 if (left.rel_value == 0)
1027 { 1019 {
1028 GNUNET_STATISTICS_update (GSC_stats, 1020 GNUNET_STATISTICS_update (GSC_stats,
1029 gettext_noop ("# sessions terminated by timeout"), 1021 gettext_noop ("# sessions terminated by timeout"),
1030 1, 1022 1, GNUNET_NO);
1031 GNUNET_NO);
1032 GSC_SESSIONS_end (&kx->peer); 1023 GSC_SESSIONS_end (&kx->peer);
1033 kx->status = KX_STATE_DOWN; 1024 kx->status = KX_STATE_DOWN;
1034 return; 1025 return;
1035 } 1026 }
1036#if DEBUG_CORE 1027#if DEBUG_CORE
1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1028 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n",
1038 "Sending KEEPALIVE to `%s'\n", 1029 GNUNET_i2s (&kx->peer));
1039 GNUNET_i2s (&kx->peer));
1040#endif 1030#endif
1041 GNUNET_STATISTICS_update (GSC_stats, 1031 GNUNET_STATISTICS_update (GSC_stats,
1042 gettext_noop ("# keepalive messages sent"), 1032 gettext_noop ("# keepalive messages sent"), 1,
1043 1, 1033 GNUNET_NO);
1044 GNUNET_NO);
1045 setup_fresh_ping (kx); 1034 setup_fresh_ping (kx);
1046 GSC_NEIGHBOURS_transmit (&kx->peer, 1035 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1047 &kx->ping.header, 1036 kx->set_key_retry_frequency);
1048 kx->set_key_retry_frequency);
1049 retry = 1037 retry =
1050 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), 1038 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1051 MIN_PING_FREQUENCY); 1039 MIN_PING_FREQUENCY);
1052 kx->keep_alive_task = 1040 kx->keep_alive_task =
1053 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); 1041 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
1054} 1042}
1055 1043
1056 1044
@@ -1064,13 +1052,15 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1064static void 1052static void
1065update_timeout (struct GSC_KeyExchangeInfo *kx) 1053update_timeout (struct GSC_KeyExchangeInfo *kx)
1066{ 1054{
1067 kx->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1055 kx->timeout =
1056 GNUNET_TIME_relative_to_absolute
1057 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1068 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) 1058 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1069 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 1059 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1070 kx->keep_alive_task = 1060 kx->keep_alive_task =
1071 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 1061 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1072 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1062 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1073 2), &send_keep_alive, kx); 1063 2), &send_keep_alive, kx);
1074} 1064}
1075 1065
1076 1066
@@ -1081,7 +1071,8 @@ update_timeout (struct GSC_KeyExchangeInfo *kx)
1081 * @param m the encrypted PONG message itself 1071 * @param m the encrypted PONG message itself
1082 */ 1072 */
1083void 1073void
1084GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageHeader *msg) 1074GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1075 const struct GNUNET_MessageHeader *msg)
1085{ 1076{
1086 const struct PongMessage *m; 1077 const struct PongMessage *m;
1087 struct PongMessage t; 1078 struct PongMessage t;
@@ -1095,19 +1086,19 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1095 GNUNET_break_op (0); 1086 GNUNET_break_op (0);
1096 return; 1087 return;
1097 } 1088 }
1098 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages received"), 1089 GNUNET_STATISTICS_update (GSC_stats,
1099 1, GNUNET_NO); 1090 gettext_noop ("# PONG messages received"), 1,
1100 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 1091 GNUNET_NO);
1101 (kx->status != KX_STATE_UP) ) 1092 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
1102 { 1093 {
1103 if (kx->status == KX_STATE_KEY_SENT) 1094 if (kx->status == KX_STATE_KEY_SENT)
1104 { 1095 {
1105 GNUNET_free_non_null (kx->pong_received); 1096 GNUNET_free_non_null (kx->pong_received);
1106 kx->pong_received = (struct PongMessage*) GNUNET_copy_message (msg); 1097 kx->pong_received = (struct PongMessage *) GNUNET_copy_message (msg);
1107 } 1098 }
1108 return; 1099 return;
1109 } 1100 }
1110 m = (const struct PongMessage*) msg; 1101 m = (const struct PongMessage *) msg;
1111#if DEBUG_HANDSHAKE 1102#if DEBUG_HANDSHAKE
1112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1113 "Core service receives `%s' response from `%4s'.\n", "PONG", 1104 "Core service receives `%s' response from `%4s'.\n", "PONG",
@@ -1125,8 +1116,9 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1125 GNUNET_break_op (0); 1116 GNUNET_break_op (0);
1126 return; 1117 return;
1127 } 1118 }
1128 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages decrypted"), 1119 GNUNET_STATISTICS_update (GSC_stats,
1129 1, GNUNET_NO); 1120 gettext_noop ("# PONG messages decrypted"), 1,
1121 GNUNET_NO);
1130 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity))) 1122 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity)))
1131 || (kx->ping_challenge != t.challenge)) 1123 || (kx->ping_challenge != t.challenge))
1132 { 1124 {
@@ -1143,9 +1135,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1143 return; 1135 return;
1144 } 1136 }
1145#if DEBUG_CORE 1137#if DEBUG_CORE
1146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
1147 "Received PONG from `%s'\n", 1139 GNUNET_i2s (&kx->peer));
1148 GNUNET_i2s (&kx->peer));
1149#endif 1140#endif
1150 switch (kx->status) 1141 switch (kx->status)
1151 { 1142 {
@@ -1170,7 +1161,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_MessageH
1170 { 1161 {
1171 emsg = kx->emsg_received; 1162 emsg = kx->emsg_received;
1172 kx->emsg_received = NULL; 1163 kx->emsg_received = NULL;
1173 GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL, 0 /* FIXME: ATSI */); 1164 GSC_KX_handle_encrypted_message (kx, &emsg->header, NULL,
1165 0 /* FIXME: ATSI */ );
1174 GNUNET_free (emsg); 1166 GNUNET_free (emsg);
1175 } 1167 }
1176 update_timeout (kx); 1168 update_timeout (kx);
@@ -1194,20 +1186,20 @@ static void
1194send_key (struct GSC_KeyExchangeInfo *kx) 1186send_key (struct GSC_KeyExchangeInfo *kx)
1195{ 1187{
1196 GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK); 1188 GNUNET_assert (kx->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK);
1197 if (KX_STATE_UP == kx->status) 1189 if (KX_STATE_UP == kx->status)
1198 return; /* nothing to do */ 1190 return; /* nothing to do */
1199 if (kx->public_key == NULL) 1191 if (kx->public_key == NULL)
1200 { 1192 {
1201 /* lookup public key, then try again */ 1193 /* lookup public key, then try again */
1202#if DEBUG_CORE 1194#if DEBUG_CORE
1203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1204 "Trying to obtain public key for `%s'\n", 1196 "Trying to obtain public key for `%s'\n",
1205 GNUNET_i2s (&kx->peer)); 1197 GNUNET_i2s (&kx->peer));
1206#endif 1198#endif
1207 kx->pitr = 1199 kx->pitr =
1208 GNUNET_PEERINFO_iterate (peerinfo, &kx->peer, 1200 GNUNET_PEERINFO_iterate (peerinfo, &kx->peer,
1209 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */, 1201 GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
1210 &process_hello, kx); 1202 &process_hello, kx);
1211 return; 1203 return;
1212 } 1204 }
1213 1205
@@ -1215,14 +1207,14 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1215 switch (kx->status) 1207 switch (kx->status)
1216 { 1208 {
1217 case KX_STATE_DOWN: 1209 case KX_STATE_DOWN:
1218 kx->status = KX_STATE_KEY_SENT; 1210 kx->status = KX_STATE_KEY_SENT;
1219 /* setup SET KEY message */ 1211 /* setup SET KEY message */
1220 setup_fresh_setkey (kx); 1212 setup_fresh_setkey (kx);
1221 setup_fresh_ping (kx); 1213 setup_fresh_ping (kx);
1222 GNUNET_STATISTICS_update (GSC_stats, 1214 GNUNET_STATISTICS_update (GSC_stats,
1223 gettext_noop 1215 gettext_noop
1224 ("# SET_KEY and PING messages created"), 1, 1216 ("# SET_KEY and PING messages created"), 1,
1225 GNUNET_NO); 1217 GNUNET_NO);
1226 break; 1218 break;
1227 case KX_STATE_KEY_SENT: 1219 case KX_STATE_KEY_SENT:
1228 break; 1220 break;
@@ -1239,19 +1231,16 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1239 /* always update sender status in SET KEY message */ 1231 /* always update sender status in SET KEY message */
1240 kx->skm.sender_status = htonl ((int32_t) kx->status); 1232 kx->skm.sender_status = htonl ((int32_t) kx->status);
1241#if DEBUG_CORE 1233#if DEBUG_CORE
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SET_KEY and PING to `%s'\n",
1243 "Sending SET_KEY and PING to `%s'\n", 1235 GNUNET_i2s (&kx->peer));
1244 GNUNET_i2s (&kx->peer));
1245#endif 1236#endif
1246 GSC_NEIGHBOURS_transmit (&kx->peer, 1237 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->skm.header,
1247 &kx->skm.header, 1238 kx->set_key_retry_frequency);
1248 kx->set_key_retry_frequency); 1239 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1249 GSC_NEIGHBOURS_transmit (&kx->peer, 1240 kx->set_key_retry_frequency);
1250 &kx->ping.header,
1251 kx->set_key_retry_frequency);
1252 kx->retry_set_key_task = 1241 kx->retry_set_key_task =
1253 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, 1242 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
1254 &set_key_retry_task, kx); 1243 &set_key_retry_task, kx);
1255} 1244}
1256 1245
1257 1246
@@ -1264,18 +1253,17 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1264 */ 1253 */
1265void 1254void
1266GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 1255GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1267 const void *payload, 1256 const void *payload, size_t payload_size)
1268 size_t payload_size)
1269{ 1257{
1270 size_t used = payload_size + sizeof (struct EncryptedMessage); 1258 size_t used = payload_size + sizeof (struct EncryptedMessage);
1271 char pbuf[used]; /* plaintext */ 1259 char pbuf[used]; /* plaintext */
1272 char cbuf[used]; /* ciphertext */ 1260 char cbuf[used]; /* ciphertext */
1273 struct EncryptedMessage *em; /* encrypted message */ 1261 struct EncryptedMessage *em; /* encrypted message */
1274 struct EncryptedMessage *ph; /* plaintext header */ 1262 struct EncryptedMessage *ph; /* plaintext header */
1275 struct GNUNET_CRYPTO_AesInitializationVector iv; 1263 struct GNUNET_CRYPTO_AesInitializationVector iv;
1276 struct GNUNET_CRYPTO_AuthKey auth_key; 1264 struct GNUNET_CRYPTO_AuthKey auth_key;
1277 1265
1278 ph = (struct EncryptedMessage*) pbuf; 1266 ph = (struct EncryptedMessage *) pbuf;
1279 ph->iv_seed = 1267 ph->iv_seed =
1280 htonl (GNUNET_CRYPTO_random_u32 1268 htonl (GNUNET_CRYPTO_random_u32
1281 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); 1269 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
@@ -1290,22 +1278,20 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1290 em->iv_seed = ph->iv_seed; 1278 em->iv_seed = ph->iv_seed;
1291 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer); 1279 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer);
1292 GNUNET_assert (GNUNET_OK == 1280 GNUNET_assert (GNUNET_OK ==
1293 do_encrypt (kx, &iv, &ph->sequence_number, &em->sequence_number, 1281 do_encrypt (kx, &iv, &ph->sequence_number,
1282 &em->sequence_number,
1294 used - ENCRYPTED_HEADER_SIZE)); 1283 used - ENCRYPTED_HEADER_SIZE));
1295#if DEBUG_CORE 1284#if DEBUG_CORE
1296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n",
1297 "Encrypted %u bytes for %s\n", 1286 used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1298 used - ENCRYPTED_HEADER_SIZE,
1299 GNUNET_i2s (&kx->peer));
1300#endif 1287#endif
1301 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed, 1288 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed,
1302 kx->encrypt_key_created); 1289 kx->encrypt_key_created);
1303 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, 1290 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
1304 used - ENCRYPTED_HEADER_SIZE, &em->hmac); 1291 used - ENCRYPTED_HEADER_SIZE, &em->hmac);
1305 GSC_NEIGHBOURS_transmit (&kx->peer, 1292 GSC_NEIGHBOURS_transmit (&kx->peer, &em->header,
1306 &em->header, 1293 GNUNET_TIME_UNIT_FOREVER_REL);
1307 GNUNET_TIME_UNIT_FOREVER_REL); 1294}
1308}
1309 1295
1310 1296
1311/** 1297/**
@@ -1313,7 +1299,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1313 */ 1299 */
1314struct DeliverMessageContext 1300struct DeliverMessageContext
1315{ 1301{
1316 1302
1317 /** 1303 /**
1318 * Performance information for the connection. 1304 * Performance information for the connection.
1319 */ 1305 */
@@ -1330,7 +1316,7 @@ struct DeliverMessageContext
1330 uint32_t atsi_count; 1316 uint32_t atsi_count;
1331}; 1317};
1332 1318
1333 1319
1334/** 1320/**
1335 * We received an encrypted message. Decrypt, validate and 1321 * We received an encrypted message. Decrypt, validate and
1336 * pass on to the appropriate clients. 1322 * pass on to the appropriate clients.
@@ -1341,10 +1327,10 @@ struct DeliverMessageContext
1341 * @param atsi_count number of entries in ats (excluding 0-termination) 1327 * @param atsi_count number of entries in ats (excluding 0-termination)
1342 */ 1328 */
1343void 1329void
1344GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, 1330GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1345 const struct GNUNET_MessageHeader *msg, 1331 const struct GNUNET_MessageHeader *msg,
1346 const struct GNUNET_ATS_Information *atsi, 1332 const struct GNUNET_ATS_Information *atsi,
1347 uint32_t atsi_count) 1333 uint32_t atsi_count)
1348{ 1334{
1349 const struct EncryptedMessage *m; 1335 const struct EncryptedMessage *m;
1350 struct EncryptedMessage *pt; /* plaintext */ 1336 struct EncryptedMessage *pt; /* plaintext */
@@ -1363,21 +1349,20 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1363 GNUNET_break_op (0); 1349 GNUNET_break_op (0);
1364 return; 1350 return;
1365 } 1351 }
1366 m = (const struct EncryptedMessage*) msg; 1352 m = (const struct EncryptedMessage *) msg;
1367 if ( (kx->status != KX_STATE_KEY_RECEIVED) && 1353 if ((kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP))
1368 (kx->status != KX_STATE_UP) )
1369 { 1354 {
1370 GNUNET_STATISTICS_update (GSC_stats, 1355 GNUNET_STATISTICS_update (GSC_stats,
1371 gettext_noop 1356 gettext_noop
1372 ("# failed to decrypt message (no session key)"), 1357 ("# failed to decrypt message (no session key)"),
1373 1, GNUNET_NO); 1358 1, GNUNET_NO);
1374 return; 1359 return;
1375 } 1360 }
1376 if (kx->status == KX_STATE_KEY_RECEIVED) 1361 if (kx->status == KX_STATE_KEY_RECEIVED)
1377 { 1362 {
1378 /* defer */ 1363 /* defer */
1379 GNUNET_free_non_null (kx->ping_received); 1364 GNUNET_free_non_null (kx->ping_received);
1380 kx->emsg_received = (struct EncryptedMessage*) GNUNET_copy_message (msg); 1365 kx->emsg_received = (struct EncryptedMessage *) GNUNET_copy_message (msg);
1381 return; 1366 return;
1382 } 1367 }
1383 /* validate hash */ 1368 /* validate hash */
@@ -1398,10 +1383,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1398 size - ENCRYPTED_HEADER_SIZE)) 1383 size - ENCRYPTED_HEADER_SIZE))
1399 return; 1384 return;
1400#if DEBUG_CORE 1385#if DEBUG_CORE
1401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n",
1402 "Decrypted %u bytes from %s\n", 1387 size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1403 size - ENCRYPTED_HEADER_SIZE,
1404 GNUNET_i2s (&kx->peer));
1405#endif 1388#endif
1406 pt = (struct EncryptedMessage *) buf; 1389 pt = (struct EncryptedMessage *) buf;
1407 1390
@@ -1480,7 +1463,8 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1480 dmc.atsi_count = atsi_count; 1463 dmc.atsi_count = atsi_count;
1481 dmc.peer = &kx->peer; 1464 dmc.peer = &kx->peer;
1482 if (GNUNET_OK != 1465 if (GNUNET_OK !=
1483 GNUNET_SERVER_mst_receive (mst, &dmc, &buf[sizeof (struct EncryptedMessage)], 1466 GNUNET_SERVER_mst_receive (mst, &dmc,
1467 &buf[sizeof (struct EncryptedMessage)],
1484 size - sizeof (struct EncryptedMessage), 1468 size - sizeof (struct EncryptedMessage),
1485 GNUNET_YES, GNUNET_NO)) 1469 GNUNET_YES, GNUNET_NO))
1486 GNUNET_break_op (0); 1470 GNUNET_break_op (0);
@@ -1490,7 +1474,7 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1490/** 1474/**
1491 * Deliver P2P message to interested clients. 1475 * Deliver P2P message to interested clients.
1492 * Invokes send twice, once for clients that want the full message, and once 1476 * Invokes send twice, once for clients that want the full message, and once
1493 * for clients that only want the header 1477 * for clients that only want the header
1494 * 1478 *
1495 * @param cls always NULL 1479 * @param cls always NULL
1496 * @param client who sent us the message (struct GSC_KeyExchangeInfo) 1480 * @param client who sent us the message (struct GSC_KeyExchangeInfo)
@@ -1505,20 +1489,15 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
1505 { 1489 {
1506 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: 1490 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
1507 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: 1491 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
1508 GSC_SESSIONS_set_typemap (dmc->peer, 1492 GSC_SESSIONS_set_typemap (dmc->peer, m);
1509 m);
1510 return; 1493 return;
1511 default: 1494 default:
1512 GSC_CLIENTS_deliver_message (dmc->peer, 1495 GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
1513 dmc->atsi, dmc->atsi_count, 1496 ntohs (m->size),
1514 m, 1497 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
1515 ntohs (m->size), 1498 GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
1516 GNUNET_CORE_OPTION_SEND_FULL_INBOUND); 1499 sizeof (struct GNUNET_MessageHeader),
1517 GSC_CLIENTS_deliver_message (dmc->peer, 1500 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1518 dmc->atsi, dmc->atsi_count,
1519 m,
1520 sizeof (struct GNUNET_MessageHeader),
1521 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1522 } 1501 }
1523} 1502}
1524 1503
@@ -1528,17 +1507,18 @@ deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
1528 * 1507 *
1529 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 1508 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1530 */ 1509 */
1531int 1510int
1532GSC_KX_init () 1511GSC_KX_init ()
1533{ 1512{
1534 char *keyfile; 1513 char *keyfile;
1535 1514
1536 if (GNUNET_OK != 1515 if (GNUNET_OK !=
1537 GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY", 1516 GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, "GNUNETD", "HOSTKEY",
1538 &keyfile)) 1517 &keyfile))
1539 { 1518 {
1540 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1519 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1541 _("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); 1520 _
1521 ("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
1542 return GNUNET_SYSERR; 1522 return GNUNET_SYSERR;
1543 } 1523 }
1544 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1524 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
@@ -1569,7 +1549,7 @@ GSC_KX_init ()
1569/** 1549/**
1570 * Shutdown KX subsystem. 1550 * Shutdown KX subsystem.
1571 */ 1551 */
1572void 1552void
1573GSC_KX_done () 1553GSC_KX_done ()
1574{ 1554{
1575 if (my_private_key != NULL) 1555 if (my_private_key != NULL)
diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h
index 0e963ef7a..5ecd2c17f 100644
--- a/src/core/gnunet-service-core_kx.h
+++ b/src/core/gnunet-service-core_kx.h
@@ -44,8 +44,8 @@ struct GSC_KeyExchangeInfo;
44 * @param msg the set key message we received 44 * @param msg the set key message we received
45 */ 45 */
46void 46void
47GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx, 47GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
48 const struct GNUNET_MessageHeader *msg); 48 const struct GNUNET_MessageHeader *msg);
49 49
50 50
51/** 51/**
@@ -56,8 +56,8 @@ GSC_KX_handle_set_key (struct GSC_KeyExchangeInfo *kx,
56 * @param msg the encrypted PING message itself 56 * @param msg the encrypted PING message itself
57 */ 57 */
58void 58void
59GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx, 59GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
60 const struct GNUNET_MessageHeader *msg); 60 const struct GNUNET_MessageHeader *msg);
61 61
62 62
63/** 63/**
@@ -68,7 +68,7 @@ GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
68 */ 68 */
69void 69void
70GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx, 70GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
71 const struct GNUNET_MessageHeader *msg); 71 const struct GNUNET_MessageHeader *msg);
72 72
73 73
74/** 74/**
@@ -80,8 +80,7 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
80 */ 80 */
81void 81void
82GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 82GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
83 const void *payload, 83 const void *payload, size_t payload_size);
84 size_t payload_size);
85 84
86 85
87/** 86/**
@@ -94,10 +93,10 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
94 * @param atsi_count number of entries in ats (excluding 0-termination) 93 * @param atsi_count number of entries in ats (excluding 0-termination)
95 */ 94 */
96void 95void
97GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx, 96GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
98 const struct GNUNET_MessageHeader *msg, 97 const struct GNUNET_MessageHeader *msg,
99 const struct GNUNET_ATS_Information *atsi, 98 const struct GNUNET_ATS_Information *atsi,
100 uint32_t atsi_count); 99 uint32_t atsi_count);
101 100
102 101
103/** 102/**
@@ -124,14 +123,14 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx);
124 * 123 *
125 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 124 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
126 */ 125 */
127int 126int
128GSC_KX_init (void); 127GSC_KX_init (void);
129 128
130 129
131/** 130/**
132 * Shutdown KX subsystem. 131 * Shutdown KX subsystem.
133 */ 132 */
134void 133void
135GSC_KX_done (void); 134GSC_KX_done (void);
136 135
137#endif 136#endif
diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c
index d7ce91a88..5014298bf 100644
--- a/src/core/gnunet-service-core_neighbours.c
+++ b/src/core/gnunet-service-core_neighbours.c
@@ -158,10 +158,10 @@ free_neighbour (struct Neighbour *n)
158 GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); 158 GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th);
159 n->th = NULL; 159 n->th = NULL;
160 } 160 }
161 GNUNET_STATISTICS_update (GSC_stats, 161 GNUNET_STATISTICS_update (GSC_stats,
162 gettext_noop ("# sessions terminated by transport disconnect"), 162 gettext_noop
163 1, 163 ("# sessions terminated by transport disconnect"),
164 GNUNET_NO); 164 1, GNUNET_NO);
165 GSC_SESSIONS_end (&n->peer); 165 GSC_SESSIONS_end (&n->peer);
166 if (NULL != n->kxinfo) 166 if (NULL != n->kxinfo)
167 { 167 {
@@ -175,8 +175,9 @@ free_neighbour (struct Neighbour *n)
175 } 175 }
176 GNUNET_assert (GNUNET_OK == 176 GNUNET_assert (GNUNET_OK ==
177 GNUNET_CONTAINER_multihashmap_remove (neighbours, 177 GNUNET_CONTAINER_multihashmap_remove (neighbours,
178 &n->peer.hashPubKey, n)); 178 &n->peer.hashPubKey, n));
179 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), 179 GNUNET_STATISTICS_set (GSC_stats,
180 gettext_noop ("# neighbour entries allocated"),
180 GNUNET_CONTAINER_multihashmap_size (neighbours), 181 GNUNET_CONTAINER_multihashmap_size (neighbours),
181 GNUNET_NO); 182 GNUNET_NO);
182 GNUNET_free (n); 183 GNUNET_free (n);
@@ -239,10 +240,10 @@ transmit_ready (void *cls, size_t size, void *buf)
239 ret = m->size; 240 ret = m->size;
240#if DEBUG_CORE 241#if DEBUG_CORE
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Copied message of type %u and size %u into transport buffer for `%4s'\n", 243 "Copied message of type %u and size %u into transport buffer for `%4s'\n",
243 (unsigned int) 244 (unsigned int)
244 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), 245 ntohs (((struct GNUNET_MessageHeader *) &m[1])->type),
245 (unsigned int) ret, GNUNET_i2s (&n->peer)); 246 (unsigned int) ret, GNUNET_i2s (&n->peer));
246#endif 247#endif
247 GNUNET_free (m); 248 GNUNET_free (m);
248 process_queue (n); 249 process_queue (n);
@@ -271,7 +272,7 @@ process_queue (struct Neighbour *n)
271 if (m == NULL) 272 if (m == NULL)
272 { 273 {
273 /* notify sessions that the queue is empty and more messages 274 /* notify sessions that the queue is empty and more messages
274 could thus be queued now */ 275 * could thus be queued now */
275 GSC_SESSIONS_solicit (&n->peer); 276 GSC_SESSIONS_solicit (&n->peer);
276 return; 277 return;
277 } 278 }
@@ -283,12 +284,10 @@ process_queue (struct Neighbour *n)
283 GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); 284 GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value);
284#endif 285#endif
285 n->th = 286 n->th =
286 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 287 GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, m->size, 0,
287 0, 288 GNUNET_TIME_absolute_get_remaining
288 GNUNET_TIME_absolute_get_remaining 289 (m->deadline), &transmit_ready,
289 (m->deadline), 290 n);
290 &transmit_ready,
291 n);
292 if (n->th != NULL) 291 if (n->th != NULL)
293 return; 292 return;
294 /* message request too large or duplicate request */ 293 /* message request too large or duplicate request */
@@ -313,8 +312,8 @@ process_queue (struct Neighbour *n)
313static void 312static void
314handle_transport_notify_connect (void *cls, 313handle_transport_notify_connect (void *cls,
315 const struct GNUNET_PeerIdentity *peer, 314 const struct GNUNET_PeerIdentity *peer,
316 const struct GNUNET_ATS_Information 315 const struct GNUNET_ATS_Information *atsi,
317 *atsi, uint32_t atsi_count) 316 uint32_t atsi_count)
318{ 317{
319 struct Neighbour *n; 318 struct Neighbour *n;
320 319
@@ -340,7 +339,8 @@ handle_transport_notify_connect (void *cls,
340 GNUNET_CONTAINER_multihashmap_put (neighbours, 339 GNUNET_CONTAINER_multihashmap_put (neighbours,
341 &n->peer.hashPubKey, n, 340 &n->peer.hashPubKey, n,
342 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 341 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
343 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# neighbour entries allocated"), 342 GNUNET_STATISTICS_set (GSC_stats,
343 gettext_noop ("# neighbour entries allocated"),
344 GNUNET_CONTAINER_multihashmap_size (neighbours), 344 GNUNET_CONTAINER_multihashmap_size (neighbours),
345 GNUNET_NO); 345 GNUNET_NO);
346 n->kxinfo = GSC_KX_start (peer); 346 n->kxinfo = GSC_KX_start (peer);
@@ -423,9 +423,7 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
423 GSC_KX_handle_pong (n->kxinfo, message); 423 GSC_KX_handle_pong (n->kxinfo, message);
424 break; 424 break;
425 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: 425 case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
426 GSC_KX_handle_encrypted_message (n->kxinfo, 426 GSC_KX_handle_encrypted_message (n->kxinfo, message, atsi, atsi_count);
427 message, atsi,
428 atsi_count);
429 break; 427 break;
430 default: 428 default:
431 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 429 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -438,15 +436,15 @@ handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
438 436
439/** 437/**
440 * Transmit the given message to the given target. 438 * Transmit the given message to the given target.
441 * 439 *
442 * @param target peer that should receive the message (must be connected) 440 * @param target peer that should receive the message (must be connected)
443 * @param msg message to transmit 441 * @param msg message to transmit
444 * @param timeout by when should the transmission be done? 442 * @param timeout by when should the transmission be done?
445 */ 443 */
446void 444void
447GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, 445GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
448 const struct GNUNET_MessageHeader *msg, 446 const struct GNUNET_MessageHeader *msg,
449 struct GNUNET_TIME_Relative timeout) 447 struct GNUNET_TIME_Relative timeout)
450{ 448{
451 struct NeighbourMessageEntry *me; 449 struct NeighbourMessageEntry *me;
452 struct Neighbour *n; 450 struct Neighbour *n;
@@ -463,9 +461,7 @@ GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
463 me->deadline = GNUNET_TIME_relative_to_absolute (timeout); 461 me->deadline = GNUNET_TIME_relative_to_absolute (timeout);
464 me->size = msize; 462 me->size = msize;
465 memcpy (&me[1], msg, msize); 463 memcpy (&me[1], msg, msize);
466 GNUNET_CONTAINER_DLL_insert_tail (n->message_head, 464 GNUNET_CONTAINER_DLL_insert_tail (n->message_head, n->message_tail, me);
467 n->message_tail,
468 me);
469 process_queue (n); 465 process_queue (n);
470} 466}
471 467
@@ -478,8 +474,7 @@ GSC_NEIGHBOURS_init ()
478{ 474{
479 neighbours = GNUNET_CONTAINER_multihashmap_create (128); 475 neighbours = GNUNET_CONTAINER_multihashmap_create (128);
480 transport = 476 transport =
481 GNUNET_TRANSPORT_connect (GSC_cfg, 477 GNUNET_TRANSPORT_connect (GSC_cfg, &GSC_my_identity, NULL,
482 &GSC_my_identity, NULL,
483 &handle_transport_receive, 478 &handle_transport_receive,
484 &handle_transport_notify_connect, 479 &handle_transport_notify_connect,
485 &handle_transport_notify_disconnect); 480 &handle_transport_notify_disconnect);
@@ -530,4 +525,3 @@ GSC_NEIGHBOURS_done ()
530} 525}
531 526
532/* end of gnunet-service-core_neighbours.c */ 527/* end of gnunet-service-core_neighbours.c */
533
diff --git a/src/core/gnunet-service-core_neighbours.h b/src/core/gnunet-service-core_neighbours.h
index 36682770e..d613c46a5 100644
--- a/src/core/gnunet-service-core_neighbours.h
+++ b/src/core/gnunet-service-core_neighbours.h
@@ -35,15 +35,15 @@
35 * when the message queue is empty). Outbound quotas and memory 35 * when the message queue is empty). Outbound quotas and memory
36 * bounds will then be enfoced (as GSC_SESSION_solicit is only called 36 * bounds will then be enfoced (as GSC_SESSION_solicit is only called
37 * if sufficient banwdith is available). 37 * if sufficient banwdith is available).
38 * 38 *
39 * @param target peer that should receive the message (must be connected) 39 * @param target peer that should receive the message (must be connected)
40 * @param msg message to transmit 40 * @param msg message to transmit
41 * @param timeout by when should the transmission be done? 41 * @param timeout by when should the transmission be done?
42 */ 42 */
43void 43void
44GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target, 44GSC_NEIGHBOURS_transmit (const struct GNUNET_PeerIdentity *target,
45 const struct GNUNET_MessageHeader *msg, 45 const struct GNUNET_MessageHeader *msg,
46 struct GNUNET_TIME_Relative timeout); 46 struct GNUNET_TIME_Relative timeout);
47 47
48 48
49/** 49/**
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index a8f7bf6bf..108fd47cf 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file core/gnunet-service-core_sessions.c 22 * @file core/gnunet-service-core_sessions.c
23 * @brief code for managing of 'encrypted' sessions (key exchange done) 23 * @brief code for managing of 'encrypted' sessions (key exchange done)
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
@@ -133,7 +133,7 @@ struct Session
133 133
134 /** 134 /**
135 * Is the neighbour queue empty and thus ready for us 135 * Is the neighbour queue empty and thus ready for us
136 * to transmit an encrypted message? 136 * to transmit an encrypted message?
137 */ 137 */
138 int ready_to_transmit; 138 int ready_to_transmit;
139 139
@@ -162,7 +162,7 @@ find_session (const struct GNUNET_PeerIdentity *peer)
162 162
163/** 163/**
164 * End the session with the given peer (we are no longer 164 * End the session with the given peer (we are no longer
165 * connected). 165 * connected).
166 * 166 *
167 * @param pid identity of peer to kill session with 167 * @param pid identity of peer to kill session with
168 */ 168 */
@@ -176,8 +176,7 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
176 if (NULL == session) 176 if (NULL == session)
177 return; 177 return;
178#if DEBUG_CORE 178#if DEBUG_CORE
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying session for peer `%4s'\n",
180 "Destroying session for peer `%4s'\n",
181 GNUNET_i2s (&session->peer)); 180 GNUNET_i2s (&session->peer));
182#endif 181#endif
183 if (GNUNET_SCHEDULER_NO_TASK != session->cork_task) 182 if (GNUNET_SCHEDULER_NO_TASK != session->cork_task)
@@ -188,22 +187,21 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
188 while (NULL != (car = session->active_client_request_head)) 187 while (NULL != (car = session->active_client_request_head))
189 { 188 {
190 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 189 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
191 session->active_client_request_tail, 190 session->active_client_request_tail, car);
192 car);
193 GSC_CLIENTS_reject_request (car); 191 GSC_CLIENTS_reject_request (car);
194 } 192 }
195 GNUNET_SCHEDULER_cancel (session->typemap_task); 193 GNUNET_SCHEDULER_cancel (session->typemap_task);
196 GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, 194 GSC_CLIENTS_notify_clients_about_neighbour (&session->peer, NULL,
197 NULL, 0 /* FIXME: ATSI */, 195 0 /* FIXME: ATSI */ ,
198 session->tmap, 196 session->tmap, NULL);
199 NULL);
200 GNUNET_assert (GNUNET_YES == 197 GNUNET_assert (GNUNET_YES ==
201 GNUNET_CONTAINER_multihashmap_remove (sessions, 198 GNUNET_CONTAINER_multihashmap_remove (sessions,
202 &session->peer.hashPubKey, session)); 199 &session->
203 GNUNET_STATISTICS_set (GSC_stats, 200 peer.hashPubKey,
204 gettext_noop ("# entries in session map"), 201 session));
205 GNUNET_CONTAINER_multihashmap_size (sessions), 202 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"),
206 GNUNET_NO); 203 GNUNET_CONTAINER_multihashmap_size (sessions),
204 GNUNET_NO);
207 GSC_TYPEMAP_destroy (session->tmap); 205 GSC_TYPEMAP_destroy (session->tmap);
208 session->tmap = NULL; 206 session->tmap = NULL;
209 GNUNET_free (session); 207 GNUNET_free (session);
@@ -216,10 +214,9 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
216 * 214 *
217 * @param cls the 'struct Session*' 215 * @param cls the 'struct Session*'
218 * @param tc unused 216 * @param tc unused
219 */ 217 */
220static void 218static void
221transmit_typemap_task (void *cls, 219transmit_typemap_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
222 const struct GNUNET_SCHEDULER_TaskContext *tc)
223{ 220{
224 struct Session *session = cls; 221 struct Session *session = cls;
225 struct GNUNET_MessageHeader *hdr; 222 struct GNUNET_MessageHeader *hdr;
@@ -227,19 +224,15 @@ transmit_typemap_task (void *cls,
227 224
228 delay = TYPEMAP_FREQUENCY; 225 delay = TYPEMAP_FREQUENCY;
229 /* randomize a bit to avoid spont. sync */ 226 /* randomize a bit to avoid spont. sync */
230 delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 227 delay.rel_value +=
231 1000); 228 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
232 session->typemap_task = GNUNET_SCHEDULER_add_delayed (delay, 229 session->typemap_task =
233 &transmit_typemap_task, 230 GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session);
234 session); 231 GNUNET_STATISTICS_update (GSC_stats,
235 GNUNET_STATISTICS_update (GSC_stats, 232 gettext_noop ("# type map refreshes sent"), 1,
236 gettext_noop ("# type map refreshes sent"), 233 GNUNET_NO);
237 1,
238 GNUNET_NO);
239 hdr = GSC_TYPEMAP_compute_type_map_message (); 234 hdr = GSC_TYPEMAP_compute_type_map_message ();
240 GSC_KX_encrypt_and_transmit (session->kxinfo, 235 GSC_KX_encrypt_and_transmit (session->kxinfo, hdr, ntohs (hdr->size));
241 hdr,
242 ntohs (hdr->size));
243 GNUNET_free (hdr); 236 GNUNET_free (hdr);
244} 237}
245 238
@@ -252,33 +245,30 @@ transmit_typemap_task (void *cls,
252 */ 245 */
253void 246void
254GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 247GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
255 struct GSC_KeyExchangeInfo *kx) 248 struct GSC_KeyExchangeInfo *kx)
256{ 249{
257 struct Session *session; 250 struct Session *session;
258 251
259#if DEBUG_CORE 252#if DEBUG_CORE
260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating session for peer `%4s'\n",
261 "Creating session for peer `%4s'\n", GNUNET_i2s (peer)); 254 GNUNET_i2s (peer));
262#endif 255#endif
263 session = GNUNET_malloc (sizeof (struct Session)); 256 session = GNUNET_malloc (sizeof (struct Session));
264 session->tmap = GSC_TYPEMAP_create (); 257 session->tmap = GSC_TYPEMAP_create ();
265 session->peer = *peer; 258 session->peer = *peer;
266 session->kxinfo = kx; 259 session->kxinfo = kx;
267 session->time_established = GNUNET_TIME_absolute_get (); 260 session->time_established = GNUNET_TIME_absolute_get ();
268 session->typemap_task = GNUNET_SCHEDULER_add_now (&transmit_typemap_task, 261 session->typemap_task =
269 session); 262 GNUNET_SCHEDULER_add_now (&transmit_typemap_task, session);
270 GNUNET_assert (GNUNET_OK == 263 GNUNET_assert (GNUNET_OK ==
271 GNUNET_CONTAINER_multihashmap_put (sessions, 264 GNUNET_CONTAINER_multihashmap_put (sessions, &peer->hashPubKey,
272 &peer->hashPubKey, session, 265 session,
273 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 266 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
274 GNUNET_STATISTICS_set (GSC_stats, 267 GNUNET_STATISTICS_set (GSC_stats, gettext_noop ("# entries in session map"),
275 gettext_noop ("# entries in session map"), 268 GNUNET_CONTAINER_multihashmap_size (sessions),
276 GNUNET_CONTAINER_multihashmap_size (sessions), 269 GNUNET_NO);
277 GNUNET_NO); 270 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0 /* FIXME: ATSI */ ,
278 GSC_CLIENTS_notify_clients_about_neighbour (peer, 271 NULL, session->tmap);
279 NULL, 0 /* FIXME: ATSI */,
280 NULL,
281 session->tmap);
282} 272}
283 273
284 274
@@ -286,23 +276,20 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
286 * Notify the given client about the session (client is new). 276 * Notify the given client about the session (client is new).
287 * 277 *
288 * @param cls the 'struct GSC_Client' 278 * @param cls the 'struct GSC_Client'
289 * @param key peer identity 279 * @param key peer identity
290 * @param value the 'struct Session' 280 * @param value the 'struct Session'
291 * @return GNUNET_OK (continue to iterate) 281 * @return GNUNET_OK (continue to iterate)
292 */ 282 */
293static int 283static int
294notify_client_about_session (void *cls, 284notify_client_about_session (void *cls, const GNUNET_HashCode * key,
295 const GNUNET_HashCode *key, 285 void *value)
296 void *value)
297{ 286{
298 struct GSC_Client *client = cls; 287 struct GSC_Client *client = cls;
299 struct Session *session = value; 288 struct Session *session = value;
300 289
301 GSC_CLIENTS_notify_client_about_neighbour (client, 290 GSC_CLIENTS_notify_client_about_neighbour (client, &session->peer, NULL, 0, /* FIXME: ATS!? */
302 &session->peer, 291 NULL, /* old TMAP: none */
303 NULL, 0, /* FIXME: ATS!? */ 292 session->tmap);
304 NULL, /* old TMAP: none */
305 session->tmap);
306 return GNUNET_OK; 293 return GNUNET_OK;
307} 294}
308 295
@@ -316,8 +303,8 @@ void
316GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) 303GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
317{ 304{
318 /* notify new client about existing sessions */ 305 /* notify new client about existing sessions */
319 GNUNET_CONTAINER_multihashmap_iterate (sessions, 306 GNUNET_CONTAINER_multihashmap_iterate (sessions, &notify_client_about_session,
320 &notify_client_about_session, client); 307 client);
321} 308}
322 309
323 310
@@ -373,7 +360,7 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car)
373 "Received client transmission request. queueing\n"); 360 "Received client transmission request. queueing\n");
374#endif 361#endif
375 GNUNET_CONTAINER_DLL_insert (session->active_client_request_head, 362 GNUNET_CONTAINER_DLL_insert (session->active_client_request_head,
376 session->active_client_request_tail, car); 363 session->active_client_request_tail, car);
377 try_transmission (session); 364 try_transmission (session);
378} 365}
379 366
@@ -389,11 +376,11 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car)
389{ 376{
390 struct Session *s; 377 struct Session *s;
391 378
392 if (0 == memcmp (&car->target, 379 if (0 ==
393 &GSC_my_identity, 380 memcmp (&car->target, &GSC_my_identity,
394 sizeof (struct GNUNET_PeerIdentity))) 381 sizeof (struct GNUNET_PeerIdentity)))
395 return; 382 return;
396 s = find_session (&car->target); 383 s = find_session (&car->target);
397 GNUNET_assert (NULL != s); 384 GNUNET_assert (NULL != s);
398 GNUNET_CONTAINER_DLL_remove (s->active_client_request_head, 385 GNUNET_CONTAINER_DLL_remove (s->active_client_request_head,
399 s->active_client_request_tail, car); 386 s->active_client_request_tail, car);
@@ -411,7 +398,7 @@ discard_expired_requests (struct Session *session)
411 struct GSC_ClientActiveRequest *pos; 398 struct GSC_ClientActiveRequest *pos;
412 struct GSC_ClientActiveRequest *nxt; 399 struct GSC_ClientActiveRequest *nxt;
413 struct GNUNET_TIME_Absolute now; 400 struct GNUNET_TIME_Absolute now;
414 401
415 now = GNUNET_TIME_absolute_get (); 402 now = GNUNET_TIME_absolute_get ();
416 pos = NULL; 403 pos = NULL;
417 nxt = session->active_client_request_head; 404 nxt = session->active_client_request_head;
@@ -419,16 +406,15 @@ discard_expired_requests (struct Session *session)
419 { 406 {
420 pos = nxt; 407 pos = nxt;
421 nxt = pos->next; 408 nxt = pos->next;
422 if ( (pos->deadline.abs_value < now.abs_value) && 409 if ((pos->deadline.abs_value < now.abs_value) &&
423 (GNUNET_YES != pos->was_solicited) ) 410 (GNUNET_YES != pos->was_solicited))
424 { 411 {
425 GNUNET_STATISTICS_update (GSC_stats, 412 GNUNET_STATISTICS_update (GSC_stats,
426 gettext_noop 413 gettext_noop
427 ("# messages discarded (expired prior to transmission)"), 414 ("# messages discarded (expired prior to transmission)"),
428 1, GNUNET_NO); 415 1, GNUNET_NO);
429 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 416 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head,
430 session->active_client_request_tail, 417 session->active_client_request_tail, pos);
431 pos);
432 GSC_CLIENTS_reject_request (pos); 418 GSC_CLIENTS_reject_request (pos);
433 } 419 }
434 } 420 }
@@ -446,7 +432,7 @@ solicit_messages (struct Session *session)
446 struct GSC_ClientActiveRequest *car; 432 struct GSC_ClientActiveRequest *car;
447 size_t so_size; 433 size_t so_size;
448 434
449 discard_expired_requests (session); 435 discard_expired_requests (session);
450 so_size = 0; 436 so_size = 0;
451 for (car = session->active_client_request_head; NULL != car; car = car->next) 437 for (car = session->active_client_request_head; NULL != car; car = car->next)
452 { 438 {
@@ -462,15 +448,14 @@ solicit_messages (struct Session *session)
462 448
463 449
464/** 450/**
465 * Some messages were delayed (corked), but the timeout has now expired. 451 * Some messages were delayed (corked), but the timeout has now expired.
466 * Send them now. 452 * Send them now.
467 * 453 *
468 * @param cls 'struct Session' with the messages to transmit now 454 * @param cls 'struct Session' with the messages to transmit now
469 * @param tc scheduler context (unused) 455 * @param tc scheduler context (unused)
470 */ 456 */
471static void 457static void
472pop_cork_task (void *cls, 458pop_cork_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
473 const struct GNUNET_SCHEDULER_TaskContext *tc)
474{ 459{
475 struct Session *session = cls; 460 struct Session *session = cls;
476 461
@@ -499,31 +484,31 @@ try_transmission (struct Session *session)
499 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS; 484 min_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
500 /* check 'ready' messages */ 485 /* check 'ready' messages */
501 pos = session->sme_head; 486 pos = session->sme_head;
502 while ( (NULL != pos) && 487 while ((NULL != pos) &&
503 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) ) 488 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE))
504 { 489 {
505 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 490 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
506 msize += pos->size; 491 msize += pos->size;
507 min_deadline = GNUNET_TIME_absolute_min (min_deadline, 492 min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline);
508 pos->deadline);
509 pos = pos->next; 493 pos = pos->next;
510 } 494 }
511 now = GNUNET_TIME_absolute_get (); 495 now = GNUNET_TIME_absolute_get ();
512 if ( (msize == 0) || 496 if ((msize == 0) ||
513 ( (msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && 497 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
514 (min_deadline.abs_value > now.abs_value) ) ) 498 (min_deadline.abs_value > now.abs_value)))
515 { 499 {
516 /* not enough ready yet, try to solicit more */ 500 /* not enough ready yet, try to solicit more */
517 solicit_messages (session); 501 solicit_messages (session);
518 if (msize > 0) 502 if (msize > 0)
519 { 503 {
520 /* if there is data to send, just not yet, make sure we do transmit 504 /* if there is data to send, just not yet, make sure we do transmit
521 it once the deadline is reached */ 505 * it once the deadline is reached */
522 if (session->cork_task != GNUNET_SCHEDULER_NO_TASK) 506 if (session->cork_task != GNUNET_SCHEDULER_NO_TASK)
523 GNUNET_SCHEDULER_cancel (session->cork_task); 507 GNUNET_SCHEDULER_cancel (session->cork_task);
524 session->cork_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (min_deadline), 508 session->cork_task =
525 &pop_cork_task, 509 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
526 session); 510 (min_deadline), &pop_cork_task,
511 session);
527 } 512 }
528 return; 513 return;
529 } 514 }
@@ -531,18 +516,15 @@ try_transmission (struct Session *session)
531 { 516 {
532 static unsigned long long total_bytes; 517 static unsigned long long total_bytes;
533 static unsigned int total_msgs; 518 static unsigned int total_msgs;
534 char pbuf[msize]; /* plaintext */ 519 char pbuf[msize]; /* plaintext */
535 size_t used; 520 size_t used;
536 521
537 used = 0; 522 used = 0;
538 while ( (NULL != (pos = session->sme_head)) && 523 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
539 (used + pos->size <= msize) )
540 { 524 {
541 memcpy (&pbuf[used], &pos[1], pos->size); 525 memcpy (&pbuf[used], &pos[1], pos->size);
542 used += pos->size; 526 used += pos->size;
543 GNUNET_CONTAINER_DLL_remove (session->sme_head, 527 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos);
544 session->sme_tail,
545 pos);
546 GNUNET_free (pos); 528 GNUNET_free (pos);
547 } 529 }
548 /* compute average payload size */ 530 /* compute average payload size */
@@ -554,15 +536,11 @@ try_transmission (struct Session *session)
554 total_msgs = 1; 536 total_msgs = 1;
555 total_bytes = used; 537 total_bytes = used;
556 } 538 }
557 GNUNET_STATISTICS_set (GSC_stats, 539 GNUNET_STATISTICS_set (GSC_stats, "# avg payload per encrypted message",
558 "# avg payload per encrypted message", 540 total_bytes / total_msgs, GNUNET_NO);
559 total_bytes / total_msgs,
560 GNUNET_NO);
561 /* now actually transmit... */ 541 /* now actually transmit... */
562 session->ready_to_transmit = GNUNET_NO; 542 session->ready_to_transmit = GNUNET_NO;
563 GSC_KX_encrypt_and_transmit (session->kxinfo, 543 GSC_KX_encrypt_and_transmit (session->kxinfo, pbuf, used);
564 pbuf,
565 used);
566 } 544 }
567} 545}
568 546
@@ -587,9 +565,7 @@ do_send_message (void *cls, const GNUNET_HashCode * key, void *value)
587 m = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size); 565 m = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
588 memcpy (&m[1], hdr, size); 566 memcpy (&m[1], hdr, size);
589 m->size = size; 567 m->size = size;
590 GNUNET_CONTAINER_DLL_insert (session->sme_head, 568 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, m);
591 session->sme_tail,
592 m);
593 try_transmission (session); 569 try_transmission (session);
594 return GNUNET_OK; 570 return GNUNET_OK;
595} 571}
@@ -605,8 +581,8 @@ GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg)
605{ 581{
606 if (NULL == sessions) 582 if (NULL == sessions)
607 return; 583 return;
608 GNUNET_CONTAINER_multihashmap_iterate (sessions, 584 GNUNET_CONTAINER_multihashmap_iterate (sessions, &do_send_message,
609 &do_send_message, (void*) msg); 585 (void *) msg);
610} 586}
611 587
612 588
@@ -640,8 +616,7 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
640 */ 616 */
641void 617void
642GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 618GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
643 const struct GNUNET_MessageHeader *msg, 619 const struct GNUNET_MessageHeader *msg, int cork)
644 int cork)
645{ 620{
646 struct Session *session; 621 struct Session *session;
647 struct SessionMessageEntry *sme; 622 struct SessionMessageEntry *sme;
@@ -655,10 +630,9 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
655 memcpy (&sme[1], msg, msize); 630 memcpy (&sme[1], msg, msize);
656 sme->size = msize; 631 sme->size = msize;
657 if (GNUNET_YES == cork) 632 if (GNUNET_YES == cork)
658 sme->deadline = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); 633 sme->deadline =
659 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, 634 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY);
660 session->sme_tail, 635 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, session->sme_tail, sme);
661 sme);
662 try_transmission (session); 636 try_transmission (session);
663} 637}
664 638
@@ -678,7 +652,7 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
678 struct GNUNET_SERVER_TransmitContext *tc = cls; 652 struct GNUNET_SERVER_TransmitContext *tc = cls;
679 struct Session *session = value; 653 struct Session *session = value;
680 struct ConnectNotifyMessage cnm; 654 struct ConnectNotifyMessage cnm;
681 655
682 /* FIXME: code duplication with clients... */ 656 /* FIXME: code duplication with clients... */
683 cnm.header.size = htons (sizeof (struct ConnectNotifyMessage)); 657 cnm.header.size = htons (sizeof (struct ConnectNotifyMessage));
684 cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 658 cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
@@ -693,23 +667,23 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
693/** 667/**
694 * Handle CORE_ITERATE_PEERS request. For this request type, the client 668 * Handle CORE_ITERATE_PEERS request. For this request type, the client
695 * does not have to have transmitted an INIT request. All current peers 669 * does not have to have transmitted an INIT request. All current peers
696 * are returned, regardless of which message types they accept. 670 * are returned, regardless of which message types they accept.
697 * 671 *
698 * @param cls unused 672 * @param cls unused
699 * @param client client sending the iteration request 673 * @param client client sending the iteration request
700 * @param message iteration request message 674 * @param message iteration request message
701 */ 675 */
702void 676void
703GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client, 677GSC_SESSIONS_handle_client_iterate_peers (void *cls,
704 const struct GNUNET_MessageHeader *message) 678 struct GNUNET_SERVER_Client *client,
679 const struct GNUNET_MessageHeader
680 *message)
705{ 681{
706 struct GNUNET_MessageHeader done_msg; 682 struct GNUNET_MessageHeader done_msg;
707 struct GNUNET_SERVER_TransmitContext *tc; 683 struct GNUNET_SERVER_TransmitContext *tc;
708 684
709 tc = GNUNET_SERVER_transmit_context_create (client); 685 tc = GNUNET_SERVER_transmit_context_create (client);
710 GNUNET_CONTAINER_multihashmap_iterate (sessions, 686 GNUNET_CONTAINER_multihashmap_iterate (sessions, &queue_connect_message, tc);
711 &queue_connect_message,
712 tc);
713 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 687 done_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
714 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); 688 done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END);
715 GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); 689 GNUNET_SERVER_transmit_context_append_message (tc, &done_msg);
@@ -728,14 +702,16 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client
728 * @param message iteration request message 702 * @param message iteration request message
729 */ 703 */
730void 704void
731GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client, 705GSC_SESSIONS_handle_client_have_peer (void *cls,
732 const struct GNUNET_MessageHeader *message) 706 struct GNUNET_SERVER_Client *client,
707 const struct GNUNET_MessageHeader
708 *message)
733{ 709{
734 struct GNUNET_MessageHeader done_msg; 710 struct GNUNET_MessageHeader done_msg;
735 struct GNUNET_SERVER_TransmitContext *tc; 711 struct GNUNET_SERVER_TransmitContext *tc;
736 const struct GNUNET_PeerIdentity *peer; 712 const struct GNUNET_PeerIdentity *peer;
737 713
738 peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK! 714 peer = (const struct GNUNET_PeerIdentity *) &message[1]; // YUCK!
739 tc = GNUNET_SERVER_transmit_context_create (client); 715 tc = GNUNET_SERVER_transmit_context_create (client);
740 GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey, 716 GNUNET_CONTAINER_multihashmap_get_multiple (sessions, &peer->hashPubKey,
741 &queue_connect_message, tc); 717 &queue_connect_message, tc);
@@ -755,24 +731,22 @@ GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *cl
755 */ 731 */
756void 732void
757GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 733GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
758 const struct GNUNET_MessageHeader *msg) 734 const struct GNUNET_MessageHeader *msg)
759{ 735{
760 struct Session *session; 736 struct Session *session;
761 struct GSC_TypeMap *nmap; 737 struct GSC_TypeMap *nmap;
762 738
763 nmap = GSC_TYPEMAP_get_from_message (msg); 739 nmap = GSC_TYPEMAP_get_from_message (msg);
764 if (NULL == nmap) 740 if (NULL == nmap)
765 return; /* malformed */ 741 return; /* malformed */
766 session = find_session (peer); 742 session = find_session (peer);
767 if (NULL == session) 743 if (NULL == session)
768 { 744 {
769 GNUNET_break (0); 745 GNUNET_break (0);
770 return; 746 return;
771 } 747 }
772 GSC_CLIENTS_notify_clients_about_neighbour (peer, 748 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */
773 NULL, 0, /* FIXME: ATS */ 749 session->tmap, nmap);
774 session->tmap,
775 nmap);
776 GSC_TYPEMAP_destroy (session->tmap); 750 GSC_TYPEMAP_destroy (session->tmap);
777 session->tmap = nmap; 751 session->tmap = nmap;
778} 752}
@@ -788,7 +762,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
788 */ 762 */
789void 763void
790GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 764GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
791 uint16_t type) 765 uint16_t type)
792{ 766{
793 struct Session *session; 767 struct Session *session;
794 struct GSC_TypeMap *nmap; 768 struct GSC_TypeMap *nmap;
@@ -797,16 +771,11 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
797 return; 771 return;
798 session = find_session (peer); 772 session = find_session (peer);
799 GNUNET_assert (NULL != session); 773 GNUNET_assert (NULL != session);
800 if (GNUNET_YES == 774 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1))
801 GSC_TYPEMAP_test_match (session->tmap, 775 return; /* already in it */
802 &type, 1)) 776 nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1);
803 return; /* already in it */ 777 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, 0, /* FIXME: ATS */
804 nmap = GSC_TYPEMAP_extend (session->tmap, 778 session->tmap, nmap);
805 &type, 1);
806 GSC_CLIENTS_notify_clients_about_neighbour (peer,
807 NULL, 0, /* FIXME: ATS */
808 session->tmap,
809 nmap);
810 GSC_TYPEMAP_destroy (session->tmap); 779 GSC_TYPEMAP_destroy (session->tmap);
811 session->tmap = nmap; 780 session->tmap = nmap;
812} 781}
@@ -846,12 +815,9 @@ free_session_helper (void *cls, const GNUNET_HashCode * key, void *value)
846void 815void
847GSC_SESSIONS_done () 816GSC_SESSIONS_done ()
848{ 817{
849 GNUNET_CONTAINER_multihashmap_iterate (sessions, 818 GNUNET_CONTAINER_multihashmap_iterate (sessions, &free_session_helper, NULL);
850 &free_session_helper,
851 NULL);
852 GNUNET_CONTAINER_multihashmap_destroy (sessions); 819 GNUNET_CONTAINER_multihashmap_destroy (sessions);
853 sessions = NULL; 820 sessions = NULL;
854} 821}
855 822
856/* end of gnunet-service-core_sessions.c */ 823/* end of gnunet-service-core_sessions.c */
857
diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h
index b70bd59fd..e09cf500e 100644
--- a/src/core/gnunet-service-core_sessions.h
+++ b/src/core/gnunet-service-core_sessions.h
@@ -20,7 +20,7 @@
20 20
21/** 21/**
22 * @file core/gnunet-service-core_neighbours.h 22 * @file core/gnunet-service-core_neighbours.h
23 * @brief code for managing of 'encrypted' sessions (key exchange done) 23 * @brief code for managing of 'encrypted' sessions (key exchange done)
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#ifndef GNUNET_SERVICE_CORE_SESSIONS_H 26#ifndef GNUNET_SERVICE_CORE_SESSIONS_H
@@ -38,12 +38,12 @@
38 */ 38 */
39void 39void
40GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 40GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
41 struct GSC_KeyExchangeInfo *kx); 41 struct GSC_KeyExchangeInfo *kx);
42 42
43 43
44/** 44/**
45 * End the session with the given peer (we are no longer 45 * End the session with the given peer (we are no longer
46 * connected). 46 * connected).
47 * 47 *
48 * @param pid identity of peer to kill session with 48 * @param pid identity of peer to kill session with
49 */ 49 */
@@ -95,8 +95,7 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
95 */ 95 */
96void 96void
97GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 97GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
98 const struct GNUNET_MessageHeader *msg, 98 const struct GNUNET_MessageHeader *msg, int cork);
99 int cork);
100 99
101 100
102/** 101/**
@@ -125,7 +124,7 @@ GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client);
125 */ 124 */
126void 125void
127GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 126GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
128 const struct GNUNET_MessageHeader *msg); 127 const struct GNUNET_MessageHeader *msg);
129 128
130 129
131/** 130/**
@@ -138,7 +137,7 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
138 */ 137 */
139void 138void
140GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 139GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
141 uint16_t type); 140 uint16_t type);
142 141
143 142
144/** 143/**
@@ -151,8 +150,10 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
151 * @param message iteration request message 150 * @param message iteration request message
152 */ 151 */
153void 152void
154GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client *client, 153GSC_SESSIONS_handle_client_iterate_peers (void *cls,
155 const struct GNUNET_MessageHeader *message); 154 struct GNUNET_SERVER_Client *client,
155 const struct GNUNET_MessageHeader
156 *message);
156 157
157 158
158/** 159/**
@@ -166,8 +167,10 @@ GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct GNUNET_SERVER_Client
166 * @param message iteration request message 167 * @param message iteration request message
167 */ 168 */
168void 169void
169GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client *client, 170GSC_SESSIONS_handle_client_have_peer (void *cls,
170 const struct GNUNET_MessageHeader *message); 171 struct GNUNET_SERVER_Client *client,
172 const struct GNUNET_MessageHeader
173 *message);
171 174
172 175
173 176
diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c
index c54e446c6..d3214ea67 100644
--- a/src/core/gnunet-service-core_typemap.c
+++ b/src/core/gnunet-service-core_typemap.c
@@ -36,7 +36,7 @@
36 * A type map describing which messages a given neighbour is able 36 * A type map describing which messages a given neighbour is able
37 * to process. 37 * to process.
38 */ 38 */
39struct GSC_TypeMap 39struct GSC_TypeMap
40{ 40{
41 uint32_t bits[(UINT16_MAX + 1) / 32]; 41 uint32_t bits[(UINT16_MAX + 1) / 32];
42}; 42};
@@ -107,10 +107,8 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
107 switch (ntohs (msg->type)) 107 switch (ntohs (msg->type))
108 { 108 {
109 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: 109 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
110 GNUNET_STATISTICS_update (GSC_stats, 110 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
111 gettext_noop ("# type maps received"), 111 1, GNUNET_NO);
112 1,
113 GNUNET_NO);
114 if (size != sizeof (struct GSC_TypeMap)) 112 if (size != sizeof (struct GSC_TypeMap))
115 { 113 {
116 GNUNET_break_op (0); 114 GNUNET_break_op (0);
@@ -120,16 +118,13 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
120 memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap)); 118 memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
121 return ret; 119 return ret;
122 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: 120 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
123 GNUNET_STATISTICS_update (GSC_stats, 121 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# type maps received"),
124 gettext_noop ("# type maps received"), 122 1, GNUNET_NO);
125 1,
126 GNUNET_NO);
127 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); 123 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
128 dlen = sizeof (struct GSC_TypeMap); 124 dlen = sizeof (struct GSC_TypeMap);
129 if ( (Z_OK != 125 if ((Z_OK !=
130 uncompress ((Bytef*) ret, &dlen, 126 uncompress ((Bytef *) ret, &dlen, (const Bytef *) &msg[1],
131 (const Bytef*) &msg[1], (uLong) size)) || 127 (uLong) size)) || (dlen != sizeof (struct GSC_TypeMap)))
132 (dlen != sizeof (struct GSC_TypeMap) ) )
133 { 128 {
134 GNUNET_break_op (0); 129 GNUNET_break_op (0);
135 GNUNET_free (ret); 130 GNUNET_free (ret);
@@ -152,10 +147,9 @@ broadcast_my_type_map ()
152 struct GNUNET_MessageHeader *hdr; 147 struct GNUNET_MessageHeader *hdr;
153 148
154 hdr = GSC_TYPEMAP_compute_type_map_message (); 149 hdr = GSC_TYPEMAP_compute_type_map_message ();
155 GNUNET_STATISTICS_update (GSC_stats, 150 GNUNET_STATISTICS_update (GSC_stats,
156 gettext_noop ("# updates to my type map"), 151 gettext_noop ("# updates to my type map"), 1,
157 1, 152 GNUNET_NO);
158 GNUNET_NO);
159 GSC_SESSIONS_broadcast (hdr); 153 GSC_SESSIONS_broadcast (hdr);
160 GNUNET_free (hdr); 154 GNUNET_free (hdr);
161} 155}
@@ -165,14 +159,13 @@ broadcast_my_type_map ()
165 * Add a set of types to our type map. 159 * Add a set of types to our type map.
166 */ 160 */
167void 161void
168GSC_TYPEMAP_add (const uint16_t *types, 162GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen)
169 unsigned int tlen)
170{ 163{
171 unsigned int i; 164 unsigned int i;
172 int changed; 165 int changed;
173 166
174 changed = GNUNET_NO; 167 changed = GNUNET_NO;
175 for (i=0;i<tlen;i++) 168 for (i = 0; i < tlen; i++)
176 { 169 {
177 if (0 == map_counters[types[i]]++) 170 if (0 == map_counters[types[i]]++)
178 { 171 {
@@ -189,14 +182,13 @@ GSC_TYPEMAP_add (const uint16_t *types,
189 * Remove a set of types from our type map. 182 * Remove a set of types from our type map.
190 */ 183 */
191void 184void
192GSC_TYPEMAP_remove (const uint16_t *types, 185GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen)
193 unsigned int tlen)
194{ 186{
195 unsigned int i; 187 unsigned int i;
196 int changed; 188 int changed;
197 189
198 changed = GNUNET_NO; 190 changed = GNUNET_NO;
199 for (i=0;i<tlen;i++) 191 for (i = 0; i < tlen; i++)
200 { 192 {
201 if (0 == --map_counters[types[i]]) 193 if (0 == --map_counters[types[i]])
202 { 194 {
@@ -217,19 +209,18 @@ GSC_TYPEMAP_remove (const uint16_t *types,
217 * @param types array of types 209 * @param types array of types
218 * @param tcnt number of entries in types 210 * @param tcnt number of entries in types
219 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not 211 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
220 */ 212 */
221int 213int
222GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 214GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
223 const uint16_t *types, 215 unsigned int tcnt)
224 unsigned int tcnt) 216{
225{
226 unsigned int i; 217 unsigned int i;
227 218
228 if (NULL == tmap) 219 if (NULL == tmap)
229 return GNUNET_NO; 220 return GNUNET_NO;
230 if (0 == tcnt) 221 if (0 == tcnt)
231 return GNUNET_YES; /* matches all */ 222 return GNUNET_YES; /* matches all */
232 for (i=0;i<tcnt;i++) 223 for (i = 0; i < tcnt; i++)
233 if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32)))) 224 if (0 != (tmap->bits[types[i] / 32] & (1 << (types[i] % 32))))
234 return GNUNET_YES; 225 return GNUNET_YES;
235 return GNUNET_NO; 226 return GNUNET_NO;
@@ -243,11 +234,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
243 * @param types array of types to add 234 * @param types array of types to add
244 * @param tcnt number of entries in types 235 * @param tcnt number of entries in types
245 * @return updated type map (fresh copy) 236 * @return updated type map (fresh copy)
246 */ 237 */
247struct GSC_TypeMap * 238struct GSC_TypeMap *
248GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 239GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
249 const uint16_t *types, 240 unsigned int tcnt)
250 unsigned int tcnt)
251{ 241{
252 struct GSC_TypeMap *ret; 242 struct GSC_TypeMap *ret;
253 unsigned int i; 243 unsigned int i;
@@ -255,7 +245,7 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
255 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap)); 245 ret = GNUNET_malloc (sizeof (struct GSC_TypeMap));
256 if (NULL != tmap) 246 if (NULL != tmap)
257 memcpy (ret, tmap, sizeof (struct GSC_TypeMap)); 247 memcpy (ret, tmap, sizeof (struct GSC_TypeMap));
258 for (i=0;i<tcnt;i++) 248 for (i = 0; i < tcnt; i++)
259 ret->bits[types[i] / 32] |= (1 << (types[i] % 32)); 249 ret->bits[types[i] / 32] |= (1 << (types[i] % 32));
260 return ret; 250 return ret;
261} 251}
diff --git a/src/core/gnunet-service-core_typemap.h b/src/core/gnunet-service-core_typemap.h
index d589c0b1c..ab106a161 100644
--- a/src/core/gnunet-service-core_typemap.h
+++ b/src/core/gnunet-service-core_typemap.h
@@ -39,16 +39,14 @@ struct GSC_TypeMap;
39 * Add a set of types to our type map. 39 * Add a set of types to our type map.
40 */ 40 */
41void 41void
42GSC_TYPEMAP_add (const uint16_t *types, 42GSC_TYPEMAP_add (const uint16_t * types, unsigned int tlen);
43 unsigned int tlen);
44 43
45 44
46/** 45/**
47 * Remove a set of types from our type map. 46 * Remove a set of types from our type map.
48 */ 47 */
49void 48void
50GSC_TYPEMAP_remove (const uint16_t *types, 49GSC_TYPEMAP_remove (const uint16_t * types, unsigned int tlen);
51 unsigned int tlen);
52 50
53 51
54/** 52/**
@@ -78,11 +76,10 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg);
78 * @param types array of types 76 * @param types array of types
79 * @param tcnt number of entries in types 77 * @param tcnt number of entries in types
80 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not 78 * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
81 */ 79 */
82int 80int
83GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 81GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, const uint16_t * types,
84 const uint16_t *types, 82 unsigned int tcnt);
85 unsigned int tcnt);
86 83
87 84
88/** 85/**
@@ -92,11 +89,10 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
92 * @param types array of types to add 89 * @param types array of types to add
93 * @param tcnt number of entries in types 90 * @param tcnt number of entries in types
94 * @return updated type map (fresh copy) 91 * @return updated type map (fresh copy)
95 */ 92 */
96struct GSC_TypeMap * 93struct GSC_TypeMap *
97GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 94GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, const uint16_t * types,
98 const uint16_t *types, 95 unsigned int tcnt);
99 unsigned int tcnt);
100 96
101/** 97/**
102 * Create an empty type map. 98 * Create an empty type map.
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index be3edf974..e63fc9f9d 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -76,7 +76,7 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 "Received (my) `%s' from transport service\n", "HELLO"); 77 "Received (my) `%s' from transport service\n", "HELLO");
78 GNUNET_assert (message != NULL); 78 GNUNET_assert (message != NULL);
79 if ((p == &p1) && (p2.th != NULL)) 79 if ((p == &p1) && (p2.th != NULL))
80 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); 80 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
81 if ((p == &p2) && (p1.th != NULL)) 81 if ((p == &p2) && (p1.th != NULL))
82 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); 82 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
@@ -165,7 +165,8 @@ transmit_ready (void *cls, size_t size, void *buf)
165 165
166static void 166static void
167connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 167connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
168 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 168 const struct GNUNET_ATS_Information *atsi,
169 unsigned int atsi_count)
169{ 170{
170 struct PeerContext *pc = cls; 171 struct PeerContext *pc = cls;
171 172
@@ -218,7 +219,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
218static int 219static int
219inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 220inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
220 const struct GNUNET_MessageHeader *message, 221 const struct GNUNET_MessageHeader *message,
221 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 222 const struct GNUNET_ATS_Information *atsi,
223 unsigned int atsi_count)
222{ 224{
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other)); 226 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
@@ -229,7 +231,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
229static int 231static int
230outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 232outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
231 const struct GNUNET_MessageHeader *message, 233 const struct GNUNET_MessageHeader *message,
232 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 234 const struct GNUNET_ATS_Information *atsi,
235 unsigned int atsi_count)
233{ 236{
234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
235 "Core notifies about outbound data for `%4s'.\n", 238 "Core notifies about outbound data for `%4s'.\n",
@@ -242,7 +245,8 @@ outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
242static int 245static int
243process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 246process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
244 const struct GNUNET_MessageHeader *message, 247 const struct GNUNET_MessageHeader *message,
245 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 248 const struct GNUNET_ATS_Information *atsi,
249 unsigned int atsi_count)
246{ 250{
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n", 251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message from `%4s'.\n",
248 GNUNET_i2s (peer)); 252 GNUNET_i2s (peer));
@@ -296,9 +300,8 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
296 /* connect p2 */ 300 /* connect p2 */
297 p2.ch = 301 p2.ch =
298 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, 302 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
299 &disconnect_notify, &inbound_notify, 303 &disconnect_notify, &inbound_notify, GNUNET_YES,
300 GNUNET_YES, &outbound_notify, GNUNET_YES, 304 &outbound_notify, GNUNET_YES, handlers);
301 handlers);
302 } 305 }
303 else 306 else
304 { 307 {
@@ -344,8 +347,8 @@ run (void *cls, char *const *args, const char *cfgfile,
344 &terminate_task_error, NULL); 347 &terminate_task_error, NULL);
345 p1.ch = 348 p1.ch =
346 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, 349 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
347 &disconnect_notify, &inbound_notify, 350 &disconnect_notify, &inbound_notify, GNUNET_YES,
348 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); 351 &outbound_notify, GNUNET_YES, handlers);
349} 352}
350 353
351 354
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 6a764c126..b2079ba35 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -156,7 +156,7 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 GNUNET_CORE_disconnect (p2.ch); 156 GNUNET_CORE_disconnect (p2.ch);
157 p2.ch = NULL; 157 p2.ch = NULL;
158 } 158 }
159 if (connect_task != GNUNET_SCHEDULER_NO_TASK) 159 if (connect_task != GNUNET_SCHEDULER_NO_TASK)
160 GNUNET_SCHEDULER_cancel (connect_task); 160 GNUNET_SCHEDULER_cancel (connect_task);
161 if (p1.th != NULL) 161 if (p1.th != NULL)
162 { 162 {
@@ -177,8 +177,9 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
177static void 177static void
178try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 178try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
179{ 179{
180 connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 180 connect_task =
181 &try_connect, NULL); 181 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
182 NULL);
182 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 183 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
183} 184}
184 185
@@ -239,7 +240,8 @@ transmit_ready (void *cls, size_t size, void *buf)
239 240
240static void 241static void
241connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 242connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
242 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 243 const struct GNUNET_ATS_Information *atsi,
244 unsigned int atsi_count)
243{ 245{
244 struct PeerContext *pc = cls; 246 struct PeerContext *pc = cls;
245 247
@@ -284,7 +286,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
284static int 286static int
285inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 287inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
286 const struct GNUNET_MessageHeader *message, 288 const struct GNUNET_MessageHeader *message,
287 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 289 const struct GNUNET_ATS_Information *atsi,
290 unsigned int atsi_count)
288{ 291{
289#if VERBOSE 292#if VERBOSE
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -297,7 +300,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
297static int 300static int
298outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 301outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
299 const struct GNUNET_MessageHeader *message, 302 const struct GNUNET_MessageHeader *message,
300 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 303 const struct GNUNET_ATS_Information *atsi,
304 unsigned int atsi_count)
301{ 305{
302#if VERBOSE 306#if VERBOSE
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -314,7 +318,8 @@ transmit_ready (void *cls, size_t size, void *buf);
314static int 318static int
315process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 319process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
316 const struct GNUNET_MessageHeader *message, 320 const struct GNUNET_MessageHeader *message,
317 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 321 const struct GNUNET_ATS_Information *atsi,
322 unsigned int atsi_count)
318{ 323{
319 static int n; 324 static int n;
320 unsigned int s; 325 unsigned int s;
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index cf9608ede..29b1f75f3 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -182,8 +182,8 @@ run (void *cls, char *const *args, const char *cfgfile,
182 "test_core_api_peer1.conf")); 182 "test_core_api_peer1.conf"));
183 183
184 core = 184 core =
185 GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, 185 GNUNET_CORE_connect (core_cfg, 42, NULL, &init, &connect_cb, NULL, NULL,
186 NULL, 0, NULL, 0, handlers); 186 0, NULL, 0, handlers);
187 187
188 die_task = 188 die_task =
189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index f27866c19..b06b97899 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -68,7 +68,7 @@ static int ok;
68static void 68static void
69connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 69connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
70 const struct GNUNET_ATS_Information *atsi, 70 const struct GNUNET_ATS_Information *atsi,
71 unsigned int atsi_count) 71 unsigned int atsi_count)
72{ 72{
73} 73}
74 74
@@ -83,7 +83,7 @@ static int
83inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 83inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
84 const struct GNUNET_MessageHeader *message, 84 const struct GNUNET_MessageHeader *message,
85 const struct GNUNET_ATS_Information *atsi, 85 const struct GNUNET_ATS_Information *atsi,
86 unsigned int atsi_count) 86 unsigned int atsi_count)
87{ 87{
88 return GNUNET_OK; 88 return GNUNET_OK;
89} 89}
@@ -93,7 +93,7 @@ static int
93outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 93outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
94 const struct GNUNET_MessageHeader *message, 94 const struct GNUNET_MessageHeader *message,
95 const struct GNUNET_ATS_Information *atsi, 95 const struct GNUNET_ATS_Information *atsi,
96 unsigned int atsi_count) 96 unsigned int atsi_count)
97{ 97{
98 return GNUNET_OK; 98 return GNUNET_OK;
99} 99}
@@ -130,9 +130,8 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
130 /* connect p2 */ 130 /* connect p2 */
131 p2.ch = 131 p2.ch =
132 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, 132 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
133 &disconnect_notify, &inbound_notify, 133 &disconnect_notify, &inbound_notify, GNUNET_YES,
134 GNUNET_YES, &outbound_notify, GNUNET_YES, 134 &outbound_notify, GNUNET_YES, handlers);
135 handlers);
136 } 135 }
137 else 136 else
138 { 137 {
@@ -193,8 +192,8 @@ run (void *cls, char *const *args, const char *cfgfile,
193 &timeout_task, NULL); 192 &timeout_task, NULL);
194 p1.ch = 193 p1.ch =
195 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, 194 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
196 &disconnect_notify, &inbound_notify, 195 &disconnect_notify, &inbound_notify, GNUNET_YES,
197 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); 196 &outbound_notify, GNUNET_YES, handlers);
198} 197}
199 198
200 199
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index be875c235..856ed13fd 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -185,8 +185,9 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
185static void 185static void
186try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 186try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
187{ 187{
188 connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 188 connect_task =
189 &try_connect, NULL); 189 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
190 NULL);
190 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 191 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
191 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 192 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
192} 193}
@@ -231,13 +232,11 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
231 232
232 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 233 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
233 234
234 throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */ 235 throughput_out = total_bytes_sent * 1000 / delta; /* convert to bytes/s */
235 throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */ 236 throughput_in = total_bytes_recv * 1000 / delta; /* convert to bytes/s */
236 237
237 max_quota_in = GNUNET_MIN (current_quota_p1_in, 238 max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in);
238 current_quota_p2_in); 239 max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out);
239 max_quota_out = GNUNET_MIN (current_quota_p1_out,
240 current_quota_p2_out);
241 if (max_quota_out < max_quota_in) 240 if (max_quota_out < max_quota_in)
242 quota_delta = max_quota_in / 5; 241 quota_delta = max_quota_in / 5;
243 else 242 else
@@ -274,7 +273,7 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
274 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2); 273 GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
275 274
276 if (ok != 0) 275 if (ok != 0)
277 kind = GNUNET_ERROR_TYPE_ERROR; 276 kind = GNUNET_ERROR_TYPE_ERROR;
278 switch (test) 277 switch (test)
279 { 278 {
280 case SYMMETRIC: 279 case SYMMETRIC:
@@ -294,12 +293,10 @@ measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
294 }; 293 };
295 GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", 294 GNUNET_log (kind, "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n",
296 throughput_out, total_bytes_sent, delta); 295 throughput_out, total_bytes_sent, delta);
297 GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", 296 GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", current_quota_p1_out);
298 current_quota_p1_out);
299 GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", 297 GNUNET_log (kind, "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n",
300 throughput_in, total_bytes_recv, delta); 298 throughput_in, total_bytes_recv, delta);
301 GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", 299 GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", current_quota_p2_in);
302 current_quota_p2_in);
303/* 300/*
304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in );
305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); 302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
@@ -322,10 +319,11 @@ transmit_ready (void *cls, size_t size, void *buf)
322 { 319 {
323 if ((p1.ch != NULL) && (p1.connect_status == 1)) 320 if ((p1.ch != NULL) && (p1.connect_status == 1))
324 GNUNET_break (NULL != 321 GNUNET_break (NULL !=
325 (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, 322 (p1.nth =
326 FAST_TIMEOUT, &p2.id, 323 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
327 MESSAGESIZE, 324 FAST_TIMEOUT, &p2.id,
328 &transmit_ready, &p1))); 325 MESSAGESIZE,
326 &transmit_ready, &p1)));
329 return 0; 327 return 0;
330 } 328 }
331 GNUNET_assert (tr_n < TOTAL_MSGS); 329 GNUNET_assert (tr_n < TOTAL_MSGS);
@@ -364,12 +362,13 @@ transmit_ready (void *cls, size_t size, void *buf)
364 362
365static void 363static void
366connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, 364connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
367 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 365 const struct GNUNET_ATS_Information *atsi,
366 unsigned int atsi_count)
368{ 367{
369 struct PeerContext *pc = cls; 368 struct PeerContext *pc = cls;
370 369
371 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 370 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
372 return; /* loopback */ 371 return; /* loopback */
373 GNUNET_assert (pc->connect_status == 0); 372 GNUNET_assert (pc->connect_status == 0);
374 pc->connect_status = 1; 373 pc->connect_status = 1;
375 if (pc == &p1) 374 if (pc == &p1)
@@ -393,10 +392,11 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
393 NULL); 392 NULL);
394 393
395 GNUNET_break (NULL != 394 GNUNET_break (NULL !=
396 (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0, 395 (p1.nth =
397 TIMEOUT, &p2.id, 396 GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, 0,
398 MESSAGESIZE, 397 TIMEOUT, &p2.id,
399 &transmit_ready, &p1))); 398 MESSAGESIZE,
399 &transmit_ready, &p1)));
400 } 400 }
401} 401}
402 402
@@ -407,12 +407,12 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
407 struct PeerContext *pc = cls; 407 struct PeerContext *pc = cls;
408 408
409 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 409 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
410 return; /* loopback */ 410 return; /* loopback */
411 pc->connect_status = 0; 411 pc->connect_status = 0;
412 if (GNUNET_SCHEDULER_NO_TASK != measure_task) 412 if (GNUNET_SCHEDULER_NO_TASK != measure_task)
413 { 413 {
414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
415 "Measurement aborted due to disconnect!\n"); 415 "Measurement aborted due to disconnect!\n");
416 GNUNET_SCHEDULER_cancel (measure_task); 416 GNUNET_SCHEDULER_cancel (measure_task);
417 measure_task = GNUNET_SCHEDULER_NO_TASK; 417 measure_task = GNUNET_SCHEDULER_NO_TASK;
418 } 418 }
@@ -431,7 +431,8 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
431static int 431static int
432inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 432inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
433 const struct GNUNET_MessageHeader *message, 433 const struct GNUNET_MessageHeader *message,
434 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 434 const struct GNUNET_ATS_Information *atsi,
435 unsigned int atsi_count)
435{ 436{
436#if DEBUG_TRANSMISSION 437#if DEBUG_TRANSMISSION
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -446,7 +447,8 @@ inbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
446static int 447static int
447outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other, 448outbound_notify (void *cls, const struct GNUNET_PeerIdentity *other,
448 const struct GNUNET_MessageHeader *message, 449 const struct GNUNET_MessageHeader *message,
449 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 450 const struct GNUNET_ATS_Information *atsi,
451 unsigned int atsi_count)
450{ 452{
451#if DEBUG_TRANSMISSION 453#if DEBUG_TRANSMISSION
452 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -463,7 +465,8 @@ transmit_ready (void *cls, size_t size, void *buf);
463static int 465static int
464process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer, 466process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
465 const struct GNUNET_MessageHeader *message, 467 const struct GNUNET_MessageHeader *message,
466 const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) 468 const struct GNUNET_ATS_Information *atsi,
469 unsigned int atsi_count)
467{ 470{
468 static int n; 471 static int n;
469 const struct TestMessage *hdr; 472 const struct TestMessage *hdr;
@@ -532,9 +535,10 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
532 GNUNET_assert (ok == 2); 535 GNUNET_assert (ok == 2);
533 OKPP; 536 OKPP;
534 /* connect p2 */ 537 /* connect p2 */
535 p2.ch = GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify, 538 p2.ch =
536 &disconnect_notify, &inbound_notify, GNUNET_YES, 539 GNUNET_CORE_connect (p2.cfg, 1, &p2, &init_notify, &connect_notify,
537 &outbound_notify, GNUNET_YES, handlers); 540 &disconnect_notify, &inbound_notify, GNUNET_YES,
541 &outbound_notify, GNUNET_YES, handlers);
538 } 542 }
539 else 543 else
540 { 544 {
@@ -546,8 +550,7 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server,
546 "Asking core (1) to connect to peer `%4s'\n", 550 "Asking core (1) to connect to peer `%4s'\n",
547 GNUNET_i2s (&p2.id)); 551 GNUNET_i2s (&p2.id));
548#endif 552#endif
549 connect_task = GNUNET_SCHEDULER_add_now (&try_connect, 553 connect_task = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
550 NULL);
551 } 554 }
552} 555}
553 556
@@ -642,9 +645,10 @@ run (void *cls, char *const *args, const char *cfgfile,
642 "TOTAL_QUOTA_OUT", 645 "TOTAL_QUOTA_OUT",
643 &current_quota_p2_out)); 646 &current_quota_p2_out));
644 647
645 p1.ch = GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify, 648 p1.ch =
646 &disconnect_notify, &inbound_notify, GNUNET_YES, 649 GNUNET_CORE_connect (p1.cfg, 1, &p1, &init_notify, &connect_notify,
647 &outbound_notify, GNUNET_YES, handlers); 650 &disconnect_notify, &inbound_notify, GNUNET_YES,
651 &outbound_notify, GNUNET_YES, handlers);
648} 652}
649 653
650 654