diff options
Diffstat (limited to 'src/transport/transport_api2_core.c')
-rw-r--r-- | src/transport/transport_api2_core.c | 128 |
1 files changed, 48 insertions, 80 deletions
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c index b7edc3cc1..78d8dcce0 100644 --- a/src/transport/transport_api2_core.c +++ b/src/transport/transport_api2_core.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009-2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2009-2013, 2016, 2018 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 |
@@ -33,12 +33,6 @@ | |||
33 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-api-core",__VA_ARGS__) | 33 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-api-core",__VA_ARGS__) |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * If we could not send any payload to a peer for this amount of | ||
37 | * time, we print a warning. | ||
38 | */ | ||
39 | #define UNREADY_WARN_TIME GNUNET_TIME_UNIT_MINUTES | ||
40 | |||
41 | /** | ||
42 | * How large to start with for the hashmap of neighbours. | 36 | * How large to start with for the hashmap of neighbours. |
43 | */ | 37 | */ |
44 | #define STARTING_NEIGHBOURS_SIZE 16 | 38 | #define STARTING_NEIGHBOURS_SIZE 16 |
@@ -49,6 +43,12 @@ | |||
49 | */ | 43 | */ |
50 | struct Neighbour | 44 | struct Neighbour |
51 | { | 45 | { |
46 | |||
47 | /** | ||
48 | * Identity of this neighbour. | ||
49 | */ | ||
50 | struct GNUNET_PeerIdentity id; | ||
51 | |||
52 | /** | 52 | /** |
53 | * Overall transport handle. | 53 | * Overall transport handle. |
54 | */ | 54 | */ |
@@ -70,16 +70,6 @@ struct Neighbour | |||
70 | void *handlers_cls; | 70 | void *handlers_cls; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Identity of this neighbour. | ||
74 | */ | ||
75 | struct GNUNET_PeerIdentity id; | ||
76 | |||
77 | /** | ||
78 | * Outbound bandwidh tracker. | ||
79 | */ | ||
80 | struct GNUNET_BANDWIDTH_Tracker out_tracker; | ||
81 | |||
82 | /** | ||
83 | * Entry in our readyness heap (which is sorted by @e next_ready | 73 | * Entry in our readyness heap (which is sorted by @e next_ready |
84 | * value). NULL if there is no pending transmission request for | 74 | * value). NULL if there is no pending transmission request for |
85 | * this neighbour or if we're waiting for @e is_ready to become | 75 | * this neighbour or if we're waiting for @e is_ready to become |
@@ -96,6 +86,11 @@ struct Neighbour | |||
96 | struct GNUNET_SCHEDULER_Task *timeout_task; | 86 | struct GNUNET_SCHEDULER_Task *timeout_task; |
97 | 87 | ||
98 | /** | 88 | /** |
89 | * Outbound bandwidh tracker. | ||
90 | */ | ||
91 | struct GNUNET_BANDWIDTH_Tracker out_tracker; | ||
92 | |||
93 | /** | ||
99 | * Sending consumed more bytes on wire than payload was announced | 94 | * Sending consumed more bytes on wire than payload was announced |
100 | * This overhead is added to the delay of next sending operation | 95 | * This overhead is added to the delay of next sending operation |
101 | */ | 96 | */ |
@@ -136,17 +131,17 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
136 | /** | 131 | /** |
137 | * function to call on connect events | 132 | * function to call on connect events |
138 | */ | 133 | */ |
139 | GNUNET_TRANSPORT_NotifyConnecT nc_cb; | 134 | GNUNET_TRANSPORT_NotifyConnect nc_cb; |
140 | 135 | ||
141 | /** | 136 | /** |
142 | * function to call on disconnect events | 137 | * function to call on disconnect events |
143 | */ | 138 | */ |
144 | GNUNET_TRANSPORT_NotifyDisconnecT nd_cb; | 139 | GNUNET_TRANSPORT_NotifyDisconnect nd_cb; |
145 | 140 | ||
146 | /** | 141 | /** |
147 | * function to call on excess bandwidth events | 142 | * function to call on excess bandwidth events |
148 | */ | 143 | */ |
149 | GNUNET_TRANSPORT_NotifyExcessBandwidtH neb_cb; | 144 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb_cb; |
150 | 145 | ||
151 | /** | 146 | /** |
152 | * My client connection to the transport service. | 147 | * My client connection to the transport service. |
@@ -306,44 +301,6 @@ mq_error_handler (void *cls, | |||
306 | 301 | ||
307 | 302 | ||
308 | /** | 303 | /** |
309 | * Function we use for checking incoming HELLO messages. | ||
310 | * | ||
311 | * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *` | ||
312 | * @param msg message received | ||
313 | * @return #GNUNET_OK if message is well-formed | ||
314 | */ | ||
315 | static int | ||
316 | check_hello (void *cls, | ||
317 | const struct GNUNET_MessageHeader *msg) | ||
318 | { | ||
319 | struct GNUNET_PeerIdentity me; | ||
320 | |||
321 | if (GNUNET_OK != | ||
322 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, | ||
323 | &me)) | ||
324 | { | ||
325 | GNUNET_break (0); | ||
326 | return GNUNET_SYSERR; | ||
327 | } | ||
328 | return GNUNET_OK; | ||
329 | } | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Function we use for handling incoming HELLO messages. | ||
334 | * | ||
335 | * @param cls closure, a `struct GNUNET_TRANSPORT_CoreHandle *` | ||
336 | * @param msg message received | ||
337 | */ | ||
338 | static void | ||
339 | handle_hello (void *cls, | ||
340 | const struct GNUNET_MessageHeader *msg) | ||
341 | { | ||
342 | /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ | ||
343 | } | ||
344 | |||
345 | |||
346 | /** | ||
347 | * A message from the handler's message queue to a neighbour was | 304 | * A message from the handler's message queue to a neighbour was |
348 | * transmitted. Now trigger (possibly delayed) notification of the | 305 | * transmitted. Now trigger (possibly delayed) notification of the |
349 | * neighbour's message queue that we are done and thus ready for | 306 | * neighbour's message queue that we are done and thus ready for |
@@ -551,7 +508,8 @@ handle_connect (void *cls, | |||
551 | "Receiving CONNECT message for `%s' with quota %u\n", | 508 | "Receiving CONNECT message for `%s' with quota %u\n", |
552 | GNUNET_i2s (&cim->id), | 509 | GNUNET_i2s (&cim->id), |
553 | ntohl (cim->quota_out.value__)); | 510 | ntohl (cim->quota_out.value__)); |
554 | n = neighbour_find (h, &cim->id); | 511 | n = neighbour_find (h, |
512 | &cim->id); | ||
555 | if (NULL != n) | 513 | if (NULL != n) |
556 | { | 514 | { |
557 | GNUNET_break (0); | 515 | GNUNET_break (0); |
@@ -613,7 +571,8 @@ handle_disconnect (void *cls, | |||
613 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 571 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
614 | "Receiving DISCONNECT message for `%s'.\n", | 572 | "Receiving DISCONNECT message for `%s'.\n", |
615 | GNUNET_i2s (&dim->peer)); | 573 | GNUNET_i2s (&dim->peer)); |
616 | n = neighbour_find (h, &dim->peer); | 574 | n = neighbour_find (h, |
575 | &dim->peer); | ||
617 | if (NULL == n) | 576 | if (NULL == n) |
618 | { | 577 | { |
619 | GNUNET_break (0); | 578 | GNUNET_break (0); |
@@ -647,7 +606,9 @@ handle_send_ok (void *cls, | |||
647 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 606 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
648 | "Receiving SEND_OK message, transmission to %s %s.\n", | 607 | "Receiving SEND_OK message, transmission to %s %s.\n", |
649 | GNUNET_i2s (&okm->peer), | 608 | GNUNET_i2s (&okm->peer), |
650 | ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); | 609 | (GNUNET_OK == ntohl (okm->success)) |
610 | ? "succeeded" | ||
611 | : "failed"); | ||
651 | n = neighbour_find (h, | 612 | n = neighbour_find (h, |
652 | &okm->peer); | 613 | &okm->peer); |
653 | if (NULL == n) | 614 | if (NULL == n) |
@@ -662,8 +623,8 @@ handle_send_ok (void *cls, | |||
662 | { | 623 | { |
663 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 624 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
664 | "Overhead for %u byte message was %u\n", | 625 | "Overhead for %u byte message was %u\n", |
665 | bytes_msg, | 626 | (unsigned int) bytes_msg, |
666 | bytes_physical - bytes_msg); | 627 | (unsigned int) (bytes_physical - bytes_msg)); |
667 | n->traffic_overhead += bytes_physical - bytes_msg; | 628 | n->traffic_overhead += bytes_physical - bytes_msg; |
668 | } | 629 | } |
669 | } | 630 | } |
@@ -677,7 +638,7 @@ handle_send_ok (void *cls, | |||
677 | */ | 638 | */ |
678 | static int | 639 | static int |
679 | check_recv (void *cls, | 640 | check_recv (void *cls, |
680 | const struct InboundMessage *im) | 641 | const struct InboundMessage *im) |
681 | { | 642 | { |
682 | const struct GNUNET_MessageHeader *imm; | 643 | const struct GNUNET_MessageHeader *imm; |
683 | uint16_t size; | 644 | uint16_t size; |
@@ -718,7 +679,8 @@ handle_recv (void *cls, | |||
718 | (unsigned int) ntohs (imm->type), | 679 | (unsigned int) ntohs (imm->type), |
719 | (unsigned int) ntohs (imm->size), | 680 | (unsigned int) ntohs (imm->size), |
720 | GNUNET_i2s (&im->peer)); | 681 | GNUNET_i2s (&im->peer)); |
721 | n = neighbour_find (h, &im->peer); | 682 | n = neighbour_find (h, |
683 | &im->peer); | ||
722 | if (NULL == n) | 684 | if (NULL == n) |
723 | { | 685 | { |
724 | GNUNET_break (0); | 686 | GNUNET_break (0); |
@@ -754,7 +716,7 @@ handle_set_quota (void *cls, | |||
754 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 716 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
755 | "Receiving SET_QUOTA message for `%s' with quota %u\n", | 717 | "Receiving SET_QUOTA message for `%s' with quota %u\n", |
756 | GNUNET_i2s (&qm->peer), | 718 | GNUNET_i2s (&qm->peer), |
757 | ntohl (qm->quota.value__)); | 719 | (unsigned int) ntohl (qm->quota.value__)); |
758 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, | 720 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, |
759 | qm->quota); | 721 | qm->quota); |
760 | } | 722 | } |
@@ -770,10 +732,6 @@ reconnect (void *cls) | |||
770 | { | 732 | { |
771 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 733 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
772 | struct GNUNET_MQ_MessageHandler handlers[] = { | 734 | struct GNUNET_MQ_MessageHandler handlers[] = { |
773 | GNUNET_MQ_hd_var_size (hello, | ||
774 | GNUNET_MESSAGE_TYPE_HELLO, | ||
775 | struct GNUNET_MessageHeader, | ||
776 | h), | ||
777 | GNUNET_MQ_hd_fixed_size (connect, | 735 | GNUNET_MQ_hd_fixed_size (connect, |
778 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | 736 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, |
779 | struct ConnectInfoMessage, | 737 | struct ConnectInfoMessage, |
@@ -826,16 +784,13 @@ reconnect (void *cls) | |||
826 | 784 | ||
827 | 785 | ||
828 | /** | 786 | /** |
829 | * Function that will schedule the job that will try | 787 | * Disconnect from the transport service. |
830 | * to connect us again to the client. | ||
831 | * | 788 | * |
832 | * @param h transport service to reconnect | 789 | * @param h transport service to reconnect |
833 | */ | 790 | */ |
834 | static void | 791 | static void |
835 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | 792 | disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
836 | { | 793 | { |
837 | GNUNET_assert (NULL == h->reconnect_task); | ||
838 | /* Forget about all neighbours that we used to be connected to */ | ||
839 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, | 794 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, |
840 | &neighbour_delete, | 795 | &neighbour_delete, |
841 | h); | 796 | h); |
@@ -844,6 +799,20 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
844 | GNUNET_MQ_destroy (h->mq); | 799 | GNUNET_MQ_destroy (h->mq); |
845 | h->mq = NULL; | 800 | h->mq = NULL; |
846 | } | 801 | } |
802 | } | ||
803 | |||
804 | |||
805 | /** | ||
806 | * Function that will schedule the job that will try | ||
807 | * to connect us again to the client. | ||
808 | * | ||
809 | * @param h transport service to reconnect | ||
810 | */ | ||
811 | static void | ||
812 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | ||
813 | { | ||
814 | GNUNET_assert (NULL == h->reconnect_task); | ||
815 | disconnect (h); | ||
847 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 816 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
848 | "Scheduling task to reconnect to transport service in %s.\n", | 817 | "Scheduling task to reconnect to transport service in %s.\n", |
849 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, | 818 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, |
@@ -896,9 +865,9 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
896 | const struct GNUNET_PeerIdentity *self, | 865 | const struct GNUNET_PeerIdentity *self, |
897 | const struct GNUNET_MQ_MessageHandler *handlers, | 866 | const struct GNUNET_MQ_MessageHandler *handlers, |
898 | void *cls, | 867 | void *cls, |
899 | GNUNET_TRANSPORT_NotifyConnecT nc, | 868 | GNUNET_TRANSPORT_NotifyConnect nc, |
900 | GNUNET_TRANSPORT_NotifyDisconnecT nd, | 869 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
901 | GNUNET_TRANSPORT_NotifyExcessBandwidtH neb) | 870 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb) |
902 | { | 871 | { |
903 | struct GNUNET_TRANSPORT_CoreHandle *h; | 872 | struct GNUNET_TRANSPORT_CoreHandle *h; |
904 | unsigned int i; | 873 | unsigned int i; |
@@ -951,8 +920,7 @@ GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) | |||
951 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 920 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
952 | "Transport disconnect called!\n"); | 921 | "Transport disconnect called!\n"); |
953 | /* this disconnects all neighbours... */ | 922 | /* this disconnects all neighbours... */ |
954 | if (NULL == handle->reconnect_task) | 923 | disconnect (handle); |
955 | disconnect_and_schedule_reconnect (handle); | ||
956 | /* and now we stop trying to connect again... */ | 924 | /* and now we stop trying to connect again... */ |
957 | if (NULL != handle->reconnect_task) | 925 | if (NULL != handle->reconnect_task) |
958 | { | 926 | { |