diff options
-rw-r--r-- | src/ats-tests/ats-testing.h | 100 | ||||
-rw-r--r-- | src/core/gnunet-service-core_kx.c | 681 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 124 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 142 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 8 | ||||
-rw-r--r-- | src/include/gnunet_transport_communication_service.h | 113 | ||||
-rw-r--r-- | src/include/gnunet_transport_core_service.h | 85 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 232 | ||||
-rw-r--r-- | src/namestore/namestore_api_monitor.c | 95 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_connectionpool.c | 230 | ||||
-rw-r--r-- | src/testbed/gnunet-service-testbed_connectionpool.h | 56 | ||||
-rw-r--r-- | src/transport/gnunet-service-tng.c | 575 | ||||
-rw-r--r-- | src/transport/gnunet-transport-profiler.c | 232 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 571 | ||||
-rw-r--r-- | src/transport/transport-testing.h | 201 | ||||
-rw-r--r-- | src/transport/transport.h | 56 | ||||
-rw-r--r-- | src/transport/transport_api2_core.c | 506 | ||||
-rw-r--r-- | src/transport/transport_api_core.c | 260 |
18 files changed, 1983 insertions, 2284 deletions
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h index 9c4353b52..f6df5a9bd 100644 --- a/src/ats-tests/ats-testing.h +++ b/src/ats-tests/ats-testing.h | |||
@@ -28,7 +28,7 @@ | |||
28 | #include "gnunet_testbed_service.h" | 28 | #include "gnunet_testbed_service.h" |
29 | #include "gnunet_ats_service.h" | 29 | #include "gnunet_ats_service.h" |
30 | #include "gnunet_core_service.h" | 30 | #include "gnunet_core_service.h" |
31 | #include "gnunet_transport_core_service.h" | 31 | #include "gnunet_transport_service.h" |
32 | 32 | ||
33 | #define TEST_ATS_PREFERENCE_DEFAULT 1.0 | 33 | #define TEST_ATS_PREFERENCE_DEFAULT 1.0 |
34 | 34 | ||
@@ -82,10 +82,10 @@ enum GeneratorType | |||
82 | * @param masters array of master peers | 82 | * @param masters array of master peers |
83 | * @param slaves array of master peers | 83 | * @param slaves array of master peers |
84 | */ | 84 | */ |
85 | typedef void | 85 | typedef void (*GNUNET_ATS_TEST_TopologySetupDoneCallback) ( |
86 | (*GNUNET_ATS_TEST_TopologySetupDoneCallback) (void *cls, | 86 | void *cls, |
87 | struct BenchmarkPeer *masters, | 87 | struct BenchmarkPeer *masters, |
88 | struct BenchmarkPeer *slaves); | 88 | struct BenchmarkPeer *slaves); |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Callback called when logging is required for the data contained | 91 | * Callback called when logging is required for the data contained |
@@ -97,13 +97,13 @@ typedef void | |||
97 | * @param bandwidth_in bandwidth inbound | 97 | * @param bandwidth_in bandwidth inbound |
98 | * @param prop performance information | 98 | * @param prop performance information |
99 | */ | 99 | */ |
100 | typedef void | 100 | typedef void (*GNUNET_ATS_TEST_LogRequest) ( |
101 | (*GNUNET_ATS_TEST_LogRequest) (void *cls, | 101 | void *cls, |
102 | const struct GNUNET_HELLO_Address *address, | 102 | const struct GNUNET_HELLO_Address *address, |
103 | int address_active, | 103 | int address_active, |
104 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 104 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
105 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 105 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
106 | const struct GNUNET_ATS_Properties *prop); | 106 | const struct GNUNET_ATS_Properties *prop); |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * Information we track for a peer in the testbed. | 109 | * Information we track for a peer in the testbed. |
@@ -176,7 +176,7 @@ struct BenchmarkPeer | |||
176 | * Masters only | 176 | * Masters only |
177 | * Progress task | 177 | * Progress task |
178 | */ | 178 | */ |
179 | struct GNUNET_SCHEDULER_Task * ats_task; | 179 | struct GNUNET_SCHEDULER_Task *ats_task; |
180 | 180 | ||
181 | /** | 181 | /** |
182 | * Masters only | 182 | * Masters only |
@@ -241,7 +241,7 @@ struct TrafficGenerator | |||
241 | long int max_rate; | 241 | long int max_rate; |
242 | struct GNUNET_TIME_Relative duration_period; | 242 | struct GNUNET_TIME_Relative duration_period; |
243 | 243 | ||
244 | struct GNUNET_SCHEDULER_Task * send_task; | 244 | struct GNUNET_SCHEDULER_Task *send_task; |
245 | struct GNUNET_TIME_Absolute next_ping_transmission; | 245 | struct GNUNET_TIME_Absolute next_ping_transmission; |
246 | struct GNUNET_TIME_Absolute time_start; | 246 | struct GNUNET_TIME_Absolute time_start; |
247 | }; | 247 | }; |
@@ -264,7 +264,7 @@ struct PreferenceGenerator | |||
264 | struct GNUNET_TIME_Relative duration_period; | 264 | struct GNUNET_TIME_Relative duration_period; |
265 | struct GNUNET_TIME_Relative frequency; | 265 | struct GNUNET_TIME_Relative frequency; |
266 | 266 | ||
267 | struct GNUNET_SCHEDULER_Task * set_task; | 267 | struct GNUNET_SCHEDULER_Task *set_task; |
268 | struct GNUNET_TIME_Absolute next_ping_transmission; | 268 | struct GNUNET_TIME_Absolute next_ping_transmission; |
269 | struct GNUNET_TIME_Absolute time_start; | 269 | struct GNUNET_TIME_Absolute time_start; |
270 | }; | 270 | }; |
@@ -353,7 +353,6 @@ struct BenchmarkPartner | |||
353 | * Current preference values for delay | 353 | * Current preference values for delay |
354 | */ | 354 | */ |
355 | double pref_delay; | 355 | double pref_delay; |
356 | |||
357 | }; | 356 | }; |
358 | 357 | ||
359 | 358 | ||
@@ -480,13 +479,12 @@ struct Episode; | |||
480 | 479 | ||
481 | struct Experiment; | 480 | struct Experiment; |
482 | 481 | ||
483 | typedef void | 482 | typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (struct Episode *e); |
484 | (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (struct Episode *e); | ||
485 | 483 | ||
486 | typedef void | 484 | typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) ( |
487 | (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e, | 485 | struct Experiment *e, |
488 | struct GNUNET_TIME_Relative duration, | 486 | struct GNUNET_TIME_Relative duration, |
489 | int success); | 487 | int success); |
490 | 488 | ||
491 | /** | 489 | /** |
492 | * An operation in an experiment | 490 | * An operation in an experiment |
@@ -533,8 +531,8 @@ struct Experiment | |||
533 | unsigned int num_episodes; | 531 | unsigned int num_episodes; |
534 | struct Episode *start; | 532 | struct Episode *start; |
535 | 533 | ||
536 | struct GNUNET_SCHEDULER_Task * experiment_timeout_task; | 534 | struct GNUNET_SCHEDULER_Task *experiment_timeout_task; |
537 | struct GNUNET_SCHEDULER_Task * episode_timeout_task; | 535 | struct GNUNET_SCHEDULER_Task *episode_timeout_task; |
538 | struct Episode *cur; | 536 | struct Episode *cur; |
539 | 537 | ||
540 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb; | 538 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb; |
@@ -552,9 +550,10 @@ extern struct GNUNET_CONFIGURATION_Handle *cfg; | |||
552 | * @param e_done_cb the experiment is completed | 550 | * @param e_done_cb the experiment is completed |
553 | */ | 551 | */ |
554 | void | 552 | void |
555 | GNUNET_ATS_TEST_experimentation_run (struct Experiment *e, | 553 | GNUNET_ATS_TEST_experimentation_run ( |
556 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, | 554 | struct Experiment *e, |
557 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb); | 555 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, |
556 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb); | ||
558 | 557 | ||
559 | 558 | ||
560 | /** | 559 | /** |
@@ -633,14 +632,15 @@ GNUNET_ATS_TEST_generate_traffic_stop_all (void); | |||
633 | * @return the traffic generator | 632 | * @return the traffic generator |
634 | */ | 633 | */ |
635 | struct PreferenceGenerator * | 634 | struct PreferenceGenerator * |
636 | GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src, | 635 | GNUNET_ATS_TEST_generate_preferences_start ( |
637 | struct BenchmarkPartner *dest, | 636 | struct BenchmarkPeer *src, |
638 | enum GeneratorType type, | 637 | struct BenchmarkPartner *dest, |
639 | unsigned int base_value, | 638 | enum GeneratorType type, |
640 | unsigned int value_rate, | 639 | unsigned int base_value, |
641 | struct GNUNET_TIME_Relative period, | 640 | unsigned int value_rate, |
642 | struct GNUNET_TIME_Relative frequency, | 641 | struct GNUNET_TIME_Relative period, |
643 | enum GNUNET_ATS_PreferenceKind kind); | 642 | struct GNUNET_TIME_Relative frequency, |
643 | enum GNUNET_ATS_PreferenceKind kind); | ||
644 | 644 | ||
645 | 645 | ||
646 | void | 646 | void |
@@ -664,11 +664,11 @@ GNUNET_ATS_TEST_generate_preferences_stop_all (void); | |||
664 | */ | 664 | */ |
665 | struct LoggingHandle * | 665 | struct LoggingHandle * |
666 | GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency, | 666 | GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency, |
667 | const char *testname, | 667 | const char *testname, |
668 | struct BenchmarkPeer *masters, | 668 | struct BenchmarkPeer *masters, |
669 | int num_masters, | 669 | int num_masters, |
670 | int num_slaves, | 670 | int num_slaves, |
671 | int verbose); | 671 | int verbose); |
672 | 672 | ||
673 | 673 | ||
674 | /** | 674 | /** |
@@ -729,20 +729,22 @@ GNUNET_ATS_TEST_get_partner (int src, int dest); | |||
729 | * @param cfg_file configuration file to use for the peers | 729 | * @param cfg_file configuration file to use for the peers |
730 | * @param num_slaves number of slaves | 730 | * @param num_slaves number of slaves |
731 | * @param num_masters number of masters | 731 | * @param num_masters number of masters |
732 | * @param test_core connect to CORE service (#GNUNET_YES) or transport (#GNUNET_NO) | 732 | * @param test_core connect to CORE service (#GNUNET_YES) or transport |
733 | * (#GNUNET_NO) | ||
733 | * @param done_cb function to call when topology is setup | 734 | * @param done_cb function to call when topology is setup |
734 | * @param done_cb_cls cls for callback | 735 | * @param done_cb_cls cls for callback |
735 | * @param log_request_cb callback to call when logging is required | 736 | * @param log_request_cb callback to call when logging is required |
736 | */ | 737 | */ |
737 | void | 738 | void |
738 | GNUNET_ATS_TEST_create_topology (char *name, | 739 | GNUNET_ATS_TEST_create_topology ( |
739 | char *cfg_file, | 740 | char *name, |
740 | unsigned int num_slaves, | 741 | char *cfg_file, |
741 | unsigned int num_masters, | 742 | unsigned int num_slaves, |
742 | int test_core, | 743 | unsigned int num_masters, |
743 | GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb, | 744 | int test_core, |
744 | void *done_cb_cls, | 745 | GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb, |
745 | GNUNET_ATS_TEST_LogRequest ats_perf_cb); | 746 | void *done_cb_cls, |
747 | GNUNET_ATS_TEST_LogRequest ats_perf_cb); | ||
746 | 748 | ||
747 | 749 | ||
748 | /** | 750 | /** |
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index bfd855285..d226b65e2 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -20,7 +20,8 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file core/gnunet-service-core_kx.c | 22 | * @file core/gnunet-service-core_kx.c |
23 | * @brief code for managing the key exchange (SET_KEY, PING, PONG) with other peers | 23 | * @brief code for managing the key exchange (SET_KEY, PING, PONG) with other |
24 | * peers | ||
24 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
25 | */ | 26 | */ |
26 | #include "platform.h" | 27 | #include "platform.h" |
@@ -28,7 +29,7 @@ | |||
28 | #include "gnunet-service-core.h" | 29 | #include "gnunet-service-core.h" |
29 | #include "gnunet-service-core_sessions.h" | 30 | #include "gnunet-service-core_sessions.h" |
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
31 | #include "gnunet_transport_core_service.h" | 32 | #include "gnunet_transport_service.h" |
32 | #include "gnunet_constants.h" | 33 | #include "gnunet_constants.h" |
33 | #include "gnunet_signatures.h" | 34 | #include "gnunet_signatures.h" |
34 | #include "gnunet_protocols.h" | 35 | #include "gnunet_protocols.h" |
@@ -42,22 +43,26 @@ | |||
42 | /** | 43 | /** |
43 | * How long do we wait for SET_KEY confirmation initially? | 44 | * How long do we wait for SET_KEY confirmation initially? |
44 | */ | 45 | */ |
45 | #define INITIAL_SET_KEY_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 46 | #define INITIAL_SET_KEY_RETRY_FREQUENCY \ |
47 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
46 | 48 | ||
47 | /** | 49 | /** |
48 | * What is the minimum frequency for a PING message? | 50 | * What is the minimum frequency for a PING message? |
49 | */ | 51 | */ |
50 | #define MIN_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 52 | #define MIN_PING_FREQUENCY \ |
53 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
51 | 54 | ||
52 | /** | 55 | /** |
53 | * How often do we rekey? | 56 | * How often do we rekey? |
54 | */ | 57 | */ |
55 | #define REKEY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) | 58 | #define REKEY_FREQUENCY \ |
59 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) | ||
56 | 60 | ||
57 | /** | 61 | /** |
58 | * What time difference do we tolerate? | 62 | * What time difference do we tolerate? |
59 | */ | 63 | */ |
60 | #define REKEY_TOLERANCE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 64 | #define REKEY_TOLERANCE \ |
65 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | ||
61 | 66 | ||
62 | /** | 67 | /** |
63 | * What is the maximum age of a message for us to consider processing | 68 | * What is the maximum age of a message for us to consider processing |
@@ -69,7 +74,6 @@ | |||
69 | #define MAX_MESSAGE_AGE GNUNET_TIME_UNIT_DAYS | 74 | #define MAX_MESSAGE_AGE GNUNET_TIME_UNIT_DAYS |
70 | 75 | ||
71 | 76 | ||
72 | |||
73 | GNUNET_NETWORK_STRUCT_BEGIN | 77 | GNUNET_NETWORK_STRUCT_BEGIN |
74 | 78 | ||
75 | /** | 79 | /** |
@@ -120,7 +124,6 @@ struct EphemeralKeyMessage | |||
120 | * ephemeral public key). | 124 | * ephemeral public key). |
121 | */ | 125 | */ |
122 | struct GNUNET_PeerIdentity origin_identity; | 126 | struct GNUNET_PeerIdentity origin_identity; |
123 | |||
124 | }; | 127 | }; |
125 | 128 | ||
126 | 129 | ||
@@ -228,7 +231,6 @@ struct EncryptedMessage | |||
228 | * (recent messages are caught with the sequence number). | 231 | * (recent messages are caught with the sequence number). |
229 | */ | 232 | */ |
230 | struct GNUNET_TIME_AbsoluteNBO timestamp; | 233 | struct GNUNET_TIME_AbsoluteNBO timestamp; |
231 | |||
232 | }; | 234 | }; |
233 | GNUNET_NETWORK_STRUCT_END | 235 | GNUNET_NETWORK_STRUCT_END |
234 | 236 | ||
@@ -237,7 +239,8 @@ GNUNET_NETWORK_STRUCT_END | |||
237 | * Number of bytes (at the beginning) of `struct EncryptedMessage` | 239 | * Number of bytes (at the beginning) of `struct EncryptedMessage` |
238 | * that are NOT encrypted. | 240 | * that are NOT encrypted. |
239 | */ | 241 | */ |
240 | #define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number)) | 242 | #define ENCRYPTED_HEADER_SIZE \ |
243 | (offsetof (struct EncryptedMessage, sequence_number)) | ||
241 | 244 | ||
242 | 245 | ||
243 | /** | 246 | /** |
@@ -354,7 +357,6 @@ struct GSC_KeyExchangeInfo | |||
354 | * What is our connection status? | 357 | * What is our connection status? |
355 | */ | 358 | */ |
356 | enum GNUNET_CORE_KxState status; | 359 | enum GNUNET_CORE_KxState status; |
357 | |||
358 | }; | 360 | }; |
359 | 361 | ||
360 | 362 | ||
@@ -411,8 +413,8 @@ calculate_seed (struct GSC_KeyExchangeInfo *kx) | |||
411 | /* Note: may want to make this non-random and instead | 413 | /* Note: may want to make this non-random and instead |
412 | derive from key material to avoid having an undetectable | 414 | derive from key material to avoid having an undetectable |
413 | side-channel */ | 415 | side-channel */ |
414 | return htonl (GNUNET_CRYPTO_random_u32 | 416 | return htonl ( |
415 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 417 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); |
416 | } | 418 | } |
417 | 419 | ||
418 | 420 | ||
@@ -431,9 +433,7 @@ monitor_notify_all (struct GSC_KeyExchangeInfo *kx) | |||
431 | msg.state = htonl ((uint32_t) kx->status); | 433 | msg.state = htonl ((uint32_t) kx->status); |
432 | msg.peer = *kx->peer; | 434 | msg.peer = *kx->peer; |
433 | msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout); | 435 | msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout); |
434 | GNUNET_notification_context_broadcast (nc, | 436 | GNUNET_notification_context_broadcast (nc, &msg.header, GNUNET_NO); |
435 | &msg.header, | ||
436 | GNUNET_NO); | ||
437 | kx->last_notify_timeout = kx->timeout; | 437 | kx->last_notify_timeout = kx->timeout; |
438 | } | 438 | } |
439 | 439 | ||
@@ -453,10 +453,8 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
453 | static const char ctx[] = "authentication key"; | 453 | static const char ctx[] = "authentication key"; |
454 | #if DEBUG_KX | 454 | #if DEBUG_KX |
455 | struct GNUNET_HashCode sh; | 455 | struct GNUNET_HashCode sh; |
456 | 456 | ||
457 | GNUNET_CRYPTO_hash (skey, | 457 | GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); |
458 | sizeof (*skey), | ||
459 | &sh); | ||
460 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
461 | "Deriving Auth key from SKEY %s and seed %u\n", | 459 | "Deriving Auth key from SKEY %s and seed %u\n", |
462 | GNUNET_h2s (&sh), | 460 | GNUNET_h2s (&sh), |
@@ -464,9 +462,13 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
464 | #endif | 462 | #endif |
465 | GNUNET_CRYPTO_hmac_derive_key (akey, | 463 | GNUNET_CRYPTO_hmac_derive_key (akey, |
466 | skey, | 464 | skey, |
467 | &seed, sizeof (seed), | 465 | &seed, |
468 | skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | 466 | sizeof (seed), |
469 | ctx, sizeof (ctx), | 467 | skey, |
468 | sizeof ( | ||
469 | struct GNUNET_CRYPTO_SymmetricSessionKey), | ||
470 | ctx, | ||
471 | sizeof (ctx), | ||
470 | NULL); | 472 | NULL); |
471 | } | 473 | } |
472 | 474 | ||
@@ -488,10 +490,8 @@ derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
488 | static const char ctx[] = "initialization vector"; | 490 | static const char ctx[] = "initialization vector"; |
489 | #if DEBUG_KX | 491 | #if DEBUG_KX |
490 | struct GNUNET_HashCode sh; | 492 | struct GNUNET_HashCode sh; |
491 | 493 | ||
492 | GNUNET_CRYPTO_hash (skey, | 494 | GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); |
493 | sizeof (*skey), | ||
494 | &sh); | ||
495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 495 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
496 | "Deriving IV from SKEY %s and seed %u for peer %s\n", | 496 | "Deriving IV from SKEY %s and seed %u for peer %s\n", |
497 | GNUNET_h2s (&sh), | 497 | GNUNET_h2s (&sh), |
@@ -500,10 +500,13 @@ derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
500 | #endif | 500 | #endif |
501 | GNUNET_CRYPTO_symmetric_derive_iv (iv, | 501 | GNUNET_CRYPTO_symmetric_derive_iv (iv, |
502 | skey, | 502 | skey, |
503 | &seed, sizeof (seed), | 503 | &seed, |
504 | identity, | 504 | sizeof (seed), |
505 | sizeof (struct GNUNET_PeerIdentity), ctx, | 505 | identity, |
506 | sizeof (ctx), NULL); | 506 | sizeof (struct GNUNET_PeerIdentity), |
507 | ctx, | ||
508 | sizeof (ctx), | ||
509 | NULL); | ||
507 | } | 510 | } |
508 | 511 | ||
509 | 512 | ||
@@ -526,10 +529,8 @@ derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
526 | static const char ctx[] = "pong initialization vector"; | 529 | static const char ctx[] = "pong initialization vector"; |
527 | #if DEBUG_KX | 530 | #if DEBUG_KX |
528 | struct GNUNET_HashCode sh; | 531 | struct GNUNET_HashCode sh; |
529 | 532 | ||
530 | GNUNET_CRYPTO_hash (skey, | 533 | GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); |
531 | sizeof (*skey), | ||
532 | &sh); | ||
533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
534 | "Deriving PONG IV from SKEY %s and seed %u/%u for %s\n", | 535 | "Deriving PONG IV from SKEY %s and seed %u/%u for %s\n", |
535 | GNUNET_h2s (&sh), | 536 | GNUNET_h2s (&sh), |
@@ -539,12 +540,15 @@ derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
539 | #endif | 540 | #endif |
540 | GNUNET_CRYPTO_symmetric_derive_iv (iv, | 541 | GNUNET_CRYPTO_symmetric_derive_iv (iv, |
541 | skey, | 542 | skey, |
542 | &seed, sizeof (seed), | 543 | &seed, |
543 | identity, | 544 | sizeof (seed), |
544 | sizeof (struct GNUNET_PeerIdentity), | 545 | identity, |
545 | &challenge, sizeof (challenge), | 546 | sizeof (struct GNUNET_PeerIdentity), |
546 | ctx, sizeof (ctx), | 547 | &challenge, |
547 | NULL); | 548 | sizeof (challenge), |
549 | ctx, | ||
550 | sizeof (ctx), | ||
551 | NULL); | ||
548 | } | 552 | } |
549 | 553 | ||
550 | 554 | ||
@@ -558,29 +562,32 @@ derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, | |||
558 | */ | 562 | */ |
559 | static void | 563 | static void |
560 | derive_aes_key (const struct GNUNET_PeerIdentity *sender, | 564 | derive_aes_key (const struct GNUNET_PeerIdentity *sender, |
561 | const struct GNUNET_PeerIdentity *receiver, | 565 | const struct GNUNET_PeerIdentity *receiver, |
562 | const struct GNUNET_HashCode *key_material, | 566 | const struct GNUNET_HashCode *key_material, |
563 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey) | 567 | struct GNUNET_CRYPTO_SymmetricSessionKey *skey) |
564 | { | 568 | { |
565 | static const char ctx[] = "aes key generation vector"; | 569 | static const char ctx[] = "aes key generation vector"; |
566 | #if DEBUG_KX | 570 | #if DEBUG_KX |
567 | struct GNUNET_HashCode sh; | 571 | struct GNUNET_HashCode sh; |
568 | 572 | ||
569 | GNUNET_CRYPTO_hash (skey, | 573 | GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); |
570 | sizeof (*skey), | ||
571 | &sh); | ||
572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 574 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
573 | "Deriving AES Keys for %s to %s from %s\n", | 575 | "Deriving AES Keys for %s to %s from %s\n", |
574 | GNUNET_i2s (sender), | 576 | GNUNET_i2s (sender), |
575 | GNUNET_i2s2 (receiver), | 577 | GNUNET_i2s2 (receiver), |
576 | GNUNET_h2s (key_material)); | 578 | GNUNET_h2s (key_material)); |
577 | #endif | 579 | #endif |
578 | GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), | 580 | GNUNET_CRYPTO_kdf (skey, |
579 | ctx, sizeof (ctx), | 581 | sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), |
580 | key_material, sizeof (struct GNUNET_HashCode), | 582 | ctx, |
581 | sender, sizeof (struct GNUNET_PeerIdentity), | 583 | sizeof (ctx), |
582 | receiver, sizeof (struct GNUNET_PeerIdentity), | 584 | key_material, |
583 | NULL); | 585 | sizeof (struct GNUNET_HashCode), |
586 | sender, | ||
587 | sizeof (struct GNUNET_PeerIdentity), | ||
588 | receiver, | ||
589 | sizeof (struct GNUNET_PeerIdentity), | ||
590 | NULL); | ||
584 | } | 591 | } |
585 | 592 | ||
586 | 593 | ||
@@ -607,15 +614,14 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx, | |||
607 | GNUNET_break (0); | 614 | GNUNET_break (0); |
608 | return GNUNET_NO; | 615 | return GNUNET_NO; |
609 | } | 616 | } |
610 | GNUNET_assert (size == | 617 | GNUNET_assert (size == GNUNET_CRYPTO_symmetric_encrypt (in, |
611 | GNUNET_CRYPTO_symmetric_encrypt (in, | 618 | (uint16_t) size, |
612 | (uint16_t) size, | 619 | &kx->encrypt_key, |
613 | &kx->encrypt_key, | 620 | iv, |
614 | iv, | 621 | out)); |
615 | out)); | ||
616 | GNUNET_STATISTICS_update (GSC_stats, | 622 | GNUNET_STATISTICS_update (GSC_stats, |
617 | gettext_noop ("# bytes encrypted"), | 623 | gettext_noop ("# bytes encrypted"), |
618 | size, | 624 | size, |
619 | GNUNET_NO); | 625 | GNUNET_NO); |
620 | /* the following is too sensitive to write to log files by accident, | 626 | /* the following is too sensitive to write to log files by accident, |
621 | so we require manual intervention to get this one... */ | 627 | so we require manual intervention to get this one... */ |
@@ -625,8 +631,7 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx, | |||
625 | (unsigned int) size, | 631 | (unsigned int) size, |
626 | GNUNET_i2s (kx->peer), | 632 | GNUNET_i2s (kx->peer), |
627 | (unsigned int) kx->encrypt_key.crc32, | 633 | (unsigned int) kx->encrypt_key.crc32, |
628 | GNUNET_CRYPTO_crc32_n (iv, | 634 | GNUNET_CRYPTO_crc32_n (iv, sizeof (iv))); |
629 | sizeof (iv))); | ||
630 | #endif | 635 | #endif |
631 | return GNUNET_OK; | 636 | return GNUNET_OK; |
632 | } | 637 | } |
@@ -656,19 +661,18 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, | |||
656 | GNUNET_break (0); | 661 | GNUNET_break (0); |
657 | return GNUNET_NO; | 662 | return GNUNET_NO; |
658 | } | 663 | } |
659 | if ( (kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) && | 664 | if ((kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) && |
660 | (kx->status != GNUNET_CORE_KX_STATE_UP) && | 665 | (kx->status != GNUNET_CORE_KX_STATE_UP) && |
661 | (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT) ) | 666 | (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT)) |
662 | { | 667 | { |
663 | GNUNET_break_op (0); | 668 | GNUNET_break_op (0); |
664 | return GNUNET_SYSERR; | 669 | return GNUNET_SYSERR; |
665 | } | 670 | } |
666 | if (size != | 671 | if (size != GNUNET_CRYPTO_symmetric_decrypt (in, |
667 | GNUNET_CRYPTO_symmetric_decrypt (in, | 672 | (uint16_t) size, |
668 | (uint16_t) size, | 673 | &kx->decrypt_key, |
669 | &kx->decrypt_key, | 674 | iv, |
670 | iv, | 675 | out)) |
671 | out)) | ||
672 | { | 676 | { |
673 | GNUNET_break (0); | 677 | GNUNET_break (0); |
674 | return GNUNET_SYSERR; | 678 | return GNUNET_SYSERR; |
@@ -685,9 +689,7 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx, | |||
685 | (unsigned int) size, | 689 | (unsigned int) size, |
686 | GNUNET_i2s (kx->peer), | 690 | GNUNET_i2s (kx->peer), |
687 | (unsigned int) kx->decrypt_key.crc32, | 691 | (unsigned int) kx->decrypt_key.crc32, |
688 | GNUNET_CRYPTO_crc32_n (iv, | 692 | GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv))); |
689 | sizeof | ||
690 | (*iv))); | ||
691 | #endif | 693 | #endif |
692 | return GNUNET_OK; | 694 | return GNUNET_OK; |
693 | } | 695 | } |
@@ -713,7 +715,8 @@ set_key_retry_task (void *cls) | |||
713 | struct GSC_KeyExchangeInfo *kx = cls; | 715 | struct GSC_KeyExchangeInfo *kx = cls; |
714 | 716 | ||
715 | kx->retry_set_key_task = NULL; | 717 | kx->retry_set_key_task = NULL; |
716 | kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency); | 718 | kx->set_key_retry_frequency = |
719 | GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency); | ||
717 | GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status); | 720 | GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status); |
718 | send_key (kx); | 721 | send_key (kx); |
719 | } | 722 | } |
@@ -732,23 +735,20 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) | |||
732 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 735 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
733 | 736 | ||
734 | pm = &kx->ping; | 737 | pm = &kx->ping; |
735 | kx->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 738 | kx->ping_challenge = |
736 | UINT32_MAX); | 739 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); |
737 | pm->header.size = htons (sizeof (struct PingMessage)); | 740 | pm->header.size = htons (sizeof (struct PingMessage)); |
738 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 741 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
739 | pm->iv_seed = calculate_seed (kx); | 742 | pm->iv_seed = calculate_seed (kx); |
740 | derive_iv (&iv, | 743 | derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, kx->peer); |
741 | &kx->encrypt_key, | ||
742 | pm->iv_seed, | ||
743 | kx->peer); | ||
744 | pp.challenge = kx->ping_challenge; | 744 | pp.challenge = kx->ping_challenge; |
745 | pp.target = *kx->peer; | 745 | pp.target = *kx->peer; |
746 | do_encrypt (kx, | 746 | do_encrypt (kx, |
747 | &iv, | 747 | &iv, |
748 | &pp.target, | 748 | &pp.target, |
749 | &pm->target, | 749 | &pm->target, |
750 | sizeof (struct PingMessage) - ((void *) &pm->target - | 750 | sizeof (struct PingMessage) - |
751 | (void *) pm)); | 751 | ((void *) &pm->target - (void *) pm)); |
752 | } | 752 | } |
753 | 753 | ||
754 | 754 | ||
@@ -764,8 +764,7 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) | |||
764 | * #GNUNET_SYSERR to stop further processing with error | 764 | * #GNUNET_SYSERR to stop further processing with error |
765 | */ | 765 | */ |
766 | static int | 766 | static int |
767 | deliver_message (void *cls, | 767 | deliver_message (void *cls, const struct GNUNET_MessageHeader *m) |
768 | const struct GNUNET_MessageHeader *m) | ||
769 | { | 768 | { |
770 | struct GSC_KeyExchangeInfo *kx = cls; | 769 | struct GSC_KeyExchangeInfo *kx = cls; |
771 | 770 | ||
@@ -816,38 +815,32 @@ deliver_message (void *cls, | |||
816 | static void * | 815 | static void * |
817 | handle_transport_notify_connect (void *cls, | 816 | handle_transport_notify_connect (void *cls, |
818 | const struct GNUNET_PeerIdentity *pid, | 817 | const struct GNUNET_PeerIdentity *pid, |
819 | struct GNUNET_MQ_Handle *mq) | 818 | struct GNUNET_MQ_Handle *mq) |
820 | { | 819 | { |
821 | struct GSC_KeyExchangeInfo *kx; | 820 | struct GSC_KeyExchangeInfo *kx; |
822 | struct GNUNET_HashCode h1; | 821 | struct GNUNET_HashCode h1; |
823 | struct GNUNET_HashCode h2; | 822 | struct GNUNET_HashCode h2; |
824 | 823 | ||
825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
826 | "Initiating key exchange with `%s'\n", | 825 | "Initiating key exchange with `%s'\n", |
827 | GNUNET_i2s (pid)); | 826 | GNUNET_i2s (pid)); |
828 | GNUNET_STATISTICS_update (GSC_stats, | 827 | GNUNET_STATISTICS_update (GSC_stats, |
829 | gettext_noop ("# key exchanges initiated"), | 828 | gettext_noop ("# key exchanges initiated"), |
830 | 1, | 829 | 1, |
831 | GNUNET_NO); | 830 | GNUNET_NO); |
832 | kx = GNUNET_new (struct GSC_KeyExchangeInfo); | 831 | kx = GNUNET_new (struct GSC_KeyExchangeInfo); |
833 | kx->mst = GNUNET_MST_create (&deliver_message, | 832 | kx->mst = GNUNET_MST_create (&deliver_message, kx); |
834 | kx); | ||
835 | kx->mq = mq; | 833 | kx->mq = mq; |
836 | kx->peer = pid; | 834 | kx->peer = pid; |
837 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; | 835 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; |
838 | GNUNET_CONTAINER_DLL_insert (kx_head, | 836 | GNUNET_CONTAINER_DLL_insert (kx_head, kx_tail, kx); |
839 | kx_tail, | ||
840 | kx); | ||
841 | kx->status = GNUNET_CORE_KX_STATE_KEY_SENT; | 837 | kx->status = GNUNET_CORE_KX_STATE_KEY_SENT; |
842 | monitor_notify_all (kx); | 838 | monitor_notify_all (kx); |
843 | GNUNET_CRYPTO_hash (pid, | 839 | GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1); |
844 | sizeof (struct GNUNET_PeerIdentity), | ||
845 | &h1); | ||
846 | GNUNET_CRYPTO_hash (&GSC_my_identity, | 840 | GNUNET_CRYPTO_hash (&GSC_my_identity, |
847 | sizeof (struct GNUNET_PeerIdentity), | 841 | sizeof (struct GNUNET_PeerIdentity), |
848 | &h2); | 842 | &h2); |
849 | if (0 < GNUNET_CRYPTO_hash_cmp (&h1, | 843 | if (0 < GNUNET_CRYPTO_hash_cmp (&h1, &h2)) |
850 | &h2)) | ||
851 | { | 844 | { |
852 | /* peer with "lower" identity starts KX, otherwise we typically end up | 845 | /* peer with "lower" identity starts KX, otherwise we typically end up |
853 | with both peers starting the exchange and transmit the 'set key' | 846 | with both peers starting the exchange and transmit the 'set key' |
@@ -858,10 +851,10 @@ handle_transport_notify_connect (void *cls, | |||
858 | { | 851 | { |
859 | /* peer with "higher" identity starts a delayed KX, if the "lower" peer | 852 | /* peer with "higher" identity starts a delayed KX, if the "lower" peer |
860 | * does not start a KX since it sees no reasons to do so */ | 853 | * does not start a KX since it sees no reasons to do so */ |
861 | kx->retry_set_key_task | 854 | kx->retry_set_key_task = |
862 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 855 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
863 | &set_key_retry_task, | 856 | &set_key_retry_task, |
864 | kx); | 857 | kx); |
865 | } | 858 | } |
866 | return kx; | 859 | return kx; |
867 | } | 860 | } |
@@ -879,7 +872,7 @@ handle_transport_notify_connect (void *cls, | |||
879 | static void | 872 | static void |
880 | handle_transport_notify_disconnect (void *cls, | 873 | handle_transport_notify_disconnect (void *cls, |
881 | const struct GNUNET_PeerIdentity *peer, | 874 | const struct GNUNET_PeerIdentity *peer, |
882 | void *handler_cls) | 875 | void *handler_cls) |
883 | { | 876 | { |
884 | struct GSC_KeyExchangeInfo *kx = handler_cls; | 877 | struct GSC_KeyExchangeInfo *kx = handler_cls; |
885 | 878 | ||
@@ -888,9 +881,9 @@ handle_transport_notify_disconnect (void *cls, | |||
888 | GNUNET_i2s (peer)); | 881 | GNUNET_i2s (peer)); |
889 | GSC_SESSIONS_end (kx->peer); | 882 | GSC_SESSIONS_end (kx->peer); |
890 | GNUNET_STATISTICS_update (GSC_stats, | 883 | GNUNET_STATISTICS_update (GSC_stats, |
891 | gettext_noop ("# key exchanges stopped"), | 884 | gettext_noop ("# key exchanges stopped"), |
892 | 1, | 885 | 1, |
893 | GNUNET_NO); | 886 | GNUNET_NO); |
894 | if (NULL != kx->retry_set_key_task) | 887 | if (NULL != kx->retry_set_key_task) |
895 | { | 888 | { |
896 | GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); | 889 | GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); |
@@ -903,9 +896,7 @@ handle_transport_notify_disconnect (void *cls, | |||
903 | } | 896 | } |
904 | kx->status = GNUNET_CORE_KX_PEER_DISCONNECT; | 897 | kx->status = GNUNET_CORE_KX_PEER_DISCONNECT; |
905 | monitor_notify_all (kx); | 898 | monitor_notify_all (kx); |
906 | GNUNET_CONTAINER_DLL_remove (kx_head, | 899 | GNUNET_CONTAINER_DLL_remove (kx_head, kx_tail, kx); |
907 | kx_tail, | ||
908 | kx); | ||
909 | GNUNET_MST_destroy (kx->mst); | 900 | GNUNET_MST_destroy (kx->mst); |
910 | GNUNET_free (kx); | 901 | GNUNET_free (kx); |
911 | } | 902 | } |
@@ -926,8 +917,7 @@ send_ping (struct GSC_KeyExchangeInfo *kx) | |||
926 | 1, | 917 | 1, |
927 | GNUNET_NO); | 918 | GNUNET_NO); |
928 | env = GNUNET_MQ_msg_copy (&kx->ping.header); | 919 | env = GNUNET_MQ_msg_copy (&kx->ping.header); |
929 | GNUNET_MQ_send (kx->mq, | 920 | GNUNET_MQ_send (kx->mq, env); |
930 | env); | ||
931 | } | 921 | } |
932 | 922 | ||
933 | 923 | ||
@@ -941,22 +931,15 @@ derive_session_keys (struct GSC_KeyExchangeInfo *kx) | |||
941 | { | 931 | { |
942 | struct GNUNET_HashCode key_material; | 932 | struct GNUNET_HashCode key_material; |
943 | 933 | ||
944 | if (GNUNET_OK != | 934 | if (GNUNET_OK != GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key, |
945 | GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key, | 935 | &kx->other_ephemeral_key, |
946 | &kx->other_ephemeral_key, | 936 | &key_material)) |
947 | &key_material)) | ||
948 | { | 937 | { |
949 | GNUNET_break (0); | 938 | GNUNET_break (0); |
950 | return; | 939 | return; |
951 | } | 940 | } |
952 | derive_aes_key (&GSC_my_identity, | 941 | derive_aes_key (&GSC_my_identity, kx->peer, &key_material, &kx->encrypt_key); |
953 | kx->peer, | 942 | derive_aes_key (kx->peer, &GSC_my_identity, &key_material, &kx->decrypt_key); |
954 | &key_material, | ||
955 | &kx->encrypt_key); | ||
956 | derive_aes_key (kx->peer, | ||
957 | &GSC_my_identity, | ||
958 | &key_material, | ||
959 | &kx->decrypt_key); | ||
960 | memset (&key_material, 0, sizeof (key_material)); | 943 | memset (&key_material, 0, sizeof (key_material)); |
961 | /* fresh key, reset sequence numbers */ | 944 | /* fresh key, reset sequence numbers */ |
962 | kx->last_sequence_number_received = 0; | 945 | kx->last_sequence_number_received = 0; |
@@ -973,8 +956,7 @@ derive_session_keys (struct GSC_KeyExchangeInfo *kx) | |||
973 | * @param m the set key message we received | 956 | * @param m the set key message we received |
974 | */ | 957 | */ |
975 | static void | 958 | static void |
976 | handle_ephemeral_key (void *cls, | 959 | handle_ephemeral_key (void *cls, const struct EphemeralKeyMessage *m) |
977 | const struct EphemeralKeyMessage *m) | ||
978 | { | 960 | { |
979 | struct GSC_KeyExchangeInfo *kx = cls; | 961 | struct GSC_KeyExchangeInfo *kx = cls; |
980 | struct GNUNET_TIME_Absolute start_t; | 962 | struct GNUNET_TIME_Absolute start_t; |
@@ -983,14 +965,14 @@ handle_ephemeral_key (void *cls, | |||
983 | enum GNUNET_CORE_KxState sender_status; | 965 | enum GNUNET_CORE_KxState sender_status; |
984 | 966 | ||
985 | end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time); | 967 | end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time); |
986 | if ( ( (GNUNET_CORE_KX_STATE_KEY_RECEIVED == kx->status) || | 968 | if (((GNUNET_CORE_KX_STATE_KEY_RECEIVED == kx->status) || |
987 | (GNUNET_CORE_KX_STATE_UP == kx->status) || | 969 | (GNUNET_CORE_KX_STATE_UP == kx->status) || |
988 | (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status) ) && | 970 | (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status)) && |
989 | (end_t.abs_value_us < kx->foreign_key_expires.abs_value_us) ) | 971 | (end_t.abs_value_us < kx->foreign_key_expires.abs_value_us)) |
990 | { | 972 | { |
991 | GNUNET_STATISTICS_update (GSC_stats, | 973 | GNUNET_STATISTICS_update (GSC_stats, |
992 | gettext_noop ("# old ephemeral keys ignored"), | 974 | gettext_noop ("# old ephemeral keys ignored"), |
993 | 1, | 975 | 1, |
994 | GNUNET_NO); | 976 | GNUNET_NO); |
995 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 977 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
996 | "Received expired EPHEMERAL_KEY from %s\n", | 978 | "Received expired EPHEMERAL_KEY from %s\n", |
@@ -1002,18 +984,18 @@ handle_ephemeral_key (void *cls, | |||
1002 | sizeof (m->ephemeral_key))) | 984 | sizeof (m->ephemeral_key))) |
1003 | { | 985 | { |
1004 | GNUNET_STATISTICS_update (GSC_stats, | 986 | GNUNET_STATISTICS_update (GSC_stats, |
1005 | gettext_noop ("# duplicate ephemeral keys ignored"), | 987 | gettext_noop ( |
1006 | 1, | 988 | "# duplicate ephemeral keys ignored"), |
989 | 1, | ||
1007 | GNUNET_NO); | 990 | GNUNET_NO); |
1008 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 991 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1009 | "Ignoring duplicate EPHEMERAL_KEY from %s\n", | 992 | "Ignoring duplicate EPHEMERAL_KEY from %s\n", |
1010 | GNUNET_i2s (&m->origin_identity)); | 993 | GNUNET_i2s (&m->origin_identity)); |
1011 | return; | 994 | return; |
1012 | } | 995 | } |
1013 | if (0 != | 996 | if (0 != memcmp (&m->origin_identity, |
1014 | memcmp (&m->origin_identity, | 997 | kx->peer, |
1015 | kx->peer, | 998 | sizeof (struct GNUNET_PeerIdentity))) |
1016 | sizeof (struct GNUNET_PeerIdentity))) | ||
1017 | { | 999 | { |
1018 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1019 | "Received EPHEMERAL_KEY from %s, but expected %s\n", | 1001 | "Received EPHEMERAL_KEY from %s, but expected %s\n", |
@@ -1024,10 +1006,10 @@ handle_ephemeral_key (void *cls, | |||
1024 | } | 1006 | } |
1025 | if ((ntohl (m->purpose.size) != | 1007 | if ((ntohl (m->purpose.size) != |
1026 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 1008 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
1027 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 1009 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
1028 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 1010 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
1029 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + | 1011 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + |
1030 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) || | 1012 | sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) || |
1031 | (GNUNET_OK != | 1013 | (GNUNET_OK != |
1032 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY, | 1014 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY, |
1033 | &m->purpose, | 1015 | &m->purpose, |
@@ -1037,7 +1019,8 @@ handle_ephemeral_key (void *cls, | |||
1037 | /* invalid signature */ | 1019 | /* invalid signature */ |
1038 | GNUNET_break_op (0); | 1020 | GNUNET_break_op (0); |
1039 | GNUNET_STATISTICS_update (GSC_stats, | 1021 | GNUNET_STATISTICS_update (GSC_stats, |
1040 | gettext_noop ("# EPHEMERAL_KEYs rejected (bad signature)"), | 1022 | gettext_noop ( |
1023 | "# EPHEMERAL_KEYs rejected (bad signature)"), | ||
1041 | 1, | 1024 | 1, |
1042 | GNUNET_NO); | 1025 | GNUNET_NO); |
1043 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1026 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1047,17 +1030,22 @@ handle_ephemeral_key (void *cls, | |||
1047 | } | 1030 | } |
1048 | now = GNUNET_TIME_absolute_get (); | 1031 | now = GNUNET_TIME_absolute_get (); |
1049 | start_t = GNUNET_TIME_absolute_ntoh (m->creation_time); | 1032 | start_t = GNUNET_TIME_absolute_ntoh (m->creation_time); |
1050 | if ( (end_t.abs_value_us < GNUNET_TIME_absolute_subtract (now, REKEY_TOLERANCE).abs_value_us) || | 1033 | if ((end_t.abs_value_us < |
1051 | (start_t.abs_value_us > GNUNET_TIME_absolute_add (now, REKEY_TOLERANCE).abs_value_us) ) | 1034 | GNUNET_TIME_absolute_subtract (now, REKEY_TOLERANCE).abs_value_us) || |
1035 | (start_t.abs_value_us > | ||
1036 | GNUNET_TIME_absolute_add (now, REKEY_TOLERANCE).abs_value_us)) | ||
1052 | { | 1037 | { |
1053 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1038 | GNUNET_log ( |
1054 | _("EPHEMERAL_KEY from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"), | 1039 | GNUNET_ERROR_TYPE_WARNING, |
1055 | GNUNET_i2s (kx->peer), | 1040 | _ ( |
1056 | (unsigned long long) now.abs_value_us, | 1041 | "EPHEMERAL_KEY from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"), |
1057 | (unsigned long long) start_t.abs_value_us, | 1042 | GNUNET_i2s (kx->peer), |
1058 | (unsigned long long) end_t.abs_value_us); | 1043 | (unsigned long long) now.abs_value_us, |
1044 | (unsigned long long) start_t.abs_value_us, | ||
1045 | (unsigned long long) end_t.abs_value_us); | ||
1059 | GNUNET_STATISTICS_update (GSC_stats, | 1046 | GNUNET_STATISTICS_update (GSC_stats, |
1060 | gettext_noop ("# EPHEMERAL_KEY messages rejected due to time"), | 1047 | gettext_noop ( |
1048 | "# EPHEMERAL_KEY messages rejected due to time"), | ||
1061 | 1, | 1049 | 1, |
1062 | GNUNET_NO); | 1050 | GNUNET_NO); |
1063 | return; | 1051 | return; |
@@ -1066,9 +1054,7 @@ handle_ephemeral_key (void *cls, | |||
1066 | { | 1054 | { |
1067 | struct GNUNET_HashCode eh; | 1055 | struct GNUNET_HashCode eh; |
1068 | 1056 | ||
1069 | GNUNET_CRYPTO_hash (&m->ephemeral_key, | 1057 | GNUNET_CRYPTO_hash (&m->ephemeral_key, sizeof (m->ephemeral_key), &eh); |
1070 | sizeof (m->ephemeral_key), | ||
1071 | &eh); | ||
1072 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1058 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1073 | "Received valid EPHEMERAL_KEY `%s' from `%s' in state %d.\n", | 1059 | "Received valid EPHEMERAL_KEY `%s' from `%s' in state %d.\n", |
1074 | GNUNET_h2s (&eh), | 1060 | GNUNET_h2s (&eh), |
@@ -1166,8 +1152,7 @@ handle_ephemeral_key (void *cls, | |||
1166 | * @param m the encrypted PING message itself | 1152 | * @param m the encrypted PING message itself |
1167 | */ | 1153 | */ |
1168 | static void | 1154 | static void |
1169 | handle_ping (void *cls, | 1155 | handle_ping (void *cls, const struct PingMessage *m) |
1170 | const struct PingMessage *m) | ||
1171 | { | 1156 | { |
1172 | struct GSC_KeyExchangeInfo *kx = cls; | 1157 | struct GSC_KeyExchangeInfo *kx = cls; |
1173 | struct PingMessage t; | 1158 | struct PingMessage t; |
@@ -1180,39 +1165,34 @@ handle_ping (void *cls, | |||
1180 | gettext_noop ("# PING messages received"), | 1165 | gettext_noop ("# PING messages received"), |
1181 | 1, | 1166 | 1, |
1182 | GNUNET_NO); | 1167 | GNUNET_NO); |
1183 | if ( (kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) && | 1168 | if ((kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) && |
1184 | (kx->status != GNUNET_CORE_KX_STATE_UP) && | 1169 | (kx->status != GNUNET_CORE_KX_STATE_UP) && |
1185 | (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT)) | 1170 | (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT)) |
1186 | { | 1171 | { |
1187 | /* ignore */ | 1172 | /* ignore */ |
1188 | GNUNET_STATISTICS_update (GSC_stats, | 1173 | GNUNET_STATISTICS_update (GSC_stats, |
1189 | gettext_noop ("# PING messages dropped (out of order)"), | 1174 | gettext_noop ( |
1175 | "# PING messages dropped (out of order)"), | ||
1190 | 1, | 1176 | 1, |
1191 | GNUNET_NO); | 1177 | GNUNET_NO); |
1192 | return; | 1178 | return; |
1193 | } | 1179 | } |
1194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1195 | "Core service receives PING request from `%s'.\n", | 1181 | "Core service receives PING request from `%s'.\n", |
1196 | GNUNET_i2s (kx->peer)); | 1182 | GNUNET_i2s (kx->peer)); |
1197 | derive_iv (&iv, | 1183 | derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity); |
1198 | &kx->decrypt_key, | 1184 | if (GNUNET_OK != do_decrypt (kx, |
1199 | m->iv_seed, | 1185 | &iv, |
1200 | &GSC_my_identity); | 1186 | &m->target, |
1201 | if (GNUNET_OK != | 1187 | &t.target, |
1202 | do_decrypt (kx, | 1188 | sizeof (struct PingMessage) - |
1203 | &iv, | 1189 | ((void *) &m->target - (void *) m))) |
1204 | &m->target, | ||
1205 | &t.target, | ||
1206 | sizeof (struct PingMessage) - ((void *) &m->target - | ||
1207 | (void *) m))) | ||
1208 | { | 1190 | { |
1209 | GNUNET_break_op (0); | 1191 | GNUNET_break_op (0); |
1210 | return; | 1192 | return; |
1211 | } | 1193 | } |
1212 | if (0 != | 1194 | if (0 != |
1213 | memcmp (&t.target, | 1195 | memcmp (&t.target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) |
1214 | &GSC_my_identity, | ||
1215 | sizeof (struct GNUNET_PeerIdentity))) | ||
1216 | { | 1196 | { |
1217 | if (GNUNET_CORE_KX_STATE_REKEY_SENT != kx->status) | 1197 | if (GNUNET_CORE_KX_STATE_REKEY_SENT != kx->status) |
1218 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1198 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -1220,9 +1200,10 @@ handle_ping (void *cls, | |||
1220 | GNUNET_i2s (kx->peer), | 1200 | GNUNET_i2s (kx->peer), |
1221 | GNUNET_i2s2 (&t.target)); | 1201 | GNUNET_i2s2 (&t.target)); |
1222 | else | 1202 | else |
1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1203 | GNUNET_log ( |
1224 | "Decryption of PING from peer `%s' failed after rekey (harmless)\n", | 1204 | GNUNET_ERROR_TYPE_DEBUG, |
1225 | GNUNET_i2s (kx->peer)); | 1205 | "Decryption of PING from peer `%s' failed after rekey (harmless)\n", |
1206 | GNUNET_i2s (kx->peer)); | ||
1226 | GNUNET_break_op (0); | 1207 | GNUNET_break_op (0); |
1227 | return; | 1208 | return; |
1228 | } | 1209 | } |
@@ -1230,26 +1211,20 @@ handle_ping (void *cls, | |||
1230 | tx.reserved = 0; | 1211 | tx.reserved = 0; |
1231 | tx.challenge = t.challenge; | 1212 | tx.challenge = t.challenge; |
1232 | tx.target = t.target; | 1213 | tx.target = t.target; |
1233 | env = GNUNET_MQ_msg (tp, | 1214 | env = GNUNET_MQ_msg (tp, GNUNET_MESSAGE_TYPE_CORE_PONG); |
1234 | GNUNET_MESSAGE_TYPE_CORE_PONG); | ||
1235 | tp->iv_seed = calculate_seed (kx); | 1215 | tp->iv_seed = calculate_seed (kx); |
1236 | derive_pong_iv (&iv, | 1216 | derive_pong_iv (&iv, &kx->encrypt_key, tp->iv_seed, t.challenge, kx->peer); |
1237 | &kx->encrypt_key, | ||
1238 | tp->iv_seed, | ||
1239 | t.challenge, | ||
1240 | kx->peer); | ||
1241 | do_encrypt (kx, | 1217 | do_encrypt (kx, |
1242 | &iv, | 1218 | &iv, |
1243 | &tx.challenge, | 1219 | &tx.challenge, |
1244 | &tp->challenge, | 1220 | &tp->challenge, |
1245 | sizeof (struct PongMessage) - ((void *) &tp->challenge - | 1221 | sizeof (struct PongMessage) - |
1246 | (void *) tp)); | 1222 | ((void *) &tp->challenge - (void *) tp)); |
1247 | GNUNET_STATISTICS_update (GSC_stats, | 1223 | GNUNET_STATISTICS_update (GSC_stats, |
1248 | gettext_noop ("# PONG messages created"), | 1224 | gettext_noop ("# PONG messages created"), |
1249 | 1, | 1225 | 1, |
1250 | GNUNET_NO); | 1226 | GNUNET_NO); |
1251 | GNUNET_MQ_send (kx->mq, | 1227 | GNUNET_MQ_send (kx->mq, env); |
1252 | env); | ||
1253 | } | 1228 | } |
1254 | 1229 | ||
1255 | 1230 | ||
@@ -1289,13 +1264,10 @@ send_keep_alive (void *cls) | |||
1289 | GNUNET_NO); | 1264 | GNUNET_NO); |
1290 | setup_fresh_ping (kx); | 1265 | setup_fresh_ping (kx); |
1291 | send_ping (kx); | 1266 | send_ping (kx); |
1292 | retry = | 1267 | retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), |
1293 | GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), | 1268 | MIN_PING_FREQUENCY); |
1294 | MIN_PING_FREQUENCY); | ||
1295 | kx->keep_alive_task = | 1269 | kx->keep_alive_task = |
1296 | GNUNET_SCHEDULER_add_delayed (retry, | 1270 | GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); |
1297 | &send_keep_alive, | ||
1298 | kx); | ||
1299 | } | 1271 | } |
1300 | 1272 | ||
1301 | 1273 | ||
@@ -1312,10 +1284,9 @@ update_timeout (struct GSC_KeyExchangeInfo *kx) | |||
1312 | struct GNUNET_TIME_Relative delta; | 1284 | struct GNUNET_TIME_Relative delta; |
1313 | 1285 | ||
1314 | kx->timeout = | 1286 | kx->timeout = |
1315 | GNUNET_TIME_relative_to_absolute | 1287 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1316 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1288 | delta = |
1317 | delta = GNUNET_TIME_absolute_get_difference (kx->last_notify_timeout, | 1289 | GNUNET_TIME_absolute_get_difference (kx->last_notify_timeout, kx->timeout); |
1318 | kx->timeout); | ||
1319 | if (delta.rel_value_us > 5LL * 1000LL * 1000LL) | 1290 | if (delta.rel_value_us > 5LL * 1000LL * 1000LL) |
1320 | { | 1291 | { |
1321 | /* we only notify monitors about timeout changes if those | 1292 | /* we only notify monitors about timeout changes if those |
@@ -1324,12 +1295,10 @@ update_timeout (struct GSC_KeyExchangeInfo *kx) | |||
1324 | } | 1295 | } |
1325 | if (NULL != kx->keep_alive_task) | 1296 | if (NULL != kx->keep_alive_task) |
1326 | GNUNET_SCHEDULER_cancel (kx->keep_alive_task); | 1297 | GNUNET_SCHEDULER_cancel (kx->keep_alive_task); |
1327 | kx->keep_alive_task = | 1298 | kx->keep_alive_task = GNUNET_SCHEDULER_add_delayed ( |
1328 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | 1299 | GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), |
1329 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1300 | &send_keep_alive, |
1330 | 2), | 1301 | kx); |
1331 | &send_keep_alive, | ||
1332 | kx); | ||
1333 | } | 1302 | } |
1334 | 1303 | ||
1335 | 1304 | ||
@@ -1340,8 +1309,7 @@ update_timeout (struct GSC_KeyExchangeInfo *kx) | |||
1340 | * @param m the encrypted PONG message itself | 1309 | * @param m the encrypted PONG message itself |
1341 | */ | 1310 | */ |
1342 | static void | 1311 | static void |
1343 | handle_pong (void *cls, | 1312 | handle_pong (void *cls, const struct PongMessage *m) |
1344 | const struct PongMessage *m) | ||
1345 | { | 1313 | { |
1346 | struct GSC_KeyExchangeInfo *kx = cls; | 1314 | struct GSC_KeyExchangeInfo *kx = cls; |
1347 | struct PongMessage t; | 1315 | struct PongMessage t; |
@@ -1355,13 +1323,17 @@ handle_pong (void *cls, | |||
1355 | { | 1323 | { |
1356 | case GNUNET_CORE_KX_STATE_DOWN: | 1324 | case GNUNET_CORE_KX_STATE_DOWN: |
1357 | GNUNET_STATISTICS_update (GSC_stats, | 1325 | GNUNET_STATISTICS_update (GSC_stats, |
1358 | gettext_noop ("# PONG messages dropped (connection down)"), 1, | 1326 | gettext_noop ( |
1359 | GNUNET_NO); | 1327 | "# PONG messages dropped (connection down)"), |
1328 | 1, | ||
1329 | GNUNET_NO); | ||
1360 | return; | 1330 | return; |
1361 | case GNUNET_CORE_KX_STATE_KEY_SENT: | 1331 | case GNUNET_CORE_KX_STATE_KEY_SENT: |
1362 | GNUNET_STATISTICS_update (GSC_stats, | 1332 | GNUNET_STATISTICS_update (GSC_stats, |
1363 | gettext_noop ("# PONG messages dropped (out of order)"), 1, | 1333 | gettext_noop ( |
1364 | GNUNET_NO); | 1334 | "# PONG messages dropped (out of order)"), |
1335 | 1, | ||
1336 | GNUNET_NO); | ||
1365 | return; | 1337 | return; |
1366 | case GNUNET_CORE_KX_STATE_KEY_RECEIVED: | 1338 | case GNUNET_CORE_KX_STATE_KEY_RECEIVED: |
1367 | break; | 1339 | break; |
@@ -1383,13 +1355,12 @@ handle_pong (void *cls, | |||
1383 | m->iv_seed, | 1355 | m->iv_seed, |
1384 | kx->ping_challenge, | 1356 | kx->ping_challenge, |
1385 | &GSC_my_identity); | 1357 | &GSC_my_identity); |
1386 | if (GNUNET_OK != | 1358 | if (GNUNET_OK != do_decrypt (kx, |
1387 | do_decrypt (kx, | 1359 | &iv, |
1388 | &iv, | 1360 | &m->challenge, |
1389 | &m->challenge, | 1361 | &t.challenge, |
1390 | &t.challenge, | 1362 | sizeof (struct PongMessage) - |
1391 | sizeof (struct PongMessage) - ((void *) &m->challenge - | 1363 | ((void *) &m->challenge - (void *) m))) |
1392 | (void *) m))) | ||
1393 | { | 1364 | { |
1394 | GNUNET_break_op (0); | 1365 | GNUNET_break_op (0); |
1395 | return; | 1366 | return; |
@@ -1398,9 +1369,8 @@ handle_pong (void *cls, | |||
1398 | gettext_noop ("# PONG messages decrypted"), | 1369 | gettext_noop ("# PONG messages decrypted"), |
1399 | 1, | 1370 | 1, |
1400 | GNUNET_NO); | 1371 | GNUNET_NO); |
1401 | if ((0 != memcmp (&t.target, | 1372 | if ((0 != |
1402 | kx->peer, | 1373 | memcmp (&t.target, kx->peer, sizeof (struct GNUNET_PeerIdentity))) || |
1403 | sizeof (struct GNUNET_PeerIdentity))) || | ||
1404 | (kx->ping_challenge != t.challenge)) | 1374 | (kx->ping_challenge != t.challenge)) |
1405 | { | 1375 | { |
1406 | /* PONG malformed */ | 1376 | /* PONG malformed */ |
@@ -1426,14 +1396,15 @@ handle_pong (void *cls, | |||
1426 | switch (kx->status) | 1396 | switch (kx->status) |
1427 | { | 1397 | { |
1428 | case GNUNET_CORE_KX_STATE_DOWN: | 1398 | case GNUNET_CORE_KX_STATE_DOWN: |
1429 | GNUNET_assert (0); /* should be impossible */ | 1399 | GNUNET_assert (0); /* should be impossible */ |
1430 | return; | 1400 | return; |
1431 | case GNUNET_CORE_KX_STATE_KEY_SENT: | 1401 | case GNUNET_CORE_KX_STATE_KEY_SENT: |
1432 | GNUNET_assert (0); /* should be impossible */ | 1402 | GNUNET_assert (0); /* should be impossible */ |
1433 | return; | 1403 | return; |
1434 | case GNUNET_CORE_KX_STATE_KEY_RECEIVED: | 1404 | case GNUNET_CORE_KX_STATE_KEY_RECEIVED: |
1435 | GNUNET_STATISTICS_update (GSC_stats, | 1405 | GNUNET_STATISTICS_update (GSC_stats, |
1436 | gettext_noop ("# session keys confirmed via PONG"), | 1406 | gettext_noop ( |
1407 | "# session keys confirmed via PONG"), | ||
1437 | 1, | 1408 | 1, |
1438 | GNUNET_NO); | 1409 | GNUNET_NO); |
1439 | kx->status = GNUNET_CORE_KX_STATE_UP; | 1410 | kx->status = GNUNET_CORE_KX_STATE_UP; |
@@ -1451,7 +1422,8 @@ handle_pong (void *cls, | |||
1451 | break; | 1422 | break; |
1452 | case GNUNET_CORE_KX_STATE_REKEY_SENT: | 1423 | case GNUNET_CORE_KX_STATE_REKEY_SENT: |
1453 | GNUNET_STATISTICS_update (GSC_stats, | 1424 | GNUNET_STATISTICS_update (GSC_stats, |
1454 | gettext_noop ("# rekey operations confirmed via PONG"), | 1425 | gettext_noop ( |
1426 | "# rekey operations confirmed via PONG"), | ||
1455 | 1, | 1427 | 1, |
1456 | GNUNET_NO); | 1428 | GNUNET_NO); |
1457 | kx->status = GNUNET_CORE_KX_STATE_UP; | 1429 | kx->status = GNUNET_CORE_KX_STATE_UP; |
@@ -1478,8 +1450,8 @@ send_key (struct GSC_KeyExchangeInfo *kx) | |||
1478 | GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status); | 1450 | GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status); |
1479 | if (NULL != kx->retry_set_key_task) | 1451 | if (NULL != kx->retry_set_key_task) |
1480 | { | 1452 | { |
1481 | GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); | 1453 | GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); |
1482 | kx->retry_set_key_task = NULL; | 1454 | kx->retry_set_key_task = NULL; |
1483 | } | 1455 | } |
1484 | /* always update sender status in SET KEY message */ | 1456 | /* always update sender status in SET KEY message */ |
1485 | #if DEBUG_KX | 1457 | #if DEBUG_KX |
@@ -1498,14 +1470,13 @@ send_key (struct GSC_KeyExchangeInfo *kx) | |||
1498 | #endif | 1470 | #endif |
1499 | current_ekm.sender_status = htonl ((int32_t) (kx->status)); | 1471 | current_ekm.sender_status = htonl ((int32_t) (kx->status)); |
1500 | env = GNUNET_MQ_msg_copy (¤t_ekm.header); | 1472 | env = GNUNET_MQ_msg_copy (¤t_ekm.header); |
1501 | GNUNET_MQ_send (kx->mq, | 1473 | GNUNET_MQ_send (kx->mq, env); |
1502 | env); | ||
1503 | if (GNUNET_CORE_KX_STATE_KEY_SENT != kx->status) | 1474 | if (GNUNET_CORE_KX_STATE_KEY_SENT != kx->status) |
1504 | send_ping (kx); | 1475 | send_ping (kx); |
1505 | kx->retry_set_key_task = | 1476 | kx->retry_set_key_task = |
1506 | GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, | 1477 | GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, |
1507 | &set_key_retry_task, | 1478 | &set_key_retry_task, |
1508 | kx); | 1479 | kx); |
1509 | } | 1480 | } |
1510 | 1481 | ||
1511 | 1482 | ||
@@ -1522,9 +1493,9 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1522 | size_t payload_size) | 1493 | size_t payload_size) |
1523 | { | 1494 | { |
1524 | size_t used = payload_size + sizeof (struct EncryptedMessage); | 1495 | size_t used = payload_size + sizeof (struct EncryptedMessage); |
1525 | char pbuf[used]; /* plaintext */ | 1496 | char pbuf[used]; /* plaintext */ |
1526 | struct EncryptedMessage *em; /* encrypted message */ | 1497 | struct EncryptedMessage *em; /* encrypted message */ |
1527 | struct EncryptedMessage *ph; /* plaintext header */ | 1498 | struct EncryptedMessage *ph; /* plaintext header */ |
1528 | struct GNUNET_MQ_Envelope *env; | 1499 | struct GNUNET_MQ_Envelope *env; |
1529 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 1500 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
1530 | struct GNUNET_CRYPTO_AuthKey auth_key; | 1501 | struct GNUNET_CRYPTO_AuthKey auth_key; |
@@ -1534,23 +1505,17 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1534 | ph->iv_seed = calculate_seed (kx); | 1505 | ph->iv_seed = calculate_seed (kx); |
1535 | ph->reserved = 0; | 1506 | ph->reserved = 0; |
1536 | ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 1507 | ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
1537 | GNUNET_memcpy (&ph[1], | 1508 | GNUNET_memcpy (&ph[1], payload, payload_size); |
1538 | payload, | ||
1539 | payload_size); | ||
1540 | env = GNUNET_MQ_msg_extra (em, | 1509 | env = GNUNET_MQ_msg_extra (em, |
1541 | payload_size, | 1510 | payload_size, |
1542 | GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE); | 1511 | GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE); |
1543 | em->iv_seed = ph->iv_seed; | 1512 | em->iv_seed = ph->iv_seed; |
1544 | derive_iv (&iv, | 1513 | derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, kx->peer); |
1545 | &kx->encrypt_key, | 1514 | GNUNET_assert (GNUNET_OK == do_encrypt (kx, |
1546 | ph->iv_seed, | 1515 | &iv, |
1547 | kx->peer); | 1516 | &ph->sequence_number, |
1548 | GNUNET_assert (GNUNET_OK == | 1517 | &em->sequence_number, |
1549 | do_encrypt (kx, | 1518 | used - ENCRYPTED_HEADER_SIZE)); |
1550 | &iv, | ||
1551 | &ph->sequence_number, | ||
1552 | &em->sequence_number, | ||
1553 | used - ENCRYPTED_HEADER_SIZE)); | ||
1554 | #if DEBUG_KX | 1519 | #if DEBUG_KX |
1555 | { | 1520 | { |
1556 | struct GNUNET_HashCode hc; | 1521 | struct GNUNET_HashCode hc; |
@@ -1565,9 +1530,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1565 | GNUNET_i2s (kx->peer)); | 1530 | GNUNET_i2s (kx->peer)); |
1566 | } | 1531 | } |
1567 | #endif | 1532 | #endif |
1568 | derive_auth_key (&auth_key, | 1533 | derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed); |
1569 | &kx->encrypt_key, | ||
1570 | ph->iv_seed); | ||
1571 | GNUNET_CRYPTO_hmac (&auth_key, | 1534 | GNUNET_CRYPTO_hmac (&auth_key, |
1572 | &em->sequence_number, | 1535 | &em->sequence_number, |
1573 | used - ENCRYPTED_HEADER_SIZE, | 1536 | used - ENCRYPTED_HEADER_SIZE, |
@@ -1576,9 +1539,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1576 | { | 1539 | { |
1577 | struct GNUNET_HashCode hc; | 1540 | struct GNUNET_HashCode hc; |
1578 | 1541 | ||
1579 | GNUNET_CRYPTO_hash (&auth_key, | 1542 | GNUNET_CRYPTO_hash (&auth_key, sizeof (auth_key), &hc); |
1580 | sizeof (auth_key), | ||
1581 | &hc); | ||
1582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1583 | "For peer %s, used AC %s to create hmac %s\n", | 1544 | "For peer %s, used AC %s to create hmac %s\n", |
1584 | GNUNET_i2s (kx->peer), | 1545 | GNUNET_i2s (kx->peer), |
@@ -1587,8 +1548,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1587 | } | 1548 | } |
1588 | #endif | 1549 | #endif |
1589 | kx->has_excess_bandwidth = GNUNET_NO; | 1550 | kx->has_excess_bandwidth = GNUNET_NO; |
1590 | GNUNET_MQ_send (kx->mq, | 1551 | GNUNET_MQ_send (kx->mq, env); |
1591 | env); | ||
1592 | } | 1552 | } |
1593 | 1553 | ||
1594 | 1554 | ||
@@ -1601,8 +1561,7 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1601 | * @return #GNUNET_OK if @a msg is well-formed (size-wise) | 1561 | * @return #GNUNET_OK if @a msg is well-formed (size-wise) |
1602 | */ | 1562 | */ |
1603 | static int | 1563 | static int |
1604 | check_encrypted (void *cls, | 1564 | check_encrypted (void *cls, const struct EncryptedMessage *m) |
1605 | const struct EncryptedMessage *m) | ||
1606 | { | 1565 | { |
1607 | uint16_t size = ntohs (m->header.size) - sizeof (*m); | 1566 | uint16_t size = ntohs (m->header.size) - sizeof (*m); |
1608 | 1567 | ||
@@ -1623,11 +1582,10 @@ check_encrypted (void *cls, | |||
1623 | * @param m encrypted message | 1582 | * @param m encrypted message |
1624 | */ | 1583 | */ |
1625 | static void | 1584 | static void |
1626 | handle_encrypted (void *cls, | 1585 | handle_encrypted (void *cls, const struct EncryptedMessage *m) |
1627 | const struct EncryptedMessage *m) | ||
1628 | { | 1586 | { |
1629 | struct GSC_KeyExchangeInfo *kx = cls; | 1587 | struct GSC_KeyExchangeInfo *kx = cls; |
1630 | struct EncryptedMessage *pt; /* plaintext */ | 1588 | struct EncryptedMessage *pt; /* plaintext */ |
1631 | struct GNUNET_HashCode ph; | 1589 | struct GNUNET_HashCode ph; |
1632 | uint32_t snum; | 1590 | uint32_t snum; |
1633 | struct GNUNET_TIME_Absolute t; | 1591 | struct GNUNET_TIME_Absolute t; |
@@ -1639,19 +1597,25 @@ handle_encrypted (void *cls, | |||
1639 | if (GNUNET_CORE_KX_STATE_UP != kx->status) | 1597 | if (GNUNET_CORE_KX_STATE_UP != kx->status) |
1640 | { | 1598 | { |
1641 | GNUNET_STATISTICS_update (GSC_stats, | 1599 | GNUNET_STATISTICS_update (GSC_stats, |
1642 | gettext_noop ("# DATA message dropped (out of order)"), | 1600 | gettext_noop ( |
1601 | "# DATA message dropped (out of order)"), | ||
1643 | 1, | 1602 | 1, |
1644 | GNUNET_NO); | 1603 | GNUNET_NO); |
1645 | return; | 1604 | return; |
1646 | } | 1605 | } |
1647 | if (0 == GNUNET_TIME_absolute_get_remaining (kx->foreign_key_expires).rel_value_us) | 1606 | if (0 == |
1607 | GNUNET_TIME_absolute_get_remaining (kx->foreign_key_expires).rel_value_us) | ||
1648 | { | 1608 | { |
1649 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1609 | GNUNET_log ( |
1650 | _("Session to peer `%s' went down due to key expiration (should not happen)\n"), | 1610 | GNUNET_ERROR_TYPE_WARNING, |
1651 | GNUNET_i2s (kx->peer)); | 1611 | _ ( |
1612 | "Session to peer `%s' went down due to key expiration (should not happen)\n"), | ||
1613 | GNUNET_i2s (kx->peer)); | ||
1652 | GNUNET_STATISTICS_update (GSC_stats, | 1614 | GNUNET_STATISTICS_update (GSC_stats, |
1653 | gettext_noop ("# sessions terminated by key expiration"), | 1615 | gettext_noop ( |
1654 | 1, GNUNET_NO); | 1616 | "# sessions terminated by key expiration"), |
1617 | 1, | ||
1618 | GNUNET_NO); | ||
1655 | GSC_SESSIONS_end (kx->peer); | 1619 | GSC_SESSIONS_end (kx->peer); |
1656 | if (NULL != kx->keep_alive_task) | 1620 | if (NULL != kx->keep_alive_task) |
1657 | { | 1621 | { |
@@ -1669,9 +1633,7 @@ handle_encrypted (void *cls, | |||
1669 | { | 1633 | { |
1670 | struct GNUNET_HashCode hc; | 1634 | struct GNUNET_HashCode hc; |
1671 | 1635 | ||
1672 | GNUNET_CRYPTO_hash (&m->sequence_number, | 1636 | GNUNET_CRYPTO_hash (&m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &hc); |
1673 | size - ENCRYPTED_HEADER_SIZE, | ||
1674 | &hc); | ||
1675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1637 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1676 | "Received encrypted payload `%s' of %u bytes from %s\n", | 1638 | "Received encrypted payload `%s' of %u bytes from %s\n", |
1677 | GNUNET_h2s (&hc), | 1639 | GNUNET_h2s (&hc), |
@@ -1679,9 +1641,7 @@ handle_encrypted (void *cls, | |||
1679 | GNUNET_i2s (kx->peer)); | 1641 | GNUNET_i2s (kx->peer)); |
1680 | } | 1642 | } |
1681 | #endif | 1643 | #endif |
1682 | derive_auth_key (&auth_key, | 1644 | derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed); |
1683 | &kx->decrypt_key, | ||
1684 | m->iv_seed); | ||
1685 | GNUNET_CRYPTO_hmac (&auth_key, | 1645 | GNUNET_CRYPTO_hmac (&auth_key, |
1686 | &m->sequence_number, | 1646 | &m->sequence_number, |
1687 | size - ENCRYPTED_HEADER_SIZE, | 1647 | size - ENCRYPTED_HEADER_SIZE, |
@@ -1690,9 +1650,7 @@ handle_encrypted (void *cls, | |||
1690 | { | 1650 | { |
1691 | struct GNUNET_HashCode hc; | 1651 | struct GNUNET_HashCode hc; |
1692 | 1652 | ||
1693 | GNUNET_CRYPTO_hash (&auth_key, | 1653 | GNUNET_CRYPTO_hash (&auth_key, sizeof (auth_key), &hc); |
1694 | sizeof (auth_key), | ||
1695 | &hc); | ||
1696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1654 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1697 | "For peer %s, used AC %s to verify hmac %s\n", | 1655 | "For peer %s, used AC %s to verify hmac %s\n", |
1698 | GNUNET_i2s (kx->peer), | 1656 | GNUNET_i2s (kx->peer), |
@@ -1700,27 +1658,21 @@ handle_encrypted (void *cls, | |||
1700 | GNUNET_h2s2 (&m->hmac)); | 1658 | GNUNET_h2s2 (&m->hmac)); |
1701 | } | 1659 | } |
1702 | #endif | 1660 | #endif |
1703 | if (0 != memcmp (&ph, | 1661 | if (0 != memcmp (&ph, &m->hmac, sizeof (struct GNUNET_HashCode))) |
1704 | &m->hmac, | ||
1705 | sizeof (struct GNUNET_HashCode))) | ||
1706 | { | 1662 | { |
1707 | /* checksum failed */ | 1663 | /* checksum failed */ |
1708 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1664 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1709 | "Failed checksum validation for a message from `%s'\n", | 1665 | "Failed checksum validation for a message from `%s'\n", |
1710 | GNUNET_i2s (kx->peer)); | 1666 | GNUNET_i2s (kx->peer)); |
1711 | return; | 1667 | return; |
1712 | } | 1668 | } |
1713 | derive_iv (&iv, | 1669 | derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity); |
1714 | &kx->decrypt_key, | ||
1715 | m->iv_seed, | ||
1716 | &GSC_my_identity); | ||
1717 | /* decrypt */ | 1670 | /* decrypt */ |
1718 | if (GNUNET_OK != | 1671 | if (GNUNET_OK != do_decrypt (kx, |
1719 | do_decrypt (kx, | 1672 | &iv, |
1720 | &iv, | 1673 | &m->sequence_number, |
1721 | &m->sequence_number, | 1674 | &buf[ENCRYPTED_HEADER_SIZE], |
1722 | &buf[ENCRYPTED_HEADER_SIZE], | 1675 | size - ENCRYPTED_HEADER_SIZE)) |
1723 | size - ENCRYPTED_HEADER_SIZE)) | ||
1724 | { | 1676 | { |
1725 | GNUNET_break_op (0); | 1677 | GNUNET_break_op (0); |
1726 | return; | 1678 | return; |
@@ -1751,8 +1703,9 @@ handle_encrypted (void *cls, | |||
1751 | "Received ancient out of sequence message, ignoring.\n"); | 1703 | "Received ancient out of sequence message, ignoring.\n"); |
1752 | /* ancient out of sequence, ignore */ | 1704 | /* ancient out of sequence, ignore */ |
1753 | GNUNET_STATISTICS_update (GSC_stats, | 1705 | GNUNET_STATISTICS_update (GSC_stats, |
1754 | gettext_noop | 1706 | gettext_noop ( |
1755 | ("# bytes dropped (out of sequence)"), size, | 1707 | "# bytes dropped (out of sequence)"), |
1708 | size, | ||
1756 | GNUNET_NO); | 1709 | GNUNET_NO); |
1757 | return; | 1710 | return; |
1758 | } | 1711 | } |
@@ -1766,7 +1719,8 @@ handle_encrypted (void *cls, | |||
1766 | "Received duplicate message, ignoring.\n"); | 1719 | "Received duplicate message, ignoring.\n"); |
1767 | GNUNET_STATISTICS_update (GSC_stats, | 1720 | GNUNET_STATISTICS_update (GSC_stats, |
1768 | gettext_noop ("# bytes dropped (duplicates)"), | 1721 | gettext_noop ("# bytes dropped (duplicates)"), |
1769 | size, GNUNET_NO); | 1722 | size, |
1723 | GNUNET_NO); | ||
1770 | /* duplicate, ignore */ | 1724 | /* duplicate, ignore */ |
1771 | return; | 1725 | return; |
1772 | } | 1726 | } |
@@ -1790,11 +1744,13 @@ handle_encrypted (void *cls, | |||
1790 | { | 1744 | { |
1791 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1792 | "Message received far too old (%s). Content ignored.\n", | 1746 | "Message received far too old (%s). Content ignored.\n", |
1793 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (t), | 1747 | GNUNET_STRINGS_relative_time_to_string ( |
1794 | GNUNET_YES)); | 1748 | GNUNET_TIME_absolute_get_duration (t), |
1749 | GNUNET_YES)); | ||
1795 | GNUNET_STATISTICS_update (GSC_stats, | 1750 | GNUNET_STATISTICS_update (GSC_stats, |
1796 | gettext_noop | 1751 | gettext_noop ( |
1797 | ("# bytes dropped (ancient message)"), size, | 1752 | "# bytes dropped (ancient message)"), |
1753 | size, | ||
1798 | GNUNET_NO); | 1754 | GNUNET_NO); |
1799 | return; | 1755 | return; |
1800 | } | 1756 | } |
@@ -1825,7 +1781,7 @@ handle_encrypted (void *cls, | |||
1825 | static void | 1781 | static void |
1826 | handle_transport_notify_excess_bw (void *cls, | 1782 | handle_transport_notify_excess_bw (void *cls, |
1827 | const struct GNUNET_PeerIdentity *pid, | 1783 | const struct GNUNET_PeerIdentity *pid, |
1828 | void *connect_cls) | 1784 | void *connect_cls) |
1829 | { | 1785 | { |
1830 | struct GSC_KeyExchangeInfo *kx = connect_cls; | 1786 | struct GSC_KeyExchangeInfo *kx = connect_cls; |
1831 | 1787 | ||
@@ -1848,31 +1804,34 @@ sign_ephemeral_key () | |||
1848 | current_ekm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY); | 1804 | current_ekm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY); |
1849 | current_ekm.sender_status = 0; /* to be set later */ | 1805 | current_ekm.sender_status = 0; /* to be set later */ |
1850 | current_ekm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY); | 1806 | current_ekm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY); |
1851 | current_ekm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + | 1807 | current_ekm.purpose.size = |
1852 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 1808 | htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + |
1853 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 1809 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
1854 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + | 1810 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
1855 | sizeof (struct GNUNET_PeerIdentity)); | 1811 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + |
1856 | current_ekm.creation_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 1812 | sizeof (struct GNUNET_PeerIdentity)); |
1857 | if (GNUNET_YES == | 1813 | current_ekm.creation_time = |
1858 | GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg, | 1814 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
1859 | "core", | 1815 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg, |
1860 | "USE_EPHEMERAL_KEYS")) | 1816 | "core", |
1817 | "USE_EPHEMERAL_KEYS")) | ||
1861 | { | 1818 | { |
1862 | current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_add (REKEY_FREQUENCY, | 1819 | current_ekm.expiration_time = |
1863 | REKEY_TOLERANCE))); | 1820 | GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute ( |
1821 | GNUNET_TIME_relative_add (REKEY_FREQUENCY, REKEY_TOLERANCE))); | ||
1864 | } | 1822 | } |
1865 | else | 1823 | else |
1866 | { | 1824 | { |
1867 | current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); | 1825 | current_ekm.expiration_time = |
1826 | GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); | ||
1868 | } | 1827 | } |
1869 | GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key, | 1828 | GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key, |
1870 | ¤t_ekm.ephemeral_key); | 1829 | ¤t_ekm.ephemeral_key); |
1871 | current_ekm.origin_identity = GSC_my_identity; | 1830 | current_ekm.origin_identity = GSC_my_identity; |
1872 | GNUNET_assert (GNUNET_OK == | 1831 | GNUNET_assert (GNUNET_OK == |
1873 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 1832 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
1874 | ¤t_ekm.purpose, | 1833 | ¤t_ekm.purpose, |
1875 | ¤t_ekm.signature)); | 1834 | ¤t_ekm.signature)); |
1876 | } | 1835 | } |
1877 | 1836 | ||
1878 | 1837 | ||
@@ -1886,9 +1845,7 @@ do_rekey (void *cls) | |||
1886 | { | 1845 | { |
1887 | struct GSC_KeyExchangeInfo *pos; | 1846 | struct GSC_KeyExchangeInfo *pos; |
1888 | 1847 | ||
1889 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, | 1848 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL); |
1890 | &do_rekey, | ||
1891 | NULL); | ||
1892 | if (NULL != my_ephemeral_key) | 1849 | if (NULL != my_ephemeral_key) |
1893 | GNUNET_free (my_ephemeral_key); | 1850 | GNUNET_free (my_ephemeral_key); |
1894 | my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); | 1851 | my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); |
@@ -1900,9 +1857,7 @@ do_rekey (void *cls) | |||
1900 | GNUNET_CRYPTO_hash (¤t_ekm.ephemeral_key, | 1857 | GNUNET_CRYPTO_hash (¤t_ekm.ephemeral_key, |
1901 | sizeof (current_ekm.ephemeral_key), | 1858 | sizeof (current_ekm.ephemeral_key), |
1902 | &eh); | 1859 | &eh); |
1903 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1860 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Rekeying to %s\n", GNUNET_h2s (&eh)); |
1904 | "Rekeying to %s\n", | ||
1905 | GNUNET_h2s (&eh)); | ||
1906 | } | 1861 | } |
1907 | for (pos = kx_head; NULL != pos; pos = pos->next) | 1862 | for (pos = kx_head; NULL != pos; pos = pos->next) |
1908 | { | 1863 | { |
@@ -1932,25 +1887,24 @@ do_rekey (void *cls) | |||
1932 | int | 1887 | int |
1933 | GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | 1888 | GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
1934 | { | 1889 | { |
1935 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1890 | struct GNUNET_MQ_MessageHandler handlers[] = |
1936 | GNUNET_MQ_hd_fixed_size (ephemeral_key, | 1891 | {GNUNET_MQ_hd_fixed_size (ephemeral_key, |
1937 | GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY, | 1892 | GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY, |
1938 | struct EphemeralKeyMessage, | 1893 | struct EphemeralKeyMessage, |
1939 | NULL), | 1894 | NULL), |
1940 | GNUNET_MQ_hd_fixed_size (ping, | 1895 | GNUNET_MQ_hd_fixed_size (ping, |
1941 | GNUNET_MESSAGE_TYPE_CORE_PING, | 1896 | GNUNET_MESSAGE_TYPE_CORE_PING, |
1942 | struct PingMessage, | 1897 | struct PingMessage, |
1943 | NULL), | 1898 | NULL), |
1944 | GNUNET_MQ_hd_fixed_size (pong, | 1899 | GNUNET_MQ_hd_fixed_size (pong, |
1945 | GNUNET_MESSAGE_TYPE_CORE_PONG, | 1900 | GNUNET_MESSAGE_TYPE_CORE_PONG, |
1946 | struct PongMessage, | 1901 | struct PongMessage, |
1947 | NULL), | 1902 | NULL), |
1948 | GNUNET_MQ_hd_var_size (encrypted, | 1903 | GNUNET_MQ_hd_var_size (encrypted, |
1949 | GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE, | 1904 | GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE, |
1950 | struct EncryptedMessage, | 1905 | struct EncryptedMessage, |
1951 | NULL), | 1906 | NULL), |
1952 | GNUNET_MQ_handler_end() | 1907 | GNUNET_MQ_handler_end ()}; |
1953 | }; | ||
1954 | 1908 | ||
1955 | my_private_key = pk; | 1909 | my_private_key = pk; |
1956 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, | 1910 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, |
@@ -1976,17 +1930,15 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
1976 | } | 1930 | } |
1977 | 1931 | ||
1978 | nc = GNUNET_notification_context_create (1); | 1932 | nc = GNUNET_notification_context_create (1); |
1979 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, | 1933 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL); |
1980 | &do_rekey, | 1934 | transport = |
1981 | NULL); | 1935 | GNUNET_TRANSPORT_core_connect (GSC_cfg, |
1982 | transport | 1936 | &GSC_my_identity, |
1983 | = GNUNET_TRANSPORT_core_connect (GSC_cfg, | 1937 | handlers, |
1984 | &GSC_my_identity, | 1938 | NULL, |
1985 | handlers, | 1939 | &handle_transport_notify_connect, |
1986 | NULL, | 1940 | &handle_transport_notify_disconnect, |
1987 | &handle_transport_notify_connect, | 1941 | &handle_transport_notify_excess_bw); |
1988 | &handle_transport_notify_disconnect, | ||
1989 | &handle_transport_notify_excess_bw); | ||
1990 | if (NULL == transport) | 1942 | if (NULL == transport) |
1991 | { | 1943 | { |
1992 | GSC_KX_done (); | 1944 | GSC_KX_done (); |
@@ -2030,7 +1982,7 @@ GSC_KX_done () | |||
2030 | } | 1982 | } |
2031 | 1983 | ||
2032 | 1984 | ||
2033 | /** | 1985 | /** |
2034 | * Check how many messages are queued for the given neighbour. | 1986 | * Check how many messages are queued for the given neighbour. |
2035 | * | 1987 | * |
2036 | * @param kxinfo data about neighbour to check | 1988 | * @param kxinfo data about neighbour to check |
@@ -2071,27 +2023,22 @@ GSC_KX_handle_client_monitor_peers (struct GNUNET_MQ_Handle *mq) | |||
2071 | struct MonitorNotifyMessage *done_msg; | 2023 | struct MonitorNotifyMessage *done_msg; |
2072 | struct GSC_KeyExchangeInfo *kx; | 2024 | struct GSC_KeyExchangeInfo *kx; |
2073 | 2025 | ||
2074 | GNUNET_notification_context_add (nc, | 2026 | GNUNET_notification_context_add (nc, mq); |
2075 | mq); | ||
2076 | for (kx = kx_head; NULL != kx; kx = kx->next) | 2027 | for (kx = kx_head; NULL != kx; kx = kx->next) |
2077 | { | 2028 | { |
2078 | struct GNUNET_MQ_Envelope *env; | 2029 | struct GNUNET_MQ_Envelope *env; |
2079 | struct MonitorNotifyMessage *msg; | 2030 | struct MonitorNotifyMessage *msg; |
2080 | 2031 | ||
2081 | env = GNUNET_MQ_msg (msg, | 2032 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); |
2082 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); | ||
2083 | msg->state = htonl ((uint32_t) kx->status); | 2033 | msg->state = htonl ((uint32_t) kx->status); |
2084 | msg->peer = *kx->peer; | 2034 | msg->peer = *kx->peer; |
2085 | msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout); | 2035 | msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout); |
2086 | GNUNET_MQ_send (mq, | 2036 | GNUNET_MQ_send (mq, env); |
2087 | env); | ||
2088 | } | 2037 | } |
2089 | env = GNUNET_MQ_msg (done_msg, | 2038 | env = GNUNET_MQ_msg (done_msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); |
2090 | GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); | ||
2091 | done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED); | 2039 | done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED); |
2092 | done_msg->timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); | 2040 | done_msg->timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); |
2093 | GNUNET_MQ_send (mq, | 2041 | GNUNET_MQ_send (mq, env); |
2094 | env); | ||
2095 | } | 2042 | } |
2096 | 2043 | ||
2097 | 2044 | ||
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 1bcf4e86a..557b91d1c 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -26,7 +26,6 @@ | |||
26 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_arm_service.h" | 27 | #include "gnunet_arm_service.h" |
28 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
29 | #include "gnunet_transport_core_service.h" | ||
30 | #include "gnunet_transport_hello_service.h" | 29 | #include "gnunet_transport_hello_service.h" |
31 | 30 | ||
32 | 31 | ||
@@ -103,26 +102,23 @@ timeout_error (void *cls) | |||
103 | */ | 102 | */ |
104 | static void * | 103 | static void * |
105 | notify_connect (void *cls, | 104 | notify_connect (void *cls, |
106 | const struct GNUNET_PeerIdentity *peer, | 105 | const struct GNUNET_PeerIdentity *peer, |
107 | struct GNUNET_MQ_Handle *mq) | 106 | struct GNUNET_MQ_Handle *mq) |
108 | { | 107 | { |
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
110 | "Peers connected, shutting down.\n"); | ||
111 | ok = 0; | 109 | ok = 0; |
112 | if (NULL != timeout_task) | 110 | if (NULL != timeout_task) |
113 | { | 111 | { |
114 | GNUNET_SCHEDULER_cancel (timeout_task); | 112 | GNUNET_SCHEDULER_cancel (timeout_task); |
115 | timeout_task = NULL; | 113 | timeout_task = NULL; |
116 | } | 114 | } |
117 | GNUNET_SCHEDULER_add_now (&clean_up, | 115 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
118 | NULL); | ||
119 | return NULL; | 116 | return NULL; |
120 | } | 117 | } |
121 | 118 | ||
122 | 119 | ||
123 | static void | 120 | static void |
124 | process_hello (void *cls, | 121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
125 | const struct GNUNET_MessageHeader *message) | ||
126 | { | 122 | { |
127 | struct PeerContext *p = cls; | 123 | struct PeerContext *p = cls; |
128 | 124 | ||
@@ -134,39 +130,35 @@ process_hello (void *cls, | |||
134 | 130 | ||
135 | 131 | ||
136 | static void | 132 | static void |
137 | setup_peer (struct PeerContext *p, | 133 | setup_peer (struct PeerContext *p, const char *cfgname) |
138 | const char *cfgname) | ||
139 | { | 134 | { |
140 | char *binary; | 135 | char *binary; |
141 | 136 | ||
142 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 137 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
143 | p->cfg = GNUNET_CONFIGURATION_create (); | 138 | p->cfg = GNUNET_CONFIGURATION_create (); |
144 | p->arm_proc = | 139 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, |
145 | GNUNET_OS_start_process (GNUNET_YES, | 140 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
146 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 141 | NULL, |
147 | NULL, | 142 | NULL, |
148 | NULL, | 143 | NULL, |
149 | NULL, | 144 | binary, |
150 | binary, | 145 | "gnunet-service-arm", |
151 | "gnunet-service-arm", | 146 | "-c", |
152 | "-c", | 147 | cfgname, |
153 | cfgname, | 148 | NULL); |
154 | NULL); | 149 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
155 | GNUNET_assert (GNUNET_OK == | ||
156 | GNUNET_CONFIGURATION_load (p->cfg, | ||
157 | cfgname)); | ||
158 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, | 150 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
159 | NULL, | 151 | NULL, |
160 | NULL, | 152 | NULL, |
161 | p, | 153 | p, |
162 | ¬ify_connect, | 154 | ¬ify_connect, |
163 | NULL, | 155 | NULL, |
164 | NULL); | 156 | NULL); |
165 | GNUNET_assert (NULL != p->th); | 157 | GNUNET_assert (NULL != p->th); |
166 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | 158 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
167 | GNUNET_TRANSPORT_AC_ANY, | 159 | GNUNET_TRANSPORT_AC_ANY, |
168 | &process_hello, | 160 | &process_hello, |
169 | p); | 161 | p); |
170 | GNUNET_free (binary); | 162 | GNUNET_free (binary); |
171 | } | 163 | } |
172 | 164 | ||
@@ -176,18 +168,13 @@ waitpid_task (void *cls) | |||
176 | { | 168 | { |
177 | struct PeerContext *p = cls; | 169 | struct PeerContext *p = cls; |
178 | 170 | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | ||
172 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | ||
173 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
174 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) | ||
175 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
180 | "Killing ARM process.\n"); | 177 | "ARM process %u stopped\n", |
181 | if (0 != GNUNET_OS_process_kill (p->arm_proc, | ||
182 | GNUNET_TERM_SIG)) | ||
183 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
184 | "kill"); | ||
185 | if (GNUNET_OK != | ||
186 | GNUNET_OS_process_wait (p->arm_proc)) | ||
187 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
188 | "waitpid"); | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
190 | "ARM process %u stopped\n", | ||
191 | GNUNET_OS_process_get_pid (p->arm_proc)); | 178 | GNUNET_OS_process_get_pid (p->arm_proc)); |
192 | GNUNET_OS_process_destroy (p->arm_proc); | 179 | GNUNET_OS_process_destroy (p->arm_proc); |
193 | p->arm_proc = NULL; | 180 | p->arm_proc = NULL; |
@@ -198,11 +185,8 @@ waitpid_task (void *cls) | |||
198 | static void | 185 | static void |
199 | stop_arm (struct PeerContext *p) | 186 | stop_arm (struct PeerContext *p) |
200 | { | 187 | { |
201 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
202 | "Asking ARM to stop core service\n"); | 189 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
203 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
204 | &waitpid_task, | ||
205 | p); | ||
206 | } | 190 | } |
207 | 191 | ||
208 | 192 | ||
@@ -225,36 +209,28 @@ run (void *cls, | |||
225 | { | 209 | { |
226 | GNUNET_assert (ok == 1); | 210 | GNUNET_assert (ok == 1); |
227 | ok++; | 211 | ok++; |
228 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 212 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
229 | &timeout_error, | 213 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
230 | NULL); | 214 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
231 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 215 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
232 | NULL); | ||
233 | setup_peer (&p1, | ||
234 | "test_gnunet_daemon_hostlist_peer1.conf"); | ||
235 | setup_peer (&p2, | ||
236 | "test_gnunet_daemon_hostlist_peer2.conf"); | ||
237 | } | 216 | } |
238 | 217 | ||
239 | 218 | ||
240 | static int | 219 | static int |
241 | check () | 220 | check () |
242 | { | 221 | { |
243 | char *const argv[] = { | 222 | char *const argv[] = {"test-gnunet-daemon-hostlist", |
244 | "test-gnunet-daemon-hostlist", | 223 | "-c", |
245 | "-c", "test_gnunet_daemon_hostlist_data.conf", | 224 | "test_gnunet_daemon_hostlist_data.conf", |
246 | NULL | 225 | NULL}; |
247 | }; | 226 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; |
248 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
249 | GNUNET_GETOPT_OPTION_END | ||
250 | }; | ||
251 | ok = 1; | 227 | ok = 1; |
252 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 228 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
253 | argv, | 229 | argv, |
254 | "test-gnunet-daemon-hostlist", | 230 | "test-gnunet-daemon-hostlist", |
255 | "nohelp", | 231 | "nohelp", |
256 | options, | 232 | options, |
257 | &run, | 233 | &run, |
258 | &ok); | 234 | &ok); |
259 | return ok; | 235 | return ok; |
260 | } | 236 | } |
@@ -271,9 +247,7 @@ main (int argc, char *argv[]) | |||
271 | "GNUNET_TEST_HOME"); | 247 | "GNUNET_TEST_HOME"); |
272 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 248 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
273 | "GNUNET_TEST_HOME"); | 249 | "GNUNET_TEST_HOME"); |
274 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", | 250 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); |
275 | "WARNING", | ||
276 | NULL); | ||
277 | ret = check (); | 251 | ret = check (); |
278 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 252 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
279 | "GNUNET_TEST_HOME"); | 253 | "GNUNET_TEST_HOME"); |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 5dc116ccd..28b2db0de 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -26,7 +26,7 @@ | |||
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_arm_service.h" | 28 | #include "gnunet_arm_service.h" |
29 | #include "gnunet_transport_core_service.h" | 29 | #include "gnunet_transport_service.h" |
30 | #include "gnunet_transport_hello_service.h" | 30 | #include "gnunet_transport_hello_service.h" |
31 | 31 | ||
32 | /** | 32 | /** |
@@ -76,11 +76,10 @@ timeout_error (void *cls) | |||
76 | */ | 76 | */ |
77 | static void * | 77 | static void * |
78 | notify_connect (void *cls, | 78 | notify_connect (void *cls, |
79 | const struct GNUNET_PeerIdentity *peer, | 79 | const struct GNUNET_PeerIdentity *peer, |
80 | struct GNUNET_MQ_Handle *mq) | 80 | struct GNUNET_MQ_Handle *mq) |
81 | { | 81 | { |
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
83 | "Peers connected, shutting down.\n"); | ||
84 | ok = 0; | 83 | ok = 0; |
85 | GNUNET_SCHEDULER_shutdown (); | 84 | GNUNET_SCHEDULER_shutdown (); |
86 | return NULL; | 85 | return NULL; |
@@ -88,8 +87,7 @@ notify_connect (void *cls, | |||
88 | 87 | ||
89 | 88 | ||
90 | static void | 89 | static void |
91 | process_hello (void *cls, | 90 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
92 | const struct GNUNET_MessageHeader *message) | ||
93 | { | 91 | { |
94 | struct PeerContext *p = cls; | 92 | struct PeerContext *p = cls; |
95 | 93 | ||
@@ -101,39 +99,35 @@ process_hello (void *cls, | |||
101 | 99 | ||
102 | 100 | ||
103 | static void | 101 | static void |
104 | setup_peer (struct PeerContext *p, | 102 | setup_peer (struct PeerContext *p, const char *cfgname) |
105 | const char *cfgname) | ||
106 | { | 103 | { |
107 | char *binary; | 104 | char *binary; |
108 | 105 | ||
109 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); | 106 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); |
110 | p->cfg = GNUNET_CONFIGURATION_create (); | 107 | p->cfg = GNUNET_CONFIGURATION_create (); |
111 | p->arm_proc = | 108 | p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, |
112 | GNUNET_OS_start_process (GNUNET_YES, | 109 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
113 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 110 | NULL, |
114 | NULL, | 111 | NULL, |
115 | NULL, | 112 | NULL, |
116 | NULL, | 113 | binary, |
117 | binary, | 114 | "gnunet-service-arm", |
118 | "gnunet-service-arm", | 115 | "-c", |
119 | "-c", | 116 | cfgname, |
120 | cfgname, | 117 | NULL); |
121 | NULL); | 118 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
122 | GNUNET_assert (GNUNET_OK == | ||
123 | GNUNET_CONFIGURATION_load (p->cfg, | ||
124 | cfgname)); | ||
125 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, | 119 | p->th = GNUNET_TRANSPORT_core_connect (p->cfg, |
126 | NULL, | 120 | NULL, |
127 | NULL, | 121 | NULL, |
128 | p, | 122 | p, |
129 | ¬ify_connect, | 123 | ¬ify_connect, |
130 | NULL, | 124 | NULL, |
131 | NULL); | 125 | NULL); |
132 | GNUNET_assert (NULL != p->th); | 126 | GNUNET_assert (NULL != p->th); |
133 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, | 127 | p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, |
134 | GNUNET_TRANSPORT_AC_ANY, | 128 | GNUNET_TRANSPORT_AC_ANY, |
135 | &process_hello, | 129 | &process_hello, |
136 | p); | 130 | p); |
137 | GNUNET_free (binary); | 131 | GNUNET_free (binary); |
138 | } | 132 | } |
139 | 133 | ||
@@ -143,18 +137,13 @@ waitpid_task (void *cls) | |||
143 | { | 137 | { |
144 | struct PeerContext *p = cls; | 138 | struct PeerContext *p = cls; |
145 | 139 | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); | ||
141 | if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) | ||
142 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
143 | if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) | ||
144 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
147 | "Killing ARM process.\n"); | 146 | "ARM process %u stopped\n", |
148 | if (0 != GNUNET_OS_process_kill (p->arm_proc, | ||
149 | GNUNET_TERM_SIG)) | ||
150 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
151 | "kill"); | ||
152 | if (GNUNET_OK != | ||
153 | GNUNET_OS_process_wait (p->arm_proc)) | ||
154 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
155 | "waitpid"); | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
157 | "ARM process %u stopped\n", | ||
158 | GNUNET_OS_process_get_pid (p->arm_proc)); | 147 | GNUNET_OS_process_get_pid (p->arm_proc)); |
159 | GNUNET_OS_process_destroy (p->arm_proc); | 148 | GNUNET_OS_process_destroy (p->arm_proc); |
160 | p->arm_proc = NULL; | 149 | p->arm_proc = NULL; |
@@ -165,11 +154,8 @@ waitpid_task (void *cls) | |||
165 | static void | 154 | static void |
166 | stop_arm (struct PeerContext *p) | 155 | stop_arm (struct PeerContext *p) |
167 | { | 156 | { |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
169 | "Asking ARM to stop core service\n"); | 158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
170 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
171 | &waitpid_task, | ||
172 | p); | ||
173 | } | 159 | } |
174 | 160 | ||
175 | 161 | ||
@@ -217,30 +203,22 @@ run (void *cls, | |||
217 | { | 203 | { |
218 | GNUNET_assert (ok == 1); | 204 | GNUNET_assert (ok == 1); |
219 | ok++; | 205 | ok++; |
220 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 206 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
221 | &timeout_error, | 207 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
222 | NULL); | 208 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
223 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 209 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
224 | NULL); | ||
225 | setup_peer (&p1, | ||
226 | "test_gnunet_daemon_hostlist_peer1.conf"); | ||
227 | setup_peer (&p2, | ||
228 | "test_gnunet_daemon_hostlist_peer2.conf"); | ||
229 | } | 210 | } |
230 | 211 | ||
231 | 212 | ||
232 | int | 213 | int |
233 | main (int argcx, | 214 | main (int argcx, char *argvx[]) |
234 | char *argvx[]) | ||
235 | { | 215 | { |
236 | static char *const argv[] = { | 216 | static char *const argv[] = {"test-gnunet-daemon-hostlist", |
237 | "test-gnunet-daemon-hostlist", | 217 | "-c", |
238 | "-c", "test_gnunet_daemon_hostlist_data.conf", | 218 | "test_gnunet_daemon_hostlist_data.conf", |
239 | NULL | 219 | NULL}; |
240 | }; | ||
241 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 220 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
242 | GNUNET_GETOPT_OPTION_END | 221 | GNUNET_GETOPT_OPTION_END}; |
243 | }; | ||
244 | 222 | ||
245 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 223 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
246 | "GNUNET_TEST_HOME"); | 224 | "GNUNET_TEST_HOME"); |
@@ -248,32 +226,28 @@ main (int argcx, | |||
248 | "GNUNET_TEST_HOME"); | 226 | "GNUNET_TEST_HOME"); |
249 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", | 227 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_data.conf", |
250 | "GNUNET_TEST_HOME"); | 228 | "GNUNET_TEST_HOME"); |
251 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", | 229 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", "WARNING", NULL); |
252 | "WARNING", | ||
253 | NULL); | ||
254 | ok = 1; | 230 | ok = 1; |
255 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 231 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
256 | argv, | 232 | argv, |
257 | "test-gnunet-daemon-hostlist", | 233 | "test-gnunet-daemon-hostlist", |
258 | "nohelp", | 234 | "nohelp", |
259 | options, | 235 | options, |
260 | &run, | 236 | &run, |
261 | &ok); | 237 | &ok); |
262 | if (0 == ok) | 238 | if (0 == ok) |
263 | { | 239 | { |
264 | FPRINTF (stderr, "%s", "."); | 240 | FPRINTF (stderr, "%s", "."); |
265 | /* now do it again */ | 241 | /* now do it again */ |
266 | ok = 1; | 242 | ok = 1; |
267 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 243 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
268 | argv, | 244 | argv, |
269 | "test-gnunet-daemon-hostlist", | 245 | "test-gnunet-daemon-hostlist", |
270 | "nohelp", | 246 | "nohelp", |
271 | options, | 247 | options, |
272 | &run, | 248 | &run, |
273 | &ok); | 249 | &ok); |
274 | FPRINTF (stderr, | 250 | FPRINTF (stderr, "%s", ".\n"); |
275 | "%s", | ||
276 | ".\n"); | ||
277 | } | 251 | } |
278 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", | 252 | GNUNET_DISK_purge_cfg_dir ("test_gnunet_daemon_hostlist_peer1.conf", |
279 | "GNUNET_TEST_HOME"); | 253 | "GNUNET_TEST_HOME"); |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 27a7034b0..7a089ad65 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1089,10 +1089,18 @@ extern "C" { | |||
1089 | 1089 | ||
1090 | /** | 1090 | /** |
1091 | * Message telling transport to limit its receive rate. | 1091 | * Message telling transport to limit its receive rate. |
1092 | * (FIXME: was the above comment ever accurate?) | ||
1093 | * | ||
1094 | * Note: dead in TNG, replaced by RECV_OK! | ||
1092 | */ | 1095 | */ |
1093 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA 366 | 1096 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA 366 |
1094 | 1097 | ||
1095 | /** | 1098 | /** |
1099 | * Message telling transport to limit its receive rate. | ||
1100 | */ | ||
1101 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK 366 | ||
1102 | |||
1103 | /** | ||
1096 | * Request to look addresses of peers in server. | 1104 | * Request to look addresses of peers in server. |
1097 | */ | 1105 | */ |
1098 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 367 | 1106 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 367 |
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h index ca5a86074..ea1ff732e 100644 --- a/src/include/gnunet_transport_communication_service.h +++ b/src/include/gnunet_transport_communication_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2018 GNUnet e.V. | 3 | Copyright (C) 2009-2019 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -36,9 +36,8 @@ | |||
36 | #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H | 36 | #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H |
37 | 37 | ||
38 | #ifdef __cplusplus | 38 | #ifdef __cplusplus |
39 | extern "C" | 39 | extern "C" { |
40 | { | 40 | #if 0 /* keep Emacsens' auto-indent happy */ |
41 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
42 | } | 41 | } |
43 | #endif | 42 | #endif |
44 | #endif | 43 | #endif |
@@ -67,12 +66,13 @@ extern "C" | |||
67 | * @param peer identity of the other peer | 66 | * @param peer identity of the other peer |
68 | * @param address where to send the message, human-readable | 67 | * @param address where to send the message, human-readable |
69 | * communicator-specific format, 0-terminated, UTF-8 | 68 | * communicator-specific format, 0-terminated, UTF-8 |
70 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid | 69 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is |
70 | * invalid | ||
71 | */ | 71 | */ |
72 | typedef int | 72 | typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( |
73 | (*GNUNET_TRANSPORT_CommunicatorMqInit) (void *cls, | 73 | void *cls, |
74 | const struct GNUNET_PeerIdentity *peer, | 74 | const struct GNUNET_PeerIdentity *peer, |
75 | const char *address); | 75 | const char *address); |
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | /** |
@@ -87,7 +87,8 @@ struct GNUNET_TRANSPORT_CommunicatorHandle; | |||
87 | * FIXME: may want to distinguish bi-directional as well, | 87 | * FIXME: may want to distinguish bi-directional as well, |
88 | * should we define a bit for that? Needed in DV logic (handle_dv_learn)! | 88 | * should we define a bit for that? Needed in DV logic (handle_dv_learn)! |
89 | */ | 89 | */ |
90 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics { | 90 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics |
91 | { | ||
91 | 92 | ||
92 | /** | 93 | /** |
93 | * Characteristics are unknown (i.e. DV). | 94 | * Characteristics are unknown (i.e. DV). |
@@ -122,10 +123,10 @@ enum GNUNET_TRANSPORT_CommunicatorCharacteristics { | |||
122 | * @param sender which peer sent the notification | 123 | * @param sender which peer sent the notification |
123 | * @param msg payload | 124 | * @param msg payload |
124 | */ | 125 | */ |
125 | typedef void | 126 | typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) ( |
126 | (*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls, | 127 | void *cls, |
127 | const struct GNUNET_PeerIdentity *sender, | 128 | const struct GNUNET_PeerIdentity *sender, |
128 | const struct GNUNET_MessageHeader *msg); | 129 | const struct GNUNET_MessageHeader *msg); |
129 | 130 | ||
130 | 131 | ||
131 | /** | 132 | /** |
@@ -145,14 +146,15 @@ typedef void | |||
145 | * @return NULL on error | 146 | * @return NULL on error |
146 | */ | 147 | */ |
147 | struct GNUNET_TRANSPORT_CommunicatorHandle * | 148 | struct GNUNET_TRANSPORT_CommunicatorHandle * |
148 | GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 149 | GNUNET_TRANSPORT_communicator_connect ( |
149 | const char *config_section_name, | 150 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
150 | const char *addr_prefix, | 151 | const char *config_section_name, |
151 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | 152 | const char *addr_prefix, |
152 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, | 153 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, |
153 | void *mq_init_cls, | 154 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, |
154 | GNUNET_TRANSPORT_CommunicatorNotify notify_cb, | 155 | void *mq_init_cls, |
155 | void *notify_cb_cls); | 156 | GNUNET_TRANSPORT_CommunicatorNotify notify_cb, |
157 | void *notify_cb_cls); | ||
156 | 158 | ||
157 | 159 | ||
158 | /** | 160 | /** |
@@ -161,22 +163,23 @@ GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle | |||
161 | * @param ch handle returned from connect | 163 | * @param ch handle returned from connect |
162 | */ | 164 | */ |
163 | void | 165 | void |
164 | GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch); | 166 | GNUNET_TRANSPORT_communicator_disconnect ( |
167 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch); | ||
165 | 168 | ||
166 | 169 | ||
167 | /* ************************* Receiving *************************** */ | 170 | /* ************************* Receiving *************************** */ |
168 | 171 | ||
169 | /** | 172 | /** |
170 | * Function called to notify communicator that we have received | 173 | * Function called to notify communicator that we have received |
171 | * and processed the message. | 174 | * and processed the message. Used for flow control (if supported |
175 | * by the communicator). | ||
172 | * | 176 | * |
173 | * @param cls closure | 177 | * @param cls closure |
174 | * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection) | 178 | * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection) |
175 | * #GNUNET_OK on success | 179 | * #GNUNET_OK on success |
176 | */ | 180 | */ |
177 | typedef void | 181 | typedef void (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls, |
178 | (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls, | 182 | int success); |
179 | int success); | ||
180 | 183 | ||
181 | 184 | ||
182 | /** | 185 | /** |
@@ -200,12 +203,13 @@ typedef void | |||
200 | * the tranport service is not yet up | 203 | * the tranport service is not yet up |
201 | */ | 204 | */ |
202 | int | 205 | int |
203 | GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle, | 206 | GNUNET_TRANSPORT_communicator_receive ( |
204 | const struct GNUNET_PeerIdentity *sender, | 207 | struct GNUNET_TRANSPORT_CommunicatorHandle *handle, |
205 | const struct GNUNET_MessageHeader *msg, | 208 | const struct GNUNET_PeerIdentity *sender, |
206 | struct GNUNET_TIME_Relative expected_addr_validity, | 209 | const struct GNUNET_MessageHeader *msg, |
207 | GNUNET_TRANSPORT_MessageCompletedCallback cb, | 210 | struct GNUNET_TIME_Relative expected_addr_validity, |
208 | void *cb_cls); | 211 | GNUNET_TRANSPORT_MessageCompletedCallback cb, |
212 | void *cb_cls); | ||
209 | 213 | ||
210 | 214 | ||
211 | /* ************************* Discovery *************************** */ | 215 | /* ************************* Discovery *************************** */ |
@@ -220,7 +224,8 @@ struct GNUNET_TRANSPORT_QueueHandle; | |||
220 | /** | 224 | /** |
221 | * Possible states of a connection. | 225 | * Possible states of a connection. |
222 | */ | 226 | */ |
223 | enum GNUNET_TRANSPORT_ConnectionStatus { | 227 | enum GNUNET_TRANSPORT_ConnectionStatus |
228 | { | ||
224 | 229 | ||
225 | /** | 230 | /** |
226 | * Connection is down. | 231 | * Connection is down. |
@@ -255,13 +260,14 @@ enum GNUNET_TRANSPORT_ConnectionStatus { | |||
255 | * @return API handle identifying the new MQ | 260 | * @return API handle identifying the new MQ |
256 | */ | 261 | */ |
257 | struct GNUNET_TRANSPORT_QueueHandle * | 262 | struct GNUNET_TRANSPORT_QueueHandle * |
258 | GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | 263 | GNUNET_TRANSPORT_communicator_mq_add ( |
259 | const struct GNUNET_PeerIdentity *peer, | 264 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch, |
260 | const char *address, | 265 | const struct GNUNET_PeerIdentity *peer, |
261 | uint32_t mtu, | 266 | const char *address, |
262 | enum GNUNET_NetworkType nt, | 267 | uint32_t mtu, |
263 | enum GNUNET_TRANSPORT_ConnectionStatus cs, | 268 | enum GNUNET_NetworkType nt, |
264 | struct GNUNET_MQ_Handle *mq); | 269 | enum GNUNET_TRANSPORT_ConnectionStatus cs, |
270 | struct GNUNET_MQ_Handle *mq); | ||
265 | 271 | ||
266 | 272 | ||
267 | /** | 273 | /** |
@@ -291,10 +297,11 @@ struct GNUNET_TRANSPORT_AddressIdentifier; | |||
291 | * @param expiration when does the communicator forsee this address expiring? | 297 | * @param expiration when does the communicator forsee this address expiring? |
292 | */ | 298 | */ |
293 | struct GNUNET_TRANSPORT_AddressIdentifier * | 299 | struct GNUNET_TRANSPORT_AddressIdentifier * |
294 | GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | 300 | GNUNET_TRANSPORT_communicator_address_add ( |
295 | const char *address, | 301 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch, |
296 | enum GNUNET_NetworkType nt, | 302 | const char *address, |
297 | struct GNUNET_TIME_Relative expiration); | 303 | enum GNUNET_NetworkType nt, |
304 | struct GNUNET_TIME_Relative expiration); | ||
298 | 305 | ||
299 | 306 | ||
300 | /** | 307 | /** |
@@ -304,7 +311,8 @@ GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorH | |||
304 | * @param ai address that is no longer provided | 311 | * @param ai address that is no longer provided |
305 | */ | 312 | */ |
306 | void | 313 | void |
307 | GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIdentifier *ai); | 314 | GNUNET_TRANSPORT_communicator_address_remove ( |
315 | struct GNUNET_TRANSPORT_AddressIdentifier *ai); | ||
308 | 316 | ||
309 | 317 | ||
310 | /** | 318 | /** |
@@ -326,13 +334,14 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde | |||
326 | * notify-API to @a pid's communicator @a comm | 334 | * notify-API to @a pid's communicator @a comm |
327 | */ | 335 | */ |
328 | void | 336 | void |
329 | GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | 337 | GNUNET_TRANSPORT_communicator_notify ( |
330 | const struct GNUNET_PeerIdentity *pid, | 338 | struct GNUNET_TRANSPORT_CommunicatorHandle *ch, |
331 | const char *comm, | 339 | const struct GNUNET_PeerIdentity *pid, |
332 | const struct GNUNET_MessageHeader *header); | 340 | const char *comm, |
341 | const struct GNUNET_MessageHeader *header); | ||
333 | 342 | ||
334 | 343 | ||
335 | #if 0 /* keep Emacsens' auto-indent happy */ | 344 | #if 0 /* keep Emacsens' auto-indent happy */ |
336 | { | 345 | { |
337 | #endif | 346 | #endif |
338 | #ifdef __cplusplus | 347 | #ifdef __cplusplus |
@@ -342,6 +351,6 @@ GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle | |||
342 | /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */ | 351 | /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */ |
343 | #endif | 352 | #endif |
344 | 353 | ||
345 | /** @} */ /* end of group */ | 354 | /** @} */ /* end of group */ |
346 | 355 | ||
347 | /* end of gnunet_transport_communicator_service.h */ | 356 | /* end of gnunet_transport_communicator_service.h */ |
diff --git a/src/include/gnunet_transport_core_service.h b/src/include/gnunet_transport_core_service.h index f442b53c0..076514779 100644 --- a/src/include/gnunet_transport_core_service.h +++ b/src/include/gnunet_transport_core_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2016 GNUnet e.V. | 3 | Copyright (C) 2009-2019 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -21,7 +21,7 @@ | |||
21 | * @author Christian Grothoff | 21 | * @author Christian Grothoff |
22 | * | 22 | * |
23 | * @file | 23 | * @file |
24 | * API of the transport service towards the CORE service. | 24 | * API of the transport service towards the CORE service (TNG version) |
25 | * | 25 | * |
26 | * @defgroup transport TRANSPORT service | 26 | * @defgroup transport TRANSPORT service |
27 | * Communication with other peers | 27 | * Communication with other peers |
@@ -34,9 +34,8 @@ | |||
34 | #define GNUNET_TRANSPORT_CORE_SERVICE_H | 34 | #define GNUNET_TRANSPORT_CORE_SERVICE_H |
35 | 35 | ||
36 | #ifdef __cplusplus | 36 | #ifdef __cplusplus |
37 | extern "C" | 37 | extern "C" { |
38 | { | 38 | #if 0 /* keep Emacsens' auto-indent happy */ |
39 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
40 | } | 39 | } |
41 | #endif | 40 | #endif |
42 | #endif | 41 | #endif |
@@ -62,15 +61,15 @@ struct GNUNET_TRANSPORT_CoreHandle; | |||
62 | * @param cls closure | 61 | * @param cls closure |
63 | * @param peer the identity of the peer that connected; this | 62 | * @param peer the identity of the peer that connected; this |
64 | * pointer will remain valid until the disconnect, hence | 63 | * pointer will remain valid until the disconnect, hence |
65 | * applications do not necessarily have to make a copy | 64 | * applications do not necessarily have to make a copy |
66 | * of the value if they only need it until disconnect | 65 | * of the value if they only need it until disconnect |
67 | * @param mq message queue to use to transmit to @a peer | 66 | * @param mq message queue to use to transmit to @a peer |
68 | * @return closure to use in MQ handlers | 67 | * @return closure to use in MQ handlers |
69 | */ | 68 | */ |
70 | typedef void * | 69 | typedef void *(*GNUNET_TRANSPORT_NotifyConnect) ( |
71 | (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, | 70 | void *cls, |
72 | const struct GNUNET_PeerIdentity *peer, | 71 | const struct GNUNET_PeerIdentity *peer, |
73 | struct GNUNET_MQ_Handle *mq); | 72 | struct GNUNET_MQ_Handle *mq); |
74 | 73 | ||
75 | 74 | ||
76 | /** | 75 | /** |
@@ -84,33 +83,10 @@ typedef void * | |||
84 | * @param handlers_cls closure of the handlers, was returned from the | 83 | * @param handlers_cls closure of the handlers, was returned from the |
85 | * connect notification callback | 84 | * connect notification callback |
86 | */ | 85 | */ |
87 | typedef void | 86 | typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) ( |
88 | (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, | 87 | void *cls, |
89 | const struct GNUNET_PeerIdentity *peer, | 88 | const struct GNUNET_PeerIdentity *peer, |
90 | void *handler_cls); | 89 | void *handler_cls); |
91 | |||
92 | |||
93 | /** | ||
94 | * Function called if we have "excess" bandwidth to a peer. | ||
95 | * The notification will happen the first time we have excess | ||
96 | * bandwidth, and then only again after the client has performed | ||
97 | * some transmission to the peer. | ||
98 | * | ||
99 | * Excess bandwidth is defined as being allowed (by ATS) to send | ||
100 | * more data, and us reaching the limit of the capacity build-up | ||
101 | * (which, if we go past it, means we don't use available bandwidth). | ||
102 | * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`. | ||
103 | * | ||
104 | * @param cls the closure | ||
105 | * @param neighbour peer that we have excess bandwidth to | ||
106 | * @param handlers_cls closure of the handlers, was returned from the | ||
107 | * connect notification callback | ||
108 | */ | ||
109 | typedef void | ||
110 | (*GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls, | ||
111 | const struct GNUNET_PeerIdentity *neighbour, | ||
112 | void *handlers_cls); | ||
113 | |||
114 | 90 | ||
115 | 91 | ||
116 | /** | 92 | /** |
@@ -136,8 +112,7 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
136 | const struct GNUNET_MQ_MessageHandler *handlers, | 112 | const struct GNUNET_MQ_MessageHandler *handlers, |
137 | void *cls, | 113 | void *cls, |
138 | GNUNET_TRANSPORT_NotifyConnect nc, | 114 | GNUNET_TRANSPORT_NotifyConnect nc, |
139 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 115 | GNUNET_TRANSPORT_NotifyDisconnect nd); |
140 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb); | ||
141 | 116 | ||
142 | 117 | ||
143 | /** | 118 | /** |
@@ -150,7 +125,33 @@ GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle); | |||
150 | 125 | ||
151 | 126 | ||
152 | /** | 127 | /** |
128 | * Notification from the CORE service to the TRANSPORT service | ||
129 | * that the CORE service has finished processing a message from | ||
130 | * TRANSPORT (via the @code{handlers} of #GNUNET_TRANSPORT_core_connect()) | ||
131 | * and that it is thus now OK for TRANSPORT to send more messages | ||
132 | * for @a pid. | ||
133 | * | ||
134 | * Used to provide flow control, this is our equivalent to | ||
135 | * #GNUNET_SERVICE_client_continue() of an ordinary service. | ||
136 | * | ||
137 | * Note that due to the use of a window, TRANSPORT may send multiple | ||
138 | * messages destined for the same peer even without an intermediate | ||
139 | * call to this function. However, CORE must still call this function | ||
140 | * once per message received, as otherwise eventually the window will | ||
141 | * be full and TRANSPORT will stop providing messages to CORE for @a | ||
142 | * pid. | ||
143 | * | ||
144 | * @param ch core handle | ||
145 | * @param pid which peer was the message from that was fully processed by CORE | ||
146 | */ | ||
147 | void | ||
148 | GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, | ||
149 | const struct GNUNET_PeerIdentity *pid); | ||
150 | |||
151 | |||
152 | /** | ||
153 | * Checks if a given peer is connected to us and get the message queue. | 153 | * Checks if a given peer is connected to us and get the message queue. |
154 | * Convenience function. | ||
154 | * | 155 | * |
155 | * @param handle connection to transport service | 156 | * @param handle connection to transport service |
156 | * @param peer the peer to check | 157 | * @param peer the peer to check |
@@ -161,7 +162,7 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
161 | const struct GNUNET_PeerIdentity *peer); | 162 | const struct GNUNET_PeerIdentity *peer); |
162 | 163 | ||
163 | 164 | ||
164 | #if 0 /* keep Emacsens' auto-indent happy */ | 165 | #if 0 /* keep Emacsens' auto-indent happy */ |
165 | { | 166 | { |
166 | #endif | 167 | #endif |
167 | #ifdef __cplusplus | 168 | #ifdef __cplusplus |
@@ -171,6 +172,6 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
171 | /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */ | 172 | /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */ |
172 | #endif | 173 | #endif |
173 | 174 | ||
174 | /** @} */ /* end of group */ | 175 | /** @} */ /* end of group */ |
175 | 176 | ||
176 | /* end of gnunet_transport_core_service.h */ | 177 | /* end of gnunet_transport_core_service.h */ |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index c5cb10ad8..80949b417 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -36,9 +36,8 @@ | |||
36 | #define GNUNET_TRANSPORT_SERVICE_H | 36 | #define GNUNET_TRANSPORT_SERVICE_H |
37 | 37 | ||
38 | #ifdef __cplusplus | 38 | #ifdef __cplusplus |
39 | extern "C" | 39 | extern "C" { |
40 | { | 40 | #if 0 /* keep Emacsens' auto-indent happy */ |
41 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
42 | } | 41 | } |
43 | #endif | 42 | #endif |
44 | #endif | 43 | #endif |
@@ -71,8 +70,8 @@ struct GNUNET_TRANSPORT_OfferHelloHandle; | |||
71 | * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail | 70 | * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail |
72 | * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success | 71 | * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success |
73 | * @param cont_cls closure for @a cont | 72 | * @param cont_cls closure for @a cont |
74 | * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure, | 73 | * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on |
75 | * in case of failure @a cont will not be called | 74 | * failure, in case of failure @a cont will not be called |
76 | * | 75 | * |
77 | */ | 76 | */ |
78 | struct GNUNET_TRANSPORT_OfferHelloHandle * | 77 | struct GNUNET_TRANSPORT_OfferHelloHandle * |
@@ -88,7 +87,8 @@ GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
88 | * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel | 87 | * @param ohh the `struct GNUNET_TRANSPORT_OfferHelloHandle` to cancel |
89 | */ | 88 | */ |
90 | void | 89 | void |
91 | GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh); | 90 | GNUNET_TRANSPORT_offer_hello_cancel ( |
91 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh); | ||
92 | 92 | ||
93 | 93 | ||
94 | /* *********************** Address to String ******************* */ | 94 | /* *********************** Address to String ******************* */ |
@@ -115,10 +115,9 @@ struct GNUNET_TRANSPORT_AddressToStringContext; | |||
115 | * if #GNUNET_NO: address was invalid (or not supported) | 115 | * if #GNUNET_NO: address was invalid (or not supported) |
116 | * if #GNUNET_SYSERR: communication error (IPC error) | 116 | * if #GNUNET_SYSERR: communication error (IPC error) |
117 | */ | 117 | */ |
118 | typedef void | 118 | typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, |
119 | (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, | 119 | const char *address, |
120 | const char *address, | 120 | int res); |
121 | int res); | ||
122 | 121 | ||
123 | 122 | ||
124 | /** | 123 | /** |
@@ -134,12 +133,13 @@ typedef void | |||
134 | * @return handle to cancel the operation, NULL on error | 133 | * @return handle to cancel the operation, NULL on error |
135 | */ | 134 | */ |
136 | struct GNUNET_TRANSPORT_AddressToStringContext * | 135 | struct GNUNET_TRANSPORT_AddressToStringContext * |
137 | GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, | 136 | GNUNET_TRANSPORT_address_to_string ( |
138 | const struct GNUNET_HELLO_Address *address, | 137 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
139 | int numeric, | 138 | const struct GNUNET_HELLO_Address *address, |
140 | struct GNUNET_TIME_Relative timeout, | 139 | int numeric, |
141 | GNUNET_TRANSPORT_AddressToStringCallback aluc, | 140 | struct GNUNET_TIME_Relative timeout, |
142 | void *aluc_cls); | 141 | GNUNET_TRANSPORT_AddressToStringCallback aluc, |
142 | void *aluc_cls); | ||
143 | 143 | ||
144 | 144 | ||
145 | /** | 145 | /** |
@@ -148,14 +148,16 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf | |||
148 | * @param alc the context handle | 148 | * @param alc the context handle |
149 | */ | 149 | */ |
150 | void | 150 | void |
151 | GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *alc); | 151 | GNUNET_TRANSPORT_address_to_string_cancel ( |
152 | struct GNUNET_TRANSPORT_AddressToStringContext *alc); | ||
152 | 153 | ||
153 | 154 | ||
154 | /* *********************** Monitoring ************************** */ | 155 | /* *********************** Monitoring ************************** */ |
155 | 156 | ||
156 | 157 | ||
157 | /** | 158 | /** |
158 | * Possible state of a neighbour. Initially, we are #GNUNET_TRANSPORT_PS_NOT_CONNECTED. | 159 | * Possible state of a neighbour. Initially, we are |
160 | * #GNUNET_TRANSPORT_PS_NOT_CONNECTED. | ||
159 | * | 161 | * |
160 | * Then, there are two main paths. If we receive a SYN message, we give | 162 | * Then, there are two main paths. If we receive a SYN message, we give |
161 | * the inbound address to ATS. After the check we ask ATS for a suggestion | 163 | * the inbound address to ATS. After the check we ask ATS for a suggestion |
@@ -174,14 +176,14 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStri | |||
174 | * #GNUNET_TRANSPORT_PS_DISCONNECT. | 176 | * #GNUNET_TRANSPORT_PS_DISCONNECT. |
175 | * | 177 | * |
176 | * If the session is in trouble (i.e. transport-level disconnect or | 178 | * If the session is in trouble (i.e. transport-level disconnect or |
177 | * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a new | 179 | * timeout), we go to #GNUNET_TRANSPORT_PS_RECONNECT_ATS where we ask ATS for a |
178 | * address (we don't notify anyone about the disconnect yet). Once we | 180 | * new address (we don't notify anyone about the disconnect yet). Once we have |
179 | * have a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a | 181 | * a new address, we enter #GNUNET_TRANSPORT_PS_RECONNECT_SENT and send a SYN |
180 | * SYN message. If we receive a | 182 | * message. If we receive a SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED |
181 | * SYN_ACK, we go to #GNUNET_TRANSPORT_PS_CONNECTED and nobody noticed that we had | 183 | * and nobody noticed that we had trouble; we also send a ACK at this time just |
182 | * trouble; we also send a ACK at this time just in case. If | 184 | * in case. If the operation times out, we go to |
183 | * the operation times out, we go to #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone | 185 | * #GNUNET_TRANSPORT_PS_DISCONNECT (and notify everyone about the lost |
184 | * about the lost connection). | 186 | * connection). |
185 | * | 187 | * |
186 | * If ATS decides to switch addresses while we have a normal | 188 | * If ATS decides to switch addresses while we have a normal |
187 | * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT | 189 | * connection, we go to #GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_SYN_SENT |
@@ -189,13 +191,14 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStri | |||
189 | * primary connection to the suggested alternative from ATS, go back | 191 | * primary connection to the suggested alternative from ATS, go back |
190 | * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be | 192 | * to #GNUNET_TRANSPORT_PS_CONNECTED and send a ACK to the other peer just to be |
191 | * sure. If the operation times out | 193 | * sure. If the operation times out |
192 | * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given alternative | 194 | * we go to #GNUNET_TRANSPORT_PS_CONNECTED (and notify ATS that the given |
193 | * address is "invalid"). | 195 | * alternative address is "invalid"). |
194 | * | 196 | * |
195 | * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and then goes | 197 | * Once a session is in #GNUNET_TRANSPORT_PS_DISCONNECT, it is cleaned up and |
196 | * to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an explicit disconnect | 198 | * then goes to (#GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED). If we receive an |
197 | * request, we can go from any state to #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after | 199 | * explicit disconnect request, we can go from any state to |
198 | * generating disconnect notifications. | 200 | * #GNUNET_TRANSPORT_PS_DISCONNECT, possibly after generating disconnect |
201 | * notifications. | ||
199 | * | 202 | * |
200 | * Note that it is quite possible that while we are in any of these | 203 | * Note that it is quite possible that while we are in any of these |
201 | * states, we could receive a 'SYN' request from the other peer. | 204 | * states, we could receive a 'SYN' request from the other peer. |
@@ -323,12 +326,12 @@ struct GNUNET_TRANSPORT_PeerMonitoringContext; | |||
323 | * @param state current state this peer is in | 326 | * @param state current state this peer is in |
324 | * @param state_timeout timeout for the current state of the peer | 327 | * @param state_timeout timeout for the current state of the peer |
325 | */ | 328 | */ |
326 | typedef void | 329 | typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) ( |
327 | (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls, | 330 | void *cls, |
328 | const struct GNUNET_PeerIdentity *peer, | 331 | const struct GNUNET_PeerIdentity *peer, |
329 | const struct GNUNET_HELLO_Address *address, | 332 | const struct GNUNET_HELLO_Address *address, |
330 | enum GNUNET_TRANSPORT_PeerState state, | 333 | enum GNUNET_TRANSPORT_PeerState state, |
331 | struct GNUNET_TIME_Absolute state_timeout); | 334 | struct GNUNET_TIME_Absolute state_timeout); |
332 | 335 | ||
333 | 336 | ||
334 | /** | 337 | /** |
@@ -352,17 +355,18 @@ typedef void | |||
352 | * @param cfg configuration to use | 355 | * @param cfg configuration to use |
353 | * @param peer a specific peer identity to obtain information for, | 356 | * @param peer a specific peer identity to obtain information for, |
354 | * NULL for all peers | 357 | * NULL for all peers |
355 | * @param one_shot #GNUNET_YES to return the current state and then end (with NULL+NULL), | 358 | * @param one_shot #GNUNET_YES to return the current state and then end (with |
356 | * #GNUNET_NO to monitor peers continuously | 359 | * NULL+NULL), #GNUNET_NO to monitor peers continuously |
357 | * @param peer_callback function to call with the results | 360 | * @param peer_callback function to call with the results |
358 | * @param peer_callback_cls closure for @a peer_callback | 361 | * @param peer_callback_cls closure for @a peer_callback |
359 | */ | 362 | */ |
360 | struct GNUNET_TRANSPORT_PeerMonitoringContext * | 363 | struct GNUNET_TRANSPORT_PeerMonitoringContext * |
361 | GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, | 364 | GNUNET_TRANSPORT_monitor_peers ( |
362 | const struct GNUNET_PeerIdentity *peer, | 365 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
363 | int one_shot, | 366 | const struct GNUNET_PeerIdentity *peer, |
364 | GNUNET_TRANSPORT_PeerIterateCallback peer_callback, | 367 | int one_shot, |
365 | void *peer_callback_cls); | 368 | GNUNET_TRANSPORT_PeerIterateCallback peer_callback, |
369 | void *peer_callback_cls); | ||
366 | 370 | ||
367 | 371 | ||
368 | /** | 372 | /** |
@@ -371,7 +375,8 @@ GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
371 | * @param pic handle for the request to cancel | 375 | * @param pic handle for the request to cancel |
372 | */ | 376 | */ |
373 | void | 377 | void |
374 | GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic); | 378 | GNUNET_TRANSPORT_monitor_peers_cancel ( |
379 | struct GNUNET_TRANSPORT_PeerMonitoringContext *pic); | ||
375 | 380 | ||
376 | 381 | ||
377 | /* *********************** Blacklisting ************************ */ | 382 | /* *********************** Blacklisting ************************ */ |
@@ -389,9 +394,9 @@ struct GNUNET_TRANSPORT_Blacklist; | |||
389 | * @param pid peer to approve or disapproave | 394 | * @param pid peer to approve or disapproave |
390 | * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not | 395 | * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not |
391 | */ | 396 | */ |
392 | typedef int | 397 | typedef int (*GNUNET_TRANSPORT_BlacklistCallback) ( |
393 | (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls, | 398 | void *cls, |
394 | const struct GNUNET_PeerIdentity *pid); | 399 | const struct GNUNET_PeerIdentity *pid); |
395 | 400 | ||
396 | 401 | ||
397 | /** | 402 | /** |
@@ -539,11 +544,11 @@ struct GNUNET_TRANSPORT_SessionInfo | |||
539 | * NULL with @a session being non-NULL if the monitor | 544 | * NULL with @a session being non-NULL if the monitor |
540 | * was being cancelled while sessions were active | 545 | * was being cancelled while sessions were active |
541 | */ | 546 | */ |
542 | typedef void | 547 | typedef void (*GNUNET_TRANSPORT_SessionMonitorCallback) ( |
543 | (*GNUNET_TRANSPORT_SessionMonitorCallback) (void *cls, | 548 | void *cls, |
544 | struct GNUNET_TRANSPORT_PluginSession *session, | 549 | struct GNUNET_TRANSPORT_PluginSession *session, |
545 | void **session_ctx, | 550 | void **session_ctx, |
546 | const struct GNUNET_TRANSPORT_SessionInfo *info); | 551 | const struct GNUNET_TRANSPORT_SessionInfo *info); |
547 | 552 | ||
548 | 553 | ||
549 | /** | 554 | /** |
@@ -569,11 +574,122 @@ GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
569 | * @param pm handle of the request that is to be cancelled | 574 | * @param pm handle of the request that is to be cancelled |
570 | */ | 575 | */ |
571 | void | 576 | void |
572 | GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor *pm); | 577 | GNUNET_TRANSPORT_monitor_plugins_cancel ( |
578 | struct GNUNET_TRANSPORT_PluginMonitor *pm); | ||
579 | |||
580 | |||
581 | /** | ||
582 | * Opaque handle to the service. | ||
583 | */ | ||
584 | struct GNUNET_TRANSPORT_CoreHandle; | ||
585 | |||
586 | |||
587 | /** | ||
588 | * Function called to notify transport users that another | ||
589 | * peer connected to us. | ||
590 | * | ||
591 | * @param cls closure | ||
592 | * @param peer the identity of the peer that connected; this | ||
593 | * pointer will remain valid until the disconnect, hence | ||
594 | * applications do not necessarily have to make a copy | ||
595 | * of the value if they only need it until disconnect | ||
596 | * @param mq message queue to use to transmit to @a peer | ||
597 | * @return closure to use in MQ handlers | ||
598 | */ | ||
599 | typedef void *(*GNUNET_TRANSPORT_NotifyConnect) ( | ||
600 | void *cls, | ||
601 | const struct GNUNET_PeerIdentity *peer, | ||
602 | struct GNUNET_MQ_Handle *mq); | ||
603 | |||
604 | |||
605 | /** | ||
606 | * Function called to notify transport users that another peer | ||
607 | * disconnected from us. The message queue that was given to the | ||
608 | * connect notification will be destroyed and must not be used | ||
609 | * henceforth. | ||
610 | * | ||
611 | * @param cls closure from #GNUNET_TRANSPORT_core_connect | ||
612 | * @param peer the peer that disconnected | ||
613 | * @param handlers_cls closure of the handlers, was returned from the | ||
614 | * connect notification callback | ||
615 | */ | ||
616 | typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) ( | ||
617 | void *cls, | ||
618 | const struct GNUNET_PeerIdentity *peer, | ||
619 | void *handler_cls); | ||
620 | |||
621 | |||
622 | /** | ||
623 | * Function called if we have "excess" bandwidth to a peer. | ||
624 | * The notification will happen the first time we have excess | ||
625 | * bandwidth, and then only again after the client has performed | ||
626 | * some transmission to the peer. | ||
627 | * | ||
628 | * Excess bandwidth is defined as being allowed (by ATS) to send | ||
629 | * more data, and us reaching the limit of the capacity build-up | ||
630 | * (which, if we go past it, means we don't use available bandwidth). | ||
631 | * See also the "max carry" in `struct GNUNET_BANDWIDTH_Tracker`. | ||
632 | * | ||
633 | * @param cls the closure | ||
634 | * @param neighbour peer that we have excess bandwidth to | ||
635 | * @param handlers_cls closure of the handlers, was returned from the | ||
636 | * connect notification callback | ||
637 | */ | ||
638 | typedef void (*GNUNET_TRANSPORT_NotifyExcessBandwidth) ( | ||
639 | void *cls, | ||
640 | const struct GNUNET_PeerIdentity *neighbour, | ||
641 | void *handlers_cls); | ||
642 | |||
643 | |||
644 | /** | ||
645 | * Connect to the transport service. Note that the connection may | ||
646 | * complete (or fail) asynchronously. | ||
647 | * | ||
648 | * @param cfg configuration to use | ||
649 | * @param self our own identity (API should check that it matches | ||
650 | * the identity found by transport), or NULL (no check) | ||
651 | * @param handlers array of message handlers; note that the | ||
652 | * closures provided will be ignored and replaced | ||
653 | * with the respective return value from @a nc | ||
654 | * @param handlers array with handlers to call when we receive messages, or NULL | ||
655 | * @param cls closure for the @a nc, @a nd and @a neb callbacks | ||
656 | * @param nc function to call on connect events, or NULL | ||
657 | * @param nd function to call on disconnect events, or NULL | ||
658 | * @param neb function to call if we have excess bandwidth to a peer, or NULL | ||
659 | * @return NULL on error | ||
660 | */ | ||
661 | struct GNUNET_TRANSPORT_CoreHandle * | ||
662 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
663 | const struct GNUNET_PeerIdentity *self, | ||
664 | const struct GNUNET_MQ_MessageHandler *handlers, | ||
665 | void *cls, | ||
666 | GNUNET_TRANSPORT_NotifyConnect nc, | ||
667 | GNUNET_TRANSPORT_NotifyDisconnect nd, | ||
668 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb); | ||
669 | |||
670 | |||
671 | /** | ||
672 | * Disconnect from the transport service. | ||
673 | * | ||
674 | * @param handle handle returned from connect | ||
675 | */ | ||
676 | void | ||
677 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle); | ||
573 | 678 | ||
574 | 679 | ||
680 | /** | ||
681 | * Checks if a given peer is connected to us and get the message queue. | ||
682 | * | ||
683 | * @param handle connection to transport service | ||
684 | * @param peer the peer to check | ||
685 | * @return NULL if disconnected, otherwise message queue for @a peer | ||
686 | */ | ||
687 | struct GNUNET_MQ_Handle * | ||
688 | GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | ||
689 | const struct GNUNET_PeerIdentity *peer); | ||
690 | |||
575 | 691 | ||
576 | #if 0 /* keep Emacsens' auto-indent happy */ | 692 | #if 0 /* keep Emacsens' auto-indent happy */ |
577 | { | 693 | { |
578 | #endif | 694 | #endif |
579 | #ifdef __cplusplus | 695 | #ifdef __cplusplus |
@@ -583,6 +699,6 @@ GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor * | |||
583 | /* ifndef GNUNET_TRANSPORT_SERVICE_H */ | 699 | /* ifndef GNUNET_TRANSPORT_SERVICE_H */ |
584 | #endif | 700 | #endif |
585 | 701 | ||
586 | /** @} */ /* end of group */ | 702 | /** @} */ /* end of group */ |
587 | 703 | ||
588 | /* end of gnunet_transport_service.h */ | 704 | /* end of gnunet_transport_service.h */ |
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 99e3864c9..2881a28ac 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -88,7 +88,6 @@ struct GNUNET_NAMESTORE_ZoneMonitor | |||
88 | * Do we first iterate over all existing records? | 88 | * Do we first iterate over all existing records? |
89 | */ | 89 | */ |
90 | int iterate_first; | 90 | int iterate_first; |
91 | |||
92 | }; | 91 | }; |
93 | 92 | ||
94 | 93 | ||
@@ -108,8 +107,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm); | |||
108 | * @param msg the sync message | 107 | * @param msg the sync message |
109 | */ | 108 | */ |
110 | static void | 109 | static void |
111 | handle_sync (void *cls, | 110 | handle_sync (void *cls, const struct GNUNET_MessageHeader *msg) |
112 | const struct GNUNET_MessageHeader *msg) | ||
113 | { | 111 | { |
114 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 112 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
115 | 113 | ||
@@ -128,10 +126,8 @@ handle_sync (void *cls, | |||
128 | * @param lrm the message from the service. | 126 | * @param lrm the message from the service. |
129 | */ | 127 | */ |
130 | static int | 128 | static int |
131 | check_result (void *cls, | 129 | check_result (void *cls, const struct RecordResultMessage *lrm) |
132 | const struct RecordResultMessage *lrm) | ||
133 | { | 130 | { |
134 | static struct GNUNET_CRYPTO_EcdsaPrivateKey zero; | ||
135 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 131 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
136 | size_t lrm_len; | 132 | size_t lrm_len; |
137 | size_t exp_lrm_len; | 133 | size_t exp_lrm_len; |
@@ -142,9 +138,8 @@ check_result (void *cls, | |||
142 | const char *rd_ser_tmp; | 138 | const char *rd_ser_tmp; |
143 | 139 | ||
144 | (void) cls; | 140 | (void) cls; |
145 | if ( (0 != GNUNET_memcmp (&lrm->private_key, | 141 | if ((0 != GNUNET_memcmp (&lrm->private_key, &zm->zone)) && |
146 | &zm->zone)) && | 142 | (0 != GNUNET_is_zero (&zm->zone))) |
147 | (0 != GNUNET_is_zero (&zm->zone)) ) | ||
148 | { | 143 | { |
149 | GNUNET_break (0); | 144 | GNUNET_break (0); |
150 | return GNUNET_SYSERR; | 145 | return GNUNET_SYSERR; |
@@ -170,7 +165,7 @@ check_result (void *cls, | |||
170 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
171 | } | 166 | } |
172 | name_tmp = (const char *) &lrm[1]; | 167 | name_tmp = (const char *) &lrm[1]; |
173 | if (name_tmp[name_len -1] != '\0') | 168 | if (name_tmp[name_len - 1] != '\0') |
174 | { | 169 | { |
175 | GNUNET_break (0); | 170 | GNUNET_break (0); |
176 | return GNUNET_SYSERR; | 171 | return GNUNET_SYSERR; |
@@ -180,10 +175,7 @@ check_result (void *cls, | |||
180 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 175 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
181 | 176 | ||
182 | if (GNUNET_OK != | 177 | if (GNUNET_OK != |
183 | GNUNET_GNSRECORD_records_deserialize (rd_len, | 178 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)) |
184 | rd_ser_tmp, | ||
185 | rd_count, | ||
186 | rd)) | ||
187 | { | 179 | { |
188 | GNUNET_break (0); | 180 | GNUNET_break (0); |
189 | return GNUNET_SYSERR; | 181 | return GNUNET_SYSERR; |
@@ -201,8 +193,7 @@ check_result (void *cls, | |||
201 | * @param lrm the message from the service. | 193 | * @param lrm the message from the service. |
202 | */ | 194 | */ |
203 | static void | 195 | static void |
204 | handle_result (void *cls, | 196 | handle_result (void *cls, const struct RecordResultMessage *lrm) |
205 | const struct RecordResultMessage *lrm) | ||
206 | { | 197 | { |
207 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 198 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
208 | size_t name_len; | 199 | size_t name_len; |
@@ -219,16 +210,10 @@ handle_result (void *cls, | |||
219 | { | 210 | { |
220 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 211 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
221 | 212 | ||
222 | GNUNET_assert (GNUNET_OK == | 213 | GNUNET_assert ( |
223 | GNUNET_GNSRECORD_records_deserialize (rd_len, | 214 | GNUNET_OK == |
224 | rd_ser_tmp, | 215 | GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd)); |
225 | rd_count, | 216 | zm->monitor (zm->monitor_cls, &lrm->private_key, name_tmp, rd_count, rd); |
226 | rd)); | ||
227 | zm->monitor (zm->monitor_cls, | ||
228 | &lrm->private_key, | ||
229 | name_tmp, | ||
230 | rd_count, | ||
231 | rd); | ||
232 | } | 217 | } |
233 | } | 218 | } |
234 | 219 | ||
@@ -242,8 +227,7 @@ handle_result (void *cls, | |||
242 | * @param error error code | 227 | * @param error error code |
243 | */ | 228 | */ |
244 | static void | 229 | static void |
245 | mq_error_handler (void *cls, | 230 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
246 | enum GNUNET_MQ_Error error) | ||
247 | { | 231 | { |
248 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; | 232 | struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls; |
249 | 233 | ||
@@ -260,17 +244,16 @@ mq_error_handler (void *cls, | |||
260 | static void | 244 | static void |
261 | reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | 245 | reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) |
262 | { | 246 | { |
263 | struct GNUNET_MQ_MessageHandler handlers[] = { | 247 | struct GNUNET_MQ_MessageHandler handlers[] = |
264 | GNUNET_MQ_hd_fixed_size (sync, | 248 | {GNUNET_MQ_hd_fixed_size (sync, |
265 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, | 249 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC, |
266 | struct GNUNET_MessageHeader, | 250 | struct GNUNET_MessageHeader, |
267 | zm), | 251 | zm), |
268 | GNUNET_MQ_hd_var_size (result, | 252 | GNUNET_MQ_hd_var_size (result, |
269 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, | 253 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT, |
270 | struct RecordResultMessage, | 254 | struct RecordResultMessage, |
271 | zm), | 255 | zm), |
272 | GNUNET_MQ_handler_end () | 256 | GNUNET_MQ_handler_end ()}; |
273 | }; | ||
274 | struct GNUNET_MQ_Envelope *env; | 257 | struct GNUNET_MQ_Envelope *env; |
275 | struct ZoneMonitorStartMessage *sm; | 258 | struct ZoneMonitorStartMessage *sm; |
276 | 259 | ||
@@ -286,12 +269,10 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
286 | zm); | 269 | zm); |
287 | if (NULL == zm->mq) | 270 | if (NULL == zm->mq) |
288 | return; | 271 | return; |
289 | env = GNUNET_MQ_msg (sm, | 272 | env = GNUNET_MQ_msg (sm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); |
290 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START); | ||
291 | sm->iterate_first = htonl (zm->iterate_first); | 273 | sm->iterate_first = htonl (zm->iterate_first); |
292 | sm->zone = zm->zone; | 274 | sm->zone = zm->zone; |
293 | GNUNET_MQ_send (zm->mq, | 275 | GNUNET_MQ_send (zm->mq, env); |
294 | env); | ||
295 | } | 276 | } |
296 | 277 | ||
297 | 278 | ||
@@ -304,7 +285,8 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
304 | * @param cfg configuration to use to connect to namestore | 285 | * @param cfg configuration to use to connect to namestore |
305 | * @param zone zone to monitor | 286 | * @param zone zone to monitor |
306 | * @param iterate_first #GNUNET_YES to first iterate over all existing records, | 287 | * @param iterate_first #GNUNET_YES to first iterate over all existing records, |
307 | * #GNUNET_NO to only return changes that happen from now on | 288 | * #GNUNET_NO to only return changes that happen from now |
289 | * on | ||
308 | * @param error_cb function to call on error (i.e. disconnect); note that | 290 | * @param error_cb function to call on error (i.e. disconnect); note that |
309 | * unlike the other error callbacks in this API, a call to this | 291 | * unlike the other error callbacks in this API, a call to this |
310 | * function does NOT destroy the monitor handle, it merely signals | 292 | * function does NOT destroy the monitor handle, it merely signals |
@@ -318,15 +300,16 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
318 | * @return handle to stop monitoring | 300 | * @return handle to stop monitoring |
319 | */ | 301 | */ |
320 | struct GNUNET_NAMESTORE_ZoneMonitor * | 302 | struct GNUNET_NAMESTORE_ZoneMonitor * |
321 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 303 | GNUNET_NAMESTORE_zone_monitor_start ( |
322 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 304 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
323 | int iterate_first, | 305 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
324 | GNUNET_SCHEDULER_TaskCallback error_cb, | 306 | int iterate_first, |
325 | void *error_cb_cls, | 307 | GNUNET_SCHEDULER_TaskCallback error_cb, |
326 | GNUNET_NAMESTORE_RecordMonitor monitor, | 308 | void *error_cb_cls, |
327 | void *monitor_cls, | 309 | GNUNET_NAMESTORE_RecordMonitor monitor, |
328 | GNUNET_SCHEDULER_TaskCallback sync_cb, | 310 | void *monitor_cls, |
329 | void *sync_cb_cls) | 311 | GNUNET_SCHEDULER_TaskCallback sync_cb, |
312 | void *sync_cb_cls) | ||
330 | { | 313 | { |
331 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 314 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
332 | 315 | ||
@@ -379,11 +362,9 @@ GNUNET_NAMESTORE_zone_monitor_next (struct GNUNET_NAMESTORE_ZoneMonitor *zm, | |||
379 | struct GNUNET_MQ_Envelope *env; | 362 | struct GNUNET_MQ_Envelope *env; |
380 | struct ZoneMonitorNextMessage *nm; | 363 | struct ZoneMonitorNextMessage *nm; |
381 | 364 | ||
382 | env = GNUNET_MQ_msg (nm, | 365 | env = GNUNET_MQ_msg (nm, GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); |
383 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT); | ||
384 | nm->limit = GNUNET_htonll (limit); | 366 | nm->limit = GNUNET_htonll (limit); |
385 | GNUNET_MQ_send (zm->mq, | 367 | GNUNET_MQ_send (zm->mq, env); |
386 | env); | ||
387 | } | 368 | } |
388 | 369 | ||
389 | 370 | ||
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.c b/src/testbed/gnunet-service-testbed_connectionpool.c index d8461f8e2..e173a2349 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.c +++ b/src/testbed/gnunet-service-testbed_connectionpool.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -27,7 +27,7 @@ | |||
27 | #include "gnunet-service-testbed.h" | 27 | #include "gnunet-service-testbed.h" |
28 | #include "gnunet-service-testbed_connectionpool.h" | 28 | #include "gnunet-service-testbed_connectionpool.h" |
29 | #include "testbed_api_operations.h" | 29 | #include "testbed_api_operations.h" |
30 | #include "gnunet_transport_core_service.h" | 30 | #include "gnunet_transport_service.h" |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Redefine LOG with a changed log component string | 33 | * Redefine LOG with a changed log component string |
@@ -35,14 +35,14 @@ | |||
35 | #ifdef LOG | 35 | #ifdef LOG |
36 | #undef LOG | 36 | #undef LOG |
37 | #endif | 37 | #endif |
38 | #define LOG(kind,...) \ | 38 | #define LOG(kind, ...) \ |
39 | GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) | 39 | GNUNET_log_from (kind, "testbed-connectionpool", __VA_ARGS__) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Time to expire a cache entry | 43 | * Time to expire a cache entry |
44 | */ | 44 | */ |
45 | #define CACHE_EXPIRY \ | 45 | #define CACHE_EXPIRY \ |
46 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 46 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
47 | 47 | ||
48 | 48 | ||
@@ -107,8 +107,8 @@ struct PooledConnection | |||
107 | struct GNUNET_PeerIdentity *peer_identity; | 107 | struct GNUNET_PeerIdentity *peer_identity; |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * The configuration of the peer. Should be not NULL as long as the core_handle | 110 | * The configuration of the peer. Should be not NULL as long as the |
111 | * or transport_handle are valid | 111 | * core_handle or transport_handle are valid |
112 | */ | 112 | */ |
113 | struct GNUNET_CONFIGURATION_Handle *cfg; | 113 | struct GNUNET_CONFIGURATION_Handle *cfg; |
114 | 114 | ||
@@ -137,12 +137,12 @@ struct PooledConnection | |||
137 | /** | 137 | /** |
138 | * The task to expire this connection from the connection pool | 138 | * The task to expire this connection from the connection pool |
139 | */ | 139 | */ |
140 | struct GNUNET_SCHEDULER_Task * expire_task; | 140 | struct GNUNET_SCHEDULER_Task *expire_task; |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * The task to notify a waiting #GST_ConnectionPool_GetHandle object | 143 | * The task to notify a waiting #GST_ConnectionPool_GetHandle object |
144 | */ | 144 | */ |
145 | struct GNUNET_SCHEDULER_Task * notify_task; | 145 | struct GNUNET_SCHEDULER_Task *notify_task; |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * Number of active requests using this pooled connection | 148 | * Number of active requests using this pooled connection |
@@ -286,17 +286,16 @@ static void | |||
286 | destroy_pooled_connection (struct PooledConnection *entry) | 286 | destroy_pooled_connection (struct PooledConnection *entry) |
287 | { | 287 | { |
288 | GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify)); | 288 | GNUNET_assert ((NULL == entry->head_notify) && (NULL == entry->tail_notify)); |
289 | GNUNET_assert ((NULL == entry->head_waiting) && (NULL == | 289 | GNUNET_assert ((NULL == entry->head_waiting) && |
290 | entry->tail_waiting)); | 290 | (NULL == entry->tail_waiting)); |
291 | GNUNET_assert (0 == entry->demand); | 291 | GNUNET_assert (0 == entry->demand); |
292 | expire_task_cancel (entry); | 292 | expire_task_cancel (entry); |
293 | if (entry->in_lru) | 293 | if (entry->in_lru) |
294 | GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); | 294 | GNUNET_CONTAINER_DLL_remove (head_lru, tail_lru, entry); |
295 | if (entry->in_pool) | 295 | if (entry->in_pool) |
296 | GNUNET_assert (GNUNET_OK == | 296 | GNUNET_assert ( |
297 | GNUNET_CONTAINER_multihashmap32_remove (map, | 297 | GNUNET_OK == |
298 | entry->index, | 298 | GNUNET_CONTAINER_multihashmap32_remove (map, entry->index, entry)); |
299 | entry)); | ||
300 | if (NULL != entry->notify_task) | 299 | if (NULL != entry->notify_task) |
301 | { | 300 | { |
302 | GNUNET_SCHEDULER_cancel (entry->notify_task); | 301 | GNUNET_SCHEDULER_cancel (entry->notify_task); |
@@ -370,12 +369,12 @@ static void | |||
370 | add_to_lru (struct PooledConnection *entry) | 369 | add_to_lru (struct PooledConnection *entry) |
371 | { | 370 | { |
372 | GNUNET_assert (0 == entry->demand); | 371 | GNUNET_assert (0 == entry->demand); |
373 | GNUNET_assert (!entry->in_lru); | 372 | GNUNET_assert (! entry->in_lru); |
374 | GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry); | 373 | GNUNET_CONTAINER_DLL_insert_tail (head_lru, tail_lru, entry); |
375 | entry->in_lru = GNUNET_YES; | 374 | entry->in_lru = GNUNET_YES; |
376 | GNUNET_assert (NULL == entry->expire_task); | 375 | GNUNET_assert (NULL == entry->expire_task); |
377 | entry->expire_task = GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, | 376 | entry->expire_task = |
378 | &expire, entry); | 377 | GNUNET_SCHEDULER_add_delayed (CACHE_EXPIRY, &expire, entry); |
379 | } | 378 | } |
380 | 379 | ||
381 | 380 | ||
@@ -404,7 +403,7 @@ search_waiting (const struct PooledConnection *entry, | |||
404 | if (NULL == entry->handle_core) | 403 | if (NULL == entry->handle_core) |
405 | continue; | 404 | continue; |
406 | if (NULL == entry->peer_identity) | 405 | if (NULL == entry->peer_identity) |
407 | continue; /* CORE connection isn't ready yet */ | 406 | continue; /* CORE connection isn't ready yet */ |
408 | break; | 407 | break; |
409 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | 408 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: |
410 | if (NULL == entry->handle_transport) | 409 | if (NULL == entry->handle_transport) |
@@ -425,7 +424,8 @@ search_waiting (const struct PooledConnection *entry, | |||
425 | * A handle in the #PooledConnection object pointed by @a cls is ready and there | 424 | * A handle in the #PooledConnection object pointed by @a cls is ready and there |
426 | * is a #GST_ConnectionPool_GetHandle object waiting in the waiting list. This | 425 | * is a #GST_ConnectionPool_GetHandle object waiting in the waiting list. This |
427 | * function retrieves that object and calls the handle ready callback. It | 426 | * function retrieves that object and calls the handle ready callback. It |
428 | * further schedules itself if there are similar waiting objects which can be notified. | 427 | * further schedules itself if there are similar waiting objects which can be |
428 | * notified. | ||
429 | * | 429 | * |
430 | * @param cls the #PooledConnection object | 430 | * @param cls the #PooledConnection object |
431 | */ | 431 | */ |
@@ -443,23 +443,18 @@ connection_ready (void *cls) | |||
443 | gh_next = NULL; | 443 | gh_next = NULL; |
444 | if (NULL != gh->next) | 444 | if (NULL != gh->next) |
445 | gh_next = search_waiting (entry, gh->next); | 445 | gh_next = search_waiting (entry, gh->next); |
446 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, | 446 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); |
447 | entry->tail_waiting, | ||
448 | gh); | ||
449 | gh->connection_ready_called = 1; | 447 | gh->connection_ready_called = 1; |
450 | if (NULL != gh_next) | 448 | if (NULL != gh_next) |
451 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, | 449 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, entry); |
452 | entry); | 450 | if ((NULL != gh->target) && (NULL != gh->connect_notify_cb)) |
453 | if ( (NULL != gh->target) && | ||
454 | (NULL != gh->connect_notify_cb) ) | ||
455 | { | 451 | { |
456 | GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, | 452 | GNUNET_CONTAINER_DLL_insert_tail (entry->head_notify, |
457 | entry->tail_notify, | 453 | entry->tail_notify, |
458 | gh); | 454 | gh); |
459 | gh->notify_waiting = 1; | 455 | gh->notify_waiting = 1; |
460 | } | 456 | } |
461 | LOG_DEBUG ("Connection ready for handle type %u\n", | 457 | LOG_DEBUG ("Connection ready for handle type %u\n", gh->service); |
462 | gh->service); | ||
463 | gh->cb (gh->cb_cls, | 458 | gh->cb (gh->cb_cls, |
464 | entry->handle_core, | 459 | entry->handle_core, |
465 | entry->handle_transport, | 460 | entry->handle_transport, |
@@ -499,9 +494,7 @@ peer_connect_notify_cb (void *cls, | |||
499 | gh = gh->next; | 494 | gh = gh->next; |
500 | continue; | 495 | continue; |
501 | } | 496 | } |
502 | if (0 != memcmp (gh->target, | 497 | if (0 != memcmp (gh->target, peer, sizeof (struct GNUNET_PeerIdentity))) |
503 | peer, | ||
504 | sizeof (struct GNUNET_PeerIdentity))) | ||
505 | { | 498 | { |
506 | gh = gh->next; | 499 | gh = gh->next; |
507 | continue; | 500 | continue; |
@@ -532,13 +525,11 @@ peer_connect_notify_cb (void *cls, | |||
532 | static void * | 525 | static void * |
533 | transport_peer_connect_notify_cb (void *cls, | 526 | transport_peer_connect_notify_cb (void *cls, |
534 | const struct GNUNET_PeerIdentity *peer, | 527 | const struct GNUNET_PeerIdentity *peer, |
535 | struct GNUNET_MQ_Handle *mq) | 528 | struct GNUNET_MQ_Handle *mq) |
536 | { | 529 | { |
537 | struct PooledConnection *entry = cls; | 530 | struct PooledConnection *entry = cls; |
538 | 531 | ||
539 | peer_connect_notify_cb (entry, | 532 | peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_TRANSPORT); |
540 | peer, | ||
541 | GST_CONNECTIONPOOL_SERVICE_TRANSPORT); | ||
542 | return NULL; | 533 | return NULL; |
543 | } | 534 | } |
544 | 535 | ||
@@ -555,16 +546,15 @@ opstart_get_handle_transport (void *cls) | |||
555 | struct PooledConnection *entry = cls; | 546 | struct PooledConnection *entry = cls; |
556 | 547 | ||
557 | GNUNET_assert (NULL != entry); | 548 | GNUNET_assert (NULL != entry); |
558 | LOG_DEBUG ("Opening a transport connection to peer %u\n", | 549 | LOG_DEBUG ("Opening a transport connection to peer %u\n", entry->index); |
559 | entry->index); | ||
560 | entry->handle_transport = | 550 | entry->handle_transport = |
561 | GNUNET_TRANSPORT_core_connect (entry->cfg, | 551 | GNUNET_TRANSPORT_core_connect (entry->cfg, |
562 | NULL, | 552 | NULL, |
563 | NULL, | 553 | NULL, |
564 | entry, | 554 | entry, |
565 | &transport_peer_connect_notify_cb, | 555 | &transport_peer_connect_notify_cb, |
566 | NULL, | 556 | NULL, |
567 | NULL); | 557 | NULL); |
568 | if (NULL == entry->handle_transport) | 558 | if (NULL == entry->handle_transport) |
569 | { | 559 | { |
570 | GNUNET_break (0); | 560 | GNUNET_break (0); |
@@ -610,14 +600,12 @@ oprelease_get_handle_transport (void *cls) | |||
610 | */ | 600 | */ |
611 | static void * | 601 | static void * |
612 | core_peer_connect_cb (void *cls, | 602 | core_peer_connect_cb (void *cls, |
613 | const struct GNUNET_PeerIdentity *peer, | 603 | const struct GNUNET_PeerIdentity *peer, |
614 | struct GNUNET_MQ_Handle *mq) | 604 | struct GNUNET_MQ_Handle *mq) |
615 | { | 605 | { |
616 | struct PooledConnection *entry = cls; | 606 | struct PooledConnection *entry = cls; |
617 | 607 | ||
618 | peer_connect_notify_cb (entry, | 608 | peer_connect_notify_cb (entry, peer, GST_CONNECTIONPOOL_SERVICE_CORE); |
619 | peer, | ||
620 | GST_CONNECTIONPOOL_SERVICE_CORE); | ||
621 | return (void *) peer; | 609 | return (void *) peer; |
622 | } | 610 | } |
623 | 611 | ||
@@ -635,8 +623,7 @@ core_peer_connect_cb (void *cls, | |||
635 | * @param my_identity ID of this peer, NULL if we failed | 623 | * @param my_identity ID of this peer, NULL if we failed |
636 | */ | 624 | */ |
637 | static void | 625 | static void |
638 | core_startup_cb (void *cls, | 626 | core_startup_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) |
639 | const struct GNUNET_PeerIdentity *my_identity) | ||
640 | { | 627 | { |
641 | struct PooledConnection *entry = cls; | 628 | struct PooledConnection *entry = cls; |
642 | 629 | ||
@@ -672,15 +659,14 @@ opstart_get_handle_core (void *cls) | |||
672 | struct PooledConnection *entry = cls; | 659 | struct PooledConnection *entry = cls; |
673 | 660 | ||
674 | GNUNET_assert (NULL != entry); | 661 | GNUNET_assert (NULL != entry); |
675 | LOG_DEBUG ("Opening a CORE connection to peer %u\n", | 662 | LOG_DEBUG ("Opening a CORE connection to peer %u\n", entry->index); |
676 | entry->index); | 663 | entry->handle_core = |
677 | entry->handle_core | 664 | GNUNET_CORE_connect (entry->cfg, |
678 | = GNUNET_CORE_connect (entry->cfg, | 665 | entry, /* closure */ |
679 | entry, /* closure */ | 666 | &core_startup_cb, /* core startup notify */ |
680 | &core_startup_cb, /* core startup notify */ | 667 | &core_peer_connect_cb, /* peer connect notify */ |
681 | &core_peer_connect_cb, /* peer connect notify */ | 668 | NULL, /* peer disconnect notify */ |
682 | NULL, /* peer disconnect notify */ | 669 | NULL); |
683 | NULL); | ||
684 | } | 670 | } |
685 | 671 | ||
686 | 672 | ||
@@ -715,8 +701,7 @@ opstart_get_handle_ats_connectivity (void *cls) | |||
715 | { | 701 | { |
716 | struct PooledConnection *entry = cls; | 702 | struct PooledConnection *entry = cls; |
717 | 703 | ||
718 | entry->handle_ats_connectivity = | 704 | entry->handle_ats_connectivity = GNUNET_ATS_connectivity_init (entry->cfg); |
719 | GNUNET_ATS_connectivity_init (entry->cfg); | ||
720 | } | 705 | } |
721 | 706 | ||
722 | 707 | ||
@@ -749,9 +734,7 @@ oprelease_get_handle_ats_connectivity (void *cls) | |||
749 | * #GNUNET_NO if not. | 734 | * #GNUNET_NO if not. |
750 | */ | 735 | */ |
751 | static int | 736 | static int |
752 | cleanup_iterator (void *cls, | 737 | cleanup_iterator (void *cls, uint32_t key, void *value) |
753 | uint32_t key, | ||
754 | void *value) | ||
755 | { | 738 | { |
756 | struct PooledConnection *entry = value; | 739 | struct PooledConnection *entry = value; |
757 | 740 | ||
@@ -789,10 +772,9 @@ GST_connection_pool_destroy () | |||
789 | 772 | ||
790 | if (NULL != map) | 773 | if (NULL != map) |
791 | { | 774 | { |
792 | GNUNET_assert (GNUNET_SYSERR != | 775 | GNUNET_assert ( |
793 | GNUNET_CONTAINER_multihashmap32_iterate (map, | 776 | GNUNET_SYSERR != |
794 | &cleanup_iterator, | 777 | GNUNET_CONTAINER_multihashmap32_iterate (map, &cleanup_iterator, NULL)); |
795 | NULL)); | ||
796 | GNUNET_CONTAINER_multihashmap32_destroy (map); | 778 | GNUNET_CONTAINER_multihashmap32_destroy (map); |
797 | map = NULL; | 779 | map = NULL; |
798 | } | 780 | } |
@@ -817,9 +799,9 @@ GST_connection_pool_destroy () | |||
817 | * @note @a connect_notify_cb will not be called if @a target is | 799 | * @note @a connect_notify_cb will not be called if @a target is |
818 | * already connected @a service level. Use | 800 | * already connected @a service level. Use |
819 | * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the | 801 | * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the |
820 | * respective @a service's API to check if the target peer is already connected or | 802 | * respective @a service's API to check if the target peer is already connected |
821 | * not. @a connect_notify_cb will be called only once or never (in case @a target | 803 | * or not. @a connect_notify_cb will be called only once or never (in case @a |
822 | * cannot be connected or is already connected). | 804 | * target cannot be connected or is already connected). |
823 | * | 805 | * |
824 | * @param peer_id the index of the peer | 806 | * @param peer_id the index of the peer |
825 | * @param cfg the configuration with which the transport handle has to be | 807 | * @param cfg the configuration with which the transport handle has to be |
@@ -828,7 +810,8 @@ GST_connection_pool_destroy () | |||
828 | * @param cb the callback to notify when the transport handle is available | 810 | * @param cb the callback to notify when the transport handle is available |
829 | * @param cb_cls the closure for @a cb | 811 | * @param cb_cls the closure for @a cb |
830 | * @param target the peer identify of the peer whose connection to our TRANSPORT | 812 | * @param target the peer identify of the peer whose connection to our TRANSPORT |
831 | * subsystem will be notified through the @a connect_notify_cb. Can be NULL | 813 | * subsystem will be notified through the @a connect_notify_cb. Can be |
814 | * NULL | ||
832 | * @param connect_notify_cb the callback to call when the @a target peer is | 815 | * @param connect_notify_cb the callback to call when the @a target peer is |
833 | * connected. This callback will only be called once or never again (in | 816 | * connected. This callback will only be called once or never again (in |
834 | * case the target peer cannot be connected). Can be NULL | 817 | * case the target peer cannot be connected). Can be NULL |
@@ -837,14 +820,15 @@ GST_connection_pool_destroy () | |||
837 | * longer being used | 820 | * longer being used |
838 | */ | 821 | */ |
839 | struct GST_ConnectionPool_GetHandle * | 822 | struct GST_ConnectionPool_GetHandle * |
840 | GST_connection_pool_get_handle (unsigned int peer_id, | 823 | GST_connection_pool_get_handle ( |
841 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 824 | unsigned int peer_id, |
842 | enum GST_ConnectionPool_Service service, | 825 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
843 | GST_connection_pool_connection_ready_cb cb, | 826 | enum GST_ConnectionPool_Service service, |
844 | void *cb_cls, | 827 | GST_connection_pool_connection_ready_cb cb, |
845 | const struct GNUNET_PeerIdentity *target, | 828 | void *cb_cls, |
846 | GST_connection_pool_peer_connect_notify connect_notify_cb, | 829 | const struct GNUNET_PeerIdentity *target, |
847 | void *connect_notify_cb_cls) | 830 | GST_connection_pool_peer_connect_notify connect_notify_cb, |
831 | void *connect_notify_cb_cls) | ||
848 | { | 832 | { |
849 | struct GST_ConnectionPool_GetHandle *gh; | 833 | struct GST_ConnectionPool_GetHandle *gh; |
850 | struct PooledConnection *entry; | 834 | struct PooledConnection *entry; |
@@ -871,20 +855,17 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
871 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | 855 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: |
872 | handle = entry->handle_transport; | 856 | handle = entry->handle_transport; |
873 | if (NULL != handle) | 857 | if (NULL != handle) |
874 | LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", | 858 | LOG_DEBUG ("Found TRANSPORT handle for peer %u\n", entry->index); |
875 | entry->index); | ||
876 | break; | 859 | break; |
877 | case GST_CONNECTIONPOOL_SERVICE_CORE: | 860 | case GST_CONNECTIONPOOL_SERVICE_CORE: |
878 | handle = entry->handle_core; | 861 | handle = entry->handle_core; |
879 | if (NULL != handle) | 862 | if (NULL != handle) |
880 | LOG_DEBUG ("Found CORE handle for peer %u\n", | 863 | LOG_DEBUG ("Found CORE handle for peer %u\n", entry->index); |
881 | entry->index); | ||
882 | break; | 864 | break; |
883 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | 865 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: |
884 | handle = entry->handle_ats_connectivity; | 866 | handle = entry->handle_ats_connectivity; |
885 | if (NULL != handle) | 867 | if (NULL != handle) |
886 | LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", | 868 | LOG_DEBUG ("Found ATS CONNECTIVITY handle for peer %u\n", entry->index); |
887 | entry->index); | ||
888 | break; | 869 | break; |
889 | } | 870 | } |
890 | } | 871 | } |
@@ -892,14 +873,15 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
892 | { | 873 | { |
893 | entry = GNUNET_new (struct PooledConnection); | 874 | entry = GNUNET_new (struct PooledConnection); |
894 | entry->index = peer_id32; | 875 | entry->index = peer_id32; |
895 | if ((NULL != map) | 876 | if ((NULL != map) && |
896 | && (GNUNET_CONTAINER_multihashmap32_size (map) < max_size)) | 877 | (GNUNET_CONTAINER_multihashmap32_size (map) < max_size)) |
897 | { | 878 | { |
898 | GNUNET_assert (GNUNET_OK == | 879 | GNUNET_assert (GNUNET_OK == |
899 | GNUNET_CONTAINER_multihashmap32_put (map, | 880 | GNUNET_CONTAINER_multihashmap32_put ( |
900 | entry->index, | 881 | map, |
901 | entry, | 882 | entry->index, |
902 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 883 | entry, |
884 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | ||
903 | entry->in_pool = GNUNET_YES; | 885 | entry->in_pool = GNUNET_YES; |
904 | } | 886 | } |
905 | else | 887 | else |
@@ -919,16 +901,14 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
919 | gh->connect_notify_cb = connect_notify_cb; | 901 | gh->connect_notify_cb = connect_notify_cb; |
920 | gh->connect_notify_cb_cls = connect_notify_cb_cls; | 902 | gh->connect_notify_cb_cls = connect_notify_cb_cls; |
921 | gh->service = service; | 903 | gh->service = service; |
922 | GNUNET_CONTAINER_DLL_insert (entry->head_waiting, | 904 | GNUNET_CONTAINER_DLL_insert (entry->head_waiting, entry->tail_waiting, gh); |
923 | entry->tail_waiting, | ||
924 | gh); | ||
925 | if (NULL != handle) | 905 | if (NULL != handle) |
926 | { | 906 | { |
927 | if (NULL == entry->notify_task) | 907 | if (NULL == entry->notify_task) |
928 | { | 908 | { |
929 | if (NULL != search_waiting (entry, entry->head_waiting)) | 909 | if (NULL != search_waiting (entry, entry->head_waiting)) |
930 | entry->notify_task = GNUNET_SCHEDULER_add_now (&connection_ready, | 910 | entry->notify_task = |
931 | entry); | 911 | GNUNET_SCHEDULER_add_now (&connection_ready, entry); |
932 | } | 912 | } |
933 | return gh; | 913 | return gh; |
934 | } | 914 | } |
@@ -937,7 +917,7 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
937 | { | 917 | { |
938 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: | 918 | case GST_CONNECTIONPOOL_SERVICE_TRANSPORT: |
939 | if (NULL != entry->op_transport) | 919 | if (NULL != entry->op_transport) |
940 | return gh; /* Operation pending */ | 920 | return gh; /* Operation pending */ |
941 | op = GNUNET_TESTBED_operation_create_ (entry, | 921 | op = GNUNET_TESTBED_operation_create_ (entry, |
942 | &opstart_get_handle_transport, | 922 | &opstart_get_handle_transport, |
943 | &oprelease_get_handle_transport); | 923 | &oprelease_get_handle_transport); |
@@ -945,7 +925,7 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
945 | break; | 925 | break; |
946 | case GST_CONNECTIONPOOL_SERVICE_CORE: | 926 | case GST_CONNECTIONPOOL_SERVICE_CORE: |
947 | if (NULL != entry->op_core) | 927 | if (NULL != entry->op_core) |
948 | return gh; /* Operation pending */ | 928 | return gh; /* Operation pending */ |
949 | op = GNUNET_TESTBED_operation_create_ (entry, | 929 | op = GNUNET_TESTBED_operation_create_ (entry, |
950 | &opstart_get_handle_core, | 930 | &opstart_get_handle_core, |
951 | &oprelease_get_handle_core); | 931 | &oprelease_get_handle_core); |
@@ -953,15 +933,15 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
953 | break; | 933 | break; |
954 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: | 934 | case GST_CONNECTIONPOOL_SERVICE_ATS_CONNECTIVITY: |
955 | if (NULL != entry->op_ats_connectivity) | 935 | if (NULL != entry->op_ats_connectivity) |
956 | return gh; /* Operation pending */ | 936 | return gh; /* Operation pending */ |
957 | op = GNUNET_TESTBED_operation_create_ (entry, | 937 | op = |
958 | &opstart_get_handle_ats_connectivity, | 938 | GNUNET_TESTBED_operation_create_ (entry, |
959 | &oprelease_get_handle_ats_connectivity); | 939 | &opstart_get_handle_ats_connectivity, |
940 | &oprelease_get_handle_ats_connectivity); | ||
960 | entry->op_ats_connectivity = op; | 941 | entry->op_ats_connectivity = op; |
961 | break; | 942 | break; |
962 | } | 943 | } |
963 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, | 944 | GNUNET_TESTBED_operation_queue_insert_ (GST_opq_openfds, op); |
964 | op); | ||
965 | GNUNET_TESTBED_operation_begin_wait_ (op); | 945 | GNUNET_TESTBED_operation_begin_wait_ (op); |
966 | return gh; | 946 | return gh; |
967 | } | 947 | } |
@@ -973,9 +953,9 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
973 | * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If | 953 | * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If |
974 | * no other objects are using the connection and the connection pool is not full | 954 | * no other objects are using the connection and the connection pool is not full |
975 | * then it is placed in a LRU queue. If the connection pool is full, then | 955 | * then it is placed in a LRU queue. If the connection pool is full, then |
976 | * connections from the LRU queue are evicted and closed to create place for this | 956 | * connections from the LRU queue are evicted and closed to create place for |
977 | * connection. If the connection pool if full and the LRU queue is empty, then | 957 | * this connection. If the connection pool if full and the LRU queue is empty, |
978 | * the connection is closed. | 958 | * then the connection is closed. |
979 | * | 959 | * |
980 | * @param gh the handle | 960 | * @param gh the handle |
981 | */ | 961 | */ |
@@ -989,14 +969,13 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh) | |||
989 | entry = gh->entry; | 969 | entry = gh->entry; |
990 | LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n", | 970 | LOG_DEBUG ("Cleaning up get handle %p for service %u, peer %u\n", |
991 | gh, | 971 | gh, |
992 | gh->service, entry->index); | 972 | gh->service, |
973 | entry->index); | ||
993 | if (! gh->connection_ready_called) | 974 | if (! gh->connection_ready_called) |
994 | { | 975 | { |
995 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, | 976 | GNUNET_CONTAINER_DLL_remove (entry->head_waiting, entry->tail_waiting, gh); |
996 | entry->tail_waiting, | 977 | if ((NULL == search_waiting (entry, entry->head_waiting)) && |
997 | gh); | 978 | (NULL != entry->notify_task)) |
998 | if ( (NULL == search_waiting (entry, entry->head_waiting)) && | ||
999 | (NULL != entry->notify_task) ) | ||
1000 | { | 979 | { |
1001 | GNUNET_SCHEDULER_cancel (entry->notify_task); | 980 | GNUNET_SCHEDULER_cancel (entry->notify_task); |
1002 | entry->notify_task = NULL; | 981 | entry->notify_task = NULL; |
@@ -1004,22 +983,18 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh) | |||
1004 | } | 983 | } |
1005 | if (gh->notify_waiting) | 984 | if (gh->notify_waiting) |
1006 | { | 985 | { |
1007 | GNUNET_CONTAINER_DLL_remove (entry->head_notify, | 986 | GNUNET_CONTAINER_DLL_remove (entry->head_notify, entry->tail_notify, gh); |
1008 | entry->tail_notify, | ||
1009 | gh); | ||
1010 | gh->notify_waiting = 0; | 987 | gh->notify_waiting = 0; |
1011 | } | 988 | } |
1012 | GNUNET_free (gh); | 989 | GNUNET_free (gh); |
1013 | gh = NULL; | 990 | gh = NULL; |
1014 | GNUNET_assert (! entry->in_lru); | 991 | GNUNET_assert (! entry->in_lru); |
1015 | if (! entry->in_pool) | 992 | if (! entry->in_pool) |
1016 | GNUNET_CONTAINER_DLL_remove (head_not_pooled, | 993 | GNUNET_CONTAINER_DLL_remove (head_not_pooled, tail_not_pooled, entry); |
1017 | tail_not_pooled, | ||
1018 | entry); | ||
1019 | if (NULL != map) | 994 | if (NULL != map) |
1020 | { | 995 | { |
1021 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_contains (map, | 996 | if (GNUNET_YES == |
1022 | entry->index)) | 997 | GNUNET_CONTAINER_multihashmap32_contains (map, entry->index)) |
1023 | goto unallocate; | 998 | goto unallocate; |
1024 | if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size) | 999 | if (GNUNET_CONTAINER_multihashmap32_size (map) == max_size) |
1025 | { | 1000 | { |
@@ -1028,14 +1003,15 @@ GST_connection_pool_get_handle_done (struct GST_ConnectionPool_GetHandle *gh) | |||
1028 | destroy_pooled_connection (head_lru); | 1003 | destroy_pooled_connection (head_lru); |
1029 | } | 1004 | } |
1030 | GNUNET_assert (GNUNET_OK == | 1005 | GNUNET_assert (GNUNET_OK == |
1031 | GNUNET_CONTAINER_multihashmap32_put (map, | 1006 | GNUNET_CONTAINER_multihashmap32_put ( |
1032 | entry->index, | 1007 | map, |
1033 | entry, | 1008 | entry->index, |
1034 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1009 | entry, |
1010 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1035 | entry->in_pool = GNUNET_YES; | 1011 | entry->in_pool = GNUNET_YES; |
1036 | } | 1012 | } |
1037 | 1013 | ||
1038 | unallocate: | 1014 | unallocate: |
1039 | GNUNET_assert (0 < entry->demand); | 1015 | GNUNET_assert (0 < entry->demand); |
1040 | entry->demand--; | 1016 | entry->demand--; |
1041 | if (0 != entry->demand) | 1017 | if (0 != entry->demand) |
diff --git a/src/testbed/gnunet-service-testbed_connectionpool.h b/src/testbed/gnunet-service-testbed_connectionpool.h index ca4ea22ce..558918c30 100644 --- a/src/testbed/gnunet-service-testbed_connectionpool.h +++ b/src/testbed/gnunet-service-testbed_connectionpool.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "gnunet_ats_service.h" | 26 | #include "gnunet_ats_service.h" |
27 | #include "gnunet_core_service.h" | 27 | #include "gnunet_core_service.h" |
28 | #include "gnunet_transport_core_service.h" | 28 | #include "gnunet_transport_service.h" |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The request handle for obtaining a pooled connection | 31 | * The request handle for obtaining a pooled connection |
@@ -87,13 +87,13 @@ GST_connection_pool_destroy (void); | |||
87 | * cases, its value being NULL means that CORE connection has failed. | 87 | * cases, its value being NULL means that CORE connection has failed. |
88 | * @param cfg configuration of the peer | 88 | * @param cfg configuration of the peer |
89 | */ | 89 | */ |
90 | typedef void | 90 | typedef void (*GST_connection_pool_connection_ready_cb) ( |
91 | (*GST_connection_pool_connection_ready_cb) (void *cls, | 91 | void *cls, |
92 | struct GNUNET_CORE_Handle *ch, | 92 | struct GNUNET_CORE_Handle *ch, |
93 | struct GNUNET_TRANSPORT_CoreHandle *th, | 93 | struct GNUNET_TRANSPORT_CoreHandle *th, |
94 | struct GNUNET_ATS_ConnectivityHandle *ac, | 94 | struct GNUNET_ATS_ConnectivityHandle *ac, |
95 | const struct GNUNET_PeerIdentity *peer_id, | 95 | const struct GNUNET_PeerIdentity *peer_id, |
96 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 96 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
97 | 97 | ||
98 | 98 | ||
99 | /** | 99 | /** |
@@ -104,9 +104,9 @@ typedef void | |||
104 | * callback | 104 | * callback |
105 | * @param target the peer identity of the target peer | 105 | * @param target the peer identity of the target peer |
106 | */ | 106 | */ |
107 | typedef void | 107 | typedef void (*GST_connection_pool_peer_connect_notify) ( |
108 | (*GST_connection_pool_peer_connect_notify) (void *cls, | 108 | void *cls, |
109 | const struct GNUNET_PeerIdentity *target); | 109 | const struct GNUNET_PeerIdentity *target); |
110 | 110 | ||
111 | 111 | ||
112 | /** | 112 | /** |
@@ -121,9 +121,9 @@ typedef void | |||
121 | * @note @a connect_notify_cb will not be called if @a target is | 121 | * @note @a connect_notify_cb will not be called if @a target is |
122 | * already connected @a service level. Use | 122 | * already connected @a service level. Use |
123 | * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the | 123 | * GNUNET_TRANSPORT_check_peer_connected() or a similar function from the |
124 | * respective @a service's API to check if the target peer is already connected or | 124 | * respective @a service's API to check if the target peer is already connected |
125 | * not. @a connect_notify_cb will be called only once or never (in case @a target | 125 | * or not. @a connect_notify_cb will be called only once or never (in case @a |
126 | * cannot be connected or is already connected). | 126 | * target cannot be connected or is already connected). |
127 | * | 127 | * |
128 | * @param peer_id the index of the peer | 128 | * @param peer_id the index of the peer |
129 | * @param cfg the configuration with which the transport handle has to be | 129 | * @param cfg the configuration with which the transport handle has to be |
@@ -132,7 +132,8 @@ typedef void | |||
132 | * @param cb the callback to notify when the transport handle is available | 132 | * @param cb the callback to notify when the transport handle is available |
133 | * @param cb_cls the closure for @a cb | 133 | * @param cb_cls the closure for @a cb |
134 | * @param target the peer identify of the peer whose connection to our TRANSPORT | 134 | * @param target the peer identify of the peer whose connection to our TRANSPORT |
135 | * subsystem will be notified through the @a connect_notify_cb. Can be NULL | 135 | * subsystem will be notified through the @a connect_notify_cb. Can be |
136 | * NULL | ||
136 | * @param connect_notify_cb the callback to call when the @a target peer is | 137 | * @param connect_notify_cb the callback to call when the @a target peer is |
137 | * connected. This callback will only be called once or never again (in | 138 | * connected. This callback will only be called once or never again (in |
138 | * case the target peer cannot be connected). Can be NULL | 139 | * case the target peer cannot be connected). Can be NULL |
@@ -141,14 +142,15 @@ typedef void | |||
141 | * longer being used | 142 | * longer being used |
142 | */ | 143 | */ |
143 | struct GST_ConnectionPool_GetHandle * | 144 | struct GST_ConnectionPool_GetHandle * |
144 | GST_connection_pool_get_handle (unsigned int peer_id, | 145 | GST_connection_pool_get_handle ( |
145 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 146 | unsigned int peer_id, |
146 | enum GST_ConnectionPool_Service service, | 147 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
147 | GST_connection_pool_connection_ready_cb cb, | 148 | enum GST_ConnectionPool_Service service, |
148 | void *cb_cls, | 149 | GST_connection_pool_connection_ready_cb cb, |
149 | const struct GNUNET_PeerIdentity *target, | 150 | void *cb_cls, |
150 | GST_connection_pool_peer_connect_notify connect_notify_cb, | 151 | const struct GNUNET_PeerIdentity *target, |
151 | void *connect_notify_cb_cls); | 152 | GST_connection_pool_peer_connect_notify connect_notify_cb, |
153 | void *connect_notify_cb_cls); | ||
152 | 154 | ||
153 | 155 | ||
154 | /** | 156 | /** |
@@ -157,9 +159,9 @@ GST_connection_pool_get_handle (unsigned int peer_id, | |||
157 | * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If | 159 | * #GST_ConnectionPool_GetHandle objects, it is left in the connection pool. If |
158 | * no other objects are using the connection and the connection pool is not full | 160 | * no other objects are using the connection and the connection pool is not full |
159 | * then it is placed in a LRU queue. If the connection pool is full, then | 161 | * then it is placed in a LRU queue. If the connection pool is full, then |
160 | * connections from the LRU queue are evicted and closed to create place for this | 162 | * connections from the LRU queue are evicted and closed to create place for |
161 | * connection. If the connection pool if full and the LRU queue is empty, then | 163 | * this connection. If the connection pool if full and the LRU queue is empty, |
162 | * the connection is closed. | 164 | * then the connection is closed. |
163 | * | 165 | * |
164 | * @param gh the handle | 166 | * @param gh the handle |
165 | */ | 167 | */ |
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index c2922dd7e..825d45522 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -24,6 +24,11 @@ | |||
24 | * | 24 | * |
25 | * TODO: | 25 | * TODO: |
26 | * Implement next: | 26 | * Implement next: |
27 | * - complete flow control push back from CORE via TRANSPORT to communicators: | ||
28 | * + resume communicators in handle_client_recv_ok (see FIXME) | ||
29 | * + count transmissions to CORE and suspend communicators if window is full | ||
30 | * - check flow control push back from TRANSPROT to CORE: | ||
31 | * + check when to send ACKs | ||
27 | * - change transport-core API to provide proper flow control in both | 32 | * - change transport-core API to provide proper flow control in both |
28 | * directions, allow multiple messages per peer simultaneously (tag | 33 | * directions, allow multiple messages per peer simultaneously (tag |
29 | * confirmations with unique message ID), and replace quota-out with | 34 | * confirmations with unique message ID), and replace quota-out with |
@@ -114,6 +119,16 @@ | |||
114 | #define MAX_DV_DISCOVERY_SELECTION 16 | 119 | #define MAX_DV_DISCOVERY_SELECTION 16 |
115 | 120 | ||
116 | /** | 121 | /** |
122 | * Window size. How many messages to the same target do we pass | ||
123 | * to CORE without a RECV_OK in between? Small values limit | ||
124 | * thoughput, large values will increase latency. | ||
125 | * | ||
126 | * FIXME-OPTIMIZE: find out what good values are experimentally, | ||
127 | * maybe set adaptively (i.e. to observed available bandwidth). | ||
128 | */ | ||
129 | #define RECV_WINDOW_SIZE 4 | ||
130 | |||
131 | /** | ||
117 | * Minimum number of hops we should forward DV learn messages | 132 | * Minimum number of hops we should forward DV learn messages |
118 | * even if they are NOT useful for us in hope of looping | 133 | * even if they are NOT useful for us in hope of looping |
119 | * back to the initiator? | 134 | * back to the initiator? |
@@ -1100,6 +1115,48 @@ struct PendingMessage; | |||
1100 | */ | 1115 | */ |
1101 | struct DistanceVectorHop; | 1116 | struct DistanceVectorHop; |
1102 | 1117 | ||
1118 | /** | ||
1119 | * A virtual link is another reachable peer that is known to CORE. It | ||
1120 | * can be either a `struct Neighbour` with at least one confirmed | ||
1121 | * `struct Queue`, or a `struct DistanceVector` with at least one | ||
1122 | * confirmed `struct DistanceVectorHop`. With a virtual link we track | ||
1123 | * data that is per neighbour that is not specific to how the | ||
1124 | * connectivity is established. | ||
1125 | */ | ||
1126 | struct VirtualLink | ||
1127 | { | ||
1128 | /** | ||
1129 | * Identity of the peer at the other end of the link. | ||
1130 | */ | ||
1131 | struct GNUNET_PeerIdentity target; | ||
1132 | |||
1133 | /** | ||
1134 | * Task scheduled to possibly notfiy core that this peer is no | ||
1135 | * longer counting as confirmed. Runs the #core_visibility_check(), | ||
1136 | * which checks that some DV-path or a queue exists that is still | ||
1137 | * considered confirmed. | ||
1138 | */ | ||
1139 | struct GNUNET_SCHEDULER_Task *visibility_task; | ||
1140 | |||
1141 | /** | ||
1142 | * Neighbour used by this virtual link, NULL if @e dv is used. | ||
1143 | */ | ||
1144 | struct Neighbour *n; | ||
1145 | |||
1146 | /** | ||
1147 | * Distance vector used by this virtual link, NULL if @e n is used. | ||
1148 | */ | ||
1149 | struct DistanceVector *dv; | ||
1150 | |||
1151 | /** | ||
1152 | * How many more messages can we send to core before we exhaust | ||
1153 | * the receive window of CORE for this peer? If this hits zero, | ||
1154 | * we must tell communicators to stop providing us more messages | ||
1155 | * for this peer. | ||
1156 | */ | ||
1157 | unsigned int core_recv_window; | ||
1158 | }; | ||
1159 | |||
1103 | 1160 | ||
1104 | /** | 1161 | /** |
1105 | * Data structure kept when we are waiting for an acknowledgement. | 1162 | * Data structure kept when we are waiting for an acknowledgement. |
@@ -1316,31 +1373,10 @@ struct DistanceVector | |||
1316 | struct GNUNET_SCHEDULER_Task *timeout_task; | 1373 | struct GNUNET_SCHEDULER_Task *timeout_task; |
1317 | 1374 | ||
1318 | /** | 1375 | /** |
1319 | * Task scheduled to possibly notfiy core that this queue is no longer | 1376 | * Do we have a confirmed working queue and are thus visible to |
1320 | * counting as confirmed. Runs the #core_queue_visibility_check(). | 1377 | * CORE? If so, this is the virtual link, otherwise NULL. |
1321 | */ | ||
1322 | struct GNUNET_SCHEDULER_Task *visibility_task; | ||
1323 | |||
1324 | /** | ||
1325 | * Quota at which CORE is allowed to transmit to this peer | ||
1326 | * (note that the value CORE should actually be told is this | ||
1327 | * value plus the respective value in `struct Neighbour`). | ||
1328 | * Should match the sum of the quotas of all of the paths. | ||
1329 | * | ||
1330 | * FIXME: not yet set, tricky to get right given multiple paths, | ||
1331 | * many of which may be inactive! (=> Idea: measure???) | ||
1332 | * FIXME: how do we set this value initially when we tell CORE? | ||
1333 | * Options: start at a minimum value or at literally zero? | ||
1334 | * (=> Current thought: clean would be zero!) | ||
1335 | */ | ||
1336 | struct GNUNET_BANDWIDTH_Value32NBO quota_out; | ||
1337 | |||
1338 | /** | ||
1339 | * Is one of the DV paths in this struct 'confirmed' and thus | ||
1340 | * the cause for CORE to see this peer as connected? (Note that | ||
1341 | * the same may apply to a `struct Neighbour` at the same time.) | ||
1342 | */ | 1378 | */ |
1343 | int core_visible; | 1379 | struct VirtualLink *link; |
1344 | }; | 1380 | }; |
1345 | 1381 | ||
1346 | 1382 | ||
@@ -1451,12 +1487,6 @@ struct Queue | |||
1451 | struct GNUNET_SCHEDULER_Task *transmit_task; | 1487 | struct GNUNET_SCHEDULER_Task *transmit_task; |
1452 | 1488 | ||
1453 | /** | 1489 | /** |
1454 | * Task scheduled to possibly notfiy core that this queue is no longer | ||
1455 | * counting as confirmed. Runs the #core_queue_visibility_check(). | ||
1456 | */ | ||
1457 | struct GNUNET_SCHEDULER_Task *visibility_task; | ||
1458 | |||
1459 | /** | ||
1460 | * How long do *we* consider this @e address to be valid? In the past or | 1490 | * How long do *we* consider this @e address to be valid? In the past or |
1461 | * zero if we have not yet validated it. Can be updated based on | 1491 | * zero if we have not yet validated it. Can be updated based on |
1462 | * challenge-response validations (via address validation logic), or when we | 1492 | * challenge-response validations (via address validation logic), or when we |
@@ -1643,11 +1673,6 @@ struct Neighbour | |||
1643 | struct Queue *queue_tail; | 1673 | struct Queue *queue_tail; |
1644 | 1674 | ||
1645 | /** | 1675 | /** |
1646 | * Task run to cleanup pending messages that have exceeded their timeout. | ||
1647 | */ | ||
1648 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
1649 | |||
1650 | /** | ||
1651 | * Handle for an operation to fetch @e last_dv_learn_monotime information from | 1676 | * Handle for an operation to fetch @e last_dv_learn_monotime information from |
1652 | * the PEERSTORE, or NULL. | 1677 | * the PEERSTORE, or NULL. |
1653 | */ | 1678 | */ |
@@ -1660,18 +1685,10 @@ struct Neighbour | |||
1660 | struct GNUNET_PEERSTORE_StoreContext *sc; | 1685 | struct GNUNET_PEERSTORE_StoreContext *sc; |
1661 | 1686 | ||
1662 | /** | 1687 | /** |
1663 | * Quota at which CORE is allowed to transmit to this peer | 1688 | * Do we have a confirmed working queue and are thus visible to |
1664 | * (note that the value CORE should actually be told is this | 1689 | * CORE? If so, this is the virtual link, otherwise NULL. |
1665 | * value plus the respective value in `struct DistanceVector`). | ||
1666 | * Should match the sum of the quotas of all of the queues. | ||
1667 | * | ||
1668 | * FIXME: not yet set, tricky to get right given multiple queues! | ||
1669 | * (=> Idea: measure???) | ||
1670 | * FIXME: how do we set this value initially when we tell CORE? | ||
1671 | * Options: start at a minimum value or at literally zero? | ||
1672 | * (=> Current thought: clean would be zero!) | ||
1673 | */ | 1690 | */ |
1674 | struct GNUNET_BANDWIDTH_Value32NBO quota_out; | 1691 | struct VirtualLink *link; |
1675 | 1692 | ||
1676 | /** | 1693 | /** |
1677 | * Latest DVLearn monotonic time seen from this peer. Initialized only | 1694 | * Latest DVLearn monotonic time seen from this peer. Initialized only |
@@ -1680,17 +1697,6 @@ struct Neighbour | |||
1680 | struct GNUNET_TIME_Absolute last_dv_learn_monotime; | 1697 | struct GNUNET_TIME_Absolute last_dv_learn_monotime; |
1681 | 1698 | ||
1682 | /** | 1699 | /** |
1683 | * What is the earliest timeout of any message in @e pending_msg_tail? | ||
1684 | */ | ||
1685 | struct GNUNET_TIME_Absolute earliest_timeout; | ||
1686 | |||
1687 | /** | ||
1688 | * Do we have a confirmed working queue and are thus visible to | ||
1689 | * CORE? | ||
1690 | */ | ||
1691 | int core_visible; | ||
1692 | |||
1693 | /** | ||
1694 | * Do we have the lastest value for @e last_dv_learn_monotime from | 1700 | * Do we have the lastest value for @e last_dv_learn_monotime from |
1695 | * PEERSTORE yet, or are we still waiting for a reply of PEERSTORE? | 1701 | * PEERSTORE yet, or are we still waiting for a reply of PEERSTORE? |
1696 | */ | 1702 | */ |
@@ -2417,6 +2423,12 @@ static struct GNUNET_CONTAINER_MultiPeerMap *dv_routes; | |||
2417 | static struct GNUNET_CONTAINER_MultiPeerMap *validation_map; | 2423 | static struct GNUNET_CONTAINER_MultiPeerMap *validation_map; |
2418 | 2424 | ||
2419 | /** | 2425 | /** |
2426 | * Map from PIDs to `struct VirtualLink` entries describing | ||
2427 | * links CORE knows to exist. | ||
2428 | */ | ||
2429 | static struct GNUNET_CONTAINER_MultiPeerMap *links; | ||
2430 | |||
2431 | /** | ||
2420 | * Map from challenges to `struct LearnLaunchEntry` values. | 2432 | * Map from challenges to `struct LearnLaunchEntry` values. |
2421 | */ | 2433 | */ |
2422 | static struct GNUNET_CONTAINER_MultiShortmap *dvlearn_map; | 2434 | static struct GNUNET_CONTAINER_MultiShortmap *dvlearn_map; |
@@ -2564,6 +2576,26 @@ free_ephemeral (struct EphemeralCacheEntry *ece) | |||
2564 | 2576 | ||
2565 | 2577 | ||
2566 | /** | 2578 | /** |
2579 | * Free virtual link. | ||
2580 | * | ||
2581 | * @param vl link data to free | ||
2582 | */ | ||
2583 | static void | ||
2584 | free_virtual_link (struct VirtualLink *vl) | ||
2585 | { | ||
2586 | GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl); | ||
2587 | if (NULL != vl->visibility_task) | ||
2588 | { | ||
2589 | GNUNET_SCHEDULER_cancel (vl->visibility_task); | ||
2590 | vl->visibility_task = NULL; | ||
2591 | } | ||
2592 | GNUNET_break (NULL == vl->n); | ||
2593 | GNUNET_break (NULL == vl->dv); | ||
2594 | GNUNET_free (vl); | ||
2595 | } | ||
2596 | |||
2597 | |||
2598 | /** | ||
2567 | * Free validation state. | 2599 | * Free validation state. |
2568 | * | 2600 | * |
2569 | * @param vs validation state to free | 2601 | * @param vs validation state to free |
@@ -2684,8 +2716,6 @@ free_dv_route (struct DistanceVector *dv) | |||
2684 | GNUNET_assert ( | 2716 | GNUNET_assert ( |
2685 | GNUNET_YES == | 2717 | GNUNET_YES == |
2686 | GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv)); | 2718 | GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv)); |
2687 | if (NULL != dv->visibility_task) | ||
2688 | GNUNET_SCHEDULER_cancel (dv->visibility_task); | ||
2689 | if (NULL != dv->timeout_task) | 2719 | if (NULL != dv->timeout_task) |
2690 | GNUNET_SCHEDULER_cancel (dv->timeout_task); | 2720 | GNUNET_SCHEDULER_cancel (dv->timeout_task); |
2691 | GNUNET_free (dv); | 2721 | GNUNET_free (dv); |
@@ -2873,8 +2903,6 @@ free_neighbour (struct Neighbour *neighbour) | |||
2873 | GNUNET_CONTAINER_multipeermap_remove (neighbours, | 2903 | GNUNET_CONTAINER_multipeermap_remove (neighbours, |
2874 | &neighbour->pid, | 2904 | &neighbour->pid, |
2875 | neighbour)); | 2905 | neighbour)); |
2876 | if (NULL != neighbour->timeout_task) | ||
2877 | GNUNET_SCHEDULER_cancel (neighbour->timeout_task); | ||
2878 | if (NULL != neighbour->reassembly_map) | 2906 | if (NULL != neighbour->reassembly_map) |
2879 | { | 2907 | { |
2880 | GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, | 2908 | GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, |
@@ -2917,19 +2945,16 @@ free_neighbour (struct Neighbour *neighbour) | |||
2917 | * | 2945 | * |
2918 | * @param tc client to inform (must be CORE client) | 2946 | * @param tc client to inform (must be CORE client) |
2919 | * @param pid peer the connection is for | 2947 | * @param pid peer the connection is for |
2920 | * @param quota_out current quota for the peer | ||
2921 | */ | 2948 | */ |
2922 | static void | 2949 | static void |
2923 | core_send_connect_info (struct TransportClient *tc, | 2950 | core_send_connect_info (struct TransportClient *tc, |
2924 | const struct GNUNET_PeerIdentity *pid, | 2951 | const struct GNUNET_PeerIdentity *pid) |
2925 | struct GNUNET_BANDWIDTH_Value32NBO quota_out) | ||
2926 | { | 2952 | { |
2927 | struct GNUNET_MQ_Envelope *env; | 2953 | struct GNUNET_MQ_Envelope *env; |
2928 | struct ConnectInfoMessage *cim; | 2954 | struct ConnectInfoMessage *cim; |
2929 | 2955 | ||
2930 | GNUNET_assert (CT_CORE == tc->type); | 2956 | GNUNET_assert (CT_CORE == tc->type); |
2931 | env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | 2957 | env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
2932 | cim->quota_out = quota_out; | ||
2933 | cim->id = *pid; | 2958 | cim->id = *pid; |
2934 | GNUNET_MQ_send (tc->mq, env); | 2959 | GNUNET_MQ_send (tc->mq, env); |
2935 | } | 2960 | } |
@@ -2939,11 +2964,9 @@ core_send_connect_info (struct TransportClient *tc, | |||
2939 | * Send message to CORE clients that we gained a connection | 2964 | * Send message to CORE clients that we gained a connection |
2940 | * | 2965 | * |
2941 | * @param pid peer the queue was for | 2966 | * @param pid peer the queue was for |
2942 | * @param quota_out current quota for the peer | ||
2943 | */ | 2967 | */ |
2944 | static void | 2968 | static void |
2945 | cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, | 2969 | cores_send_connect_info (const struct GNUNET_PeerIdentity *pid) |
2946 | struct GNUNET_BANDWIDTH_Value32NBO quota_out) | ||
2947 | { | 2970 | { |
2948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2971 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2949 | "Informing CORE clients about connection to %s\n", | 2972 | "Informing CORE clients about connection to %s\n", |
@@ -2952,7 +2975,7 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid, | |||
2952 | { | 2975 | { |
2953 | if (CT_CORE != tc->type) | 2976 | if (CT_CORE != tc->type) |
2954 | continue; | 2977 | continue; |
2955 | core_send_connect_info (tc, pid, quota_out); | 2978 | core_send_connect_info (tc, pid); |
2956 | } | 2979 | } |
2957 | } | 2980 | } |
2958 | 2981 | ||
@@ -3059,13 +3082,43 @@ schedule_transmit_on_queue (struct Queue *queue, int inside_job) | |||
3059 | 3082 | ||
3060 | 3083 | ||
3061 | /** | 3084 | /** |
3062 | * Check whether the CORE visibility of @a n changed. If so, | 3085 | * Task run to check whether the hops of the @a cls still |
3063 | * check whether we need to notify CORE. | 3086 | * are validated, or if we need to core about disconnection. |
3064 | * | 3087 | * |
3065 | * @param n neighbour to perform the check for | 3088 | * @param cls a `struct VirtualLink` |
3066 | */ | 3089 | */ |
3067 | static void | 3090 | static void |
3068 | update_neighbour_core_visibility (struct Neighbour *n); | 3091 | check_link_down (void *cls) |
3092 | { | ||
3093 | struct VirtualLink *vl = cls; | ||
3094 | struct DistanceVector *dv = vl->dv; | ||
3095 | struct Neighbour *n = vl->n; | ||
3096 | struct GNUNET_TIME_Absolute dvh_timeout; | ||
3097 | struct GNUNET_TIME_Absolute q_timeout; | ||
3098 | |||
3099 | vl->visibility_task = NULL; | ||
3100 | dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; | ||
3101 | for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; | ||
3102 | pos = pos->next_dv) | ||
3103 | dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until); | ||
3104 | if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us) | ||
3105 | vl->dv = NULL; | ||
3106 | q_timeout = GNUNET_TIME_UNIT_ZERO_ABS; | ||
3107 | for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) | ||
3108 | q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until); | ||
3109 | if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us) | ||
3110 | vl->n = NULL; | ||
3111 | if ((NULL == vl->n) && (NULL == vl->dv)) | ||
3112 | { | ||
3113 | cores_send_disconnect_info (&dv->target); | ||
3114 | free_virtual_link (vl); | ||
3115 | return; | ||
3116 | } | ||
3117 | vl->visibility_task = | ||
3118 | GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout), | ||
3119 | &check_link_down, | ||
3120 | vl); | ||
3121 | } | ||
3069 | 3122 | ||
3070 | 3123 | ||
3071 | /** | 3124 | /** |
@@ -3083,17 +3136,13 @@ free_queue (struct Queue *queue) | |||
3083 | struct QueueEntry *qe; | 3136 | struct QueueEntry *qe; |
3084 | int maxxed; | 3137 | int maxxed; |
3085 | struct PendingAcknowledgement *pa; | 3138 | struct PendingAcknowledgement *pa; |
3139 | struct VirtualLink *vl; | ||
3086 | 3140 | ||
3087 | if (NULL != queue->transmit_task) | 3141 | if (NULL != queue->transmit_task) |
3088 | { | 3142 | { |
3089 | GNUNET_SCHEDULER_cancel (queue->transmit_task); | 3143 | GNUNET_SCHEDULER_cancel (queue->transmit_task); |
3090 | queue->transmit_task = NULL; | 3144 | queue->transmit_task = NULL; |
3091 | } | 3145 | } |
3092 | if (NULL != queue->visibility_task) | ||
3093 | { | ||
3094 | GNUNET_SCHEDULER_cancel (queue->visibility_task); | ||
3095 | queue->visibility_task = NULL; | ||
3096 | } | ||
3097 | while (NULL != (pa = queue->pa_head)) | 3146 | while (NULL != (pa = queue->pa_head)) |
3098 | { | 3147 | { |
3099 | GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa); | 3148 | GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa); |
@@ -3139,9 +3188,12 @@ free_queue (struct Queue *queue) | |||
3139 | notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); | 3188 | notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); |
3140 | GNUNET_free (queue); | 3189 | GNUNET_free (queue); |
3141 | 3190 | ||
3142 | update_neighbour_core_visibility (neighbour); | 3191 | vl = GNUNET_CONTAINER_multipeermap_get (links, &neighbour->pid); |
3143 | cores_send_disconnect_info (&neighbour->pid); | 3192 | if ((NULL != vl) && (neighbour == vl->n)) |
3144 | 3193 | { | |
3194 | GNUNET_SCHEDULER_cancel (vl->visibility_task); | ||
3195 | check_link_down (vl); | ||
3196 | } | ||
3145 | if (NULL == neighbour->queue_head) | 3197 | if (NULL == neighbour->queue_head) |
3146 | { | 3198 | { |
3147 | free_neighbour (neighbour); | 3199 | free_neighbour (neighbour); |
@@ -3281,12 +3333,12 @@ notify_client_connect_info (void *cls, | |||
3281 | void *value) | 3333 | void *value) |
3282 | { | 3334 | { |
3283 | struct TransportClient *tc = cls; | 3335 | struct TransportClient *tc = cls; |
3284 | struct Neighbour *neighbour = value; | ||
3285 | 3336 | ||
3337 | (void) value; | ||
3286 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3287 | "Telling new CORE client about existing connection to %s\n", | 3339 | "Telling new CORE client about existing connection to %s\n", |
3288 | GNUNET_i2s (pid)); | 3340 | GNUNET_i2s (pid)); |
3289 | core_send_connect_info (tc, pid, neighbour->quota_out); | 3341 | core_send_connect_info (tc, pid); |
3290 | return GNUNET_OK; | 3342 | return GNUNET_OK; |
3291 | } | 3343 | } |
3292 | 3344 | ||
@@ -3469,9 +3521,6 @@ client_send_response (struct PendingMessage *pm, | |||
3469 | if (NULL != tc) | 3521 | if (NULL != tc) |
3470 | { | 3522 | { |
3471 | env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | 3523 | env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); |
3472 | som->success = htonl ((uint32_t) success); | ||
3473 | som->bytes_msg = htons (pm->bytes_msg); | ||
3474 | som->bytes_physical = htonl (bytes_physical); | ||
3475 | som->peer = target->pid; | 3524 | som->peer = target->pid; |
3476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3525 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3477 | "Confirming %s transmission of %u/%u bytes to %s\n", | 3526 | "Confirming %s transmission of %u/%u bytes to %s\n", |
@@ -3486,45 +3535,6 @@ client_send_response (struct PendingMessage *pm, | |||
3486 | 3535 | ||
3487 | 3536 | ||
3488 | /** | 3537 | /** |
3489 | * Checks the message queue for a neighbour for messages that have timed | ||
3490 | * out and purges them. | ||
3491 | * | ||
3492 | * @param cls a `struct Neighbour` | ||
3493 | */ | ||
3494 | static void | ||
3495 | check_queue_timeouts (void *cls) | ||
3496 | { | ||
3497 | struct Neighbour *n = cls; | ||
3498 | struct PendingMessage *pm; | ||
3499 | struct GNUNET_TIME_Absolute now; | ||
3500 | struct GNUNET_TIME_Absolute earliest_timeout; | ||
3501 | |||
3502 | n->timeout_task = NULL; | ||
3503 | earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
3504 | now = GNUNET_TIME_absolute_get (); | ||
3505 | for (struct PendingMessage *pos = n->pending_msg_head; NULL != pos; pos = pm) | ||
3506 | { | ||
3507 | pm = pos->next_neighbour; | ||
3508 | if (pos->timeout.abs_value_us <= now.abs_value_us) | ||
3509 | { | ||
3510 | GNUNET_STATISTICS_update (GST_stats, | ||
3511 | "# messages dropped (timeout before confirmation)", | ||
3512 | 1, | ||
3513 | GNUNET_NO); | ||
3514 | client_send_response (pm, GNUNET_NO, 0); | ||
3515 | continue; | ||
3516 | } | ||
3517 | earliest_timeout = | ||
3518 | GNUNET_TIME_absolute_min (earliest_timeout, pos->timeout); | ||
3519 | } | ||
3520 | n->earliest_timeout = earliest_timeout; | ||
3521 | if (NULL != n->pending_msg_head) | ||
3522 | n->timeout_task = | ||
3523 | GNUNET_SCHEDULER_add_at (earliest_timeout, &check_queue_timeouts, n); | ||
3524 | } | ||
3525 | |||
3526 | |||
3527 | /** | ||
3528 | * Create a DV Box message. | 3538 | * Create a DV Box message. |
3529 | * | 3539 | * |
3530 | * @param total_hops how many hops did the message take so far | 3540 | * @param total_hops how many hops did the message take so far |
@@ -3689,30 +3699,18 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) | |||
3689 | const void *payload; | 3699 | const void *payload; |
3690 | size_t payload_size; | 3700 | size_t payload_size; |
3691 | struct TransportDVBoxMessage *dvb; | 3701 | struct TransportDVBoxMessage *dvb; |
3702 | struct VirtualLink *vl; | ||
3692 | 3703 | ||
3693 | GNUNET_assert (CT_CORE == tc->type); | 3704 | GNUNET_assert (CT_CORE == tc->type); |
3694 | obmm = (const struct GNUNET_MessageHeader *) &obm[1]; | 3705 | obmm = (const struct GNUNET_MessageHeader *) &obm[1]; |
3695 | bytes_msg = ntohs (obmm->size); | 3706 | bytes_msg = ntohs (obmm->size); |
3696 | target = lookup_neighbour (&obm->peer); | 3707 | vl = GNUNET_CONTAINER_multipeermap_get (links, &obm->peer); |
3697 | if (NULL == target) | 3708 | if (NULL == vl) |
3698 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &obm->peer); | ||
3699 | else | ||
3700 | dv = NULL; | ||
3701 | if ((NULL == target) && ((NULL == dv) || (GNUNET_NO == dv->core_visible))) | ||
3702 | { | 3709 | { |
3703 | /* Failure: don't have this peer as a neighbour (anymore). | 3710 | /* Failure: don't have this peer as a neighbour (anymore). |
3704 | Might have gone down asynchronously, so this is NOT | 3711 | Might have gone down asynchronously, so this is NOT |
3705 | a protocol violation by CORE. Still count the event, | 3712 | a protocol violation by CORE. Still count the event, |
3706 | as this should be rare. */ | 3713 | as this should be rare. */ |
3707 | struct GNUNET_MQ_Envelope *env; | ||
3708 | struct SendOkMessage *som; | ||
3709 | |||
3710 | env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); | ||
3711 | som->success = htonl (GNUNET_SYSERR); | ||
3712 | som->bytes_msg = htonl (bytes_msg); | ||
3713 | som->bytes_physical = htonl (0); | ||
3714 | som->peer = obm->peer; | ||
3715 | GNUNET_MQ_send (tc->mq, env); | ||
3716 | GNUNET_SERVICE_client_continue (tc->client); | 3714 | GNUNET_SERVICE_client_continue (tc->client); |
3717 | GNUNET_STATISTICS_update (GST_stats, | 3715 | GNUNET_STATISTICS_update (GST_stats, |
3718 | "# messages dropped (neighbour unknown)", | 3716 | "# messages dropped (neighbour unknown)", |
@@ -3720,6 +3718,12 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) | |||
3720 | GNUNET_NO); | 3718 | GNUNET_NO); |
3721 | return; | 3719 | return; |
3722 | } | 3720 | } |
3721 | target = lookup_neighbour (&obm->peer); | ||
3722 | if (NULL == target) | ||
3723 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &obm->peer); | ||
3724 | else | ||
3725 | dv = NULL; | ||
3726 | GNUNET_assert ((NULL != target) || (NULL != dv)); | ||
3723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3724 | "Sending %u bytes to %s using %s\n", | 3728 | "Sending %u bytes to %s using %s\n", |
3725 | bytes_msg, | 3729 | bytes_msg, |
@@ -3756,8 +3760,6 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) | |||
3756 | pm->client = tc; | 3760 | pm->client = tc; |
3757 | pm->target = target; | 3761 | pm->target = target; |
3758 | pm->bytes_msg = payload_size; | 3762 | pm->bytes_msg = payload_size; |
3759 | pm->timeout = | ||
3760 | GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout)); | ||
3761 | memcpy (&pm[1], payload, payload_size); | 3763 | memcpy (&pm[1], payload, payload_size); |
3762 | GNUNET_free_non_null (dvb); | 3764 | GNUNET_free_non_null (dvb); |
3763 | dvb = NULL; | 3765 | dvb = NULL; |
@@ -3777,15 +3779,6 @@ handle_client_send (void *cls, const struct OutboundMessage *obm) | |||
3777 | tc->details.core.pending_msg_head, | 3779 | tc->details.core.pending_msg_head, |
3778 | tc->details.core.pending_msg_tail, | 3780 | tc->details.core.pending_msg_tail, |
3779 | pm); | 3781 | pm); |
3780 | if (target->earliest_timeout.abs_value_us > pm->timeout.abs_value_us) | ||
3781 | { | ||
3782 | target->earliest_timeout.abs_value_us = pm->timeout.abs_value_us; | ||
3783 | if (NULL != target->timeout_task) | ||
3784 | GNUNET_SCHEDULER_cancel (target->timeout_task); | ||
3785 | target->timeout_task = GNUNET_SCHEDULER_add_at (target->earliest_timeout, | ||
3786 | &check_queue_timeouts, | ||
3787 | target); | ||
3788 | } | ||
3789 | if (! was_empty) | 3782 | if (! was_empty) |
3790 | return; /* all queues must already be busy */ | 3783 | return; /* all queues must already be busy */ |
3791 | for (struct Queue *queue = target->queue_head; NULL != queue; | 3784 | for (struct Queue *queue = target->queue_head; NULL != queue; |
@@ -3834,6 +3827,47 @@ check_communicator_available ( | |||
3834 | 3827 | ||
3835 | 3828 | ||
3836 | /** | 3829 | /** |
3830 | * Client confirms that it is done handling message(s) to a particular | ||
3831 | * peer. We may now provide more messages to CORE for this peer. | ||
3832 | * | ||
3833 | * Notifies the respective queues that more messages can now be received. | ||
3834 | * | ||
3835 | * @param cls the client | ||
3836 | * @param rom the message that was sent | ||
3837 | */ | ||
3838 | static void | ||
3839 | handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) | ||
3840 | { | ||
3841 | struct TransportClient *tc = cls; | ||
3842 | struct VirtualLink *vl; | ||
3843 | uint32_t delta; | ||
3844 | |||
3845 | if (CT_CORE != tc->type) | ||
3846 | { | ||
3847 | GNUNET_break (0); | ||
3848 | GNUNET_SERVICE_client_drop (tc->client); | ||
3849 | return; | ||
3850 | } | ||
3851 | vl = GNUNET_CONTAINER_multipeermap_get (links, &rom->peer); | ||
3852 | if (NULL == vl) | ||
3853 | { | ||
3854 | GNUNET_STATISTICS_update (GST_stats, | ||
3855 | "# RECV_OK dropped: virtual link unknown", | ||
3856 | 1, | ||
3857 | GNUNET_NO); | ||
3858 | GNUNET_SERVICE_client_continue (tc->client); | ||
3859 | return; | ||
3860 | } | ||
3861 | delta = ntohl (rom->increase_window_delta); | ||
3862 | vl->core_recv_window += delta; | ||
3863 | if (delta == vl->core_recv_window) | ||
3864 | { | ||
3865 | // FIXME: resume communicators! | ||
3866 | } | ||
3867 | } | ||
3868 | |||
3869 | |||
3870 | /** | ||
3837 | * Communicator started. Process the request. | 3871 | * Communicator started. Process the request. |
3838 | * | 3872 | * |
3839 | * @param cls the client | 3873 | * @param cls the client |
@@ -4090,20 +4124,18 @@ route_via_neighbour (const struct Neighbour *n, | |||
4090 | for (struct Queue *pos = n->queue_head; NULL != pos; | 4124 | for (struct Queue *pos = n->queue_head; NULL != pos; |
4091 | pos = pos->next_neighbour) | 4125 | pos = pos->next_neighbour) |
4092 | { | 4126 | { |
4093 | /* Count the queue with the visibility task in all cases, as | ||
4094 | otherwise we may end up with no queues just because the | ||
4095 | time for the visibility task just expired but the scheduler | ||
4096 | just ran this task first */ | ||
4097 | if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || | 4127 | if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || |
4098 | (pos->validated_until.abs_value_us > now.abs_value_us) || | 4128 | (pos->validated_until.abs_value_us > now.abs_value_us)) |
4099 | (NULL != pos->visibility_task)) | ||
4100 | candidates++; | 4129 | candidates++; |
4101 | } | 4130 | } |
4102 | if (0 == candidates) | 4131 | if (0 == candidates) |
4103 | { | 4132 | { |
4104 | /* Given that we above check for pos->visibility task, | 4133 | /* This can happen rarely if the last confirmed queue timed |
4105 | this should be strictly impossible. */ | 4134 | out just as we were beginning to process this message. */ |
4106 | GNUNET_break (0); | 4135 | GNUNET_STATISTICS_update (GST_stats, |
4136 | "# route selection failed (all no valid queue)", | ||
4137 | 1, | ||
4138 | GNUNET_NO); | ||
4107 | return; | 4139 | return; |
4108 | } | 4140 | } |
4109 | sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); | 4141 | sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); |
@@ -4115,12 +4147,8 @@ route_via_neighbour (const struct Neighbour *n, | |||
4115 | for (struct Queue *pos = n->queue_head; NULL != pos; | 4147 | for (struct Queue *pos = n->queue_head; NULL != pos; |
4116 | pos = pos->next_neighbour) | 4148 | pos = pos->next_neighbour) |
4117 | { | 4149 | { |
4118 | /* Count the queue with the visibility task in all cases, as | 4150 | if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || |
4119 | otherwise we may end up with no queues just because the | 4151 | (pos->validated_until.abs_value_us > now.abs_value_us)) |
4120 | time for the visibility task just expired but the scheduler | ||
4121 | just ran this task first */ | ||
4122 | if ((pos->validated_until.abs_value_us > now.abs_value_us) || | ||
4123 | (NULL != pos->visibility_task)) | ||
4124 | { | 4152 | { |
4125 | if ((sel1 == candidates) || (sel2 == candidates)) | 4153 | if ((sel1 == candidates) || (sel2 == candidates)) |
4126 | queue_send_msg (pos, NULL, hdr, ntohs (hdr->size)); | 4154 | queue_send_msg (pos, NULL, hdr, ntohs (hdr->size)); |
@@ -4197,21 +4225,21 @@ route_message (const struct GNUNET_PeerIdentity *target, | |||
4197 | struct GNUNET_MessageHeader *hdr, | 4225 | struct GNUNET_MessageHeader *hdr, |
4198 | enum RouteMessageOptions options) | 4226 | enum RouteMessageOptions options) |
4199 | { | 4227 | { |
4228 | struct VirtualLink *vl; | ||
4200 | struct Neighbour *n; | 4229 | struct Neighbour *n; |
4201 | struct DistanceVector *dv; | 4230 | struct DistanceVector *dv; |
4202 | 4231 | ||
4203 | n = lookup_neighbour (target); | 4232 | vl = GNUNET_CONTAINER_multipeermap_get (links, target); |
4204 | dv = (0 != (options & RMO_DV_ALLOWED)) | 4233 | n = vl->n; |
4205 | ? GNUNET_CONTAINER_multipeermap_get (dv_routes, target) | 4234 | dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; |
4206 | : NULL; | ||
4207 | if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) | 4235 | if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) |
4208 | { | 4236 | { |
4209 | /* if confirmed is required, and we do not have anything | 4237 | /* if confirmed is required, and we do not have anything |
4210 | confirmed, drop respective options */ | 4238 | confirmed, drop respective options */ |
4211 | if ((NULL != n) && (GNUNET_NO == n->core_visible)) | 4239 | if (NULL == n) |
4212 | n = NULL; | 4240 | n = lookup_neighbour (target); |
4213 | if ((NULL != dv) && (GNUNET_NO == dv->core_visible)) | 4241 | if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) |
4214 | dv = NULL; | 4242 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target); |
4215 | } | 4243 | } |
4216 | if ((NULL == n) && (NULL == dv)) | 4244 | if ((NULL == n) && (NULL == dv)) |
4217 | { | 4245 | { |
@@ -5758,40 +5786,6 @@ path_cleanup_cb (void *cls) | |||
5758 | GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); | 5786 | GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); |
5759 | } | 5787 | } |
5760 | 5788 | ||
5761 | /** | ||
5762 | * Task run to check whether the hops of the @a cls still | ||
5763 | * are validated, or if we need to core about disconnection. | ||
5764 | * | ||
5765 | * @param cls a `struct DistanceVector` (with core_visible set!) | ||
5766 | */ | ||
5767 | static void | ||
5768 | check_dv_path_down (void *cls) | ||
5769 | { | ||
5770 | struct DistanceVector *dv = cls; | ||
5771 | struct Neighbour *n; | ||
5772 | |||
5773 | dv->visibility_task = NULL; | ||
5774 | GNUNET_assert (GNUNET_YES == dv->core_visible); | ||
5775 | for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; | ||
5776 | pos = pos->next_dv) | ||
5777 | { | ||
5778 | if (0 < | ||
5779 | GNUNET_TIME_absolute_get_remaining (pos->path_valid_until).rel_value_us) | ||
5780 | { | ||
5781 | dv->visibility_task = GNUNET_SCHEDULER_add_at (pos->path_valid_until, | ||
5782 | &check_dv_path_down, | ||
5783 | dv); | ||
5784 | return; | ||
5785 | } | ||
5786 | } | ||
5787 | /* all paths invalid, make dv core-invisible */ | ||
5788 | dv->core_visible = GNUNET_NO; | ||
5789 | n = lookup_neighbour (&dv->target); | ||
5790 | if ((NULL != n) && (GNUNET_YES == n->core_visible)) | ||
5791 | return; /* no need to tell core, connection still up! */ | ||
5792 | cores_send_disconnect_info (&dv->target); | ||
5793 | } | ||
5794 | |||
5795 | 5789 | ||
5796 | /** | 5790 | /** |
5797 | * The @a hop is a validated path to the respective target | 5791 | * The @a hop is a validated path to the respective target |
@@ -5804,22 +5798,30 @@ static void | |||
5804 | activate_core_visible_dv_path (struct DistanceVectorHop *hop) | 5798 | activate_core_visible_dv_path (struct DistanceVectorHop *hop) |
5805 | { | 5799 | { |
5806 | struct DistanceVector *dv = hop->dv; | 5800 | struct DistanceVector *dv = hop->dv; |
5807 | struct Neighbour *n; | 5801 | struct VirtualLink *vl; |
5808 | |||
5809 | GNUNET_assert (GNUNET_NO == dv->core_visible); | ||
5810 | GNUNET_assert (NULL == dv->visibility_task); | ||
5811 | 5802 | ||
5812 | dv->core_visible = GNUNET_YES; | 5803 | vl = GNUNET_CONTAINER_multipeermap_get (links, &dv->target); |
5813 | dv->visibility_task = | 5804 | if (NULL != vl) |
5814 | GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_dv_path_down, dv); | 5805 | { |
5815 | n = lookup_neighbour (&dv->target); | 5806 | /* Link was already up, remember dv is also now available and we are done */ |
5816 | if ((NULL != n) && (GNUNET_YES == n->core_visible)) | 5807 | vl->dv = dv; |
5817 | return; /* no need to tell core, connection already up! */ | 5808 | return; |
5818 | cores_send_connect_info (&dv->target, | 5809 | } |
5819 | (NULL != n) | 5810 | vl = GNUNET_new (struct VirtualLink); |
5820 | ? GNUNET_BANDWIDTH_value_sum (n->quota_out, | 5811 | vl->target = dv->target; |
5821 | dv->quota_out) | 5812 | vl->dv = dv; |
5822 | : dv->quota_out); | 5813 | vl->core_recv_window = RECV_WINDOW_SIZE; |
5814 | vl->visibility_task = | ||
5815 | GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl); | ||
5816 | GNUNET_break (GNUNET_YES == | ||
5817 | GNUNET_CONTAINER_multipeermap_put ( | ||
5818 | links, | ||
5819 | &vl->target, | ||
5820 | vl, | ||
5821 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
5822 | /* We lacked a confirmed connection to the target | ||
5823 | before, so tell CORE about it (finally!) */ | ||
5824 | cores_send_connect_info (&dv->target); | ||
5823 | } | 5825 | } |
5824 | 5826 | ||
5825 | 5827 | ||
@@ -5934,9 +5936,8 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, | |||
5934 | GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until); | 5936 | GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until); |
5935 | GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); | 5937 | GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); |
5936 | GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); | 5938 | GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); |
5937 | if ((GNUNET_NO == dv->core_visible) && | 5939 | if (0 < |
5938 | (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until) | 5940 | GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) |
5939 | .rel_value_us)) | ||
5940 | activate_core_visible_dv_path (pos); | 5941 | activate_core_visible_dv_path (pos); |
5941 | if (last_timeout.rel_value_us < | 5942 | if (last_timeout.rel_value_us < |
5942 | GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, | 5943 | GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, |
@@ -5976,8 +5977,7 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path, | |||
5976 | next_hop->dv_head, | 5977 | next_hop->dv_head, |
5977 | next_hop->dv_tail, | 5978 | next_hop->dv_tail, |
5978 | hop); | 5979 | hop); |
5979 | if ((GNUNET_NO == dv->core_visible) && | 5980 | if (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) |
5980 | (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us)) | ||
5981 | activate_core_visible_dv_path (hop); | 5981 | activate_core_visible_dv_path (hop); |
5982 | return GNUNET_YES; | 5982 | return GNUNET_YES; |
5983 | } | 5983 | } |
@@ -6943,75 +6943,6 @@ find_queue (const struct GNUNET_PeerIdentity *pid, const char *address) | |||
6943 | 6943 | ||
6944 | 6944 | ||
6945 | /** | 6945 | /** |
6946 | * Task run periodically to check whether the validity of the given queue has | ||
6947 | * run its course. If so, finds either another queue to take over, or clears | ||
6948 | * the neighbour's `core_visible` flag. In the latter case, gives DV routes a | ||
6949 | * chance to take over, and if that fails, notifies CORE about the disconnect. | ||
6950 | * | ||
6951 | * @param cls a `struct Queue` | ||
6952 | */ | ||
6953 | static void | ||
6954 | core_queue_visibility_check (void *cls) | ||
6955 | { | ||
6956 | struct Queue *q = cls; | ||
6957 | |||
6958 | q->visibility_task = NULL; | ||
6959 | if (0 != GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us) | ||
6960 | { | ||
6961 | q->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until, | ||
6962 | &core_queue_visibility_check, | ||
6963 | q); | ||
6964 | return; | ||
6965 | } | ||
6966 | update_neighbour_core_visibility (q->neighbour); | ||
6967 | } | ||
6968 | |||
6969 | |||
6970 | /** | ||
6971 | * Check whether the CORE visibility of @a n should change. Finds either a | ||
6972 | * queue to preserve the visibility, or clears the neighbour's `core_visible` | ||
6973 | * flag. In the latter case, gives DV routes a chance to take over, and if | ||
6974 | * that fails, notifies CORE about the disconnect. If so, check whether we | ||
6975 | * need to notify CORE. | ||
6976 | * | ||
6977 | * @param n neighbour to perform the check for | ||
6978 | */ | ||
6979 | static void | ||
6980 | update_neighbour_core_visibility (struct Neighbour *n) | ||
6981 | { | ||
6982 | struct DistanceVector *dv; | ||
6983 | |||
6984 | GNUNET_assert (GNUNET_YES == n->core_visible); | ||
6985 | /* Check if _any_ queue of this neighbour is still valid, if so, schedule | ||
6986 | the #core_queue_visibility_check() task for that queue */ | ||
6987 | for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) | ||
6988 | { | ||
6989 | if (0 != | ||
6990 | GNUNET_TIME_absolute_get_remaining (q->validated_until).rel_value_us) | ||
6991 | { | ||
6992 | /* found a valid queue, use this one */ | ||
6993 | q->visibility_task = | ||
6994 | GNUNET_SCHEDULER_add_at (q->validated_until, | ||
6995 | &core_queue_visibility_check, | ||
6996 | q); | ||
6997 | return; | ||
6998 | } | ||
6999 | } | ||
7000 | n->core_visible = GNUNET_NO; | ||
7001 | |||
7002 | /* Check if _any_ DV route to this neighbour is currently | ||
7003 | valid, if so, do NOT tell core about the loss of direct | ||
7004 | connectivity (DV still counts!) */ | ||
7005 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &n->pid); | ||
7006 | if (GNUNET_YES == dv->core_visible) | ||
7007 | return; | ||
7008 | /* Nothing works anymore, need to tell CORE about the loss of | ||
7009 | connectivity! */ | ||
7010 | cores_send_disconnect_info (&n->pid); | ||
7011 | } | ||
7012 | |||
7013 | |||
7014 | /** | ||
7015 | * Communicator gave us a transport address validation response. Process the | 6946 | * Communicator gave us a transport address validation response. Process the |
7016 | * request. | 6947 | * request. |
7017 | * | 6948 | * |
@@ -7030,8 +6961,8 @@ handle_validation_response ( | |||
7030 | .vs = NULL}; | 6961 | .vs = NULL}; |
7031 | struct GNUNET_TIME_Absolute origin_time; | 6962 | struct GNUNET_TIME_Absolute origin_time; |
7032 | struct Queue *q; | 6963 | struct Queue *q; |
7033 | struct DistanceVector *dv; | ||
7034 | struct Neighbour *n; | 6964 | struct Neighbour *n; |
6965 | struct VirtualLink *vl; | ||
7035 | 6966 | ||
7036 | /* check this is one of our challenges */ | 6967 | /* check this is one of our challenges */ |
7037 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 6968 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, |
@@ -7129,24 +7060,28 @@ handle_validation_response ( | |||
7129 | q->validated_until = vs->validated_until; | 7060 | q->validated_until = vs->validated_until; |
7130 | q->pd.aged_rtt = vs->validation_rtt; | 7061 | q->pd.aged_rtt = vs->validation_rtt; |
7131 | n = q->neighbour; | 7062 | n = q->neighbour; |
7132 | if (GNUNET_NO != n->core_visible) | 7063 | vl = GNUNET_CONTAINER_multipeermap_get (links, &vs->pid); |
7133 | return; /* nothing changed, we are done here */ | 7064 | if (NULL != vl) |
7134 | n->core_visible = GNUNET_YES; | 7065 | { |
7135 | q->visibility_task = GNUNET_SCHEDULER_add_at (q->validated_until, | 7066 | /* Link was already up, remember n is also now available and we are done */ |
7136 | &core_queue_visibility_check, | 7067 | vl->n = n; |
7137 | q); | 7068 | return; |
7138 | /* Check if _any_ DV route to this neighbour is | 7069 | } |
7139 | currently valid, if so, do NOT tell core anything! */ | 7070 | vl = GNUNET_new (struct VirtualLink); |
7140 | dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &n->pid); | 7071 | vl->target = n->pid; |
7141 | if ((NULL != dv) && (GNUNET_YES == dv->core_visible)) | 7072 | vl->n = n; |
7142 | return; /* nothing changed, done */ | 7073 | vl->core_recv_window = RECV_WINDOW_SIZE; |
7143 | /* We lacked a confirmed connection to the neighbour | 7074 | vl->visibility_task = |
7075 | GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); | ||
7076 | GNUNET_break (GNUNET_YES == | ||
7077 | GNUNET_CONTAINER_multipeermap_put ( | ||
7078 | links, | ||
7079 | &vl->target, | ||
7080 | vl, | ||
7081 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
7082 | /* We lacked a confirmed connection to the target | ||
7144 | before, so tell CORE about it (finally!) */ | 7083 | before, so tell CORE about it (finally!) */ |
7145 | cores_send_connect_info (&n->pid, | 7084 | cores_send_connect_info (&n->pid); |
7146 | (NULL != dv) | ||
7147 | ? GNUNET_BANDWIDTH_value_sum (dv->quota_out, | ||
7148 | n->quota_out) | ||
7149 | : n->quota_out); | ||
7150 | } | 7085 | } |
7151 | 7086 | ||
7152 | 7087 | ||
@@ -8256,7 +8191,6 @@ handle_add_queue_message (void *cls, | |||
8256 | if (NULL == neighbour) | 8191 | if (NULL == neighbour) |
8257 | { | 8192 | { |
8258 | neighbour = GNUNET_new (struct Neighbour); | 8193 | neighbour = GNUNET_new (struct Neighbour); |
8259 | neighbour->earliest_timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
8260 | neighbour->pid = aqm->receiver; | 8194 | neighbour->pid = aqm->receiver; |
8261 | GNUNET_assert (GNUNET_OK == | 8195 | GNUNET_assert (GNUNET_OK == |
8262 | GNUNET_CONTAINER_multipeermap_put ( | 8196 | GNUNET_CONTAINER_multipeermap_put ( |
@@ -8872,8 +8806,12 @@ do_shutdown (void *cls) | |||
8872 | NULL); | 8806 | NULL); |
8873 | GNUNET_CONTAINER_multishortmap_destroy (pending_acks); | 8807 | GNUNET_CONTAINER_multishortmap_destroy (pending_acks); |
8874 | pending_acks = NULL; | 8808 | pending_acks = NULL; |
8809 | GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)); | ||
8875 | GNUNET_CONTAINER_multipeermap_destroy (neighbours); | 8810 | GNUNET_CONTAINER_multipeermap_destroy (neighbours); |
8876 | neighbours = NULL; | 8811 | neighbours = NULL; |
8812 | GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (links)); | ||
8813 | GNUNET_CONTAINER_multipeermap_destroy (links); | ||
8814 | links = NULL; | ||
8877 | GNUNET_CONTAINER_multipeermap_iterate (backtalkers, | 8815 | GNUNET_CONTAINER_multipeermap_iterate (backtalkers, |
8878 | &free_backtalker_cb, | 8816 | &free_backtalker_cb, |
8879 | NULL); | 8817 | NULL); |
@@ -8926,6 +8864,7 @@ run (void *cls, | |||
8926 | pending_acks = GNUNET_CONTAINER_multishortmap_create (32768, GNUNET_YES); | 8864 | pending_acks = GNUNET_CONTAINER_multishortmap_create (32768, GNUNET_YES); |
8927 | ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); | 8865 | ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); |
8928 | neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); | 8866 | neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); |
8867 | links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES); | ||
8929 | dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); | 8868 | dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); |
8930 | ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); | 8869 | ephemeral_map = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
8931 | ephemeral_heap = | 8870 | ephemeral_heap = |
@@ -8995,6 +8934,10 @@ GNUNET_SERVICE_MAIN ( | |||
8995 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, | 8934 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, |
8996 | struct OutboundMessage, | 8935 | struct OutboundMessage, |
8997 | NULL), | 8936 | NULL), |
8937 | GNUNET_MQ_hd_fixed_size (client_recv_ok, | ||
8938 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, | ||
8939 | struct RecvOkMessage, | ||
8940 | NULL), | ||
8998 | /* communication with communicators */ | 8941 | /* communication with communicators */ |
8999 | GNUNET_MQ_hd_var_size (communicator_available, | 8942 | GNUNET_MQ_hd_var_size (communicator_available, |
9000 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, | 8943 | GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, |
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c index 9160a78b2..89f5b4108 100644 --- a/src/transport/gnunet-transport-profiler.c +++ b/src/transport/gnunet-transport-profiler.c | |||
@@ -32,7 +32,6 @@ | |||
32 | #include "gnunet_protocols.h" | 32 | #include "gnunet_protocols.h" |
33 | #include "gnunet_ats_service.h" | 33 | #include "gnunet_ats_service.h" |
34 | #include "gnunet_transport_service.h" | 34 | #include "gnunet_transport_service.h" |
35 | #include "gnunet_transport_core_service.h" | ||
36 | 35 | ||
37 | 36 | ||
38 | struct Iteration | 37 | struct Iteration |
@@ -54,7 +53,8 @@ struct Iteration | |||
54 | /** | 53 | /** |
55 | * Timeout for a connections | 54 | * Timeout for a connections |
56 | */ | 55 | */ |
57 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 56 | #define CONNECT_TIMEOUT \ |
57 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Benchmarking block size in bye | 60 | * Benchmarking block size in bye |
@@ -214,15 +214,16 @@ shutdown_task (void *cls) | |||
214 | { | 214 | { |
215 | inext = icur->next; | 215 | inext = icur->next; |
216 | icur->rate = ((benchmark_count * benchmark_size) / 1024) / | 216 | icur->rate = ((benchmark_count * benchmark_size) / 1024) / |
217 | ((float) icur->dur.rel_value_us / (1000 * 1000)); | 217 | ((float) icur->dur.rel_value_us / (1000 * 1000)); |
218 | if (verbosity > 0) | 218 | if (verbosity > 0) |
219 | FPRINTF (stdout, _("%llu B in %llu ms == %.2f KB/s!\n"), | 219 | FPRINTF (stdout, |
220 | ((long long unsigned int) benchmark_count * benchmark_size), | 220 | _ ("%llu B in %llu ms == %.2f KB/s!\n"), |
221 | ((long long unsigned int) icur->dur.rel_value_us / 1000), | 221 | ((long long unsigned int) benchmark_count * benchmark_size), |
222 | (float) icur->rate); | 222 | ((long long unsigned int) icur->dur.rel_value_us / 1000), |
223 | (float) icur->rate); | ||
223 | 224 | ||
224 | avg_duration += icur->dur.rel_value_us / (1000); | 225 | avg_duration += icur->dur.rel_value_us / (1000); |
225 | avg_rate += icur->rate; | 226 | avg_rate += icur->rate; |
226 | iterations++; | 227 | iterations++; |
227 | } | 228 | } |
228 | if (0 == iterations) | 229 | if (0 == iterations) |
@@ -238,19 +239,17 @@ shutdown_task (void *cls) | |||
238 | while (NULL != (icur = inext)) | 239 | while (NULL != (icur = inext)) |
239 | { | 240 | { |
240 | inext = icur->next; | 241 | inext = icur->next; |
241 | stddev_rate += ((icur->rate-avg_rate) * | 242 | stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate)); |
242 | (icur->rate-avg_rate)); | ||
243 | stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) * | 243 | stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) * |
244 | ((icur->dur.rel_value_us / 1000) - avg_duration)); | 244 | ((icur->dur.rel_value_us / 1000) - avg_duration)); |
245 | |||
246 | } | 245 | } |
247 | /* Calculate standard deviation rate */ | 246 | /* Calculate standard deviation rate */ |
248 | stddev_rate = stddev_rate / iterations; | 247 | stddev_rate = stddev_rate / iterations; |
249 | stddev_rate = sqrtf(stddev_rate); | 248 | stddev_rate = sqrtf (stddev_rate); |
250 | 249 | ||
251 | /* Calculate standard deviation duration */ | 250 | /* Calculate standard deviation duration */ |
252 | stddev_duration = stddev_duration / iterations; | 251 | stddev_duration = stddev_duration / iterations; |
253 | stddev_duration = sqrtf(stddev_duration); | 252 | stddev_duration = sqrtf (stddev_duration); |
254 | 253 | ||
255 | /* Output */ | 254 | /* Output */ |
256 | FPRINTF (stdout, | 255 | FPRINTF (stdout, |
@@ -266,9 +265,7 @@ shutdown_task (void *cls) | |||
266 | while (NULL != (icur = inext)) | 265 | while (NULL != (icur = inext)) |
267 | { | 266 | { |
268 | inext = icur->next; | 267 | inext = icur->next; |
269 | GNUNET_CONTAINER_DLL_remove (ihead, | 268 | GNUNET_CONTAINER_DLL_remove (ihead, itail, icur); |
270 | itail, | ||
271 | icur); | ||
272 | 269 | ||
273 | FPRINTF (stdout, | 270 | FPRINTF (stdout, |
274 | ";%llu;%.2f", | 271 | ";%llu;%.2f", |
@@ -316,27 +313,19 @@ send_msg (void *cls) | |||
316 | 313 | ||
317 | if (NULL == mq) | 314 | if (NULL == mq) |
318 | return; | 315 | return; |
319 | env = GNUNET_MQ_msg_extra (m, | 316 | env = GNUNET_MQ_msg_extra (m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY); |
320 | benchmark_size, | 317 | memset (&m[1], 52, benchmark_size - sizeof (struct GNUNET_MessageHeader)); |
321 | GNUNET_MESSAGE_TYPE_DUMMY); | 318 | |
322 | memset (&m[1], | ||
323 | 52, | ||
324 | benchmark_size - sizeof(struct GNUNET_MessageHeader)); | ||
325 | |||
326 | if (itail->msgs_sent < benchmark_count) | 319 | if (itail->msgs_sent < benchmark_count) |
327 | { | 320 | { |
328 | GNUNET_MQ_notify_sent (env, | 321 | GNUNET_MQ_notify_sent (env, &send_msg, NULL); |
329 | &send_msg, | ||
330 | NULL); | ||
331 | } | 322 | } |
332 | else | 323 | else |
333 | { | 324 | { |
334 | iteration_done (); | 325 | iteration_done (); |
335 | } | 326 | } |
336 | GNUNET_MQ_send (mq, | 327 | GNUNET_MQ_send (mq, env); |
337 | env); | 328 | if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) |
338 | if ( (verbosity > 0) && | ||
339 | (0 == itail->msgs_sent % 10) ) | ||
340 | FPRINTF (stdout, "."); | 329 | FPRINTF (stdout, "."); |
341 | } | 330 | } |
342 | 331 | ||
@@ -351,15 +340,14 @@ iteration_start () | |||
351 | return; | 340 | return; |
352 | benchmark_running = GNUNET_YES; | 341 | benchmark_running = GNUNET_YES; |
353 | icur = GNUNET_new (struct Iteration); | 342 | icur = GNUNET_new (struct Iteration); |
354 | GNUNET_CONTAINER_DLL_insert_tail (ihead, | 343 | GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); |
355 | itail, | 344 | icur->start = GNUNET_TIME_absolute_get (); |
356 | icur); | ||
357 | icur->start = GNUNET_TIME_absolute_get(); | ||
358 | if (verbosity > 0) | 345 | if (verbosity > 0) |
359 | FPRINTF (stdout, | 346 | FPRINTF ( |
360 | "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", | 347 | stdout, |
361 | benchmark_count, | 348 | "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", |
362 | benchmark_size); | 349 | benchmark_count, |
350 | benchmark_size); | ||
363 | send_msg (NULL); | 351 | send_msg (NULL); |
364 | } | 352 | } |
365 | 353 | ||
@@ -393,22 +381,16 @@ iteration_done () | |||
393 | static void * | 381 | static void * |
394 | notify_connect (void *cls, | 382 | notify_connect (void *cls, |
395 | const struct GNUNET_PeerIdentity *peer, | 383 | const struct GNUNET_PeerIdentity *peer, |
396 | struct GNUNET_MQ_Handle *m) | 384 | struct GNUNET_MQ_Handle *m) |
397 | { | 385 | { |
398 | if (0 != memcmp (&pid, | 386 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
399 | peer, | ||
400 | sizeof(struct GNUNET_PeerIdentity))) | ||
401 | { | 387 | { |
402 | FPRINTF (stdout, | 388 | FPRINTF (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid)); |
403 | "Connected to different peer `%s'\n", | ||
404 | GNUNET_i2s (&pid)); | ||
405 | return NULL; | 389 | return NULL; |
406 | } | 390 | } |
407 | 391 | ||
408 | if (verbosity > 0) | 392 | if (verbosity > 0) |
409 | FPRINTF (stdout, | 393 | FPRINTF (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid)); |
410 | "Successfully connected to `%s'\n", | ||
411 | GNUNET_i2s (&pid)); | ||
412 | mq = m; | 394 | mq = m; |
413 | iteration_start (); | 395 | iteration_start (); |
414 | return NULL; | 396 | return NULL; |
@@ -426,18 +408,16 @@ notify_connect (void *cls, | |||
426 | static void | 408 | static void |
427 | notify_disconnect (void *cls, | 409 | notify_disconnect (void *cls, |
428 | const struct GNUNET_PeerIdentity *peer, | 410 | const struct GNUNET_PeerIdentity *peer, |
429 | void *internal_cls) | 411 | void *internal_cls) |
430 | { | 412 | { |
431 | if (0 != memcmp (&pid, | 413 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
432 | peer, | ||
433 | sizeof(struct GNUNET_PeerIdentity))) | ||
434 | return; | 414 | return; |
435 | mq = NULL; | 415 | mq = NULL; |
436 | if (GNUNET_YES == benchmark_running) | 416 | if (GNUNET_YES == benchmark_running) |
437 | { | 417 | { |
438 | FPRINTF (stdout, | 418 | FPRINTF (stdout, |
439 | "Disconnected from peer `%s' while benchmarking\n", | 419 | "Disconnected from peer `%s' while benchmarking\n", |
440 | GNUNET_i2s (&pid)); | 420 | GNUNET_i2s (&pid)); |
441 | return; | 421 | return; |
442 | } | 422 | } |
443 | } | 423 | } |
@@ -451,8 +431,7 @@ notify_disconnect (void *cls, | |||
451 | * @return #GNUNET_OK | 431 | * @return #GNUNET_OK |
452 | */ | 432 | */ |
453 | static int | 433 | static int |
454 | check_dummy (void *cls, | 434 | check_dummy (void *cls, const struct GNUNET_MessageHeader *message) |
455 | const struct GNUNET_MessageHeader *message) | ||
456 | { | 435 | { |
457 | return GNUNET_OK; /* all messages are fine */ | 436 | return GNUNET_OK; /* all messages are fine */ |
458 | } | 437 | } |
@@ -465,30 +444,24 @@ check_dummy (void *cls, | |||
465 | * @param message the message | 444 | * @param message the message |
466 | */ | 445 | */ |
467 | static void | 446 | static void |
468 | handle_dummy (void *cls, | 447 | handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) |
469 | const struct GNUNET_MessageHeader *message) | ||
470 | { | 448 | { |
471 | if (! benchmark_receive) | 449 | if (! benchmark_receive) |
472 | return; | 450 | return; |
473 | if (verbosity > 0) | 451 | if (verbosity > 0) |
474 | FPRINTF (stdout, | 452 | FPRINTF (stdout, |
475 | "Received %u bytes\n", | 453 | "Received %u bytes\n", |
476 | (unsigned int) ntohs (message->size)); | 454 | (unsigned int) ntohs (message->size)); |
477 | } | 455 | } |
478 | 456 | ||
479 | 457 | ||
480 | static int | 458 | static int |
481 | blacklist_cb (void *cls, | 459 | blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer) |
482 | const struct GNUNET_PeerIdentity *peer) | ||
483 | { | 460 | { |
484 | if (0 != memcmp (&pid, | 461 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
485 | peer, | ||
486 | sizeof(struct GNUNET_PeerIdentity))) | ||
487 | { | 462 | { |
488 | if (verbosity > 0) | 463 | if (verbosity > 0) |
489 | FPRINTF (stdout, | 464 | FPRINTF (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer)); |
490 | "Denying connection to `%s'\n", | ||
491 | GNUNET_i2s (peer)); | ||
492 | return GNUNET_SYSERR; | 465 | return GNUNET_SYSERR; |
493 | } | 466 | } |
494 | return GNUNET_OK; | 467 | return GNUNET_OK; |
@@ -509,38 +482,32 @@ run (void *cls, | |||
509 | const char *cfgfile, | 482 | const char *cfgfile, |
510 | const struct GNUNET_CONFIGURATION_Handle *mycfg) | 483 | const struct GNUNET_CONFIGURATION_Handle *mycfg) |
511 | { | 484 | { |
512 | struct GNUNET_MQ_MessageHandler handlers[] = { | 485 | struct GNUNET_MQ_MessageHandler handlers[] = |
513 | GNUNET_MQ_hd_var_size (dummy, | 486 | {GNUNET_MQ_hd_var_size (dummy, |
514 | GNUNET_MESSAGE_TYPE_DUMMY, | 487 | GNUNET_MESSAGE_TYPE_DUMMY, |
515 | struct GNUNET_MessageHeader, | 488 | struct GNUNET_MessageHeader, |
516 | NULL), | 489 | NULL), |
517 | GNUNET_MQ_handler_end () | 490 | GNUNET_MQ_handler_end ()}; |
518 | }; | 491 | |
519 | |||
520 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | 492 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; |
521 | 493 | ||
522 | ret = 1; | 494 | ret = 1; |
523 | if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) | 495 | if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) |
524 | { | 496 | { |
525 | FPRINTF (stderr, | 497 | FPRINTF (stderr, "Message size too big!\n"); |
526 | "Message size too big!\n"); | ||
527 | return; | 498 | return; |
528 | } | 499 | } |
529 | 500 | ||
530 | if (NULL == cpid) | 501 | if (NULL == cpid) |
531 | { | 502 | { |
532 | FPRINTF (stderr, | 503 | FPRINTF (stderr, "No peer identity given\n"); |
533 | "No peer identity given\n"); | ||
534 | return; | 504 | return; |
535 | } | 505 | } |
536 | if (GNUNET_OK != | 506 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, |
537 | GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, | 507 | strlen (cpid), |
538 | strlen (cpid), | 508 | &pid.public_key)) |
539 | &pid.public_key)) | ||
540 | { | 509 | { |
541 | FPRINTF (stderr, | 510 | FPRINTF (stderr, "Failed to parse peer identity `%s'\n", cpid); |
542 | "Failed to parse peer identity `%s'\n", | ||
543 | cpid); | ||
544 | return; | 511 | return; |
545 | } | 512 | } |
546 | if (1 == benchmark_send) | 513 | if (1 == benchmark_send) |
@@ -548,7 +515,8 @@ run (void *cls, | |||
548 | if (verbosity > 0) | 515 | if (verbosity > 0) |
549 | FPRINTF (stderr, | 516 | FPRINTF (stderr, |
550 | "Trying to send %u messages with size %u to peer `%s'\n", | 517 | "Trying to send %u messages with size %u to peer `%s'\n", |
551 | benchmark_count, benchmark_size, | 518 | benchmark_count, |
519 | benchmark_size, | ||
552 | GNUNET_i2s (&pid)); | 520 | GNUNET_i2s (&pid)); |
553 | } | 521 | } |
554 | else if (1 == benchmark_receive) | 522 | else if (1 == benchmark_receive) |
@@ -559,50 +527,42 @@ run (void *cls, | |||
559 | } | 527 | } |
560 | else | 528 | else |
561 | { | 529 | { |
562 | FPRINTF (stderr, | 530 | FPRINTF (stderr, "No operation given\n"); |
563 | "No operation given\n"); | ||
564 | return; | 531 | return; |
565 | } | 532 | } |
566 | 533 | ||
567 | ats = GNUNET_ATS_connectivity_init (cfg); | 534 | ats = GNUNET_ATS_connectivity_init (cfg); |
568 | if (NULL == ats) | 535 | if (NULL == ats) |
569 | { | 536 | { |
570 | FPRINTF (stderr, | 537 | FPRINTF (stderr, "Failed to connect to ATS service\n"); |
571 | "Failed to connect to ATS service\n"); | ||
572 | ret = 1; | 538 | ret = 1; |
573 | return; | 539 | return; |
574 | } | 540 | } |
575 | 541 | ||
576 | handle = GNUNET_TRANSPORT_core_connect (cfg, | 542 | handle = GNUNET_TRANSPORT_core_connect (cfg, |
577 | NULL, | 543 | NULL, |
578 | handlers, | 544 | handlers, |
579 | NULL, | 545 | NULL, |
580 | ¬ify_connect, | 546 | ¬ify_connect, |
581 | ¬ify_disconnect, | 547 | ¬ify_disconnect, |
582 | NULL); | 548 | NULL); |
583 | if (NULL == handle) | 549 | if (NULL == handle) |
584 | { | 550 | { |
585 | FPRINTF (stderr, | 551 | FPRINTF (stderr, "Failed to connect to transport service\n"); |
586 | "Failed to connect to transport service\n"); | ||
587 | GNUNET_ATS_connectivity_done (ats); | 552 | GNUNET_ATS_connectivity_done (ats); |
588 | ats = NULL; | 553 | ats = NULL; |
589 | ret = 1; | 554 | ret = 1; |
590 | return; | 555 | return; |
591 | } | 556 | } |
592 | 557 | ||
593 | bl_handle = GNUNET_TRANSPORT_blacklist (cfg, | 558 | bl_handle = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); |
594 | &blacklist_cb, | 559 | ats_sh = GNUNET_ATS_connectivity_suggest (ats, &pid, 1); |
595 | NULL); | 560 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
596 | ats_sh = GNUNET_ATS_connectivity_suggest (ats, | ||
597 | &pid, | ||
598 | 1); | ||
599 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
600 | NULL); | ||
601 | } | 561 | } |
602 | 562 | ||
603 | 563 | ||
604 | int | 564 | int |
605 | main (int argc, char * const *argv) | 565 | main (int argc, char *const *argv) |
606 | { | 566 | { |
607 | int res; | 567 | int res; |
608 | benchmark_count = DEFAULT_MESSAGE_COUNT; | 568 | benchmark_count = DEFAULT_MESSAGE_COUNT; |
@@ -613,46 +573,48 @@ main (int argc, char * const *argv) | |||
613 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 573 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
614 | 574 | ||
615 | GNUNET_GETOPT_option_flag ('s', | 575 | GNUNET_GETOPT_option_flag ('s', |
616 | "send", | 576 | "send", |
617 | gettext_noop ("send data to peer"), | 577 | gettext_noop ("send data to peer"), |
618 | &benchmark_send), | 578 | &benchmark_send), |
619 | GNUNET_GETOPT_option_flag ('r', | 579 | GNUNET_GETOPT_option_flag ('r', |
620 | "receive", | 580 | "receive", |
621 | gettext_noop ("receive data from peer"), | 581 | gettext_noop ("receive data from peer"), |
622 | &benchmark_receive), | 582 | &benchmark_receive), |
623 | GNUNET_GETOPT_option_uint ('i', | 583 | GNUNET_GETOPT_option_uint ('i', |
624 | "iterations", | 584 | "iterations", |
625 | NULL, | 585 | NULL, |
626 | gettext_noop ("iterations"), | 586 | gettext_noop ("iterations"), |
627 | &benchmark_iterations), | 587 | &benchmark_iterations), |
628 | GNUNET_GETOPT_option_uint ('n', | 588 | GNUNET_GETOPT_option_uint ('n', |
629 | "number", | 589 | "number", |
630 | NULL, | 590 | NULL, |
631 | gettext_noop ("number of messages to send"), | 591 | gettext_noop ("number of messages to send"), |
632 | &benchmark_count), | 592 | &benchmark_count), |
633 | GNUNET_GETOPT_option_uint ('m', | 593 | GNUNET_GETOPT_option_uint ('m', |
634 | "messagesize", | 594 | "messagesize", |
635 | NULL, | 595 | NULL, |
636 | gettext_noop ("message size to use"), | 596 | gettext_noop ("message size to use"), |
637 | &benchmark_size), | 597 | &benchmark_size), |
638 | GNUNET_GETOPT_option_string ('p', | 598 | GNUNET_GETOPT_option_string ('p', |
639 | "peer", | 599 | "peer", |
640 | "PEER", | 600 | "PEER", |
641 | gettext_noop ("peer identity"), | 601 | gettext_noop ("peer identity"), |
642 | &cpid), | 602 | &cpid), |
643 | GNUNET_GETOPT_option_verbose (&verbosity), | 603 | GNUNET_GETOPT_option_verbose (&verbosity), |
644 | GNUNET_GETOPT_OPTION_END | 604 | GNUNET_GETOPT_OPTION_END}; |
645 | }; | ||
646 | 605 | ||
647 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 606 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
648 | return 2; | 607 | return 2; |
649 | 608 | ||
650 | res = GNUNET_PROGRAM_run (argc, argv, | 609 | res = |
651 | "gnunet-transport", | 610 | GNUNET_PROGRAM_run (argc, |
652 | gettext_noop ("Direct access to transport service."), | 611 | argv, |
653 | options, | 612 | "gnunet-transport", |
654 | &run, NULL); | 613 | gettext_noop ("Direct access to transport service."), |
655 | GNUNET_free((void *) argv); | 614 | options, |
615 | &run, | ||
616 | NULL); | ||
617 | GNUNET_free ((void *) argv); | ||
656 | if (GNUNET_OK == res) | 618 | if (GNUNET_OK == res) |
657 | return ret; | 619 | return ret; |
658 | return 1; | 620 | return 1; |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index c3c1afc38..36c8fc451 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -29,12 +29,12 @@ | |||
29 | #include "gnunet_resolver_service.h" | 29 | #include "gnunet_resolver_service.h" |
30 | #include "gnunet_protocols.h" | 30 | #include "gnunet_protocols.h" |
31 | #include "gnunet_transport_service.h" | 31 | #include "gnunet_transport_service.h" |
32 | #include "gnunet_transport_core_service.h" | ||
33 | 32 | ||
34 | /** | 33 | /** |
35 | * Timeout for a name resolution | 34 | * Timeout for a name resolution |
36 | */ | 35 | */ |
37 | #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 36 | #define RESOLUTION_TIMEOUT \ |
37 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Timeout for an operation | 40 | * Timeout for an operation |
@@ -332,16 +332,13 @@ static struct PeerResolutionContext *rc_tail; | |||
332 | * @return #GNUNET_OK (continue to iterate) | 332 | * @return #GNUNET_OK (continue to iterate) |
333 | */ | 333 | */ |
334 | static int | 334 | static int |
335 | destroy_it (void *cls, | 335 | destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
336 | const struct GNUNET_PeerIdentity *key, | ||
337 | void *value) | ||
338 | { | 336 | { |
339 | struct MonitoredPeer *m = value; | 337 | struct MonitoredPeer *m = value; |
340 | 338 | ||
341 | GNUNET_assert (GNUNET_OK == | 339 | GNUNET_assert ( |
342 | GNUNET_CONTAINER_multipeermap_remove (monitored_peers, | 340 | GNUNET_OK == |
343 | key, | 341 | GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value)); |
344 | value)); | ||
345 | GNUNET_free_non_null (m->address); | 342 | GNUNET_free_non_null (m->address); |
346 | GNUNET_free (value); | 343 | GNUNET_free (value); |
347 | return GNUNET_OK; | 344 | return GNUNET_OK; |
@@ -384,18 +381,14 @@ shutdown_task (void *cls) | |||
384 | next = cur->next; | 381 | next = cur->next; |
385 | 382 | ||
386 | GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); | 383 | GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); |
387 | GNUNET_CONTAINER_DLL_remove (vc_head, | 384 | GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur); |
388 | vc_tail, | ||
389 | cur); | ||
390 | GNUNET_free (cur->transport); | 385 | GNUNET_free (cur->transport); |
391 | GNUNET_HELLO_address_free (cur->addrcp); | 386 | GNUNET_HELLO_address_free (cur->addrcp); |
392 | GNUNET_free (cur); | 387 | GNUNET_free (cur); |
393 | } | 388 | } |
394 | while (NULL != (rc = rc_head)) | 389 | while (NULL != (rc = rc_head)) |
395 | { | 390 | { |
396 | GNUNET_CONTAINER_DLL_remove (rc_head, | 391 | GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); |
397 | rc_tail, | ||
398 | rc); | ||
399 | GNUNET_TRANSPORT_address_to_string_cancel (rc->asc); | 392 | GNUNET_TRANSPORT_address_to_string_cancel (rc->asc); |
400 | GNUNET_free (rc->transport); | 393 | GNUNET_free (rc->transport); |
401 | GNUNET_free (rc->addrcp); | 394 | GNUNET_free (rc->addrcp); |
@@ -410,35 +403,30 @@ shutdown_task (void *cls) | |||
410 | { | 403 | { |
411 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 404 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
412 | FPRINTF (stdout, | 405 | FPRINTF (stdout, |
413 | _("Transmitted %llu bytes/s (%llu bytes in %s)\n"), | 406 | _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"), |
414 | 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), | 407 | 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), |
415 | traffic_sent, | 408 | traffic_sent, |
416 | GNUNET_STRINGS_relative_time_to_string (duration, | 409 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); |
417 | GNUNET_YES)); | ||
418 | } | 410 | } |
419 | if (benchmark_receive) | 411 | if (benchmark_receive) |
420 | { | 412 | { |
421 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 413 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
422 | FPRINTF (stdout, | 414 | FPRINTF (stdout, |
423 | _("Received %llu bytes/s (%llu bytes in %s)\n"), | 415 | _ ("Received %llu bytes/s (%llu bytes in %s)\n"), |
424 | 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), | 416 | 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), |
425 | traffic_received, | 417 | traffic_received, |
426 | GNUNET_STRINGS_relative_time_to_string (duration, | 418 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); |
427 | GNUNET_YES)); | ||
428 | } | 419 | } |
429 | 420 | ||
430 | if (NULL != monitored_peers) | 421 | if (NULL != monitored_peers) |
431 | { | 422 | { |
432 | GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, | 423 | GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL); |
433 | &destroy_it, | ||
434 | NULL); | ||
435 | GNUNET_CONTAINER_multipeermap_destroy (monitored_peers); | 424 | GNUNET_CONTAINER_multipeermap_destroy (monitored_peers); |
436 | monitored_peers = NULL; | 425 | monitored_peers = NULL; |
437 | } | 426 | } |
438 | if (NULL != monitored_plugins) | 427 | if (NULL != monitored_plugins) |
439 | { | 428 | { |
440 | GNUNET_break (0 == | 429 | GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins)); |
441 | GNUNET_CONTAINER_multipeermap_size (monitored_plugins)); | ||
442 | GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins); | 430 | GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins); |
443 | monitored_plugins = NULL; | 431 | monitored_plugins = NULL; |
444 | } | 432 | } |
@@ -463,9 +451,7 @@ operation_timeout (void *cls) | |||
463 | op_timeout = NULL; | 451 | op_timeout = NULL; |
464 | if ((benchmark_send) || (benchmark_receive)) | 452 | if ((benchmark_send) || (benchmark_receive)) |
465 | { | 453 | { |
466 | FPRINTF (stdout, | 454 | FPRINTF (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); |
467 | _("Failed to connect to `%s'\n"), | ||
468 | GNUNET_i2s_full (&pid)); | ||
469 | GNUNET_SCHEDULER_shutdown (); | 455 | GNUNET_SCHEDULER_shutdown (); |
470 | ret = 1; | 456 | ret = 1; |
471 | return; | 457 | return; |
@@ -477,21 +463,18 @@ operation_timeout (void *cls) | |||
477 | { | 463 | { |
478 | next = cur->next; | 464 | next = cur->next; |
479 | FPRINTF (stdout, | 465 | FPRINTF (stdout, |
480 | _("Failed to resolve address for peer `%s'\n"), | 466 | _ ("Failed to resolve address for peer `%s'\n"), |
481 | GNUNET_i2s (&cur->addrcp->peer)); | 467 | GNUNET_i2s (&cur->addrcp->peer)); |
482 | 468 | ||
483 | GNUNET_CONTAINER_DLL_remove(rc_head, | 469 | GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur); |
484 | rc_tail, | ||
485 | cur); | ||
486 | GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); | 470 | GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); |
487 | GNUNET_free (cur->transport); | 471 | GNUNET_free (cur->transport); |
488 | GNUNET_free (cur->addrcp); | 472 | GNUNET_free (cur->addrcp); |
489 | GNUNET_free (cur); | 473 | GNUNET_free (cur); |
490 | |||
491 | } | 474 | } |
492 | FPRINTF (stdout, | 475 | FPRINTF (stdout, |
493 | "%s", | 476 | "%s", |
494 | _("Failed to list connections, timeout occurred\n")); | 477 | _ ("Failed to list connections, timeout occurred\n")); |
495 | GNUNET_SCHEDULER_shutdown (); | 478 | GNUNET_SCHEDULER_shutdown (); |
496 | ret = 1; | 479 | ret = 1; |
497 | return; | 480 | return; |
@@ -512,22 +495,15 @@ do_send (void *cls) | |||
512 | struct GNUNET_MessageHeader *m; | 495 | struct GNUNET_MessageHeader *m; |
513 | struct GNUNET_MQ_Envelope *env; | 496 | struct GNUNET_MQ_Envelope *env; |
514 | 497 | ||
515 | env = GNUNET_MQ_msg_extra (m, | 498 | env = GNUNET_MQ_msg_extra (m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY); |
516 | BLOCKSIZE * 1024, | 499 | memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof (struct GNUNET_MessageHeader)); |
517 | GNUNET_MESSAGE_TYPE_DUMMY); | ||
518 | memset (&m[1], | ||
519 | 52, | ||
520 | BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader)); | ||
521 | traffic_sent += BLOCKSIZE * 1024; | 500 | traffic_sent += BLOCKSIZE * 1024; |
522 | GNUNET_MQ_notify_sent (env, | 501 | GNUNET_MQ_notify_sent (env, &do_send, mq); |
523 | &do_send, | ||
524 | mq); | ||
525 | if (verbosity > 0) | 502 | if (verbosity > 0) |
526 | FPRINTF (stdout, | 503 | FPRINTF (stdout, |
527 | _("Transmitting %u bytes\n"), | 504 | _ ("Transmitting %u bytes\n"), |
528 | (unsigned int) BLOCKSIZE * 1024); | 505 | (unsigned int) BLOCKSIZE * 1024); |
529 | GNUNET_MQ_send (mq, | 506 | GNUNET_MQ_send (mq, env); |
530 | env); | ||
531 | } | 507 | } |
532 | 508 | ||
533 | 509 | ||
@@ -542,11 +518,9 @@ do_send (void *cls) | |||
542 | static void * | 518 | static void * |
543 | notify_connect (void *cls, | 519 | notify_connect (void *cls, |
544 | const struct GNUNET_PeerIdentity *peer, | 520 | const struct GNUNET_PeerIdentity *peer, |
545 | struct GNUNET_MQ_Handle *mq) | 521 | struct GNUNET_MQ_Handle *mq) |
546 | { | 522 | { |
547 | if (0 != memcmp (&pid, | 523 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
548 | peer, | ||
549 | sizeof(struct GNUNET_PeerIdentity))) | ||
550 | return NULL; | 524 | return NULL; |
551 | ret = 0; | 525 | ret = 0; |
552 | if (! benchmark_send) | 526 | if (! benchmark_send) |
@@ -557,10 +531,12 @@ notify_connect (void *cls, | |||
557 | op_timeout = NULL; | 531 | op_timeout = NULL; |
558 | } | 532 | } |
559 | if (verbosity > 0) | 533 | if (verbosity > 0) |
560 | FPRINTF (stdout, | 534 | FPRINTF ( |
561 | _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), | 535 | stdout, |
562 | GNUNET_i2s (peer), | 536 | _ ( |
563 | BLOCKSIZE); | 537 | "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), |
538 | GNUNET_i2s (peer), | ||
539 | BLOCKSIZE); | ||
564 | start_time = GNUNET_TIME_absolute_get (); | 540 | start_time = GNUNET_TIME_absolute_get (); |
565 | do_send (mq); | 541 | do_send (mq); |
566 | return mq; | 542 | return mq; |
@@ -578,19 +554,17 @@ notify_connect (void *cls, | |||
578 | static void | 554 | static void |
579 | notify_disconnect (void *cls, | 555 | notify_disconnect (void *cls, |
580 | const struct GNUNET_PeerIdentity *peer, | 556 | const struct GNUNET_PeerIdentity *peer, |
581 | void *internal_cls) | 557 | void *internal_cls) |
582 | { | 558 | { |
583 | if (0 != memcmp (&pid, | 559 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
584 | peer, | ||
585 | sizeof(struct GNUNET_PeerIdentity))) | ||
586 | return; | 560 | return; |
587 | if (NULL == internal_cls) | 561 | if (NULL == internal_cls) |
588 | return; /* not about target peer */ | 562 | return; /* not about target peer */ |
589 | if (! benchmark_send) | 563 | if (! benchmark_send) |
590 | return; /* not transmitting */ | 564 | return; /* not transmitting */ |
591 | FPRINTF (stdout, | 565 | FPRINTF (stdout, |
592 | _("Disconnected from peer `%s' while benchmarking\n"), | 566 | _ ("Disconnected from peer `%s' while benchmarking\n"), |
593 | GNUNET_i2s (&pid)); | 567 | GNUNET_i2s (&pid)); |
594 | } | 568 | } |
595 | 569 | ||
596 | 570 | ||
@@ -606,16 +580,16 @@ notify_disconnect (void *cls, | |||
606 | static void * | 580 | static void * |
607 | monitor_notify_connect (void *cls, | 581 | monitor_notify_connect (void *cls, |
608 | const struct GNUNET_PeerIdentity *peer, | 582 | const struct GNUNET_PeerIdentity *peer, |
609 | struct GNUNET_MQ_Handle *mq) | 583 | struct GNUNET_MQ_Handle *mq) |
610 | { | 584 | { |
611 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 585 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
612 | const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 586 | const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); |
613 | 587 | ||
614 | monitor_connect_counter++; | 588 | monitor_connect_counter++; |
615 | FPRINTF (stdout, | 589 | FPRINTF (stdout, |
616 | _("%24s: %-17s %4s (%u connections in total)\n"), | 590 | _ ("%24s: %-17s %4s (%u connections in total)\n"), |
617 | now_str, | 591 | now_str, |
618 | _("Connected to"), | 592 | _ ("Connected to"), |
619 | GNUNET_i2s (peer), | 593 | GNUNET_i2s (peer), |
620 | monitor_connect_counter); | 594 | monitor_connect_counter); |
621 | return NULL; | 595 | return NULL; |
@@ -633,18 +607,18 @@ monitor_notify_connect (void *cls, | |||
633 | static void | 607 | static void |
634 | monitor_notify_disconnect (void *cls, | 608 | monitor_notify_disconnect (void *cls, |
635 | const struct GNUNET_PeerIdentity *peer, | 609 | const struct GNUNET_PeerIdentity *peer, |
636 | void *internal_cls) | 610 | void *internal_cls) |
637 | { | 611 | { |
638 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 612 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
639 | const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 613 | const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); |
640 | 614 | ||
641 | GNUNET_assert(monitor_connect_counter > 0); | 615 | GNUNET_assert (monitor_connect_counter > 0); |
642 | monitor_connect_counter--; | 616 | monitor_connect_counter--; |
643 | 617 | ||
644 | FPRINTF (stdout, | 618 | FPRINTF (stdout, |
645 | _("%24s: %-17s %4s (%u connections in total)\n"), | 619 | _ ("%24s: %-17s %4s (%u connections in total)\n"), |
646 | now_str, | 620 | now_str, |
647 | _("Disconnected from"), | 621 | _ ("Disconnected from"), |
648 | GNUNET_i2s (peer), | 622 | GNUNET_i2s (peer), |
649 | monitor_connect_counter); | 623 | monitor_connect_counter); |
650 | } | 624 | } |
@@ -658,8 +632,7 @@ monitor_notify_disconnect (void *cls, | |||
658 | * @return #GNUNET_OK | 632 | * @return #GNUNET_OK |
659 | */ | 633 | */ |
660 | static int | 634 | static int |
661 | check_dummy (void *cls, | 635 | check_dummy (void *cls, const struct GNUNET_MessageHeader *message) |
662 | const struct GNUNET_MessageHeader *message) | ||
663 | { | 636 | { |
664 | return GNUNET_OK; /* all messages are fine */ | 637 | return GNUNET_OK; /* all messages are fine */ |
665 | } | 638 | } |
@@ -672,15 +645,14 @@ check_dummy (void *cls, | |||
672 | * @param message the message | 645 | * @param message the message |
673 | */ | 646 | */ |
674 | static void | 647 | static void |
675 | handle_dummy (void *cls, | 648 | handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) |
676 | const struct GNUNET_MessageHeader *message) | ||
677 | { | 649 | { |
678 | if (! benchmark_receive) | 650 | if (! benchmark_receive) |
679 | return; | 651 | return; |
680 | if (verbosity > 0) | 652 | if (verbosity > 0) |
681 | FPRINTF (stdout, | 653 | FPRINTF (stdout, |
682 | _("Received %u bytes\n"), | 654 | _ ("Received %u bytes\n"), |
683 | (unsigned int) ntohs (message->size)); | 655 | (unsigned int) ntohs (message->size)); |
684 | if (0 == traffic_received) | 656 | if (0 == traffic_received) |
685 | start_time = GNUNET_TIME_absolute_get (); | 657 | start_time = GNUNET_TIME_absolute_get (); |
686 | traffic_received += ntohs (message->size); | 658 | traffic_received += ntohs (message->size); |
@@ -711,24 +683,23 @@ print_info (const struct GNUNET_PeerIdentity *id, | |||
711 | struct GNUNET_TIME_Absolute state_timeout) | 683 | struct GNUNET_TIME_Absolute state_timeout) |
712 | { | 684 | { |
713 | 685 | ||
714 | if ( ((GNUNET_YES == iterate_connections) && | 686 | if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || |
715 | (GNUNET_YES == iterate_all)) || | 687 | (GNUNET_YES == monitor_connections)) |
716 | (GNUNET_YES == monitor_connections)) | ||
717 | { | 688 | { |
718 | FPRINTF (stdout, | 689 | FPRINTF (stdout, |
719 | _("Peer `%s': %s %s in state `%s' until %s\n"), | 690 | _ ("Peer `%s': %s %s in state `%s' until %s\n"), |
720 | GNUNET_i2s (id), | 691 | GNUNET_i2s (id), |
721 | (NULL == transport) ? "<none>" : transport, | 692 | (NULL == transport) ? "<none>" : transport, |
722 | (NULL == transport) ? "<none>" : addr, | 693 | (NULL == transport) ? "<none>" : addr, |
723 | GNUNET_TRANSPORT_ps2s (state), | 694 | GNUNET_TRANSPORT_ps2s (state), |
724 | GNUNET_STRINGS_absolute_time_to_string (state_timeout)); | 695 | GNUNET_STRINGS_absolute_time_to_string (state_timeout)); |
725 | } | 696 | } |
726 | else if ( (GNUNET_YES == iterate_connections) && | 697 | else if ((GNUNET_YES == iterate_connections) && |
727 | (GNUNET_TRANSPORT_is_connected(state)) ) | 698 | (GNUNET_TRANSPORT_is_connected (state))) |
728 | { | 699 | { |
729 | /* Only connected peers, skip state */ | 700 | /* Only connected peers, skip state */ |
730 | FPRINTF (stdout, | 701 | FPRINTF (stdout, |
731 | _("Peer `%s': %s %s\n"), | 702 | _ ("Peer `%s': %s %s\n"), |
732 | GNUNET_i2s (id), | 703 | GNUNET_i2s (id), |
733 | transport, | 704 | transport, |
734 | addr); | 705 | addr); |
@@ -753,9 +724,7 @@ print_info (const struct GNUNET_PeerIdentity *id, | |||
753 | * if #GNUNET_SYSERR: communication error (IPC error) | 724 | * if #GNUNET_SYSERR: communication error (IPC error) |
754 | */ | 725 | */ |
755 | static void | 726 | static void |
756 | process_peer_string (void *cls, | 727 | process_peer_string (void *cls, const char *address, int res) |
757 | const char *address, | ||
758 | int res) | ||
759 | { | 728 | { |
760 | struct PeerResolutionContext *rc = cls; | 729 | struct PeerResolutionContext *rc = cls; |
761 | 730 | ||
@@ -763,11 +732,12 @@ process_peer_string (void *cls, | |||
763 | { | 732 | { |
764 | if (GNUNET_SYSERR == res) | 733 | if (GNUNET_SYSERR == res) |
765 | { | 734 | { |
766 | FPRINTF (stderr, | 735 | FPRINTF ( |
767 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", | 736 | stderr, |
768 | GNUNET_i2s (&rc->addrcp->peer), | 737 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", |
769 | rc->addrcp->transport_name, | 738 | GNUNET_i2s (&rc->addrcp->peer), |
770 | (unsigned int) rc->addrcp->address_length); | 739 | rc->addrcp->transport_name, |
740 | (unsigned int) rc->addrcp->address_length); | ||
771 | print_info (&rc->addrcp->peer, | 741 | print_info (&rc->addrcp->peer, |
772 | rc->transport, | 742 | rc->transport, |
773 | NULL, | 743 | NULL, |
@@ -818,9 +788,7 @@ process_peer_string (void *cls, | |||
818 | } | 788 | } |
819 | GNUNET_free (rc->transport); | 789 | GNUNET_free (rc->transport); |
820 | GNUNET_free (rc->addrcp); | 790 | GNUNET_free (rc->addrcp); |
821 | GNUNET_CONTAINER_DLL_remove (rc_head, | 791 | GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); |
822 | rc_tail, | ||
823 | rc); | ||
824 | GNUNET_free (rc); | 792 | GNUNET_free (rc); |
825 | if ((0 == address_resolutions) && (iterate_connections)) | 793 | if ((0 == address_resolutions) && (iterate_connections)) |
826 | { | 794 | { |
@@ -854,9 +822,7 @@ resolve_peer_address (const struct GNUNET_HELLO_Address *address, | |||
854 | struct PeerResolutionContext *rc; | 822 | struct PeerResolutionContext *rc; |
855 | 823 | ||
856 | rc = GNUNET_new (struct PeerResolutionContext); | 824 | rc = GNUNET_new (struct PeerResolutionContext); |
857 | GNUNET_CONTAINER_DLL_insert (rc_head, | 825 | GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); |
858 | rc_tail, | ||
859 | rc); | ||
860 | address_resolutions++; | 826 | address_resolutions++; |
861 | rc->transport = GNUNET_strdup (address->transport_name); | 827 | rc->transport = GNUNET_strdup (address->transport_name); |
862 | rc->addrcp = GNUNET_HELLO_address_copy (address); | 828 | rc->addrcp = GNUNET_HELLO_address_copy (address); |
@@ -869,7 +835,7 @@ resolve_peer_address (const struct GNUNET_HELLO_Address *address, | |||
869 | numeric, | 835 | numeric, |
870 | RESOLUTION_TIMEOUT, | 836 | RESOLUTION_TIMEOUT, |
871 | &process_peer_string, | 837 | &process_peer_string, |
872 | rc); | 838 | rc); |
873 | } | 839 | } |
874 | 840 | ||
875 | 841 | ||
@@ -897,15 +863,14 @@ process_peer_iteration_cb (void *cls, | |||
897 | return; | 863 | return; |
898 | } | 864 | } |
899 | 865 | ||
900 | if ( (GNUNET_NO == iterate_all) && | 866 | if ((GNUNET_NO == iterate_all) && |
901 | (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state))) | 867 | (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state))) |
902 | return; /* Display only connected peers */ | 868 | return; /* Display only connected peers */ |
903 | 869 | ||
904 | if (NULL != op_timeout) | 870 | if (NULL != op_timeout) |
905 | GNUNET_SCHEDULER_cancel (op_timeout); | 871 | GNUNET_SCHEDULER_cancel (op_timeout); |
906 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, | 872 | op_timeout = |
907 | &operation_timeout, | 873 | GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); |
908 | NULL); | ||
909 | 874 | ||
910 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
911 | "Received address for peer `%s': %s\n", | 876 | "Received address for peer `%s': %s\n", |
@@ -913,16 +878,9 @@ process_peer_iteration_cb (void *cls, | |||
913 | address ? address->transport_name : ""); | 878 | address ? address->transport_name : ""); |
914 | 879 | ||
915 | if (NULL != address) | 880 | if (NULL != address) |
916 | resolve_peer_address (address, | 881 | resolve_peer_address (address, numeric, state, state_timeout); |
917 | numeric, | ||
918 | state, | ||
919 | state_timeout); | ||
920 | else | 882 | else |
921 | print_info (peer, | 883 | print_info (peer, NULL, NULL, state, state_timeout); |
922 | NULL, | ||
923 | NULL, | ||
924 | state, | ||
925 | state_timeout); | ||
926 | } | 884 | } |
927 | 885 | ||
928 | 886 | ||
@@ -958,7 +916,7 @@ struct PluginMonitorAddress | |||
958 | */ | 916 | */ |
959 | static void | 917 | static void |
960 | print_plugin_event_info (struct PluginMonitorAddress *addr, | 918 | print_plugin_event_info (struct PluginMonitorAddress *addr, |
961 | const struct GNUNET_TRANSPORT_SessionInfo *info) | 919 | const struct GNUNET_TRANSPORT_SessionInfo *info) |
962 | { | 920 | { |
963 | const char *state; | 921 | const char *state; |
964 | 922 | ||
@@ -987,20 +945,22 @@ print_plugin_event_info (struct PluginMonitorAddress *addr, | |||
987 | "%s: state %s timeout in %s @ %s%s\n", | 945 | "%s: state %s timeout in %s @ %s%s\n", |
988 | GNUNET_i2s (&info->address->peer), | 946 | GNUNET_i2s (&info->address->peer), |
989 | state, | 947 | state, |
990 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (info->session_timeout), | 948 | GNUNET_STRINGS_relative_time_to_string ( |
991 | GNUNET_YES), | 949 | GNUNET_TIME_absolute_get_remaining (info->session_timeout), |
992 | addr->str, | 950 | GNUNET_YES), |
951 | addr->str, | ||
993 | (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); | 952 | (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); |
994 | fprintf (stdout, | 953 | fprintf (stdout, |
995 | "%s: queue has %3u messages and %6u bytes\n", | 954 | "%s: queue has %3u messages and %6u bytes\n", |
996 | GNUNET_i2s (&info->address->peer), | 955 | GNUNET_i2s (&info->address->peer), |
997 | info->num_msg_pending, | 956 | info->num_msg_pending, |
998 | info->num_bytes_pending); | 957 | info->num_bytes_pending); |
999 | if (0 != GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us) | 958 | if (0 != |
959 | GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us) | ||
1000 | fprintf (stdout, | 960 | fprintf (stdout, |
1001 | "%s: receiving blocked until %s\n", | 961 | "%s: receiving blocked until %s\n", |
1002 | GNUNET_i2s (&info->address->peer), | 962 | GNUNET_i2s (&info->address->peer), |
1003 | GNUNET_STRINGS_absolute_time_to_string (info->receive_delay)); | 963 | GNUNET_STRINGS_absolute_time_to_string (info->receive_delay)); |
1004 | } | 964 | } |
1005 | 965 | ||
1006 | 966 | ||
@@ -1021,9 +981,7 @@ print_plugin_event_info (struct PluginMonitorAddress *addr, | |||
1021 | * if #GNUNET_SYSERR: communication error (IPC error) | 981 | * if #GNUNET_SYSERR: communication error (IPC error) |
1022 | */ | 982 | */ |
1023 | static void | 983 | static void |
1024 | address_cb (void *cls, | 984 | address_cb (void *cls, const char *address, int res) |
1025 | const char *address, | ||
1026 | int res) | ||
1027 | { | 985 | { |
1028 | struct PluginMonitorAddress *addr = cls; | 986 | struct PluginMonitorAddress *addr = cls; |
1029 | 987 | ||
@@ -1035,8 +993,7 @@ address_cb (void *cls, | |||
1035 | if (NULL != addr->str) | 993 | if (NULL != addr->str) |
1036 | return; | 994 | return; |
1037 | addr->str = GNUNET_strdup (address); | 995 | addr->str = GNUNET_strdup (address); |
1038 | print_plugin_event_info (addr, | 996 | print_plugin_event_info (addr, &addr->si); |
1039 | &addr->si); | ||
1040 | } | 997 | } |
1041 | 998 | ||
1042 | 999 | ||
@@ -1065,8 +1022,7 @@ plugin_monitoring_cb (void *cls, | |||
1065 | { | 1022 | { |
1066 | struct PluginMonitorAddress *addr; | 1023 | struct PluginMonitorAddress *addr; |
1067 | 1024 | ||
1068 | if ( (NULL == info) && | 1025 | if ((NULL == info) && (NULL == session)) |
1069 | (NULL == session) ) | ||
1070 | return; /* in sync with transport service */ | 1026 | return; /* in sync with transport service */ |
1071 | addr = *session_ctx; | 1027 | addr = *session_ctx; |
1072 | if (NULL == info) | 1028 | if (NULL == info) |
@@ -1084,26 +1040,25 @@ plugin_monitoring_cb (void *cls, | |||
1084 | } | 1040 | } |
1085 | return; /* shutdown */ | 1041 | return; /* shutdown */ |
1086 | } | 1042 | } |
1087 | if (0 != memcmp (&info->address->peer, | 1043 | if (0 != |
1088 | &pid, | 1044 | memcmp (&info->address->peer, &pid, sizeof (struct GNUNET_PeerIdentity))) |
1089 | sizeof (struct GNUNET_PeerIdentity))) | ||
1090 | return; /* filtered */ | 1045 | return; /* filtered */ |
1091 | if (NULL == addr) | 1046 | if (NULL == addr) |
1092 | { | 1047 | { |
1093 | addr = GNUNET_new (struct PluginMonitorAddress); | 1048 | addr = GNUNET_new (struct PluginMonitorAddress); |
1094 | addr->asc = GNUNET_TRANSPORT_address_to_string (cfg, | 1049 | addr->asc = |
1095 | info->address, | 1050 | GNUNET_TRANSPORT_address_to_string (cfg, |
1096 | numeric, | 1051 | info->address, |
1097 | GNUNET_TIME_UNIT_FOREVER_REL, | 1052 | numeric, |
1098 | &address_cb, | 1053 | GNUNET_TIME_UNIT_FOREVER_REL, |
1099 | addr); | 1054 | &address_cb, |
1055 | addr); | ||
1100 | *session_ctx = addr; | 1056 | *session_ctx = addr; |
1101 | } | 1057 | } |
1102 | if (NULL == addr->str) | 1058 | if (NULL == addr->str) |
1103 | addr->si = *info; | 1059 | addr->si = *info; |
1104 | else | 1060 | else |
1105 | print_plugin_event_info (addr, | 1061 | print_plugin_event_info (addr, info); |
1106 | info); | ||
1107 | if (GNUNET_TRANSPORT_SS_DONE == info->state) | 1062 | if (GNUNET_TRANSPORT_SS_DONE == info->state) |
1108 | { | 1063 | { |
1109 | if (NULL != addr->asc) | 1064 | if (NULL != addr->asc) |
@@ -1141,38 +1096,35 @@ process_peer_monitoring_cb (void *cls, | |||
1141 | { | 1096 | { |
1142 | FPRINTF (stdout, | 1097 | FPRINTF (stdout, |
1143 | "%s", | 1098 | "%s", |
1144 | _("Monitor disconnected from transport service. Reconnecting.\n")); | 1099 | _ ( |
1100 | "Monitor disconnected from transport service. Reconnecting.\n")); | ||
1145 | return; | 1101 | return; |
1146 | } | 1102 | } |
1147 | 1103 | ||
1148 | if (NULL != op_timeout) | 1104 | if (NULL != op_timeout) |
1149 | GNUNET_SCHEDULER_cancel (op_timeout); | 1105 | GNUNET_SCHEDULER_cancel (op_timeout); |
1150 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, | 1106 | op_timeout = |
1151 | &operation_timeout, | 1107 | GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); |
1152 | NULL); | ||
1153 | 1108 | ||
1154 | if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, | 1109 | if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) |
1155 | peer))) | ||
1156 | { | 1110 | { |
1157 | m = GNUNET_new (struct MonitoredPeer); | 1111 | m = GNUNET_new (struct MonitoredPeer); |
1158 | GNUNET_CONTAINER_multipeermap_put (monitored_peers, | 1112 | GNUNET_CONTAINER_multipeermap_put ( |
1159 | peer, | 1113 | monitored_peers, |
1160 | m, | 1114 | peer, |
1161 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1115 | m, |
1116 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
1162 | } | 1117 | } |
1163 | else | 1118 | else |
1164 | { | 1119 | { |
1165 | if ( (m->state == state) && | 1120 | if ((m->state == state) && |
1166 | (m->state_timeout.abs_value_us == state_timeout.abs_value_us) && | 1121 | (m->state_timeout.abs_value_us == state_timeout.abs_value_us) && |
1167 | (NULL == address) && | 1122 | (NULL == address) && (NULL == m->address)) |
1168 | (NULL == m->address) ) | ||
1169 | { | 1123 | { |
1170 | return; /* No real change */ | 1124 | return; /* No real change */ |
1171 | } | 1125 | } |
1172 | if ( (m->state == state) && | 1126 | if ((m->state == state) && (NULL != address) && (NULL != m->address) && |
1173 | (NULL != address) && | 1127 | (0 == GNUNET_HELLO_address_cmp (m->address, address))) |
1174 | (NULL != m->address) && | ||
1175 | (0 == GNUNET_HELLO_address_cmp(m->address, address)) ) | ||
1176 | return; /* No real change */ | 1128 | return; /* No real change */ |
1177 | } | 1129 | } |
1178 | 1130 | ||
@@ -1187,16 +1139,9 @@ process_peer_monitoring_cb (void *cls, | |||
1187 | m->state_timeout = state_timeout; | 1139 | m->state_timeout = state_timeout; |
1188 | 1140 | ||
1189 | if (NULL != address) | 1141 | if (NULL != address) |
1190 | resolve_peer_address (m->address, | 1142 | resolve_peer_address (m->address, numeric, m->state, m->state_timeout); |
1191 | numeric, | ||
1192 | m->state, | ||
1193 | m->state_timeout); | ||
1194 | else | 1143 | else |
1195 | print_info (peer, | 1144 | print_info (peer, NULL, NULL, m->state, m->state_timeout); |
1196 | NULL, | ||
1197 | NULL, | ||
1198 | m->state, | ||
1199 | m->state_timeout); | ||
1200 | } | 1145 | } |
1201 | 1146 | ||
1202 | 1147 | ||
@@ -1210,12 +1155,9 @@ process_peer_monitoring_cb (void *cls, | |||
1210 | * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not | 1155 | * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not |
1211 | */ | 1156 | */ |
1212 | static int | 1157 | static int |
1213 | blacklist_cb (void *cls, | 1158 | blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid) |
1214 | const struct GNUNET_PeerIdentity *cpid) | ||
1215 | { | 1159 | { |
1216 | if (0 == memcmp (cpid, | 1160 | if (0 == memcmp (cpid, &pid, sizeof (struct GNUNET_PeerIdentity))) |
1217 | &pid, | ||
1218 | sizeof (struct GNUNET_PeerIdentity))) | ||
1219 | return GNUNET_SYSERR; | 1161 | return GNUNET_SYSERR; |
1220 | return GNUNET_OK; | 1162 | return GNUNET_OK; |
1221 | } | 1163 | } |
@@ -1231,7 +1173,7 @@ blacklist_cb (void *cls, | |||
1231 | */ | 1173 | */ |
1232 | static void | 1174 | static void |
1233 | run (void *cls, | 1175 | run (void *cls, |
1234 | char * const *args, | 1176 | char *const *args, |
1235 | const char *cfgfile, | 1177 | const char *cfgfile, |
1236 | const struct GNUNET_CONFIGURATION_Handle *mycfg) | 1178 | const struct GNUNET_CONFIGURATION_Handle *mycfg) |
1237 | { | 1179 | { |
@@ -1241,127 +1183,119 @@ run (void *cls, | |||
1241 | 1183 | ||
1242 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; | 1184 | cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; |
1243 | 1185 | ||
1244 | counter = benchmark_send + benchmark_receive + iterate_connections | 1186 | counter = benchmark_send + benchmark_receive + iterate_connections + |
1245 | + monitor_connections + monitor_connects + do_disconnect + | 1187 | monitor_connections + monitor_connects + do_disconnect + |
1246 | monitor_plugins; | 1188 | monitor_plugins; |
1247 | 1189 | ||
1248 | if (1 < counter) | 1190 | if (1 < counter) |
1249 | { | 1191 | { |
1250 | FPRINTF (stderr, | 1192 | FPRINTF ( |
1251 | _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), | 1193 | stderr, |
1252 | "disconnect", | 1194 | _ ( |
1253 | "benchmark send", | 1195 | "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), |
1254 | "benchmark receive", | 1196 | "disconnect", |
1255 | "information", | 1197 | "benchmark send", |
1256 | "monitor", | 1198 | "benchmark receive", |
1257 | "events", | 1199 | "information", |
1258 | "plugins"); | 1200 | "monitor", |
1201 | "events", | ||
1202 | "plugins"); | ||
1259 | return; | 1203 | return; |
1260 | } | 1204 | } |
1261 | if (0 == counter) | 1205 | if (0 == counter) |
1262 | { | 1206 | { |
1263 | FPRINTF (stderr, | 1207 | FPRINTF ( |
1264 | _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), | 1208 | stderr, |
1265 | "disconnect", | 1209 | _ ( |
1266 | "benchmark send", | 1210 | "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), |
1267 | "benchmark receive", | 1211 | "disconnect", |
1268 | "information", | 1212 | "benchmark send", |
1269 | "monitor", | 1213 | "benchmark receive", |
1270 | "events", | 1214 | "information", |
1271 | "plugins"); | 1215 | "monitor", |
1216 | "events", | ||
1217 | "plugins"); | ||
1272 | return; | 1218 | return; |
1273 | } | 1219 | } |
1274 | 1220 | ||
1275 | if (do_disconnect) /* -D: Disconnect from peer */ | 1221 | if (do_disconnect) /* -D: Disconnect from peer */ |
1276 | { | 1222 | { |
1277 | if (0 == memcmp (&zero_pid, | 1223 | if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) |
1278 | &pid, | ||
1279 | sizeof (pid))) | ||
1280 | { | 1224 | { |
1281 | FPRINTF (stderr, | 1225 | FPRINTF (stderr, |
1282 | _("Option `%s' makes no sense without option `%s'.\n"), | 1226 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
1283 | "-D", "-p"); | 1227 | "-D", |
1228 | "-p"); | ||
1284 | ret = 1; | 1229 | ret = 1; |
1285 | return; | 1230 | return; |
1286 | } | 1231 | } |
1287 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, | 1232 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); |
1288 | &blacklist_cb, | ||
1289 | NULL); | ||
1290 | if (NULL == blacklist) | 1233 | if (NULL == blacklist) |
1291 | { | 1234 | { |
1292 | FPRINTF (stderr, | 1235 | FPRINTF (stderr, |
1293 | "%s", | 1236 | "%s", |
1294 | _("Failed to connect to transport service for disconnection\n")); | 1237 | _ ( |
1238 | "Failed to connect to transport service for disconnection\n")); | ||
1295 | ret = 1; | 1239 | ret = 1; |
1296 | return; | 1240 | return; |
1297 | } | 1241 | } |
1298 | FPRINTF (stdout, | 1242 | FPRINTF (stdout, |
1299 | "%s", | 1243 | "%s", |
1300 | _("Blacklisting request in place, stop with CTRL-C\n")); | 1244 | _ ("Blacklisting request in place, stop with CTRL-C\n")); |
1301 | } | 1245 | } |
1302 | else if (benchmark_send) /* -s: Benchmark sending */ | 1246 | else if (benchmark_send) /* -s: Benchmark sending */ |
1303 | { | 1247 | { |
1304 | if (0 == memcmp (&zero_pid, | 1248 | if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) |
1305 | &pid, | ||
1306 | sizeof (pid))) | ||
1307 | { | 1249 | { |
1308 | FPRINTF (stderr, | 1250 | FPRINTF (stderr, |
1309 | _("Option `%s' makes no sense without option `%s'.\n"), | 1251 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
1310 | "-s", "-p"); | 1252 | "-s", |
1253 | "-p"); | ||
1311 | ret = 1; | 1254 | ret = 1; |
1312 | return; | 1255 | return; |
1313 | } | 1256 | } |
1314 | handle = GNUNET_TRANSPORT_core_connect (cfg, | 1257 | handle = GNUNET_TRANSPORT_core_connect (cfg, |
1315 | NULL, | 1258 | NULL, |
1316 | NULL, | 1259 | NULL, |
1317 | NULL, | 1260 | NULL, |
1318 | ¬ify_connect, | 1261 | ¬ify_connect, |
1319 | ¬ify_disconnect, | 1262 | ¬ify_disconnect, |
1320 | NULL); | 1263 | NULL); |
1321 | if (NULL == handle) | 1264 | if (NULL == handle) |
1322 | { | 1265 | { |
1323 | FPRINTF (stderr, | 1266 | FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); |
1324 | "%s", | ||
1325 | _("Failed to connect to transport service\n")); | ||
1326 | ret = 1; | 1267 | ret = 1; |
1327 | return; | 1268 | return; |
1328 | } | 1269 | } |
1329 | start_time = GNUNET_TIME_absolute_get (); | 1270 | start_time = GNUNET_TIME_absolute_get (); |
1330 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, | 1271 | op_timeout = |
1331 | &operation_timeout, | 1272 | GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); |
1332 | NULL); | ||
1333 | } | 1273 | } |
1334 | else if (benchmark_receive) /* -b: Benchmark receiving */ | 1274 | else if (benchmark_receive) /* -b: Benchmark receiving */ |
1335 | { | 1275 | { |
1336 | struct GNUNET_MQ_MessageHandler handlers[] = { | 1276 | struct GNUNET_MQ_MessageHandler handlers[] = |
1337 | GNUNET_MQ_hd_var_size (dummy, | 1277 | {GNUNET_MQ_hd_var_size (dummy, |
1338 | GNUNET_MESSAGE_TYPE_DUMMY, | 1278 | GNUNET_MESSAGE_TYPE_DUMMY, |
1339 | struct GNUNET_MessageHeader, | 1279 | struct GNUNET_MessageHeader, |
1340 | NULL), | 1280 | NULL), |
1341 | GNUNET_MQ_handler_end () | 1281 | GNUNET_MQ_handler_end ()}; |
1342 | }; | ||
1343 | 1282 | ||
1344 | handle = GNUNET_TRANSPORT_core_connect (cfg, | 1283 | handle = GNUNET_TRANSPORT_core_connect (cfg, |
1345 | NULL, | 1284 | NULL, |
1346 | handlers, | 1285 | handlers, |
1347 | NULL, | 1286 | NULL, |
1348 | NULL, | 1287 | NULL, |
1349 | NULL, | 1288 | NULL, |
1350 | NULL); | 1289 | NULL); |
1351 | if (NULL == handle) | 1290 | if (NULL == handle) |
1352 | { | 1291 | { |
1353 | FPRINTF (stderr, | 1292 | FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); |
1354 | "%s", | ||
1355 | _("Failed to connect to transport service\n")); | ||
1356 | ret = 1; | 1293 | ret = 1; |
1357 | return; | 1294 | return; |
1358 | } | 1295 | } |
1359 | if (verbosity > 0) | 1296 | if (verbosity > 0) |
1360 | FPRINTF (stdout, | 1297 | FPRINTF (stdout, "%s", _ ("Starting to receive benchmark data\n")); |
1361 | "%s", | ||
1362 | _("Starting to receive benchmark data\n")); | ||
1363 | start_time = GNUNET_TIME_absolute_get (); | 1298 | start_time = GNUNET_TIME_absolute_get (); |
1364 | |||
1365 | } | 1299 | } |
1366 | else if (iterate_connections) /* -i: List information about peers once */ | 1300 | else if (iterate_connections) /* -i: List information about peers once */ |
1367 | { | 1301 | { |
@@ -1370,42 +1304,38 @@ run (void *cls, | |||
1370 | GNUNET_YES, | 1304 | GNUNET_YES, |
1371 | &process_peer_iteration_cb, | 1305 | &process_peer_iteration_cb, |
1372 | (void *) cfg); | 1306 | (void *) cfg); |
1373 | op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, | 1307 | op_timeout = |
1374 | &operation_timeout, | 1308 | GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); |
1375 | NULL); | ||
1376 | } | 1309 | } |
1377 | else if (monitor_connections) /* -m: List information about peers continuously */ | 1310 | else if (monitor_connections) /* -m: List information about peers continuously |
1311 | */ | ||
1378 | { | 1312 | { |
1379 | monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, | 1313 | monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1380 | GNUNET_NO); | ||
1381 | pic = GNUNET_TRANSPORT_monitor_peers (cfg, | 1314 | pic = GNUNET_TRANSPORT_monitor_peers (cfg, |
1382 | &pid, | 1315 | &pid, |
1383 | GNUNET_NO, | 1316 | GNUNET_NO, |
1384 | &process_peer_monitoring_cb, | 1317 | &process_peer_monitoring_cb, |
1385 | NULL); | 1318 | NULL); |
1386 | } | 1319 | } |
1387 | else if (monitor_plugins) /* -P: List information about plugins continuously */ | 1320 | else if (monitor_plugins) /* -P: List information about plugins continuously |
1321 | */ | ||
1388 | { | 1322 | { |
1389 | monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1323 | monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1390 | pm = GNUNET_TRANSPORT_monitor_plugins (cfg, | 1324 | pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL); |
1391 | &plugin_monitoring_cb, | ||
1392 | NULL); | ||
1393 | } | 1325 | } |
1394 | else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ | 1326 | else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ |
1395 | { | 1327 | { |
1396 | monitor_connect_counter = 0; | 1328 | monitor_connect_counter = 0; |
1397 | handle = GNUNET_TRANSPORT_core_connect (cfg, | 1329 | handle = GNUNET_TRANSPORT_core_connect (cfg, |
1398 | NULL, | 1330 | NULL, |
1399 | NULL, | 1331 | NULL, |
1400 | NULL, | 1332 | NULL, |
1401 | &monitor_notify_connect, | 1333 | &monitor_notify_connect, |
1402 | &monitor_notify_disconnect, | 1334 | &monitor_notify_disconnect, |
1403 | NULL); | 1335 | NULL); |
1404 | if (NULL == handle) | 1336 | if (NULL == handle) |
1405 | { | 1337 | { |
1406 | FPRINTF (stderr, | 1338 | FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); |
1407 | "%s", | ||
1408 | _("Failed to connect to transport service\n")); | ||
1409 | ret = 1; | 1339 | ret = 1; |
1410 | return; | 1340 | return; |
1411 | } | 1341 | } |
@@ -1413,75 +1343,86 @@ run (void *cls, | |||
1413 | } | 1343 | } |
1414 | else | 1344 | else |
1415 | { | 1345 | { |
1416 | GNUNET_break(0); | 1346 | GNUNET_break (0); |
1417 | return; | 1347 | return; |
1418 | } | 1348 | } |
1419 | 1349 | ||
1420 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1350 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
1421 | NULL); | ||
1422 | } | 1351 | } |
1423 | 1352 | ||
1424 | 1353 | ||
1425 | int | 1354 | int |
1426 | main (int argc, | 1355 | main (int argc, char *const *argv) |
1427 | char * const *argv) | ||
1428 | { | 1356 | { |
1429 | int res; | 1357 | int res; |
1430 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 1358 | struct GNUNET_GETOPT_CommandLineOption options[] = |
1431 | GNUNET_GETOPT_option_flag ('a', | 1359 | {GNUNET_GETOPT_option_flag ( |
1432 | "all", | 1360 | 'a', |
1433 | gettext_noop ("print information for all peers (instead of only connected peers)"), | 1361 | "all", |
1434 | &iterate_all), | 1362 | gettext_noop ( |
1435 | GNUNET_GETOPT_option_flag ('b', | 1363 | "print information for all peers (instead of only connected peers)"), |
1436 | "benchmark", | 1364 | &iterate_all), |
1437 | gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"), | 1365 | GNUNET_GETOPT_option_flag ( |
1438 | &benchmark_receive), | 1366 | 'b', |
1439 | GNUNET_GETOPT_option_flag ('D', | 1367 | "benchmark", |
1440 | "disconnect", | 1368 | gettext_noop ( |
1441 | gettext_noop ("disconnect from a peer"), | 1369 | "measure how fast we are receiving data from all peers (until CTRL-C)"), |
1442 | &do_disconnect), | 1370 | &benchmark_receive), |
1443 | GNUNET_GETOPT_option_flag ('i', | 1371 | GNUNET_GETOPT_option_flag ('D', |
1444 | "information", | 1372 | "disconnect", |
1445 | gettext_noop ("provide information about all current connections (once)"), | 1373 | gettext_noop ("disconnect from a peer"), |
1446 | &iterate_connections), | 1374 | &do_disconnect), |
1447 | GNUNET_GETOPT_option_flag ('m', | 1375 | GNUNET_GETOPT_option_flag ( |
1448 | "monitor", | 1376 | 'i', |
1449 | gettext_noop ("provide information about all current connections (continuously)"), | 1377 | "information", |
1450 | &monitor_connections), | 1378 | gettext_noop ( |
1451 | GNUNET_GETOPT_option_flag ('e', | 1379 | "provide information about all current connections (once)"), |
1452 | "events", | 1380 | &iterate_connections), |
1453 | gettext_noop ("provide information about all connects and disconnect events (continuously)"), | 1381 | GNUNET_GETOPT_option_flag ( |
1454 | &monitor_connects), | 1382 | 'm', |
1455 | GNUNET_GETOPT_option_flag ('n', | 1383 | "monitor", |
1456 | "numeric", | 1384 | gettext_noop ( |
1457 | gettext_noop ("do not resolve hostnames"), | 1385 | "provide information about all current connections (continuously)"), |
1458 | &numeric), | 1386 | &monitor_connections), |
1459 | GNUNET_GETOPT_option_base32_auto ('p', | 1387 | GNUNET_GETOPT_option_flag ( |
1460 | "peer", | 1388 | 'e', |
1461 | "PEER", | 1389 | "events", |
1462 | gettext_noop ("peer identity"), | 1390 | gettext_noop ( |
1463 | &pid), | 1391 | "provide information about all connects and disconnect events (continuously)"), |
1464 | GNUNET_GETOPT_option_flag ('P', | 1392 | &monitor_connects), |
1465 | "plugins", | 1393 | GNUNET_GETOPT_option_flag ('n', |
1466 | gettext_noop ("monitor plugin sessions"), | 1394 | "numeric", |
1467 | &monitor_plugins), | 1395 | gettext_noop ("do not resolve hostnames"), |
1468 | GNUNET_GETOPT_option_flag ('s', | 1396 | &numeric), |
1469 | "send", | 1397 | GNUNET_GETOPT_option_base32_auto ('p', |
1470 | gettext_noop | 1398 | "peer", |
1471 | ("send data for benchmarking to the other peer (until CTRL-C)"), | 1399 | "PEER", |
1472 | &benchmark_send), | 1400 | gettext_noop ("peer identity"), |
1473 | GNUNET_GETOPT_option_verbose (&verbosity), | 1401 | &pid), |
1474 | GNUNET_GETOPT_OPTION_END | 1402 | GNUNET_GETOPT_option_flag ('P', |
1475 | }; | 1403 | "plugins", |
1404 | gettext_noop ("monitor plugin sessions"), | ||
1405 | &monitor_plugins), | ||
1406 | GNUNET_GETOPT_option_flag ( | ||
1407 | 's', | ||
1408 | "send", | ||
1409 | gettext_noop ( | ||
1410 | "send data for benchmarking to the other peer (until CTRL-C)"), | ||
1411 | &benchmark_send), | ||
1412 | GNUNET_GETOPT_option_verbose (&verbosity), | ||
1413 | GNUNET_GETOPT_OPTION_END}; | ||
1476 | 1414 | ||
1477 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1415 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1478 | return 2; | 1416 | return 2; |
1479 | 1417 | ||
1480 | res = GNUNET_PROGRAM_run (argc, argv, | 1418 | res = |
1481 | "gnunet-transport", | 1419 | GNUNET_PROGRAM_run (argc, |
1482 | gettext_noop ("Direct access to transport service."), | 1420 | argv, |
1483 | options, | 1421 | "gnunet-transport", |
1484 | &run, NULL); | 1422 | gettext_noop ("Direct access to transport service."), |
1423 | options, | ||
1424 | &run, | ||
1425 | NULL); | ||
1485 | GNUNET_free ((void *) argv); | 1426 | GNUNET_free ((void *) argv); |
1486 | if (GNUNET_OK == res) | 1427 | if (GNUNET_OK == res) |
1487 | return ret; | 1428 | return ret; |
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index 4629d6125..83bbf277b 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -30,7 +30,6 @@ | |||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_transport_service.h" | 32 | #include "gnunet_transport_service.h" |
33 | #include "gnunet_transport_core_service.h" | ||
34 | #include "gnunet_transport_hello_service.h" | 33 | #include "gnunet_transport_hello_service.h" |
35 | #include "gnunet_transport_manipulation_service.h" | 34 | #include "gnunet_transport_manipulation_service.h" |
36 | #include "gnunet_testing_lib.h" | 35 | #include "gnunet_testing_lib.h" |
@@ -143,7 +142,7 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
143 | * Closure for @e start_cb. | 142 | * Closure for @e start_cb. |
144 | */ | 143 | */ |
145 | void *start_cb_cls; | 144 | void *start_cb_cls; |
146 | 145 | ||
147 | /** | 146 | /** |
148 | * An unique number to identify the peer | 147 | * An unique number to identify the peer |
149 | */ | 148 | */ |
@@ -207,12 +206,12 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest | |||
207 | */ | 206 | */ |
208 | struct GNUNET_MQ_Handle *mq; | 207 | struct GNUNET_MQ_Handle *mq; |
209 | 208 | ||
210 | /** | 209 | /** |
211 | * Set if peer1 says the connection is up to peer2. | 210 | * Set if peer1 says the connection is up to peer2. |
212 | */ | 211 | */ |
213 | int p1_c; | 212 | int p1_c; |
214 | 213 | ||
215 | /** | 214 | /** |
216 | * Set if peer2 says the connection is up to peer1. | 215 | * Set if peer2 says the connection is up to peer1. |
217 | */ | 216 | */ |
218 | int p2_c; | 217 | int p2_c; |
@@ -289,15 +288,16 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); | |||
289 | * @return the peer context | 288 | * @return the peer context |
290 | */ | 289 | */ |
291 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | 290 | struct GNUNET_TRANSPORT_TESTING_PeerContext * |
292 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, | 291 | GNUNET_TRANSPORT_TESTING_start_peer ( |
293 | const char *cfgname, | 292 | struct GNUNET_TRANSPORT_TESTING_Handle *tth, |
294 | int peer_id, | 293 | const char *cfgname, |
295 | const struct GNUNET_MQ_MessageHandler *handlers, | 294 | int peer_id, |
296 | GNUNET_TRANSPORT_NotifyConnect nc, | 295 | const struct GNUNET_MQ_MessageHandler *handlers, |
297 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 296 | GNUNET_TRANSPORT_NotifyConnect nc, |
298 | void *cb_cls, | 297 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
299 | GNUNET_SCHEDULER_TaskCallback start_cb, | 298 | void *cb_cls, |
300 | void *start_cb_cls); | 299 | GNUNET_SCHEDULER_TaskCallback start_cb, |
300 | void *start_cb_cls); | ||
301 | 301 | ||
302 | 302 | ||
303 | /** | 303 | /** |
@@ -306,7 +306,8 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth | |||
306 | * @param p the peer | 306 | * @param p the peer |
307 | */ | 307 | */ |
308 | void | 308 | void |
309 | GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); | 309 | GNUNET_TRANSPORT_TESTING_stop_peer ( |
310 | struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); | ||
310 | 311 | ||
311 | 312 | ||
312 | /** | 313 | /** |
@@ -318,10 +319,10 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
318 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR | 319 | * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR |
319 | */ | 320 | */ |
320 | int | 321 | int |
321 | GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 322 | GNUNET_TRANSPORT_TESTING_restart_peer ( |
322 | GNUNET_SCHEDULER_TaskCallback restart_cb, | 323 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
323 | void *restart_cb_cls); | 324 | GNUNET_SCHEDULER_TaskCallback restart_cb, |
324 | 325 | void *restart_cb_cls); | |
325 | 326 | ||
326 | 327 | ||
327 | /** | 328 | /** |
@@ -331,15 +332,17 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte | |||
331 | * | 332 | * |
332 | * @param p1 peer 1 | 333 | * @param p1 peer 1 |
333 | * @param p2 peer 2 | 334 | * @param p2 peer 2 |
334 | * @param cb the callback to call when both peers notified that they are connected | 335 | * @param cb the callback to call when both peers notified that they are |
336 | * connected | ||
335 | * @param cls callback cls | 337 | * @param cls callback cls |
336 | * @return a connect request handle | 338 | * @return a connect request handle |
337 | */ | 339 | */ |
338 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest * | 340 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest * |
339 | GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, | 341 | GNUNET_TRANSPORT_TESTING_connect_peers ( |
340 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, | 342 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, |
341 | GNUNET_SCHEDULER_TaskCallback cb, | 343 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, |
342 | void *cls); | 344 | GNUNET_SCHEDULER_TaskCallback cb, |
345 | void *cls); | ||
343 | 346 | ||
344 | 347 | ||
345 | /** | 348 | /** |
@@ -350,7 +353,8 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont | |||
350 | * @param cc a connect request handle | 353 | * @param cc a connect request handle |
351 | */ | 354 | */ |
352 | void | 355 | void |
353 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | 356 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel ( |
357 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | ||
354 | 358 | ||
355 | 359 | ||
356 | /** | 360 | /** |
@@ -359,9 +363,9 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_C | |||
359 | * @param cls closure | 363 | * @param cls closure |
360 | * @param cc request matching the query | 364 | * @param cc request matching the query |
361 | */ | 365 | */ |
362 | typedef void | 366 | typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) ( |
363 | (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback)(void *cls, | 367 | void *cls, |
364 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | 368 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); |
365 | 369 | ||
366 | 370 | ||
367 | /** | 371 | /** |
@@ -369,14 +373,15 @@ typedef void | |||
369 | * | 373 | * |
370 | * @param p1 first peer | 374 | * @param p1 first peer |
371 | * @param p2 second peer | 375 | * @param p2 second peer |
372 | * @param cb function to call | 376 | * @param cb function to call |
373 | * @param cb_cls closure for @a cb | 377 | * @param cb_cls closure for @a cb |
374 | */ | 378 | */ |
375 | void | 379 | void |
376 | GNUNET_TRANSPORT_TESTING_find_connecting_context (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, | 380 | GNUNET_TRANSPORT_TESTING_find_connecting_context ( |
377 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, | 381 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, |
378 | GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, | 382 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, |
379 | void *cb_cls); | 383 | GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, |
384 | void *cb_cls); | ||
380 | 385 | ||
381 | 386 | ||
382 | /* ********************** high-level process functions *************** */ | 387 | /* ********************** high-level process functions *************** */ |
@@ -390,10 +395,10 @@ GNUNET_TRANSPORT_TESTING_find_connecting_context (struct GNUNET_TRANSPORT_TESTIN | |||
390 | * @param num_peers size of the @a p array | 395 | * @param num_peers size of the @a p array |
391 | * @param p the peers that were launched | 396 | * @param p the peers that were launched |
392 | */ | 397 | */ |
393 | typedef void | 398 | typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContinuation) ( |
394 | (*GNUNET_TRANSPORT_TESTING_ConnectContinuation)(void *cls, | 399 | void *cls, |
395 | unsigned int num_peers, | 400 | unsigned int num_peers, |
396 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]); | 401 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]); |
397 | 402 | ||
398 | 403 | ||
399 | /** | 404 | /** |
@@ -423,7 +428,6 @@ struct GNUNET_TRANSPORT_TESTING_TestMessage | |||
423 | GNUNET_NETWORK_STRUCT_END | 428 | GNUNET_NETWORK_STRUCT_END |
424 | 429 | ||
425 | 430 | ||
426 | |||
427 | /** | 431 | /** |
428 | * Function called by the transport for each received message. | 432 | * Function called by the transport for each received message. |
429 | * | 433 | * |
@@ -432,11 +436,11 @@ GNUNET_NETWORK_STRUCT_END | |||
432 | * @param sender sender of the message | 436 | * @param sender sender of the message |
433 | * @param message the message | 437 | * @param message the message |
434 | */ | 438 | */ |
435 | typedef void | 439 | typedef void (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) ( |
436 | (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, | 440 | void *cls, |
437 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 441 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
438 | const struct GNUNET_PeerIdentity *sender, | 442 | const struct GNUNET_PeerIdentity *sender, |
439 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message); | 443 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message); |
440 | 444 | ||
441 | 445 | ||
442 | /** | 446 | /** |
@@ -447,10 +451,10 @@ typedef void | |||
447 | * @param me peer experiencing the event | 451 | * @param me peer experiencing the event |
448 | * @param other peer that connected to @a me | 452 | * @param other peer that connected to @a me |
449 | */ | 453 | */ |
450 | typedef void | 454 | typedef void (*GNUNET_TRANSPORT_TESTING_NotifyConnect) ( |
451 | (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (void *cls, | 455 | void *cls, |
452 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 456 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
453 | const struct GNUNET_PeerIdentity *other); | 457 | const struct GNUNET_PeerIdentity *other); |
454 | 458 | ||
455 | 459 | ||
456 | /** | 460 | /** |
@@ -461,10 +465,10 @@ typedef void | |||
461 | * @param me peer experiencing the event | 465 | * @param me peer experiencing the event |
462 | * @param other peer that disconnected from @a me | 466 | * @param other peer that disconnected from @a me |
463 | */ | 467 | */ |
464 | typedef void | 468 | typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) ( |
465 | (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (void *cls, | 469 | void *cls, |
466 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 470 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
467 | const struct GNUNET_PeerIdentity *other); | 471 | const struct GNUNET_PeerIdentity *other); |
468 | 472 | ||
469 | 473 | ||
470 | /** | 474 | /** |
@@ -593,7 +597,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext | |||
593 | * message. | 597 | * message. |
594 | */ | 598 | */ |
595 | uint32_t send_num_gen; | 599 | uint32_t send_num_gen; |
596 | 600 | ||
597 | /* ******* internal state, clients should not mess with this **** */ | 601 | /* ******* internal state, clients should not mess with this **** */ |
598 | 602 | ||
599 | /** | 603 | /** |
@@ -625,7 +629,6 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext | |||
625 | * Array with @e num_peers entries. | 629 | * Array with @e num_peers entries. |
626 | */ | 630 | */ |
627 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip; | 631 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip; |
628 | |||
629 | }; | 632 | }; |
630 | 633 | ||
631 | 634 | ||
@@ -637,8 +640,9 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext | |||
637 | * @return NULL if @a peer was not found | 640 | * @return NULL if @a peer was not found |
638 | */ | 641 | */ |
639 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | 642 | struct GNUNET_TRANSPORT_TESTING_PeerContext * |
640 | GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | 643 | GNUNET_TRANSPORT_TESTING_find_peer ( |
641 | const struct GNUNET_PeerIdentity *peer); | 644 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, |
645 | const struct GNUNET_PeerIdentity *peer); | ||
642 | 646 | ||
643 | 647 | ||
644 | /** | 648 | /** |
@@ -648,7 +652,8 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck | |||
648 | * abort the test, and a shutdown handler to clean up properly | 652 | * abort the test, and a shutdown handler to clean up properly |
649 | * on exit. | 653 | * on exit. |
650 | * | 654 | * |
651 | * @param cls closure of type `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | 655 | * @param cls closure of type `struct |
656 | * GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | ||
652 | * @param tth_ initialized testing handle | 657 | * @param tth_ initialized testing handle |
653 | * @param test_plugin_ name of the plugin | 658 | * @param test_plugin_ name of the plugin |
654 | * @param test_name_ name of the test | 659 | * @param test_name_ name of the test |
@@ -657,12 +662,13 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck | |||
657 | * @return #GNUNET_SYSERR on error | 662 | * @return #GNUNET_SYSERR on error |
658 | */ | 663 | */ |
659 | int | 664 | int |
660 | GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | 665 | GNUNET_TRANSPORT_TESTING_connect_check ( |
661 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | 666 | void *cls, |
662 | const char *test_plugin_, | 667 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
663 | const char *test_name_, | 668 | const char *test_plugin_, |
664 | unsigned int num_peers, | 669 | const char *test_name_, |
665 | char *cfg_files[]); | 670 | unsigned int num_peers, |
671 | char *cfg_files[]); | ||
666 | 672 | ||
667 | 673 | ||
668 | /** | 674 | /** |
@@ -677,13 +683,13 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | |||
677 | * @param cfg_files array of names of configuration files for the peers | 683 | * @param cfg_files array of names of configuration files for the peers |
678 | * @return #GNUNET_SYSERR on error | 684 | * @return #GNUNET_SYSERR on error |
679 | */ | 685 | */ |
680 | typedef int | 686 | typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) ( |
681 | (*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, | 687 | void *cls, |
682 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | 688 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
683 | const char *test_plugin_, | 689 | const char *test_plugin_, |
684 | const char *test_name_, | 690 | const char *test_name_, |
685 | unsigned int num_peers, | 691 | unsigned int num_peers, |
686 | char *cfg_files[]); | 692 | char *cfg_files[]); |
687 | 693 | ||
688 | 694 | ||
689 | /** | 695 | /** |
@@ -712,8 +718,12 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
712 | * @param check_cls closure for @a check | 718 | * @param check_cls closure for @a check |
713 | * @return #GNUNET_OK on success | 719 | * @return #GNUNET_OK on success |
714 | */ | 720 | */ |
715 | #define GNUNET_TRANSPORT_TESTING_main(num_peers,check,check_cls) \ | 721 | #define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \ |
716 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) | 722 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], \ |
723 | __FILE__, \ | ||
724 | num_peers, \ | ||
725 | check, \ | ||
726 | check_cls) | ||
717 | 727 | ||
718 | /* ***************** Convenience functions for sending ********* */ | 728 | /* ***************** Convenience functions for sending ********* */ |
719 | 729 | ||
@@ -725,7 +735,8 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
725 | * @param sender the sending peer | 735 | * @param sender the sending peer |
726 | * @param receiver the receiving peer | 736 | * @param receiver the receiving peer |
727 | * @param mtype message type to use | 737 | * @param mtype message type to use |
728 | * @param msize size of the message, at least `sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)` | 738 | * @param msize size of the message, at least `sizeof (struct |
739 | * GNUNET_TRANSPORT_TESTING_TestMessage)` | ||
729 | * @param num unique message number | 740 | * @param num unique message number |
730 | * @param cont continuation to call after transmission | 741 | * @param cont continuation to call after transmission |
731 | * @param cont_cls closure for @a cont | 742 | * @param cont_cls closure for @a cont |
@@ -734,13 +745,14 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
734 | * #GNUNET_SYSERR if @a msize is illegal | 745 | * #GNUNET_SYSERR if @a msize is illegal |
735 | */ | 746 | */ |
736 | int | 747 | int |
737 | GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, | 748 | GNUNET_TRANSPORT_TESTING_send ( |
738 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | 749 | struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, |
739 | uint16_t mtype, | 750 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
740 | uint16_t msize, | 751 | uint16_t mtype, |
741 | uint32_t num, | 752 | uint16_t msize, |
742 | GNUNET_SCHEDULER_TaskCallback cont, | 753 | uint32_t num, |
743 | void *cont_cls); | 754 | GNUNET_SCHEDULER_TaskCallback cont, |
755 | void *cont_cls); | ||
744 | 756 | ||
745 | 757 | ||
746 | /** | 758 | /** |
@@ -771,14 +783,14 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure | |||
771 | * the message size, can be NULL in which case the message | 783 | * the message size, can be NULL in which case the message |
772 | * size is the default. | 784 | * size is the default. |
773 | */ | 785 | */ |
774 | size_t (*get_size_cb)(unsigned int n); | 786 | size_t (*get_size_cb) (unsigned int n); |
775 | 787 | ||
776 | /** | 788 | /** |
777 | * Number of messages to be transmitted in a loop. | 789 | * Number of messages to be transmitted in a loop. |
778 | * Use zero for "forever" (until external shutdown). | 790 | * Use zero for "forever" (until external shutdown). |
779 | */ | 791 | */ |
780 | unsigned int num_messages; | 792 | unsigned int num_messages; |
781 | 793 | ||
782 | /** | 794 | /** |
783 | * Function to call after all transmissions, can be NULL. | 795 | * Function to call after all transmissions, can be NULL. |
784 | */ | 796 | */ |
@@ -788,12 +800,11 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure | |||
788 | * Closure for @e cont. | 800 | * Closure for @e cont. |
789 | */ | 801 | */ |
790 | void *cont_cls; | 802 | void *cont_cls; |
791 | |||
792 | }; | 803 | }; |
793 | 804 | ||
794 | 805 | ||
795 | /** | 806 | /** |
796 | * Task that sends a minimalistic test message from the | 807 | * Task that sends a minimalistic test message from the |
797 | * first peer to the second peer. | 808 | * first peer to the second peer. |
798 | * | 809 | * |
799 | * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` | 810 | * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` |
@@ -804,14 +815,14 @@ void | |||
804 | GNUNET_TRANSPORT_TESTING_simple_send (void *cls); | 815 | GNUNET_TRANSPORT_TESTING_simple_send (void *cls); |
805 | 816 | ||
806 | /** | 817 | /** |
807 | * Size of a message sent with | 818 | * Size of a message sent with |
808 | * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough | 819 | * #GNUNET_TRANSPORT_TESTING_large_send(). Big enough |
809 | * to usually force defragmentation. | 820 | * to usually force defragmentation. |
810 | */ | 821 | */ |
811 | #define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 | 822 | #define GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE 2600 |
812 | 823 | ||
813 | /** | 824 | /** |
814 | * Task that sends a large test message from the | 825 | * Task that sends a large test message from the |
815 | * first peer to the second peer. | 826 | * first peer to the second peer. |
816 | * | 827 | * |
817 | * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` | 828 | * @param cls the `struct GNUNET_TRANSPORT_TESTING_SendClosure` |
@@ -833,9 +844,10 @@ GNUNET_TRANSPORT_TESTING_large_send (void *cls); | |||
833 | * @param other peer that connected. | 844 | * @param other peer that connected. |
834 | */ | 845 | */ |
835 | void | 846 | void |
836 | GNUNET_TRANSPORT_TESTING_log_connect (void *cls, | 847 | GNUNET_TRANSPORT_TESTING_log_connect ( |
837 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 848 | void *cls, |
838 | const struct GNUNET_PeerIdentity *other); | 849 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
850 | const struct GNUNET_PeerIdentity *other); | ||
839 | 851 | ||
840 | 852 | ||
841 | /** | 853 | /** |
@@ -846,10 +858,10 @@ GNUNET_TRANSPORT_TESTING_log_connect (void *cls, | |||
846 | * @param other peer that disconnected. | 858 | * @param other peer that disconnected. |
847 | */ | 859 | */ |
848 | void | 860 | void |
849 | GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, | 861 | GNUNET_TRANSPORT_TESTING_log_disconnect ( |
850 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | 862 | void *cls, |
851 | const struct GNUNET_PeerIdentity *other); | 863 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
852 | 864 | const struct GNUNET_PeerIdentity *other); | |
853 | 865 | ||
854 | 866 | ||
855 | /* ********************** low-level filename functions *************** */ | 867 | /* ********************** low-level filename functions *************** */ |
@@ -875,8 +887,7 @@ GNUNET_TRANSPORT_TESTING_get_test_name (const char *file); | |||
875 | * @return configuration name to use | 887 | * @return configuration name to use |
876 | */ | 888 | */ |
877 | char * | 889 | char * |
878 | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, | 890 | GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count); |
879 | int count); | ||
880 | 891 | ||
881 | 892 | ||
882 | /** | 893 | /** |
diff --git a/src/transport/transport.h b/src/transport/transport.h index d2a3a262b..ed89940cc 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -123,10 +123,21 @@ struct ConnectInfoMessage | |||
123 | */ | 123 | */ |
124 | struct GNUNET_MessageHeader header; | 124 | struct GNUNET_MessageHeader header; |
125 | 125 | ||
126 | #if (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ | ||
127 | defined(GNUNET_TRANSPORT_CORE_VERSION)) | ||
128 | |||
129 | /** | ||
130 | * Always zero, for alignment. | ||
131 | */ | ||
132 | uint32_t reserved GNUNET_PACKED; | ||
133 | |||
134 | #else | ||
135 | |||
126 | /** | 136 | /** |
127 | * Current outbound quota for this peer | 137 | * Current outbound quota for this peer |
128 | */ | 138 | */ |
129 | struct GNUNET_BANDWIDTH_Value32NBO quota_out; | 139 | struct GNUNET_BANDWIDTH_Value32NBO quota_out; |
140 | #endif | ||
130 | 141 | ||
131 | /** | 142 | /** |
132 | * Identity of the new neighbour. | 143 | * Identity of the new neighbour. |
@@ -163,6 +174,8 @@ struct DisconnectInfoMessage | |||
163 | * Message used to set a particular bandwidth quota. Sent TO the | 174 | * Message used to set a particular bandwidth quota. Sent TO the |
164 | * service to set an incoming quota, sent FROM the service to update | 175 | * service to set an incoming quota, sent FROM the service to update |
165 | * an outgoing quota. | 176 | * an outgoing quota. |
177 | * | ||
178 | * NOTE: no longer used in TNG! | ||
166 | */ | 179 | */ |
167 | struct QuotaSetMessage | 180 | struct QuotaSetMessage |
168 | { | 181 | { |
@@ -215,6 +228,13 @@ struct SendOkMessage | |||
215 | */ | 228 | */ |
216 | struct GNUNET_MessageHeader header; | 229 | struct GNUNET_MessageHeader header; |
217 | 230 | ||
231 | #if (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ | ||
232 | defined(GNUNET_TRANSPORT_CORE_VERSION)) | ||
233 | |||
234 | uint32_t reserved GNUNET_PACKED; | ||
235 | |||
236 | #else | ||
237 | |||
218 | /** | 238 | /** |
219 | * #GNUNET_OK if the transmission succeeded, | 239 | * #GNUNET_OK if the transmission succeeded, |
220 | * #GNUNET_SYSERR if it failed (i.e. network disconnect); | 240 | * #GNUNET_SYSERR if it failed (i.e. network disconnect); |
@@ -229,11 +249,13 @@ struct SendOkMessage | |||
229 | uint16_t bytes_msg GNUNET_PACKED; | 249 | uint16_t bytes_msg GNUNET_PACKED; |
230 | 250 | ||
231 | /** | 251 | /** |
232 | * Size of message sent over wire | 252 | * Size of message sent over wire. |
233 | * Includes plugin and protocol specific overhead | 253 | * Includes plugin and protocol specific overheads. |
234 | */ | 254 | */ |
235 | uint32_t bytes_physical GNUNET_PACKED; | 255 | uint32_t bytes_physical GNUNET_PACKED; |
236 | 256 | ||
257 | #endif | ||
258 | |||
237 | /** | 259 | /** |
238 | * Which peer can send more now? | 260 | * Which peer can send more now? |
239 | */ | 261 | */ |
@@ -242,6 +264,32 @@ struct SendOkMessage | |||
242 | 264 | ||
243 | 265 | ||
244 | /** | 266 | /** |
267 | * Message used to notify the transport API that it can | ||
268 | * send another message to the transport service. | ||
269 | * (Used to implement flow control.) | ||
270 | */ | ||
271 | struct RecvOkMessage | ||
272 | { | ||
273 | |||
274 | /** | ||
275 | * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK | ||
276 | */ | ||
277 | struct GNUNET_MessageHeader header; | ||
278 | |||
279 | /** | ||
280 | * Number of messages by which to increase the window, greater or | ||
281 | * equal to one. | ||
282 | */ | ||
283 | uint32_t increase_window_delta GNUNET_PACKED; | ||
284 | |||
285 | /** | ||
286 | * Which peer can CORE handle more from now? | ||
287 | */ | ||
288 | struct GNUNET_PeerIdentity peer; | ||
289 | }; | ||
290 | |||
291 | |||
292 | /** | ||
245 | * Message used to notify the transport service about a message | 293 | * Message used to notify the transport service about a message |
246 | * to be transmitted to another peer. The actual message follows. | 294 | * to be transmitted to another peer. The actual message follows. |
247 | */ | 295 | */ |
@@ -258,10 +306,14 @@ struct OutboundMessage | |||
258 | */ | 306 | */ |
259 | uint32_t reserved GNUNET_PACKED; | 307 | uint32_t reserved GNUNET_PACKED; |
260 | 308 | ||
309 | #if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ | ||
310 | defined(GNUNET_TRANSPORT_CORE_VERSION)) | ||
311 | |||
261 | /** | 312 | /** |
262 | * Allowed delay. | 313 | * Allowed delay. |
263 | */ | 314 | */ |
264 | struct GNUNET_TIME_RelativeNBO timeout; | 315 | struct GNUNET_TIME_RelativeNBO timeout; |
316 | #endif | ||
265 | 317 | ||
266 | /** | 318 | /** |
267 | * Which peer should receive the message? | 319 | * Which peer should receive the message? |
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c index f00d00a44..a3c49e94f 100644 --- a/src/transport/transport_api2_core.c +++ b/src/transport/transport_api2_core.c | |||
@@ -32,13 +32,23 @@ | |||
32 | #include "gnunet_transport_core_service.h" | 32 | #include "gnunet_transport_core_service.h" |
33 | #include "transport.h" | 33 | #include "transport.h" |
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-api-core",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * How large to start with for the hashmap of neighbours. | 38 | * How large to start with for the hashmap of neighbours. |
39 | */ | 39 | */ |
40 | #define STARTING_NEIGHBOURS_SIZE 16 | 40 | #define STARTING_NEIGHBOURS_SIZE 16 |
41 | 41 | ||
42 | /** | ||
43 | * Window size. How many messages to the same target do we pass | ||
44 | * to TRANSPORT without a SEND_OK in between? Small values limit | ||
45 | * thoughput, large values will increase latency. | ||
46 | * | ||
47 | * FIXME-OPTIMIZE: find out what good values are experimentally, | ||
48 | * maybe set adaptively (i.e. to observed available bandwidth). | ||
49 | */ | ||
50 | #define SEND_WINDOW_SIZE 4 | ||
51 | |||
42 | 52 | ||
43 | /** | 53 | /** |
44 | * Entry in hash table of all of our current (connected) neighbours. | 54 | * Entry in hash table of all of our current (connected) neighbours. |
@@ -72,46 +82,27 @@ struct Neighbour | |||
72 | void *handlers_cls; | 82 | void *handlers_cls; |
73 | 83 | ||
74 | /** | 84 | /** |
75 | * Entry in our readyness heap (which is sorted by @e next_ready | 85 | * How many messages can we still send to this peer before we should |
76 | * value). NULL if there is no pending transmission request for | 86 | * throttle? |
77 | * this neighbour or if we're waiting for @e is_ready to become | ||
78 | * true AFTER the @e out_tracker suggested that this peer's quota | ||
79 | * has been satisfied (so once @e is_ready goes to #GNUNET_YES, | ||
80 | * we should immediately go back into the heap). | ||
81 | */ | 87 | */ |
82 | struct GNUNET_CONTAINER_HeapNode *hn; | 88 | unsigned int ready_window; |
83 | 89 | ||
84 | /** | 90 | /** |
85 | * Task to trigger MQ when we have enough bandwidth for the | 91 | * Used to indicate our status if @e env is non-NULL. Set to |
86 | * next transmission. | 92 | * #GNUNET_YES if we did pass a message to the MQ and are waiting |
93 | * for the call to #notify_send_done(). Set to #GNUNET_NO if the @e | ||
94 | * ready_window is 0 and @e env is waiting for a | ||
95 | * #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK? | ||
87 | */ | 96 | */ |
88 | struct GNUNET_SCHEDULER_Task *timeout_task; | 97 | int16_t awaiting_done; |
89 | |||
90 | /** | ||
91 | * Outbound bandwidh tracker. | ||
92 | */ | ||
93 | struct GNUNET_BANDWIDTH_Tracker out_tracker; | ||
94 | |||
95 | /** | ||
96 | * Sending consumed more bytes on wire than payload was announced | ||
97 | * This overhead is added to the delay of next sending operation | ||
98 | */ | ||
99 | unsigned long long traffic_overhead; | ||
100 | |||
101 | /** | ||
102 | * Is this peer currently ready to receive a message? | ||
103 | */ | ||
104 | int is_ready; | ||
105 | 98 | ||
106 | /** | 99 | /** |
107 | * Size of the message in @e env. | 100 | * Size of the message in @e env. |
108 | */ | 101 | */ |
109 | uint16_t env_size; | 102 | uint16_t env_size; |
110 | |||
111 | }; | 103 | }; |
112 | 104 | ||
113 | 105 | ||
114 | |||
115 | /** | 106 | /** |
116 | * Handle for the transport service (includes all of the | 107 | * Handle for the transport service (includes all of the |
117 | * state for the transport service). | 108 | * state for the transport service). |
@@ -141,11 +132,6 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
141 | GNUNET_TRANSPORT_NotifyDisconnect nd_cb; | 132 | GNUNET_TRANSPORT_NotifyDisconnect nd_cb; |
142 | 133 | ||
143 | /** | 134 | /** |
144 | * function to call on excess bandwidth events | ||
145 | */ | ||
146 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb_cb; | ||
147 | |||
148 | /** | ||
149 | * My client connection to the transport service. | 135 | * My client connection to the transport service. |
150 | */ | 136 | */ |
151 | struct GNUNET_MQ_Handle *mq; | 137 | struct GNUNET_MQ_Handle *mq; |
@@ -181,7 +167,6 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
181 | * (if #GNUNET_NO, then @e self is all zeros!). | 167 | * (if #GNUNET_NO, then @e self is all zeros!). |
182 | */ | 168 | */ |
183 | int check_self; | 169 | int check_self; |
184 | |||
185 | }; | 170 | }; |
186 | 171 | ||
187 | 172 | ||
@@ -206,31 +191,7 @@ static struct Neighbour * | |||
206 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, | 191 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, |
207 | const struct GNUNET_PeerIdentity *peer) | 192 | const struct GNUNET_PeerIdentity *peer) |
208 | { | 193 | { |
209 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, | 194 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); |
210 | peer); | ||
211 | } | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Function called by the bandwidth tracker if we have excess | ||
216 | * bandwidth. | ||
217 | * | ||
218 | * @param cls the `struct Neighbour` that has excess bandwidth | ||
219 | */ | ||
220 | static void | ||
221 | notify_excess_cb (void *cls) | ||
222 | { | ||
223 | struct Neighbour *n = cls; | ||
224 | struct GNUNET_TRANSPORT_CoreHandle *h = n->h; | ||
225 | |||
226 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
227 | "Notifying CORE that more bandwidth is available for %s\n", | ||
228 | GNUNET_i2s (&n->id)); | ||
229 | |||
230 | if (NULL != h->neb_cb) | ||
231 | h->neb_cb (h->cls, | ||
232 | &n->id, | ||
233 | n->handlers_cls); | ||
234 | } | 195 | } |
235 | 196 | ||
236 | 197 | ||
@@ -245,9 +206,7 @@ notify_excess_cb (void *cls) | |||
245 | * #GNUNET_NO if not. | 206 | * #GNUNET_NO if not. |
246 | */ | 207 | */ |
247 | static int | 208 | static int |
248 | neighbour_delete (void *cls, | 209 | neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
249 | const struct GNUNET_PeerIdentity *key, | ||
250 | void *value) | ||
251 | { | 210 | { |
252 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; | 211 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; |
253 | struct Neighbour *n = value; | 212 | struct Neighbour *n = value; |
@@ -255,16 +214,8 @@ neighbour_delete (void *cls, | |||
255 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 214 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
256 | "Dropping entry for neighbour `%s'.\n", | 215 | "Dropping entry for neighbour `%s'.\n", |
257 | GNUNET_i2s (key)); | 216 | GNUNET_i2s (key)); |
258 | GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker); | ||
259 | if (NULL != handle->nd_cb) | 217 | if (NULL != handle->nd_cb) |
260 | handle->nd_cb (handle->cls, | 218 | handle->nd_cb (handle->cls, &n->id, n->handlers_cls); |
261 | &n->id, | ||
262 | n->handlers_cls); | ||
263 | if (NULL != n->timeout_task) | ||
264 | { | ||
265 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
266 | n->timeout_task = NULL; | ||
267 | } | ||
268 | if (NULL != n->env) | 219 | if (NULL != n->env) |
269 | { | 220 | { |
270 | GNUNET_MQ_send_cancel (n->env); | 221 | GNUNET_MQ_send_cancel (n->env); |
@@ -272,10 +223,9 @@ neighbour_delete (void *cls, | |||
272 | } | 223 | } |
273 | GNUNET_MQ_destroy (n->mq); | 224 | GNUNET_MQ_destroy (n->mq); |
274 | GNUNET_assert (NULL == n->mq); | 225 | GNUNET_assert (NULL == n->mq); |
275 | GNUNET_assert (GNUNET_YES == | 226 | GNUNET_assert ( |
276 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, | 227 | GNUNET_YES == |
277 | key, | 228 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); |
278 | n)); | ||
279 | GNUNET_free (n); | 229 | GNUNET_free (n); |
280 | return GNUNET_YES; | 230 | return GNUNET_YES; |
281 | } | 231 | } |
@@ -291,8 +241,7 @@ neighbour_delete (void *cls, | |||
291 | * @param error error code | 241 | * @param error error code |
292 | */ | 242 | */ |
293 | static void | 243 | static void |
294 | mq_error_handler (void *cls, | 244 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
295 | enum GNUNET_MQ_Error error) | ||
296 | { | 245 | { |
297 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 246 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
298 | 247 | ||
@@ -306,57 +255,42 @@ mq_error_handler (void *cls, | |||
306 | * A message from the handler's message queue to a neighbour was | 255 | * A message from the handler's message queue to a neighbour was |
307 | * transmitted. Now trigger (possibly delayed) notification of the | 256 | * transmitted. Now trigger (possibly delayed) notification of the |
308 | * neighbour's message queue that we are done and thus ready for | 257 | * neighbour's message queue that we are done and thus ready for |
309 | * the next message. | 258 | * the next message. Note that the MQ being ready is independent |
259 | * of the send window, as we may queue many messages and simply | ||
260 | * not pass them to TRANSPORT if the send window is insufficient. | ||
310 | * | 261 | * |
311 | * @param cls the `struct Neighbour` where the message was sent | 262 | * @param cls the `struct Neighbour` where the message was sent |
312 | */ | 263 | */ |
313 | static void | 264 | static void |
314 | notify_send_done_fin (void *cls) | 265 | notify_send_done (void *cls) |
315 | { | 266 | { |
316 | struct Neighbour *n = cls; | 267 | struct Neighbour *n = cls; |
317 | 268 | ||
318 | n->timeout_task = NULL; | 269 | n->awaiting_done = GNUNET_NO; |
319 | n->is_ready = GNUNET_YES; | 270 | n->env = NULL; |
320 | GNUNET_MQ_impl_send_continue (n->mq); | 271 | GNUNET_MQ_impl_send_continue (n->mq); |
321 | } | 272 | } |
322 | 273 | ||
323 | 274 | ||
324 | /** | 275 | /** |
325 | * A message from the handler's message queue to a neighbour was | 276 | * We have an envelope waiting for transmission at @a n, and |
326 | * transmitted. Now trigger (possibly delayed) notification of the | 277 | * our transmission window is positive. Perform the transmission. |
327 | * neighbour's message queue that we are done and thus ready for | ||
328 | * the next message. | ||
329 | * | 278 | * |
330 | * @param cls the `struct Neighbour` where the message was sent | 279 | * @param n neighbour to perform transmission for |
331 | */ | 280 | */ |
332 | static void | 281 | static void |
333 | notify_send_done (void *cls) | 282 | do_send (struct Neighbour *n) |
334 | { | 283 | { |
335 | struct Neighbour *n = cls; | 284 | GNUNET_assert (0 < n->ready_window); |
336 | struct GNUNET_TIME_Relative delay; | 285 | GNUNET_assert (NULL != n->env); |
337 | 286 | n->ready_window--; | |
338 | n->timeout_task = NULL; | 287 | n->awaiting_done = GNUNET_YES; |
339 | if (NULL != n->env) | 288 | GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); |
340 | { | 289 | GNUNET_MQ_send (n->h->mq, n->env); |
341 | GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, | 290 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
342 | n->env_size + n->traffic_overhead); | 291 | "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", |
343 | n->env = NULL; | 292 | ntohs (GNUNET_MQ_env_get_msg (n->env)->type), |
344 | n->traffic_overhead = 0; | 293 | GNUNET_i2s (&n->id)); |
345 | } | ||
346 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, | ||
347 | 128); | ||
348 | if (0 == delay.rel_value_us) | ||
349 | { | ||
350 | n->is_ready = GNUNET_YES; | ||
351 | GNUNET_MQ_impl_send_continue (n->mq); | ||
352 | return; | ||
353 | } | ||
354 | GNUNET_MQ_impl_send_in_flight (n->mq); | ||
355 | /* cannot send even a small message without violating | ||
356 | quota, wait a before allowing MQ to send next message */ | ||
357 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, | ||
358 | ¬ify_send_done_fin, | ||
359 | n); | ||
360 | } | 294 | } |
361 | 295 | ||
362 | 296 | ||
@@ -376,11 +310,9 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
376 | void *impl_state) | 310 | void *impl_state) |
377 | { | 311 | { |
378 | struct Neighbour *n = impl_state; | 312 | struct Neighbour *n = impl_state; |
379 | struct GNUNET_TRANSPORT_CoreHandle *h = n->h; | ||
380 | struct OutboundMessage *obm; | 313 | struct OutboundMessage *obm; |
381 | uint16_t msize; | 314 | uint16_t msize; |
382 | 315 | ||
383 | GNUNET_assert (GNUNET_YES == n->is_ready); | ||
384 | msize = ntohs (msg->size); | 316 | msize = ntohs (msg->size); |
385 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm)) | 317 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm)) |
386 | { | 318 | { |
@@ -388,25 +320,24 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
388 | GNUNET_MQ_impl_send_continue (mq); | 320 | GNUNET_MQ_impl_send_continue (mq); |
389 | return; | 321 | return; |
390 | } | 322 | } |
391 | GNUNET_assert (NULL == n->env); | ||
392 | n->env = GNUNET_MQ_msg_nested_mh (obm, | ||
393 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, | ||
394 | msg); | ||
395 | obm->reserved = htonl (0); | ||
396 | obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ | ||
397 | obm->peer = n->id; | ||
398 | GNUNET_assert (NULL == n->timeout_task); | ||
399 | n->is_ready = GNUNET_NO; | ||
400 | n->env_size = ntohs (msg->size); | ||
401 | GNUNET_MQ_notify_sent (n->env, | ||
402 | ¬ify_send_done, | ||
403 | n); | ||
404 | GNUNET_MQ_send (h->mq, | ||
405 | n->env); | ||
406 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 323 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
407 | "Queued message of type %u for neighbour `%s'.\n", | 324 | "CORE requested transmission of message of type %u to neighbour `%s'.\n", |
408 | ntohs (msg->type), | 325 | ntohs (msg->type), |
409 | GNUNET_i2s (&n->id)); | 326 | GNUNET_i2s (&n->id)); |
327 | |||
328 | GNUNET_assert (NULL == n->env); | ||
329 | n->env = | ||
330 | GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); | ||
331 | n->env_size = ntohs (msg->size); | ||
332 | obm->reserved = htonl (0); | ||
333 | obm->peer = n->id; | ||
334 | if (0 == n->ready_window) | ||
335 | { | ||
336 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
337 | "Flow control delays transmission to CORE until we see SEND_OK.\n"); | ||
338 | return; /* can't send yet, need to wait for SEND_OK */ | ||
339 | } | ||
340 | do_send (n); | ||
410 | } | 341 | } |
411 | 342 | ||
412 | 343 | ||
@@ -418,8 +349,7 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
418 | * @param impl_state state of the implementation | 349 | * @param impl_state state of the implementation |
419 | */ | 350 | */ |
420 | static void | 351 | static void |
421 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, | 352 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
422 | void *impl_state) | ||
423 | { | 353 | { |
424 | struct Neighbour *n = impl_state; | 354 | struct Neighbour *n = impl_state; |
425 | 355 | ||
@@ -436,19 +366,22 @@ mq_destroy_impl (struct GNUNET_MQ_Handle *mq, | |||
436 | * @param impl_state state specific to the implementation | 366 | * @param impl_state state specific to the implementation |
437 | */ | 367 | */ |
438 | static void | 368 | static void |
439 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, | 369 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
440 | void *impl_state) | ||
441 | { | 370 | { |
442 | struct Neighbour *n = impl_state; | 371 | struct Neighbour *n = impl_state; |
443 | 372 | ||
444 | GNUNET_assert (GNUNET_NO == n->is_ready); | 373 | n->ready_window++; |
445 | if (NULL != n->env) | 374 | if (GNUNET_YES == n->awaiting_done) |
446 | { | 375 | { |
447 | GNUNET_MQ_send_cancel (n->env); | 376 | GNUNET_MQ_send_cancel (n->env); |
448 | n->env = NULL; | 377 | n->env = NULL; |
378 | n->awaiting_done = GNUNET_NO; | ||
379 | } | ||
380 | else | ||
381 | { | ||
382 | GNUNET_assert (0 == n->ready_window); | ||
383 | n->env = NULL; | ||
449 | } | 384 | } |
450 | |||
451 | n->is_ready = GNUNET_YES; | ||
452 | } | 385 | } |
453 | 386 | ||
454 | 387 | ||
@@ -461,8 +394,7 @@ mq_cancel_impl (struct GNUNET_MQ_Handle *mq, | |||
461 | * @param error error code | 394 | * @param error error code |
462 | */ | 395 | */ |
463 | static void | 396 | static void |
464 | peer_mq_error_handler (void *cls, | 397 | peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
465 | enum GNUNET_MQ_Error error) | ||
466 | { | 398 | { |
467 | /* struct Neighbour *n = cls; */ | 399 | /* struct Neighbour *n = cls; */ |
468 | 400 | ||
@@ -471,47 +403,21 @@ peer_mq_error_handler (void *cls, | |||
471 | 403 | ||
472 | 404 | ||
473 | /** | 405 | /** |
474 | * The outbound quota has changed in a way that may require | ||
475 | * us to reset the timeout. Update the timeout. | ||
476 | * | ||
477 | * @param cls the `struct Neighbour` for which the timeout changed | ||
478 | */ | ||
479 | static void | ||
480 | outbound_bw_tracker_update (void *cls) | ||
481 | { | ||
482 | struct Neighbour *n = cls; | ||
483 | struct GNUNET_TIME_Relative delay; | ||
484 | |||
485 | if (NULL == n->timeout_task) | ||
486 | return; | ||
487 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, | ||
488 | 128); | ||
489 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
490 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, | ||
491 | ¬ify_send_done, | ||
492 | n); | ||
493 | } | ||
494 | |||
495 | |||
496 | /** | ||
497 | * Function we use for handling incoming connect messages. | 406 | * Function we use for handling incoming connect messages. |
498 | * | 407 | * |
499 | * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` | 408 | * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *` |
500 | * @param cim message received | 409 | * @param cim message received |
501 | */ | 410 | */ |
502 | static void | 411 | static void |
503 | handle_connect (void *cls, | 412 | handle_connect (void *cls, const struct ConnectInfoMessage *cim) |
504 | const struct ConnectInfoMessage *cim) | ||
505 | { | 413 | { |
506 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 414 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
507 | struct Neighbour *n; | 415 | struct Neighbour *n; |
508 | 416 | ||
509 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 417 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
510 | "Receiving CONNECT message for `%s' with quota %u\n", | 418 | "Receiving CONNECT message for `%s'\n", |
511 | GNUNET_i2s (&cim->id), | 419 | GNUNET_i2s (&cim->id)); |
512 | ntohl (cim->quota_out.value__)); | 420 | n = neighbour_find (h, &cim->id); |
513 | n = neighbour_find (h, | ||
514 | &cim->id); | ||
515 | if (NULL != n) | 421 | if (NULL != n) |
516 | { | 422 | { |
517 | GNUNET_break (0); | 423 | GNUNET_break (0); |
@@ -521,23 +427,14 @@ handle_connect (void *cls, | |||
521 | n = GNUNET_new (struct Neighbour); | 427 | n = GNUNET_new (struct Neighbour); |
522 | n->id = cim->id; | 428 | n->id = cim->id; |
523 | n->h = h; | 429 | n->h = h; |
524 | n->is_ready = GNUNET_YES; | 430 | n->ready_window = SEND_WINDOW_SIZE; |
525 | n->traffic_overhead = 0; | ||
526 | GNUNET_BANDWIDTH_tracker_init2 (&n->out_tracker, | ||
527 | &outbound_bw_tracker_update, | ||
528 | n, | ||
529 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | ||
530 | MAX_BANDWIDTH_CARRY_S, | ||
531 | ¬ify_excess_cb, | ||
532 | n); | ||
533 | GNUNET_assert (GNUNET_OK == | 431 | GNUNET_assert (GNUNET_OK == |
534 | GNUNET_CONTAINER_multipeermap_put (h->neighbours, | 432 | GNUNET_CONTAINER_multipeermap_put ( |
535 | &n->id, | 433 | h->neighbours, |
536 | n, | 434 | &n->id, |
537 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 435 | n, |
436 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
538 | 437 | ||
539 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, | ||
540 | cim->quota_out); | ||
541 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, | 438 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, |
542 | &mq_destroy_impl, | 439 | &mq_destroy_impl, |
543 | &mq_cancel_impl, | 440 | &mq_cancel_impl, |
@@ -547,11 +444,8 @@ handle_connect (void *cls, | |||
547 | n); | 444 | n); |
548 | if (NULL != h->nc_cb) | 445 | if (NULL != h->nc_cb) |
549 | { | 446 | { |
550 | n->handlers_cls = h->nc_cb (h->cls, | 447 | n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); |
551 | &n->id, | 448 | GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); |
552 | n->mq); | ||
553 | GNUNET_MQ_set_handlers_closure (n->mq, | ||
554 | n->handlers_cls); | ||
555 | } | 449 | } |
556 | } | 450 | } |
557 | 451 | ||
@@ -563,8 +457,7 @@ handle_connect (void *cls, | |||
563 | * @param dim message received | 457 | * @param dim message received |
564 | */ | 458 | */ |
565 | static void | 459 | static void |
566 | handle_disconnect (void *cls, | 460 | handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) |
567 | const struct DisconnectInfoMessage *dim) | ||
568 | { | 461 | { |
569 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 462 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
570 | struct Neighbour *n; | 463 | struct Neighbour *n; |
@@ -573,18 +466,14 @@ handle_disconnect (void *cls, | |||
573 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 466 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
574 | "Receiving DISCONNECT message for `%s'.\n", | 467 | "Receiving DISCONNECT message for `%s'.\n", |
575 | GNUNET_i2s (&dim->peer)); | 468 | GNUNET_i2s (&dim->peer)); |
576 | n = neighbour_find (h, | 469 | n = neighbour_find (h, &dim->peer); |
577 | &dim->peer); | ||
578 | if (NULL == n) | 470 | if (NULL == n) |
579 | { | 471 | { |
580 | GNUNET_break (0); | 472 | GNUNET_break (0); |
581 | disconnect_and_schedule_reconnect (h); | 473 | disconnect_and_schedule_reconnect (h); |
582 | return; | 474 | return; |
583 | } | 475 | } |
584 | GNUNET_assert (GNUNET_YES == | 476 | GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); |
585 | neighbour_delete (h, | ||
586 | &dim->peer, | ||
587 | n)); | ||
588 | } | 477 | } |
589 | 478 | ||
590 | 479 | ||
@@ -595,24 +484,15 @@ handle_disconnect (void *cls, | |||
595 | * @param okm message received | 484 | * @param okm message received |
596 | */ | 485 | */ |
597 | static void | 486 | static void |
598 | handle_send_ok (void *cls, | 487 | handle_send_ok (void *cls, const struct SendOkMessage *okm) |
599 | const struct SendOkMessage *okm) | ||
600 | { | 488 | { |
601 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 489 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
602 | struct Neighbour *n; | 490 | struct Neighbour *n; |
603 | uint16_t bytes_msg; | ||
604 | uint32_t bytes_physical; | ||
605 | 491 | ||
606 | bytes_msg = ntohs (okm->bytes_msg); | ||
607 | bytes_physical = ntohl (okm->bytes_physical); | ||
608 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 492 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
609 | "Receiving SEND_OK message, transmission to %s %s.\n", | 493 | "Receiving SEND_OK message for transmission to %s\n", |
610 | GNUNET_i2s (&okm->peer), | 494 | GNUNET_i2s (&okm->peer)); |
611 | (GNUNET_OK == ntohs (okm->success)) | 495 | n = neighbour_find (h, &okm->peer); |
612 | ? "succeeded" | ||
613 | : "failed"); | ||
614 | n = neighbour_find (h, | ||
615 | &okm->peer); | ||
616 | if (NULL == n) | 496 | if (NULL == n) |
617 | { | 497 | { |
618 | /* We should never get a 'SEND_OK' for a peer that we are not | 498 | /* We should never get a 'SEND_OK' for a peer that we are not |
@@ -621,14 +501,9 @@ handle_send_ok (void *cls, | |||
621 | disconnect_and_schedule_reconnect (h); | 501 | disconnect_and_schedule_reconnect (h); |
622 | return; | 502 | return; |
623 | } | 503 | } |
624 | if (bytes_physical > bytes_msg) | 504 | n->ready_window++; |
625 | { | 505 | if ((NULL != n->env) && (1 == n->ready_window)) |
626 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 506 | do_send (n); |
627 | "Overhead for %u byte message was %u\n", | ||
628 | (unsigned int) bytes_msg, | ||
629 | (unsigned int) (bytes_physical - bytes_msg)); | ||
630 | n->traffic_overhead += bytes_physical - bytes_msg; | ||
631 | } | ||
632 | } | 507 | } |
633 | 508 | ||
634 | 509 | ||
@@ -639,8 +514,7 @@ handle_send_ok (void *cls, | |||
639 | * @param im message received | 514 | * @param im message received |
640 | */ | 515 | */ |
641 | static int | 516 | static int |
642 | check_recv (void *cls, | 517 | check_recv (void *cls, const struct InboundMessage *im) |
643 | const struct InboundMessage *im) | ||
644 | { | 518 | { |
645 | const struct GNUNET_MessageHeader *imm; | 519 | const struct GNUNET_MessageHeader *imm; |
646 | uint16_t size; | 520 | uint16_t size; |
@@ -668,12 +542,11 @@ check_recv (void *cls, | |||
668 | * @param im message received | 542 | * @param im message received |
669 | */ | 543 | */ |
670 | static void | 544 | static void |
671 | handle_recv (void *cls, | 545 | handle_recv (void *cls, const struct InboundMessage *im) |
672 | const struct InboundMessage *im) | ||
673 | { | 546 | { |
674 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 547 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
675 | const struct GNUNET_MessageHeader *imm | 548 | const struct GNUNET_MessageHeader *imm = |
676 | = (const struct GNUNET_MessageHeader *) &im[1]; | 549 | (const struct GNUNET_MessageHeader *) &im[1]; |
677 | struct Neighbour *n; | 550 | struct Neighbour *n; |
678 | 551 | ||
679 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 552 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -681,46 +554,14 @@ handle_recv (void *cls, | |||
681 | (unsigned int) ntohs (imm->type), | 554 | (unsigned int) ntohs (imm->type), |
682 | (unsigned int) ntohs (imm->size), | 555 | (unsigned int) ntohs (imm->size), |
683 | GNUNET_i2s (&im->peer)); | 556 | GNUNET_i2s (&im->peer)); |
684 | n = neighbour_find (h, | 557 | n = neighbour_find (h, &im->peer); |
685 | &im->peer); | ||
686 | if (NULL == n) | ||
687 | { | ||
688 | GNUNET_break (0); | ||
689 | disconnect_and_schedule_reconnect (h); | ||
690 | return; | ||
691 | } | ||
692 | GNUNET_MQ_inject_message (n->mq, | ||
693 | imm); | ||
694 | } | ||
695 | |||
696 | |||
697 | /** | ||
698 | * Function we use for handling incoming set quota messages. | ||
699 | * | ||
700 | * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *` | ||
701 | * @param msg message received | ||
702 | */ | ||
703 | static void | ||
704 | handle_set_quota (void *cls, | ||
705 | const struct QuotaSetMessage *qm) | ||
706 | { | ||
707 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | ||
708 | struct Neighbour *n; | ||
709 | |||
710 | n = neighbour_find (h, | ||
711 | &qm->peer); | ||
712 | if (NULL == n) | 558 | if (NULL == n) |
713 | { | 559 | { |
714 | GNUNET_break (0); | 560 | GNUNET_break (0); |
715 | disconnect_and_schedule_reconnect (h); | 561 | disconnect_and_schedule_reconnect (h); |
716 | return; | 562 | return; |
717 | } | 563 | } |
718 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 564 | GNUNET_MQ_inject_message (n->mq, imm); |
719 | "Receiving SET_QUOTA message for `%s' with quota %u\n", | ||
720 | GNUNET_i2s (&qm->peer), | ||
721 | (unsigned int) ntohl (qm->quota.value__)); | ||
722 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, | ||
723 | qm->quota); | ||
724 | } | 565 | } |
725 | 566 | ||
726 | 567 | ||
@@ -733,46 +574,36 @@ static void | |||
733 | reconnect (void *cls) | 574 | reconnect (void *cls) |
734 | { | 575 | { |
735 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 576 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
736 | struct GNUNET_MQ_MessageHandler handlers[] = { | 577 | struct GNUNET_MQ_MessageHandler handlers[] = |
737 | GNUNET_MQ_hd_fixed_size (connect, | 578 | {GNUNET_MQ_hd_fixed_size (connect, |
738 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | 579 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, |
739 | struct ConnectInfoMessage, | 580 | struct ConnectInfoMessage, |
740 | h), | 581 | h), |
741 | GNUNET_MQ_hd_fixed_size (disconnect, | 582 | GNUNET_MQ_hd_fixed_size (disconnect, |
742 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, | 583 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, |
743 | struct DisconnectInfoMessage, | 584 | struct DisconnectInfoMessage, |
744 | h), | 585 | h), |
745 | GNUNET_MQ_hd_fixed_size (send_ok, | 586 | GNUNET_MQ_hd_fixed_size (send_ok, |
746 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, | 587 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, |
747 | struct SendOkMessage, | 588 | struct SendOkMessage, |
748 | h), | 589 | h), |
749 | GNUNET_MQ_hd_var_size (recv, | 590 | GNUNET_MQ_hd_var_size (recv, |
750 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, | 591 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, |
751 | struct InboundMessage, | 592 | struct InboundMessage, |
752 | h), | 593 | h), |
753 | GNUNET_MQ_hd_fixed_size (set_quota, | 594 | GNUNET_MQ_handler_end ()}; |
754 | GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, | ||
755 | struct QuotaSetMessage, | ||
756 | h), | ||
757 | GNUNET_MQ_handler_end () | ||
758 | }; | ||
759 | struct GNUNET_MQ_Envelope *env; | 595 | struct GNUNET_MQ_Envelope *env; |
760 | struct StartMessage *s; | 596 | struct StartMessage *s; |
761 | uint32_t options; | 597 | uint32_t options; |
762 | 598 | ||
763 | h->reconnect_task = NULL; | 599 | h->reconnect_task = NULL; |
764 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 600 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); |
765 | "Connecting to transport service.\n"); | ||
766 | GNUNET_assert (NULL == h->mq); | 601 | GNUNET_assert (NULL == h->mq); |
767 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 602 | h->mq = |
768 | "transport", | 603 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); |
769 | handlers, | ||
770 | &mq_error_handler, | ||
771 | h); | ||
772 | if (NULL == h->mq) | 604 | if (NULL == h->mq) |
773 | return; | 605 | return; |
774 | env = GNUNET_MQ_msg (s, | 606 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
775 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); | ||
776 | options = 0; | 607 | options = 0; |
777 | if (h->check_self) | 608 | if (h->check_self) |
778 | options |= 1; | 609 | options |= 1; |
@@ -780,8 +611,7 @@ reconnect (void *cls) | |||
780 | options |= 2; | 611 | options |= 2; |
781 | s->options = htonl (options); | 612 | s->options = htonl (options); |
782 | s->self = h->self; | 613 | s->self = h->self; |
783 | GNUNET_MQ_send (h->mq, | 614 | GNUNET_MQ_send (h->mq, env); |
784 | env); | ||
785 | } | 615 | } |
786 | 616 | ||
787 | 617 | ||
@@ -793,9 +623,7 @@ reconnect (void *cls) | |||
793 | static void | 623 | static void |
794 | disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | 624 | disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
795 | { | 625 | { |
796 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, | 626 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); |
797 | &neighbour_delete, | ||
798 | h); | ||
799 | if (NULL != h->mq) | 627 | if (NULL != h->mq) |
800 | { | 628 | { |
801 | GNUNET_MQ_destroy (h->mq); | 629 | GNUNET_MQ_destroy (h->mq); |
@@ -817,12 +645,9 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
817 | disconnect (h); | 645 | disconnect (h); |
818 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 646 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
819 | "Scheduling task to reconnect to transport service in %s.\n", | 647 | "Scheduling task to reconnect to transport service in %s.\n", |
820 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, | 648 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); |
821 | GNUNET_YES)); | ||
822 | h->reconnect_task = | 649 | h->reconnect_task = |
823 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, | 650 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
824 | &reconnect, | ||
825 | h); | ||
826 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 651 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
827 | } | 652 | } |
828 | 653 | ||
@@ -840,8 +665,7 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
840 | { | 665 | { |
841 | struct Neighbour *n; | 666 | struct Neighbour *n; |
842 | 667 | ||
843 | n = neighbour_find (handle, | 668 | n = neighbour_find (handle, peer); |
844 | peer); | ||
845 | if (NULL == n) | 669 | if (NULL == n) |
846 | return NULL; | 670 | return NULL; |
847 | return n->mq; | 671 | return n->mq; |
@@ -849,6 +673,45 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
849 | 673 | ||
850 | 674 | ||
851 | /** | 675 | /** |
676 | * Notification from the CORE service to the TRANSPORT service | ||
677 | * that the CORE service has finished processing a message from | ||
678 | * TRANSPORT (via the @code{handlers} of #GNUNET_TRANSPORT_core_connect()) | ||
679 | * and that it is thus now OK for TRANSPORT to send more messages | ||
680 | * for @a pid. | ||
681 | * | ||
682 | * Used to provide flow control, this is our equivalent to | ||
683 | * #GNUNET_SERVICE_client_continue() of an ordinary service. | ||
684 | * | ||
685 | * Note that due to the use of a window, TRANSPORT may send multiple | ||
686 | * messages destined for the same peer even without an intermediate | ||
687 | * call to this function. However, CORE must still call this function | ||
688 | * once per message received, as otherwise eventually the window will | ||
689 | * be full and TRANSPORT will stop providing messages to CORE for @a | ||
690 | * pid. | ||
691 | * | ||
692 | * @param ch core handle | ||
693 | * @param pid which peer was the message from that was fully processed by CORE | ||
694 | */ | ||
695 | void | ||
696 | GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, | ||
697 | const struct GNUNET_PeerIdentity *pid) | ||
698 | { | ||
699 | struct GNUNET_MQ_Envelope *env; | ||
700 | struct RecvOkMessage *rok; | ||
701 | |||
702 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
703 | "Message for %s finished CORE processing, sending RECV_OK.\n", | ||
704 | GNUNET_i2s (pid)); | ||
705 | if (NULL == ch->mq) | ||
706 | return; | ||
707 | env = GNUNET_MQ_msg (rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); | ||
708 | rok->increase_window_delta = htonl (1); | ||
709 | rok->peer = *pid; | ||
710 | GNUNET_MQ_send (ch->mq, env); | ||
711 | } | ||
712 | |||
713 | |||
714 | /** | ||
852 | * Connect to the transport service. Note that the connection may | 715 | * Connect to the transport service. Note that the connection may |
853 | * complete (or fail) asynchronously. | 716 | * complete (or fail) asynchronously. |
854 | * | 717 | * |
@@ -859,17 +722,15 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
859 | * @param rec receive function to call | 722 | * @param rec receive function to call |
860 | * @param nc function to call on connect events | 723 | * @param nc function to call on connect events |
861 | * @param nd function to call on disconnect events | 724 | * @param nd function to call on disconnect events |
862 | * @param neb function to call if we have excess bandwidth to a peer | ||
863 | * @return NULL on error | 725 | * @return NULL on error |
864 | */ | 726 | */ |
865 | struct GNUNET_TRANSPORT_CoreHandle * | 727 | struct GNUNET_TRANSPORT_CoreHandle * |
866 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 728 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
867 | const struct GNUNET_PeerIdentity *self, | 729 | const struct GNUNET_PeerIdentity *self, |
868 | const struct GNUNET_MQ_MessageHandler *handlers, | 730 | const struct GNUNET_MQ_MessageHandler *handlers, |
869 | void *cls, | 731 | void *cls, |
870 | GNUNET_TRANSPORT_NotifyConnect nc, | 732 | GNUNET_TRANSPORT_NotifyConnect nc, |
871 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 733 | GNUNET_TRANSPORT_NotifyDisconnect nd) |
872 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb) | ||
873 | { | 734 | { |
874 | struct GNUNET_TRANSPORT_CoreHandle *h; | 735 | struct GNUNET_TRANSPORT_CoreHandle *h; |
875 | unsigned int i; | 736 | unsigned int i; |
@@ -884,19 +745,17 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
884 | h->cls = cls; | 745 | h->cls = cls; |
885 | h->nc_cb = nc; | 746 | h->nc_cb = nc; |
886 | h->nd_cb = nd; | 747 | h->nd_cb = nd; |
887 | h->neb_cb = neb; | ||
888 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 748 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
889 | if (NULL != handlers) | 749 | if (NULL != handlers) |
890 | { | 750 | { |
891 | for (i=0;NULL != handlers[i].cb; i++) ; | 751 | for (i = 0; NULL != handlers[i].cb; i++) |
892 | h->handlers = GNUNET_new_array (i + 1, | 752 | ; |
893 | struct GNUNET_MQ_MessageHandler); | 753 | h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); |
894 | GNUNET_memcpy (h->handlers, | 754 | GNUNET_memcpy (h->handlers, |
895 | handlers, | 755 | handlers, |
896 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | 756 | i * sizeof (struct GNUNET_MQ_MessageHandler)); |
897 | } | 757 | } |
898 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 758 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); |
899 | "Connecting to transport service\n"); | ||
900 | reconnect (h); | 759 | reconnect (h); |
901 | if (NULL == h->mq) | 760 | if (NULL == h->mq) |
902 | { | 761 | { |
@@ -905,8 +764,7 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
905 | return NULL; | 764 | return NULL; |
906 | } | 765 | } |
907 | h->neighbours = | 766 | h->neighbours = |
908 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, | 767 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); |
909 | GNUNET_YES); | ||
910 | return h; | 768 | return h; |
911 | } | 769 | } |
912 | 770 | ||
@@ -914,13 +772,13 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
914 | /** | 772 | /** |
915 | * Disconnect from the transport service. | 773 | * Disconnect from the transport service. |
916 | * | 774 | * |
917 | * @param handle handle to the service as returned from #GNUNET_TRANSPORT_core_connect() | 775 | * @param handle handle to the service as returned from |
776 | * #GNUNET_TRANSPORT_core_connect() | ||
918 | */ | 777 | */ |
919 | void | 778 | void |
920 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) | 779 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) |
921 | { | 780 | { |
922 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 781 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); |
923 | "Transport disconnect called!\n"); | ||
924 | /* this disconnects all neighbours... */ | 782 | /* this disconnects all neighbours... */ |
925 | disconnect (handle); | 783 | disconnect (handle); |
926 | /* and now we stop trying to connect again... */ | 784 | /* and now we stop trying to connect again... */ |
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c index e86499173..a163d7ccf 100644 --- a/src/transport/transport_api_core.c +++ b/src/transport/transport_api_core.c | |||
@@ -29,11 +29,10 @@ | |||
29 | #include "gnunet_arm_service.h" | 29 | #include "gnunet_arm_service.h" |
30 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
31 | #include "gnunet_protocols.h" | 31 | #include "gnunet_protocols.h" |
32 | #include "gnunet_transport_core_service.h" | ||
33 | #include "gnunet_transport_service.h" | 32 | #include "gnunet_transport_service.h" |
34 | #include "transport.h" | 33 | #include "transport.h" |
35 | 34 | ||
36 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-api-core",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) |
37 | 36 | ||
38 | /** | 37 | /** |
39 | * If we could not send any payload to a peer for this amount of | 38 | * If we could not send any payload to a peer for this amount of |
@@ -113,11 +112,9 @@ struct Neighbour | |||
113 | * Size of the message in @e env. | 112 | * Size of the message in @e env. |
114 | */ | 113 | */ |
115 | uint16_t env_size; | 114 | uint16_t env_size; |
116 | |||
117 | }; | 115 | }; |
118 | 116 | ||
119 | 117 | ||
120 | |||
121 | /** | 118 | /** |
122 | * Handle for the transport service (includes all of the | 119 | * Handle for the transport service (includes all of the |
123 | * state for the transport service). | 120 | * state for the transport service). |
@@ -187,7 +184,6 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
187 | * (if #GNUNET_NO, then @e self is all zeros!). | 184 | * (if #GNUNET_NO, then @e self is all zeros!). |
188 | */ | 185 | */ |
189 | int check_self; | 186 | int check_self; |
190 | |||
191 | }; | 187 | }; |
192 | 188 | ||
193 | 189 | ||
@@ -212,8 +208,7 @@ static struct Neighbour * | |||
212 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, | 208 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, |
213 | const struct GNUNET_PeerIdentity *peer) | 209 | const struct GNUNET_PeerIdentity *peer) |
214 | { | 210 | { |
215 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, | 211 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); |
216 | peer); | ||
217 | } | 212 | } |
218 | 213 | ||
219 | 214 | ||
@@ -234,9 +229,7 @@ notify_excess_cb (void *cls) | |||
234 | GNUNET_i2s (&n->id)); | 229 | GNUNET_i2s (&n->id)); |
235 | 230 | ||
236 | if (NULL != h->neb_cb) | 231 | if (NULL != h->neb_cb) |
237 | h->neb_cb (h->cls, | 232 | h->neb_cb (h->cls, &n->id, n->handlers_cls); |
238 | &n->id, | ||
239 | n->handlers_cls); | ||
240 | } | 233 | } |
241 | 234 | ||
242 | 235 | ||
@@ -251,9 +244,7 @@ notify_excess_cb (void *cls) | |||
251 | * #GNUNET_NO if not. | 244 | * #GNUNET_NO if not. |
252 | */ | 245 | */ |
253 | static int | 246 | static int |
254 | neighbour_delete (void *cls, | 247 | neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
255 | const struct GNUNET_PeerIdentity *key, | ||
256 | void *value) | ||
257 | { | 248 | { |
258 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; | 249 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; |
259 | struct Neighbour *n = value; | 250 | struct Neighbour *n = value; |
@@ -263,9 +254,7 @@ neighbour_delete (void *cls, | |||
263 | GNUNET_i2s (key)); | 254 | GNUNET_i2s (key)); |
264 | GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker); | 255 | GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker); |
265 | if (NULL != handle->nd_cb) | 256 | if (NULL != handle->nd_cb) |
266 | handle->nd_cb (handle->cls, | 257 | handle->nd_cb (handle->cls, &n->id, n->handlers_cls); |
267 | &n->id, | ||
268 | n->handlers_cls); | ||
269 | if (NULL != n->timeout_task) | 258 | if (NULL != n->timeout_task) |
270 | { | 259 | { |
271 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 260 | GNUNET_SCHEDULER_cancel (n->timeout_task); |
@@ -278,10 +267,9 @@ neighbour_delete (void *cls, | |||
278 | } | 267 | } |
279 | GNUNET_MQ_destroy (n->mq); | 268 | GNUNET_MQ_destroy (n->mq); |
280 | GNUNET_assert (NULL == n->mq); | 269 | GNUNET_assert (NULL == n->mq); |
281 | GNUNET_assert (GNUNET_YES == | 270 | GNUNET_assert ( |
282 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, | 271 | GNUNET_YES == |
283 | key, | 272 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); |
284 | n)); | ||
285 | GNUNET_free (n); | 273 | GNUNET_free (n); |
286 | return GNUNET_YES; | 274 | return GNUNET_YES; |
287 | } | 275 | } |
@@ -297,8 +285,7 @@ neighbour_delete (void *cls, | |||
297 | * @param error error code | 285 | * @param error error code |
298 | */ | 286 | */ |
299 | static void | 287 | static void |
300 | mq_error_handler (void *cls, | 288 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
301 | enum GNUNET_MQ_Error error) | ||
302 | { | 289 | { |
303 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 290 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
304 | 291 | ||
@@ -317,14 +304,12 @@ mq_error_handler (void *cls, | |||
317 | * @return #GNUNET_OK if message is well-formed | 304 | * @return #GNUNET_OK if message is well-formed |
318 | */ | 305 | */ |
319 | static int | 306 | static int |
320 | check_hello (void *cls, | 307 | check_hello (void *cls, const struct GNUNET_MessageHeader *msg) |
321 | const struct GNUNET_MessageHeader *msg) | ||
322 | { | 308 | { |
323 | struct GNUNET_PeerIdentity me; | 309 | struct GNUNET_PeerIdentity me; |
324 | 310 | ||
325 | if (GNUNET_OK != | 311 | if (GNUNET_OK != |
326 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, | 312 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me)) |
327 | &me)) | ||
328 | { | 313 | { |
329 | GNUNET_break (0); | 314 | GNUNET_break (0); |
330 | return GNUNET_SYSERR; | 315 | return GNUNET_SYSERR; |
@@ -340,8 +325,7 @@ check_hello (void *cls, | |||
340 | * @param msg message received | 325 | * @param msg message received |
341 | */ | 326 | */ |
342 | static void | 327 | static void |
343 | handle_hello (void *cls, | 328 | handle_hello (void *cls, const struct GNUNET_MessageHeader *msg) |
344 | const struct GNUNET_MessageHeader *msg) | ||
345 | { | 329 | { |
346 | /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ | 330 | /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ |
347 | } | 331 | } |
@@ -388,8 +372,7 @@ notify_send_done (void *cls) | |||
388 | n->env = NULL; | 372 | n->env = NULL; |
389 | n->traffic_overhead = 0; | 373 | n->traffic_overhead = 0; |
390 | } | 374 | } |
391 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, | 375 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); |
392 | 128); | ||
393 | if (0 == delay.rel_value_us) | 376 | if (0 == delay.rel_value_us) |
394 | { | 377 | { |
395 | n->is_ready = GNUNET_YES; | 378 | n->is_ready = GNUNET_YES; |
@@ -399,9 +382,8 @@ notify_send_done (void *cls) | |||
399 | GNUNET_MQ_impl_send_in_flight (n->mq); | 382 | GNUNET_MQ_impl_send_in_flight (n->mq); |
400 | /* cannot send even a small message without violating | 383 | /* cannot send even a small message without violating |
401 | quota, wait a before allowing MQ to send next message */ | 384 | quota, wait a before allowing MQ to send next message */ |
402 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, | 385 | n->timeout_task = |
403 | ¬ify_send_done_fin, | 386 | GNUNET_SCHEDULER_add_delayed (delay, ¬ify_send_done_fin, n); |
404 | n); | ||
405 | } | 387 | } |
406 | 388 | ||
407 | 389 | ||
@@ -434,20 +416,17 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
434 | return; | 416 | return; |
435 | } | 417 | } |
436 | GNUNET_assert (NULL == n->env); | 418 | GNUNET_assert (NULL == n->env); |
437 | n->env = GNUNET_MQ_msg_nested_mh (obm, | 419 | n->env = |
438 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, | 420 | GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); |
439 | msg); | ||
440 | obm->reserved = htonl (0); | 421 | obm->reserved = htonl (0); |
441 | obm->timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ | 422 | obm->timeout = GNUNET_TIME_relative_hton ( |
423 | GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ | ||
442 | obm->peer = n->id; | 424 | obm->peer = n->id; |
443 | GNUNET_assert (NULL == n->timeout_task); | 425 | GNUNET_assert (NULL == n->timeout_task); |
444 | n->is_ready = GNUNET_NO; | 426 | n->is_ready = GNUNET_NO; |
445 | n->env_size = ntohs (msg->size); | 427 | n->env_size = ntohs (msg->size); |
446 | GNUNET_MQ_notify_sent (n->env, | 428 | GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); |
447 | ¬ify_send_done, | 429 | GNUNET_MQ_send (h->mq, n->env); |
448 | n); | ||
449 | GNUNET_MQ_send (h->mq, | ||
450 | n->env); | ||
451 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 430 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
452 | "Queued message of type %u for neighbour `%s'.\n", | 431 | "Queued message of type %u for neighbour `%s'.\n", |
453 | ntohs (msg->type), | 432 | ntohs (msg->type), |
@@ -463,8 +442,7 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
463 | * @param impl_state state of the implementation | 442 | * @param impl_state state of the implementation |
464 | */ | 443 | */ |
465 | static void | 444 | static void |
466 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, | 445 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
467 | void *impl_state) | ||
468 | { | 446 | { |
469 | struct Neighbour *n = impl_state; | 447 | struct Neighbour *n = impl_state; |
470 | 448 | ||
@@ -481,8 +459,7 @@ mq_destroy_impl (struct GNUNET_MQ_Handle *mq, | |||
481 | * @param impl_state state specific to the implementation | 459 | * @param impl_state state specific to the implementation |
482 | */ | 460 | */ |
483 | static void | 461 | static void |
484 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, | 462 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
485 | void *impl_state) | ||
486 | { | 463 | { |
487 | struct Neighbour *n = impl_state; | 464 | struct Neighbour *n = impl_state; |
488 | 465 | ||
@@ -506,8 +483,7 @@ mq_cancel_impl (struct GNUNET_MQ_Handle *mq, | |||
506 | * @param error error code | 483 | * @param error error code |
507 | */ | 484 | */ |
508 | static void | 485 | static void |
509 | peer_mq_error_handler (void *cls, | 486 | peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
510 | enum GNUNET_MQ_Error error) | ||
511 | { | 487 | { |
512 | /* struct Neighbour *n = cls; */ | 488 | /* struct Neighbour *n = cls; */ |
513 | 489 | ||
@@ -529,12 +505,9 @@ outbound_bw_tracker_update (void *cls) | |||
529 | 505 | ||
530 | if (NULL == n->timeout_task) | 506 | if (NULL == n->timeout_task) |
531 | return; | 507 | return; |
532 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, | 508 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); |
533 | 128); | ||
534 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 509 | GNUNET_SCHEDULER_cancel (n->timeout_task); |
535 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, | 510 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, ¬ify_send_done, n); |
536 | ¬ify_send_done, | ||
537 | n); | ||
538 | } | 511 | } |
539 | 512 | ||
540 | 513 | ||
@@ -545,8 +518,7 @@ outbound_bw_tracker_update (void *cls) | |||
545 | * @param cim message received | 518 | * @param cim message received |
546 | */ | 519 | */ |
547 | static void | 520 | static void |
548 | handle_connect (void *cls, | 521 | handle_connect (void *cls, const struct ConnectInfoMessage *cim) |
549 | const struct ConnectInfoMessage *cim) | ||
550 | { | 522 | { |
551 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 523 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
552 | struct Neighbour *n; | 524 | struct Neighbour *n; |
@@ -555,8 +527,7 @@ handle_connect (void *cls, | |||
555 | "Receiving CONNECT message for `%s' with quota %u\n", | 527 | "Receiving CONNECT message for `%s' with quota %u\n", |
556 | GNUNET_i2s (&cim->id), | 528 | GNUNET_i2s (&cim->id), |
557 | ntohl (cim->quota_out.value__)); | 529 | ntohl (cim->quota_out.value__)); |
558 | n = neighbour_find (h, | 530 | n = neighbour_find (h, &cim->id); |
559 | &cim->id); | ||
560 | if (NULL != n) | 531 | if (NULL != n) |
561 | { | 532 | { |
562 | GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */ | 533 | GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */ |
@@ -576,13 +547,13 @@ handle_connect (void *cls, | |||
576 | ¬ify_excess_cb, | 547 | ¬ify_excess_cb, |
577 | n); | 548 | n); |
578 | GNUNET_assert (GNUNET_OK == | 549 | GNUNET_assert (GNUNET_OK == |
579 | GNUNET_CONTAINER_multipeermap_put (h->neighbours, | 550 | GNUNET_CONTAINER_multipeermap_put ( |
580 | &n->id, | 551 | h->neighbours, |
581 | n, | 552 | &n->id, |
582 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 553 | n, |
554 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
583 | 555 | ||
584 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, | 556 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); |
585 | cim->quota_out); | ||
586 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, | 557 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, |
587 | &mq_destroy_impl, | 558 | &mq_destroy_impl, |
588 | &mq_cancel_impl, | 559 | &mq_cancel_impl, |
@@ -592,11 +563,8 @@ handle_connect (void *cls, | |||
592 | n); | 563 | n); |
593 | if (NULL != h->nc_cb) | 564 | if (NULL != h->nc_cb) |
594 | { | 565 | { |
595 | n->handlers_cls = h->nc_cb (h->cls, | 566 | n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); |
596 | &n->id, | 567 | GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); |
597 | n->mq); | ||
598 | GNUNET_MQ_set_handlers_closure (n->mq, | ||
599 | n->handlers_cls); | ||
600 | } | 568 | } |
601 | } | 569 | } |
602 | 570 | ||
@@ -608,8 +576,7 @@ handle_connect (void *cls, | |||
608 | * @param dim message received | 576 | * @param dim message received |
609 | */ | 577 | */ |
610 | static void | 578 | static void |
611 | handle_disconnect (void *cls, | 579 | handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) |
612 | const struct DisconnectInfoMessage *dim) | ||
613 | { | 580 | { |
614 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 581 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
615 | struct Neighbour *n; | 582 | struct Neighbour *n; |
@@ -625,10 +592,7 @@ handle_disconnect (void *cls, | |||
625 | disconnect_and_schedule_reconnect (h); | 592 | disconnect_and_schedule_reconnect (h); |
626 | return; | 593 | return; |
627 | } | 594 | } |
628 | GNUNET_assert (GNUNET_YES == | 595 | GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); |
629 | neighbour_delete (h, | ||
630 | &dim->peer, | ||
631 | n)); | ||
632 | } | 596 | } |
633 | 597 | ||
634 | 598 | ||
@@ -639,8 +603,7 @@ handle_disconnect (void *cls, | |||
639 | * @param okm message received | 603 | * @param okm message received |
640 | */ | 604 | */ |
641 | static void | 605 | static void |
642 | handle_send_ok (void *cls, | 606 | handle_send_ok (void *cls, const struct SendOkMessage *okm) |
643 | const struct SendOkMessage *okm) | ||
644 | { | 607 | { |
645 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 608 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
646 | struct Neighbour *n; | 609 | struct Neighbour *n; |
@@ -653,8 +616,7 @@ handle_send_ok (void *cls, | |||
653 | "Receiving SEND_OK message, transmission to %s %s.\n", | 616 | "Receiving SEND_OK message, transmission to %s %s.\n", |
654 | GNUNET_i2s (&okm->peer), | 617 | GNUNET_i2s (&okm->peer), |
655 | ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); | 618 | ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); |
656 | n = neighbour_find (h, | 619 | n = neighbour_find (h, &okm->peer); |
657 | &okm->peer); | ||
658 | if (NULL == n) | 620 | if (NULL == n) |
659 | { | 621 | { |
660 | /* We should never get a 'SEND_OK' for a peer that we are not | 622 | /* We should never get a 'SEND_OK' for a peer that we are not |
@@ -681,8 +643,7 @@ handle_send_ok (void *cls, | |||
681 | * @param im message received | 643 | * @param im message received |
682 | */ | 644 | */ |
683 | static int | 645 | static int |
684 | check_recv (void *cls, | 646 | check_recv (void *cls, const struct InboundMessage *im) |
685 | const struct InboundMessage *im) | ||
686 | { | 647 | { |
687 | const struct GNUNET_MessageHeader *imm; | 648 | const struct GNUNET_MessageHeader *imm; |
688 | uint16_t size; | 649 | uint16_t size; |
@@ -710,12 +671,11 @@ check_recv (void *cls, | |||
710 | * @param im message received | 671 | * @param im message received |
711 | */ | 672 | */ |
712 | static void | 673 | static void |
713 | handle_recv (void *cls, | 674 | handle_recv (void *cls, const struct InboundMessage *im) |
714 | const struct InboundMessage *im) | ||
715 | { | 675 | { |
716 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 676 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
717 | const struct GNUNET_MessageHeader *imm | 677 | const struct GNUNET_MessageHeader *imm = |
718 | = (const struct GNUNET_MessageHeader *) &im[1]; | 678 | (const struct GNUNET_MessageHeader *) &im[1]; |
719 | struct Neighbour *n; | 679 | struct Neighbour *n; |
720 | 680 | ||
721 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 681 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -730,8 +690,7 @@ handle_recv (void *cls, | |||
730 | disconnect_and_schedule_reconnect (h); | 690 | disconnect_and_schedule_reconnect (h); |
731 | return; | 691 | return; |
732 | } | 692 | } |
733 | GNUNET_MQ_inject_message (n->mq, | 693 | GNUNET_MQ_inject_message (n->mq, imm); |
734 | imm); | ||
735 | } | 694 | } |
736 | 695 | ||
737 | 696 | ||
@@ -742,8 +701,7 @@ handle_recv (void *cls, | |||
742 | * @param msg message received | 701 | * @param msg message received |
743 | */ | 702 | */ |
744 | static void | 703 | static void |
745 | handle_set_quota (void *cls, | 704 | handle_set_quota (void *cls, const struct QuotaSetMessage *qm) |
746 | const struct QuotaSetMessage *qm) | ||
747 | { | 705 | { |
748 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 706 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
749 | struct Neighbour *n; | 707 | struct Neighbour *n; |
@@ -752,16 +710,15 @@ handle_set_quota (void *cls, | |||
752 | "Receiving SET_QUOTA message for `%s' with quota %u\n", | 710 | "Receiving SET_QUOTA message for `%s' with quota %u\n", |
753 | GNUNET_i2s (&qm->peer), | 711 | GNUNET_i2s (&qm->peer), |
754 | ntohl (qm->quota.value__)); | 712 | ntohl (qm->quota.value__)); |
755 | n = neighbour_find (h, | 713 | n = neighbour_find (h, &qm->peer); |
756 | &qm->peer); | ||
757 | if (NULL == n) | 714 | if (NULL == n) |
758 | { | 715 | { |
759 | GNUNET_break (0); /* FIXME: julius reports this assertion fails sometimes? */ | 716 | GNUNET_break ( |
717 | 0); /* FIXME: julius reports this assertion fails sometimes? */ | ||
760 | disconnect_and_schedule_reconnect (h); | 718 | disconnect_and_schedule_reconnect (h); |
761 | return; | 719 | return; |
762 | } | 720 | } |
763 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, | 721 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota); |
764 | qm->quota); | ||
765 | } | 722 | } |
766 | 723 | ||
767 | 724 | ||
@@ -774,50 +731,44 @@ static void | |||
774 | reconnect (void *cls) | 731 | reconnect (void *cls) |
775 | { | 732 | { |
776 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 733 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
777 | struct GNUNET_MQ_MessageHandler handlers[] = { | 734 | struct GNUNET_MQ_MessageHandler handlers[] = |
778 | GNUNET_MQ_hd_var_size (hello, | 735 | {GNUNET_MQ_hd_var_size (hello, |
779 | GNUNET_MESSAGE_TYPE_HELLO, | 736 | GNUNET_MESSAGE_TYPE_HELLO, |
780 | struct GNUNET_MessageHeader, | 737 | struct GNUNET_MessageHeader, |
781 | h), | 738 | h), |
782 | GNUNET_MQ_hd_fixed_size (connect, | 739 | GNUNET_MQ_hd_fixed_size (connect, |
783 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | 740 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, |
784 | struct ConnectInfoMessage, | 741 | struct ConnectInfoMessage, |
785 | h), | 742 | h), |
786 | GNUNET_MQ_hd_fixed_size (disconnect, | 743 | GNUNET_MQ_hd_fixed_size (disconnect, |
787 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, | 744 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, |
788 | struct DisconnectInfoMessage, | 745 | struct DisconnectInfoMessage, |
789 | h), | 746 | h), |
790 | GNUNET_MQ_hd_fixed_size (send_ok, | 747 | GNUNET_MQ_hd_fixed_size (send_ok, |
791 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, | 748 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, |
792 | struct SendOkMessage, | 749 | struct SendOkMessage, |
793 | h), | 750 | h), |
794 | GNUNET_MQ_hd_var_size (recv, | 751 | GNUNET_MQ_hd_var_size (recv, |
795 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, | 752 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, |
796 | struct InboundMessage, | 753 | struct InboundMessage, |
797 | h), | 754 | h), |
798 | GNUNET_MQ_hd_fixed_size (set_quota, | 755 | GNUNET_MQ_hd_fixed_size (set_quota, |
799 | GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, | 756 | GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, |
800 | struct QuotaSetMessage, | 757 | struct QuotaSetMessage, |
801 | h), | 758 | h), |
802 | GNUNET_MQ_handler_end () | 759 | GNUNET_MQ_handler_end ()}; |
803 | }; | ||
804 | struct GNUNET_MQ_Envelope *env; | 760 | struct GNUNET_MQ_Envelope *env; |
805 | struct StartMessage *s; | 761 | struct StartMessage *s; |
806 | uint32_t options; | 762 | uint32_t options; |
807 | 763 | ||
808 | h->reconnect_task = NULL; | 764 | h->reconnect_task = NULL; |
809 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 765 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); |
810 | "Connecting to transport service.\n"); | ||
811 | GNUNET_assert (NULL == h->mq); | 766 | GNUNET_assert (NULL == h->mq); |
812 | h->mq = GNUNET_CLIENT_connect (h->cfg, | 767 | h->mq = |
813 | "transport", | 768 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); |
814 | handlers, | ||
815 | &mq_error_handler, | ||
816 | h); | ||
817 | if (NULL == h->mq) | 769 | if (NULL == h->mq) |
818 | return; | 770 | return; |
819 | env = GNUNET_MQ_msg (s, | 771 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
820 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); | ||
821 | options = 0; | 772 | options = 0; |
822 | if (h->check_self) | 773 | if (h->check_self) |
823 | options |= 1; | 774 | options |= 1; |
@@ -825,8 +776,7 @@ reconnect (void *cls) | |||
825 | options |= 2; | 776 | options |= 2; |
826 | s->options = htonl (options); | 777 | s->options = htonl (options); |
827 | s->self = h->self; | 778 | s->self = h->self; |
828 | GNUNET_MQ_send (h->mq, | 779 | GNUNET_MQ_send (h->mq, env); |
829 | env); | ||
830 | } | 780 | } |
831 | 781 | ||
832 | 782 | ||
@@ -841,9 +791,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
841 | { | 791 | { |
842 | GNUNET_assert (NULL == h->reconnect_task); | 792 | GNUNET_assert (NULL == h->reconnect_task); |
843 | /* Forget about all neighbours that we used to be connected to */ | 793 | /* Forget about all neighbours that we used to be connected to */ |
844 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, | 794 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); |
845 | &neighbour_delete, | ||
846 | h); | ||
847 | if (NULL != h->mq) | 795 | if (NULL != h->mq) |
848 | { | 796 | { |
849 | GNUNET_MQ_destroy (h->mq); | 797 | GNUNET_MQ_destroy (h->mq); |
@@ -851,12 +799,9 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
851 | } | 799 | } |
852 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 800 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
853 | "Scheduling task to reconnect to transport service in %s.\n", | 801 | "Scheduling task to reconnect to transport service in %s.\n", |
854 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, | 802 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); |
855 | GNUNET_YES)); | ||
856 | h->reconnect_task = | 803 | h->reconnect_task = |
857 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, | 804 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); |
858 | &reconnect, | ||
859 | h); | ||
860 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 805 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
861 | } | 806 | } |
862 | 807 | ||
@@ -874,8 +819,7 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
874 | { | 819 | { |
875 | struct Neighbour *n; | 820 | struct Neighbour *n; |
876 | 821 | ||
877 | n = neighbour_find (handle, | 822 | n = neighbour_find (handle, peer); |
878 | peer); | ||
879 | if (NULL == n) | 823 | if (NULL == n) |
880 | return NULL; | 824 | return NULL; |
881 | return n->mq; | 825 | return n->mq; |
@@ -898,12 +842,12 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
898 | */ | 842 | */ |
899 | struct GNUNET_TRANSPORT_CoreHandle * | 843 | struct GNUNET_TRANSPORT_CoreHandle * |
900 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 844 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
901 | const struct GNUNET_PeerIdentity *self, | 845 | const struct GNUNET_PeerIdentity *self, |
902 | const struct GNUNET_MQ_MessageHandler *handlers, | 846 | const struct GNUNET_MQ_MessageHandler *handlers, |
903 | void *cls, | 847 | void *cls, |
904 | GNUNET_TRANSPORT_NotifyConnect nc, | 848 | GNUNET_TRANSPORT_NotifyConnect nc, |
905 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 849 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
906 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb) | 850 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb) |
907 | { | 851 | { |
908 | struct GNUNET_TRANSPORT_CoreHandle *h; | 852 | struct GNUNET_TRANSPORT_CoreHandle *h; |
909 | unsigned int i; | 853 | unsigned int i; |
@@ -922,15 +866,14 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
922 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 866 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
923 | if (NULL != handlers) | 867 | if (NULL != handlers) |
924 | { | 868 | { |
925 | for (i=0;NULL != handlers[i].cb; i++) ; | 869 | for (i = 0; NULL != handlers[i].cb; i++) |
926 | h->handlers = GNUNET_new_array (i + 1, | 870 | ; |
927 | struct GNUNET_MQ_MessageHandler); | 871 | h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); |
928 | GNUNET_memcpy (h->handlers, | 872 | GNUNET_memcpy (h->handlers, |
929 | handlers, | 873 | handlers, |
930 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | 874 | i * sizeof (struct GNUNET_MQ_MessageHandler)); |
931 | } | 875 | } |
932 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 876 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); |
933 | "Connecting to transport service\n"); | ||
934 | reconnect (h); | 877 | reconnect (h); |
935 | if (NULL == h->mq) | 878 | if (NULL == h->mq) |
936 | { | 879 | { |
@@ -939,8 +882,7 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
939 | return NULL; | 882 | return NULL; |
940 | } | 883 | } |
941 | h->neighbours = | 884 | h->neighbours = |
942 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, | 885 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); |
943 | GNUNET_YES); | ||
944 | return h; | 886 | return h; |
945 | } | 887 | } |
946 | 888 | ||
@@ -948,13 +890,13 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
948 | /** | 890 | /** |
949 | * Disconnect from the transport service. | 891 | * Disconnect from the transport service. |
950 | * | 892 | * |
951 | * @param handle handle to the service as returned from #GNUNET_TRANSPORT_core_connect() | 893 | * @param handle handle to the service as returned from |
894 | * #GNUNET_TRANSPORT_core_connect() | ||
952 | */ | 895 | */ |
953 | void | 896 | void |
954 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) | 897 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) |
955 | { | 898 | { |
956 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 899 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); |
957 | "Transport disconnect called!\n"); | ||
958 | /* this disconnects all neighbours... */ | 900 | /* this disconnects all neighbours... */ |
959 | if (NULL == handle->reconnect_task) | 901 | if (NULL == handle->reconnect_task) |
960 | disconnect_and_schedule_reconnect (handle); | 902 | disconnect_and_schedule_reconnect (handle); |