diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/core/gnunet-service-core_clients.c | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/core/gnunet-service-core_clients.c')
-rw-r--r-- | src/core/gnunet-service-core_clients.c | 281 |
1 files changed, 133 insertions, 148 deletions
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 | */ |
148 | static void | 148 | static void |
149 | send_to_client (struct GSC_Client *client, | 149 | send_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 | */ |
172 | void | 171 | void |
173 | GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client, | 172 | GSC_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 | */ |
196 | static int | 195 | static int |
197 | type_match (uint16_t type, | 196 | type_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 | */ |
220 | static void | 218 | static void |
221 | send_to_all_clients (const struct GNUNET_PeerIdentity *sender, | 219 | send_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 | */ |
493 | static void | 484 | static void |
494 | client_tokenizer_callback (void *cls, void *client, | 485 | client_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 | */ |
562 | static void | 552 | static void |
563 | handle_client_disconnect (void *cls, | 553 | handle_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 | |||
632 | GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) | 620 | GSC_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 | */ |
655 | void | 644 | void |
656 | GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | 645 | GSC_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 | */ |
750 | void | 738 | void |
751 | GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour, | 739 | GSC_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 | */ |
779 | void | 767 | void |
780 | GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | 768 | GSC_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 | { |