diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-12 15:00:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-12 15:00:47 +0000 |
commit | 63d15aa9d1ea50933ff34fc42916024a5d3196bf (patch) | |
tree | 5f5dad8cabd420639867d630a0b92c000001fc06 | |
parent | e5a68574ecfc990eedae657c74e54dda3d96f599 (diff) | |
download | gnunet-63d15aa9d1ea50933ff34fc42916024a5d3196bf.tar.gz gnunet-63d15aa9d1ea50933ff34fc42916024a5d3196bf.zip |
no need for public key
-rw-r--r-- | src/ats/ats_api.c | 20 | ||||
-rw-r--r-- | src/include/gnunet_ats_service.h | 6 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 269 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.h | 60 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 2 |
5 files changed, 120 insertions, 237 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index f748a558b..1fcdd8262 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c | |||
@@ -38,11 +38,6 @@ struct AllocationRecord | |||
38 | { | 38 | { |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Public key of the peer. | ||
42 | */ | ||
43 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | ||
44 | |||
45 | /** | ||
46 | * Performance information associated with this address (array). | 41 | * Performance information associated with this address (array). |
47 | */ | 42 | */ |
48 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 43 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
@@ -512,8 +507,7 @@ update_session (void *cls, | |||
512 | * @param ats_count number of performance records in 'ats' | 507 | * @param ats_count number of performance records in 'ats' |
513 | */ | 508 | */ |
514 | static struct AllocationRecord * | 509 | static struct AllocationRecord * |
515 | create_allocation_record (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | 510 | create_allocation_record (const char *plugin_name, |
516 | const char *plugin_name, | ||
517 | struct Session *session, | 511 | struct Session *session, |
518 | const void *plugin_addr, | 512 | const void *plugin_addr, |
519 | size_t plugin_addr_len, | 513 | size_t plugin_addr_len, |
@@ -523,7 +517,6 @@ create_allocation_record (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | |||
523 | struct AllocationRecord *ar; | 517 | struct AllocationRecord *ar; |
524 | 518 | ||
525 | ar = GNUNET_malloc (sizeof (struct AllocationRecord) + plugin_addr_len); | 519 | ar = GNUNET_malloc (sizeof (struct AllocationRecord) + plugin_addr_len); |
526 | ar->public_key = *public_key; | ||
527 | ar->plugin_name = GNUNET_strdup (plugin_name); | 520 | ar->plugin_name = GNUNET_strdup (plugin_name); |
528 | ar->plugin_addr = &ar[1]; | 521 | ar->plugin_addr = &ar[1]; |
529 | memcpy (&ar[1], plugin_addr, plugin_addr_len); | 522 | memcpy (&ar[1], plugin_addr, plugin_addr_len); |
@@ -570,7 +563,6 @@ disconnect_peer (void *cls, | |||
570 | * Calculate bandwidth assignments including the new peer. | 563 | * Calculate bandwidth assignments including the new peer. |
571 | * | 564 | * |
572 | * @param atc handle | 565 | * @param atc handle |
573 | * @param public_key public key of the peer | ||
574 | * @param peer identity of the new peer | 566 | * @param peer identity of the new peer |
575 | * @param plugin_name name of the currently used transport plugin | 567 | * @param plugin_name name of the currently used transport plugin |
576 | * @param session session in use (if available) | 568 | * @param session session in use (if available) |
@@ -581,7 +573,6 @@ disconnect_peer (void *cls, | |||
581 | */ | 573 | */ |
582 | void | 574 | void |
583 | GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, | 575 | GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, |
584 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
585 | const struct GNUNET_PeerIdentity *peer, | 576 | const struct GNUNET_PeerIdentity *peer, |
586 | const char *plugin_name, | 577 | const char *plugin_name, |
587 | struct Session *session, | 578 | struct Session *session, |
@@ -596,8 +587,7 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, | |||
596 | (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, | 587 | (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, |
597 | &disconnect_peer, | 588 | &disconnect_peer, |
598 | atc); | 589 | atc); |
599 | ar = create_allocation_record (public_key, | 590 | ar = create_allocation_record (plugin_name, |
600 | plugin_name, | ||
601 | session, | 591 | session, |
602 | plugin_addr, | 592 | plugin_addr, |
603 | plugin_addr_len, | 593 | plugin_addr_len, |
@@ -732,7 +722,6 @@ notify_valid (void *cls, | |||
732 | struct GNUNET_ATS_SuggestionContext *asc = value; | 722 | struct GNUNET_ATS_SuggestionContext *asc = value; |
733 | 723 | ||
734 | asc->cb (asc->cb_cls, | 724 | asc->cb (asc->cb_cls, |
735 | &ar->public_key, | ||
736 | &asc->target, | 725 | &asc->target, |
737 | ar->plugin_name, | 726 | ar->plugin_name, |
738 | ar->plugin_addr, | 727 | ar->plugin_addr, |
@@ -752,7 +741,6 @@ notify_valid (void *cls, | |||
752 | * for later use). Update bandwidth assignments. | 741 | * for later use). Update bandwidth assignments. |
753 | * | 742 | * |
754 | * @param atc handle | 743 | * @param atc handle |
755 | * @param public_key public key of the peer | ||
756 | * @param peer identity of the peer | 744 | * @param peer identity of the peer |
757 | * @param valid_until how long is the address valid? | 745 | * @param valid_until how long is the address valid? |
758 | * @param plugin_name name of the transport plugin | 746 | * @param plugin_name name of the transport plugin |
@@ -764,7 +752,6 @@ notify_valid (void *cls, | |||
764 | */ | 752 | */ |
765 | void | 753 | void |
766 | GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, | 754 | GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, |
767 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
768 | const struct GNUNET_PeerIdentity *peer, | 755 | const struct GNUNET_PeerIdentity *peer, |
769 | struct GNUNET_TIME_Absolute valid_until, | 756 | struct GNUNET_TIME_Absolute valid_until, |
770 | const char *plugin_name, | 757 | const char *plugin_name, |
@@ -777,8 +764,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, | |||
777 | struct AllocationRecord *ar; | 764 | struct AllocationRecord *ar; |
778 | struct UpdateSessionContext usc; | 765 | struct UpdateSessionContext usc; |
779 | 766 | ||
780 | ar = create_allocation_record (public_key, | 767 | ar = create_allocation_record (plugin_name, |
781 | plugin_name, | ||
782 | session, | 768 | session, |
783 | plugin_addr, | 769 | plugin_addr, |
784 | plugin_addr_len, | 770 | plugin_addr_len, |
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 0001bd1e5..87bd4eba0 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h | |||
@@ -94,7 +94,6 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc); | |||
94 | * Signature of a function that takes an address suggestion | 94 | * Signature of a function that takes an address suggestion |
95 | * | 95 | * |
96 | * @param cls closure | 96 | * @param cls closure |
97 | * @param public_key public key of the peer | ||
98 | * @param peer identity of the new peer | 97 | * @param peer identity of the new peer |
99 | * @param plugin_name name of the plugin, NULL if we have no suggestion | 98 | * @param plugin_name name of the plugin, NULL if we have no suggestion |
100 | * @param plugin_addr suggested address, NULL if we have no suggestion | 99 | * @param plugin_addr suggested address, NULL if we have no suggestion |
@@ -104,7 +103,6 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc); | |||
104 | * @param ats_count number of performance records in 'ats' | 103 | * @param ats_count number of performance records in 'ats' |
105 | */ | 104 | */ |
106 | typedef void (*GNUNET_ATS_AddressSuggestionCallback)(void *cls, | 105 | typedef void (*GNUNET_ATS_AddressSuggestionCallback)(void *cls, |
107 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
108 | const struct GNUNET_PeerIdentity *peer, | 106 | const struct GNUNET_PeerIdentity *peer, |
109 | const char *plugin_name, | 107 | const char *plugin_name, |
110 | const void *plugin_addr, | 108 | const void *plugin_addr, |
@@ -151,7 +149,6 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc); | |||
151 | * Calculate bandwidth assignments including the new peer. | 149 | * Calculate bandwidth assignments including the new peer. |
152 | * | 150 | * |
153 | * @param atc handle | 151 | * @param atc handle |
154 | * @param public_key public key of the peer | ||
155 | * @param peer identity of the new peer | 152 | * @param peer identity of the new peer |
156 | * @param plugin_name name of the currently used transport plugin | 153 | * @param plugin_name name of the currently used transport plugin |
157 | * @param session session in use (if available) | 154 | * @param session session in use (if available) |
@@ -162,7 +159,6 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SuggestionContext *asc); | |||
162 | */ | 159 | */ |
163 | void | 160 | void |
164 | GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, | 161 | GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, |
165 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
166 | const struct GNUNET_PeerIdentity *peer, | 162 | const struct GNUNET_PeerIdentity *peer, |
167 | const char *plugin_name, | 163 | const char *plugin_name, |
168 | struct Session *session, | 164 | struct Session *session, |
@@ -207,7 +203,6 @@ GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc, | |||
207 | * for later use). Update bandwidth assignments. | 203 | * for later use). Update bandwidth assignments. |
208 | * | 204 | * |
209 | * @param atc handle | 205 | * @param atc handle |
210 | * @param public_key public key of the peer | ||
211 | * @param peer identity of the new peer | 206 | * @param peer identity of the new peer |
212 | * @param valid_until how long is the address valid? | 207 | * @param valid_until how long is the address valid? |
213 | * @param plugin_name name of the transport plugin | 208 | * @param plugin_name name of the transport plugin |
@@ -219,7 +214,6 @@ GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc, | |||
219 | */ | 214 | */ |
220 | void | 215 | void |
221 | GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, | 216 | GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, |
222 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
223 | const struct GNUNET_PeerIdentity *peer, | 217 | const struct GNUNET_PeerIdentity *peer, |
224 | struct GNUNET_TIME_Absolute valid_until, | 218 | struct GNUNET_TIME_Absolute valid_until, |
225 | const char *plugin_name, | 219 | const char *plugin_name, |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index c833f6085..f30878966 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -38,6 +38,11 @@ | |||
38 | */ | 38 | */ |
39 | #define NEIGHBOUR_TABLE_SIZE 256 | 39 | #define NEIGHBOUR_TABLE_SIZE 256 |
40 | 40 | ||
41 | /** | ||
42 | * How often must a peer violate bandwidth quotas before we start | ||
43 | * to simply drop its messages? | ||
44 | */ | ||
45 | #define QUOTA_VIOLATION_DROP_THRESHOLD 10 | ||
41 | 46 | ||
42 | 47 | ||
43 | // TODO: | 48 | // TODO: |
@@ -145,11 +150,6 @@ struct NeighbourMapEntry | |||
145 | size_t addrlen; | 150 | size_t addrlen; |
146 | 151 | ||
147 | /** | 152 | /** |
148 | * Public key for this peer. Valid only if the respective flag is set below. | ||
149 | */ | ||
150 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | ||
151 | |||
152 | /** | ||
153 | * Identity of this neighbour. | 153 | * Identity of this neighbour. |
154 | */ | 154 | */ |
155 | struct GNUNET_PeerIdentity id; | 155 | struct GNUNET_PeerIdentity id; |
@@ -198,11 +198,6 @@ struct NeighbourMapEntry | |||
198 | // int received_pong; | 198 | // int received_pong; |
199 | 199 | ||
200 | /** | 200 | /** |
201 | * Do we have a valid public key for this neighbour? | ||
202 | */ | ||
203 | int public_key_valid; | ||
204 | |||
205 | /** | ||
206 | * Are we already in the process of disconnecting this neighbour? | 201 | * Are we already in the process of disconnecting this neighbour? |
207 | */ | 202 | */ |
208 | // int in_disconnect; | 203 | // int in_disconnect; |
@@ -372,6 +367,23 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
372 | 367 | ||
373 | 368 | ||
374 | /** | 369 | /** |
370 | * Peer has been idle for too long. Disconnect. | ||
371 | * | ||
372 | * @param cls the 'struct NeighbourMapEntry' of the neighbour that went idle | ||
373 | * @param tc scheduler context | ||
374 | */ | ||
375 | static void | ||
376 | neighbour_timeout_task (void *cls, | ||
377 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
378 | { | ||
379 | struct NeighbourMapEntry *n = cls; | ||
380 | |||
381 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
382 | disconnect_neighbour (n); | ||
383 | } | ||
384 | |||
385 | |||
386 | /** | ||
375 | * Disconnect from the given neighbour. | 387 | * Disconnect from the given neighbour. |
376 | * | 388 | * |
377 | * @param cls unused | 389 | * @param cls unused |
@@ -461,7 +473,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
461 | * Try to connect to the target peer using the given address | 473 | * Try to connect to the target peer using the given address |
462 | * | 474 | * |
463 | * @param cls the 'struct NeighbourMapEntry' of the target | 475 | * @param cls the 'struct NeighbourMapEntry' of the target |
464 | * @param public_key public key for the peer, never NULL | ||
465 | * @param target identity of the target peer | 476 | * @param target identity of the target peer |
466 | * @param plugin_name name of the plugin | 477 | * @param plugin_name name of the plugin |
467 | * @param plugin_address binary address | 478 | * @param plugin_address binary address |
@@ -472,7 +483,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
472 | */ | 483 | */ |
473 | static void | 484 | static void |
474 | try_connect_using_address (void *cls, | 485 | try_connect_using_address (void *cls, |
475 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
476 | const struct GNUNET_PeerIdentity *target, | 486 | const struct GNUNET_PeerIdentity *target, |
477 | const char *plugin_name, | 487 | const char *plugin_name, |
478 | const void *plugin_address, | 488 | const void *plugin_address, |
@@ -484,11 +494,6 @@ try_connect_using_address (void *cls, | |||
484 | struct NeighbourMapEntry *n = cls; | 494 | struct NeighbourMapEntry *n = cls; |
485 | 495 | ||
486 | n->asc = NULL; | 496 | n->asc = NULL; |
487 | if (n->public_key_valid == GNUNET_NO) | ||
488 | { | ||
489 | n->public_key = *public_key; | ||
490 | n->public_key_valid = GNUNET_YES; | ||
491 | } | ||
492 | GST_neighbours_switch_to_address (target, | 497 | GST_neighbours_switch_to_address (target, |
493 | plugin_name, | 498 | plugin_name, |
494 | plugin_address, | 499 | plugin_address, |
@@ -506,29 +511,6 @@ try_connect_using_address (void *cls, | |||
506 | 511 | ||
507 | 512 | ||
508 | /** | 513 | /** |
509 | * We've tried to connect but waited long enough and failed. Clean up. | ||
510 | * | ||
511 | * @param cls the 'struct NeighbourMapEntry' of the neighbour that failed to connect | ||
512 | * @param tc scheduler context | ||
513 | */ | ||
514 | static void | ||
515 | neighbour_connect_timeout_task (void *cls, | ||
516 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
517 | { | ||
518 | struct NeighbourMapEntry *n = cls; | ||
519 | |||
520 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
521 | GNUNET_assert (GNUNET_YES == | ||
522 | GNUNET_CONTAINER_multihashmap_remove (neighbours, | ||
523 | &n->id.hashPubKey, | ||
524 | n)); | ||
525 | GNUNET_assert (NULL == n->messages_head); | ||
526 | GNUNET_assert (NULL == n->ats); | ||
527 | GNUNET_free (n); | ||
528 | } | ||
529 | |||
530 | |||
531 | /** | ||
532 | * Try to create a connection to the given target (eventually). | 514 | * Try to create a connection to the given target (eventually). |
533 | * | 515 | * |
534 | * @param target peer to try to connect to | 516 | * @param target peer to try to connect to |
@@ -542,7 +524,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
542 | &GST_my_identity, | 524 | &GST_my_identity, |
543 | sizeof (struct GNUNET_PeerIdentity))); | 525 | sizeof (struct GNUNET_PeerIdentity))); |
544 | n = lookup_neighbour (target); | 526 | n = lookup_neighbour (target); |
545 | if ( (NULL != n) || | 527 | if ( (NULL != n) && |
546 | (GNUNET_YES == n->is_connected) ) | 528 | (GNUNET_YES == n->is_connected) ) |
547 | return; /* already connected */ | 529 | return; /* already connected */ |
548 | if (n == NULL) | 530 | if (n == NULL) |
@@ -553,7 +535,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
553 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | 535 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, |
554 | MAX_BANDWIDTH_CARRY_S); | 536 | MAX_BANDWIDTH_CARRY_S); |
555 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 537 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
556 | &neighbour_connect_timeout_task, n); | 538 | &neighbour_timeout_task, n); |
557 | GNUNET_assert (GNUNET_OK == | 539 | GNUNET_assert (GNUNET_OK == |
558 | GNUNET_CONTAINER_multihashmap_put (neighbours, | 540 | GNUNET_CONTAINER_multihashmap_put (neighbours, |
559 | &n->id.hashPubKey, | 541 | &n->id.hashPubKey, |
@@ -643,6 +625,83 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | |||
643 | 625 | ||
644 | 626 | ||
645 | /** | 627 | /** |
628 | * We have received a message from the given sender. How long should | ||
629 | * we delay before receiving more? (Also used to keep the peer marked | ||
630 | * as live). | ||
631 | * | ||
632 | * @param sender sender of the message | ||
633 | * @param size size of the message | ||
634 | * @return how long to wait before reading more from this sender | ||
635 | */ | ||
636 | struct GNUNET_TIME_Relative | ||
637 | GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender, | ||
638 | ssize_t size) | ||
639 | { | ||
640 | struct NeighbourMapEntry *n; | ||
641 | struct GNUNET_TIME_Relative ret; | ||
642 | |||
643 | n = lookup_neighbour (sender); | ||
644 | if (n == NULL) | ||
645 | return GNUNET_TIME_UNIT_ZERO; | ||
646 | if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, | ||
647 | size)) | ||
648 | { | ||
649 | n->quota_violation_count++; | ||
650 | #if DEBUG_TRANSPORT | ||
651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
652 | "Bandwidth quota (%u b/s) violation detected (total of %u).\n", | ||
653 | n->in_tracker.available_bytes_per_s__, | ||
654 | n->quota_violation_count); | ||
655 | #endif | ||
656 | /* Discount 32k per violation */ | ||
657 | GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, | ||
658 | - 32 * 1024); | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | if (n->quota_violation_count > 0) | ||
663 | { | ||
664 | /* try to add 32k back */ | ||
665 | GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, | ||
666 | 32 * 1024); | ||
667 | n->quota_violation_count--; | ||
668 | } | ||
669 | } | ||
670 | n->peer_timeout = | ||
671 | GNUNET_TIME_relative_to_absolute | ||
672 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
673 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
674 | n->timeout_task = | ||
675 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
676 | &neighbour_timeout_task, n); | ||
677 | if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) | ||
678 | { | ||
679 | GNUNET_STATISTICS_update (GST_stats, | ||
680 | gettext_noop ("# bandwidth quota violations by other peers"), | ||
681 | 1, | ||
682 | GNUNET_NO); | ||
683 | return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; | ||
684 | } | ||
685 | ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0); | ||
686 | if (ret.rel_value > 0) | ||
687 | { | ||
688 | #if DEBUG_TRANSPORT | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
690 | "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n", | ||
691 | (unsigned long long) n->in_tracker.consumption_since_last_update__, | ||
692 | (unsigned int) n->in_tracker.available_bytes_per_s__, | ||
693 | (unsigned long long) ret.rel_value); | ||
694 | #endif | ||
695 | GNUNET_STATISTICS_update (GST_stats, | ||
696 | gettext_noop ("# ms throttling suggested"), | ||
697 | (int64_t) ret.rel_value, | ||
698 | GNUNET_NO); | ||
699 | } | ||
700 | return ret; | ||
701 | } | ||
702 | |||
703 | |||
704 | /** | ||
646 | * Change the incoming quota for the given peer. | 705 | * Change the incoming quota for the given peer. |
647 | * | 706 | * |
648 | * @param neighbour identity of peer to change qutoa for | 707 | * @param neighbour identity of peer to change qutoa for |
@@ -746,105 +805,6 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, | |||
746 | 805 | ||
747 | 806 | ||
748 | /** | 807 | /** |
749 | * Peer has been idle for too long. Disconnect. | ||
750 | * | ||
751 | * @param cls the 'struct NeighbourMapEntry' of the neighbour that went idle | ||
752 | * @param tc scheduler context | ||
753 | */ | ||
754 | static void | ||
755 | neighbour_idle_timeout_task (void *cls, | ||
756 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
757 | { | ||
758 | struct NeighbourMapEntry *n = cls; | ||
759 | |||
760 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
761 | disconnect_neighbour (n); | ||
762 | } | ||
763 | |||
764 | |||
765 | /** | ||
766 | * We have received a CONNECT. Set the peer to connected. | ||
767 | * | ||
768 | * @param sender peer sending the PONG | ||
769 | * @param hdr the PONG message (presumably) | ||
770 | * @param plugin_name name of transport that delivered the PONG | ||
771 | * @param sender_address address of the other peer, NULL if other peer | ||
772 | * connected to us | ||
773 | * @param sender_address_len number of bytes in sender_address | ||
774 | * @param bandwidth bandwidth for the connection | ||
775 | * @param ats performance data | ||
776 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
777 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | ||
778 | */ | ||
779 | int | ||
780 | GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | ||
781 | const struct GNUNET_MessageHeader *hdr, | ||
782 | const char *plugin_name, | ||
783 | const void *sender_address, | ||
784 | size_t sender_address_len, | ||
785 | struct Session *session, | ||
786 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
787 | uint32_t ats_count) | ||
788 | { | ||
789 | struct NeighbourMapEntry *n; | ||
790 | |||
791 | if (0 == memcmp (sender, | ||
792 | &GST_my_identity, | ||
793 | sizeof (struct GNUNET_PeerIdentity))) | ||
794 | { | ||
795 | GNUNET_break (0); | ||
796 | return GNUNET_SYSERR; | ||
797 | } | ||
798 | n = lookup_neighbour (sender); | ||
799 | if ( (NULL != n) && | ||
800 | (n->is_connected == GNUNET_YES) ) | ||
801 | return GNUNET_OK; /* ats will consider switching and tell us */ | ||
802 | if (n == NULL) | ||
803 | { | ||
804 | n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); | ||
805 | n->id = *sender; | ||
806 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, | ||
807 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | ||
808 | MAX_BANDWIDTH_CARRY_S); | ||
809 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
810 | &neighbour_connect_timeout_task, n); | ||
811 | GNUNET_assert (GNUNET_OK == | ||
812 | GNUNET_CONTAINER_multihashmap_put (neighbours, | ||
813 | &n->id.hashPubKey, | ||
814 | n, | ||
815 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
816 | } | ||
817 | GST_neighbours_switch_to_address (sender, | ||
818 | plugin_name, | ||
819 | sender_address, | ||
820 | sender_address_len, | ||
821 | session, | ||
822 | ats, ats_count); | ||
823 | if (NULL != session) | ||
824 | { | ||
825 | /* inbound bi-directional connection, just use it */ | ||
826 | n->is_connected = GNUNET_YES; | ||
827 | connect_notify_cb (callback_cls, | ||
828 | sender, | ||
829 | n->ats, | ||
830 | n->ats_count); | ||
831 | n->peer_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
832 | if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) | ||
833 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
834 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
835 | &neighbour_idle_timeout_task, | ||
836 | n); | ||
837 | } | ||
838 | else | ||
839 | { | ||
840 | /* try to establish our connection back to the initiator */ | ||
841 | GST_neighbours_try_connect (sender); | ||
842 | } | ||
843 | return GNUNET_OK; | ||
844 | } | ||
845 | |||
846 | |||
847 | /** | ||
848 | * If we have an active connection to the given target, it must be shutdown. | 808 | * If we have an active connection to the given target, it must be shutdown. |
849 | * | 809 | * |
850 | * @param target peer to disconnect from | 810 | * @param target peer to disconnect from |
@@ -860,31 +820,4 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) | |||
860 | } | 820 | } |
861 | 821 | ||
862 | 822 | ||
863 | /** | ||
864 | * We have received a DISCONNECT. Set the peer to disconnected. | ||
865 | * | ||
866 | * @param sender peer sending the PONG | ||
867 | * @param hdr the PONG message (presumably) | ||
868 | * @param plugin_name name of transport that delivered the PONG | ||
869 | * @param sender_address address of the other peer, NULL if other peer | ||
870 | * connected to us | ||
871 | * @param sender_address_len number of bytes in sender_address | ||
872 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | ||
873 | */ | ||
874 | int | ||
875 | GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender, | ||
876 | const struct GNUNET_MessageHeader *hdr, | ||
877 | const char *plugin_name, | ||
878 | const void *sender_address, | ||
879 | size_t sender_address_len) | ||
880 | { | ||
881 | struct NeighbourMapEntry *n; | ||
882 | |||
883 | n = lookup_neighbour (sender); | ||
884 | /* FIXME: should disconnects have a signature that we should check here? */ | ||
885 | disconnect_neighbour (n); | ||
886 | return GNUNET_OK; | ||
887 | } | ||
888 | |||
889 | |||
890 | /* end of file gnunet-service-transport_neighbours.c */ | 823 | /* end of file gnunet-service-transport_neighbours.c */ |
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 8c038ef20..281060913 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h | |||
@@ -103,6 +103,21 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | |||
103 | GST_NeighbourSendContinuation cont, | 103 | GST_NeighbourSendContinuation cont, |
104 | void *cont_cls); | 104 | void *cont_cls); |
105 | 105 | ||
106 | |||
107 | /** | ||
108 | * We have received a message from the given sender. | ||
109 | * How long should we delay before receiving more? | ||
110 | * (Also used to keep the peer marked as live). | ||
111 | * | ||
112 | * @param sender sender of the message | ||
113 | * @param size size of the message | ||
114 | * @return how long to wait before reading more from this sender | ||
115 | */ | ||
116 | struct GNUNET_TIME_Relative | ||
117 | GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender, | ||
118 | ssize_t size); | ||
119 | |||
120 | |||
106 | /** | 121 | /** |
107 | * Change the incoming quota for the given peer. | 122 | * Change the incoming quota for the given peer. |
108 | * | 123 | * |
@@ -149,32 +164,8 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, | |||
149 | 164 | ||
150 | 165 | ||
151 | /** | 166 | /** |
152 | * We have received a CONNECT. Set the peer to connected. | ||
153 | * | ||
154 | * @param sender peer sending the PONG | ||
155 | * @param hdr the PONG message (presumably) | ||
156 | * @param plugin_name name of transport that delivered the PONG | ||
157 | * @param sender_address address of the other peer, NULL if other peer | ||
158 | * connected to us | ||
159 | * @param sender_address_len number of bytes in sender_address | ||
160 | * @param ats performance data | ||
161 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
162 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | ||
163 | */ | ||
164 | int | ||
165 | GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | ||
166 | const struct GNUNET_MessageHeader *hdr, | ||
167 | const char *plugin_name, | ||
168 | const void *sender_address, | ||
169 | size_t sender_address_len, | ||
170 | struct Session *session, | ||
171 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
172 | uint32_t ats_count); | ||
173 | |||
174 | |||
175 | /** | ||
176 | * For an existing neighbour record, set the active connection to | 167 | * For an existing neighbour record, set the active connection to |
177 | * the given address. | 168 | * use the given address. |
178 | * | 169 | * |
179 | * @param plugin_name name of transport that delivered the PONG | 170 | * @param plugin_name name of transport that delivered the PONG |
180 | * @param address address of the other peer, NULL if other peer | 171 | * @param address address of the other peer, NULL if other peer |
@@ -193,24 +184,5 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
193 | uint32_t ats_count); | 184 | uint32_t ats_count); |
194 | 185 | ||
195 | 186 | ||
196 | /** | ||
197 | * We have received a DISCONNECT. Set the peer to disconnected. | ||
198 | * | ||
199 | * @param sender peer sending the PONG | ||
200 | * @param hdr the PONG message (presumably) | ||
201 | * @param plugin_name name of transport that delivered the PONG | ||
202 | * @param sender_address address of the other peer, NULL if other peer | ||
203 | * connected to us | ||
204 | * @param sender_address_len number of bytes in sender_address | ||
205 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | ||
206 | */ | ||
207 | int | ||
208 | GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender, | ||
209 | const struct GNUNET_MessageHeader *hdr, | ||
210 | const char *plugin_name, | ||
211 | const void *sender_address, | ||
212 | size_t sender_address_len); | ||
213 | |||
214 | |||
215 | #endif | 187 | #endif |
216 | /* end of file gnunet-service-transport_neighbours.h */ | 188 | /* end of file gnunet-service-transport_neighbours.h */ |
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index f5e2bf820..50626eaa6 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -419,7 +419,6 @@ add_valid_address (void *cls, | |||
419 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, | 419 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, |
420 | expiration); | 420 | expiration); |
421 | GNUNET_ATS_address_update (GST_ats, | 421 | GNUNET_ATS_address_update (GST_ats, |
422 | &public_key, | ||
423 | &pid, | 422 | &pid, |
424 | ve->valid_until, | 423 | ve->valid_until, |
425 | tname, | 424 | tname, |
@@ -1039,7 +1038,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1039 | /* validity achieved, remember it! */ | 1038 | /* validity achieved, remember it! */ |
1040 | ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); | 1039 | ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); |
1041 | GNUNET_ATS_address_update (GST_ats, | 1040 | GNUNET_ATS_address_update (GST_ats, |
1042 | &ve->public_key, | ||
1043 | &ve->pid, | 1041 | &ve->pid, |
1044 | ve->valid_until, | 1042 | ve->valid_until, |
1045 | ve->transport_name, | 1043 | ve->transport_name, |