aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c886
1 files changed, 439 insertions, 447 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index d0d5b099c..0ceba53bc 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -122,7 +122,7 @@ struct SessionDisconnectMessage
122 * Public key of the sender. 122 * Public key of the sender.
123 */ 123 */
124 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; 124 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
125 125
126 /** 126 /**
127 * Signature of the peer that sends us the disconnect. Only 127 * Signature of the peer that sends us the disconnect. Only
128 * valid if the timestamp is AFTER the timestamp from the 128 * valid if the timestamp is AFTER the timestamp from the
@@ -186,18 +186,18 @@ struct MessageQueue
186 186
187enum State 187enum State
188{ 188{
189 /* fresh peer or completely disconnected */ 189 /* fresh peer or completely disconnected */
190 S_NOT_CONNECTED = 0, 190 S_NOT_CONNECTED = 0,
191 /* sent CONNECT message to other peer, waiting for CONNECT_ACK */ 191 /* sent CONNECT message to other peer, waiting for CONNECT_ACK */
192 S_CONNECT_SENT = 1, 192 S_CONNECT_SENT = 1,
193 /* received CONNECT message to other peer, sending CONNECT_ACK */ 193 /* received CONNECT message to other peer, sending CONNECT_ACK */
194 S_CONNECT_RECV = 4, 194 S_CONNECT_RECV = 4,
195 /* sent CONNECT_ACK message to other peer, wait for ACK or payload */ 195 /* sent CONNECT_ACK message to other peer, wait for ACK or payload */
196 S_CONNECT_RECV_ACK_SENT = 8, 196 S_CONNECT_RECV_ACK_SENT = 8,
197 /* received ACK or payload */ 197 /* received ACK or payload */
198 S_CONNECTED = 16, 198 S_CONNECTED = 16,
199 /* Disconnect in progress */ 199 /* Disconnect in progress */
200 S_DISCONNECT = 32 200 S_DISCONNECT = 32
201}; 201};
202 202
203/** 203/**
@@ -359,7 +359,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
359#define change_state(n, state, ...) change (n, state, __LINE__) 359#define change_state(n, state, ...) change (n, state, __LINE__)
360 360
361static int 361static int
362is_connecting (struct NeighbourMapEntry * n) 362is_connecting (struct NeighbourMapEntry *n)
363{ 363{
364 if ((n->state > S_NOT_CONNECTED) && (n->state < S_CONNECTED)) 364 if ((n->state > S_NOT_CONNECTED) && (n->state < S_CONNECTED))
365 return GNUNET_YES; 365 return GNUNET_YES;
@@ -367,7 +367,7 @@ is_connecting (struct NeighbourMapEntry * n)
367} 367}
368 368
369static int 369static int
370is_connected (struct NeighbourMapEntry * n) 370is_connected (struct NeighbourMapEntry *n)
371{ 371{
372 if (n->state == S_CONNECTED) 372 if (n->state == S_CONNECTED)
373 return GNUNET_YES; 373 return GNUNET_YES;
@@ -375,7 +375,7 @@ is_connected (struct NeighbourMapEntry * n)
375} 375}
376 376
377static int 377static int
378is_disconnecting (struct NeighbourMapEntry * n) 378is_disconnecting (struct NeighbourMapEntry *n)
379{ 379{
380 if (n->state == S_DISCONNECT) 380 if (n->state == S_DISCONNECT)
381 return GNUNET_YES; 381 return GNUNET_YES;
@@ -385,84 +385,85 @@ is_disconnecting (struct NeighbourMapEntry * n)
385static const char * 385static const char *
386print_state (int state) 386print_state (int state)
387{ 387{
388 switch (state) { 388 switch (state)
389 case S_CONNECTED: 389 {
390 return "S_CONNECTED"; 390 case S_CONNECTED:
391 break; 391 return "S_CONNECTED";
392 case S_CONNECT_RECV: 392 break;
393 return "S_CONNECT_RECV"; 393 case S_CONNECT_RECV:
394 break; 394 return "S_CONNECT_RECV";
395 case S_CONNECT_RECV_ACK_SENT: 395 break;
396 return"S_CONNECT_RECV_ACK_SENT"; 396 case S_CONNECT_RECV_ACK_SENT:
397 break; 397 return "S_CONNECT_RECV_ACK_SENT";
398 case S_CONNECT_SENT: 398 break;
399 return "S_CONNECT_SENT"; 399 case S_CONNECT_SENT:
400 break; 400 return "S_CONNECT_SENT";
401 case S_DISCONNECT: 401 break;
402 return "S_DISCONNECT"; 402 case S_DISCONNECT:
403 break; 403 return "S_DISCONNECT";
404 case S_NOT_CONNECTED: 404 break;
405 return "S_NOT_CONNECTED"; 405 case S_NOT_CONNECTED:
406 break; 406 return "S_NOT_CONNECTED";
407 default: 407 break;
408 GNUNET_break (0); 408 default:
409 break; 409 GNUNET_break (0);
410 break;
410 } 411 }
411 return NULL; 412 return NULL;
412} 413}
413 414
414static int 415static int
415change (struct NeighbourMapEntry * n, int state, int line); 416change (struct NeighbourMapEntry *n, int state, int line);
416 417
417static void 418static void
418ats_suggest_cancel (void *cls, 419ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
419 const struct GNUNET_SCHEDULER_TaskContext *tc);
420 420
421static void 421static void
422reset_task (void *cls, 422reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
423 const struct GNUNET_SCHEDULER_TaskContext *tc)
424{ 423{
425 struct NeighbourMapEntry * n = cls; 424 struct NeighbourMapEntry *n = cls;
426 425
427 n->state_reset = GNUNET_SCHEDULER_NO_TASK; 426 n->state_reset = GNUNET_SCHEDULER_NO_TASK;
428 427
429#if DEBUG_TRANSPORT 428#if DEBUG_TRANSPORT
430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
431 "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", 430 "Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n",
432 GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state)); 431 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, n->addr,
432 n->addrlen),
433 print_state (n->state));
433#endif 434#endif
434 GNUNET_STATISTICS_update (GST_stats, 435 GNUNET_STATISTICS_update (GST_stats,
435 gettext_noop ("# failed connection attempts due to timeout"), 436 gettext_noop
436 1, 437 ("# failed connection attempts due to timeout"), 1,
437 GNUNET_NO); 438 GNUNET_NO);
438 439
439 /* resetting state */ 440 /* resetting state */
440 n->state = S_NOT_CONNECTED; 441 n->state = S_NOT_CONNECTED;
441 442
442 /* destroying address */ 443 /* destroying address */
443 GNUNET_ATS_address_destroyed (GST_ats, 444 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
444 &n->id, 445 n->addrlen, NULL);
445 n->plugin_name,
446 n->addr,
447 n->addrlen,
448 NULL);
449 446
450 /* request new address */ 447 /* request new address */
451 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 448 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
452 GNUNET_SCHEDULER_cancel(n->ats_suggest); 449 GNUNET_SCHEDULER_cancel (n->ats_suggest);
453 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 450 n->ats_suggest =
454 GNUNET_ATS_suggest_address(GST_ats, &n->id); 451 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
452 n);
453 GNUNET_ATS_suggest_address (GST_ats, &n->id);
455} 454}
456 455
457static int 456static int
458change (struct NeighbourMapEntry * n, int state, int line) 457change (struct NeighbourMapEntry *n, int state, int line)
459{ 458{
460 char * old = strdup(print_state(n->state)); 459 char *old = strdup (print_state (n->state));
461 char * new = strdup(print_state(state)); 460 char *new = strdup (print_state (state));
462 461
463 /* allowed transitions */ 462 /* allowed transitions */
464 int allowed = GNUNET_NO; 463 int allowed = GNUNET_NO;
465 switch (n->state) { 464
465 switch (n->state)
466 {
466 case S_NOT_CONNECTED: 467 case S_NOT_CONNECTED:
467 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) || 468 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ||
468 (state == S_DISCONNECT)) 469 (state == S_DISCONNECT))
@@ -470,10 +471,12 @@ change (struct NeighbourMapEntry * n, int state, int line)
470 allowed = GNUNET_YES; 471 allowed = GNUNET_YES;
471 472
472 /* Schedule reset task */ 473 /* Schedule reset task */
473 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT) ) 474 if ((state == S_CONNECT_RECV) || (state == S_CONNECT_SENT))
474 { 475 {
475 GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK); 476 GNUNET_assert (n->state_reset == GNUNET_SCHEDULER_NO_TASK);
476 n->state_reset = GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task, n); 477 n->state_reset =
478 GNUNET_SCHEDULER_add_delayed (SETUP_CONNECTION_TIMEOUT, &reset_task,
479 n);
477 } 480 }
478 481
479 break; 482 break;
@@ -481,14 +484,18 @@ change (struct NeighbourMapEntry * n, int state, int line)
481 break; 484 break;
482 case S_CONNECT_RECV: 485 case S_CONNECT_RECV:
483 if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) || 486 if ((state == S_NOT_CONNECTED) || (state == S_DISCONNECT) ||
484 (state == S_CONNECTED) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_SENT)) 487 (state == S_CONNECTED) ||
488 /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_SENT))
485 { 489 {
486 if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) 490 if ((state == S_CONNECTED) || (state == S_DISCONNECT) ||
491 (state == S_NOT_CONNECTED))
487 { 492 {
488#if DEBUG_TRANSPORT 493#if DEBUG_TRANSPORT
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 495 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
491 GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); 496 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name,
497 n->addr, n->addrlen),
498 print_state (n->state), print_state (state));
492#endif 499#endif
493 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); 500 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
494 GNUNET_SCHEDULER_cancel (n->state_reset); 501 GNUNET_SCHEDULER_cancel (n->state_reset);
@@ -501,14 +508,18 @@ change (struct NeighbourMapEntry * n, int state, int line)
501 break; 508 break;
502 case S_CONNECT_SENT: 509 case S_CONNECT_SENT:
503 if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) || 510 if ((state == S_NOT_CONNECTED) || (state == S_CONNECTED) ||
504 (state == S_DISCONNECT) || /* FIXME SENT -> RECV ISSUE!*/ (state == S_CONNECT_RECV)) 511 (state == S_DISCONNECT) ||
512 /* FIXME SENT -> RECV ISSUE! */ (state == S_CONNECT_RECV))
505 { 513 {
506 if ((state == S_CONNECTED) || (state == S_DISCONNECT) || (state == S_NOT_CONNECTED)) 514 if ((state == S_CONNECTED) || (state == S_DISCONNECT) ||
515 (state == S_NOT_CONNECTED))
507 { 516 {
508#if DEBUG_TRANSPORT 517#if DEBUG_TRANSPORT
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", 519 "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n",
511 GNUNET_i2s (&n->id), GST_plugins_a2s(n->plugin_name, n->addr, n->addrlen), print_state(n->state), print_state(state)); 520 GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name,
521 n->addr, n->addrlen),
522 print_state (n->state), print_state (state));
512#endif 523#endif
513 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); 524 GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK);
514 GNUNET_SCHEDULER_cancel (n->state_reset); 525 GNUNET_SCHEDULER_cancel (n->state_reset);
@@ -528,11 +539,11 @@ change (struct NeighbourMapEntry * n, int state, int line)
528 break; 539 break;
529 case S_DISCONNECT: 540 case S_DISCONNECT:
530 /* 541 /*
531 if (state == S_NOT_CONNECTED) 542 * if (state == S_NOT_CONNECTED)
532 { 543 * {
533 allowed = GNUNET_YES; 544 * allowed = GNUNET_YES;
534 break; 545 * break;
535 }*/ 546 * } */
536 break; 547 break;
537 default: 548 default:
538 GNUNET_break (0); 549 GNUNET_break (0);
@@ -543,8 +554,8 @@ change (struct NeighbourMapEntry * n, int state, int line)
543 if (allowed == GNUNET_NO) 554 if (allowed == GNUNET_NO)
544 { 555 {
545 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 556 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
546 "Illegal state transition from `%s' to `%s' in line %u \n", 557 "Illegal state transition from `%s' to `%s' in line %u \n", old,
547 old, new, line); 558 new, line);
548 GNUNET_break (0); 559 GNUNET_break (0);
549 GNUNET_free (old); 560 GNUNET_free (old);
550 GNUNET_free (new); 561 GNUNET_free (new);
@@ -553,8 +564,9 @@ change (struct NeighbourMapEntry * n, int state, int line)
553 564
554 n->state = state; 565 n->state = state;
555#if DEBUG_TRANSPORT 566#if DEBUG_TRANSPORT
556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n", 567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
557 GNUNET_i2s (&n->id), n, old, new, line); 568 "State for neighbour `%s' %X changed from `%s' to `%s' in line %u\n",
569 GNUNET_i2s (&n->id), n, old, new, line);
558#endif 570#endif
559 GNUNET_free (old); 571 GNUNET_free (old);
560 GNUNET_free (new); 572 GNUNET_free (new);
@@ -562,19 +574,12 @@ change (struct NeighbourMapEntry * n, int state, int line)
562} 574}
563 575
564static ssize_t 576static ssize_t
565send_with_plugin ( const struct GNUNET_PeerIdentity * target, 577send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf,
566 const char *msgbuf, 578 size_t msgbuf_size, uint32_t priority,
567 size_t msgbuf_size, 579 struct GNUNET_TIME_Relative timeout, struct Session *session,
568 uint32_t priority, 580 const char *plugin_name, const void *addr, size_t addrlen,
569 struct GNUNET_TIME_Relative timeout, 581 int force_address, GNUNET_TRANSPORT_TransmitContinuation cont,
570 struct Session * session, 582 void *cont_cls)
571 const char * plugin_name,
572 const void *addr,
573 size_t addrlen,
574 int force_address,
575 GNUNET_TRANSPORT_TransmitContinuation cont,
576 void *cont_cls)
577
578{ 583{
579 struct GNUNET_TRANSPORT_PluginFunctions *papi; 584 struct GNUNET_TRANSPORT_PluginFunctions *papi;
580 size_t ret = GNUNET_SYSERR; 585 size_t ret = GNUNET_SYSERR;
@@ -602,15 +607,9 @@ send_with_plugin ( const struct GNUNET_PeerIdentity * target,
602 return GNUNET_SYSERR; 607 return GNUNET_SYSERR;
603 } 608 }
604 609
605 ret = papi->send (papi->cls, 610 ret =
606 target, 611 papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session,
607 msgbuf, msgbuf_size, 612 addr, addrlen, GNUNET_YES, cont, cont_cls);
608 0,
609 timeout,
610 session,
611 addr, addrlen,
612 GNUNET_YES,
613 cont, cont_cls);
614 613
615 if (ret == -1) 614 if (ret == -1)
616 { 615 {
@@ -713,7 +712,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
713 n->is_active = mq; 712 n->is_active = mq;
714 mq->n = n; 713 mq->n = n;
715 714
716 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) 715 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
717 { 716 {
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n", 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n",
719 GNUNET_i2s (&n->id)); 718 GNUNET_i2s (&n->id));
@@ -723,12 +722,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
723 return; 722 return;
724 } 723 }
725 724
726 ret = send_with_plugin (&n->id, 725 ret =
727 mq->message_buf, mq->message_buf_size, 0, 726 send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0,
728 timeout, 727 timeout, n->session, n->plugin_name, n->addr,
729 n->session, n->plugin_name, n->addr, n->addrlen, 728 n->addrlen, GNUNET_YES, &transmit_send_continuation,
730 GNUNET_YES, 729 mq);
731 &transmit_send_continuation, mq);
732 if (ret == -1) 730 if (ret == -1)
733 { 731 {
734 /* failure, but 'send' would not call continuation in this case, 732 /* failure, but 'send' would not call continuation in this case,
@@ -749,7 +747,8 @@ static void
749transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 747transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
750{ 748{
751 struct NeighbourMapEntry *n = cls; 749 struct NeighbourMapEntry *n = cls;
752 GNUNET_assert (NULL != lookup_neighbour(&n->id)); 750
751 GNUNET_assert (NULL != lookup_neighbour (&n->id));
753 n->transmission_task = GNUNET_SCHEDULER_NO_TASK; 752 n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
754 try_transmission_to_peer (n); 753 try_transmission_to_peer (n);
755} 754}
@@ -774,56 +773,61 @@ GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb,
774 773
775 774
776static void 775static void
777send_disconnect_cont (void *cls, 776send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
778 const struct GNUNET_PeerIdentity * target, 777 int result)
779 int result)
780{ 778{
781#if DEBUG_TRANSPORT 779#if DEBUG_TRANSPORT
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s': %i\n", 780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 "Sending DISCONNECT message to peer `%4s': %i\n",
783 GNUNET_i2s (target), result); 782 GNUNET_i2s (target), result);
784#endif 783#endif
785} 784}
786 785
787 786
788static int 787static int
789send_disconnect (const struct GNUNET_PeerIdentity * target, 788send_disconnect (const struct GNUNET_PeerIdentity *target,
790 const char *plugin_name, 789 const char *plugin_name, const char *sender_address,
791 const char *sender_address, uint16_t sender_address_len, 790 uint16_t sender_address_len, struct Session *session)
792 struct Session *session)
793{ 791{
794 size_t ret; 792 size_t ret;
795 struct SessionDisconnectMessage disconnect_msg; 793 struct SessionDisconnectMessage disconnect_msg;
796 794
797#if DEBUG_TRANSPORT 795#if DEBUG_TRANSPORT
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending DISCONNECT message to peer `%4s'\n", 796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
797 "Sending DISCONNECT message to peer `%4s'\n",
799 GNUNET_i2s (target)); 798 GNUNET_i2s (target));
800#endif 799#endif
801 800
802 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); 801 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
803 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 802 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
804 disconnect_msg.reserved = htonl (0); 803 disconnect_msg.reserved = htonl (0);
805 disconnect_msg.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 804 disconnect_msg.purpose.size =
806 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 805 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
807 sizeof (struct GNUNET_TIME_AbsoluteNBO) ); 806 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
808 disconnect_msg.purpose.purpose = htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 807 sizeof (struct GNUNET_TIME_AbsoluteNBO));
809 disconnect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 808 disconnect_msg.purpose.purpose =
809 htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
810 disconnect_msg.timestamp =
811 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
810 disconnect_msg.public_key = GST_my_public_key; 812 disconnect_msg.public_key = GST_my_public_key;
811 GNUNET_assert (GNUNET_OK == 813 GNUNET_assert (GNUNET_OK ==
812 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, 814 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
813 &disconnect_msg.purpose, 815 &disconnect_msg.purpose,
814 &disconnect_msg.signature)); 816 &disconnect_msg.signature));
815 817
816 ret = send_with_plugin(target, 818 ret =
817 (const char *) &disconnect_msg, sizeof (disconnect_msg), 819 send_with_plugin (target, (const char *) &disconnect_msg,
818 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 820 sizeof (disconnect_msg), UINT32_MAX,
819 session, plugin_name, sender_address, sender_address_len, 821 GNUNET_TIME_UNIT_FOREVER_REL, session, plugin_name,
820 GNUNET_YES, &send_disconnect_cont, NULL); 822 sender_address, sender_address_len, GNUNET_YES,
823 &send_disconnect_cont, NULL);
821 824
822 if (ret == GNUNET_SYSERR) 825 if (ret == GNUNET_SYSERR)
823 return GNUNET_SYSERR; 826 return GNUNET_SYSERR;
824 827
825 GNUNET_STATISTICS_update (GST_stats, 828 GNUNET_STATISTICS_update (GST_stats,
826 gettext_noop ("# peers disconnected due to external request"), 1, 829 gettext_noop
830 ("# peers disconnected due to external request"), 1,
827 GNUNET_NO); 831 GNUNET_NO);
828 return GNUNET_OK; 832 return GNUNET_OK;
829} 833}
@@ -837,21 +841,24 @@ static void
837disconnect_neighbour (struct NeighbourMapEntry *n) 841disconnect_neighbour (struct NeighbourMapEntry *n)
838{ 842{
839 struct MessageQueue *mq; 843 struct MessageQueue *mq;
840 int was_connected = is_connected(n); 844 int was_connected = is_connected (n);
841 845
842 /* send DISCONNECT MESSAGE */ 846 /* send DISCONNECT MESSAGE */
843 if (is_connected(n) || is_connecting(n)) 847 if (is_connected (n) || is_connecting (n))
844 { 848 {
845 if (GNUNET_OK == send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session)) 849 if (GNUNET_OK ==
850 send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen,
851 n->session))
846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", 852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n",
847 GNUNET_i2s (&n->id)); 853 GNUNET_i2s (&n->id));
848 else 854 else
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Could not send DISCONNECT_MSG to `%s'\n", 855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "Could not send DISCONNECT_MSG to `%s'\n",
850 GNUNET_i2s (&n->id)); 857 GNUNET_i2s (&n->id));
851 } 858 }
852 859
853 860
854 if (is_disconnecting(n)) 861 if (is_disconnecting (n))
855 return; 862 return;
856 change_state (n, S_DISCONNECT); 863 change_state (n, S_DISCONNECT);
857 864
@@ -871,7 +878,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
871 { 878 {
872 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task); 879 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task);
873 GNUNET_SCHEDULER_cancel (n->keepalive_task); 880 GNUNET_SCHEDULER_cancel (n->keepalive_task);
874 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK; 881 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
875 GNUNET_assert (neighbours_connected > 0); 882 GNUNET_assert (neighbours_connected > 0);
876 neighbours_connected--; 883 neighbours_connected--;
877 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, 884 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
@@ -929,7 +936,8 @@ neighbour_timeout_task (void *cls,
929 n->timeout_task = GNUNET_SCHEDULER_NO_TASK; 936 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
930 937
931 GNUNET_STATISTICS_update (GST_stats, 938 GNUNET_STATISTICS_update (GST_stats,
932 gettext_noop ("# peers disconnected due to timeout"), 1, 939 gettext_noop
940 ("# peers disconnected due to timeout"), 1,
933 GNUNET_NO); 941 GNUNET_NO);
934 disconnect_neighbour (n); 942 disconnect_neighbour (n);
935} 943}
@@ -943,27 +951,24 @@ neighbour_timeout_task (void *cls,
943 */ 951 */
944static void 952static void
945neighbour_keepalive_task (void *cls, 953neighbour_keepalive_task (void *cls,
946 const struct GNUNET_SCHEDULER_TaskContext *tc) 954 const struct GNUNET_SCHEDULER_TaskContext *tc)
947{ 955{
948 struct NeighbourMapEntry *n = cls; 956 struct NeighbourMapEntry *n = cls;
949 struct GNUNET_MessageHeader m; 957 struct GNUNET_MessageHeader m;
950 958
951 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 959 n->keepalive_task =
952 &neighbour_keepalive_task, 960 GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
953 n); 961 &neighbour_keepalive_task, n);
954 GNUNET_assert (is_connected(n)); 962 GNUNET_assert (is_connected (n));
955 GNUNET_STATISTICS_update (GST_stats, 963 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1,
956 gettext_noop ("# keepalives sent"), 1, 964 GNUNET_NO);
957 GNUNET_NO);
958 m.size = htons (sizeof (struct GNUNET_MessageHeader)); 965 m.size = htons (sizeof (struct GNUNET_MessageHeader));
959 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 966 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
960 967
961 send_with_plugin(&n->id, (const void *) &m, 968 send_with_plugin (&n->id, (const void *) &m, sizeof (m),
962 sizeof (m), 969 UINT32_MAX /* priority */ ,
963 UINT32_MAX /* priority */ , 970 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name,
964 GNUNET_TIME_UNIT_FOREVER_REL, 971 n->addr, n->addrlen, GNUNET_YES, NULL, NULL);
965 n->session, n->plugin_name, n->addr, n->addrlen,
966 GNUNET_YES, NULL, NULL);
967} 972}
968 973
969 974
@@ -983,18 +988,18 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n", 988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
984 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 989 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
985#endif 990#endif
986 if (is_connected(n)) 991 if (is_connected (n))
987 GNUNET_STATISTICS_update (GST_stats, 992 GNUNET_STATISTICS_update (GST_stats,
988 gettext_noop ("# peers disconnected due to global disconnect"), 1, 993 gettext_noop
989 GNUNET_NO); 994 ("# peers disconnected due to global disconnect"),
995 1, GNUNET_NO);
990 disconnect_neighbour (n); 996 disconnect_neighbour (n);
991 return GNUNET_OK; 997 return GNUNET_OK;
992} 998}
993 999
994 1000
995static void 1001static void
996ats_suggest_cancel (void *cls, 1002ats_suggest_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
997 const struct GNUNET_SCHEDULER_TaskContext *tc)
998{ 1003{
999 struct NeighbourMapEntry *n = cls; 1004 struct NeighbourMapEntry *n = cls;
1000 1005
@@ -1004,7 +1009,7 @@ ats_suggest_cancel (void *cls,
1004 " ATS did not suggested address to connect to peer `%s'\n", 1009 " ATS did not suggested address to connect to peer `%s'\n",
1005 GNUNET_i2s (&n->id)); 1010 GNUNET_i2s (&n->id));
1006 1011
1007 disconnect_neighbour(n); 1012 disconnect_neighbour (n);
1008} 1013}
1009 1014
1010/** 1015/**
@@ -1039,44 +1044,39 @@ GST_neighbours_stop ()
1039 * @param success GNUNET_OK on success 1044 * @param success GNUNET_OK on success
1040 */ 1045 */
1041static void 1046static void
1042send_connect_continuation (void *cls, 1047send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target,
1043 const struct GNUNET_PeerIdentity * target, 1048 int success)
1044 int success)
1045
1046{ 1049{
1047 struct NeighbourMapEntry *n = cls; 1050 struct NeighbourMapEntry *n = cls;
1048 1051
1049 GNUNET_assert (n != NULL); 1052 GNUNET_assert (n != NULL);
1050 GNUNET_assert (!is_connected(n)); 1053 GNUNET_assert (!is_connected (n));
1051 1054
1052 if (is_disconnecting(n)) 1055 if (is_disconnecting (n))
1053 return; /* neighbour is going away */ 1056 return; /* neighbour is going away */
1054 1057
1055 if (GNUNET_YES != success) 1058 if (GNUNET_YES != success)
1056 { 1059 {
1057#if DEBUG_TRANSPORT 1060#if DEBUG_TRANSPORT
1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1059 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", 1062 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
1060 GNUNET_i2s (&n->id), n->plugin_name, 1063 GNUNET_i2s (&n->id), n->plugin_name,
1061 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1064 (n->addrlen ==
1062 n->addr, 1065 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
1063 n->addrlen), 1066 n->addrlen), n->session);
1064 n->session);
1065#endif 1067#endif
1066 1068
1067 GNUNET_ATS_address_destroyed (GST_ats, 1069 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
1068 &n->id, 1070 n->addrlen, NULL);
1069 n->plugin_name,
1070 n->addr,
1071 n->addrlen,
1072 NULL);
1073 1071
1074 change_state(n, S_NOT_CONNECTED); 1072 change_state (n, S_NOT_CONNECTED);
1075 1073
1076 if (n->ats_suggest!= GNUNET_SCHEDULER_NO_TASK) 1074 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1077 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1075 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1078 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1076 n->ats_suggest =
1079 GNUNET_ATS_suggest_address(GST_ats, &n->id); 1077 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1078 n);
1079 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1080 return; 1080 return;
1081 } 1081 }
1082 1082
@@ -1093,40 +1093,36 @@ send_connect_continuation (void *cls,
1093 */ 1093 */
1094static void 1094static void
1095send_switch_address_continuation (void *cls, 1095send_switch_address_continuation (void *cls,
1096 const struct GNUNET_PeerIdentity * target, 1096 const struct GNUNET_PeerIdentity *target,
1097 int success) 1097 int success)
1098
1099{ 1098{
1100 struct NeighbourMapEntry *n = cls; 1099 struct NeighbourMapEntry *n = cls;
1101 1100
1102 GNUNET_assert (n != NULL); 1101 GNUNET_assert (n != NULL);
1103 if (is_disconnecting(n)) 1102 if (is_disconnecting (n))
1104 return; /* neighbour is going away */ 1103 return; /* neighbour is going away */
1105 1104
1106 GNUNET_assert (n->state == S_CONNECTED); 1105 GNUNET_assert (n->state == S_CONNECTED);
1107 if (GNUNET_YES != success) 1106 if (GNUNET_YES != success)
1108 { 1107 {
1109#if DEBUG_TRANSPORT 1108#if DEBUG_TRANSPORT
1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111 "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", 1110 "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n",
1112 GNUNET_i2s (&n->id), n->plugin_name, 1111 GNUNET_i2s (&n->id), n->plugin_name,
1113 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1112 (n->addrlen ==
1114 n->addr, 1113 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
1115 n->addrlen), 1114 n->addrlen), n->session);
1116 n->session);
1117#endif 1115#endif
1118 1116
1119 GNUNET_ATS_address_destroyed (GST_ats, 1117 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
1120 &n->id, 1118 n->addrlen, NULL);
1121 n->plugin_name,
1122 n->addr,
1123 n->addrlen,
1124 NULL);
1125 1119
1126 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1120 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1127 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1121 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1128 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1122 n->ats_suggest =
1129 GNUNET_ATS_suggest_address(GST_ats, &n->id); 1123 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1124 n);
1125 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1130 return; 1126 return;
1131 } 1127 }
1132} 1128}
@@ -1141,40 +1137,37 @@ send_switch_address_continuation (void *cls,
1141 */ 1137 */
1142static void 1138static void
1143send_connect_ack_continuation (void *cls, 1139send_connect_ack_continuation (void *cls,
1144 const struct GNUNET_PeerIdentity * target, 1140 const struct GNUNET_PeerIdentity *target,
1145 int success) 1141 int success)
1146
1147{ 1142{
1148 struct NeighbourMapEntry *n = cls; 1143 struct NeighbourMapEntry *n = cls;
1149 1144
1150 GNUNET_assert (n != NULL); 1145 GNUNET_assert (n != NULL);
1151 1146
1152 if (GNUNET_YES == success) 1147 if (GNUNET_YES == success)
1153 return; /* sending successful */ 1148 return; /* sending successful */
1154 1149
1155 /* sending failed, ask for next address */ 1150 /* sending failed, ask for next address */
1156#if DEBUG_TRANSPORT 1151#if DEBUG_TRANSPORT
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", 1153 "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n",
1159 GNUNET_i2s (&n->id), n->plugin_name, 1154 GNUNET_i2s (&n->id), n->plugin_name,
1160 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 1155 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
1161 n->addr, 1156 n->addr,
1162 n->addrlen), 1157 n->addrlen),
1163 n->session); 1158 n->session);
1164#endif 1159#endif
1165 change_state(n, S_NOT_CONNECTED); 1160 change_state (n, S_NOT_CONNECTED);
1166 1161
1167 GNUNET_ATS_address_destroyed (GST_ats, 1162 GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr,
1168 &n->id, 1163 n->addrlen, NULL);
1169 n->plugin_name,
1170 n->addr,
1171 n->addrlen,
1172 NULL);
1173 1164
1174 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1165 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1175 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1166 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1176 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1167 n->ats_suggest =
1177 GNUNET_ATS_suggest_address(GST_ats, &n->id); 1168 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1169 n);
1170 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1178} 1171}
1179 1172
1180/** 1173/**
@@ -1194,12 +1187,15 @@ send_connect_ack_continuation (void *cls,
1194 */ 1187 */
1195int 1188int
1196GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, 1189GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1197 const char *plugin_name, const void *address, 1190 const char *plugin_name,
1198 size_t address_len, struct Session *session, 1191 const void *address, size_t address_len,
1199 const struct GNUNET_ATS_Information 1192 struct Session *session,
1200 *ats, uint32_t ats_count, 1193 const struct GNUNET_ATS_Information *ats,
1201 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1194 uint32_t ats_count,
1202 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1195 struct GNUNET_BANDWIDTH_Value32NBO
1196 bandwidth_in,
1197 struct GNUNET_BANDWIDTH_Value32NBO
1198 bandwidth_out)
1203{ 1199{
1204 struct NeighbourMapEntry *n; 1200 struct NeighbourMapEntry *n;
1205 struct SessionConnectMessage connect_msg; 1201 struct SessionConnectMessage connect_msg;
@@ -1219,14 +1215,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1219 { 1215 {
1220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1216 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1221 "ATS offered suggested us empty address: plugin NULL"); 1217 "ATS offered suggested us empty address: plugin NULL");
1222 GNUNET_break_op(0); 1218 GNUNET_break_op (0);
1223 checks_failed = GNUNET_YES; 1219 checks_failed = GNUNET_YES;
1224 } 1220 }
1225 if ((address == NULL) && (address_len == 0 ) && (session == NULL)) 1221 if ((address == NULL) && (address_len == 0) && (session == NULL))
1226 { 1222 {
1227 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1223 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1228 "ATS offered suggested us empty address: address NULL & session NULL"); 1224 "ATS offered suggested us empty address: address NULL & session NULL");
1229 GNUNET_break_op(0); 1225 GNUNET_break_op (0);
1230 checks_failed = GNUNET_YES; 1226 checks_failed = GNUNET_YES;
1231 } 1227 }
1232 1228
@@ -1236,12 +1232,10 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1236 1232
1237 if (checks_failed == GNUNET_YES) 1233 if (checks_failed == GNUNET_YES)
1238 { 1234 {
1239 GNUNET_ATS_address_destroyed (GST_ats, 1235 GNUNET_ATS_address_destroyed (GST_ats, peer, plugin_name, address,
1240 peer, 1236 address_len, session);
1241 plugin_name, address,
1242 address_len, session);
1243 if (n != NULL) 1237 if (n != NULL)
1244 GNUNET_ATS_suggest_address(GST_ats, peer); 1238 GNUNET_ATS_suggest_address (GST_ats, peer);
1245 return GNUNET_NO; 1239 return GNUNET_NO;
1246 } 1240 }
1247 1241
@@ -1253,18 +1247,18 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1253 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, 1247 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name,
1254 address, 1248 address,
1255 address_len), 1249 address_len),
1256 session, (is_connected(n) ? "CONNECTED" : "NOT CONNECTED"), 1250 session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"),
1257 GNUNET_i2s (peer)); 1251 GNUNET_i2s (peer));
1258#endif 1252#endif
1259 1253
1260 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1254 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1261 { 1255 {
1262 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1256 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1263 n->ats_suggest = GNUNET_SCHEDULER_NO_TASK; 1257 n->ats_suggest = GNUNET_SCHEDULER_NO_TASK;
1264 } 1258 }
1265 1259
1266 // do not switch addresses just update quotas 1260 // do not switch addresses just update quotas
1267 if ((is_connected(n)) && (address_len == n->addrlen)) 1261 if ((is_connected (n)) && (address_len == n->addrlen))
1268 { 1262 {
1269 if ((0 == memcmp (address, n->addr, address_len)) && 1263 if ((0 == memcmp (address, n->addr, address_len)) &&
1270 (n->session == session)) 1264 (n->session == session))
@@ -1272,16 +1266,15 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer,
1272 struct QuotaSetMessage q_msg; 1266 struct QuotaSetMessage q_msg;
1273 1267
1274#if DEBUG_TRANSPORT 1268#if DEBUG_TRANSPORT
1275GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1276 "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", 1270 "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n",
1277 ntohl (n->bandwidth_out.value__), 1271 ntohl (n->bandwidth_out.value__),
1278 ntohl (n->bandwidth_in.value__), 1272 ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer));
1279 GNUNET_i2s (peer));
1280#endif 1273#endif
1281 1274
1282 n->bandwidth_in = bandwidth_in; 1275 n->bandwidth_in = bandwidth_in;
1283 n->bandwidth_out = bandwidth_out; 1276 n->bandwidth_out = bandwidth_out;
1284 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 1277 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
1285 1278
1286 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 1279 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
1287 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 1280 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
@@ -1324,9 +1317,11 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1324 1317
1325 change_state (n, S_CONNECT_SENT); 1318 change_state (n, S_CONNECT_SENT);
1326 1319
1327 ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1320 ret =
1328 session, plugin_name, address, address_len, 1321 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1329 GNUNET_YES, &send_connect_continuation, n); 1322 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1323 plugin_name, address, address_len, GNUNET_YES,
1324 &send_connect_continuation, n);
1330 1325
1331 return GNUNET_NO; 1326 return GNUNET_NO;
1332 } 1327 }
@@ -1336,13 +1331,16 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1336 msg_len = sizeof (struct SessionConnectMessage); 1331 msg_len = sizeof (struct SessionConnectMessage);
1337 connect_msg.header.size = htons (msg_len); 1332 connect_msg.header.size = htons (msg_len);
1338 connect_msg.header.type = 1333 connect_msg.header.type =
1339 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); 1334 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK);
1340 connect_msg.reserved = htonl (0); 1335 connect_msg.reserved = htonl (0);
1341 connect_msg.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1336 connect_msg.timestamp =
1337 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1342 1338
1343 ret = send_with_plugin(&n->id, (const void *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1339 ret =
1344 session, plugin_name, address, address_len, 1340 send_with_plugin (&n->id, (const void *) &connect_msg, msg_len,
1345 GNUNET_YES, &send_connect_ack_continuation, n); 1341 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1342 plugin_name, address, address_len, GNUNET_YES,
1343 &send_connect_ack_continuation, n);
1346 return GNUNET_NO; 1344 return GNUNET_NO;
1347 } 1345 }
1348 /* connected peer is switching addresses */ 1346 /* connected peer is switching addresses */
@@ -1356,26 +1354,28 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1356 connect_msg.timestamp = 1354 connect_msg.timestamp =
1357 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1355 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1358 1356
1359 ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1357 ret =
1360 session, plugin_name, address, address_len, 1358 send_with_plugin (peer, (const char *) &connect_msg, msg_len,
1361 GNUNET_YES, &send_switch_address_continuation, n); 1359 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session,
1360 plugin_name, address, address_len, GNUNET_YES,
1361 &send_switch_address_continuation, n);
1362 if (ret == GNUNET_SYSERR) 1362 if (ret == GNUNET_SYSERR)
1363 { 1363 {
1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1365 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", 1365 "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n",
1366 GNUNET_i2s (peer), plugin_name, 1366 GNUNET_i2s (peer), plugin_name,
1367 (address_len == 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, 1367 (address_len ==
1368 address, 1368 0) ? "<inbound>" : GST_plugins_a2s (plugin_name, address,
1369 address_len), 1369 address_len), session);
1370 session);
1371 } 1370 }
1372 return GNUNET_NO; 1371 return GNUNET_NO;
1373 } 1372 }
1374 else if (n->state == S_CONNECT_SENT) 1373 else if (n->state == S_CONNECT_SENT)
1375 { 1374 {
1376 return GNUNET_NO; 1375 return GNUNET_NO;
1377 } 1376 }
1378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid connection state to switch addresses %u \n", n->state); 1377 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1378 "Invalid connection state to switch addresses %u \n", n->state);
1379 GNUNET_break_op (0); 1379 GNUNET_break_op (0);
1380 return GNUNET_NO; 1380 return GNUNET_NO;
1381} 1381}
@@ -1383,7 +1383,7 @@ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1383 1383
1384/** 1384/**
1385 * Create an entry in the neighbour map for the given peer 1385 * Create an entry in the neighbour map for the given peer
1386 * 1386 *
1387 * @param peer peer to create an entry for 1387 * @param peer peer to create an entry for
1388 * @return new neighbour map entry 1388 * @return new neighbour map entry
1389 */ 1389 */
@@ -1394,22 +1394,21 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
1394 1394
1395#if DEBUG_TRANSPORT 1395#if DEBUG_TRANSPORT
1396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1397 "Unknown peer `%s', creating new neighbour\n", 1397 "Unknown peer `%s', creating new neighbour\n", GNUNET_i2s (peer));
1398 GNUNET_i2s (peer));
1399#endif 1398#endif
1400 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 1399 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
1401 n->id = *peer; 1400 n->id = *peer;
1402 n->state = S_NOT_CONNECTED; 1401 n->state = S_NOT_CONNECTED;
1403 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 1402 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
1404 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 1403 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
1405 MAX_BANDWIDTH_CARRY_S); 1404 MAX_BANDWIDTH_CARRY_S);
1406 n->timeout_task = 1405 n->timeout_task =
1407 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1406 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1408 &neighbour_timeout_task, n); 1407 &neighbour_timeout_task, n);
1409 GNUNET_assert (GNUNET_OK == 1408 GNUNET_assert (GNUNET_OK ==
1410 GNUNET_CONTAINER_multihashmap_put (neighbours, 1409 GNUNET_CONTAINER_multihashmap_put (neighbours,
1411 &n->id.hashPubKey, n, 1410 &n->id.hashPubKey, n,
1412 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1413 return n; 1412 return n;
1414} 1413}
1415 1414
@@ -1433,8 +1432,8 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n", 1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to peer `%s'\n",
1434 GNUNET_i2s (target)); 1433 GNUNET_i2s (target));
1435#endif 1434#endif
1436 if (0 == memcmp (target, &GST_my_identity, 1435 if (0 ==
1437 sizeof (struct GNUNET_PeerIdentity))) 1436 memcmp (target, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
1438 { 1437 {
1439 /* my own hello */ 1438 /* my own hello */
1440 return; 1439 return;
@@ -1443,9 +1442,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1443 1442
1444 if (NULL != n) 1443 if (NULL != n)
1445 { 1444 {
1446 if ((is_connected(n)) || (is_connecting(n))) 1445 if ((is_connected (n)) || (is_connecting (n)))
1447 return; /* already connecting or connected */ 1446 return; /* already connecting or connected */
1448 if (is_disconnecting(n)) 1447 if (is_disconnecting (n))
1449 change_state (n, S_NOT_CONNECTED); 1448 change_state (n, S_NOT_CONNECTED);
1450 } 1449 }
1451 1450
@@ -1458,7 +1457,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1458 GNUNET_i2s (&n->id)); 1457 GNUNET_i2s (&n->id));
1459#endif 1458#endif
1460 1459
1461 GNUNET_ATS_suggest_address (GST_ats, &n->id); 1460 GNUNET_ATS_suggest_address (GST_ats, &n->id);
1462} 1461}
1463 1462
1464/** 1463/**
@@ -1480,7 +1479,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
1480 1479
1481 n = lookup_neighbour (target); 1480 n = lookup_neighbour (target);
1482 1481
1483 if ((NULL == n) || (!is_connected(n))) 1482 if ((NULL == n) || (!is_connected (n)))
1484 return GNUNET_NO; /* not connected */ 1483 return GNUNET_NO; /* not connected */
1485 return GNUNET_YES; 1484 return GNUNET_YES;
1486} 1485}
@@ -1505,8 +1504,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1505 } 1504 }
1506 1505
1507#if DEBUG_TRANSPORT 1506#if DEBUG_TRANSPORT
1508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1507 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n",
1509 "Session %X to peer `%s' ended \n",
1510 session, GNUNET_i2s (peer)); 1508 session, GNUNET_i2s (peer));
1511#endif 1509#endif
1512 1510
@@ -1522,7 +1520,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1522 n->addrlen = 0; 1520 n->addrlen = 0;
1523 1521
1524 /* not connected anymore anyway, shouldn't matter */ 1522 /* not connected anymore anyway, shouldn't matter */
1525 if ((!is_connected(n)) && (!is_connecting(n))) 1523 if ((!is_connected (n)) && (!is_connecting (n)))
1526 return; 1524 return;
1527 1525
1528 /* We are connected, so ask ATS to switch addresses */ 1526 /* We are connected, so ask ATS to switch addresses */
@@ -1532,8 +1530,10 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
1532 &neighbour_timeout_task, n); 1530 &neighbour_timeout_task, n);
1533 /* try QUICKLY to re-establish a connection, reduce timeout! */ 1531 /* try QUICKLY to re-establish a connection, reduce timeout! */
1534 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 1532 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
1535 GNUNET_SCHEDULER_cancel(n->ats_suggest); 1533 GNUNET_SCHEDULER_cancel (n->ats_suggest);
1536 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 1534 n->ats_suggest =
1535 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
1536 n);
1537 GNUNET_ATS_suggest_address (GST_ats, peer); 1537 GNUNET_ATS_suggest_address (GST_ats, peer);
1538} 1538}
1539 1539
@@ -1563,7 +1563,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1563 } 1563 }
1564 1564
1565 n = lookup_neighbour (target); 1565 n = lookup_neighbour (target);
1566 if ((n == NULL) || (!is_connected(n))) 1566 if ((n == NULL) || (!is_connected (n)))
1567 { 1567 {
1568 GNUNET_STATISTICS_update (GST_stats, 1568 GNUNET_STATISTICS_update (GST_stats,
1569 gettext_noop 1569 gettext_noop
@@ -1574,7 +1574,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1575 "Could not send message to peer `%s': unknown neighbour", 1575 "Could not send message to peer `%s': unknown neighbour",
1576 GNUNET_i2s (target)); 1576 GNUNET_i2s (target));
1577 else if (!is_connected(n)) 1577 else if (!is_connected (n))
1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1579 "Could not send message to peer `%s': not connected\n", 1579 "Could not send message to peer `%s': not connected\n",
1580 GNUNET_i2s (target)); 1580 GNUNET_i2s (target));
@@ -1584,16 +1584,16 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1584 return; 1584 return;
1585 } 1585 }
1586 1586
1587 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen ==0)) 1587 if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0))
1588 { 1588 {
1589 GNUNET_STATISTICS_update (GST_stats, 1589 GNUNET_STATISTICS_update (GST_stats,
1590 gettext_noop 1590 gettext_noop
1591 ("# messages not sent (no such peer or not connected)"), 1591 ("# messages not sent (no such peer or not connected)"),
1592 1, GNUNET_NO); 1592 1, GNUNET_NO);
1593#if DEBUG_TRANSPORT 1593#if DEBUG_TRANSPORT
1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1594 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1595 "Could not send message to peer `%s': no address available\n", 1595 "Could not send message to peer `%s': no address available\n",
1596 GNUNET_i2s (target)); 1596 GNUNET_i2s (target));
1597#endif 1597#endif
1598 1598
1599 if (NULL != cont) 1599 if (NULL != cont)
@@ -1655,14 +1655,14 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
1655 if (NULL == n) 1655 if (NULL == n)
1656 { 1656 {
1657 GNUNET_STATISTICS_update (GST_stats, 1657 GNUNET_STATISTICS_update (GST_stats,
1658 gettext_noop 1658 gettext_noop
1659 ("# messages discarded due to lack of neighbour record"), 1659 ("# messages discarded due to lack of neighbour record"),
1660 1, GNUNET_NO); 1660 1, GNUNET_NO);
1661 *do_forward = GNUNET_NO; 1661 *do_forward = GNUNET_NO;
1662 return GNUNET_TIME_UNIT_ZERO; 1662 return GNUNET_TIME_UNIT_ZERO;
1663 } 1663 }
1664 } 1664 }
1665 if (!is_connected(n)) 1665 if (!is_connected (n))
1666 { 1666 {
1667 *do_forward = GNUNET_SYSERR; 1667 *do_forward = GNUNET_SYSERR;
1668 return GNUNET_TIME_UNIT_ZERO; 1668 return GNUNET_TIME_UNIT_ZERO;
@@ -1784,10 +1784,10 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n", 1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n",
1785 GNUNET_i2s (&n->id), "SET_QUOTA"); 1785 GNUNET_i2s (&n->id), "SET_QUOTA");
1786#endif 1786#endif
1787 if (is_connected(n)) 1787 if (is_connected (n))
1788 GNUNET_STATISTICS_update (GST_stats, 1788 GNUNET_STATISTICS_update (GST_stats,
1789 gettext_noop ("# disconnects due to quota of 0"), 1, 1789 gettext_noop ("# disconnects due to quota of 0"),
1790 GNUNET_NO); 1790 1, GNUNET_NO);
1791 disconnect_neighbour (n); 1791 disconnect_neighbour (n);
1792} 1792}
1793 1793
@@ -1823,7 +1823,7 @@ neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value)
1823 struct IteratorContext *ic = cls; 1823 struct IteratorContext *ic = cls;
1824 struct NeighbourMapEntry *n = value; 1824 struct NeighbourMapEntry *n = value;
1825 1825
1826 if (!is_connected(n)) 1826 if (!is_connected (n))
1827 return GNUNET_OK; 1827 return GNUNET_OK;
1828 1828
1829 ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen); 1829 ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen);
@@ -1872,13 +1872,13 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1872 n = lookup_neighbour (target); 1872 n = lookup_neighbour (target);
1873 if (NULL == n) 1873 if (NULL == n)
1874 return; /* not active */ 1874 return; /* not active */
1875 if (is_connected(n)) 1875 if (is_connected (n))
1876 { 1876 {
1877 send_disconnect(&n->id, n->plugin_name, n->addr, n->addrlen, n->session); 1877 send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, n->session);
1878 1878
1879 n = lookup_neighbour (target); 1879 n = lookup_neighbour (target);
1880 if (NULL == n) 1880 if (NULL == n)
1881 return; /* gone already */ 1881 return; /* gone already */
1882 } 1882 }
1883 disconnect_neighbour (n); 1883 disconnect_neighbour (n);
1884} 1884}
@@ -1887,13 +1887,15 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1887/** 1887/**
1888 * We received a disconnect message from the given peer, 1888 * We received a disconnect message from the given peer,
1889 * validate and process. 1889 * validate and process.
1890 * 1890 *
1891 * @param peer sender of the message 1891 * @param peer sender of the message
1892 * @param msg the disconnect message 1892 * @param msg the disconnect message
1893 */ 1893 */
1894void 1894void
1895GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, 1895GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
1896 const struct GNUNET_MessageHeader *msg) 1896 *peer,
1897 const struct GNUNET_MessageHeader
1898 *msg)
1897{ 1899{
1898 struct NeighbourMapEntry *n; 1900 struct NeighbourMapEntry *n;
1899 const struct SessionDisconnectMessage *sdm; 1901 const struct SessionDisconnectMessage *sdm;
@@ -1901,18 +1903,20 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1901 1903
1902#if DEBUG_TRANSPORT 1904#if DEBUG_TRANSPORT
1903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1904 "Received DISCONNECT message from peer `%s'\n", GNUNET_i2s (peer)); 1906 "Received DISCONNECT message from peer `%s'\n",
1907 GNUNET_i2s (peer));
1905#endif 1908#endif
1906 1909
1907 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) 1910 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
1908 { 1911 {
1909 // GNUNET_break_op (0); 1912 // GNUNET_break_op (0);
1910 GNUNET_STATISTICS_update (GST_stats, 1913 GNUNET_STATISTICS_update (GST_stats,
1911 gettext_noop ("# disconnect messages ignored (old format)"), 1, 1914 gettext_noop
1912 GNUNET_NO); 1915 ("# disconnect messages ignored (old format)"), 1,
1916 GNUNET_NO);
1913 return; 1917 return;
1914 } 1918 }
1915 sdm = (const struct SessionDisconnectMessage* ) msg; 1919 sdm = (const struct SessionDisconnectMessage *) msg;
1916 n = lookup_neighbour (peer); 1920 n = lookup_neighbour (peer);
1917 if (NULL == n) 1921 if (NULL == n)
1918 return; /* gone already */ 1922 return; /* gone already */
@@ -1920,21 +1924,20 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1920 n->connect_ts.abs_value) 1924 n->connect_ts.abs_value)
1921 { 1925 {
1922 GNUNET_STATISTICS_update (GST_stats, 1926 GNUNET_STATISTICS_update (GST_stats,
1923 gettext_noop ("# disconnect messages ignored (timestamp)"), 1, 1927 gettext_noop
1924 GNUNET_NO); 1928 ("# disconnect messages ignored (timestamp)"), 1,
1929 GNUNET_NO);
1925 return; 1930 return;
1926 } 1931 }
1927 GNUNET_CRYPTO_hash (&sdm->public_key, 1932 GNUNET_CRYPTO_hash (&sdm->public_key,
1928 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1933 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1929 &hc); 1934 &hc);
1930 if (0 != memcmp (peer, 1935 if (0 != memcmp (peer, &hc, sizeof (struct GNUNET_PeerIdentity)))
1931 &hc,
1932 sizeof (struct GNUNET_PeerIdentity)))
1933 { 1936 {
1934 GNUNET_break_op (0); 1937 GNUNET_break_op (0);
1935 return; 1938 return;
1936 } 1939 }
1937 if (ntohl (sdm->purpose.size) != 1940 if (ntohl (sdm->purpose.size) !=
1938 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 1941 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
1939 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 1942 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1940 sizeof (struct GNUNET_TIME_AbsoluteNBO)) 1943 sizeof (struct GNUNET_TIME_AbsoluteNBO))
@@ -1943,10 +1946,9 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1943 return; 1946 return;
1944 } 1947 }
1945 if (GNUNET_OK != 1948 if (GNUNET_OK !=
1946 GNUNET_CRYPTO_rsa_verify (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, 1949 GNUNET_CRYPTO_rsa_verify
1947 &sdm->purpose, 1950 (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, &sdm->purpose,
1948 &sdm->signature, 1951 &sdm->signature, &sdm->public_key))
1949 &sdm->public_key))
1950 { 1952 {
1951 GNUNET_break_op (0); 1953 GNUNET_break_op (0);
1952 return; 1954 return;
@@ -1970,12 +1972,13 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
1970 */ 1972 */
1971void 1973void
1972GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, 1974GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
1973 const struct GNUNET_PeerIdentity *peer, 1975 const struct GNUNET_PeerIdentity *peer,
1974 const char *plugin_name, 1976 const char *plugin_name,
1975 const char *sender_address, uint16_t sender_address_len, 1977 const char *sender_address,
1976 struct Session *session, 1978 uint16_t sender_address_len,
1977 const struct GNUNET_ATS_Information *ats, 1979 struct Session *session,
1978 uint32_t ats_count) 1980 const struct GNUNET_ATS_Information *ats,
1981 uint32_t ats_count)
1979{ 1982{
1980 const struct SessionConnectMessage *scm; 1983 const struct SessionConnectMessage *scm;
1981 struct QuotaSetMessage q_msg; 1984 struct QuotaSetMessage q_msg;
@@ -1987,7 +1990,8 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
1987 1990
1988#if DEBUG_TRANSPORT 1991#if DEBUG_TRANSPORT
1989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1990 "Received CONNECT_ACK message from peer `%s'\n", GNUNET_i2s (peer)); 1993 "Received CONNECT_ACK message from peer `%s'\n",
1994 GNUNET_i2s (peer));
1991#endif 1995#endif
1992 1996
1993 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 1997 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
@@ -2013,104 +2017,94 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
2013 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2017 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2014 "transport-ats", 2018 "transport-ats",
2015 "Giving ATS session %p of plugin %s for peer %s\n", 2019 "Giving ATS session %p of plugin %s for peer %s\n",
2016 session, 2020 session, plugin_name, GNUNET_i2s (peer));
2017 plugin_name, 2021 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
2018 GNUNET_i2s (peer)); 2022 sender_address_len, session, ats, ats_count);
2019 GNUNET_ATS_address_update (GST_ats, 2023
2020 peer, 2024 was_connected = is_connected (n);
2021 plugin_name, sender_address, sender_address_len, 2025 if (!is_connected (n))
2022 session, ats, ats_count);
2023
2024 was_connected = is_connected(n);
2025 if (!is_connected(n))
2026 change_state (n, S_CONNECTED); 2026 change_state (n, S_CONNECTED);
2027 2027
2028 GNUNET_ATS_address_in_use (GST_ats, 2028 GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address,
2029 peer, 2029 sender_address_len, session, GNUNET_YES);
2030 plugin_name,
2031 sender_address,
2032 sender_address_len,
2033 session,
2034 GNUNET_YES);
2035 2030
2036#if DEBUG_TRANSPORT 2031#if DEBUG_TRANSPORT
2037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2032 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2038 "Setting inbound quota of %u for peer `%s' to \n", 2033 "Setting inbound quota of %u for peer `%s' to \n",
2039 ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id)); 2034 ntohl (n->bandwidth_in.value__), GNUNET_i2s (&n->id));
2040#endif 2035#endif
2041 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 2036 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
2042 2037
2043 /* send ACK (ACK)*/ 2038 /* send ACK (ACK) */
2044 msg_len = sizeof (msg); 2039 msg_len = sizeof (msg);
2045 msg.size = htons (msg_len); 2040 msg.size = htons (msg_len);
2046 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 2041 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
2047 2042
2048 ret = send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, 2043 ret =
2049 GNUNET_TIME_UNIT_FOREVER_REL, 2044 send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX,
2050 n->session, n->plugin_name, n->addr, n->addrlen, 2045 GNUNET_TIME_UNIT_FOREVER_REL, n->session,
2051 GNUNET_YES, NULL, NULL); 2046 n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL,
2047 NULL);
2052 2048
2053 if (ret == GNUNET_SYSERR) 2049 if (ret == GNUNET_SYSERR)
2054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2055 "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n", 2051 "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n",
2056 GNUNET_i2s (&n->id), n->plugin_name, 2052 GNUNET_i2s (&n->id), n->plugin_name,
2057 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 2053 (n->addrlen ==
2058 n->addr, 2054 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2059 n->addrlen), 2055 n->addrlen), n->session);
2060 n->session);
2061 2056
2062 2057
2063 if (!was_connected) 2058 if (!was_connected)
2064 { 2059 {
2065 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2060 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
2066 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 2061 n->keepalive_task =
2067 &neighbour_keepalive_task, 2062 GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
2068 n); 2063 &neighbour_keepalive_task, n);
2069 2064
2070 neighbours_connected++; 2065 neighbours_connected++;
2071 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2066 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2072 GNUNET_NO); 2067 GNUNET_NO);
2073#if DEBUG_TRANSPORT 2068#if DEBUG_TRANSPORT
2074 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2075 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", 2070 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
2076 GNUNET_i2s (&n->id), n->plugin_name, 2071 GNUNET_i2s (&n->id), n->plugin_name,
2077 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 2072 (n->addrlen ==
2078 n->addr, 2073 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2079 n->addrlen), 2074 n->addrlen), n->session,
2080 n->session, __LINE__); 2075 __LINE__);
2081#endif 2076#endif
2082 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2077 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
2083 } 2078 }
2084 2079
2085#if DEBUG_TRANSPORT 2080#if DEBUG_TRANSPORT
2086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2087 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 2082 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
2088 ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer)); 2083 ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer));
2089#endif 2084#endif
2090 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 2085 q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
2091 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 2086 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
2092 q_msg.quota = n->bandwidth_out; 2087 q_msg.quota = n->bandwidth_out;
2093 q_msg.peer = (*peer); 2088 q_msg.peer = (*peer);
2094 GST_clients_broadcast (&q_msg.header, GNUNET_NO); 2089 GST_clients_broadcast (&q_msg.header, GNUNET_NO);
2095 2090
2096} 2091}
2097 2092
2098void 2093void
2099GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, 2094GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2100 const struct GNUNET_PeerIdentity *peer, 2095 const struct GNUNET_PeerIdentity *peer,
2101 const char *plugin_name, 2096 const char *plugin_name, const char *sender_address,
2102 const char *sender_address, uint16_t sender_address_len, 2097 uint16_t sender_address_len, struct Session *session,
2103 struct Session *session, 2098 const struct GNUNET_ATS_Information *ats,
2104 const struct GNUNET_ATS_Information *ats, 2099 uint32_t ats_count)
2105 uint32_t ats_count)
2106{ 2100{
2107 struct NeighbourMapEntry *n; 2101 struct NeighbourMapEntry *n;
2108 struct QuotaSetMessage q_msg; 2102 struct QuotaSetMessage q_msg;
2109 int was_connected; 2103 int was_connected;
2110 2104
2111#if DEBUG_TRANSPORT 2105#if DEBUG_TRANSPORT
2112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ACK message from peer `%s'\n",
2113 "Received ACK message from peer `%s'\n", GNUNET_i2s (peer)); 2107 GNUNET_i2s (peer));
2114#endif 2108#endif
2115 2109
2116 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) 2110 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
@@ -2122,60 +2116,52 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
2122 n = lookup_neighbour (peer); 2116 n = lookup_neighbour (peer);
2123 if (NULL == n) 2117 if (NULL == n)
2124 { 2118 {
2125 send_disconnect(peer, plugin_name, sender_address, sender_address_len, session); 2119 send_disconnect (peer, plugin_name, sender_address, sender_address_len,
2120 session);
2126 GNUNET_break (0); 2121 GNUNET_break (0);
2127 return; 2122 return;
2128 } 2123 }
2129 2124
2130 if (is_connected(n)) 2125 if (is_connected (n))
2131 return; 2126 return;
2132 2127
2133 if (NULL != session) 2128 if (NULL != session)
2134 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2129 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2135 "transport-ats", 2130 "transport-ats",
2136 "Giving ATS session %p of plugin %s for peer %s\n", 2131 "Giving ATS session %p of plugin %s for peer %s\n",
2137 session, 2132 session, plugin_name, GNUNET_i2s (peer));
2138 plugin_name, 2133 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
2139 GNUNET_i2s (peer)); 2134 sender_address_len, session, ats, ats_count);
2140 GNUNET_ATS_address_update (GST_ats, 2135
2141 peer, 2136 was_connected = is_connected (n);
2142 plugin_name, sender_address, sender_address_len,
2143 session, ats, ats_count);
2144
2145 was_connected = is_connected(n);
2146 change_state (n, S_CONNECTED); 2137 change_state (n, S_CONNECTED);
2147 2138
2148 GNUNET_ATS_address_in_use (GST_ats, 2139 GNUNET_ATS_address_in_use (GST_ats, peer, plugin_name, sender_address,
2149 peer, 2140 sender_address_len, session, GNUNET_YES);
2150 plugin_name,
2151 sender_address,
2152 sender_address_len,
2153 session,
2154 GNUNET_YES);
2155 2141
2156 GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in); 2142 GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in);
2157 2143
2158 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK) 2144 if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
2159 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY, 2145 n->keepalive_task =
2160 &neighbour_keepalive_task, 2146 GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
2161 n); 2147 &neighbour_keepalive_task, n);
2162 2148
2163 if (!was_connected) 2149 if (!was_connected)
2164 { 2150 {
2165 neighbours_connected++; 2151 neighbours_connected++;
2166 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 2152 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
2167 GNUNET_NO); 2153 GNUNET_NO);
2168 2154
2169#if DEBUG_TRANSPORT 2155#if DEBUG_TRANSPORT
2170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2171 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", 2157 "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n",
2172 GNUNET_i2s (&n->id), n->plugin_name, 2158 GNUNET_i2s (&n->id), n->plugin_name,
2173 (n->addrlen == 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, 2159 (n->addrlen ==
2174 n->addr, 2160 0) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
2175 n->addrlen), 2161 n->addrlen), n->session,
2176 n->session, __LINE__); 2162 __LINE__);
2177#endif 2163#endif
2178 connect_notify_cb (callback_cls, &n->id, ats, ats_count); 2164 connect_notify_cb (callback_cls, &n->id, ats, ats_count);
2179 } 2165 }
2180#if DEBUG_TRANSPORT 2166#if DEBUG_TRANSPORT
2181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2209,15 +2195,17 @@ struct BlackListCheckContext
2209 2195
2210static void 2196static void
2211handle_connect_blacklist_cont (void *cls, 2197handle_connect_blacklist_cont (void *cls,
2212 const struct GNUNET_PeerIdentity 2198 const struct GNUNET_PeerIdentity *peer,
2213 * peer, int result) 2199 int result)
2214{ 2200{
2215 struct NeighbourMapEntry *n; 2201 struct NeighbourMapEntry *n;
2216 struct BlackListCheckContext * bcc = cls; 2202 struct BlackListCheckContext *bcc = cls;
2217 2203
2218#if DEBUG_TRANSPORT 2204#if DEBUG_TRANSPORT
2219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2220 "Blacklist check due to CONNECT message: `%s'\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN"); 2206 "Blacklist check due to CONNECT message: `%s'\n",
2207 GNUNET_i2s (peer),
2208 (result == GNUNET_OK) ? "ALLOWED" : "FORBIDDEN");
2221#endif 2209#endif
2222 2210
2223 /* not allowed */ 2211 /* not allowed */
@@ -2237,13 +2225,12 @@ handle_connect_blacklist_cont (void *cls,
2237 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2225 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2238 "transport-ats", 2226 "transport-ats",
2239 "Giving ATS session %p of plugin %s address `%s' for peer %s\n", 2227 "Giving ATS session %p of plugin %s address `%s' for peer %s\n",
2240 bcc->session, 2228 bcc->session, bcc->plugin_name,
2241 bcc->plugin_name, 2229 GST_plugins_a2s (bcc->plugin_name, bcc->sender_address,
2242 GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, bcc->sender_address_len), 2230 bcc->sender_address_len),
2243 GNUNET_i2s (peer)); 2231 GNUNET_i2s (peer));
2244 GNUNET_ATS_address_update (GST_ats, 2232 GNUNET_ATS_address_update (GST_ats, peer, bcc->plugin_name,
2245 peer, 2233 bcc->sender_address, bcc->sender_address_len,
2246 bcc->plugin_name, bcc->sender_address, bcc->sender_address_len,
2247 bcc->session, bcc->ats, bcc->ats_count); 2234 bcc->session, bcc->ats, bcc->ats_count);
2248 n->connect_ts = bcc->ts; 2235 n->connect_ts = bcc->ts;
2249 } 2236 }
@@ -2251,13 +2238,15 @@ handle_connect_blacklist_cont (void *cls,
2251 GNUNET_free (bcc); 2238 GNUNET_free (bcc);
2252 2239
2253 if (n->state != S_CONNECT_RECV) 2240 if (n->state != S_CONNECT_RECV)
2254 change_state (n, S_CONNECT_RECV); 2241 change_state (n, S_CONNECT_RECV);
2255 2242
2256 /* Ask ATS for an address to connect via that address */ 2243 /* Ask ATS for an address to connect via that address */
2257 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) 2244 if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK)
2258 GNUNET_SCHEDULER_cancel(n->ats_suggest); 2245 GNUNET_SCHEDULER_cancel (n->ats_suggest);
2259 n->ats_suggest = GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel, n); 2246 n->ats_suggest =
2260 GNUNET_ATS_suggest_address(GST_ats, peer); 2247 GNUNET_SCHEDULER_add_delayed (ATS_RESPONSE_TIMEOUT, ats_suggest_cancel,
2248 n);
2249 GNUNET_ATS_suggest_address (GST_ats, peer);
2261} 2250}
2262 2251
2263/** 2252/**
@@ -2276,20 +2265,21 @@ handle_connect_blacklist_cont (void *cls,
2276 */ 2265 */
2277void 2266void
2278GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, 2267GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2279 const struct GNUNET_PeerIdentity *peer, 2268 const struct GNUNET_PeerIdentity *peer,
2280 const char *plugin_name, 2269 const char *plugin_name,
2281 const char *sender_address, uint16_t sender_address_len, 2270 const char *sender_address,
2282 struct Session *session, 2271 uint16_t sender_address_len,
2283 const struct GNUNET_ATS_Information *ats, 2272 struct Session *session,
2284 uint32_t ats_count) 2273 const struct GNUNET_ATS_Information *ats,
2274 uint32_t ats_count)
2285{ 2275{
2286 const struct SessionConnectMessage *scm; 2276 const struct SessionConnectMessage *scm;
2287 struct NeighbourMapEntry * n; 2277 struct NeighbourMapEntry *n;
2288 struct BlackListCheckContext * bcc = NULL; 2278 struct BlackListCheckContext *bcc = NULL;
2289 2279
2290#if DEBUG_TRANSPORT 2280#if DEBUG_TRANSPORT
2291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2292 "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer)); 2282 "Received CONNECT message from peer `%s'\n", GNUNET_i2s (peer));
2293#endif 2283#endif
2294 2284
2295 if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) 2285 if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
@@ -2301,23 +2291,24 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2301 scm = (const struct SessionConnectMessage *) message; 2291 scm = (const struct SessionConnectMessage *) message;
2302 GNUNET_break_op (ntohl (scm->reserved) == 0); 2292 GNUNET_break_op (ntohl (scm->reserved) == 0);
2303 2293
2304 n = lookup_neighbour(peer); 2294 n = lookup_neighbour (peer);
2305 if (n != NULL) 2295 if (n != NULL)
2306 { 2296 {
2307 /* connected peer switches addresses */ 2297 /* connected peer switches addresses */
2308 if (is_connected(n)) 2298 if (is_connected (n))
2309 { 2299 {
2310 GNUNET_ATS_address_update(GST_ats, peer, plugin_name, sender_address, sender_address_len, session, ats, ats_count); 2300 GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address,
2301 sender_address_len, session, ats, ats_count);
2311 return; 2302 return;
2312 } 2303 }
2313 } 2304 }
2314 2305
2315 /* we are not connected to this peer */ 2306 /* we are not connected to this peer */
2316 /* do blacklist check*/ 2307 /* do blacklist check */
2317 bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext) + 2308 bcc =
2318 sizeof (struct GNUNET_ATS_Information) * ats_count + 2309 GNUNET_malloc (sizeof (struct BlackListCheckContext) +
2319 sender_address_len + 2310 sizeof (struct GNUNET_ATS_Information) * ats_count +
2320 strlen (plugin_name)+1); 2311 sender_address_len + strlen (plugin_name) + 1);
2321 2312
2322 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2313 bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
2323 2314
@@ -2326,15 +2317,16 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2326 bcc->session = session; 2317 bcc->session = session;
2327 2318
2328 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; 2319 bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1];
2329 memcpy (bcc->ats, ats,sizeof (struct GNUNET_ATS_Information) * ats_count ); 2320 memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count);
2330 2321
2331 bcc->sender_address = (char *) &bcc->ats[ats_count]; 2322 bcc->sender_address = (char *) &bcc->ats[ats_count];
2332 memcpy (bcc->sender_address, sender_address , sender_address_len); 2323 memcpy (bcc->sender_address, sender_address, sender_address_len);
2333 2324
2334 bcc->plugin_name = &bcc->sender_address[sender_address_len]; 2325 bcc->plugin_name = &bcc->sender_address[sender_address_len];
2335 strcpy (bcc->plugin_name, plugin_name); 2326 strcpy (bcc->plugin_name, plugin_name);
2336 2327
2337 GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, bcc); 2328 GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont,
2329 bcc);
2338} 2330}
2339 2331
2340 2332