diff options
25 files changed, 1023 insertions, 1333 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h index 482b7b4b3..69788971e 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h | |||
@@ -105,29 +105,6 @@ struct RequestAddressMessage | |||
105 | 105 | ||
106 | 106 | ||
107 | /** | 107 | /** |
108 | * Scheduling client to ATS service: reset backoff for | ||
109 | * address suggestions to this peer. | ||
110 | */ | ||
111 | struct ResetBackoffMessage | ||
112 | { | ||
113 | /** | ||
114 | * Type is #GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF. | ||
115 | */ | ||
116 | struct GNUNET_MessageHeader header; | ||
117 | |||
118 | /** | ||
119 | * Always zero. | ||
120 | */ | ||
121 | uint32_t reserved GNUNET_PACKED; | ||
122 | |||
123 | /** | ||
124 | * Peer to reset backoff for. | ||
125 | */ | ||
126 | struct GNUNET_PeerIdentity peer; | ||
127 | }; | ||
128 | |||
129 | |||
130 | /** | ||
131 | * ATS client to ATS service: here is another address you can use. | 108 | * ATS client to ATS service: here is another address you can use. |
132 | */ | 109 | */ |
133 | struct AddressAddMessage | 110 | struct AddressAddMessage |
@@ -214,37 +191,6 @@ struct AddressUpdateMessage | |||
214 | 191 | ||
215 | 192 | ||
216 | /** | 193 | /** |
217 | * Message sent from ATS client to ATS service to notify | ||
218 | * it if we started (or stopped) using an address. | ||
219 | */ | ||
220 | struct AddressUseMessage | ||
221 | { | ||
222 | /** | ||
223 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE. | ||
224 | */ | ||
225 | struct GNUNET_MessageHeader header; | ||
226 | |||
227 | /** | ||
228 | * Internal number this client uses to refer to this address. | ||
229 | */ | ||
230 | uint32_t session_id GNUNET_PACKED; | ||
231 | |||
232 | /** | ||
233 | * Which peer is this about? (Technically redundant, as the | ||
234 | * @e session_id should be sufficient, but enables ATS service | ||
235 | * to find the session faster). | ||
236 | */ | ||
237 | struct GNUNET_PeerIdentity peer; | ||
238 | |||
239 | /** | ||
240 | * #GNUNET_YES or #GNUNET_NO. | ||
241 | */ | ||
242 | uint32_t in_use GNUNET_PACKED; | ||
243 | |||
244 | }; | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Message sent by ATS client to ATS service when an address | 194 | * Message sent by ATS client to ATS service when an address |
249 | * was destroyed and must thus henceforth no longer be considered | 195 | * was destroyed and must thus henceforth no longer be considered |
250 | * for scheduling. | 196 | * for scheduling. |
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c index 9198118a4..0871544dc 100644 --- a/src/ats/ats_api_connectivity.c +++ b/src/ats/ats_api_connectivity.c | |||
@@ -303,6 +303,9 @@ GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, | |||
303 | { | 303 | { |
304 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; | 304 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; |
305 | 305 | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
307 | "Requesting ATS to suggest address for `%s'\n", | ||
308 | GNUNET_i2s (peer)); | ||
306 | s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle); | 309 | s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle); |
307 | s->ch = ch; | 310 | s->ch = ch; |
308 | s->id = *peer; | 311 | s->id = *peer; |
@@ -336,6 +339,9 @@ GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHan | |||
336 | struct GNUNET_MQ_Envelope *ev; | 339 | struct GNUNET_MQ_Envelope *ev; |
337 | struct RequestAddressMessage *m; | 340 | struct RequestAddressMessage *m; |
338 | 341 | ||
342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
343 | "Telling ATS we no longer care for an address for `%s'\n", | ||
344 | GNUNET_i2s (&sh->id)); | ||
339 | GNUNET_assert (GNUNET_OK == | 345 | GNUNET_assert (GNUNET_OK == |
340 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, | 346 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, |
341 | &sh->id, | 347 | &sh->id, |
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index f81dfe7eb..792215598 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -92,13 +92,6 @@ struct GNUNET_ATS_AddressRecord | |||
92 | uint32_t slot; | 92 | uint32_t slot; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Is this address currently in use? In use means | ||
96 | * that the transport service will use this address | ||
97 | * for sending. | ||
98 | */ | ||
99 | int in_use; | ||
100 | |||
101 | /** | ||
102 | * We're about to destroy this address record, just ATS does | 95 | * We're about to destroy this address record, just ATS does |
103 | * not know this yet. Once ATS confirms its destruction, | 96 | * not know this yet. Once ATS confirms its destruction, |
104 | * we can clean up. | 97 | * we can clean up. |
@@ -418,6 +411,11 @@ process_ats_address_suggestion_message (void *cls, | |||
418 | if ( (0 == ntohl (m->bandwidth_out.value__)) && | 411 | if ( (0 == ntohl (m->bandwidth_out.value__)) && |
419 | (0 == ntohl (m->bandwidth_in.value__)) ) | 412 | (0 == ntohl (m->bandwidth_in.value__)) ) |
420 | { | 413 | { |
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "ATS suggests disconnect from peer `%s' with BW %u/%u\n", | ||
416 | GNUNET_i2s (&ar->address->peer), | ||
417 | (unsigned int) ntohl (m->bandwidth_out.value__), | ||
418 | (unsigned int) ntohl (m->bandwidth_in.value__)); | ||
421 | sh->suggest_cb (sh->suggest_cb_cls, | 419 | sh->suggest_cb (sh->suggest_cb_cls, |
422 | &m->peer, | 420 | &m->peer, |
423 | NULL, | 421 | NULL, |
@@ -434,6 +432,11 @@ process_ats_address_suggestion_message (void *cls, | |||
434 | GNUNET_break (0); | 432 | GNUNET_break (0); |
435 | return; | 433 | return; |
436 | } | 434 | } |
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
436 | "ATS suggests address slot %u for peer `%s' using plugin %s\n", | ||
437 | ar->slot, | ||
438 | GNUNET_i2s (&ar->address->peer), | ||
439 | ar->address->transport_name); | ||
437 | sh->suggest_cb (sh->suggest_cb_cls, | 440 | sh->suggest_cb (sh->suggest_cb_cls, |
438 | &m->peer, | 441 | &m->peer, |
439 | ar->address, | 442 | ar->address, |
@@ -498,7 +501,7 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
498 | m->session_id = htonl (ar->slot); | 501 | m->session_id = htonl (ar->slot); |
499 | 502 | ||
500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
501 | "Adding address for peer `%s', plugin `%s', session %p id %u\n", | 504 | "Adding address for peer `%s', plugin `%s', session %p slot %u\n", |
502 | GNUNET_i2s (&ar->address->peer), | 505 | GNUNET_i2s (&ar->address->peer), |
503 | ar->address->transport_name, | 506 | ar->address->transport_name, |
504 | ar->session, | 507 | ar->session, |
@@ -520,29 +523,6 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
520 | 523 | ||
521 | 524 | ||
522 | /** | 525 | /** |
523 | * Generate and transmit the `struct AddressUseMessage` for the given | ||
524 | * address record. | ||
525 | * | ||
526 | * @param ar the address to inform the ATS service about | ||
527 | * @param in_use say if it is in use or not | ||
528 | */ | ||
529 | static void | ||
530 | send_in_use_message (struct GNUNET_ATS_AddressRecord *ar, | ||
531 | int in_use) | ||
532 | { | ||
533 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | ||
534 | struct GNUNET_MQ_Envelope *ev; | ||
535 | struct AddressUseMessage *m; | ||
536 | |||
537 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); | ||
538 | m->peer = ar->address->peer; | ||
539 | m->in_use = htonl ((uint32_t) in_use); | ||
540 | m->session_id = htonl (ar->slot); | ||
541 | GNUNET_MQ_send (sh->mq, ev); | ||
542 | } | ||
543 | |||
544 | |||
545 | /** | ||
546 | * Re-establish the connection to the ATS service. | 526 | * Re-establish the connection to the ATS service. |
547 | * | 527 | * |
548 | * @param sh handle to use to re-connect. | 528 | * @param sh handle to use to re-connect. |
@@ -586,8 +566,6 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
586 | if (NULL == ar) | 566 | if (NULL == ar) |
587 | continue; | 567 | continue; |
588 | send_add_address_message (sh, ar); | 568 | send_add_address_message (sh, ar); |
589 | if (ar->in_use) | ||
590 | send_in_use_message (ar, GNUNET_YES); | ||
591 | if (NULL == sh->mq) | 569 | if (NULL == sh->mq) |
592 | return; | 570 | return; |
593 | } | 571 | } |
@@ -652,27 +630,6 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) | |||
652 | 630 | ||
653 | 631 | ||
654 | /** | 632 | /** |
655 | * We would like to reset the address suggestion block time for this | ||
656 | * peer. | ||
657 | * | ||
658 | * @param sh handle | ||
659 | * @param peer identity of the peer we want to reset | ||
660 | */ | ||
661 | void | ||
662 | GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, | ||
663 | const struct GNUNET_PeerIdentity *peer) | ||
664 | { | ||
665 | struct GNUNET_MQ_Envelope *ev; | ||
666 | struct ResetBackoffMessage *m; | ||
667 | |||
668 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF); | ||
669 | m->reserved = htonl (0); | ||
670 | m->peer = *peer; | ||
671 | GNUNET_MQ_send (sh->mq, ev); | ||
672 | } | ||
673 | |||
674 | |||
675 | /** | ||
676 | * Test if a address and a session is known to ATS | 633 | * Test if a address and a session is known to ATS |
677 | * | 634 | * |
678 | * @param sh the scheduling handle | 635 | * @param sh the scheduling handle |
@@ -799,7 +756,6 @@ GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar, | |||
799 | { | 756 | { |
800 | GNUNET_break (session == ar->session); | 757 | GNUNET_break (session == ar->session); |
801 | ar->session = NULL; | 758 | ar->session = NULL; |
802 | GNUNET_break (GNUNET_NO == ar->in_use); | ||
803 | if (GNUNET_HELLO_address_check_option (ar->address, | 759 | if (GNUNET_HELLO_address_check_option (ar->address, |
804 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 760 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
805 | { | 761 | { |
@@ -834,7 +790,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
834 | size_t msize; | 790 | size_t msize; |
835 | 791 | ||
836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
837 | "Adding address for peer `%s', plugin `%s', session %p id %u\n", | 793 | "Updating address for peer `%s', plugin `%s', session %p slot %u\n", |
838 | GNUNET_i2s (&ar->address->peer), | 794 | GNUNET_i2s (&ar->address->peer), |
839 | ar->address->transport_name, | 795 | ar->address->transport_name, |
840 | ar->session, | 796 | ar->session, |
@@ -861,29 +817,6 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
861 | } | 817 | } |
862 | 818 | ||
863 | 819 | ||
864 | /** | ||
865 | * An address is now in use or not used any more. | ||
866 | * | ||
867 | * @param ar the address | ||
868 | * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO | ||
869 | * if address is not used any more | ||
870 | */ | ||
871 | void | ||
872 | GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar, | ||
873 | int in_use) | ||
874 | { | ||
875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
876 | "Setting address used to %s for peer `%s', plugin `%s', session %p\n", | ||
877 | (GNUNET_YES == in_use) ? "YES" : "NO", | ||
878 | GNUNET_i2s (&ar->address->peer), | ||
879 | ar->address->transport_name, | ||
880 | ar->session); | ||
881 | ar->in_use = in_use; | ||
882 | if (NULL == ar->sh->mq) | ||
883 | return; | ||
884 | send_in_use_message (ar, in_use); | ||
885 | } | ||
886 | |||
887 | 820 | ||
888 | /** | 821 | /** |
889 | * An address got destroyed, stop using it as a valid address. | 822 | * An address got destroyed, stop using it as a valid address. |
@@ -898,9 +831,10 @@ GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar) | |||
898 | struct AddressDestroyedMessage *m; | 831 | struct AddressDestroyedMessage *m; |
899 | 832 | ||
900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
901 | "Deleting address for peer `%s', plugin `%s', session %p\n", | 834 | "Deleting address for peer `%s', plugin `%s', slot %u session %p\n", |
902 | GNUNET_i2s (&ar->address->peer), | 835 | GNUNET_i2s (&ar->address->peer), |
903 | ar->address->transport_name, | 836 | ar->address->transport_name, |
837 | ar->slot, | ||
904 | ar->session); | 838 | ar->session); |
905 | GNUNET_break (NULL == ar->session); | 839 | GNUNET_break (NULL == ar->session); |
906 | ar->session = NULL; | 840 | ar->session = NULL; |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 83fa42b35..944db77f6 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -165,9 +165,6 @@ run (void *cls, | |||
165 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, 0}, | 165 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, 0}, |
166 | {&GAS_handle_address_update, NULL, | 166 | {&GAS_handle_address_update, NULL, |
167 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, | 167 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0}, |
168 | {&GAS_handle_address_in_use, NULL, | ||
169 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, | ||
170 | sizeof (struct AddressUseMessage) }, | ||
171 | {&GAS_handle_address_destroyed, NULL, | 168 | {&GAS_handle_address_destroyed, NULL, |
172 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, | 169 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, |
173 | sizeof (struct AddressDestroyedMessage) }, | 170 | sizeof (struct AddressDestroyedMessage) }, |
@@ -178,9 +175,6 @@ run (void *cls, | |||
178 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, | 175 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, |
179 | {&GAS_handle_preference_feedback, NULL, | 176 | {&GAS_handle_preference_feedback, NULL, |
180 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, 0}, | 177 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, 0}, |
181 | {&GAS_handle_reset_backoff, NULL, | ||
182 | GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF, | ||
183 | sizeof (struct ResetBackoffMessage)}, | ||
184 | {NULL, NULL, 0, 0} | 178 | {NULL, NULL, 0, 0} |
185 | }; | 179 | }; |
186 | GSA_server = server; | 180 | GSA_server = server; |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 8b38120cc..1d2c9d3e5 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2011-2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * NOTE: Do not change this documentation. This documentation is based on | 39 | * NOTE: Do not change this documentation. This documentation is based on |
40 | * gnunet.org:/vcs/fsnsg/ats-paper.git/tech-doku/ats-tech-guide.tex | 40 | * gnunet.org:/vcs/fsnsg/2014-p2p-ats.git/tech-doku/ats-tech-guide.tex |
41 | * use build_txt.sh to generate plaintext output | 41 | * use build_txt.sh to generate plaintext output |
42 | * | 42 | * |
43 | * 1 ATS addresses : ATS address management | 43 | * 1 ATS addresses : ATS address management |
@@ -192,22 +192,10 @@ | |||
192 | * available it will not respond at all If the client is not interested | 192 | * available it will not respond at all If the client is not interested |
193 | * anymore, it has to cancel the address suggestion request. | 193 | * anymore, it has to cancel the address suggestion request. |
194 | * | 194 | * |
195 | * 1.7.6 Suggestions blocks and reset | 195 | * 1.7.6 Address lifecycle |
196 | * | ||
197 | * After suggesting an address it is blocked for ATS_BLOCKING_DELTA sec. to | ||
198 | * prevent the client from being thrashed. If the client requires immediately | ||
199 | * it can reset this block using GAS_addresses_handle_backoff_reset. | ||
200 | * | ||
201 | * 1.7.7 Marking address in use | ||
202 | * | ||
203 | * The client can notify addresses that it successfully uses an address and | ||
204 | * wants this address to be kept by calling GSA_address_in_use. Adresses will | ||
205 | * mark the address as used an notify the solver about the use. | ||
206 | * | ||
207 | * 1.7.8 Address lifecycle | ||
208 | * | 196 | * |
209 | * * (add address) | 197 | * * (add address) |
210 | * * (updated address) || (address in use) | 198 | * * (updated address) |
211 | * * (delete address) | 199 | * * (delete address) |
212 | * | 200 | * |
213 | * 1.8 Bandwidth assignment | 201 | * 1.8 Bandwidth assignment |
@@ -302,7 +290,9 @@ static int ats_mode; | |||
302 | static void *solver; | 290 | static void *solver; |
303 | 291 | ||
304 | /** | 292 | /** |
305 | * Address suggestion requests DLL head | 293 | * Address suggestion requests DLL head. |
294 | * FIXME: This must become a Multipeermap! O(n) operations | ||
295 | * galore instead of O(1)!!! | ||
306 | */ | 296 | */ |
307 | static struct GAS_Addresses_Suggestion_Requests *pending_requests_head; | 297 | static struct GAS_Addresses_Suggestion_Requests *pending_requests_head; |
308 | 298 | ||
@@ -1086,66 +1076,6 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
1086 | 1076 | ||
1087 | 1077 | ||
1088 | /** | 1078 | /** |
1089 | * Notification about active use of an address. | ||
1090 | * in_use == #GNUNET_YES: | ||
1091 | * This address is used to maintain an active connection with a peer. | ||
1092 | * in_use == #GNUNET_NO: | ||
1093 | * This address is no longer used to maintain an active connection with a peer. | ||
1094 | * | ||
1095 | * Note: can only be called with in_use == #GNUNET_NO if called with #GNUNET_YES | ||
1096 | * before | ||
1097 | * | ||
1098 | * @param peer peer | ||
1099 | * @param session_id session id, can be 0 | ||
1100 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME | ||
1101 | * @return #GNUNET_SYSERR on failure (address unknown ...) | ||
1102 | */ | ||
1103 | int | ||
1104 | GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | ||
1105 | uint32_t session_id, | ||
1106 | int in_use) | ||
1107 | { | ||
1108 | struct ATS_Address *ea; | ||
1109 | |||
1110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1111 | "Received `%s' for peer `%s'\n", | ||
1112 | "ADDRESS IN USE", | ||
1113 | GNUNET_i2s (peer)); | ||
1114 | if (GNUNET_NO == running) | ||
1115 | return GNUNET_SYSERR; | ||
1116 | ea = find_exact_address (peer, | ||
1117 | session_id); | ||
1118 | if (NULL == ea) | ||
1119 | { | ||
1120 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1121 | "Trying to set unknown address `%s' `%u' to %s \n", | ||
1122 | GNUNET_i2s (peer), | ||
1123 | session_id, | ||
1124 | (GNUNET_NO == in_use) ? "NO" : "YES"); | ||
1125 | GNUNET_break (0); | ||
1126 | return GNUNET_SYSERR; | ||
1127 | } | ||
1128 | if (ea->used == in_use) | ||
1129 | { | ||
1130 | GNUNET_break (0); | ||
1131 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1132 | "Address in use called multiple times for peer `%s': %s -> %s \n", | ||
1133 | GNUNET_i2s (peer), | ||
1134 | (GNUNET_NO == ea->used) ? "NO" : "YES", | ||
1135 | (GNUNET_NO == in_use) ? "NO" : "YES"); | ||
1136 | return GNUNET_SYSERR; | ||
1137 | } | ||
1138 | /* Tell solver about update */ | ||
1139 | ea->used = in_use; | ||
1140 | ea->t_last_activity = GNUNET_TIME_absolute_get(); | ||
1141 | env.sf.s_address_update_inuse (solver, | ||
1142 | ea, | ||
1143 | ea->used); | ||
1144 | return GNUNET_OK; | ||
1145 | } | ||
1146 | |||
1147 | |||
1148 | /** | ||
1149 | * Cancel address suggestions for a peer | 1079 | * Cancel address suggestions for a peer |
1150 | * | 1080 | * |
1151 | * @param peer the peer id | 1081 | * @param peer the peer id |
@@ -1169,16 +1099,15 @@ GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer) | |||
1169 | 1099 | ||
1170 | if (NULL == cur) | 1100 | if (NULL == cur) |
1171 | { | 1101 | { |
1172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1173 | "No address requests pending for peer `%s', cannot remove!\n", | 1103 | "No address requests pending for peer `%s', cannot remove!\n", |
1174 | GNUNET_i2s (peer)); | 1104 | GNUNET_i2s (peer)); |
1175 | return; | 1105 | return; |
1176 | } | 1106 | } |
1177 | env.sf.s_get_stop (solver, peer); | 1107 | env.sf.s_get_stop (solver, peer); |
1178 | GAS_addresses_handle_backoff_reset (peer); | 1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1179 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1109 | "Removed request pending for peer `%s\n", |
1180 | "Removed request pending for peer `%s\n", | 1110 | GNUNET_i2s (peer)); |
1181 | GNUNET_i2s (peer)); | ||
1182 | GNUNET_CONTAINER_DLL_remove (pending_requests_head, | 1111 | GNUNET_CONTAINER_DLL_remove (pending_requests_head, |
1183 | pending_requests_tail, | 1112 | pending_requests_tail, |
1184 | cur); | 1113 | cur); |
@@ -1213,10 +1142,10 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | |||
1213 | if (NULL == cur) | 1142 | if (NULL == cur) |
1214 | { | 1143 | { |
1215 | cur = GNUNET_new (struct GAS_Addresses_Suggestion_Requests); | 1144 | cur = GNUNET_new (struct GAS_Addresses_Suggestion_Requests); |
1216 | cur->id = (*peer); | 1145 | cur->id = *peer; |
1217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1218 | "Adding new address suggestion request for `%s'\n", | 1147 | "Adding new address suggestion request for `%s'\n", |
1219 | GNUNET_i2s (peer)); | 1148 | GNUNET_i2s (peer)); |
1220 | GNUNET_CONTAINER_DLL_insert (pending_requests_head, | 1149 | GNUNET_CONTAINER_DLL_insert (pending_requests_head, |
1221 | pending_requests_tail, | 1150 | pending_requests_tail, |
1222 | cur); | 1151 | cur); |
@@ -1249,55 +1178,6 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | |||
1249 | aa->block_interval); | 1178 | aa->block_interval); |
1250 | } | 1179 | } |
1251 | 1180 | ||
1252 | /** | ||
1253 | * Iterator to reset address blocking | ||
1254 | * | ||
1255 | * @param cls not used | ||
1256 | * @param key the peer | ||
1257 | * @param value the address to reset | ||
1258 | * @return #GNUNET_OK to continue | ||
1259 | */ | ||
1260 | static int | ||
1261 | reset_address_it (void *cls, | ||
1262 | const struct GNUNET_PeerIdentity *key, | ||
1263 | void *value) | ||
1264 | { | ||
1265 | struct ATS_Address *aa = value; | ||
1266 | |||
1267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1268 | "Resetting interval for peer `%s' address %p from %llu to 0\n", | ||
1269 | GNUNET_i2s (&aa->peer), | ||
1270 | aa, | ||
1271 | aa->block_interval); | ||
1272 | aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1273 | aa->block_interval = GNUNET_TIME_UNIT_ZERO; | ||
1274 | return GNUNET_OK; | ||
1275 | } | ||
1276 | |||
1277 | |||
1278 | /** | ||
1279 | * Reset suggestion backoff for a peer | ||
1280 | * | ||
1281 | * Suggesting addresses is blocked for ATS_BLOCKING_DELTA. Blocking can be | ||
1282 | * reset using this function | ||
1283 | * | ||
1284 | * @param peer the peer id | ||
1285 | */ | ||
1286 | void | ||
1287 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer) | ||
1288 | { | ||
1289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1290 | "Received `%s' for peer `%s'\n", | ||
1291 | "RESET BACKOFF", | ||
1292 | GNUNET_i2s (peer)); | ||
1293 | |||
1294 | GNUNET_break(GNUNET_SYSERR != | ||
1295 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, | ||
1296 | peer, | ||
1297 | &reset_address_it, | ||
1298 | NULL)); | ||
1299 | } | ||
1300 | |||
1301 | 1181 | ||
1302 | /** | 1182 | /** |
1303 | * Solver information callback | 1183 | * Solver information callback |
@@ -1741,7 +1621,9 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
1741 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 1621 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); |
1742 | 1622 | ||
1743 | for (cur = pending_requests_head;NULL != cur; cur = cur->next) | 1623 | for (cur = pending_requests_head;NULL != cur; cur = cur->next) |
1744 | if (0 == memcmp (&address->peer, &cur->id, sizeof(cur->id))) | 1624 | if (0 == memcmp (&address->peer, |
1625 | &cur->id, | ||
1626 | sizeof(cur->id))) | ||
1745 | break; /* we have an address request pending*/ | 1627 | break; /* we have an address request pending*/ |
1746 | if (NULL == cur) | 1628 | if (NULL == cur) |
1747 | { | 1629 | { |
@@ -1891,10 +1773,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1891 | GNUNET_asprintf (&plugin, | 1773 | GNUNET_asprintf (&plugin, |
1892 | "libgnunet_plugin_ats_%s", | 1774 | "libgnunet_plugin_ats_%s", |
1893 | plugin_short); | 1775 | plugin_short); |
1894 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1895 | _("Initializing solver `%s '`%s'\n"), | 1777 | "Initializing solver `%s '`%s'\n", |
1896 | plugin_short, | 1778 | plugin_short, |
1897 | plugin); | 1779 | plugin); |
1898 | if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env))) | 1780 | if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env))) |
1899 | { | 1781 | { |
1900 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1782 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1904,7 +1786,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1904 | } | 1786 | } |
1905 | 1787 | ||
1906 | GNUNET_assert (NULL != env.sf.s_add); | 1788 | GNUNET_assert (NULL != env.sf.s_add); |
1907 | GNUNET_assert (NULL != env.sf.s_address_update_inuse); | ||
1908 | GNUNET_assert (NULL != env.sf.s_address_update_property); | 1789 | GNUNET_assert (NULL != env.sf.s_address_update_property); |
1909 | GNUNET_assert (NULL != env.sf.s_address_update_session); | 1790 | GNUNET_assert (NULL != env.sf.s_address_update_session); |
1910 | GNUNET_assert (NULL != env.sf.s_address_update_network); | 1791 | GNUNET_assert (NULL != env.sf.s_address_update_network); |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 2f21ae380..8892f77c4 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -196,16 +196,10 @@ | |||
196 | * prevent the client from being thrashed. If the client requires immediately | 196 | * prevent the client from being thrashed. If the client requires immediately |
197 | * it can reset this block using GAS_addresses_handle_backoff_reset. | 197 | * it can reset this block using GAS_addresses_handle_backoff_reset. |
198 | * | 198 | * |
199 | * 1.7.7 Marking address in use | 199 | * 1.7.7 Address lifecycle |
200 | * | ||
201 | * The client can notify addresses that it successfully uses an address and | ||
202 | * wants this address to be kept by calling GSA_address_in_use. Adresses will | ||
203 | * mark the address as used an notify the solver about the use. | ||
204 | * | ||
205 | * 1.7.8 Address lifecycle | ||
206 | * | 200 | * |
207 | * * (add address) | 201 | * * (add address) |
208 | * * (updated address) || (address in use) | 202 | * * (updated address) |
209 | * * (delete address) | 203 | * * (delete address) |
210 | * | 204 | * |
211 | * 1.8 Bandwidth assignment | 205 | * 1.8 Bandwidth assignment |
@@ -454,27 +448,6 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
454 | 448 | ||
455 | 449 | ||
456 | /** | 450 | /** |
457 | * Notification about active use of an address. | ||
458 | * in_use == #GNUNET_YES: | ||
459 | * This address is used to maintain an active connection with a peer. | ||
460 | * in_use == #GNUNET_NO: | ||
461 | * This address is no longer used to maintain an active connection with a peer. | ||
462 | * | ||
463 | * Note: can only be called with in_use == #GNUNET_NO if called with #GNUNET_YES | ||
464 | * before | ||
465 | * | ||
466 | * @param peer peer | ||
467 | * @param session_id session id, can never be 0 | ||
468 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME | ||
469 | * @return #GNUNET_SYSERR on failure (address unknown ...) | ||
470 | */ | ||
471 | int | ||
472 | GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | ||
473 | uint32_t session_id, | ||
474 | int in_use); | ||
475 | |||
476 | |||
477 | /** | ||
478 | * Update an address with new performance information for a peer. | 451 | * Update an address with new performance information for a peer. |
479 | * | 452 | * |
480 | * @param peer peer | 453 | * @param peer peer |
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 6b6b6c24f..9d7562e7b 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c | |||
@@ -120,30 +120,6 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
120 | 120 | ||
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Handle 'reset backoff' messages from clients. | ||
124 | * | ||
125 | * @param cls unused, NULL | ||
126 | * @param client client that sent the request | ||
127 | * @param message the request message | ||
128 | */ | ||
129 | void | ||
130 | GAS_handle_reset_backoff (void *cls, | ||
131 | struct GNUNET_SERVER_Client *client, | ||
132 | const struct GNUNET_MessageHeader *message) | ||
133 | { | ||
134 | const struct ResetBackoffMessage *msg = | ||
135 | (const struct ResetBackoffMessage *) message; | ||
136 | |||
137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
138 | "Received `%s' message\n", | ||
139 | "RESET_BACKOFF"); | ||
140 | GNUNET_break (0 == ntohl (msg->reserved)); | ||
141 | GAS_addresses_handle_backoff_reset (&msg->peer); | ||
142 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
143 | } | ||
144 | |||
145 | |||
146 | /** | ||
147 | * Handle 'address add' messages from clients. | 123 | * Handle 'address add' messages from clients. |
148 | * | 124 | * |
149 | * @param cls unused, NULL | 125 | * @param cls unused, NULL |
@@ -262,35 +238,6 @@ GAS_handle_address_update (void *cls, | |||
262 | 238 | ||
263 | 239 | ||
264 | /** | 240 | /** |
265 | * Handle 'address in use' messages from clients. | ||
266 | * | ||
267 | * @param cls unused, NULL | ||
268 | * @param client client that sent the request | ||
269 | * @param message the request message | ||
270 | */ | ||
271 | void | ||
272 | GAS_handle_address_in_use (void *cls, | ||
273 | struct GNUNET_SERVER_Client *client, | ||
274 | const struct GNUNET_MessageHeader *message) | ||
275 | { | ||
276 | const struct AddressUseMessage *m; | ||
277 | int res; | ||
278 | |||
279 | m = (const struct AddressUseMessage *) message; | ||
280 | res = GAS_addresses_in_use (&m->peer, | ||
281 | ntohl (m->session_id), | ||
282 | ntohl (m->in_use)); | ||
283 | if (GNUNET_OK != res) | ||
284 | { | ||
285 | GNUNET_break (0); | ||
286 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
287 | return; | ||
288 | } | ||
289 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
290 | } | ||
291 | |||
292 | |||
293 | /** | ||
294 | * Handle 'address destroyed' messages from clients. | 241 | * Handle 'address destroyed' messages from clients. |
295 | * | 242 | * |
296 | * @param cls unused, NULL | 243 | * @param cls unused, NULL |
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c index 75bb76dde..15fa5e6bd 100644 --- a/src/ats/plugin_ats_mlp.c +++ b/src/ats/plugin_ats_mlp.c | |||
@@ -2064,25 +2064,6 @@ GAS_mlp_address_session_changed (void *solver, | |||
2064 | 2064 | ||
2065 | 2065 | ||
2066 | /** | 2066 | /** |
2067 | * Transport session for this address has changed | ||
2068 | * | ||
2069 | * NOTE: values in addresses are already updated | ||
2070 | * | ||
2071 | * @param solver solver handle | ||
2072 | * @param address the address | ||
2073 | * @param in_use usage state | ||
2074 | */ | ||
2075 | static void | ||
2076 | GAS_mlp_address_inuse_changed (void *solver, | ||
2077 | struct ATS_Address *address, | ||
2078 | int in_use) | ||
2079 | { | ||
2080 | /* Nothing to do here */ | ||
2081 | return; | ||
2082 | } | ||
2083 | |||
2084 | |||
2085 | /** | ||
2086 | * Network scope for this address has changed | 2067 | * Network scope for this address has changed |
2087 | * | 2068 | * |
2088 | * NOTE: values in addresses are already updated | 2069 | * NOTE: values in addresses are already updated |
@@ -2973,7 +2954,6 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2973 | env->sf.s_add = &GAS_mlp_address_add; | 2954 | env->sf.s_add = &GAS_mlp_address_add; |
2974 | env->sf.s_address_update_property = &GAS_mlp_address_property_changed; | 2955 | env->sf.s_address_update_property = &GAS_mlp_address_property_changed; |
2975 | env->sf.s_address_update_session = &GAS_mlp_address_session_changed; | 2956 | env->sf.s_address_update_session = &GAS_mlp_address_session_changed; |
2976 | env->sf.s_address_update_inuse = &GAS_mlp_address_inuse_changed; | ||
2977 | env->sf.s_address_update_network = &GAS_mlp_address_change_network; | 2957 | env->sf.s_address_update_network = &GAS_mlp_address_change_network; |
2978 | env->sf.s_get = &GAS_mlp_get_preferred_address; | 2958 | env->sf.s_get = &GAS_mlp_get_preferred_address; |
2979 | env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address; | 2959 | env->sf.s_get_stop = &GAS_mlp_stop_get_preferred_address; |
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 64dca90c5..7bcc948b7 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -50,7 +50,7 @@ | |||
50 | * outbound quota is configured and the bandwidth available in | 50 | * outbound quota is configured and the bandwidth available in |
51 | * these networks is distributed over the addresses. The solver | 51 | * these networks is distributed over the addresses. The solver |
52 | * first assigns every addresses the minimum amount of bandwidth | 52 | * first assigns every addresses the minimum amount of bandwidth |
53 | * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT and then distributes the | 53 | * #GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT and then distributes the |
54 | * remaining bandwidth available according to the preference | 54 | * remaining bandwidth available according to the preference |
55 | * values. For each peer only a single address gets bandwidth | 55 | * values. For each peer only a single address gets bandwidth |
56 | * assigned and only one address marked as active. The most | 56 | * assigned and only one address marked as active. The most |
@@ -104,7 +104,7 @@ | |||
104 | * solver is when an address switches network it is located | 104 | * solver is when an address switches network it is located |
105 | * in. This is common because addresses added by transport's | 105 | * in. This is common because addresses added by transport's |
106 | * validation mechanism are commonly located in | 106 | * validation mechanism are commonly located in |
107 | * GNUNET_ATS_NET_UNSPECIFIED. Addresses in validation are located | 107 | * #GNUNET_ATS_NET_UNSPECIFIED. Addresses in validation are located |
108 | * in this network type and only if a connection is successful on | 108 | * in this network type and only if a connection is successful on |
109 | * return of payload data transport switches to the real network | 109 | * return of payload data transport switches to the real network |
110 | * the address is located in. When an address changes networks it | 110 | * the address is located in. When an address changes networks it |
@@ -155,9 +155,9 @@ | |||
155 | * the best available address. Several checks are done when an | 155 | * the best available address. Several checks are done when an |
156 | * address is selected. First if this address is currently blocked | 156 | * address is selected. First if this address is currently blocked |
157 | * by addresses from being suggested. An address is blocked for the | 157 | * by addresses from being suggested. An address is blocked for the |
158 | * duration of ATS_BLOCKING_DELTA when it is suggested to | 158 | * duration of #ATS_BLOCKING_DELTA when it is suggested to |
159 | * transport. Next it is checked if at least | 159 | * transport. Next it is checked if at least |
160 | * GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT bytes bandwidth is available | 160 | * #GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT bytes bandwidth is available |
161 | * in the addresse's network, because suggesting an address without | 161 | * in the addresse's network, because suggesting an address without |
162 | * bandwidth does not make sense. This also ensures that all active | 162 | * bandwidth does not make sense. This also ensures that all active |
163 | * addresses in this network get at least the minimum amount of | 163 | * addresses in this network get at least the minimum amount of |
@@ -322,13 +322,11 @@ struct Network | |||
322 | 322 | ||
323 | /** | 323 | /** |
324 | * Total inbound quota | 324 | * Total inbound quota |
325 | * | ||
326 | */ | 325 | */ |
327 | unsigned long long total_quota_in; | 326 | unsigned long long total_quota_in; |
328 | 327 | ||
329 | /** | 328 | /** |
330 | * Total outbound quota | 329 | * Total outbound quota |
331 | * | ||
332 | */ | 330 | */ |
333 | unsigned long long total_quota_out; | 331 | unsigned long long total_quota_out; |
334 | 332 | ||
@@ -375,13 +373,11 @@ struct AddressSolverInformation | |||
375 | 373 | ||
376 | /** | 374 | /** |
377 | * Inbound quota | 375 | * Inbound quota |
378 | * | ||
379 | */ | 376 | */ |
380 | uint32_t calculated_quota_in; | 377 | uint32_t calculated_quota_in; |
381 | 378 | ||
382 | /** | 379 | /** |
383 | * Outbound quota | 380 | * Outbound quota |
384 | * | ||
385 | */ | 381 | */ |
386 | uint32_t calculated_quota_out; | 382 | uint32_t calculated_quota_out; |
387 | 383 | ||
@@ -427,7 +423,6 @@ libgnunet_plugin_ats_proportional_done (void *cls) | |||
427 | struct AddressWrapper *next; | 423 | struct AddressWrapper *next; |
428 | int c; | 424 | int c; |
429 | 425 | ||
430 | GNUNET_assert(s != NULL); | ||
431 | for (c = 0; c < s->network_count; c++) | 426 | for (c = 0; c < s->network_count; c++) |
432 | { | 427 | { |
433 | if (s->network_entries[c].total_addresses > 0) | 428 | if (s->network_entries[c].total_addresses > 0) |
@@ -515,11 +510,10 @@ is_bandwidth_available_in_network (struct Network *net) | |||
515 | */ | 510 | */ |
516 | static void | 511 | static void |
517 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | 512 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, |
518 | struct Network *net) | 513 | struct Network *net) |
519 | { | 514 | { |
520 | struct AddressSolverInformation *asi; | 515 | struct AddressSolverInformation *asi; |
521 | struct AddressWrapper *cur_address; | 516 | struct AddressWrapper *cur_address; |
522 | |||
523 | unsigned long long remaining_quota_in = 0; | 517 | unsigned long long remaining_quota_in = 0; |
524 | unsigned long long quota_out_used = 0; | 518 | unsigned long long quota_out_used = 0; |
525 | unsigned long long remaining_quota_out = 0; | 519 | unsigned long long remaining_quota_out = 0; |
@@ -537,10 +531,12 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
537 | uint32_t assigned_quota_out = 0; | 531 | uint32_t assigned_quota_out = 0; |
538 | 532 | ||
539 | 533 | ||
540 | LOG(GNUNET_ERROR_TYPE_INFO, | 534 | LOG (GNUNET_ERROR_TYPE_INFO, |
541 | "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", | 535 | "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", |
542 | net->desc, net->active_addresses, net->total_quota_in, | 536 | net->desc, |
543 | net->total_quota_in); | 537 | net->active_addresses, |
538 | net->total_quota_in, | ||
539 | net->total_quota_in); | ||
544 | 540 | ||
545 | if (net->active_addresses == 0) | 541 | if (net->active_addresses == 0) |
546 | { | 542 | { |
@@ -803,7 +799,6 @@ find_best_address_it (void *cls, | |||
803 | /* user shorter distance */ | 799 | /* user shorter distance */ |
804 | if (cur_distance < best_distance) | 800 | if (cur_distance < best_distance) |
805 | { | 801 | { |
806 | |||
807 | if (GNUNET_NO == ctx->best->active) | 802 | if (GNUNET_NO == ctx->best->active) |
808 | { | 803 | { |
809 | current_best = current; /* Use current */ | 804 | current_best = current; /* Use current */ |
@@ -864,9 +859,10 @@ get_best_address (struct GAS_PROPORTIONAL_Handle *s, | |||
864 | 859 | ||
865 | fba_ctx.best = NULL; | 860 | fba_ctx.best = NULL; |
866 | fba_ctx.s = s; | 861 | fba_ctx.s = s; |
867 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, id, | 862 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, |
868 | &find_best_address_it, &fba_ctx); | 863 | id, |
869 | 864 | &find_best_address_it, | |
865 | &fba_ctx); | ||
870 | return fba_ctx.best; | 866 | return fba_ctx.best; |
871 | } | 867 | } |
872 | 868 | ||
@@ -1203,7 +1199,7 @@ distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | |||
1203 | * @param peer the peer to check | 1199 | * @param peer the peer to check |
1204 | * return the new address or NULL if no update was performed | 1200 | * return the new address or NULL if no update was performed |
1205 | */ | 1201 | */ |
1206 | static const struct ATS_Address * | 1202 | static struct ATS_Address * |
1207 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, | 1203 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, |
1208 | const struct GNUNET_PeerIdentity *peer) | 1204 | const struct GNUNET_PeerIdentity *peer) |
1209 | { | 1205 | { |
@@ -1217,27 +1213,38 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1217 | GNUNET_i2s (peer)); | 1213 | GNUNET_i2s (peer)); |
1218 | 1214 | ||
1219 | /* Find active address */ | 1215 | /* Find active address */ |
1220 | current_address = get_active_address (s, s->addresses, peer); | 1216 | current_address = get_active_address (s, |
1217 | s->addresses, | ||
1218 | peer); | ||
1221 | 1219 | ||
1222 | LOG (GNUNET_ERROR_TYPE_INFO, "Peer `%s' has active address %p\n", | 1220 | LOG (GNUNET_ERROR_TYPE_INFO, |
1223 | GNUNET_i2s (peer), current_address); | 1221 | "Peer `%s' has active address %p\n", |
1222 | GNUNET_i2s (peer), | ||
1223 | current_address); | ||
1224 | 1224 | ||
1225 | /* Find best address */ | 1225 | /* Find best address */ |
1226 | best_address = get_best_address (s,s->addresses, peer); | 1226 | best_address = get_best_address (s, |
1227 | LOG (GNUNET_ERROR_TYPE_INFO, "Peer `%s' has best address %p\n", | 1227 | s->addresses, |
1228 | GNUNET_i2s (peer), best_address); | 1228 | peer); |
1229 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1230 | "Peer `%s' has best address %p\n", | ||
1231 | GNUNET_i2s (peer), | ||
1232 | best_address); | ||
1229 | 1233 | ||
1230 | if (NULL != current_address) | 1234 | if (NULL != current_address) |
1231 | { | 1235 | { |
1232 | if ((NULL == best_address) || ((NULL != best_address) && | 1236 | if ( (NULL == best_address) || |
1233 | (GNUNET_NO == address_eq (current_address, best_address)))) | 1237 | ( (NULL != best_address) && |
1238 | (GNUNET_NO == address_eq (current_address, | ||
1239 | best_address)) ) ) | ||
1234 | { | 1240 | { |
1235 | /* We switch to a new address, mark old address as inactive */ | 1241 | /* We switch to a new address (or to none), |
1242 | mark old address as inactive */ | ||
1236 | LOG (GNUNET_ERROR_TYPE_INFO, | 1243 | LOG (GNUNET_ERROR_TYPE_INFO, |
1237 | "Disabling previous %s address %p for peer `%s'\n", | 1244 | "Disabling previous %s address %p for peer `%s'\n", |
1238 | (GNUNET_NO == current_address->active) ? "inactive" : "active", | 1245 | (GNUNET_NO == current_address->active) ? "inactive" : "active", |
1239 | current_address, | 1246 | current_address, |
1240 | GNUNET_i2s (peer)); | 1247 | GNUNET_i2s (peer)); |
1241 | 1248 | ||
1242 | asi = current_address->solver_information; | 1249 | asi = current_address->solver_information; |
1243 | GNUNET_assert (NULL != asi); | 1250 | GNUNET_assert (NULL != asi); |
@@ -1258,32 +1265,31 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1258 | { | 1265 | { |
1259 | /* We previously had an active address, but now we cannot suggest one | 1266 | /* We previously had an active address, but now we cannot suggest one |
1260 | * Therefore we have to disconnect the peer */ | 1267 | * Therefore we have to disconnect the peer */ |
1261 | |||
1262 | LOG (GNUNET_ERROR_TYPE_INFO, | 1268 | LOG (GNUNET_ERROR_TYPE_INFO, |
1263 | "Disconnecting peer `%s' with previous %s address %p\n", | 1269 | "Disconnecting peer `%s' with previous address %p\n", |
1264 | GNUNET_i2s (peer), | 1270 | GNUNET_i2s (peer), |
1265 | (GNUNET_NO == current_address->active) ? "inactive" : "active", | 1271 | current_address); |
1266 | current_address); | 1272 | s->bw_changed (s->bw_changed_cls, |
1267 | s->bw_changed (s->bw_changed_cls, current_address); | 1273 | current_address); |
1268 | } | 1274 | } |
1269 | } | 1275 | } |
1270 | |||
1271 | if (NULL == best_address) | 1276 | if (NULL == best_address) |
1272 | { | 1277 | { |
1273 | LOG (GNUNET_ERROR_TYPE_INFO, "Cannot suggest address for peer `%s'\n", | 1278 | LOG (GNUNET_ERROR_TYPE_INFO, |
1274 | GNUNET_i2s (peer)); | 1279 | "Cannot suggest address for peer `%s'\n", |
1275 | return NULL ; | 1280 | GNUNET_i2s (peer)); |
1281 | return NULL; | ||
1276 | } | 1282 | } |
1277 | 1283 | ||
1278 | LOG (GNUNET_ERROR_TYPE_INFO, "Suggesting %s address %p for peer `%s'\n", | 1284 | LOG (GNUNET_ERROR_TYPE_INFO, |
1279 | (GNUNET_NO == best_address->active) ? "inactive" : "active", best_address, | 1285 | "Suggesting new address %p for peer `%s'\n", |
1280 | GNUNET_i2s (peer)); | 1286 | best_address, |
1287 | GNUNET_i2s (peer)); | ||
1281 | 1288 | ||
1282 | if ((NULL != current_address) && | 1289 | if ( (NULL != current_address) && |
1283 | (GNUNET_YES == address_eq (best_address, current_address))) | 1290 | (GNUNET_YES == address_eq (best_address, current_address)) ) |
1284 | { | 1291 | { |
1285 | if (current_address->active == GNUNET_NO) | 1292 | GNUNET_break (GNUNET_NO != current_address->active); |
1286 | GNUNET_break (0); /* Should never happen */ | ||
1287 | return best_address; /* Same same */ | 1293 | return best_address; /* Same same */ |
1288 | } | 1294 | } |
1289 | 1295 | ||
@@ -1292,11 +1298,13 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
1292 | net = asi->network; | 1298 | net = asi->network; |
1293 | 1299 | ||
1294 | /* Mark address as active */ | 1300 | /* Mark address as active */ |
1295 | asi->activated = GNUNET_TIME_absolute_get(); | 1301 | asi->activated = GNUNET_TIME_absolute_get (); |
1296 | best_address->active = GNUNET_YES; | 1302 | best_address->active = GNUNET_YES; |
1297 | address_increment (s, net, GNUNET_NO, GNUNET_YES); | 1303 | address_increment (s, net, GNUNET_NO, GNUNET_YES); |
1298 | LOG (GNUNET_ERROR_TYPE_INFO, "Address %p for peer `%s' is now active\n", | 1304 | LOG (GNUNET_ERROR_TYPE_INFO, |
1299 | best_address, GNUNET_i2s (peer)); | 1305 | "Address %p for peer `%s' is now active\n", |
1306 | best_address, | ||
1307 | GNUNET_i2s (peer)); | ||
1300 | /* Distribute bandwidth */ | 1308 | /* Distribute bandwidth */ |
1301 | distribute_bandwidth_in_network (s, net); | 1309 | distribute_bandwidth_in_network (s, net); |
1302 | return best_address; | 1310 | return best_address; |
@@ -1322,15 +1330,13 @@ GAS_proportional_address_change_preference (void *solver, | |||
1322 | struct ATS_Address *active_address; | 1330 | struct ATS_Address *active_address; |
1323 | struct AddressSolverInformation *asi; | 1331 | struct AddressSolverInformation *asi; |
1324 | 1332 | ||
1325 | GNUNET_assert(NULL != s); | 1333 | if (GNUNET_NO == |
1326 | GNUNET_assert(NULL != peer); | 1334 | GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) |
1327 | |||
1328 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | ||
1329 | return; /* Peer is not requested */ | 1335 | return; /* Peer is not requested */ |
1330 | 1336 | ||
1331 | /* This peer is requested, find best address */ | 1337 | /* This peer is requested, find best address */ |
1332 | active_address = get_active_address(s, s->addresses, peer); | 1338 | active_address = get_active_address (s, s->addresses, peer); |
1333 | best_address = (struct ATS_Address *) update_active_address (s, peer); | 1339 | best_address = update_active_address (s, peer); |
1334 | 1340 | ||
1335 | if ((NULL != best_address) && ((NULL != active_address) && | 1341 | if ((NULL != best_address) && ((NULL != active_address) && |
1336 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1342 | (GNUNET_YES == address_eq (active_address, best_address)))) |
@@ -1383,18 +1389,18 @@ GAS_proportional_get_preferred_address (void *solver, | |||
1383 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1389 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1384 | const struct ATS_Address *best_address; | 1390 | const struct ATS_Address *best_address; |
1385 | 1391 | ||
1386 | |||
1387 | GNUNET_assert(s != NULL); | ||
1388 | GNUNET_assert(peer != NULL); | ||
1389 | |||
1390 | /* Add to list of pending requests */ | 1392 | /* Add to list of pending requests */ |
1391 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | 1393 | if (GNUNET_NO == |
1394 | GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | ||
1392 | { | 1395 | { |
1393 | GNUNET_assert( | 1396 | GNUNET_assert (GNUNET_OK == |
1394 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (s->requests, peer, NULL, | 1397 | GNUNET_CONTAINER_multipeermap_put (s->requests, |
1398 | peer, | ||
1399 | NULL, | ||
1395 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1400 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1396 | LOG (GNUNET_ERROR_TYPE_INFO, "Start suggesting addresses for peer `%s'\n", | 1401 | LOG (GNUNET_ERROR_TYPE_INFO, |
1397 | GNUNET_i2s (peer)); | 1402 | "Start suggesting addresses for peer `%s'\n", |
1403 | GNUNET_i2s (peer)); | ||
1398 | } | 1404 | } |
1399 | 1405 | ||
1400 | best_address = update_active_address (s, peer); | 1406 | best_address = update_active_address (s, peer); |
@@ -1420,23 +1426,28 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1420 | struct AddressSolverInformation *asi; | 1426 | struct AddressSolverInformation *asi; |
1421 | struct Network *cur_net; | 1427 | struct Network *cur_net; |
1422 | 1428 | ||
1423 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | 1429 | if (GNUNET_YES == |
1430 | GNUNET_CONTAINER_multipeermap_contains (s->requests, peer)) | ||
1424 | { | 1431 | { |
1425 | GNUNET_assert (GNUNET_OK == | 1432 | GNUNET_assert (GNUNET_OK == |
1426 | GNUNET_CONTAINER_multipeermap_remove (s->requests, | 1433 | GNUNET_CONTAINER_multipeermap_remove (s->requests, |
1427 | peer, NULL)); | 1434 | peer, |
1435 | NULL)); | ||
1428 | LOG (GNUNET_ERROR_TYPE_INFO, | 1436 | LOG (GNUNET_ERROR_TYPE_INFO, |
1429 | "Stop suggesting addresses for peer `%s'\n", | 1437 | "Stop suggesting addresses for peer `%s'\n", |
1430 | GNUNET_i2s (peer)); | 1438 | GNUNET_i2s (peer)); |
1431 | } | 1439 | } |
1432 | 1440 | ||
1433 | cur = get_active_address (s, s->addresses, peer); | 1441 | cur = get_active_address (s, |
1442 | s->addresses, | ||
1443 | peer); | ||
1434 | if (NULL != cur) | 1444 | if (NULL != cur) |
1435 | { | 1445 | { |
1436 | LOG(GNUNET_ERROR_TYPE_INFO, | 1446 | LOG (GNUNET_ERROR_TYPE_INFO, |
1437 | "Disabling %s address %p for peer `%s'\n", | 1447 | "Disabling %s address %p for peer `%s'\n", |
1438 | (GNUNET_NO == cur->active) ? "inactive" : "active", cur, | 1448 | (GNUNET_NO == cur->active) ? "inactive" : "active", |
1439 | GNUNET_i2s (&cur->peer)); | 1449 | cur, |
1450 | GNUNET_i2s (&cur->peer)); | ||
1440 | 1451 | ||
1441 | /* Disabling current address */ | 1452 | /* Disabling current address */ |
1442 | asi = cur->solver_information; | 1453 | asi = cur->solver_information; |
@@ -1446,12 +1457,12 @@ GAS_proportional_stop_get_preferred_address (void *solver, | |||
1446 | cur->assigned_bw_in = 0; /* no bandwidth assigned */ | 1457 | cur->assigned_bw_in = 0; /* no bandwidth assigned */ |
1447 | cur->assigned_bw_out = 0; /* no bandwidth assigned */ | 1458 | cur->assigned_bw_out = 0; /* no bandwidth assigned */ |
1448 | 1459 | ||
1449 | if (GNUNET_SYSERR == addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES)) | 1460 | if (GNUNET_SYSERR == |
1461 | addresse_decrement (s, cur_net, GNUNET_NO, GNUNET_YES)) | ||
1450 | GNUNET_break(0); | 1462 | GNUNET_break(0); |
1451 | 1463 | ||
1452 | distribute_bandwidth_in_network (s, cur_net ); | 1464 | distribute_bandwidth_in_network (s, cur_net); |
1453 | } | 1465 | } |
1454 | return; | ||
1455 | } | 1466 | } |
1456 | 1467 | ||
1457 | 1468 | ||
@@ -1490,11 +1501,14 @@ GAS_proportional_address_delete (void *solver, | |||
1490 | 1501 | ||
1491 | if (GNUNET_NO == session_only) | 1502 | if (GNUNET_NO == session_only) |
1492 | { | 1503 | { |
1493 | LOG(GNUNET_ERROR_TYPE_INFO, | 1504 | LOG (GNUNET_ERROR_TYPE_INFO, |
1494 | "Deleting %s address %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", | 1505 | "Deleting %s address %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", |
1495 | (GNUNET_NO == address->active) ? "inactive" : "active", address, | 1506 | (GNUNET_NO == address->active) ? "inactive" : "active", |
1496 | GNUNET_i2s (&address->peer), net->desc, net->total_addresses, | 1507 | address, |
1497 | net->active_addresses); | 1508 | GNUNET_i2s (&address->peer), |
1509 | net->desc, | ||
1510 | net->total_addresses, | ||
1511 | net->active_addresses); | ||
1498 | 1512 | ||
1499 | /* Remove address */ | 1513 | /* Remove address */ |
1500 | addresse_decrement (s, net, GNUNET_YES, GNUNET_NO); | 1514 | addresse_decrement (s, net, GNUNET_YES, GNUNET_NO); |
@@ -1508,42 +1522,48 @@ GAS_proportional_address_delete (void *solver, | |||
1508 | GNUNET_break(0); | 1522 | GNUNET_break(0); |
1509 | return; | 1523 | return; |
1510 | } | 1524 | } |
1511 | GNUNET_CONTAINER_DLL_remove(net->head, net->tail, aw); | 1525 | GNUNET_CONTAINER_DLL_remove (net->head, |
1512 | GNUNET_free(aw); | 1526 | net->tail, |
1527 | aw); | ||
1528 | GNUNET_free (aw); | ||
1513 | } | 1529 | } |
1514 | else | 1530 | else |
1515 | { | 1531 | { |
1516 | /* Remove session only: remove if active and update */ | 1532 | /* Remove session only: remove if active and update */ |
1517 | LOG(GNUNET_ERROR_TYPE_INFO, | 1533 | LOG (GNUNET_ERROR_TYPE_INFO, |
1518 | "Deleting %s session %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", | 1534 | "Deleting %s session %p for peer `%s' from network `%s' (total: %u/ active: %u)\n", |
1519 | (GNUNET_NO == address->active) ? "inactive" : "active", address, | 1535 | (GNUNET_NO == address->active) ? "inactive" : "active", |
1520 | GNUNET_i2s (&address->peer), net->desc, net->total_addresses, | 1536 | address, |
1521 | net->active_addresses); | 1537 | GNUNET_i2s (&address->peer), |
1538 | net->desc, | ||
1539 | net->total_addresses, | ||
1540 | net->active_addresses); | ||
1522 | } | 1541 | } |
1523 | 1542 | ||
1524 | if (GNUNET_YES == address->active) | 1543 | if (GNUNET_YES == address->active) |
1525 | { | 1544 | { |
1526 | /* Address was active, remove from network and update quotas*/ | 1545 | /* Address was active, remove from network and update quotas*/ |
1527 | address->active = GNUNET_NO; | 1546 | address->active = GNUNET_NO; |
1528 | |||
1529 | address->assigned_bw_in = 0; | 1547 | address->assigned_bw_in = 0; |
1530 | address->assigned_bw_out = 0; | 1548 | address->assigned_bw_out = 0; |
1531 | asi->calculated_quota_in = 0; | 1549 | asi->calculated_quota_in = 0; |
1532 | asi->calculated_quota_out = 0; | 1550 | asi->calculated_quota_out = 0; |
1533 | 1551 | ||
1534 | if (GNUNET_SYSERR == addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) | 1552 | if (GNUNET_SYSERR == |
1553 | addresse_decrement (s, net, GNUNET_NO, GNUNET_YES)) | ||
1535 | GNUNET_break(0); | 1554 | GNUNET_break(0); |
1536 | distribute_bandwidth_in_network (s, net); | 1555 | distribute_bandwidth_in_network (s, net); |
1537 | 1556 | ||
1538 | if (NULL == update_active_address (s, &address->peer)) | 1557 | if (NULL == |
1558 | update_active_address (s, &address->peer)) | ||
1539 | { | 1559 | { |
1540 | /* No alternative address found, disconnect peer */ | 1560 | /* No alternative address found, disconnect peer */ |
1541 | LOG (GNUNET_ERROR_TYPE_INFO, | 1561 | LOG (GNUNET_ERROR_TYPE_INFO, |
1542 | "Disconnecting peer `%s' after deleting previous %s address %p\n", | 1562 | "Disconnecting peer `%s' after deleting previous address %p\n", |
1543 | GNUNET_i2s (&address->peer), | 1563 | GNUNET_i2s (&address->peer), |
1544 | (GNUNET_NO == address->active) ? "inactive" : "active", | 1564 | address); |
1545 | address); | 1565 | s->bw_changed (s->bw_changed_cls, |
1546 | s->bw_changed (s->bw_changed_cls, address); | 1566 | address); |
1547 | } | 1567 | } |
1548 | } | 1568 | } |
1549 | if (GNUNET_NO == session_only) | 1569 | if (GNUNET_NO == session_only) |
@@ -1552,10 +1572,11 @@ GAS_proportional_address_delete (void *solver, | |||
1552 | address->solver_information = NULL; | 1572 | address->solver_information = NULL; |
1553 | } | 1573 | } |
1554 | 1574 | ||
1555 | LOG(GNUNET_ERROR_TYPE_INFO, | 1575 | LOG (GNUNET_ERROR_TYPE_INFO, |
1556 | "After deleting address now total %u and active %u addresses in network `%s'\n", | 1576 | "After deleting address now total %u and active %u addresses in network `%s'\n", |
1557 | net->total_addresses, net->active_addresses, net->desc); | 1577 | net->total_addresses, |
1558 | 1578 | net->active_addresses, | |
1579 | net->desc); | ||
1559 | } | 1580 | } |
1560 | 1581 | ||
1561 | 1582 | ||
@@ -1571,7 +1592,7 @@ GAS_proportional_bulk_start (void *solver) | |||
1571 | 1592 | ||
1572 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1593 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1573 | "Locking solver for bulk operation ...\n"); | 1594 | "Locking solver for bulk operation ...\n"); |
1574 | GNUNET_assert(NULL != solver); | 1595 | GNUNET_assert (NULL != solver); |
1575 | s->bulk_lock++; | 1596 | s->bulk_lock++; |
1576 | } | 1597 | } |
1577 | 1598 | ||
@@ -1586,8 +1607,6 @@ GAS_proportional_bulk_stop (void *solver) | |||
1586 | 1607 | ||
1587 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1608 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1588 | "Unlocking solver from bulk operation ...\n"); | 1609 | "Unlocking solver from bulk operation ...\n"); |
1589 | GNUNET_assert(NULL != solver); | ||
1590 | |||
1591 | if (s->bulk_lock < 1) | 1610 | if (s->bulk_lock < 1) |
1592 | { | 1611 | { |
1593 | GNUNET_break(0); | 1612 | GNUNET_break(0); |
@@ -1638,8 +1657,6 @@ GAS_proportional_address_property_changed (void *solver, | |||
1638 | struct ATS_Address *best_address; | 1657 | struct ATS_Address *best_address; |
1639 | struct ATS_Address *active_address; | 1658 | struct ATS_Address *active_address; |
1640 | 1659 | ||
1641 | GNUNET_assert(NULL != s); | ||
1642 | GNUNET_assert(NULL != address); | ||
1643 | asi = address->solver_information; | 1660 | asi = address->solver_information; |
1644 | if (NULL == asi) | 1661 | if (NULL == asi) |
1645 | { | 1662 | { |
@@ -1664,7 +1681,8 @@ GAS_proportional_address_property_changed (void *solver, | |||
1664 | 1681 | ||
1665 | /* This peer is requested, find active and best address */ | 1682 | /* This peer is requested, find active and best address */ |
1666 | active_address = get_active_address(s, s->addresses, &address->peer); | 1683 | active_address = get_active_address(s, s->addresses, &address->peer); |
1667 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | 1684 | best_address = update_active_address (s, |
1685 | &address->peer); | ||
1668 | 1686 | ||
1669 | if ((NULL != best_address) && ((NULL != active_address) && | 1687 | if ((NULL != best_address) && ((NULL != active_address) && |
1670 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1688 | (GNUNET_YES == address_eq (active_address, best_address)))) |
@@ -1712,12 +1730,13 @@ GAS_proportional_address_session_changed (void *solver, | |||
1712 | return; | 1730 | return; |
1713 | } | 1731 | } |
1714 | 1732 | ||
1715 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | 1733 | if (GNUNET_NO == |
1734 | GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | ||
1716 | return; /* Peer is not requested */ | 1735 | return; /* Peer is not requested */ |
1717 | 1736 | ||
1718 | /* This peer is requested, find active and best address */ | 1737 | /* This peer is requested, find active and best address */ |
1719 | active_address = get_active_address(s, s->addresses, &address->peer); | 1738 | active_address = get_active_address (s, s->addresses, &address->peer); |
1720 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | 1739 | best_address = update_active_address (s, &address->peer); |
1721 | 1740 | ||
1722 | if ((NULL != best_address) && ((NULL != active_address) && | 1741 | if ((NULL != best_address) && ((NULL != active_address) && |
1723 | (GNUNET_YES == address_eq (active_address, best_address)))) | 1742 | (GNUNET_YES == address_eq (active_address, best_address)))) |
@@ -1732,65 +1751,6 @@ GAS_proportional_address_session_changed (void *solver, | |||
1732 | 1751 | ||
1733 | 1752 | ||
1734 | /** | 1753 | /** |
1735 | * Usage for this address has changed | ||
1736 | * | ||
1737 | * NOTE: values in addresses are already updated | ||
1738 | * | ||
1739 | * @param solver solver handle | ||
1740 | * @param address the address | ||
1741 | * @param in_use usage state | ||
1742 | */ | ||
1743 | static void | ||
1744 | GAS_proportional_address_inuse_changed (void *solver, | ||
1745 | struct ATS_Address *address, | ||
1746 | int in_use) | ||
1747 | { | ||
1748 | struct GAS_PROPORTIONAL_Handle *s = solver; | ||
1749 | struct Network *n; | ||
1750 | struct AddressSolverInformation *asi; | ||
1751 | struct ATS_Address *best_address; | ||
1752 | struct ATS_Address *active_address; | ||
1753 | |||
1754 | GNUNET_assert(NULL != s); | ||
1755 | GNUNET_assert(NULL != address); | ||
1756 | asi = address->solver_information; | ||
1757 | if (NULL == asi) | ||
1758 | { | ||
1759 | GNUNET_break(0); | ||
1760 | return; | ||
1761 | } | ||
1762 | |||
1763 | n = asi->network; | ||
1764 | if (NULL == n) | ||
1765 | { | ||
1766 | GNUNET_break(0); | ||
1767 | return; | ||
1768 | } | ||
1769 | |||
1770 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1771 | "Usage of peer `%s' address %p changed to %s \n", | ||
1772 | GNUNET_i2s (&address->peer), address, | ||
1773 | (GNUNET_YES == in_use) ? "YES" : "NO"); | ||
1774 | |||
1775 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (s->requests, &address->peer)) | ||
1776 | return; /* Peer is not requested */ | ||
1777 | |||
1778 | /* This peer is requested, find active and best address */ | ||
1779 | active_address = get_active_address(s, s->addresses, &address->peer); | ||
1780 | best_address = (struct ATS_Address *) update_active_address (s, &address->peer); | ||
1781 | |||
1782 | if ((NULL != best_address) && ((NULL != active_address) && | ||
1783 | (GNUNET_YES == address_eq (active_address, best_address)))) | ||
1784 | { | ||
1785 | asi = best_address->solver_information; | ||
1786 | GNUNET_assert (NULL != asi); | ||
1787 | |||
1788 | /* We sticked to the same address, therefore redistribute */ | ||
1789 | distribute_bandwidth_in_network (s, asi->network); | ||
1790 | } | ||
1791 | } | ||
1792 | |||
1793 | /** | ||
1794 | * Network scope for this address has changed | 1754 | * Network scope for this address has changed |
1795 | * | 1755 | * |
1796 | * NOTE: values in addresses are already updated | 1756 | * NOTE: values in addresses are already updated |
@@ -1955,7 +1915,6 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1955 | env->sf.s_add = &GAS_proportional_address_add; | 1915 | env->sf.s_add = &GAS_proportional_address_add; |
1956 | env->sf.s_address_update_property = &GAS_proportional_address_property_changed; | 1916 | env->sf.s_address_update_property = &GAS_proportional_address_property_changed; |
1957 | env->sf.s_address_update_session = &GAS_proportional_address_session_changed; | 1917 | env->sf.s_address_update_session = &GAS_proportional_address_session_changed; |
1958 | env->sf.s_address_update_inuse = &GAS_proportional_address_inuse_changed; | ||
1959 | env->sf.s_address_update_network = &GAS_proportional_address_change_network; | 1918 | env->sf.s_address_update_network = &GAS_proportional_address_change_network; |
1960 | env->sf.s_get = &GAS_proportional_get_preferred_address; | 1919 | env->sf.s_get = &GAS_proportional_get_preferred_address; |
1961 | env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; | 1920 | env->sf.s_get_stop = &GAS_proportional_stop_get_preferred_address; |
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index c87876ea1..5c396e82e 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -2166,7 +2166,7 @@ GAS_ril_address_change_preference (void *solver, | |||
2166 | * @param network network type of this address | 2166 | * @param network network type of this address |
2167 | */ | 2167 | */ |
2168 | static void | 2168 | static void |
2169 | GAS_ril_address_add (void *solver, | 2169 | GAS_ril_address_add (void *solver, |
2170 | struct ATS_Address *address, | 2170 | struct ATS_Address *address, |
2171 | uint32_t network) | 2171 | uint32_t network) |
2172 | { | 2172 | { |
@@ -2181,7 +2181,7 @@ GAS_ril_address_add (void *solver, | |||
2181 | int i; | 2181 | int i; |
2182 | unsigned int zero; | 2182 | unsigned int zero; |
2183 | 2183 | ||
2184 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2184 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2185 | "API_address_add()\n"); | 2185 | "API_address_add()\n"); |
2186 | 2186 | ||
2187 | net = ril_get_network (s, network); | 2187 | net = ril_get_network (s, network); |
@@ -2256,7 +2256,7 @@ GAS_ril_address_add (void *solver, | |||
2256 | */ | 2256 | */ |
2257 | static void | 2257 | static void |
2258 | GAS_ril_address_delete (void *solver, | 2258 | GAS_ril_address_delete (void *solver, |
2259 | struct ATS_Address *address, | 2259 | struct ATS_Address *address, |
2260 | int session_only) | 2260 | int session_only) |
2261 | { | 2261 | { |
2262 | struct GAS_RIL_Handle *s = solver; | 2262 | struct GAS_RIL_Handle *s = solver; |
@@ -2272,7 +2272,7 @@ GAS_ril_address_delete (void *solver, | |||
2272 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2272 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2273 | "API_address_delete() Delete %s%s %s address %s for peer '%s'\n", | 2273 | "API_address_delete() Delete %s%s %s address %s for peer '%s'\n", |
2274 | session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, | 2274 | session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin, |
2275 | address->addr, | 2275 | address->addr, |
2276 | GNUNET_i2s (&address->peer)); | 2276 | GNUNET_i2s (&address->peer)); |
2277 | 2277 | ||
2278 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); | 2278 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); |
@@ -2373,7 +2373,7 @@ GAS_ril_address_property_changed (void *solver, | |||
2373 | 2373 | ||
2374 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2374 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2375 | "API_address_property_changed() Property '%s' for peer '%s' address %s changed " | 2375 | "API_address_property_changed() Property '%s' for peer '%s' address %s changed " |
2376 | "to %.2f \n", | 2376 | "to %.2f \n", |
2377 | GNUNET_ATS_print_property_type (type), | 2377 | GNUNET_ATS_print_property_type (type), |
2378 | GNUNET_i2s (&address->peer), | 2378 | GNUNET_i2s (&address->peer), |
2379 | address->addr, rel_value); | 2379 | address->addr, rel_value); |
@@ -2407,27 +2407,6 @@ GAS_ril_address_session_changed (void *solver, | |||
2407 | 2407 | ||
2408 | 2408 | ||
2409 | /** | 2409 | /** |
2410 | * Notify the solver that an address is (not) actively used by transport | ||
2411 | * to communicate with a remote peer | ||
2412 | * | ||
2413 | * NOTE: values in addresses are already updated | ||
2414 | * | ||
2415 | * @param solver solver handle | ||
2416 | * @param address the address | ||
2417 | * @param in_use usage state | ||
2418 | */ | ||
2419 | static void | ||
2420 | GAS_ril_address_inuse_changed (void *solver, | ||
2421 | struct ATS_Address *address, | ||
2422 | int in_use) | ||
2423 | { | ||
2424 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
2425 | "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", | ||
2426 | address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED"); | ||
2427 | } | ||
2428 | |||
2429 | |||
2430 | /** | ||
2431 | * Notify solver that the network an address is located in has changed | 2410 | * Notify solver that the network an address is located in has changed |
2432 | * | 2411 | * |
2433 | * NOTE: values in addresses are already updated | 2412 | * NOTE: values in addresses are already updated |
@@ -2446,7 +2425,7 @@ GAS_ril_address_change_network (void *solver, | |||
2446 | struct GAS_RIL_Handle *s = solver; | 2425 | struct GAS_RIL_Handle *s = solver; |
2447 | struct RIL_Peer_Agent *agent; | 2426 | struct RIL_Peer_Agent *agent; |
2448 | 2427 | ||
2449 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2428 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2450 | "API_address_change_network() Network type changed, moving " | 2429 | "API_address_change_network() Network type changed, moving " |
2451 | "%s address of peer %s from '%s' to '%s'\n", | 2430 | "%s address of peer %s from '%s' to '%s'\n", |
2452 | (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer), | 2431 | (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer), |
@@ -2526,8 +2505,8 @@ GAS_ril_bulk_stop (void *solver) | |||
2526 | { | 2505 | { |
2527 | struct GAS_RIL_Handle *s = solver; | 2506 | struct GAS_RIL_Handle *s = solver; |
2528 | 2507 | ||
2529 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2508 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2530 | "API_bulk_stop() lock: %d\n", | 2509 | "API_bulk_stop() lock: %d\n", |
2531 | s->bulk_lock - 1); | 2510 | s->bulk_lock - 1); |
2532 | 2511 | ||
2533 | if (s->bulk_lock < 1) | 2512 | if (s->bulk_lock < 1) |
@@ -2604,7 +2583,7 @@ GAS_ril_stop_get_preferred_address (void *solver, | |||
2604 | struct GAS_RIL_Handle *s = solver; | 2583 | struct GAS_RIL_Handle *s = solver; |
2605 | struct RIL_Peer_Agent *agent; | 2584 | struct RIL_Peer_Agent *agent; |
2606 | 2585 | ||
2607 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2586 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2608 | "API_stop_get_preferred_address()"); | 2587 | "API_stop_get_preferred_address()"); |
2609 | 2588 | ||
2610 | agent = ril_get_agent (s, peer, GNUNET_NO); | 2589 | agent = ril_get_agent (s, peer, GNUNET_NO); |
@@ -2872,7 +2851,6 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
2872 | env->sf.s_add = &GAS_ril_address_add; | 2851 | env->sf.s_add = &GAS_ril_address_add; |
2873 | env->sf.s_address_update_property = &GAS_ril_address_property_changed; | 2852 | env->sf.s_address_update_property = &GAS_ril_address_property_changed; |
2874 | env->sf.s_address_update_session = &GAS_ril_address_session_changed; | 2853 | env->sf.s_address_update_session = &GAS_ril_address_session_changed; |
2875 | env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed; | ||
2876 | env->sf.s_address_update_network = &GAS_ril_address_change_network; | 2854 | env->sf.s_address_update_network = &GAS_ril_address_change_network; |
2877 | env->sf.s_get = &GAS_ril_get_preferred_address; | 2855 | env->sf.s_get = &GAS_ril_get_preferred_address; |
2878 | env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address; | 2856 | env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address; |
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h index 15c3ebbf4..02875a070 100644 --- a/src/include/gnunet_ats_plugin.h +++ b/src/include/gnunet_ats_plugin.h | |||
@@ -142,18 +142,6 @@ typedef void | |||
142 | (*GAS_solver_address_session_changed) (void *solver, | 142 | (*GAS_solver_address_session_changed) (void *solver, |
143 | struct ATS_Address *address, uint32_t cur_session, uint32_t new_session); | 143 | struct ATS_Address *address, uint32_t cur_session, uint32_t new_session); |
144 | 144 | ||
145 | /** | ||
146 | * Transport session for this address has changed | ||
147 | * | ||
148 | * NOTE: values in addresses are already updated | ||
149 | * | ||
150 | * @param solver solver handle | ||
151 | * @param address the address | ||
152 | * @param in_use usage state | ||
153 | */ | ||
154 | typedef void | ||
155 | (*GAS_solver_address_inuse_changed) (void *solver, struct ATS_Address *address, | ||
156 | int in_use); | ||
157 | 145 | ||
158 | /** | 146 | /** |
159 | * Network scope for this address has changed | 147 | * Network scope for this address has changed |
@@ -218,12 +206,6 @@ struct GNUNET_ATS_SolverFunctions | |||
218 | GAS_solver_address_session_changed s_address_update_session; | 206 | GAS_solver_address_session_changed s_address_update_session; |
219 | 207 | ||
220 | /** | 208 | /** |
221 | * Notify the solver that in address is (not) actively used by transport | ||
222 | * to communicate with a remote peer | ||
223 | */ | ||
224 | GAS_solver_address_inuse_changed s_address_update_inuse; | ||
225 | |||
226 | /** | ||
227 | * Notify solver that the network an address is located in has changed | 209 | * Notify solver that the network an address is located in has changed |
228 | */ | 210 | */ |
229 | GAS_solver_address_network_changed s_address_update_network; | 211 | GAS_solver_address_network_changed s_address_update_network; |
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 88df7d0da..380a2a7af 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h | |||
@@ -481,18 +481,6 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh); | |||
481 | 481 | ||
482 | 482 | ||
483 | /** | 483 | /** |
484 | * We would like to reset the address suggestion block time for this | ||
485 | * peer. | ||
486 | * | ||
487 | * @param sh handle | ||
488 | * @param peer identity of the peer we want to reset | ||
489 | */ | ||
490 | void | ||
491 | GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, | ||
492 | const struct GNUNET_PeerIdentity *peer); | ||
493 | |||
494 | |||
495 | /** | ||
496 | * Test if a address and a session is known to ATS. | 484 | * Test if a address and a session is known to ATS. |
497 | * | 485 | * |
498 | * @param sh the scheduling handle | 486 | * @param sh the scheduling handle |
@@ -582,18 +570,6 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
582 | 570 | ||
583 | 571 | ||
584 | /** | 572 | /** |
585 | * An address is now in use, or not used any more. | ||
586 | * | ||
587 | * @param ar address record for which to toggle the flag | ||
588 | * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO | ||
589 | * if address is not used any more | ||
590 | */ | ||
591 | void | ||
592 | GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar, | ||
593 | int in_use); | ||
594 | |||
595 | |||
596 | /** | ||
597 | * An address got destroyed, stop using it as a valid address. | 573 | * An address got destroyed, stop using it as a valid address. |
598 | * | 574 | * |
599 | * @param ar address record to destroy, it's validation has | 575 | * @param ar address record to destroy, it's validation has |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 57bbdfceb..fa21ce97a 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1148,18 +1148,6 @@ extern "C" | |||
1148 | #define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 350 | 1148 | #define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 350 |
1149 | 1149 | ||
1150 | /** | 1150 | /** |
1151 | * Type of the 'struct AddressUseMessage' sent by ATS to client | ||
1152 | * to confirm that an address is used or not used anymore | ||
1153 | */ | ||
1154 | #define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 351 | ||
1155 | |||
1156 | /** | ||
1157 | * Type of the 'struct AddressUseMessage' sent by ATS to client | ||
1158 | * to confirm that an address is used or not used anymore | ||
1159 | */ | ||
1160 | #define GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF 352 | ||
1161 | |||
1162 | /** | ||
1163 | * Type of the 'struct AddressUpdateMessage' sent by client to ATS | 1151 | * Type of the 'struct AddressUpdateMessage' sent by client to ATS |
1164 | * to add a new address | 1152 | * to add a new address |
1165 | */ | 1153 | */ |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 749550657..7beec3118 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -416,6 +416,9 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \ | |||
416 | 416 | ||
417 | if HAVE_TESTING | 417 | if HAVE_TESTING |
418 | check_PROGRAMS = \ | 418 | check_PROGRAMS = \ |
419 | test_transport_api_restart_2peers \ | ||
420 | test_transport_address_switch_tcp \ | ||
421 | test_transport_address_switch_udp \ | ||
419 | test_transport_testing_startstop \ | 422 | test_transport_testing_startstop \ |
420 | test_transport_testing_restart \ | 423 | test_transport_testing_restart \ |
421 | test_transport_testing \ | 424 | test_transport_testing \ |
@@ -435,14 +438,11 @@ check_PROGRAMS = \ | |||
435 | test_transport_api_bidirectional_connect \ | 438 | test_transport_api_bidirectional_connect \ |
436 | test_transport_api_tcp \ | 439 | test_transport_api_tcp \ |
437 | test_transport_api_restart_1peer \ | 440 | test_transport_api_restart_1peer \ |
438 | test_transport_api_restart_2peers \ | ||
439 | test_transport_api_timeout_tcp \ | 441 | test_transport_api_timeout_tcp \ |
440 | test_transport_address_switch_tcp \ | ||
441 | test_transport_api_limited_sockets_tcp \ | 442 | test_transport_api_limited_sockets_tcp \ |
442 | test_transport_api_tcp_nat \ | 443 | test_transport_api_tcp_nat \ |
443 | test_transport_api_udp \ | 444 | test_transport_api_udp \ |
444 | test_transport_api_timeout_udp \ | 445 | test_transport_api_timeout_udp \ |
445 | test_transport_address_switch_udp \ | ||
446 | $(UNIX_PLUGIN_TEST) \ | 446 | $(UNIX_PLUGIN_TEST) \ |
447 | $(UNIX_PLUGIN_TIMEOUT_TEST) \ | 447 | $(UNIX_PLUGIN_TIMEOUT_TEST) \ |
448 | $(UNIX_API_ABSTRACT_TEST) \ | 448 | $(UNIX_API_ABSTRACT_TEST) \ |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index e3bbf7167..f317e924f 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -17,7 +17,6 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | 20 | /** |
22 | * @file transport/gnunet-service-transport.c | 21 | * @file transport/gnunet-service-transport.c |
23 | * @brief main for gnunet-service-transport | 22 | * @brief main for gnunet-service-transport |
@@ -41,6 +40,7 @@ | |||
41 | #include "gnunet-service-transport_manipulation.h" | 40 | #include "gnunet-service-transport_manipulation.h" |
42 | #include "transport.h" | 41 | #include "transport.h" |
43 | 42 | ||
43 | |||
44 | /** | 44 | /** |
45 | * Information we need for an asynchronous session kill. | 45 | * Information we need for an asynchronous session kill. |
46 | */ | 46 | */ |
@@ -73,18 +73,45 @@ struct SessionKiller | |||
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | /** | ||
77 | * We track active blacklist checks in a DLL so we can cancel them if | ||
78 | * necessary. We typically check against the blacklist a few times | ||
79 | * during connection setup, as the check is asynchronous and the | ||
80 | * blacklist may change its mind before the connection goes fully up. | ||
81 | * Similarly, the session may die during the asynchronous check, so | ||
82 | * we use this list to then cancel ongoing checks. | ||
83 | */ | ||
76 | struct BlacklistCheckContext | 84 | struct BlacklistCheckContext |
77 | { | 85 | { |
86 | /** | ||
87 | * We keep these in a DLL. | ||
88 | */ | ||
78 | struct BlacklistCheckContext *prev; | 89 | struct BlacklistCheckContext *prev; |
79 | 90 | ||
91 | /** | ||
92 | * We keep these in a DLL. | ||
93 | */ | ||
80 | struct BlacklistCheckContext *next; | 94 | struct BlacklistCheckContext *next; |
81 | 95 | ||
96 | /** | ||
97 | * Handle with the blacklist subsystem. | ||
98 | */ | ||
82 | struct GST_BlacklistCheck *blc; | 99 | struct GST_BlacklistCheck *blc; |
83 | 100 | ||
101 | /** | ||
102 | * The address we are checking. | ||
103 | */ | ||
84 | struct GNUNET_HELLO_Address *address; | 104 | struct GNUNET_HELLO_Address *address; |
85 | 105 | ||
106 | /** | ||
107 | * Session associated with the address (or NULL). | ||
108 | */ | ||
86 | struct Session *session; | 109 | struct Session *session; |
87 | 110 | ||
111 | /** | ||
112 | * Message to process in the continuation if the | ||
113 | * blacklist check is ok, can be NULL. | ||
114 | */ | ||
88 | struct GNUNET_MessageHeader *msg; | 115 | struct GNUNET_MessageHeader *msg; |
89 | 116 | ||
90 | }; | 117 | }; |
@@ -152,12 +179,16 @@ static struct SessionKiller *sk_tail; | |||
152 | static struct GNUNET_ATS_InterfaceScanner *is; | 179 | static struct GNUNET_ATS_InterfaceScanner *is; |
153 | 180 | ||
154 | /** | 181 | /** |
155 | * FIXME | 182 | * Head of DLL of blacklist checks we have pending for |
183 | * incoming sessions and/or SYN requests. We may | ||
184 | * want to move this into the blacklist-logic at some | ||
185 | * point. | ||
156 | */ | 186 | */ |
157 | struct BlacklistCheckContext *bc_head; | 187 | struct BlacklistCheckContext *bc_head; |
158 | 188 | ||
159 | /** | 189 | /** |
160 | * FIXME | 190 | * Tail of DLL of blacklist checks we have pending for |
191 | * incoming sessions and/or SYN requests. | ||
161 | */ | 192 | */ |
162 | struct BlacklistCheckContext *bc_tail; | 193 | struct BlacklistCheckContext *bc_tail; |
163 | 194 | ||
@@ -202,7 +233,8 @@ transmit_our_hello (void *cls, | |||
202 | * @param hello new HELLO | 233 | * @param hello new HELLO |
203 | */ | 234 | */ |
204 | static void | 235 | static void |
205 | process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) | 236 | process_hello_update (void *cls, |
237 | const struct GNUNET_MessageHeader *hello) | ||
206 | { | 238 | { |
207 | GST_clients_broadcast (hello, GNUNET_NO); | 239 | GST_clients_broadcast (hello, GNUNET_NO); |
208 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); | 240 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); |
@@ -268,20 +300,24 @@ process_payload (const struct GNUNET_HELLO_Address *address, | |||
268 | * @param tc scheduler context | 300 | * @param tc scheduler context |
269 | */ | 301 | */ |
270 | static void | 302 | static void |
271 | kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 303 | kill_session_task (void *cls, |
304 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
272 | { | 305 | { |
273 | struct SessionKiller *sk = cls; | 306 | struct SessionKiller *sk = cls; |
274 | 307 | ||
275 | sk->task = NULL; | 308 | sk->task = NULL; |
276 | GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); | 309 | GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); |
277 | sk->plugin->disconnect_session (sk->plugin->cls, sk->session); | 310 | sk->plugin->disconnect_session (sk->plugin->cls, sk->session); |
278 | GNUNET_free(sk); | 311 | GNUNET_free(sk); |
279 | } | 312 | } |
280 | 313 | ||
281 | 314 | ||
282 | /** | 315 | /** |
283 | * FIXME. Also, consider moving the "bc_*" logic into | 316 | * Cancel all blacklist checks that are pending for the given address and session. |
284 | * blacklist.h? | 317 | * NOTE: Consider moving the "bc_*" logic into blacklist.h? |
318 | * | ||
319 | * @param address address to remove from check | ||
320 | * @param sesssion session that must match to remove for check | ||
285 | */ | 321 | */ |
286 | static void | 322 | static void |
287 | cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, | 323 | cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, |
@@ -298,7 +334,9 @@ cancel_pending_blacklist_checks (const struct GNUNET_HELLO_Address *address, | |||
298 | (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) && | 334 | (0 == GNUNET_HELLO_address_cmp(blctx->address, address)) && |
299 | (blctx->session == session)) | 335 | (blctx->session == session)) |
300 | { | 336 | { |
301 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | 337 | GNUNET_CONTAINER_DLL_remove (bc_head, |
338 | bc_tail, | ||
339 | blctx); | ||
302 | if (NULL != blctx->blc) | 340 | if (NULL != blctx->blc) |
303 | { | 341 | { |
304 | GST_blacklist_test_cancel (blctx->blc); | 342 | GST_blacklist_test_cancel (blctx->blc); |
@@ -361,35 +399,37 @@ connect_bl_check_cont (void *cls, | |||
361 | { | 399 | { |
362 | struct BlacklistCheckContext *blctx = cls; | 400 | struct BlacklistCheckContext *blctx = cls; |
363 | 401 | ||
364 | GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, blctx); | 402 | GNUNET_CONTAINER_DLL_remove (bc_head, |
403 | bc_tail, | ||
404 | blctx); | ||
365 | blctx->blc = NULL; | 405 | blctx->blc = NULL; |
366 | |||
367 | if (GNUNET_OK == result) | 406 | if (GNUNET_OK == result) |
368 | { | 407 | { |
369 | /* Blacklist allows to speak to this peer, forward SYN to neighbours */ | 408 | /* Blacklist allows to speak to this peer, forward SYN to neighbours */ |
370 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
371 | "Received SYN message from peer `%s' with `%s' %p\n", | 410 | "Received SYN message from peer `%s' at `%s'\n", |
372 | GNUNET_i2s (peer), | 411 | GNUNET_i2s (peer), |
373 | GST_plugins_a2s (blctx->address), | 412 | GST_plugins_a2s (blctx->address)); |
374 | blctx->session); | ||
375 | |||
376 | if (GNUNET_OK != | 413 | if (GNUNET_OK != |
377 | GST_neighbours_handle_session_syn (blctx->msg, | 414 | GST_neighbours_handle_session_syn (blctx->msg, |
378 | &blctx->address->peer)) | 415 | &blctx->address->peer)) |
379 | { | 416 | { |
380 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | 417 | cancel_pending_blacklist_checks (blctx->address, |
381 | kill_session (blctx->address->transport_name, blctx->session); | 418 | blctx->session); |
419 | kill_session (blctx->address->transport_name, | ||
420 | blctx->session); | ||
382 | } | 421 | } |
383 | } | 422 | } |
384 | else | 423 | else |
385 | { | 424 | { |
386 | /* Blacklist denies to speak to this peer */ | 425 | /* Blacklist denies to speak to this peer */ |
387 | 426 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | |
388 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 427 | "Discarding SYN message from `%s' due to denied blacklist check\n", |
389 | "Discarding SYN message from `%s' due to denied blacklist check\n", | 428 | GNUNET_i2s (peer)); |
390 | GNUNET_i2s (peer)); | 429 | cancel_pending_blacklist_checks (blctx->address, |
391 | cancel_pending_blacklist_checks (blctx->address, blctx->session); | 430 | blctx->session); |
392 | kill_session (blctx->address->transport_name, blctx->session); | 431 | kill_session (blctx->address->transport_name, |
432 | blctx->session); | ||
393 | } | 433 | } |
394 | 434 | ||
395 | if (NULL != blctx->address) | 435 | if (NULL != blctx->address) |
@@ -429,7 +469,7 @@ GST_receive_callback (void *cls, | |||
429 | goto end; | 469 | goto end; |
430 | type = ntohs (message->type); | 470 | type = ntohs (message->type); |
431 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
432 | "Received Message with type %u from peer `%s'\n", | 472 | "Received message with type %u from peer `%s'\n", |
433 | type, | 473 | type, |
434 | GNUNET_i2s (&address->peer)); | 474 | GNUNET_i2s (&address->peer)); |
435 | 475 | ||
@@ -485,11 +525,17 @@ GST_receive_callback (void *cls, | |||
485 | blctx->address = GNUNET_HELLO_address_copy (address); | 525 | blctx->address = GNUNET_HELLO_address_copy (address); |
486 | blctx->session = session; | 526 | blctx->session = session; |
487 | blctx->msg = GNUNET_malloc (ntohs(message->size)); | 527 | blctx->msg = GNUNET_malloc (ntohs(message->size)); |
488 | memcpy (blctx->msg, message, ntohs(message->size)); | 528 | memcpy (blctx->msg, |
489 | GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, blctx); | 529 | message, |
490 | if (NULL != (blc = GST_blacklist_test_allowed (&address->peer, NULL, | 530 | ntohs (message->size)); |
491 | &connect_bl_check_cont, | 531 | GNUNET_CONTAINER_DLL_insert (bc_head, |
492 | blctx))) | 532 | bc_tail, |
533 | blctx); | ||
534 | if (NULL != | ||
535 | (blc = GST_blacklist_test_allowed (&address->peer, | ||
536 | NULL, | ||
537 | &connect_bl_check_cont, | ||
538 | blctx))) | ||
493 | { | 539 | { |
494 | blctx->blc = blc; | 540 | blctx->blc = blc; |
495 | } | 541 | } |
@@ -619,11 +665,8 @@ plugin_env_session_end (void *cls, | |||
619 | } | 665 | } |
620 | GNUNET_assert (strlen (address->transport_name) > 0); | 666 | GNUNET_assert (strlen (address->transport_name) > 0); |
621 | 667 | ||
622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
623 | "Notification from plugin `%s' about terminated %s session %p from peer `%s' address `%s'\n", | 669 | "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", |
624 | address->transport_name, | ||
625 | GNUNET_HELLO_address_check_option (address, | ||
626 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", | ||
627 | session, | 670 | session, |
628 | GNUNET_i2s (&address->peer), | 671 | GNUNET_i2s (&address->peer), |
629 | GST_plugins_a2s (address)); | 672 | GST_plugins_a2s (address)); |
@@ -719,6 +762,15 @@ plugin_env_session_start_bl_check_cont (void *cls, | |||
719 | kill_session (blctx->address->transport_name, | 762 | kill_session (blctx->address->transport_name, |
720 | blctx->session); | 763 | blctx->session); |
721 | } | 764 | } |
765 | else if (GNUNET_YES != | ||
766 | GNUNET_HELLO_address_check_option (blctx->address, | ||
767 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
768 | { | ||
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
770 | "Informing verifier about inbound session's address `%s'\n", | ||
771 | GST_plugins_a2s (blctx->address)); | ||
772 | GST_validation_handle_address (blctx->address); | ||
773 | } | ||
722 | GNUNET_HELLO_address_free (blctx->address); | 774 | GNUNET_HELLO_address_free (blctx->address); |
723 | GNUNET_free (blctx); | 775 | GNUNET_free (blctx); |
724 | } | 776 | } |
@@ -754,35 +806,34 @@ plugin_env_session_start (void *cls, | |||
754 | return; | 806 | return; |
755 | } | 807 | } |
756 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 808 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
757 | "Notification from plugin `%s' about new %s session %p from peer `%s' address `%s'\n", | 809 | "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n", |
758 | address->transport_name, | 810 | address->transport_name, |
759 | GNUNET_HELLO_address_check_option (address, | ||
760 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound", | ||
761 | session, | 811 | session, |
762 | GNUNET_i2s (&address->peer), | 812 | GNUNET_i2s (&address->peer), |
763 | GST_plugins_a2s (address)); | 813 | GST_plugins_a2s (address)); |
764 | if ( (GNUNET_YES == | 814 | if (GNUNET_YES == |
765 | GNUNET_HELLO_address_check_option (address, | 815 | GNUNET_HELLO_address_check_option (address, |
766 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) || | 816 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
767 | (GNUNET_NO == | ||
768 | GST_ats_is_known (address, NULL) ) ) | ||
769 | { | 817 | { |
770 | /* inbound is always new, but outbound MAY already be known, but | 818 | /* inbound is always new, but outbound MAY already be known, but |
771 | for example for UNIX, we have symmetric connections and thus we | 819 | for example for UNIX, we have symmetric connections and thus we |
772 | may not know the address yet; add if necessary! */ | 820 | may not know the address yet; add if necessary! */ |
773 | GST_ats_add_address (address, | 821 | GST_ats_add_inbound_address (address, |
774 | session, | 822 | session, |
775 | ats, | 823 | ats, |
776 | ats_count); | 824 | ats_count); |
777 | } | 825 | } |
778 | else | 826 | else |
779 | { | 827 | { |
780 | GST_ats_new_session (address, | 828 | if (GNUNET_YES == |
781 | session); | 829 | GST_ats_is_known (address, |
782 | GST_ats_update_metrics (address, | 830 | session)) |
783 | session, | 831 | { |
784 | ats, | 832 | GST_ats_update_metrics (address, |
785 | ats_count); | 833 | session, |
834 | ats, | ||
835 | ats_count); | ||
836 | } | ||
786 | } | 837 | } |
787 | /* Do blacklist check if communication with this peer is allowed */ | 838 | /* Do blacklist check if communication with this peer is allowed */ |
788 | blctx = GNUNET_new (struct BlacklistCheckContext); | 839 | blctx = GNUNET_new (struct BlacklistCheckContext); |
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c index 0b864f3fb..c3f52de91 100644 --- a/src/transport/gnunet-service-transport_ats.c +++ b/src/transport/gnunet-service-transport_ats.c | |||
@@ -256,6 +256,10 @@ unblock_address (void *cls, | |||
256 | struct AddressInfo *ai = cls; | 256 | struct AddressInfo *ai = cls; |
257 | 257 | ||
258 | ai->unblock_task = NULL; | 258 | ai->unblock_task = NULL; |
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
260 | "Unblocking address %s of peer %s\n", | ||
261 | GST_plugins_a2s (ai->address), | ||
262 | GNUNET_i2s (&ai->address->peer)); | ||
259 | ai->ar = GNUNET_ATS_address_add (GST_ats, | 263 | ai->ar = GNUNET_ATS_address_add (GST_ats, |
260 | ai->address, | 264 | ai->address, |
261 | ai->session, | 265 | ai->session, |
@@ -291,8 +295,26 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address, | |||
291 | GNUNET_break (0); | 295 | GNUNET_break (0); |
292 | return; | 296 | return; |
293 | } | 297 | } |
294 | GNUNET_ATS_address_destroy (ai->ar); | 298 | if (GNUNET_YES == |
299 | GNUNET_HELLO_address_check_option (address, | ||
300 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "Removing address %s of peer %s from use (inbound died)\n", | ||
303 | GST_plugins_a2s (address), | ||
304 | GNUNET_i2s (&address->peer)); | ||
305 | else | ||
306 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
307 | "Blocking address %s of peer %s from use for a while\n", | ||
308 | GST_plugins_a2s (address), | ||
309 | GNUNET_i2s (&address->peer)); | ||
310 | /* destroy session and address */ | ||
311 | if ( (NULL == session) || | ||
312 | (GNUNET_NO == | ||
313 | GNUNET_ATS_address_del_session (ai->ar, session)) ) | ||
314 | GNUNET_ATS_address_destroy (ai->ar); | ||
295 | ai->ar = NULL; | 315 | ai->ar = NULL; |
316 | |||
317 | /* determine when the address should come back to life */ | ||
296 | ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); | 318 | ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); |
297 | ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off); | 319 | ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off); |
298 | ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off, | 320 | ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off, |
@@ -302,8 +324,10 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address, | |||
302 | 324 | ||
303 | 325 | ||
304 | /** | 326 | /** |
305 | * Notify ATS about the new address including the network this address is | 327 | * Notify ATS about the a new inbound address. We may already |
306 | * located in. | 328 | * know the address (as this is called each time we receive |
329 | * a message from an inbound connection). If the address is | ||
330 | * indeed new, make it available to ATS. | ||
307 | * | 331 | * |
308 | * @param address the address | 332 | * @param address the address |
309 | * @param session the session | 333 | * @param session the session |
@@ -311,10 +335,10 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address, | |||
311 | * @param ats_count number of @a ats information | 335 | * @param ats_count number of @a ats information |
312 | */ | 336 | */ |
313 | void | 337 | void |
314 | GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | 338 | GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address, |
315 | struct Session *session, | 339 | struct Session *session, |
316 | const struct GNUNET_ATS_Information *ats, | 340 | const struct GNUNET_ATS_Information *ats, |
317 | uint32_t ats_count) | 341 | uint32_t ats_count) |
318 | { | 342 | { |
319 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 343 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
320 | struct GNUNET_ATS_Information ats2[ats_count + 1]; | 344 | struct GNUNET_ATS_Information ats2[ats_count + 1]; |
@@ -328,55 +352,37 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | |||
328 | GNUNET_break(0); | 352 | GNUNET_break(0); |
329 | return; | 353 | return; |
330 | } | 354 | } |
331 | if (GNUNET_YES == | 355 | GNUNET_assert (GNUNET_YES == |
332 | GNUNET_HELLO_address_check_option (address, | 356 | GNUNET_HELLO_address_check_option (address, |
333 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 357 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)); |
334 | { | 358 | GNUNET_assert (NULL != session); |
335 | GNUNET_break (NULL != session); | 359 | ai = find_ai (address, session); |
336 | } | ||
337 | ai = (NULL == session) | ||
338 | ? find_ai_no_session (address) | ||
339 | : find_ai (address, session); | ||
340 | if (NULL != ai) | 360 | if (NULL != ai) |
341 | return; | ||
342 | if (NULL != session) | ||
343 | { | ||
344 | /* in this case, we must not find an existing | ||
345 | session-less address, as the caller should | ||
346 | have checked for this case if it were possible. */ | ||
347 | ai = find_ai (address, NULL); | ||
348 | if (NULL != ai) | ||
349 | { | ||
350 | GNUNET_assert (0); | ||
351 | return; | ||
352 | } | ||
353 | } | ||
354 | if (NULL == (papi = GST_plugins_find (address->transport_name))) | ||
355 | { | 361 | { |
356 | /* we don't have the plugin for this address */ | 362 | /* This should only be called for new sessions, and thus |
357 | GNUNET_assert (0); | 363 | we should not already have the address */ |
364 | GNUNET_break (0); | ||
358 | return; | 365 | return; |
359 | } | 366 | } |
360 | if (NULL != session) | 367 | papi = GST_plugins_find (address->transport_name); |
368 | GNUNET_assert (NULL != papi); | ||
369 | net = papi->get_network (papi->cls, session); | ||
370 | if (GNUNET_ATS_NET_UNSPECIFIED == net) | ||
361 | { | 371 | { |
362 | net = papi->get_network (papi->cls, session); | 372 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
363 | if (GNUNET_ATS_NET_UNSPECIFIED == net) | 373 | _("Could not obtain a valid network for `%s' %s (%s)\n"), |
364 | { | 374 | GNUNET_i2s (&address->peer), |
365 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 375 | GST_plugins_a2s (address), |
366 | _ ("Could not obtain a valid network for `%s' %s (%s)\n"), | 376 | address->transport_name); |
367 | GNUNET_i2s (&address->peer), | 377 | return; |
368 | GST_plugins_a2s (address), | ||
369 | address->transport_name); | ||
370 | return; | ||
371 | } | ||
372 | ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
373 | ats2[0].value = htonl (net); | ||
374 | memcpy (&ats2[1], | ||
375 | ats, | ||
376 | sizeof(struct GNUNET_ATS_Information) * ats_count); | ||
377 | } | 378 | } |
378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 379 | ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); |
379 | "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", | 380 | ats2[0].value = htonl (net); |
381 | memcpy (&ats2[1], | ||
382 | ats, | ||
383 | sizeof(struct GNUNET_ATS_Information) * ats_count); | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n", | ||
380 | GNUNET_i2s (&address->peer), | 386 | GNUNET_i2s (&address->peer), |
381 | (0 == address->address_length) | 387 | (0 == address->address_length) |
382 | ? "<inbound>" | 388 | ? "<inbound>" |
@@ -401,6 +407,55 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | |||
401 | 407 | ||
402 | 408 | ||
403 | /** | 409 | /** |
410 | * Notify ATS about the new address including the network this address is | ||
411 | * located in. The address must NOT be inbound and must be new to ATS. | ||
412 | * | ||
413 | * @param address the address | ||
414 | * @param ats ats information | ||
415 | * @param ats_count number of @a ats information | ||
416 | */ | ||
417 | void | ||
418 | GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | ||
419 | const struct GNUNET_ATS_Information *ats, | ||
420 | uint32_t ats_count) | ||
421 | { | ||
422 | struct GNUNET_ATS_AddressRecord *ar; | ||
423 | struct AddressInfo *ai; | ||
424 | |||
425 | /* valid new address, let ATS know! */ | ||
426 | if (NULL == address->transport_name) | ||
427 | { | ||
428 | GNUNET_break(0); | ||
429 | return; | ||
430 | } | ||
431 | GNUNET_assert (GNUNET_YES != | ||
432 | GNUNET_HELLO_address_check_option (address, | ||
433 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)); | ||
434 | ai = find_ai_no_session (address); | ||
435 | GNUNET_assert (NULL == ai); | ||
436 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
437 | "Notifying ATS about peer `%s''s new address `%s'\n", | ||
438 | GNUNET_i2s (&address->peer), | ||
439 | (0 == address->address_length) | ||
440 | ? "<inbound>" | ||
441 | : GST_plugins_a2s (address)); | ||
442 | ar = GNUNET_ATS_address_add (GST_ats, | ||
443 | address, | ||
444 | NULL, | ||
445 | ats, | ||
446 | ats_count); | ||
447 | ai = GNUNET_new (struct AddressInfo); | ||
448 | ai->address = GNUNET_HELLO_address_copy (address); | ||
449 | ai->ar = ar; | ||
450 | (void) GNUNET_CONTAINER_multipeermap_put (p2a, | ||
451 | &ai->address->peer, | ||
452 | ai, | ||
453 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
454 | publish_p2a_stat_update (); | ||
455 | } | ||
456 | |||
457 | |||
458 | /** | ||
404 | * Notify ATS about a new session now existing for the given | 459 | * Notify ATS about a new session now existing for the given |
405 | * address. | 460 | * address. |
406 | * | 461 | * |
@@ -477,7 +532,14 @@ GST_ats_del_session (const struct GNUNET_HELLO_Address *address, | |||
477 | GNUNET_i2s (&address->peer)); | 532 | GNUNET_i2s (&address->peer)); |
478 | if (NULL == ai->ar) | 533 | if (NULL == ai->ar) |
479 | { | 534 | { |
480 | GST_ats_expire_address (address); | 535 | /* If ATS doesn't know about the address/session, and this |
536 | was an inbound session that expired, then we must forget | ||
537 | about the address as well. Otherwise, we are done as | ||
538 | we have set `ai->session` to NULL already. */ | ||
539 | if (GNUNET_YES == | ||
540 | GNUNET_HELLO_address_check_option (address, | ||
541 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
542 | GST_ats_expire_address (address); | ||
481 | return; | 543 | return; |
482 | } | 544 | } |
483 | if (GNUNET_YES == | 545 | if (GNUNET_YES == |
@@ -516,7 +578,6 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address, | |||
516 | GNUNET_assert (GNUNET_YES != | 578 | GNUNET_assert (GNUNET_YES != |
517 | GNUNET_HELLO_address_check_option (address, | 579 | GNUNET_HELLO_address_check_option (address, |
518 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)); | 580 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)); |
519 | |||
520 | return; | 581 | return; |
521 | } | 582 | } |
522 | /* Call to manipulation to manipulate ATS information */ | 583 | /* Call to manipulation to manipulate ATS information */ |
@@ -541,31 +602,6 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address, | |||
541 | 602 | ||
542 | 603 | ||
543 | /** | 604 | /** |
544 | * Notify ATS about a new session now being in use (or not). | ||
545 | * | ||
546 | * @param address the address | ||
547 | * @param session the session | ||
548 | * @param in_use #GNUNET_YES or #GNUNET_NO | ||
549 | */ | ||
550 | void | ||
551 | GST_ats_set_in_use (const struct GNUNET_HELLO_Address *address, | ||
552 | struct Session *session, | ||
553 | int in_use) | ||
554 | { | ||
555 | struct AddressInfo *ai; | ||
556 | |||
557 | ai = find_ai (address, session); | ||
558 | if (NULL == ai) | ||
559 | { | ||
560 | GNUNET_break (0); | ||
561 | return; | ||
562 | } | ||
563 | GNUNET_assert (NULL != ai->ar); | ||
564 | GNUNET_ATS_address_set_in_use (ai->ar, in_use); | ||
565 | } | ||
566 | |||
567 | |||
568 | /** | ||
569 | * Notify ATS that the address has expired and thus cannot | 605 | * Notify ATS that the address has expired and thus cannot |
570 | * be used any longer. This function must only be called | 606 | * be used any longer. This function must only be called |
571 | * if the corresponding session is already gone. | 607 | * if the corresponding session is already gone. |
@@ -577,7 +613,11 @@ GST_ats_expire_address (const struct GNUNET_HELLO_Address *address) | |||
577 | { | 613 | { |
578 | struct AddressInfo *ai; | 614 | struct AddressInfo *ai; |
579 | 615 | ||
580 | ai = find_ai (address, NULL); | 616 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
617 | "Address %s of peer %s expired\n", | ||
618 | GST_plugins_a2s (address), | ||
619 | GNUNET_i2s (&address->peer)); | ||
620 | ai = find_ai_no_session (address); | ||
581 | if (NULL == ai) | 621 | if (NULL == ai) |
582 | { | 622 | { |
583 | GNUNET_assert (0); | 623 | GNUNET_assert (0); |
@@ -595,7 +635,15 @@ GST_ats_expire_address (const struct GNUNET_HELLO_Address *address) | |||
595 | GNUNET_i2s (&address->peer)); | 635 | GNUNET_i2s (&address->peer)); |
596 | if (NULL != ai->ar) | 636 | if (NULL != ai->ar) |
597 | { | 637 | { |
598 | GNUNET_ATS_address_destroy (ai->ar); | 638 | /* We usually should not have a session here when we |
639 | expire an address, but during shutdown a session | ||
640 | may be active while validation causes the address | ||
641 | to 'expire'. So clean up both if necessary. */ | ||
642 | if ( (NULL == ai->session) || | ||
643 | (GNUNET_NO == | ||
644 | GNUNET_ATS_address_del_session (ai->ar, | ||
645 | ai->session)) ) | ||
646 | GNUNET_ATS_address_destroy (ai->ar); | ||
599 | ai->ar = NULL; | 647 | ai->ar = NULL; |
600 | } | 648 | } |
601 | if (NULL != ai->unblock_task) | 649 | if (NULL != ai->unblock_task) |
diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h index 53c4caa68..e2f829898 100644 --- a/src/transport/gnunet-service-transport_ats.h +++ b/src/transport/gnunet-service-transport_ats.h | |||
@@ -21,11 +21,6 @@ | |||
21 | * @file transport/gnunet-service-transport_ats.h | 21 | * @file transport/gnunet-service-transport_ats.h |
22 | * @brief interfacing between transport and ATS service | 22 | * @brief interfacing between transport and ATS service |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * | ||
25 | * FIXME: | ||
26 | * - add API to give ATS feedback about an address that was | ||
27 | * suggested but did not work out (without fully 'deleting' | ||
28 | * it forever) | ||
29 | */ | 24 | */ |
30 | #ifndef GNUNET_SERVICE_TRANSPORT_ATS_H | 25 | #ifndef GNUNET_SERVICE_TRANSPORT_ATS_H |
31 | #define GNUNET_SERVICE_TRANSPORT_ATS_H | 26 | #define GNUNET_SERVICE_TRANSPORT_ATS_H |
@@ -72,9 +67,14 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address, | |||
72 | struct Session *session); | 67 | struct Session *session); |
73 | 68 | ||
74 | 69 | ||
70 | /* FIXME: might want to add a function to reset the | ||
71 | back-off from blocking */ | ||
72 | |||
75 | /** | 73 | /** |
76 | * Notify ATS about the new address including the network this address is | 74 | * Notify ATS about the a new inbound address. We may already |
77 | * located in. | 75 | * know the address (as this is called each time we receive |
76 | * a message from an inbound connection). If the address is | ||
77 | * indeed new, make it available to ATS. | ||
78 | * | 78 | * |
79 | * @param address the address | 79 | * @param address the address |
80 | * @param session the session | 80 | * @param session the session |
@@ -82,35 +82,36 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address, | |||
82 | * @param ats_count number of @a ats information | 82 | * @param ats_count number of @a ats information |
83 | */ | 83 | */ |
84 | void | 84 | void |
85 | GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | 85 | GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address, |
86 | struct Session *session, | 86 | struct Session *session, |
87 | const struct GNUNET_ATS_Information *ats, | 87 | const struct GNUNET_ATS_Information *ats, |
88 | uint32_t ats_count); | 88 | uint32_t ats_count); |
89 | 89 | ||
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Notify ATS about a new session now existing for the given | 92 | * Notify ATS about the new address including the network this address is |
93 | * address. | 93 | * located in. The address must NOT be inbound and must be new to ATS. |
94 | * | 94 | * |
95 | * @param address the address | 95 | * @param address the address |
96 | * @param session the session | 96 | * @param ats ats information |
97 | * @param ats_count number of @a ats information | ||
97 | */ | 98 | */ |
98 | void | 99 | void |
99 | GST_ats_new_session (const struct GNUNET_HELLO_Address *address, | 100 | GST_ats_add_address (const struct GNUNET_HELLO_Address *address, |
100 | struct Session *session); | 101 | const struct GNUNET_ATS_Information *ats, |
102 | uint32_t ats_count); | ||
101 | 103 | ||
102 | 104 | ||
103 | /** | 105 | /** |
104 | * Notify ATS about a new session now being in use (or not). | 106 | * Notify ATS about a new session now existing for the given |
107 | * address. | ||
105 | * | 108 | * |
106 | * @param address the address | 109 | * @param address the address |
107 | * @param session the session | 110 | * @param session the session |
108 | * @param in_use #GNUNET_YES or #GNUNET_NO | ||
109 | */ | 111 | */ |
110 | void | 112 | void |
111 | GST_ats_set_in_use (const struct GNUNET_HELLO_Address *address, | 113 | GST_ats_new_session (const struct GNUNET_HELLO_Address *address, |
112 | struct Session *session, | 114 | struct Session *session); |
113 | int in_use); | ||
114 | 115 | ||
115 | 116 | ||
116 | /** | 117 | /** |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index bd9257db3..ca4fa7824 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -38,7 +38,6 @@ | |||
38 | #include "transport.h" | 38 | #include "transport.h" |
39 | 39 | ||
40 | 40 | ||
41 | |||
42 | /** | 41 | /** |
43 | * Size of the neighbour hash map. | 42 | * Size of the neighbour hash map. |
44 | */ | 43 | */ |
@@ -509,11 +508,14 @@ static unsigned long long bytes_in_send_queue; | |||
509 | /** | 508 | /** |
510 | * Task transmitting utilization data | 509 | * Task transmitting utilization data |
511 | */ | 510 | */ |
512 | static struct GNUNET_SCHEDULER_Task * util_transmission_tk; | 511 | static struct GNUNET_SCHEDULER_Task *util_transmission_tk; |
513 | 512 | ||
514 | 513 | ||
515 | /** | 514 | /** |
516 | * FIXME | 515 | * Convert the given ACK state to a string. |
516 | * | ||
517 | * @param s state | ||
518 | * @return corresponding human-readable string | ||
517 | */ | 519 | */ |
518 | static char * | 520 | static char * |
519 | print_ack_state (enum GST_ACK_State s) | 521 | print_ack_state (enum GST_ACK_State s) |
@@ -617,7 +619,6 @@ neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer, | |||
617 | } | 619 | } |
618 | 620 | ||
619 | 621 | ||
620 | |||
621 | /** | 622 | /** |
622 | * Lookup a neighbour entry in the neighbours hash map. | 623 | * Lookup a neighbour entry in the neighbours hash map. |
623 | * | 624 | * |
@@ -662,7 +663,8 @@ send_outbound_quota (const struct GNUNET_PeerIdentity *target, | |||
662 | 663 | ||
663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
664 | "Sending outbound quota of %u Bps for peer `%s' to all clients\n", | 665 | "Sending outbound quota of %u Bps for peer `%s' to all clients\n", |
665 | ntohl (quota.value__), GNUNET_i2s (target)); | 666 | ntohl (quota.value__), |
667 | GNUNET_i2s (target)); | ||
666 | q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); | 668 | q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); |
667 | q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); | 669 | q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); |
668 | q_msg.quota = quota; | 670 | q_msg.quota = quota; |
@@ -682,49 +684,34 @@ static void | |||
682 | free_address (struct NeighbourAddress *na) | 684 | free_address (struct NeighbourAddress *na) |
683 | { | 685 | { |
684 | if (GNUNET_YES == na->ats_active) | 686 | if (GNUNET_YES == na->ats_active) |
685 | { | ||
686 | GST_validation_set_address_use (na->address, | 687 | GST_validation_set_address_use (na->address, |
687 | GNUNET_NO); | 688 | GNUNET_NO); |
688 | GST_ats_set_in_use (na->address, | ||
689 | na->session, | ||
690 | GNUNET_NO); | ||
691 | } | ||
692 | |||
693 | na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0); | ||
694 | na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0); | ||
695 | na->ats_active = GNUNET_NO; | ||
696 | na->keep_alive_nonce = 0; | ||
697 | if (NULL != na->address) | 689 | if (NULL != na->address) |
698 | { | 690 | { |
691 | GST_ats_block_address (na->address, | ||
692 | na->session); | ||
699 | GNUNET_HELLO_address_free (na->address); | 693 | GNUNET_HELLO_address_free (na->address); |
700 | na->address = NULL; | 694 | na->address = NULL; |
701 | } | 695 | } |
696 | na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0); | ||
697 | na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0); | ||
698 | na->ats_active = GNUNET_NO; | ||
699 | na->keep_alive_nonce = 0; | ||
702 | na->session = NULL; | 700 | na->session = NULL; |
703 | } | 701 | } |
704 | 702 | ||
705 | 703 | ||
706 | /** | 704 | /** |
707 | * Set net state for this neighbour and notify monitoring | 705 | * Master task run for every neighbour. Performs all of the time-related |
706 | * activities (keep alive, send next message, disconnect if idle, finish | ||
707 | * clean up after disconnect). | ||
708 | * | 708 | * |
709 | * @param n the respective neighbour | 709 | * @param cls the `struct NeighbourMapEntry` for which we are running |
710 | * @param s the new state | 710 | * @param tc scheduler context (unused) |
711 | */ | 711 | */ |
712 | static void | 712 | static void |
713 | set_state (struct NeighbourMapEntry *n, | 713 | master_task (void *cls, |
714 | enum GNUNET_TRANSPORT_PeerState s) | 714 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
715 | { | ||
716 | n->state = s; | ||
717 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
718 | "Neighbour `%s' changed state to %s\n", | ||
719 | GNUNET_i2s (&n->id), | ||
720 | GNUNET_TRANSPORT_ps2s(s)); | ||
721 | neighbours_changed_notification (&n->id, | ||
722 | n->primary_address.address, | ||
723 | n->state, | ||
724 | n->timeout, | ||
725 | n->primary_address.bandwidth_in, | ||
726 | n->primary_address.bandwidth_out); | ||
727 | } | ||
728 | 715 | ||
729 | 716 | ||
730 | /** | 717 | /** |
@@ -739,7 +726,36 @@ set_state_and_timeout (struct NeighbourMapEntry *n, | |||
739 | enum GNUNET_TRANSPORT_PeerState s, | 726 | enum GNUNET_TRANSPORT_PeerState s, |
740 | struct GNUNET_TIME_Absolute timeout) | 727 | struct GNUNET_TIME_Absolute timeout) |
741 | { | 728 | { |
729 | if (GNUNET_TRANSPORT_is_connected (s) && | ||
730 | ! GNUNET_TRANSPORT_is_connected (n->state) ) | ||
731 | { | ||
732 | neighbours_connect_notification (&n->id, | ||
733 | n->primary_address.bandwidth_in, | ||
734 | n->primary_address.bandwidth_out); | ||
735 | GNUNET_STATISTICS_set (GST_stats, | ||
736 | gettext_noop ("# peers connected"), | ||
737 | ++neighbours_connected, | ||
738 | GNUNET_NO); | ||
739 | } | ||
740 | if (! GNUNET_TRANSPORT_is_connected (s) && | ||
741 | GNUNET_TRANSPORT_is_connected (n->state) ) | ||
742 | { | ||
743 | GNUNET_STATISTICS_set (GST_stats, | ||
744 | gettext_noop ("# peers connected"), | ||
745 | --neighbours_connected, | ||
746 | GNUNET_NO); | ||
747 | neighbours_disconnect_notification (&n->id); | ||
748 | } | ||
742 | n->state = s; | 749 | n->state = s; |
750 | if ( (timeout.abs_value_us < n->timeout.abs_value_us) && | ||
751 | (NULL != n->task ) ) | ||
752 | { | ||
753 | /* new timeout is earlier, reschedule master task */ | ||
754 | GNUNET_SCHEDULER_cancel (n->task); | ||
755 | n->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (timeout), | ||
756 | &master_task, | ||
757 | n); | ||
758 | } | ||
743 | n->timeout = timeout; | 759 | n->timeout = timeout; |
744 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 760 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
745 | "Neighbour `%s' changed state to %s with timeout %s\n", | 761 | "Neighbour `%s' changed state to %s with timeout %s\n", |
@@ -756,29 +772,6 @@ set_state_and_timeout (struct NeighbourMapEntry *n, | |||
756 | 772 | ||
757 | 773 | ||
758 | /** | 774 | /** |
759 | * Set new state timeout for this neighbour and notify monitoring | ||
760 | * | ||
761 | * @param n the respective neighbour | ||
762 | * @param timeout the new timeout | ||
763 | */ | ||
764 | static void | ||
765 | set_timeout (struct NeighbourMapEntry *n, | ||
766 | struct GNUNET_TIME_Absolute timeout) | ||
767 | { | ||
768 | n->timeout = timeout; | ||
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
770 | "Neighbour `%s' changed timeout %s\n", | ||
771 | GNUNET_i2s (&n->id), | ||
772 | GNUNET_STRINGS_absolute_time_to_string (timeout)); | ||
773 | neighbours_changed_notification (&n->id, | ||
774 | n->primary_address.address, | ||
775 | n->state, n->timeout, | ||
776 | n->primary_address.bandwidth_in, | ||
777 | n->primary_address.bandwidth_out); | ||
778 | } | ||
779 | |||
780 | |||
781 | /** | ||
782 | * Initialize the alternative address of a neighbour | 775 | * Initialize the alternative address of a neighbour |
783 | * | 776 | * |
784 | * @param n the neighbour | 777 | * @param n the neighbour |
@@ -809,9 +802,15 @@ set_alternative_address (struct NeighbourMapEntry *n, | |||
809 | n->alternative_address.bandwidth_out = bandwidth_out; | 802 | n->alternative_address.bandwidth_out = bandwidth_out; |
810 | return; | 803 | return; |
811 | } | 804 | } |
812 | free_address (&n->alternative_address); | 805 | if (NULL != n->alternative_address.address) |
806 | { | ||
807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
808 | "Replacing existing alternative address with another one\n"); | ||
809 | free_address (&n->alternative_address); | ||
810 | } | ||
813 | if (NULL == session) | 811 | if (NULL == session) |
814 | session = papi->get_session (papi->cls, address); | 812 | session = papi->get_session (papi->cls, |
813 | address); | ||
815 | if (NULL == session) | 814 | if (NULL == session) |
816 | { | 815 | { |
817 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -824,7 +823,8 @@ set_alternative_address (struct NeighbourMapEntry *n, | |||
824 | GNUNET_NO); | 823 | GNUNET_NO); |
825 | return; | 824 | return; |
826 | } | 825 | } |
827 | GST_ats_new_session (address, session); | 826 | GST_ats_new_session (address, |
827 | session); | ||
828 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 828 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
829 | "Neighbour `%s' configured alternative address %s\n", | 829 | "Neighbour `%s' configured alternative address %s\n", |
830 | GNUNET_i2s (&n->id), | 830 | GNUNET_i2s (&n->id), |
@@ -859,48 +859,50 @@ set_primary_address (struct NeighbourMapEntry *n, | |||
859 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 859 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
860 | int is_active) | 860 | int is_active) |
861 | { | 861 | { |
862 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
863 | |||
864 | if (NULL == (papi = GST_plugins_find (address->transport_name))) | ||
865 | { | ||
866 | GNUNET_break (0); | ||
867 | return; | ||
868 | } | ||
869 | if (session == n->primary_address.session) | 862 | if (session == n->primary_address.session) |
870 | { | 863 | { |
871 | n->primary_address.bandwidth_in = bandwidth_in; | ||
872 | n->primary_address.bandwidth_out = bandwidth_out; | ||
873 | if (is_active != n->primary_address.ats_active) | 864 | if (is_active != n->primary_address.ats_active) |
874 | { | 865 | { |
875 | n->primary_address.ats_active = is_active; | 866 | n->primary_address.ats_active = is_active; |
876 | GST_ats_set_in_use (n->primary_address.address, | ||
877 | n->primary_address.session, | ||
878 | is_active); | ||
879 | GST_validation_set_address_use (n->primary_address.address, | 867 | GST_validation_set_address_use (n->primary_address.address, |
880 | is_active); | 868 | is_active); |
881 | } | 869 | } |
882 | if (GNUNET_YES == is_active) | 870 | if (GNUNET_YES == is_active) |
883 | { | 871 | { |
884 | GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in); | 872 | if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) |
885 | send_outbound_quota (&address->peer, bandwidth_out); | 873 | { |
874 | n->primary_address.bandwidth_in = bandwidth_in; | ||
875 | GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in); | ||
876 | } | ||
877 | if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) | ||
878 | { | ||
879 | n->primary_address.bandwidth_out = bandwidth_out; | ||
880 | send_outbound_quota (&address->peer, | ||
881 | bandwidth_out); | ||
882 | } | ||
886 | } | 883 | } |
887 | return; | 884 | return; |
888 | } | 885 | } |
889 | free_address (&n->primary_address); | 886 | if ( (NULL != n->primary_address.address) && |
890 | if (NULL == session) | 887 | (0 == GNUNET_HELLO_address_cmp (address, |
891 | session = papi->get_session (papi->cls, address); | 888 | n->primary_address.address)) ) |
889 | { | ||
890 | GNUNET_break (0); | ||
891 | return; | ||
892 | } | ||
892 | if (NULL == session) | 893 | if (NULL == session) |
893 | { | 894 | { |
894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 895 | GNUNET_break (0); |
895 | "Failed to obtain new session for peer `%s' and address '%s'\n", | 896 | GST_ats_block_address (address, |
896 | GNUNET_i2s (&address->peer), GST_plugins_a2s (address)); | 897 | session); |
897 | GNUNET_STATISTICS_update (GST_stats, | ||
898 | gettext_noop ("# session creation failed"), | ||
899 | 1, | ||
900 | GNUNET_NO); | ||
901 | return; | 898 | return; |
902 | } | 899 | } |
903 | GST_ats_new_session (address, session); | 900 | if (NULL != n->primary_address.address) |
901 | { | ||
902 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
903 | "Replacing existing primary address with another one\n"); | ||
904 | free_address (&n->primary_address); | ||
905 | } | ||
904 | n->primary_address.address = GNUNET_HELLO_address_copy (address); | 906 | n->primary_address.address = GNUNET_HELLO_address_copy (address); |
905 | n->primary_address.bandwidth_in = bandwidth_in; | 907 | n->primary_address.bandwidth_in = bandwidth_in; |
906 | n->primary_address.bandwidth_out = bandwidth_out; | 908 | n->primary_address.bandwidth_out = bandwidth_out; |
@@ -909,14 +911,12 @@ set_primary_address (struct NeighbourMapEntry *n, | |||
909 | n->primary_address.keep_alive_nonce = 0; | 911 | n->primary_address.keep_alive_nonce = 0; |
910 | if (GNUNET_YES == is_active) | 912 | if (GNUNET_YES == is_active) |
911 | { | 913 | { |
912 | /* Telling ATS about new session */ | 914 | /* subsystems about address use */ |
913 | GST_ats_set_in_use (n->primary_address.address, | ||
914 | n->primary_address.session, | ||
915 | GNUNET_YES); | ||
916 | GST_validation_set_address_use (n->primary_address.address, | 915 | GST_validation_set_address_use (n->primary_address.address, |
917 | GNUNET_YES); | 916 | GNUNET_YES); |
918 | GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in); | 917 | GST_neighbours_set_incoming_quota (&address->peer, bandwidth_in); |
919 | send_outbound_quota (&address->peer, bandwidth_out); | 918 | send_outbound_quota (&address->peer, |
919 | bandwidth_out); | ||
920 | } | 920 | } |
921 | 921 | ||
922 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 922 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -943,32 +943,21 @@ static void | |||
943 | unset_primary_address (struct NeighbourMapEntry *n) | 943 | unset_primary_address (struct NeighbourMapEntry *n) |
944 | { | 944 | { |
945 | /* Notify monitoring about change */ | 945 | /* Notify monitoring about change */ |
946 | if (NULL == n->primary_address.address) | ||
947 | return; | ||
948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
949 | "Disabling primary address\n"); | ||
946 | neighbours_changed_notification (&n->id, | 950 | neighbours_changed_notification (&n->id, |
947 | n->primary_address.address, | 951 | n->primary_address.address, |
948 | n->state, | 952 | n->state, |
949 | n->timeout, | 953 | n->timeout, |
950 | GNUNET_BANDWIDTH_value_init (0), | 954 | GNUNET_BANDWIDTH_value_init (0), |
951 | GNUNET_BANDWIDTH_value_init (0)); | 955 | GNUNET_BANDWIDTH_value_init (0)); |
952 | /* Unset primary address */ | ||
953 | free_address (&n->primary_address); | 956 | free_address (&n->primary_address); |
954 | } | 957 | } |
955 | 958 | ||
956 | 959 | ||
957 | /** | 960 | /** |
958 | * Clear the alternative address of a neighbour since this address is not | ||
959 | * valid anymore | ||
960 | * | ||
961 | * @param n the neighbour | ||
962 | */ | ||
963 | static void | ||
964 | unset_alternative_address (struct NeighbourMapEntry *n) | ||
965 | { | ||
966 | /* Unset primary address */ | ||
967 | free_address (&n->alternative_address); | ||
968 | } | ||
969 | |||
970 | |||
971 | /** | ||
972 | * Free a neighbour map entry. | 961 | * Free a neighbour map entry. |
973 | * | 962 | * |
974 | * @param n entry to free | 963 | * @param n entry to free |
@@ -986,29 +975,29 @@ free_neighbour (struct NeighbourMapEntry *n) | |||
986 | /* fail messages currently in the queue */ | 975 | /* fail messages currently in the queue */ |
987 | while (NULL != (mq = n->messages_head)) | 976 | while (NULL != (mq = n->messages_head)) |
988 | { | 977 | { |
989 | GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); | 978 | GNUNET_CONTAINER_DLL_remove (n->messages_head, |
979 | n->messages_tail, | ||
980 | mq); | ||
990 | if (NULL != mq->cont) | 981 | if (NULL != mq->cont) |
991 | mq->cont (mq->cont_cls, GNUNET_SYSERR, mq->message_buf_size, 0); | 982 | mq->cont (mq->cont_cls, |
983 | GNUNET_SYSERR, | ||
984 | mq->message_buf_size, | ||
985 | 0); | ||
992 | GNUNET_free (mq); | 986 | GNUNET_free (mq); |
993 | } | 987 | } |
994 | /* It is too late to send other peer disconnect notifications, but at | ||
995 | least internally we need to get clean... */ | ||
996 | if (GNUNET_YES == test_connected (n)) | ||
997 | { | ||
998 | GNUNET_STATISTICS_set (GST_stats, | ||
999 | gettext_noop ("# peers connected"), | ||
1000 | --neighbours_connected, | ||
1001 | GNUNET_NO); | ||
1002 | neighbours_disconnect_notification (&n->id); | ||
1003 | } | ||
1004 | |||
1005 | /* Mark peer as disconnected */ | 988 | /* Mark peer as disconnected */ |
1006 | set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED); | 989 | set_state_and_timeout (n, |
1007 | 990 | GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, | |
991 | GNUNET_TIME_UNIT_FOREVER_ABS); | ||
1008 | /* free addresses and mark as unused */ | 992 | /* free addresses and mark as unused */ |
1009 | unset_primary_address (n); | 993 | unset_primary_address (n); |
1010 | free_address (&n->alternative_address); | ||
1011 | 994 | ||
995 | if (NULL != n->alternative_address.address) | ||
996 | { | ||
997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
998 | "Cleaning up alternative address\n"); | ||
999 | free_address (&n->alternative_address); | ||
1000 | } | ||
1012 | GNUNET_assert (GNUNET_YES == | 1001 | GNUNET_assert (GNUNET_YES == |
1013 | GNUNET_CONTAINER_multipeermap_remove (neighbours, | 1002 | GNUNET_CONTAINER_multipeermap_remove (neighbours, |
1014 | &n->id, n)); | 1003 | &n->id, n)); |
@@ -1056,7 +1045,8 @@ free_neighbour (struct NeighbourMapEntry *n) | |||
1056 | */ | 1045 | */ |
1057 | static struct GNUNET_TIME_Relative | 1046 | static struct GNUNET_TIME_Relative |
1058 | send_with_session (struct NeighbourMapEntry *n, | 1047 | send_with_session (struct NeighbourMapEntry *n, |
1059 | const char *msgbuf, size_t msgbuf_size, | 1048 | const void *msgbuf, |
1049 | size_t msgbuf_size, | ||
1060 | uint32_t priority, | 1050 | uint32_t priority, |
1061 | struct GNUNET_TIME_Relative timeout, | 1051 | struct GNUNET_TIME_Relative timeout, |
1062 | unsigned int use_keepalive_timeout, | 1052 | unsigned int use_keepalive_timeout, |
@@ -1070,14 +1060,20 @@ send_with_session (struct NeighbourMapEntry *n, | |||
1070 | if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) || | 1060 | if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) || |
1071 | (-1 == papi->send (papi->cls, | 1061 | (-1 == papi->send (papi->cls, |
1072 | n->primary_address.session, | 1062 | n->primary_address.session, |
1073 | msgbuf, msgbuf_size, | 1063 | msgbuf, |
1064 | msgbuf_size, | ||
1074 | priority, | 1065 | priority, |
1075 | (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : | 1066 | (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : |
1076 | GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1067 | GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1077 | papi->query_keepalive_factor (papi->cls))), | 1068 | papi->query_keepalive_factor (papi->cls))), |
1078 | cont, cont_cls)))) && | 1069 | cont, |
1070 | cont_cls)))) && | ||
1079 | (NULL != cont)) | 1071 | (NULL != cont)) |
1080 | cont (cont_cls, &n->id, GNUNET_SYSERR, msgbuf_size, 0); | 1072 | cont (cont_cls, |
1073 | &n->id, | ||
1074 | GNUNET_SYSERR, | ||
1075 | msgbuf_size, | ||
1076 | 0); | ||
1081 | GST_neighbours_notify_data_sent (n->primary_address.address, | 1077 | GST_neighbours_notify_data_sent (n->primary_address.address, |
1082 | n->primary_address.session, | 1078 | n->primary_address.session, |
1083 | msgbuf_size); | 1079 | msgbuf_size); |
@@ -1087,19 +1083,6 @@ send_with_session (struct NeighbourMapEntry *n, | |||
1087 | 1083 | ||
1088 | 1084 | ||
1089 | /** | 1085 | /** |
1090 | * Master task run for every neighbour. Performs all of the time-related | ||
1091 | * activities (keep alive, send next message, disconnect if idle, finish | ||
1092 | * clean up after disconnect). | ||
1093 | * | ||
1094 | * @param cls the `struct NeighbourMapEntry` for which we are running | ||
1095 | * @param tc scheduler context (unused) | ||
1096 | */ | ||
1097 | static void | ||
1098 | master_task (void *cls, | ||
1099 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
1100 | |||
1101 | |||
1102 | /** | ||
1103 | * Function called when the 'DISCONNECT' message has been sent by the | 1086 | * Function called when the 'DISCONNECT' message has been sent by the |
1104 | * plugin. Frees the neighbour --- if the entry still exists. | 1087 | * plugin. Frees the neighbour --- if the entry still exists. |
1105 | * | 1088 | * |
@@ -1107,11 +1090,14 @@ master_task (void *cls, | |||
1107 | * @param target identity of the neighbour that was disconnected | 1090 | * @param target identity of the neighbour that was disconnected |
1108 | * @param result #GNUNET_OK if the disconnect got out successfully | 1091 | * @param result #GNUNET_OK if the disconnect got out successfully |
1109 | * @param payload bytes payload | 1092 | * @param payload bytes payload |
1110 | * @param physical bytes physical | 1093 | * @param physical bytes on wire |
1111 | */ | 1094 | */ |
1112 | static void | 1095 | static void |
1113 | send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, | 1096 | send_disconnect_cont (void *cls, |
1114 | int result, size_t payload, size_t physical) | 1097 | const struct GNUNET_PeerIdentity *target, |
1098 | int result, | ||
1099 | size_t payload, | ||
1100 | size_t physical) | ||
1115 | { | 1101 | { |
1116 | struct NeighbourMapEntry *n; | 1102 | struct NeighbourMapEntry *n; |
1117 | 1103 | ||
@@ -1157,12 +1143,17 @@ send_disconnect (struct NeighbourMapEntry *n) | |||
1157 | &disconnect_msg.purpose, | 1143 | &disconnect_msg.purpose, |
1158 | &disconnect_msg.signature)); | 1144 | &disconnect_msg.signature)); |
1159 | 1145 | ||
1160 | (void) send_with_session (n, (const char *) &disconnect_msg, | 1146 | (void) send_with_session (n, |
1161 | sizeof (disconnect_msg), UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, | 1147 | &disconnect_msg, |
1162 | GNUNET_NO, &send_disconnect_cont, NULL ); | 1148 | sizeof (disconnect_msg), |
1149 | UINT32_MAX, | ||
1150 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1151 | GNUNET_NO, | ||
1152 | &send_disconnect_cont, | ||
1153 | NULL); | ||
1163 | GNUNET_STATISTICS_update (GST_stats, | 1154 | GNUNET_STATISTICS_update (GST_stats, |
1164 | gettext_noop | 1155 | gettext_noop ("# DISCONNECT messages sent"), |
1165 | ("# DISCONNECT messages sent"), 1, | 1156 | 1, |
1166 | GNUNET_NO); | 1157 | GNUNET_NO); |
1167 | } | 1158 | } |
1168 | 1159 | ||
@@ -1190,7 +1181,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
1190 | return; | 1181 | return; |
1191 | case GNUNET_TRANSPORT_PS_SYN_SENT: | 1182 | case GNUNET_TRANSPORT_PS_SYN_SENT: |
1192 | send_disconnect (n); | 1183 | send_disconnect (n); |
1193 | set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); | 1184 | set_state_and_timeout (n, |
1185 | GNUNET_TRANSPORT_PS_DISCONNECT, | ||
1186 | GNUNET_TIME_UNIT_FOREVER_ABS); | ||
1194 | break; | 1187 | break; |
1195 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: | 1188 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: |
1196 | /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ | 1189 | /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ |
@@ -1199,7 +1192,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
1199 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: | 1192 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: |
1200 | /* we DID ACK the other peer's request, must send DISCONNECT */ | 1193 | /* we DID ACK the other peer's request, must send DISCONNECT */ |
1201 | send_disconnect (n); | 1194 | send_disconnect (n); |
1202 | set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); | 1195 | set_state_and_timeout (n, |
1196 | GNUNET_TRANSPORT_PS_DISCONNECT, | ||
1197 | GNUNET_TIME_UNIT_FOREVER_ABS); | ||
1203 | break; | 1198 | break; |
1204 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 1199 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
1205 | case GNUNET_TRANSPORT_PS_CONNECTED: | 1200 | case GNUNET_TRANSPORT_PS_CONNECTED: |
@@ -1207,12 +1202,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
1207 | /* we are currently connected, need to send disconnect and do | 1202 | /* we are currently connected, need to send disconnect and do |
1208 | internal notifications and update statistics */ | 1203 | internal notifications and update statistics */ |
1209 | send_disconnect (n); | 1204 | send_disconnect (n); |
1210 | GNUNET_STATISTICS_set (GST_stats, | 1205 | set_state_and_timeout (n, |
1211 | gettext_noop ("# peers connected"), | 1206 | GNUNET_TRANSPORT_PS_DISCONNECT, |
1212 | --neighbours_connected, | 1207 | GNUNET_TIME_UNIT_FOREVER_ABS); |
1213 | GNUNET_NO); | ||
1214 | neighbours_disconnect_notification (&n->id); | ||
1215 | set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); | ||
1216 | break; | 1208 | break; |
1217 | case GNUNET_TRANSPORT_PS_RECONNECT_ATS: | 1209 | case GNUNET_TRANSPORT_PS_RECONNECT_ATS: |
1218 | /* Disconnecting while waiting for an ATS address to reconnect, | 1210 | /* Disconnecting while waiting for an ATS address to reconnect, |
@@ -1237,7 +1229,8 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
1237 | if (NULL != n->task) | 1229 | if (NULL != n->task) |
1238 | GNUNET_SCHEDULER_cancel (n->task); | 1230 | GNUNET_SCHEDULER_cancel (n->task); |
1239 | n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT, | 1231 | n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT, |
1240 | &master_task, n); | 1232 | &master_task, |
1233 | n); | ||
1241 | } | 1234 | } |
1242 | 1235 | ||
1243 | 1236 | ||
@@ -1276,9 +1269,11 @@ transmit_send_continuation (void *cls, | |||
1276 | { | 1269 | { |
1277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1278 | "Bytes_in_send_queue `%u', Message_size %u, result: %s, payload %u, on wire %u\n", | 1271 | "Bytes_in_send_queue `%u', Message_size %u, result: %s, payload %u, on wire %u\n", |
1279 | bytes_in_send_queue, mq->message_buf_size, | 1272 | bytes_in_send_queue, |
1273 | mq->message_buf_size, | ||
1280 | (GNUNET_OK == success) ? "OK" : "FAIL", | 1274 | (GNUNET_OK == success) ? "OK" : "FAIL", |
1281 | size_payload, physical); | 1275 | size_payload, |
1276 | physical); | ||
1282 | GNUNET_break (0); | 1277 | GNUNET_break (0); |
1283 | } | 1278 | } |
1284 | 1279 | ||
@@ -1357,28 +1352,35 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) | |||
1357 | gettext_noop | 1352 | gettext_noop |
1358 | ("# messages timed out while in transport queue"), | 1353 | ("# messages timed out while in transport queue"), |
1359 | 1, GNUNET_NO); | 1354 | 1, GNUNET_NO); |
1360 | GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); | 1355 | GNUNET_CONTAINER_DLL_remove (n->messages_head, |
1356 | n->messages_tail, | ||
1357 | mq); | ||
1361 | n->is_active = mq; | 1358 | n->is_active = mq; |
1362 | transmit_send_continuation (mq, &n->id, | 1359 | transmit_send_continuation (mq, |
1360 | &n->id, | ||
1363 | GNUNET_SYSERR, | 1361 | GNUNET_SYSERR, |
1364 | mq->message_buf_size, 0); /* timeout */ | 1362 | mq->message_buf_size, |
1363 | 0); /* timeout */ | ||
1365 | } | 1364 | } |
1366 | if (NULL == mq) | 1365 | if (NULL == mq) |
1367 | return; /* no more messages */ | 1366 | return; /* no more messages */ |
1368 | GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); | 1367 | GNUNET_CONTAINER_DLL_remove (n->messages_head, |
1368 | n->messages_tail, | ||
1369 | mq); | ||
1369 | n->is_active = mq; | 1370 | n->is_active = mq; |
1370 | 1371 | ||
1371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1372 | "Giving message with %u bytes to plugin session %p\n", | 1373 | "Giving message with %u bytes to plugin session %p\n", |
1373 | mq->message_buf_size, n->primary_address.session); | 1374 | mq->message_buf_size, |
1374 | 1375 | n->primary_address.session); | |
1375 | (void) send_with_session (n, | 1376 | (void) send_with_session (n, |
1376 | mq->message_buf, | 1377 | mq->message_buf, |
1377 | mq->message_buf_size, | 1378 | mq->message_buf_size, |
1378 | 0 /* priority */, | 1379 | 0 /* priority */, |
1379 | timeout, | 1380 | timeout, |
1380 | GNUNET_NO, | 1381 | GNUNET_NO, |
1381 | &transmit_send_continuation, mq); | 1382 | &transmit_send_continuation, |
1383 | mq); | ||
1382 | } | 1384 | } |
1383 | 1385 | ||
1384 | 1386 | ||
@@ -1398,7 +1400,7 @@ send_keepalive (struct NeighbourMapEntry *n) | |||
1398 | uint32_t nonce; | 1400 | uint32_t nonce; |
1399 | 1401 | ||
1400 | GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || | 1402 | GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || |
1401 | (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT)); | 1403 | (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)); |
1402 | if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0) | 1404 | if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0) |
1403 | return; /* no keepalive needed at this time */ | 1405 | return; /* no keepalive needed at this time */ |
1404 | 1406 | ||
@@ -1407,25 +1409,28 @@ send_keepalive (struct NeighbourMapEntry *n) | |||
1407 | nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 1409 | nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
1408 | 1410 | ||
1409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1410 | "Sending keep alive to peer `%s' with nonce %u\n", | 1412 | "Sending keep alive to peer `%s' with nonce %u\n", |
1411 | GNUNET_i2s (&n->id), nonce); | 1413 | GNUNET_i2s (&n->id), |
1412 | 1414 | nonce); | |
1413 | m.header.size = htons (sizeof (struct SessionKeepAliveMessage)); | 1415 | m.header.size = htons (sizeof (struct SessionKeepAliveMessage)); |
1414 | m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); | 1416 | m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); |
1415 | m.nonce = htonl (nonce); | 1417 | m.nonce = htonl (nonce); |
1416 | 1418 | ||
1417 | timeout = send_with_session (n, | 1419 | timeout = send_with_session (n, |
1418 | (const void *) &m, sizeof (m), | 1420 | &m, |
1421 | sizeof (m), | ||
1419 | UINT32_MAX /* priority */, | 1422 | UINT32_MAX /* priority */, |
1420 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, | 1423 | GNUNET_TIME_UNIT_FOREVER_REL, |
1424 | GNUNET_YES, | ||
1421 | NULL, NULL); | 1425 | NULL, NULL); |
1422 | GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1, | 1426 | GNUNET_STATISTICS_update (GST_stats, |
1427 | gettext_noop ("# keepalives sent"), | ||
1428 | 1, | ||
1423 | GNUNET_NO); | 1429 | GNUNET_NO); |
1424 | n->primary_address.keep_alive_nonce = nonce; | 1430 | n->primary_address.keep_alive_nonce = nonce; |
1425 | n->expect_latency_response = GNUNET_YES; | 1431 | n->expect_latency_response = GNUNET_YES; |
1426 | n->last_keep_alive_time = GNUNET_TIME_absolute_get (); | 1432 | n->last_keep_alive_time = GNUNET_TIME_absolute_get (); |
1427 | n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout); | 1433 | n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout); |
1428 | |||
1429 | } | 1434 | } |
1430 | 1435 | ||
1431 | 1436 | ||
@@ -1473,11 +1478,13 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour, | |||
1473 | msg.header.size = htons (sizeof (struct SessionKeepAliveMessage)); | 1478 | msg.header.size = htons (sizeof (struct SessionKeepAliveMessage)); |
1474 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); | 1479 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); |
1475 | msg.nonce = msg_in->nonce; | 1480 | msg.nonce = msg_in->nonce; |
1476 | (void) send_with_session(n, | 1481 | (void) send_with_session (n, |
1477 | (const void *) &msg, sizeof (struct SessionKeepAliveMessage), | 1482 | &msg, |
1478 | UINT32_MAX /* priority */, | 1483 | sizeof (struct SessionKeepAliveMessage), |
1479 | GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, | 1484 | UINT32_MAX /* priority */, |
1480 | NULL, NULL); | 1485 | GNUNET_TIME_UNIT_FOREVER_REL, |
1486 | GNUNET_YES, | ||
1487 | NULL, NULL); | ||
1481 | } | 1488 | } |
1482 | 1489 | ||
1483 | 1490 | ||
@@ -1559,7 +1566,9 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, | |||
1559 | 1566 | ||
1560 | n->primary_address.keep_alive_nonce = 0; | 1567 | n->primary_address.keep_alive_nonce = 0; |
1561 | n->expect_latency_response = GNUNET_NO; | 1568 | n->expect_latency_response = GNUNET_NO; |
1562 | set_timeout (n, GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | 1569 | set_state_and_timeout (n, |
1570 | n->state, | ||
1571 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | ||
1563 | 1572 | ||
1564 | latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time); | 1573 | latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time); |
1565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1653,9 +1662,8 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity | |||
1653 | if (ret.rel_value_us > 0) | 1662 | if (ret.rel_value_us > 0) |
1654 | { | 1663 | { |
1655 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1656 | "Throttling read (%llu bytes excess at %u b/s), waiting %s before reading more.\n", | 1665 | "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n", |
1657 | (unsigned long long) n->in_tracker. | 1666 | (long long) n->in_tracker.consumption_since_last_update__, |
1658 | consumption_since_last_update__, | ||
1659 | (unsigned int) n->in_tracker.available_bytes_per_s__, | 1667 | (unsigned int) n->in_tracker.available_bytes_per_s__, |
1660 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | 1668 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); |
1661 | GNUNET_STATISTICS_update (GST_stats, | 1669 | GNUNET_STATISTICS_update (GST_stats, |
@@ -1728,14 +1736,23 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | |||
1728 | 1736 | ||
1729 | 1737 | ||
1730 | /** | 1738 | /** |
1731 | * FIXME | 1739 | * Continuation called from our attempt to transmitted our |
1740 | * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN to the specified @a | ||
1741 | * target. Continue processing based on the @a result. Specifically, | ||
1742 | * if we failed to transmit, discard the address we used. | ||
1743 | * | ||
1744 | * @param cls NULL | ||
1745 | * @param target which peer received the transmission | ||
1746 | * @param result #GNUNET_OK if sending worked | ||
1747 | * @param size_payload how many bytes of payload were sent (ignored) | ||
1748 | * @param size_on_wire how much bandwidth was consumed on the wire (ignored) | ||
1732 | */ | 1749 | */ |
1733 | static void | 1750 | static void |
1734 | send_session_connect_cont (void *cls, | 1751 | send_session_syn_cont (void *cls, |
1735 | const struct GNUNET_PeerIdentity *target, | 1752 | const struct GNUNET_PeerIdentity *target, |
1736 | int result, | 1753 | int result, |
1737 | size_t size_payload, | 1754 | size_t size_payload, |
1738 | size_t size_on_wire) | 1755 | size_t size_on_wire) |
1739 | { | 1756 | { |
1740 | struct NeighbourMapEntry *n; | 1757 | struct NeighbourMapEntry *n; |
1741 | 1758 | ||
@@ -1761,31 +1778,35 @@ send_session_connect_cont (void *cls, | |||
1761 | return; | 1778 | return; |
1762 | 1779 | ||
1763 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1780 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1764 | _("Failed to send SYN message to peer `%s' using address `%s' session %p\n"), | 1781 | _("Failed to send SYN message to peer `%s'\n"), |
1765 | GNUNET_i2s (target), | 1782 | GNUNET_i2s (target)); |
1766 | GST_plugins_a2s (n->primary_address.address), | ||
1767 | n->primary_address.session); | ||
1768 | |||
1769 | switch (n->state) { | 1783 | switch (n->state) { |
1770 | case GNUNET_TRANSPORT_PS_SYN_SENT: | 1784 | case GNUNET_TRANSPORT_PS_SYN_SENT: |
1771 | /* Remove address and request an additional one */ | 1785 | /* Remove address and request an additional one */ |
1772 | unset_primary_address (n); | 1786 | unset_primary_address (n); |
1773 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, | 1787 | set_state_and_timeout (n, |
1788 | GNUNET_TRANSPORT_PS_INIT_ATS, | ||
1774 | GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); | 1789 | GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); |
1775 | break; | 1790 | break; |
1776 | case GNUNET_TRANSPORT_PS_RECONNECT_SENT: | 1791 | case GNUNET_TRANSPORT_PS_RECONNECT_SENT: |
1777 | /* Remove address and request an additional one */ | 1792 | /* Remove address and request an additional one */ |
1778 | unset_primary_address (n); | 1793 | unset_primary_address (n); |
1779 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, | 1794 | set_state_and_timeout (n, |
1780 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 1795 | GNUNET_TRANSPORT_PS_RECONNECT_ATS, |
1796 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
1781 | break; | 1797 | break; |
1782 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 1798 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
1783 | /* Remove address and request and go back to primary address */ | 1799 | /* Remove address and request and go back to primary address */ |
1784 | GNUNET_STATISTICS_update (GST_stats, gettext_noop | 1800 | GNUNET_STATISTICS_update (GST_stats, |
1785 | ("# Failed attempts to switch addresses (failed to send SYN CONT)"), 1, GNUNET_NO); | 1801 | gettext_noop ("# Failed attempts to switch addresses (failed to send SYN CONT)"), |
1786 | unset_alternative_address (n); | 1802 | 1, |
1787 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, | 1803 | GNUNET_NO); |
1788 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 1804 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1805 | "Switch failed, cleaning up alternative address\n"); | ||
1806 | free_address (&n->alternative_address); | ||
1807 | set_state_and_timeout (n, | ||
1808 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
1809 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
1789 | break; | 1810 | break; |
1790 | default: | 1811 | default: |
1791 | disconnect_neighbour (n); | 1812 | disconnect_neighbour (n); |
@@ -1793,6 +1814,7 @@ send_session_connect_cont (void *cls, | |||
1793 | } | 1814 | } |
1794 | } | 1815 | } |
1795 | 1816 | ||
1817 | |||
1796 | /** | 1818 | /** |
1797 | * Send a SYN message via the given address. | 1819 | * Send a SYN message via the given address. |
1798 | * | 1820 | * |
@@ -1805,24 +1827,14 @@ send_syn (struct NeighbourAddress *na) | |||
1805 | struct TransportSynMessage connect_msg; | 1827 | struct TransportSynMessage connect_msg; |
1806 | struct NeighbourMapEntry *n; | 1828 | struct NeighbourMapEntry *n; |
1807 | 1829 | ||
1830 | GNUNET_assert (NULL != na->session); | ||
1808 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1831 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1809 | "Sending SYN message to peer `%s'\n", | 1832 | "Sending SYN message to peer `%s' at %s\n", |
1810 | GNUNET_i2s (&na->address->peer)); | 1833 | GNUNET_i2s (&na->address->peer), |
1834 | GST_plugins_a2s (na->address)); | ||
1811 | 1835 | ||
1812 | if (NULL == (papi = GST_plugins_find (na->address->transport_name))) | 1836 | papi = GST_plugins_find (na->address->transport_name); |
1813 | { | 1837 | GNUNET_assert (NULL != papi); |
1814 | GNUNET_break (0); | ||
1815 | return; | ||
1816 | } | ||
1817 | if (NULL == na->session) | ||
1818 | na->session = papi->get_session (papi->cls, na->address); | ||
1819 | if (NULL == na->session) | ||
1820 | { | ||
1821 | GNUNET_break (0); | ||
1822 | return; | ||
1823 | } | ||
1824 | GST_ats_new_session (na->address, | ||
1825 | na->session); | ||
1826 | GNUNET_STATISTICS_update (GST_stats, | 1838 | GNUNET_STATISTICS_update (GST_stats, |
1827 | gettext_noop | 1839 | gettext_noop |
1828 | ("# SYN messages sent"), | 1840 | ("# SYN messages sent"), |
@@ -1835,46 +1847,56 @@ send_syn (struct NeighbourAddress *na) | |||
1835 | if (-1 == | 1847 | if (-1 == |
1836 | papi->send (papi->cls, | 1848 | papi->send (papi->cls, |
1837 | na->session, | 1849 | na->session, |
1838 | (const char *) &connect_msg, sizeof (struct TransportSynMessage), | 1850 | (const char *) &connect_msg, |
1851 | sizeof (struct TransportSynMessage), | ||
1839 | UINT_MAX, | 1852 | UINT_MAX, |
1840 | SETUP_CONNECTION_TIMEOUT, | 1853 | SETUP_CONNECTION_TIMEOUT, |
1841 | send_session_connect_cont, NULL)) | 1854 | &send_session_syn_cont, NULL)) |
1842 | { | 1855 | { |
1843 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1856 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1844 | _("Failed to transmit SYN message via plugin to %s\n"), | 1857 | _("Failed to transmit SYN message to %s\n"), |
1845 | GST_plugins_a2s (na->address)); | 1858 | GST_plugins_a2s (na->address)); |
1846 | |||
1847 | n = lookup_neighbour (&na->address->peer); | 1859 | n = lookup_neighbour (&na->address->peer); |
1848 | if (NULL == n) | 1860 | if (NULL == n) |
1849 | { | 1861 | { |
1850 | GNUNET_break (0); | 1862 | GNUNET_break (0); |
1851 | return; | 1863 | return; |
1852 | } | 1864 | } |
1853 | |||
1854 | switch (n->state) { | 1865 | switch (n->state) { |
1855 | case GNUNET_TRANSPORT_PS_SYN_SENT: | 1866 | case GNUNET_TRANSPORT_PS_SYN_SENT: |
1856 | /* Remove address and request and additional one */ | 1867 | /* Remove address and request and additional one */ |
1868 | GNUNET_assert (na == &n->primary_address); | ||
1857 | unset_primary_address (n); | 1869 | unset_primary_address (n); |
1858 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, | 1870 | set_state_and_timeout (n, |
1859 | GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); | 1871 | GNUNET_TRANSPORT_PS_INIT_ATS, |
1872 | GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); | ||
1860 | /* Hard failure to send the SYN message with this address: | 1873 | /* Hard failure to send the SYN message with this address: |
1861 | Destroy address and session */ | 1874 | Destroy address and session */ |
1862 | break; | 1875 | break; |
1863 | case GNUNET_TRANSPORT_PS_RECONNECT_SENT: | 1876 | case GNUNET_TRANSPORT_PS_RECONNECT_SENT: |
1864 | /* Remove address and request an additional one */ | 1877 | /* Remove address and request an additional one */ |
1878 | GNUNET_assert (na == &n->primary_address); | ||
1865 | unset_primary_address (n); | 1879 | unset_primary_address (n); |
1866 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, | 1880 | set_state_and_timeout (n, |
1867 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 1881 | GNUNET_TRANSPORT_PS_RECONNECT_ATS, |
1882 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
1868 | break; | 1883 | break; |
1869 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 1884 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
1870 | GNUNET_STATISTICS_update (GST_stats, gettext_noop | 1885 | GNUNET_assert (na == &n->alternative_address); |
1871 | ("# Failed attempts to switch addresses (failed to send SYN)"), 1, GNUNET_NO); | 1886 | GNUNET_STATISTICS_update (GST_stats, |
1887 | gettext_noop ("# Failed attempts to switch addresses (failed to send SYN)"), | ||
1888 | 1, | ||
1889 | GNUNET_NO); | ||
1872 | /* Remove address and request an additional one */ | 1890 | /* Remove address and request an additional one */ |
1873 | unset_alternative_address (n); | 1891 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1874 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, | 1892 | "Switch failed, cleaning up alternative address\n"); |
1875 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 1893 | free_address (&n->alternative_address); |
1894 | set_state_and_timeout (n, | ||
1895 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
1896 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
1876 | break; | 1897 | break; |
1877 | default: | 1898 | default: |
1899 | GNUNET_break (0); | ||
1878 | disconnect_neighbour (n); | 1900 | disconnect_neighbour (n); |
1879 | break; | 1901 | break; |
1880 | } | 1902 | } |
@@ -1886,14 +1908,23 @@ send_syn (struct NeighbourAddress *na) | |||
1886 | 1908 | ||
1887 | 1909 | ||
1888 | /** | 1910 | /** |
1889 | * FIXME. | 1911 | * Continuation called from our attempt to transmitted our |
1912 | * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK to the specified @a | ||
1913 | * target. Continue processing based on the @a result. Specifically, | ||
1914 | * if we failed to transmit, discard the address we used. | ||
1915 | * | ||
1916 | * @param cls NULL | ||
1917 | * @param target which peer received the transmission | ||
1918 | * @param result #GNUNET_OK if sending worked | ||
1919 | * @param size_payload how many bytes of payload were sent (ignored) | ||
1920 | * @param size_on_wire how much bandwidth was consumed on the wire (ignored) | ||
1890 | */ | 1921 | */ |
1891 | static void | 1922 | static void |
1892 | send_session_connect_ack_cont (void *cls, | 1923 | send_session_syn_ack_cont (void *cls, |
1893 | const struct GNUNET_PeerIdentity *target, | 1924 | const struct GNUNET_PeerIdentity *target, |
1894 | int result, | 1925 | int result, |
1895 | size_t size_payload, | 1926 | size_t size_payload, |
1896 | size_t size_on_wire) | 1927 | size_t size_on_wire) |
1897 | { | 1928 | { |
1898 | struct NeighbourMapEntry *n; | 1929 | struct NeighbourMapEntry *n; |
1899 | 1930 | ||
@@ -1917,33 +1948,35 @@ send_session_connect_ack_cont (void *cls, | |||
1917 | return; | 1948 | return; |
1918 | 1949 | ||
1919 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1950 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1920 | _("Failed to send SYN_ACK message to peer `%s' using address `%s' session %p\n"), | 1951 | _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"), |
1921 | GNUNET_i2s (target), | 1952 | GNUNET_i2s (target), |
1922 | GST_plugins_a2s (n->primary_address.address), | 1953 | GST_plugins_a2s (n->primary_address.address)); |
1923 | n->primary_address.session); | ||
1924 | 1954 | ||
1925 | /* Remove address and request and additional one */ | 1955 | /* Remove address and request and additional one */ |
1956 | /* FIXME: what if the neighbour's primary address | ||
1957 | changed in the meantime? Might want to instead | ||
1958 | pass "something" around in closure to be sure. */ | ||
1926 | unset_primary_address (n); | 1959 | unset_primary_address (n); |
1927 | n->ack_state = ACK_SEND_SYN_ACK; | 1960 | n->ack_state = ACK_SEND_SYN_ACK; |
1928 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, | 1961 | set_state_and_timeout (n, |
1962 | GNUNET_TRANSPORT_PS_SYN_RECV_ATS, | ||
1929 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 1963 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); |
1930 | return; | ||
1931 | } | 1964 | } |
1932 | 1965 | ||
1933 | 1966 | ||
1934 | /** | 1967 | /** |
1935 | * Send a SYN_ACK message via the given address. | 1968 | * Send a SYN_ACK message via the given address. |
1936 | * | 1969 | * |
1937 | * @param address address to use | 1970 | * @param na address and session to use |
1938 | * @param session session to use | ||
1939 | * @param timestamp timestamp to use for the ACK message | 1971 | * @param timestamp timestamp to use for the ACK message |
1940 | * @return GNUNET_SYSERR if sending immediately failed, GNUNET_OK otherwise | 1972 | * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise |
1941 | */ | 1973 | */ |
1942 | static void | 1974 | static void |
1943 | send_connect_ack_message (const struct GNUNET_HELLO_Address *address, | 1975 | send_syn_ack_message (struct NeighbourAddress *na, |
1944 | struct Session *session, | 1976 | struct GNUNET_TIME_Absolute timestamp) |
1945 | struct GNUNET_TIME_Absolute timestamp) | ||
1946 | { | 1977 | { |
1978 | const struct GNUNET_HELLO_Address *address = na->address; | ||
1979 | struct Session *session = na->session; | ||
1947 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 1980 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
1948 | struct TransportSynMessage connect_msg; | 1981 | struct TransportSynMessage connect_msg; |
1949 | struct NeighbourMapEntry *n; | 1982 | struct NeighbourMapEntry *n; |
@@ -1958,13 +1991,15 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address, | |||
1958 | return; | 1991 | return; |
1959 | } | 1992 | } |
1960 | if (NULL == session) | 1993 | if (NULL == session) |
1961 | session = papi->get_session (papi->cls, address); | 1994 | session = papi->get_session (papi->cls, |
1995 | address); | ||
1962 | if (NULL == session) | 1996 | if (NULL == session) |
1963 | { | 1997 | { |
1964 | GNUNET_break (0); | 1998 | GNUNET_break (0); |
1965 | return; | 1999 | return; |
1966 | } | 2000 | } |
1967 | GST_ats_new_session (address, session); | 2001 | GST_ats_new_session (address, |
2002 | session); | ||
1968 | GNUNET_STATISTICS_update (GST_stats, | 2003 | GNUNET_STATISTICS_update (GST_stats, |
1969 | gettext_noop | 2004 | gettext_noop |
1970 | ("# SYN_ACK messages sent"), | 2005 | ("# SYN_ACK messages sent"), |
@@ -1974,15 +2009,17 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address, | |||
1974 | connect_msg.reserved = htonl (0); | 2009 | connect_msg.reserved = htonl (0); |
1975 | connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp); | 2010 | connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp); |
1976 | 2011 | ||
1977 | if (GNUNET_SYSERR == papi->send (papi->cls, | 2012 | if (GNUNET_SYSERR == |
1978 | session, | 2013 | papi->send (papi->cls, |
1979 | (const char *) &connect_msg, sizeof (struct TransportSynMessage), | 2014 | session, |
1980 | UINT_MAX, | 2015 | (const char *) &connect_msg, |
1981 | GNUNET_TIME_UNIT_FOREVER_REL, | 2016 | sizeof (struct TransportSynMessage), |
1982 | send_session_connect_ack_cont, NULL)) | 2017 | UINT_MAX, |
2018 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2019 | &send_session_syn_ack_cont, NULL)) | ||
1983 | { | 2020 | { |
1984 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2021 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1985 | _("Failed to transmit SYN_ACK message via plugin to %s\n"), | 2022 | _("Failed to transmit SYN_ACK message to %s\n"), |
1986 | GST_plugins_a2s (address)); | 2023 | GST_plugins_a2s (address)); |
1987 | 2024 | ||
1988 | n = lookup_neighbour (&address->peer); | 2025 | n = lookup_neighbour (&address->peer); |
@@ -1994,11 +2031,11 @@ send_connect_ack_message (const struct GNUNET_HELLO_Address *address, | |||
1994 | /* Remove address and request and additional one */ | 2031 | /* Remove address and request and additional one */ |
1995 | unset_primary_address (n); | 2032 | unset_primary_address (n); |
1996 | n->ack_state = ACK_SEND_SYN_ACK; | 2033 | n->ack_state = ACK_SEND_SYN_ACK; |
1997 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, | 2034 | set_state_and_timeout (n, |
1998 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 2035 | GNUNET_TRANSPORT_PS_SYN_RECV_ATS, |
2036 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
1999 | return; | 2037 | return; |
2000 | } | 2038 | } |
2001 | |||
2002 | } | 2039 | } |
2003 | 2040 | ||
2004 | 2041 | ||
@@ -2056,10 +2093,6 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
2056 | n->id = *peer; | 2093 | n->id = *peer; |
2057 | n->ack_state = ACK_UNDEFINED; | 2094 | n->ack_state = ACK_UNDEFINED; |
2058 | n->last_util_transmission = GNUNET_TIME_absolute_get(); | 2095 | n->last_util_transmission = GNUNET_TIME_absolute_get(); |
2059 | n->util_payload_bytes_recv = 0; | ||
2060 | n->util_payload_bytes_sent = 0; | ||
2061 | n->util_total_bytes_recv = 0; | ||
2062 | n->util_total_bytes_sent = 0; | ||
2063 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, | 2096 | GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, |
2064 | &inbound_bw_tracker_update, | 2097 | &inbound_bw_tracker_update, |
2065 | n, | 2098 | n, |
@@ -2073,6 +2106,9 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
2073 | GNUNET_CONTAINER_multipeermap_put (neighbours, | 2106 | GNUNET_CONTAINER_multipeermap_put (neighbours, |
2074 | &n->id, n, | 2107 | &n->id, n, |
2075 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2108 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2109 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, | ||
2110 | peer); | ||
2111 | |||
2076 | return n; | 2112 | return n; |
2077 | } | 2113 | } |
2078 | 2114 | ||
@@ -2157,10 +2193,6 @@ try_connect_bl_check_cont (void *cls, | |||
2157 | set_state_and_timeout (n, | 2193 | set_state_and_timeout (n, |
2158 | GNUNET_TRANSPORT_PS_INIT_ATS, | 2194 | GNUNET_TRANSPORT_PS_INIT_ATS, |
2159 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 2195 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); |
2160 | GNUNET_ATS_reset_backoff (GST_ats, peer); | ||
2161 | GNUNET_assert (NULL == n->suggest_handle); | ||
2162 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, | ||
2163 | peer); | ||
2164 | } | 2196 | } |
2165 | 2197 | ||
2166 | 2198 | ||
@@ -2304,17 +2336,16 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2304 | { | 2336 | { |
2305 | case GNUNET_TRANSPORT_PS_NOT_CONNECTED: | 2337 | case GNUNET_TRANSPORT_PS_NOT_CONNECTED: |
2306 | /* Request an address from ATS to send SYN_ACK to this peer */ | 2338 | /* Request an address from ATS to send SYN_ACK to this peer */ |
2307 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, | 2339 | set_state_and_timeout (n, |
2308 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 2340 | GNUNET_TRANSPORT_PS_SYN_RECV_ATS, |
2309 | if (NULL == n->suggest_handle) | 2341 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); |
2310 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, | ||
2311 | peer); | ||
2312 | break; | 2342 | break; |
2313 | case GNUNET_TRANSPORT_PS_INIT_ATS: | 2343 | case GNUNET_TRANSPORT_PS_INIT_ATS: |
2314 | /* SYN message takes priority over us asking ATS for address: | 2344 | /* SYN message takes priority over us asking ATS for address: |
2315 | * Wait for ATS to suggest an address and send SYN_ACK */ | 2345 | * Wait for ATS to suggest an address and send SYN_ACK */ |
2316 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, | 2346 | set_state_and_timeout (n, |
2317 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 2347 | GNUNET_TRANSPORT_PS_SYN_RECV_ATS, |
2348 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
2318 | break; | 2349 | break; |
2319 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: | 2350 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: |
2320 | /* We already wait for an address to send an SYN_ACK */ | 2351 | /* We already wait for an address to send an SYN_ACK */ |
@@ -2323,16 +2354,16 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2323 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: | 2354 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: |
2324 | /* Send ACK immediately */ | 2355 | /* Send ACK immediately */ |
2325 | n->ack_state = ACK_SEND_ACK; | 2356 | n->ack_state = ACK_SEND_ACK; |
2326 | send_connect_ack_message (n->primary_address.address, | 2357 | send_syn_ack_message (&n->primary_address, |
2327 | n->primary_address.session, ts); | 2358 | ts); |
2328 | break; | 2359 | break; |
2329 | case GNUNET_TRANSPORT_PS_CONNECTED: | 2360 | case GNUNET_TRANSPORT_PS_CONNECTED: |
2330 | /* we are already connected and can thus send the ACK immediately */ | 2361 | /* we are already connected and can thus send the ACK immediately */ |
2331 | GNUNET_assert (NULL != n->primary_address.address); | 2362 | GNUNET_assert (NULL != n->primary_address.address); |
2332 | GNUNET_assert (NULL != n->primary_address.session); | 2363 | GNUNET_assert (NULL != n->primary_address.session); |
2333 | n->ack_state = ACK_SEND_ACK; | 2364 | n->ack_state = ACK_SEND_ACK; |
2334 | send_connect_ack_message (n->primary_address.address, | 2365 | send_syn_ack_message (&n->primary_address, |
2335 | n->primary_address.session, ts); | 2366 | ts); |
2336 | break; | 2367 | break; |
2337 | case GNUNET_TRANSPORT_PS_RECONNECT_ATS: | 2368 | case GNUNET_TRANSPORT_PS_RECONNECT_ATS: |
2338 | /* We wait for ATS address suggestion */ | 2369 | /* We wait for ATS address suggestion */ |
@@ -2341,8 +2372,8 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2341 | /* We received a SYN message while waiting for a SYN_ACK in fast | 2372 | /* We received a SYN message while waiting for a SYN_ACK in fast |
2342 | * reconnect. Send SYN_ACK immediately */ | 2373 | * reconnect. Send SYN_ACK immediately */ |
2343 | n->ack_state = ACK_SEND_ACK; | 2374 | n->ack_state = ACK_SEND_ACK; |
2344 | send_connect_ack_message (n->primary_address.address, | 2375 | send_syn_ack_message (&n->primary_address, |
2345 | n->primary_address.session, n->connect_ack_timestamp); | 2376 | n->connect_ack_timestamp); |
2346 | break; | 2377 | break; |
2347 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 2378 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
2348 | /* We are already connected and can thus send the ACK immediately; | 2379 | /* We are already connected and can thus send the ACK immediately; |
@@ -2351,8 +2382,8 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2351 | GNUNET_assert (NULL != n->primary_address.address); | 2382 | GNUNET_assert (NULL != n->primary_address.address); |
2352 | GNUNET_assert (NULL != n->primary_address.session); | 2383 | GNUNET_assert (NULL != n->primary_address.session); |
2353 | n->ack_state = ACK_SEND_ACK; | 2384 | n->ack_state = ACK_SEND_ACK; |
2354 | send_connect_ack_message (n->primary_address.address, | 2385 | send_syn_ack_message (&n->primary_address, |
2355 | n->primary_address.session, ts); | 2386 | ts); |
2356 | break; | 2387 | break; |
2357 | case GNUNET_TRANSPORT_PS_DISCONNECT: | 2388 | case GNUNET_TRANSPORT_PS_DISCONNECT: |
2358 | /* Get rid of remains and re-try */ | 2389 | /* Get rid of remains and re-try */ |
@@ -2362,10 +2393,9 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, | |||
2362 | n->ack_state = ACK_SEND_SYN_ACK; | 2393 | n->ack_state = ACK_SEND_SYN_ACK; |
2363 | n->connect_ack_timestamp = ts; | 2394 | n->connect_ack_timestamp = ts; |
2364 | /* Request an address for the peer */ | 2395 | /* Request an address for the peer */ |
2365 | n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, | 2396 | set_state_and_timeout (n, |
2366 | peer); | 2397 | GNUNET_TRANSPORT_PS_SYN_RECV_ATS, |
2367 | GNUNET_ATS_reset_backoff (GST_ats, peer); | 2398 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); |
2368 | set_state (n, GNUNET_TRANSPORT_PS_SYN_RECV_ATS); | ||
2369 | break; | 2399 | break; |
2370 | case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: | 2400 | case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: |
2371 | /* should not be possible */ | 2401 | /* should not be possible */ |
@@ -2405,7 +2435,6 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address, | |||
2405 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 2435 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
2406 | { | 2436 | { |
2407 | struct NeighbourMapEntry *n; | 2437 | struct NeighbourMapEntry *n; |
2408 | int connected; | ||
2409 | 2438 | ||
2410 | n = lookup_neighbour (&address->peer); | 2439 | n = lookup_neighbour (&address->peer); |
2411 | if ( (NULL == n) || | 2440 | if ( (NULL == n) || |
@@ -2419,16 +2448,7 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address, | |||
2419 | { | 2448 | { |
2420 | /* switch to a different session, but keeping same address; could | 2449 | /* switch to a different session, but keeping same address; could |
2421 | happen if there is a 2nd inbound connection */ | 2450 | happen if there is a 2nd inbound connection */ |
2422 | connected = GNUNET_TRANSPORT_is_connected (n->state); | ||
2423 | if (GNUNET_YES == connected) | ||
2424 | GST_ats_set_in_use (n->primary_address.address, | ||
2425 | n->primary_address.session, | ||
2426 | GNUNET_NO); | ||
2427 | n->primary_address.session = session; | 2451 | n->primary_address.session = session; |
2428 | if (GNUNET_YES == connected) | ||
2429 | GST_ats_set_in_use (n->primary_address.address, | ||
2430 | n->primary_address.session, | ||
2431 | GNUNET_YES); | ||
2432 | } | 2452 | } |
2433 | n->primary_address.bandwidth_in = bandwidth_in; | 2453 | n->primary_address.bandwidth_in = bandwidth_in; |
2434 | n->primary_address.bandwidth_out = bandwidth_out; | 2454 | n->primary_address.bandwidth_out = bandwidth_out; |
@@ -2470,8 +2490,10 @@ switch_address_bl_check_cont (void *cls, | |||
2470 | "# ATS suggestions ignored (blacklist denied)", | 2490 | "# ATS suggestions ignored (blacklist denied)", |
2471 | 1, | 2491 | 1, |
2472 | GNUNET_NO); | 2492 | GNUNET_NO); |
2473 | /* FIXME: tell plugin to force killing session here and now! */ | 2493 | /* FIXME: tell plugin to force killing session here and now |
2474 | /* FIXME: Let ATS know that the suggested address did not work! */ | 2494 | (note: _proper_ plugin API for this does not yet exist) */ |
2495 | GST_ats_block_address (blc_ctx->address, | ||
2496 | blc_ctx->session); | ||
2475 | goto cleanup; | 2497 | goto cleanup; |
2476 | } | 2498 | } |
2477 | 2499 | ||
@@ -2501,10 +2523,11 @@ switch_address_bl_check_cont (void *cls, | |||
2501 | GNUNET_NO); | 2523 | GNUNET_NO); |
2502 | /* No session could be obtained, remove blacklist check and clean up */ | 2524 | /* No session could be obtained, remove blacklist check and clean up */ |
2503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2504 | "Failed to obtain new session for peer `%s' and address '%s'\n", | 2526 | "Failed to obtain new session for peer `%s' and address '%s'\n", |
2505 | GNUNET_i2s (&blc_ctx->address->peer), | 2527 | GNUNET_i2s (&blc_ctx->address->peer), |
2506 | GST_plugins_a2s (blc_ctx->address)); | 2528 | GST_plugins_a2s (blc_ctx->address)); |
2507 | /* FIXME: Let ATS know that the suggested address did not work! */ | 2529 | GST_ats_block_address (blc_ctx->address, |
2530 | blc_ctx->session); | ||
2508 | goto cleanup; | 2531 | goto cleanup; |
2509 | } | 2532 | } |
2510 | 2533 | ||
@@ -2526,15 +2549,16 @@ switch_address_bl_check_cont (void *cls, | |||
2526 | } | 2549 | } |
2527 | 2550 | ||
2528 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2551 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2529 | "Peer `%s' switches to address `%s' session %p\n", | 2552 | "Peer `%s' switches to address `%s'\n", |
2530 | GNUNET_i2s (&blc_ctx->address->peer), | 2553 | GNUNET_i2s (&blc_ctx->address->peer), |
2531 | GST_plugins_a2s (blc_ctx->address), | 2554 | GST_plugins_a2s (blc_ctx->address)); |
2532 | blc_ctx->session); | ||
2533 | 2555 | ||
2534 | switch (n->state) | 2556 | switch (n->state) |
2535 | { | 2557 | { |
2536 | case GNUNET_TRANSPORT_PS_NOT_CONNECTED: | 2558 | case GNUNET_TRANSPORT_PS_NOT_CONNECTED: |
2537 | GNUNET_break (0); | 2559 | GNUNET_break (0); |
2560 | GST_ats_block_address (blc_ctx->address, | ||
2561 | blc_ctx->session); | ||
2538 | free_neighbour (n); | 2562 | free_neighbour (n); |
2539 | return; | 2563 | return; |
2540 | case GNUNET_TRANSPORT_PS_INIT_ATS: | 2564 | case GNUNET_TRANSPORT_PS_INIT_ATS: |
@@ -2550,9 +2574,8 @@ switch_address_bl_check_cont (void *cls, | |||
2550 | { | 2574 | { |
2551 | /* Send pending SYN_ACK message */ | 2575 | /* Send pending SYN_ACK message */ |
2552 | n->ack_state = ACK_SEND_ACK; | 2576 | n->ack_state = ACK_SEND_ACK; |
2553 | send_connect_ack_message (n->primary_address.address, | 2577 | send_syn_ack_message (&n->primary_address, |
2554 | n->primary_address.session, | 2578 | n->connect_ack_timestamp); |
2555 | n->connect_ack_timestamp); | ||
2556 | } | 2579 | } |
2557 | set_state_and_timeout (n, | 2580 | set_state_and_timeout (n, |
2558 | GNUNET_TRANSPORT_PS_SYN_SENT, | 2581 | GNUNET_TRANSPORT_PS_SYN_SENT, |
@@ -2573,9 +2596,8 @@ switch_address_bl_check_cont (void *cls, | |||
2573 | { | 2596 | { |
2574 | /* Send pending SYN_ACK message */ | 2597 | /* Send pending SYN_ACK message */ |
2575 | n->ack_state = ACK_SEND_ACK; | 2598 | n->ack_state = ACK_SEND_ACK; |
2576 | send_connect_ack_message (n->primary_address.address, | 2599 | send_syn_ack_message (&n->primary_address, |
2577 | n->primary_address.session, | 2600 | n->connect_ack_timestamp); |
2578 | n->connect_ack_timestamp); | ||
2579 | } | 2601 | } |
2580 | set_state_and_timeout (n, | 2602 | set_state_and_timeout (n, |
2581 | GNUNET_TRANSPORT_PS_SYN_SENT, | 2603 | GNUNET_TRANSPORT_PS_SYN_SENT, |
@@ -2595,9 +2617,8 @@ switch_address_bl_check_cont (void *cls, | |||
2595 | set_state_and_timeout (n, | 2617 | set_state_and_timeout (n, |
2596 | GNUNET_TRANSPORT_PS_SYN_RECV_ACK, | 2618 | GNUNET_TRANSPORT_PS_SYN_RECV_ACK, |
2597 | GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); | 2619 | GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); |
2598 | send_connect_ack_message (n->primary_address.address, | 2620 | send_syn_ack_message (&n->primary_address, |
2599 | n->primary_address.session, | 2621 | n->connect_ack_timestamp); |
2600 | n->connect_ack_timestamp); | ||
2601 | if ( (ACK_SEND_SYN_ACK == n->ack_state) || | 2622 | if ( (ACK_SEND_SYN_ACK == n->ack_state) || |
2602 | (ACK_UNDEFINED == n->ack_state) ) | 2623 | (ACK_UNDEFINED == n->ack_state) ) |
2603 | n->ack_state = ACK_SEND_ACK; | 2624 | n->ack_state = ACK_SEND_ACK; |
@@ -2608,9 +2629,8 @@ switch_address_bl_check_cont (void *cls, | |||
2608 | if ( (ACK_SEND_SYN_ACK == n->ack_state) ) | 2629 | if ( (ACK_SEND_SYN_ACK == n->ack_state) ) |
2609 | { | 2630 | { |
2610 | n->ack_state = ACK_SEND_ACK; | 2631 | n->ack_state = ACK_SEND_ACK; |
2611 | send_connect_ack_message (n->primary_address.address, | 2632 | send_syn_ack_message (&n->primary_address, |
2612 | n->primary_address.session, | 2633 | n->connect_ack_timestamp); |
2613 | n->connect_ack_timestamp); | ||
2614 | } | 2634 | } |
2615 | set_primary_address (n, | 2635 | set_primary_address (n, |
2616 | blc_ctx->address, | 2636 | blc_ctx->address, |
@@ -2625,18 +2645,7 @@ switch_address_bl_check_cont (void *cls, | |||
2625 | case GNUNET_TRANSPORT_PS_CONNECTED: | 2645 | case GNUNET_TRANSPORT_PS_CONNECTED: |
2626 | GNUNET_assert (NULL != n->primary_address.address); | 2646 | GNUNET_assert (NULL != n->primary_address.address); |
2627 | GNUNET_assert (NULL != n->primary_address.session); | 2647 | GNUNET_assert (NULL != n->primary_address.session); |
2628 | if (n->primary_address.session == blc_ctx->session) | 2648 | GNUNET_break (n->primary_address.session != blc_ctx->session); |
2629 | { | ||
2630 | /* not an address change, just a quota change */ | ||
2631 | // FIXME: this case should have been caught above! | ||
2632 | set_primary_address (n, | ||
2633 | blc_ctx->address, | ||
2634 | blc_ctx->session, | ||
2635 | blc_ctx->bandwidth_in, | ||
2636 | blc_ctx->bandwidth_out, | ||
2637 | GNUNET_YES); | ||
2638 | break; | ||
2639 | } | ||
2640 | /* ATS asks us to switch a life connection; see if we can get | 2649 | /* ATS asks us to switch a life connection; see if we can get |
2641 | a SYN_ACK on it before we actually do this! */ | 2650 | a SYN_ACK on it before we actually do this! */ |
2642 | set_alternative_address (n, | 2651 | set_alternative_address (n, |
@@ -2644,7 +2653,8 @@ switch_address_bl_check_cont (void *cls, | |||
2644 | blc_ctx->session, | 2653 | blc_ctx->session, |
2645 | blc_ctx->bandwidth_in, | 2654 | blc_ctx->bandwidth_in, |
2646 | blc_ctx->bandwidth_out); | 2655 | blc_ctx->bandwidth_out); |
2647 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, | 2656 | set_state_and_timeout (n, |
2657 | GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, | ||
2648 | GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); | 2658 | GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); |
2649 | GNUNET_STATISTICS_update (GST_stats, | 2659 | GNUNET_STATISTICS_update (GST_stats, |
2650 | gettext_noop ("# Attempts to switch addresses"), | 2660 | gettext_noop ("# Attempts to switch addresses"), |
@@ -2663,9 +2673,8 @@ switch_address_bl_check_cont (void *cls, | |||
2663 | { | 2673 | { |
2664 | /* Send pending SYN_ACK message */ | 2674 | /* Send pending SYN_ACK message */ |
2665 | n->ack_state = ACK_SEND_ACK; | 2675 | n->ack_state = ACK_SEND_ACK; |
2666 | send_connect_ack_message (n->primary_address.address, | 2676 | send_syn_ack_message (&n->primary_address, |
2667 | n->primary_address.session, | 2677 | n->connect_ack_timestamp); |
2668 | n->connect_ack_timestamp); | ||
2669 | } | 2678 | } |
2670 | set_state_and_timeout (n, | 2679 | set_state_and_timeout (n, |
2671 | GNUNET_TRANSPORT_PS_RECONNECT_SENT, | 2680 | GNUNET_TRANSPORT_PS_RECONNECT_SENT, |
@@ -2687,13 +2696,17 @@ switch_address_bl_check_cont (void *cls, | |||
2687 | send_syn (&n->primary_address); | 2696 | send_syn (&n->primary_address); |
2688 | break; | 2697 | break; |
2689 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 2698 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
2690 | if ( (0 == GNUNET_HELLO_address_cmp(n->primary_address.address, | 2699 | if ( (0 == GNUNET_HELLO_address_cmp (n->primary_address.address, |
2691 | blc_ctx->address)) && | 2700 | blc_ctx->address)) && |
2692 | (n->primary_address.session == blc_ctx->session) ) | 2701 | (n->primary_address.session == blc_ctx->session) ) |
2693 | { | 2702 | { |
2694 | /* ATS switches back to still-active session */ | 2703 | /* ATS switches back to still-active session */ |
2704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2705 | "ATS double-switched, cleaning up alternative address\n"); | ||
2695 | free_address (&n->alternative_address); | 2706 | free_address (&n->alternative_address); |
2696 | set_state (n, GNUNET_TRANSPORT_PS_CONNECTED); | 2707 | set_state_and_timeout (n, |
2708 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
2709 | n->timeout); | ||
2697 | break; | 2710 | break; |
2698 | } | 2711 | } |
2699 | /* ATS asks us to switch a life connection, send */ | 2712 | /* ATS asks us to switch a life connection, send */ |
@@ -2737,7 +2750,11 @@ switch_address_bl_check_cont (void *cls, | |||
2737 | * For the given peer, switch to this address. | 2750 | * For the given peer, switch to this address. |
2738 | * | 2751 | * |
2739 | * Before accepting this addresses and actively using it, a blacklist check | 2752 | * Before accepting this addresses and actively using it, a blacklist check |
2740 | * is performed. If this blacklist check fails the address will be destroyed. | 2753 | * is performed. |
2754 | * | ||
2755 | * If any check fails or the suggestion can somehow not be followed, we | ||
2756 | * MUST call #GST_ats_block_address() to tell ATS that the suggestion | ||
2757 | * could not be satisfied and force ATS to do something else. | ||
2741 | * | 2758 | * |
2742 | * @param address address of the other peer, | 2759 | * @param address address of the other peer, |
2743 | * @param session session to use or NULL if transport should initiate a session | 2760 | * @param session session to use or NULL if transport should initiate a session |
@@ -2755,9 +2772,6 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, | |||
2755 | struct GST_BlacklistCheck *blc; | 2772 | struct GST_BlacklistCheck *blc; |
2756 | struct BlacklistCheckSwitchContext *blc_ctx; | 2773 | struct BlacklistCheckSwitchContext *blc_ctx; |
2757 | 2774 | ||
2758 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2759 | "ATS has decided on an address for peer %s\n", | ||
2760 | GNUNET_i2s (&address->peer)); | ||
2761 | GNUNET_assert (NULL != address->transport_name); | 2775 | GNUNET_assert (NULL != address->transport_name); |
2762 | if (GNUNET_OK == | 2776 | if (GNUNET_OK == |
2763 | try_run_fast_ats_update (address, | 2777 | try_run_fast_ats_update (address, |
@@ -2771,6 +2785,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, | |||
2771 | { | 2785 | { |
2772 | /* we don't have the plugin for this address */ | 2786 | /* we don't have the plugin for this address */ |
2773 | GNUNET_break (0); | 2787 | GNUNET_break (0); |
2788 | GST_ats_block_address (address, | ||
2789 | session); | ||
2774 | return; | 2790 | return; |
2775 | } | 2791 | } |
2776 | if ((NULL == session) && | 2792 | if ((NULL == session) && |
@@ -2779,14 +2795,13 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, | |||
2779 | { | 2795 | { |
2780 | /* This is a inbound address and we do not have a session to use! */ | 2796 | /* This is a inbound address and we do not have a session to use! */ |
2781 | GNUNET_break (0); | 2797 | GNUNET_break (0); |
2798 | GST_ats_block_address (address, | ||
2799 | session); | ||
2782 | return; | 2800 | return; |
2783 | } | 2801 | } |
2784 | 2802 | ||
2785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2786 | "ATS suggests %s address '%s' for peer `%s'\n", | 2804 | "ATS suggests address '%s' for peer `%s'\n", |
2787 | GNUNET_HELLO_address_check_option (address, | ||
2788 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) | ||
2789 | ? "inbound" : "outbound", | ||
2790 | GST_plugins_a2s (address), | 2805 | GST_plugins_a2s (address), |
2791 | GNUNET_i2s (&address->peer)); | 2806 | GNUNET_i2s (&address->peer)); |
2792 | 2807 | ||
@@ -2831,7 +2846,7 @@ send_utilization_data (void *cls, | |||
2831 | uint32_t bps_out; | 2846 | uint32_t bps_out; |
2832 | struct GNUNET_TIME_Relative delta; | 2847 | struct GNUNET_TIME_Relative delta; |
2833 | 2848 | ||
2834 | if (GNUNET_TRANSPORT_PS_CONNECTED != n->state) | 2849 | if (GNUNET_YES != test_connected (n)) |
2835 | return GNUNET_OK; | 2850 | return GNUNET_OK; |
2836 | delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission, | 2851 | delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission, |
2837 | GNUNET_TIME_absolute_get ()); | 2852 | GNUNET_TIME_absolute_get ()); |
@@ -2894,13 +2909,13 @@ utilization_transmission (void *cls, | |||
2894 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 2909 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
2895 | { | 2910 | { |
2896 | util_transmission_tk = NULL; | 2911 | util_transmission_tk = NULL; |
2897 | 2912 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, | |
2898 | if (0 < GNUNET_CONTAINER_multipeermap_size (neighbours)) | 2913 | &send_utilization_data, |
2899 | GNUNET_CONTAINER_multipeermap_iterate (neighbours, send_utilization_data, NULL); | 2914 | NULL); |
2900 | 2915 | util_transmission_tk | |
2901 | util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, | 2916 | = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, |
2902 | utilization_transmission, NULL); | 2917 | &utilization_transmission, |
2903 | 2918 | NULL); | |
2904 | } | 2919 | } |
2905 | 2920 | ||
2906 | 2921 | ||
@@ -3040,8 +3055,9 @@ master_task (void *cls, | |||
3040 | GNUNET_i2s (&n->id)); | 3055 | GNUNET_i2s (&n->id)); |
3041 | /* Remove address and request and additional one */ | 3056 | /* Remove address and request and additional one */ |
3042 | unset_primary_address (n); | 3057 | unset_primary_address (n); |
3043 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, | 3058 | set_state_and_timeout (n, |
3044 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 3059 | GNUNET_TRANSPORT_PS_INIT_ATS, |
3060 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
3045 | return; | 3061 | return; |
3046 | } | 3062 | } |
3047 | break; | 3063 | break; |
@@ -3100,15 +3116,12 @@ master_task (void *cls, | |||
3100 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 3116 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
3101 | if (0 == delay.rel_value_us) | 3117 | if (0 == delay.rel_value_us) |
3102 | { | 3118 | { |
3103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3104 | "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs (after trying to SYN on alternative address)\n", | 3120 | "Switch failed, cleaning up alternative address\n"); |
3105 | GNUNET_i2s (&n->id)); | 3121 | free_address (&n->alternative_address); |
3106 | GNUNET_STATISTICS_update (GST_stats, | 3122 | set_state_and_timeout (n, |
3107 | gettext_noop ("# Failed attempts to switch addresses (no response)"), | 3123 | GNUNET_TRANSPORT_PS_CONNECTED, |
3108 | 1, | 3124 | GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); |
3109 | GNUNET_NO); | ||
3110 | disconnect_neighbour (n); | ||
3111 | return; | ||
3112 | } | 3125 | } |
3113 | try_transmission_to_peer (n); | 3126 | try_transmission_to_peer (n); |
3114 | send_keepalive (n); | 3127 | send_keepalive (n); |
@@ -3130,6 +3143,7 @@ master_task (void *cls, | |||
3130 | GNUNET_break (0); | 3143 | GNUNET_break (0); |
3131 | break; | 3144 | break; |
3132 | } | 3145 | } |
3146 | delay = GNUNET_TIME_absolute_get_remaining (n->timeout); | ||
3133 | if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) || | 3147 | if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) || |
3134 | (GNUNET_TRANSPORT_PS_CONNECTED == n->state) ) | 3148 | (GNUNET_TRANSPORT_PS_CONNECTED == n->state) ) |
3135 | { | 3149 | { |
@@ -3157,15 +3171,19 @@ send_session_ack_message (struct NeighbourMapEntry *n) | |||
3157 | { | 3171 | { |
3158 | struct GNUNET_MessageHeader msg; | 3172 | struct GNUNET_MessageHeader msg; |
3159 | 3173 | ||
3160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sending ACK message to peer `%s'\n", | 3174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
3175 | "Sending ACK message to peer `%s'\n", | ||
3161 | GNUNET_i2s (&n->id)); | 3176 | GNUNET_i2s (&n->id)); |
3162 | 3177 | ||
3163 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 3178 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
3164 | msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); | 3179 | msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); |
3165 | (void) send_with_session(n, | 3180 | (void) send_with_session (n, |
3166 | (const char *) &msg, sizeof (struct GNUNET_MessageHeader), | 3181 | &msg, |
3167 | UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, | 3182 | sizeof (struct GNUNET_MessageHeader), |
3168 | NULL, NULL); | 3183 | UINT32_MAX, |
3184 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
3185 | GNUNET_NO, | ||
3186 | NULL, NULL); | ||
3169 | } | 3187 | } |
3170 | 3188 | ||
3171 | 3189 | ||
@@ -3173,7 +3191,7 @@ send_session_ack_message (struct NeighbourMapEntry *n) | |||
3173 | * We received a 'SESSION_SYN_ACK' message from the other peer. | 3191 | * We received a 'SESSION_SYN_ACK' message from the other peer. |
3174 | * Consider switching to it. | 3192 | * Consider switching to it. |
3175 | * | 3193 | * |
3176 | * @param message possibly a 'struct SessionConnectMessage' (check format) | 3194 | * @param message possibly a `struct SessionConnectMessage` (check format) |
3177 | * @param peer identity of the peer to switch the address for | 3195 | * @param peer identity of the peer to switch the address for |
3178 | * @param address address of the other peer, NULL if other peer | 3196 | * @param address address of the other peer, NULL if other peer |
3179 | * connected to us | 3197 | * connected to us |
@@ -3189,10 +3207,6 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag | |||
3189 | struct GNUNET_TIME_Absolute ts; | 3207 | struct GNUNET_TIME_Absolute ts; |
3190 | struct NeighbourMapEntry *n; | 3208 | struct NeighbourMapEntry *n; |
3191 | 3209 | ||
3192 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
3193 | "Received SYN_ACK message from peer `%s'\n", | ||
3194 | GNUNET_i2s (&address->peer)); | ||
3195 | |||
3196 | if (ntohs (message->size) != sizeof (struct TransportSynMessage)) | 3210 | if (ntohs (message->size) != sizeof (struct TransportSynMessage)) |
3197 | { | 3211 | { |
3198 | GNUNET_break_op (0); | 3212 | GNUNET_break_op (0); |
@@ -3212,6 +3226,11 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag | |||
3212 | 1, GNUNET_NO); | 3226 | 1, GNUNET_NO); |
3213 | return GNUNET_SYSERR; | 3227 | return GNUNET_SYSERR; |
3214 | } | 3228 | } |
3229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3230 | "Received SYN_ACK message from peer `%s' in state %s/%s\n", | ||
3231 | GNUNET_i2s (&address->peer), | ||
3232 | GNUNET_TRANSPORT_ps2s (n->state), | ||
3233 | print_ack_state (n->ack_state)); | ||
3215 | ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); | 3234 | ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); |
3216 | switch (n->state) | 3235 | switch (n->state) |
3217 | { | 3236 | { |
@@ -3221,9 +3240,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag | |||
3221 | return GNUNET_SYSERR; | 3240 | return GNUNET_SYSERR; |
3222 | case GNUNET_TRANSPORT_PS_INIT_ATS: | 3241 | case GNUNET_TRANSPORT_PS_INIT_ATS: |
3223 | GNUNET_STATISTICS_update (GST_stats, | 3242 | GNUNET_STATISTICS_update (GST_stats, |
3224 | gettext_noop | 3243 | gettext_noop ("# unexpected SYN_ACK messages (not ready)"), |
3225 | ("# unexpected SYN_ACK messages (not ready)"), | 3244 | 1, |
3226 | 1, GNUNET_NO); | 3245 | GNUNET_NO); |
3227 | break; | 3246 | break; |
3228 | case GNUNET_TRANSPORT_PS_SYN_SENT: | 3247 | case GNUNET_TRANSPORT_PS_SYN_SENT: |
3229 | if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) | 3248 | if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) |
@@ -3232,16 +3251,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag | |||
3232 | "SYN_ACK ignored as the timestamp does not match our SYN request\n"); | 3251 | "SYN_ACK ignored as the timestamp does not match our SYN request\n"); |
3233 | return GNUNET_OK; | 3252 | return GNUNET_OK; |
3234 | } | 3253 | } |
3235 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, | 3254 | set_state_and_timeout (n, |
3236 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | 3255 | GNUNET_TRANSPORT_PS_CONNECTED, |
3237 | GNUNET_STATISTICS_set (GST_stats, | 3256 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); |
3238 | gettext_noop ("# peers connected"), | ||
3239 | ++neighbours_connected, | ||
3240 | GNUNET_NO); | ||
3241 | neighbours_connect_notification (&n->id, | ||
3242 | n->primary_address.bandwidth_in, | ||
3243 | n->primary_address.bandwidth_out); | ||
3244 | /* Tell ATS that the outbound session we created to send SYN was successful */ | ||
3245 | set_primary_address (n, | 3257 | set_primary_address (n, |
3246 | n->primary_address.address, | 3258 | n->primary_address.address, |
3247 | n->primary_address.session, | 3259 | n->primary_address.session, |
@@ -3253,9 +3265,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag | |||
3253 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: | 3265 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: |
3254 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: | 3266 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: |
3255 | GNUNET_STATISTICS_update (GST_stats, | 3267 | GNUNET_STATISTICS_update (GST_stats, |
3256 | gettext_noop | 3268 | gettext_noop ("# unexpected SYN_ACK messages (not ready)"), |
3257 | ("# unexpected SYN_ACK messages (not ready)"), | 3269 | 1, |
3258 | 1, GNUNET_NO); | 3270 | GNUNET_NO); |
3259 | break; | 3271 | break; |
3260 | case GNUNET_TRANSPORT_PS_CONNECTED: | 3272 | case GNUNET_TRANSPORT_PS_CONNECTED: |
3261 | /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */ | 3273 | /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */ |
@@ -3265,30 +3277,40 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag | |||
3265 | /* we didn't expect any SYN_ACK, as we are waiting for ATS | 3277 | /* we didn't expect any SYN_ACK, as we are waiting for ATS |
3266 | to give us a new address... */ | 3278 | to give us a new address... */ |
3267 | GNUNET_STATISTICS_update (GST_stats, | 3279 | GNUNET_STATISTICS_update (GST_stats, |
3268 | gettext_noop | 3280 | gettext_noop ("# unexpected SYN_ACK messages (waiting on ATS)"), |
3269 | ("# unexpected SYN_ACK messages (waiting on ATS)"), | 3281 | 1, |
3270 | 1, GNUNET_NO); | 3282 | GNUNET_NO); |
3271 | break; | 3283 | break; |
3272 | case GNUNET_TRANSPORT_PS_RECONNECT_SENT: | 3284 | case GNUNET_TRANSPORT_PS_RECONNECT_SENT: |
3273 | /* Reconnecting with new address address worked; go back to connected! */ | 3285 | /* Reconnecting with new address address worked; go back to connected! */ |
3274 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, | 3286 | set_state_and_timeout (n, |
3275 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | 3287 | GNUNET_TRANSPORT_PS_CONNECTED, |
3288 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | ||
3276 | send_session_ack_message (n); | 3289 | send_session_ack_message (n); |
3277 | break; | 3290 | break; |
3278 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 3291 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
3279 | /* new address worked; adopt it and go back to connected! */ | 3292 | /* new address worked; adopt it and go back to connected! */ |
3280 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, | 3293 | set_state_and_timeout (n, |
3294 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
3281 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | 3295 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); |
3282 | GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); | 3296 | GNUNET_break (GNUNET_NO == n->alternative_address.ats_active); |
3283 | 3297 | ||
3284 | /* Set primary addresses */ | 3298 | /* Set primary addresses */ |
3285 | set_primary_address (n, n->alternative_address.address, | 3299 | set_primary_address (n, |
3286 | n->alternative_address.session, n->alternative_address.bandwidth_in, | 3300 | n->alternative_address.address, |
3287 | n->alternative_address.bandwidth_out, GNUNET_YES); | 3301 | n->alternative_address.session, |
3288 | GNUNET_STATISTICS_update (GST_stats, gettext_noop | 3302 | n->alternative_address.bandwidth_in, |
3289 | ("# Successful attempts to switch addresses"), 1, GNUNET_NO); | 3303 | n->alternative_address.bandwidth_out, |
3304 | GNUNET_YES); | ||
3305 | GNUNET_STATISTICS_update (GST_stats, | ||
3306 | gettext_noop ("# Successful attempts to switch addresses"), | ||
3307 | 1, | ||
3308 | GNUNET_NO); | ||
3290 | 3309 | ||
3291 | free_address (&n->alternative_address); | 3310 | GNUNET_HELLO_address_free (n->alternative_address.address); |
3311 | memset (&n->alternative_address, | ||
3312 | 0, | ||
3313 | sizeof (n->alternative_address)); | ||
3292 | send_session_ack_message (n); | 3314 | send_session_ack_message (n); |
3293 | break; | 3315 | break; |
3294 | case GNUNET_TRANSPORT_PS_DISCONNECT: | 3316 | case GNUNET_TRANSPORT_PS_DISCONNECT: |
@@ -3351,8 +3373,12 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | |||
3351 | /* Free alternative address */ | 3373 | /* Free alternative address */ |
3352 | if (session == n->alternative_address.session) | 3374 | if (session == n->alternative_address.session) |
3353 | { | 3375 | { |
3354 | if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ) | 3376 | if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) |
3355 | set_state (n, GNUNET_TRANSPORT_PS_CONNECTED); | 3377 | set_state_and_timeout (n, |
3378 | GNUNET_TRANSPORT_PS_CONNECTED, | ||
3379 | n->timeout); | ||
3380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3381 | "Session died, cleaning up alternative address\n"); | ||
3356 | free_address (&n->alternative_address); | 3382 | free_address (&n->alternative_address); |
3357 | } | 3383 | } |
3358 | return GNUNET_NO; /* doesn't affect us further */ | 3384 | return GNUNET_NO; /* doesn't affect us further */ |
@@ -3382,20 +3408,21 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | |||
3382 | 3408 | ||
3383 | /* Destroy the address since it cannot be used */ | 3409 | /* Destroy the address since it cannot be used */ |
3384 | unset_primary_address (n); | 3410 | unset_primary_address (n); |
3385 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, | 3411 | set_state_and_timeout (n, |
3386 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 3412 | GNUNET_TRANSPORT_PS_INIT_ATS, |
3413 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
3387 | break; | 3414 | break; |
3388 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: | 3415 | case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: |
3389 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: | 3416 | case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: |
3390 | /* error on inbound session; free neighbour entirely */ | 3417 | /* error on inbound session; free neighbour entirely */ |
3391 | free_address (&n->primary_address); | ||
3392 | free_neighbour (n); | 3418 | free_neighbour (n); |
3393 | return GNUNET_YES; | 3419 | return GNUNET_YES; |
3394 | case GNUNET_TRANSPORT_PS_CONNECTED: | 3420 | case GNUNET_TRANSPORT_PS_CONNECTED: |
3395 | /* Our primary connection died, try a fast reconnect */ | 3421 | /* Our primary connection died, try a fast reconnect */ |
3396 | unset_primary_address (n); | 3422 | unset_primary_address (n); |
3397 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, | 3423 | set_state_and_timeout (n, |
3398 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 3424 | GNUNET_TRANSPORT_PS_RECONNECT_ATS, |
3425 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
3399 | break; | 3426 | break; |
3400 | case GNUNET_TRANSPORT_PS_RECONNECT_ATS: | 3427 | case GNUNET_TRANSPORT_PS_RECONNECT_ATS: |
3401 | /* we don't have an address, how can it go down? */ | 3428 | /* we don't have an address, how can it go down? */ |
@@ -3410,36 +3437,39 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | |||
3410 | GNUNET_i2s (peer)); | 3437 | GNUNET_i2s (peer)); |
3411 | /* Destroy the address since it cannot be used */ | 3438 | /* Destroy the address since it cannot be used */ |
3412 | unset_primary_address (n); | 3439 | unset_primary_address (n); |
3413 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, | 3440 | set_state_and_timeout (n, |
3414 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | 3441 | GNUNET_TRANSPORT_PS_RECONNECT_ATS, |
3442 | GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); | ||
3415 | break; | 3443 | break; |
3416 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: | 3444 | case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: |
3417 | /* primary went down while we were waiting for SYN_ACK on secondary; | 3445 | /* primary went down while we were waiting for SYN_ACK on secondary; |
3418 | secondary as primary */ | 3446 | secondary as primary */ |
3419 | 3447 | ||
3420 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3421 | "Connection `%s' %p to peer `%s' was terminated while switching, " | 3449 | "Connection `%s' %p to peer `%s' was terminated while switching, " |
3422 | "switching to alternative address `%s' %p\n", | 3450 | "switching to alternative address `%s' %p\n", |
3423 | GST_plugins_a2s (n->primary_address.address), | 3451 | GST_plugins_a2s (n->primary_address.address), |
3424 | n->primary_address.session, | 3452 | n->primary_address.session, |
3425 | GNUNET_i2s (peer), | 3453 | GNUNET_i2s (peer), |
3426 | GST_plugins_a2s (n->alternative_address.address), | 3454 | GST_plugins_a2s (n->alternative_address.address), |
3427 | n->alternative_address.session); | 3455 | n->alternative_address.session); |
3428 | 3456 | ||
3429 | /* Destroy the inbound address since it cannot be used */ | 3457 | /* Destroy the inbound address since it cannot be used */ |
3430 | free_address (&n->primary_address); | 3458 | free_address (&n->primary_address); |
3431 | n->primary_address = n->alternative_address; | 3459 | n->primary_address = n->alternative_address; |
3432 | memset (&n->alternative_address, 0, sizeof (struct NeighbourAddress)); | 3460 | memset (&n->alternative_address, |
3433 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_SENT, | 3461 | 0, |
3434 | GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); | 3462 | sizeof (struct NeighbourAddress)); |
3463 | set_state_and_timeout (n, | ||
3464 | GNUNET_TRANSPORT_PS_RECONNECT_SENT, | ||
3465 | GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); | ||
3435 | break; | 3466 | break; |
3436 | case GNUNET_TRANSPORT_PS_DISCONNECT: | 3467 | case GNUNET_TRANSPORT_PS_DISCONNECT: |
3437 | free_address (&n->primary_address); | 3468 | unset_primary_address (n); |
3438 | break; | 3469 | break; |
3439 | case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: | 3470 | case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: |
3440 | /* neighbour was freed and plugins told to terminate session */ | 3471 | /* neighbour was freed and plugins told to terminate session */ |
3441 | return GNUNET_NO; | 3472 | return GNUNET_NO; |
3442 | break; | ||
3443 | default: | 3473 | default: |
3444 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3474 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3445 | "Unhandled state `%s'\n", | 3475 | "Unhandled state `%s'\n", |
@@ -3471,9 +3501,6 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, | |||
3471 | { | 3501 | { |
3472 | struct NeighbourMapEntry *n; | 3502 | struct NeighbourMapEntry *n; |
3473 | 3503 | ||
3474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3475 | "Received ACK message from peer `%s'\n", | ||
3476 | GNUNET_i2s (&address->peer)); | ||
3477 | if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) | 3504 | if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) |
3478 | { | 3505 | { |
3479 | GNUNET_break_op (0); | 3506 | GNUNET_break_op (0); |
@@ -3488,10 +3515,8 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, | |||
3488 | GNUNET_break_op (0); | 3515 | GNUNET_break_op (0); |
3489 | return GNUNET_SYSERR; | 3516 | return GNUNET_SYSERR; |
3490 | } | 3517 | } |
3491 | 3518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
3492 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3519 | "Received ACK for peer `%s' in state %s/%s\n", |
3493 | "Received %s for peer `%s' in state %s/%s\n", | ||
3494 | "ACK", | ||
3495 | GNUNET_i2s (&address->peer), | 3520 | GNUNET_i2s (&address->peer), |
3496 | GNUNET_TRANSPORT_ps2s (n->state), | 3521 | GNUNET_TRANSPORT_ps2s (n->state), |
3497 | print_ack_state (n->ack_state)); | 3522 | print_ack_state (n->ack_state)); |
@@ -3521,20 +3546,6 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, | |||
3521 | GNUNET_NO); | 3546 | GNUNET_NO); |
3522 | return GNUNET_OK; | 3547 | return GNUNET_OK; |
3523 | } | 3548 | } |
3524 | |||
3525 | /* We are connected */ | ||
3526 | if (GNUNET_NO == GST_neighbours_test_connected(&n->id)) | ||
3527 | { | ||
3528 | /* Notify about connection */ | ||
3529 | neighbours_connect_notification (&n->id, | ||
3530 | n->primary_address.bandwidth_in, | ||
3531 | n->primary_address.bandwidth_out); | ||
3532 | GNUNET_STATISTICS_set (GST_stats, | ||
3533 | gettext_noop ("# peers connected"), | ||
3534 | ++neighbours_connected, | ||
3535 | GNUNET_NO); | ||
3536 | } | ||
3537 | |||
3538 | if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) | 3549 | if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) |
3539 | { | 3550 | { |
3540 | /* We tried to switch addresses while being connect. We explicitly wait | 3551 | /* We tried to switch addresses while being connect. We explicitly wait |
@@ -3542,9 +3553,9 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, | |||
3542 | * so we do not want to set the address as in use! */ | 3553 | * so we do not want to set the address as in use! */ |
3543 | return GNUNET_OK; | 3554 | return GNUNET_OK; |
3544 | } | 3555 | } |
3545 | 3556 | set_state_and_timeout (n, | |
3546 | set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, | 3557 | GNUNET_TRANSPORT_PS_CONNECTED, |
3547 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); | 3558 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); |
3548 | 3559 | ||
3549 | /* Set primary address to used */ | 3560 | /* Set primary address to used */ |
3550 | set_primary_address (n, | 3561 | set_primary_address (n, |
@@ -3880,7 +3891,7 @@ GST_neighbours_stop () | |||
3880 | &disconnect_all_neighbours, | 3891 | &disconnect_all_neighbours, |
3881 | NULL); | 3892 | NULL); |
3882 | GNUNET_CONTAINER_multipeermap_destroy (neighbours); | 3893 | GNUNET_CONTAINER_multipeermap_destroy (neighbours); |
3883 | 3894 | neighbours = NULL; | |
3884 | next = pending_bc_head; | 3895 | next = pending_bc_head; |
3885 | for (cur = next; NULL != cur; cur = next) | 3896 | for (cur = next; NULL != cur; cur = next) |
3886 | { | 3897 | { |
@@ -3898,7 +3909,6 @@ GST_neighbours_stop () | |||
3898 | GNUNET_HELLO_address_free (cur->address); | 3909 | GNUNET_HELLO_address_free (cur->address); |
3899 | GNUNET_free (cur); | 3910 | GNUNET_free (cur); |
3900 | } | 3911 | } |
3901 | neighbours = NULL; | ||
3902 | } | 3912 | } |
3903 | 3913 | ||
3904 | 3914 | ||
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index fb2791eba..746a99f9f 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -450,7 +450,7 @@ cleanup_validation_entry (void *cls, | |||
450 | validations_running, | 450 | validations_running, |
451 | GNUNET_NO); | 451 | GNUNET_NO); |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
453 | "Validation finished, %u validation processes running\n", | 453 | "Validation aborted, %u validation processes running\n", |
454 | validations_running); | 454 | validations_running); |
455 | } | 455 | } |
456 | GNUNET_free (ve); | 456 | GNUNET_free (ve); |
@@ -830,7 +830,7 @@ add_valid_address (void *cls, | |||
830 | if (GNUNET_YES != ve->known_to_ats) | 830 | if (GNUNET_YES != ve->known_to_ats) |
831 | { | 831 | { |
832 | ve->known_to_ats = GNUNET_YES; | 832 | ve->known_to_ats = GNUNET_YES; |
833 | GST_ats_add_address (address, NULL, &ats, 1); | 833 | GST_ats_add_address (address, &ats, 1); |
834 | } | 834 | } |
835 | return GNUNET_OK; | 835 | return GNUNET_OK; |
836 | } | 836 | } |
@@ -1230,6 +1230,35 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
1230 | 1230 | ||
1231 | 1231 | ||
1232 | /** | 1232 | /** |
1233 | * Validate an individual address. | ||
1234 | * | ||
1235 | * @param address address we should try to validate | ||
1236 | */ | ||
1237 | void | ||
1238 | GST_validation_handle_address (const struct GNUNET_HELLO_Address *address) | ||
1239 | { | ||
1240 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
1241 | struct ValidationEntry *ve; | ||
1242 | |||
1243 | papi = GST_plugins_find (address->transport_name); | ||
1244 | if (NULL == papi) | ||
1245 | { | ||
1246 | /* This plugin is currently unvailable ... ignore */ | ||
1247 | return; | ||
1248 | } | ||
1249 | ve = find_validation_entry (address); | ||
1250 | if (NULL == ve->revalidation_task) | ||
1251 | { | ||
1252 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1253 | "Validation process started for fresh address `%s' of %s\n", | ||
1254 | GST_plugins_a2s (ve->address), | ||
1255 | GNUNET_i2s (&ve->address->peer)); | ||
1256 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); | ||
1257 | } | ||
1258 | } | ||
1259 | |||
1260 | |||
1261 | /** | ||
1233 | * Iterator callback to go over all addresses and try to validate them | 1262 | * Iterator callback to go over all addresses and try to validate them |
1234 | * (unless blocked or already validated). | 1263 | * (unless blocked or already validated). |
1235 | * | 1264 | * |
@@ -1243,29 +1272,13 @@ validate_address_iterator (void *cls, | |||
1243 | const struct GNUNET_HELLO_Address *address, | 1272 | const struct GNUNET_HELLO_Address *address, |
1244 | struct GNUNET_TIME_Absolute expiration) | 1273 | struct GNUNET_TIME_Absolute expiration) |
1245 | { | 1274 | { |
1246 | struct GNUNET_TRANSPORT_PluginFunctions * papi; | ||
1247 | struct ValidationEntry *ve; | ||
1248 | |||
1249 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 1275 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
1250 | { | 1276 | { |
1251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1252 | "Skipping expired address from HELLO\n"); | 1278 | "Skipping expired address from HELLO\n"); |
1253 | return GNUNET_OK; /* expired */ | 1279 | return GNUNET_OK; /* expired */ |
1254 | } | 1280 | } |
1255 | papi = GST_plugins_find (address->transport_name); | 1281 | GST_validation_handle_address (address); |
1256 | if (NULL == papi) | ||
1257 | { | ||
1258 | /* This plugin is currently unvailable ... ignore */ | ||
1259 | return GNUNET_OK; | ||
1260 | } | ||
1261 | ve = find_validation_entry (address); | ||
1262 | if (NULL == ve->revalidation_task) | ||
1263 | { | ||
1264 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1265 | "Validation process started for fresh address `%s'\n", | ||
1266 | GST_plugins_a2s (ve->address)); | ||
1267 | ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); | ||
1268 | } | ||
1269 | return GNUNET_OK; | 1282 | return GNUNET_OK; |
1270 | } | 1283 | } |
1271 | 1284 | ||
@@ -1457,7 +1470,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1457 | else | 1470 | else |
1458 | { | 1471 | { |
1459 | ve->known_to_ats = GNUNET_YES; | 1472 | ve->known_to_ats = GNUNET_YES; |
1460 | GST_ats_add_address (ve->address, NULL, ats, 2); | 1473 | GST_ats_add_address (ve->address, ats, 2); |
1461 | } | 1474 | } |
1462 | } | 1475 | } |
1463 | if (validations_running > 0) | 1476 | if (validations_running > 0) |
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index a14937022..f292c1df6 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h | |||
@@ -132,6 +132,15 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello); | |||
132 | 132 | ||
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Validate an individual address. | ||
136 | * | ||
137 | * @param address address we should try to validate | ||
138 | */ | ||
139 | void | ||
140 | GST_validation_handle_address (const struct GNUNET_HELLO_Address *address); | ||
141 | |||
142 | |||
143 | /** | ||
135 | * Function called for each address (or address status change) that | 144 | * Function called for each address (or address status change) that |
136 | * the validation module is aware of (for the given target). | 145 | * the validation module is aware of (for the given target). |
137 | * | 146 | * |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index c7c145328..fc35b08fb 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -604,6 +604,7 @@ server_delete_session (struct Session *s) | |||
604 | plugin->env->session_end (plugin->env->cls, | 604 | plugin->env->session_end (plugin->env->cls, |
605 | s->address, | 605 | s->address, |
606 | s); | 606 | s); |
607 | s->known_to_service = GNUNET_NO; | ||
607 | } | 608 | } |
608 | if (NULL != s->msg_tk) | 609 | if (NULL != s->msg_tk) |
609 | { | 610 | { |
@@ -1522,7 +1523,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1522 | notify_session_monitor (plugin, | 1523 | notify_session_monitor (plugin, |
1523 | s, | 1524 | s, |
1524 | GNUNET_TRANSPORT_SS_UP); | 1525 | GNUNET_TRANSPORT_SS_UP); |
1525 | plugin->env->session_start (NULL, | 1526 | plugin->env->session_start (plugin->env->cls, |
1526 | s->address, | 1527 | s->address, |
1527 | s, | 1528 | s, |
1528 | NULL, 0); | 1529 | NULL, 0); |
@@ -1670,7 +1671,7 @@ server_receive_mst_cb (void *cls, | |||
1670 | if (GNUNET_NO == s->known_to_service) | 1671 | if (GNUNET_NO == s->known_to_service) |
1671 | { | 1672 | { |
1672 | s->known_to_service = GNUNET_YES; | 1673 | s->known_to_service = GNUNET_YES; |
1673 | plugin->env->session_start (NULL, | 1674 | plugin->env->session_start (plugin->env->cls, |
1674 | s->address, | 1675 | s->address, |
1675 | s, | 1676 | s, |
1676 | NULL, | 1677 | NULL, |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index a070fdfc0..882cc4a44 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1523,7 +1523,9 @@ tcp_plugin_get_session (void *cls, | |||
1523 | addrlen = address->address_length; | 1523 | addrlen = address->address_length; |
1524 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1524 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1525 | "Trying to get session for `%s' address of peer `%s'\n", | 1525 | "Trying to get session for `%s' address of peer `%s'\n", |
1526 | tcp_plugin_address_to_string(NULL, address->address, address->address_length), | 1526 | tcp_plugin_address_to_string (NULL, |
1527 | address->address, | ||
1528 | address->address_length), | ||
1527 | GNUNET_i2s (&address->peer)); | 1529 | GNUNET_i2s (&address->peer)); |
1528 | 1530 | ||
1529 | if (GNUNET_HELLO_address_check_option (address, | 1531 | if (GNUNET_HELLO_address_check_option (address, |
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 5ecbaa9ed..d07005b56 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -76,7 +76,7 @@ GNUNET_NETWORK_STRUCT_END | |||
76 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 76 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
77 | 77 | ||
78 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 78 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
79 | #define DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 79 | |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Timeout task to send messages | 82 | * Timeout task to send messages |
@@ -140,9 +140,6 @@ static unsigned int p2_addresses_avail; | |||
140 | static unsigned long long bytes_sent_after_switch; | 140 | static unsigned long long bytes_sent_after_switch; |
141 | static unsigned long long bytes_recv_after_switch; | 141 | static unsigned long long bytes_recv_after_switch; |
142 | 142 | ||
143 | /* | ||
144 | * END Testcase specific declarations | ||
145 | */ | ||
146 | 143 | ||
147 | #if VERBOSE | 144 | #if VERBOSE |
148 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 145 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
@@ -150,8 +147,6 @@ static unsigned long long bytes_recv_after_switch; | |||
150 | #define OKPP do { ok++; } while (0) | 147 | #define OKPP do { ok++; } while (0) |
151 | #endif | 148 | #endif |
152 | 149 | ||
153 | static void end (); | ||
154 | |||
155 | 150 | ||
156 | static int | 151 | static int |
157 | stat_start_attempt_cb (void *cls, | 152 | stat_start_attempt_cb (void *cls, |
@@ -346,8 +341,11 @@ end () | |||
346 | FPRINTF (stderr, "\n"); | 341 | FPRINTF (stderr, "\n"); |
347 | if (p1_switch_attempts > 0) | 342 | if (p1_switch_attempts > 0) |
348 | { | 343 | { |
349 | FPRINTF (stderr, "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", | 344 | FPRINTF (stderr, |
350 | p1_switch_attempts, p1_switch_success, p1_switch_fail); | 345 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", |
346 | p1_switch_attempts, | ||
347 | p1_switch_success, | ||
348 | p1_switch_fail); | ||
351 | if (p1_switch_success != p1_switch_attempts) | 349 | if (p1_switch_success != p1_switch_attempts) |
352 | { | 350 | { |
353 | GNUNET_break (0); | 351 | GNUNET_break (0); |
@@ -356,13 +354,17 @@ end () | |||
356 | } | 354 | } |
357 | else if (p1_addresses_avail > 1) | 355 | else if (p1_addresses_avail > 1) |
358 | { | 356 | { |
359 | FPRINTF (stderr, "Peer 1 had %u addresses available, but did not try to switch\n", | 357 | FPRINTF (stderr, |
360 | p1_addresses_avail); | 358 | "Peer 1 had %u addresses available, but did not try to switch\n", |
359 | p1_addresses_avail); | ||
361 | } | 360 | } |
362 | if (p2_switch_attempts > 0) | 361 | if (p2_switch_attempts > 0) |
363 | { | 362 | { |
364 | FPRINTF (stderr, "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", | 363 | FPRINTF (stderr, |
365 | p2_switch_attempts, p2_switch_success, p2_switch_fail); | 364 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", |
365 | p2_switch_attempts, | ||
366 | p2_switch_success, | ||
367 | p2_switch_fail); | ||
366 | if (p2_switch_success != p2_switch_attempts) | 368 | if (p2_switch_success != p2_switch_attempts) |
367 | { | 369 | { |
368 | GNUNET_break (0); | 370 | GNUNET_break (0); |
@@ -371,8 +373,9 @@ end () | |||
371 | } | 373 | } |
372 | else if (p2_addresses_avail > 1) | 374 | else if (p2_addresses_avail > 1) |
373 | { | 375 | { |
374 | FPRINTF (stderr, "Peer 2 had %u addresses available, but did not try to switch\n", | 376 | FPRINTF (stderr, |
375 | p2_addresses_avail); | 377 | "Peer 2 had %u addresses available, but did not try to switch\n", |
378 | p2_addresses_avail); | ||
376 | } | 379 | } |
377 | 380 | ||
378 | if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) && | 381 | if ( ((p1_switch_attempts > 0) || (p2_switch_attempts > 0)) && |
@@ -400,15 +403,14 @@ static void | |||
400 | end_badly () | 403 | end_badly () |
401 | { | 404 | { |
402 | die_task = NULL; | 405 | die_task = NULL; |
403 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 406 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
404 | "Fail! Stopping peers\n"); | 407 | "Fail (timeout)! Stopping peers\n"); |
405 | |||
406 | if (test_connected == GNUNET_YES) | 408 | if (test_connected == GNUNET_YES) |
407 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
408 | "Peers got connected\n"); | 410 | "Peers got connected\n"); |
409 | else | 411 | else |
410 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 412 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
411 | "Peers got NOT connected\n"); | 413 | "Peers got NOT EVEN connected\n"); |
412 | clean_up(); | 414 | clean_up(); |
413 | res = GNUNET_YES; | 415 | res = GNUNET_YES; |
414 | } | 416 | } |
@@ -428,11 +430,11 @@ notify_receive (void *cls, | |||
428 | struct PeerContext *p = cls; | 430 | struct PeerContext *p = cls; |
429 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 431 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); |
430 | 432 | ||
431 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
432 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps, | 434 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", p->no, ps, |
433 | ntohl (hdr->num), | 435 | ntohl (hdr->num), |
434 | ntohs (message->size), | 436 | ntohs (message->size), |
435 | GNUNET_i2s (peer)); | 437 | GNUNET_i2s (peer)); |
436 | if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) && | 438 | if ( ((p1_switch_attempts >= 1) || (p2_switch_attempts >= 1)) && |
437 | (p1_switch_attempts == p1_switch_fail + p1_switch_success) && | 439 | (p1_switch_attempts == p1_switch_fail + p1_switch_success) && |
438 | (p2_switch_attempts == p2_switch_fail + p2_switch_success) ) | 440 | (p2_switch_attempts == p2_switch_fail + p2_switch_success) ) |
@@ -464,7 +466,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
464 | "Timeout occurred while waiting for transmit_ready for message\n"); | 466 | "Timeout occurred while waiting for transmit_ready for message\n"); |
465 | if (NULL != die_task) | 467 | if (NULL != die_task) |
466 | GNUNET_SCHEDULER_cancel (die_task); | 468 | GNUNET_SCHEDULER_cancel (die_task); |
467 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); | 469 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
468 | res = 1; | 470 | res = 1; |
469 | return 0; | 471 | return 0; |
470 | } | 472 | } |
@@ -479,18 +481,16 @@ notify_ready (void *cls, size_t size, void *buf) | |||
479 | memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage)); | 481 | memcpy (&cbuf[0], &hdr, sizeof(struct TestMessage)); |
480 | memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage)); | 482 | memset (&cbuf[sizeof(struct TestMessage)], '0', MSIZE - sizeof(struct TestMessage)); |
481 | 483 | ||
482 | #if VERBOSE | ||
483 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 484 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
484 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 485 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
485 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | 486 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", |
486 | (unsigned int) (counter - 1), | 487 | (unsigned int) (counter - 1), |
487 | s, | 488 | MSIZE, |
488 | sender->no, | 489 | sender->no, |
489 | GNUNET_i2s (&sender->id), | 490 | GNUNET_i2s (&sender->id), |
490 | receiver->no, | 491 | receiver->no, |
491 | receiver_s); | 492 | receiver_s); |
492 | GNUNET_free(receiver_s); | 493 | GNUNET_free(receiver_s); |
493 | #endif | ||
494 | 494 | ||
495 | if (th == NULL) | 495 | if (th == NULL) |
496 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | 496 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, |
@@ -510,9 +510,11 @@ notify_ready (void *cls, size_t size, void *buf) | |||
510 | 510 | ||
511 | 511 | ||
512 | static void | 512 | static void |
513 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 513 | notify_connect (void *cls, |
514 | const struct GNUNET_PeerIdentity *peer) | ||
514 | { | 515 | { |
515 | struct PeerContext *p = cls; | 516 | struct PeerContext *p = cls; |
517 | |||
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
517 | "Peer %u (`%4s') connected to us!\n", | 519 | "Peer %u (`%4s') connected to us!\n", |
518 | p->no, | 520 | p->no, |
@@ -526,14 +528,19 @@ notify_disconnect (void *cls, | |||
526 | { | 528 | { |
527 | struct PeerContext *p = cls; | 529 | struct PeerContext *p = cls; |
528 | 530 | ||
529 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 531 | if (NULL != p1) |
530 | "Peer %u (`%4s') disconnected!\n", | 532 | { |
531 | p->no, | 533 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
532 | GNUNET_i2s (peer)); | 534 | "Peer %u (`%4s') disconnected early!\n", |
533 | if (th != NULL) | 535 | p->no, |
536 | GNUNET_i2s (peer)); | ||
537 | GNUNET_SCHEDULER_shutdown (); | ||
538 | } | ||
539 | if (NULL != th) | ||
540 | { | ||
534 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 541 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
535 | th = NULL; | 542 | th = NULL; |
536 | 543 | } | |
537 | } | 544 | } |
538 | 545 | ||
539 | 546 | ||
@@ -570,14 +577,16 @@ progress_indicator (void *cls, | |||
570 | 577 | ||
571 | 578 | ||
572 | static void | 579 | static void |
573 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | 580 | testing_connect_cb (struct PeerContext *p1, |
581 | struct PeerContext *p2, | ||
582 | void *cls) | ||
574 | { | 583 | { |
575 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 584 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); |
576 | 585 | ||
577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
578 | "Peers connected: %u (%s) <-> %u (%s)\n", | 587 | "Peers connected: %u (%s) <-> %u (%s)\n", |
579 | p1->no, p1_c, p2->no, | 588 | p1->no, p1_c, p2->no, |
580 | GNUNET_i2s (&p2->id)); | 589 | GNUNET_i2s (&p2->id)); |
581 | GNUNET_free (p1_c); | 590 | GNUNET_free (p1_c); |
582 | 591 | ||
583 | cc = NULL; | 592 | cc = NULL; |
@@ -613,10 +622,12 @@ start_cb (struct PeerContext *p, void *cls) | |||
613 | receiver = p1; | 622 | receiver = p1; |
614 | 623 | ||
615 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); | 624 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); |
616 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 625 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
617 | "Test tries to send from %u (%s) -> peer %u (%s)\n", | 626 | "Test tries to send from %u (%s) -> peer %u (%s)\n", |
618 | sender->no, sender_c, | 627 | sender->no, |
619 | receiver->no, GNUNET_i2s (&receiver->id)); | 628 | sender_c, |
629 | receiver->no, | ||
630 | GNUNET_i2s (&receiver->id)); | ||
620 | GNUNET_free (sender_c); | 631 | GNUNET_free (sender_c); |
621 | 632 | ||
622 | /* Connect the peers */ | 633 | /* Connect the peers */ |
@@ -632,20 +643,18 @@ run (void *cls, | |||
632 | const char *cfgfile, | 643 | const char *cfgfile, |
633 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 644 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
634 | { | 645 | { |
635 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | 646 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
636 | 647 | ||
637 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | 648 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
638 | ¬ify_receive, ¬ify_connect, ¬ify_disconnect, &start_cb, NULL ); | 649 | ¬ify_receive, ¬ify_connect, ¬ify_disconnect, &start_cb, NULL); |
639 | 650 | ||
640 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | 651 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, |
641 | ¬ify_receive, ¬ify_connect, ¬ify_disconnect, &start_cb, NULL ); | 652 | ¬ify_receive, ¬ify_connect, ¬ify_disconnect, &start_cb, NULL); |
642 | 653 | ||
643 | if ((p1 == NULL )|| (p2 == NULL)) | 654 | if ((p1 == NULL )|| (p2 == NULL)) |
644 | { | 655 | { |
645 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | 656 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); |
646 | if (die_task != NULL) | 657 | GNUNET_SCHEDULER_shutdown (); |
647 | GNUNET_SCHEDULER_cancel (die_task); | ||
648 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
649 | return; | 658 | return; |
650 | } | 659 | } |
651 | 660 | ||
@@ -693,10 +702,9 @@ run (void *cls, | |||
693 | 702 | ||
694 | if ((p1_stat == NULL )|| (p2_stat == NULL)) | 703 | if ((p1_stat == NULL )|| (p2_stat == NULL)) |
695 | { | 704 | { |
696 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not create statistics for peers!\n"); | 705 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
697 | if (die_task != NULL) | 706 | "Fail! Could not create statistics for peers!\n"); |
698 | GNUNET_SCHEDULER_cancel (die_task); | 707 | GNUNET_SCHEDULER_shutdown (); |
699 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
700 | return; | 708 | return; |
701 | } | 709 | } |
702 | } | 710 | } |
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c index 25054b536..e593b08fa 100644 --- a/src/transport/test_transport_api_restart_2peers.c +++ b/src/transport/test_transport_api_restart_2peers.c | |||
@@ -23,7 +23,6 @@ | |||
23 | * | 23 | * |
24 | * This test case starts 2 peers, connects and exchanges a message | 24 | * This test case starts 2 peers, connects and exchanges a message |
25 | * boths peer are restarted and tested if peers reconnect | 25 | * boths peer are restarted and tested if peers reconnect |
26 | * C code apparently. | ||
27 | */ | 26 | */ |
28 | #include "platform.h" | 27 | #include "platform.h" |
29 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
@@ -32,7 +31,7 @@ | |||
32 | /** | 31 | /** |
33 | * How long until we give up on transmitting the message? | 32 | * How long until we give up on transmitting the message? |
34 | */ | 33 | */ |
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) |
36 | 35 | ||
37 | /** | 36 | /** |
38 | * How long until we give up on transmitting the message? | 37 | * How long until we give up on transmitting the message? |
@@ -163,7 +162,9 @@ static void | |||
163 | restart (struct PeerContext *p, char *cfg_file) | 162 | restart (struct PeerContext *p, char *cfg_file) |
164 | { | 163 | { |
165 | GNUNET_assert (p != NULL); | 164 | GNUNET_assert (p != NULL); |
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarting peer %u (`%4s')\n", p->no, | 165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
166 | "Restarting peer %u (`%4s')\n", | ||
167 | p->no, | ||
167 | GNUNET_i2s (&p->id)); | 168 | GNUNET_i2s (&p->id)); |
168 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); | 169 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, cfg_file, &restart_cb, p); |
169 | } | 170 | } |
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index fd352a1e5..a2649db8f 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -512,7 +512,7 @@ outbound_bw_tracker_update (void *cls) | |||
512 | if (NULL == n->hn) | 512 | if (NULL == n->hn) |
513 | return; | 513 | return; |
514 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, | 514 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, |
515 | n->th->notify_size + n->traffic_overhead); | 515 | n->th->notify_size + n->traffic_overhead); |
516 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 516 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
517 | "New outbound delay %llu us\n", | 517 | "New outbound delay %llu us\n", |
518 | GNUNET_STRINGS_relative_time_to_string (delay, | 518 | GNUNET_STRINGS_relative_time_to_string (delay, |
@@ -703,7 +703,8 @@ demultiplexer (void *cls, | |||
703 | "CONNECT", | 703 | "CONNECT", |
704 | GNUNET_i2s (&cim->id), | 704 | GNUNET_i2s (&cim->id), |
705 | ntohl (cim->quota_out.value__)); | 705 | ntohl (cim->quota_out.value__)); |
706 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); | 706 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, |
707 | cim->quota_out); | ||
707 | if (h->nc_cb != NULL) | 708 | if (h->nc_cb != NULL) |
708 | h->nc_cb (h->cls, &n->id); | 709 | h->nc_cb (h->cls, &n->id); |
709 | break; | 710 | break; |
@@ -745,9 +746,10 @@ demultiplexer (void *cls, | |||
745 | 746 | ||
746 | if (bytes_physical >= bytes_msg) | 747 | if (bytes_physical >= bytes_msg) |
747 | { | 748 | { |
748 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 749 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
749 | "Overhead for %u byte message: %u\n", | 750 | "Overhead for %u byte message: %u\n", |
750 | bytes_msg, bytes_physical - bytes_msg); | 751 | bytes_msg, |
752 | bytes_physical - bytes_msg); | ||
751 | n->traffic_overhead += bytes_physical - bytes_msg; | 753 | n->traffic_overhead += bytes_physical - bytes_msg; |
752 | } | 754 | } |
753 | GNUNET_break (GNUNET_NO == n->is_ready); | 755 | GNUNET_break (GNUNET_NO == n->is_ready); |