diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-21 13:48:14 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-21 13:48:14 +0000 |
commit | c13dfb403b26b07486953500103bccf9132654d6 (patch) | |
tree | cd4e7ed6ddae473bdb11fe8d54a48ec0a10363ab /src/transport | |
parent | b14bc9fba69cf77acd84995881e744016eea702c (diff) | |
download | gnunet-c13dfb403b26b07486953500103bccf9132654d6.tar.gz gnunet-c13dfb403b26b07486953500103bccf9132654d6.zip |
still massively broken, but this stuff now compiles... transport_api.c needs work (who is going to do that?)
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 371 | ||||
-rw-r--r-- | src/transport/plugin_transport.h | 13 | ||||
-rw-r--r-- | src/transport/test_transport_api.c | 43 |
3 files changed, 273 insertions, 154 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index c106457d9..553ffb4d3 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -173,11 +173,11 @@ struct TransportPlugin | |||
173 | int rebuild; | 173 | int rebuild; |
174 | }; | 174 | }; |
175 | 175 | ||
176 | struct NeighbourList; | 176 | struct NeighborList; |
177 | 177 | ||
178 | /** | 178 | /** |
179 | * For each neighbour we keep a list of messages | 179 | * For each neighbor we keep a list of messages |
180 | * that we still want to transmit to the neighbour. | 180 | * that we still want to transmit to the neighbor. |
181 | */ | 181 | */ |
182 | struct MessageQueue | 182 | struct MessageQueue |
183 | { | 183 | { |
@@ -200,9 +200,9 @@ struct MessageQueue | |||
200 | struct TransportClient *client; | 200 | struct TransportClient *client; |
201 | 201 | ||
202 | /** | 202 | /** |
203 | * Neighbour this entry belongs to. | 203 | * Neighbor this entry belongs to. |
204 | */ | 204 | */ |
205 | struct NeighbourList *neighbour; | 205 | struct NeighborList *neighbor; |
206 | 206 | ||
207 | /** | 207 | /** |
208 | * Plugin that we used for the transmission. | 208 | * Plugin that we used for the transmission. |
@@ -228,7 +228,7 @@ struct MessageQueue | |||
228 | 228 | ||
229 | 229 | ||
230 | /** | 230 | /** |
231 | * For a given Neighbour, which plugins are available | 231 | * For a given Neighbor, which plugins are available |
232 | * to talk to this peer and what are their costs? | 232 | * to talk to this peer and what are their costs? |
233 | */ | 233 | */ |
234 | struct ReadyList | 234 | struct ReadyList |
@@ -246,9 +246,9 @@ struct ReadyList | |||
246 | struct TransportPlugin *plugin; | 246 | struct TransportPlugin *plugin; |
247 | 247 | ||
248 | /** | 248 | /** |
249 | * Neighbour this entry belongs to. | 249 | * Neighbor this entry belongs to. |
250 | */ | 250 | */ |
251 | struct NeighbourList *neighbour; | 251 | struct NeighborList *neighbor; |
252 | 252 | ||
253 | /** | 253 | /** |
254 | * What was the last latency observed for this plugin | 254 | * What was the last latency observed for this plugin |
@@ -296,15 +296,15 @@ struct ReadyList | |||
296 | 296 | ||
297 | 297 | ||
298 | /** | 298 | /** |
299 | * Entry in linked list of all of our current neighbours. | 299 | * Entry in linked list of all of our current neighbors. |
300 | */ | 300 | */ |
301 | struct NeighbourList | 301 | struct NeighborList |
302 | { | 302 | { |
303 | 303 | ||
304 | /** | 304 | /** |
305 | * This is a linked list. | 305 | * This is a linked list. |
306 | */ | 306 | */ |
307 | struct NeighbourList *next; | 307 | struct NeighborList *next; |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Which of our transports is connected to this peer | 310 | * Which of our transports is connected to this peer |
@@ -319,10 +319,20 @@ struct NeighbourList | |||
319 | struct MessageQueue *messages; | 319 | struct MessageQueue *messages; |
320 | 320 | ||
321 | /** | 321 | /** |
322 | * Identity of this neighbour. | 322 | * Identity of this neighbor. |
323 | */ | 323 | */ |
324 | struct GNUNET_PeerIdentity id; | 324 | struct GNUNET_PeerIdentity id; |
325 | 325 | ||
326 | /* | ||
327 | * Opaque addr of this peer, only known to the plugin | ||
328 | */ | ||
329 | char *addr; | ||
330 | |||
331 | /* | ||
332 | * Size of addr | ||
333 | */ | ||
334 | size_t addr_len; | ||
335 | |||
326 | /** | 336 | /** |
327 | * ID of task scheduled to run when this peer is about to | 337 | * ID of task scheduled to run when this peer is about to |
328 | * time out (will free resources associated with the peer). | 338 | * time out (will free resources associated with the peer). |
@@ -354,7 +364,7 @@ struct NeighbourList | |||
354 | uint64_t last_received; | 364 | uint64_t last_received; |
355 | 365 | ||
356 | /** | 366 | /** |
357 | * Global quota for inbound traffic for the neighbour in bytes/ms. | 367 | * Global quota for inbound traffic for the neighbor in bytes/ms. |
358 | */ | 368 | */ |
359 | uint32_t quota_in; | 369 | uint32_t quota_in; |
360 | 370 | ||
@@ -367,12 +377,20 @@ struct NeighbourList | |||
367 | unsigned int quota_violation_count; | 377 | unsigned int quota_violation_count; |
368 | 378 | ||
369 | /** | 379 | /** |
370 | * Have we seen an ACK from this neighbour in the past? | 380 | * Have we seen an ACK from this neighbor in the past? |
371 | * (used to make up a fake ACK for clients connecting after | 381 | * (used to make up a fake ACK for clients connecting after |
372 | * the neighbour connected to us). | 382 | * the neighbor connected to us). |
373 | */ | 383 | */ |
374 | int saw_ack; | 384 | int saw_ack; |
375 | 385 | ||
386 | /* The latency we have seen for this particular address for | ||
387 | * this particular peer. This latency may have been calculated | ||
388 | * over multiple transports. This value reflects how long it took | ||
389 | * us to receive a response when SENDING via this particular | ||
390 | * transport/neighbor/address combination! | ||
391 | */ | ||
392 | struct GNUNET_TIME_RelativeNBO latency; | ||
393 | |||
376 | }; | 394 | }; |
377 | 395 | ||
378 | 396 | ||
@@ -517,7 +535,7 @@ static struct GNUNET_HELLO_Message *our_hello; | |||
517 | 535 | ||
518 | /** | 536 | /** |
519 | * "version" of "our_hello". Used to see if a given | 537 | * "version" of "our_hello". Used to see if a given |
520 | * neighbour has already been sent the latest version | 538 | * neighbor has already been sent the latest version |
521 | * of our HELLO message. | 539 | * of our HELLO message. |
522 | */ | 540 | */ |
523 | static unsigned int our_hello_version; | 541 | static unsigned int our_hello_version; |
@@ -563,28 +581,43 @@ static struct TransportPlugin *plugins; | |||
563 | static struct GNUNET_SERVER_Handle *server; | 581 | static struct GNUNET_SERVER_Handle *server; |
564 | 582 | ||
565 | /** | 583 | /** |
566 | * All known neighbours and their HELLOs. | 584 | * All known neighbors and their HELLOs. |
567 | */ | 585 | */ |
568 | static struct NeighbourList *neighbours; | 586 | static struct NeighborList *neighbors; |
569 | 587 | ||
570 | /** | 588 | /** |
571 | * Number of neighbours we'd like to have. | 589 | * Number of neighbors we'd like to have. |
572 | */ | 590 | */ |
573 | static uint32_t max_connect_per_transport; | 591 | static uint32_t max_connect_per_transport; |
574 | 592 | ||
575 | 593 | ||
576 | /** | 594 | /** |
577 | * Find an entry in the neighbour list for a particular peer. | 595 | * Find an entry in the neighbor list for a particular peer. |
596 | * if sender_address is not specified (NULL) then return the | ||
597 | * first matching entry. If sender_address is specified, then | ||
598 | * make sure that the address and address_len also matches. | ||
578 | * | 599 | * |
579 | * @return NULL if not found. | 600 | * @return NULL if not found. |
580 | */ | 601 | */ |
581 | static struct NeighbourList * | 602 | static struct NeighborList * |
582 | find_neighbour (const struct GNUNET_PeerIdentity *key) | 603 | find_neighbor (const struct GNUNET_PeerIdentity *key, const char *sender_address, |
604 | size_t sender_address_len) | ||
583 | { | 605 | { |
584 | struct NeighbourList *head = neighbours; | 606 | struct NeighborList *head = neighbors; |
585 | while ((head != NULL) && | 607 | if (sender_address == NULL) |
586 | (0 != memcmp (key, &head->id, sizeof (struct GNUNET_PeerIdentity)))) | 608 | { |
587 | head = head->next; | 609 | while ((head != NULL) && |
610 | (0 != memcmp (key, &head->id, sizeof (struct GNUNET_PeerIdentity)))) | ||
611 | head = head->next; | ||
612 | } | ||
613 | else | ||
614 | { | ||
615 | while ((head != NULL) && | ||
616 | (0 != memcmp (key, &head->id, sizeof (struct GNUNET_PeerIdentity))) && | ||
617 | (sender_address_len != head->addr_len) && | ||
618 | (0 != memcmp (sender_address, &head->addr, head->addr_len))) | ||
619 | head = head->next; | ||
620 | } | ||
588 | return head; | 621 | return head; |
589 | } | 622 | } |
590 | 623 | ||
@@ -605,10 +638,10 @@ find_transport (const char *short_name) | |||
605 | 638 | ||
606 | 639 | ||
607 | /** | 640 | /** |
608 | * Update the quota values for the given neighbour now. | 641 | * Update the quota values for the given neighbor now. |
609 | */ | 642 | */ |
610 | static void | 643 | static void |
611 | update_quota (struct NeighbourList *n) | 644 | update_quota (struct NeighborList *n) |
612 | { | 645 | { |
613 | struct GNUNET_TIME_Relative delta; | 646 | struct GNUNET_TIME_Relative delta; |
614 | uint64_t allowed; | 647 | uint64_t allowed; |
@@ -775,22 +808,22 @@ transmit_to_client (struct TransportClient *client, | |||
775 | /** | 808 | /** |
776 | * Find alternative plugins for communication. | 809 | * Find alternative plugins for communication. |
777 | * | 810 | * |
778 | * @param neighbour for which neighbour should we try to find | 811 | * @param neighbor for which neighbor should we try to find |
779 | * more plugins? | 812 | * more plugins? |
780 | */ | 813 | */ |
781 | static void | 814 | static void |
782 | try_alternative_plugins (struct NeighbourList *neighbour) | 815 | try_alternative_plugins (struct NeighborList *neighbor) |
783 | { | 816 | { |
784 | struct ReadyList *rl; | 817 | struct ReadyList *rl; |
785 | 818 | ||
786 | if ((neighbour->plugins != NULL) && | 819 | if ((neighbor->plugins != NULL) && |
787 | (neighbour->retry_plugins_time.value > | 820 | (neighbor->retry_plugins_time.value > |
788 | GNUNET_TIME_absolute_get ().value)) | 821 | GNUNET_TIME_absolute_get ().value)) |
789 | return; /* don't try right now */ | 822 | return; /* don't try right now */ |
790 | neighbour->retry_plugins_time | 823 | neighbor->retry_plugins_time |
791 | = GNUNET_TIME_relative_to_absolute (PLUGIN_RETRY_FREQUENCY); | 824 | = GNUNET_TIME_relative_to_absolute (PLUGIN_RETRY_FREQUENCY); |
792 | 825 | ||
793 | rl = neighbour->plugins; | 826 | rl = neighbor->plugins; |
794 | while (rl != NULL) | 827 | while (rl != NULL) |
795 | { | 828 | { |
796 | if (rl->connect_attempts > 0) | 829 | if (rl->connect_attempts > 0) |
@@ -802,29 +835,29 @@ try_alternative_plugins (struct NeighbourList *neighbour) | |||
802 | 835 | ||
803 | 836 | ||
804 | /** | 837 | /** |
805 | * The peer specified by the given neighbour has timed-out or a plugin | 838 | * The peer specified by the given neighbor has timed-out or a plugin |
806 | * has disconnected. We may either need to do nothing (other plugins | 839 | * has disconnected. We may either need to do nothing (other plugins |
807 | * still up), or trigger a full disconnect and clean up. This | 840 | * still up), or trigger a full disconnect and clean up. This |
808 | * function updates our state and do the necessary notifications. | 841 | * function updates our state and do the necessary notifications. |
809 | * Also notifies our clients that the neighbour is now officially | 842 | * Also notifies our clients that the neighbor is now officially |
810 | * gone. | 843 | * gone. |
811 | * | 844 | * |
812 | * @param n the neighbour list entry for the peer | 845 | * @param n the neighbor list entry for the peer |
813 | * @param check should we just check if all plugins | 846 | * @param check should we just check if all plugins |
814 | * disconnected or must we ask all plugins to | 847 | * disconnected or must we ask all plugins to |
815 | * disconnect? | 848 | * disconnect? |
816 | */ | 849 | */ |
817 | static void disconnect_neighbour (struct NeighbourList *n, int check); | 850 | static void disconnect_neighbor (struct NeighborList *n, int check); |
818 | 851 | ||
819 | 852 | ||
820 | /** | 853 | /** |
821 | * Check the ready list for the given neighbour and | 854 | * Check the ready list for the given neighbor and |
822 | * if a plugin is ready for transmission (and if we | 855 | * if a plugin is ready for transmission (and if we |
823 | * have a message), do so! | 856 | * have a message), do so! |
824 | * | 857 | * |
825 | * @param neighbour target peer for which to check the plugins | 858 | * @param neighbor target peer for which to check the plugins |
826 | */ | 859 | */ |
827 | static void try_transmission_to_peer (struct NeighbourList *neighbour); | 860 | static void try_transmission_to_peer (struct NeighborList *neighbor); |
828 | 861 | ||
829 | 862 | ||
830 | /** | 863 | /** |
@@ -849,10 +882,10 @@ transmit_send_continuation (void *cls, | |||
849 | struct MessageQueue *mq = cls; | 882 | struct MessageQueue *mq = cls; |
850 | struct ReadyList *rl; | 883 | struct ReadyList *rl; |
851 | struct SendOkMessage send_ok_msg; | 884 | struct SendOkMessage send_ok_msg; |
852 | struct NeighbourList *n; | 885 | struct NeighborList *n; |
853 | 886 | ||
854 | GNUNET_assert (mq != NULL); | 887 | GNUNET_assert (mq != NULL); |
855 | n = mq->neighbour; | 888 | n = mq->neighbor; |
856 | GNUNET_assert (n != NULL); | 889 | GNUNET_assert (n != NULL); |
857 | GNUNET_assert (0 == | 890 | GNUNET_assert (0 == |
858 | memcmp (&n->id, target, | 891 | memcmp (&n->id, target, |
@@ -894,17 +927,17 @@ transmit_send_continuation (void *cls, | |||
894 | if (result == GNUNET_OK) | 927 | if (result == GNUNET_OK) |
895 | try_transmission_to_peer (n); | 928 | try_transmission_to_peer (n); |
896 | else | 929 | else |
897 | disconnect_neighbour (n, GNUNET_YES); | 930 | disconnect_neighbor (n, GNUNET_YES); |
898 | } | 931 | } |
899 | 932 | ||
900 | 933 | ||
901 | /** | 934 | /** |
902 | * Check the ready list for the given neighbour and | 935 | * Check the ready list for the given neighbor and |
903 | * if a plugin is ready for transmission (and if we | 936 | * if a plugin is ready for transmission (and if we |
904 | * have a message), do so! | 937 | * have a message), do so! |
905 | */ | 938 | */ |
906 | static void | 939 | static void |
907 | try_transmission_to_peer (struct NeighbourList *neighbour) | 940 | try_transmission_to_peer (struct NeighborList *neighbor) |
908 | { | 941 | { |
909 | struct ReadyList *pos; | 942 | struct ReadyList *pos; |
910 | struct GNUNET_TIME_Relative min_latency; | 943 | struct GNUNET_TIME_Relative min_latency; |
@@ -912,14 +945,14 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
912 | struct MessageQueue *mq; | 945 | struct MessageQueue *mq; |
913 | struct GNUNET_TIME_Absolute now; | 946 | struct GNUNET_TIME_Absolute now; |
914 | 947 | ||
915 | if (neighbour->messages == NULL) | 948 | if (neighbor->messages == NULL) |
916 | return; /* nothing to do */ | 949 | return; /* nothing to do */ |
917 | try_alternative_plugins (neighbour); | 950 | try_alternative_plugins (neighbor); |
918 | min_latency = GNUNET_TIME_UNIT_FOREVER_REL; | 951 | min_latency = GNUNET_TIME_UNIT_FOREVER_REL; |
919 | rl = NULL; | 952 | rl = NULL; |
920 | mq = neighbour->messages; | 953 | mq = neighbor->messages; |
921 | now = GNUNET_TIME_absolute_get (); | 954 | now = GNUNET_TIME_absolute_get (); |
922 | pos = neighbour->plugins; | 955 | pos = neighbor->plugins; |
923 | while (pos != NULL) | 956 | while (pos != NULL) |
924 | { | 957 | { |
925 | /* set plugins that are inactive for a long time back to disconnected */ | 958 | /* set plugins that are inactive for a long time back to disconnected */ |
@@ -928,7 +961,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
928 | #if DEBUG_TRANSPORT | 961 | #if DEBUG_TRANSPORT |
929 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 962 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
930 | "Marking long-time inactive connection to `%4s' as down.\n", | 963 | "Marking long-time inactive connection to `%4s' as down.\n", |
931 | GNUNET_i2s (&neighbour->id)); | 964 | GNUNET_i2s (&neighbor->id)); |
932 | #endif | 965 | #endif |
933 | pos->connected = GNUNET_NO; | 966 | pos->connected = GNUNET_NO; |
934 | } | 967 | } |
@@ -957,10 +990,10 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
957 | #if DEBUG_TRANSPORT | 990 | #if DEBUG_TRANSPORT |
958 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
959 | "Establishing fresh connection with `%4s' via plugin `%s'\n", | 992 | "Establishing fresh connection with `%4s' via plugin `%s'\n", |
960 | GNUNET_i2s (&neighbour->id), rl->plugin->short_name); | 993 | GNUNET_i2s (&neighbor->id), rl->plugin->short_name); |
961 | #endif | 994 | #endif |
962 | } | 995 | } |
963 | neighbour->messages = mq->next; | 996 | neighbor->messages = mq->next; |
964 | mq->plugin = rl->plugin; | 997 | mq->plugin = rl->plugin; |
965 | if (!mq->internal_msg) | 998 | if (!mq->internal_msg) |
966 | rl->transmit_ready = GNUNET_NO; | 999 | rl->transmit_ready = GNUNET_NO; |
@@ -968,13 +1001,17 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
968 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1001 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
969 | "Giving message of type `%u' for `%4s' to plugin `%s'\n", | 1002 | "Giving message of type `%u' for `%4s' to plugin `%s'\n", |
970 | ntohs (mq->message->type), | 1003 | ntohs (mq->message->type), |
971 | GNUNET_i2s (&neighbour->id), rl->plugin->short_name); | 1004 | GNUNET_i2s (&neighbor->id), rl->plugin->short_name); |
972 | #endif | 1005 | #endif |
1006 | |||
973 | rl->plugin->api->send (rl->plugin->api->cls, | 1007 | rl->plugin->api->send (rl->plugin->api->cls, |
974 | &neighbour->id, | 1008 | &neighbor->id, |
975 | mq->priority, | ||
976 | mq->message, | 1009 | mq->message, |
1010 | mq->priority, | ||
977 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1011 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1012 | rl->neighbor->addr, | ||
1013 | rl->neighbor->addr_len, | ||
1014 | GNUNET_NO, | ||
978 | &transmit_send_continuation, mq); | 1015 | &transmit_send_continuation, mq); |
979 | } | 1016 | } |
980 | 1017 | ||
@@ -986,13 +1023,13 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
986 | * @param priority how important is the message | 1023 | * @param priority how important is the message |
987 | * @param msg message to send | 1024 | * @param msg message to send |
988 | * @param is_internal is this an internal message | 1025 | * @param is_internal is this an internal message |
989 | * @param neighbour handle to the neighbour for transmission | 1026 | * @param neighbor handle to the neighbor for transmission |
990 | */ | 1027 | */ |
991 | static void | 1028 | static void |
992 | transmit_to_peer (struct TransportClient *client, | 1029 | transmit_to_peer (struct TransportClient *client, |
993 | unsigned int priority, | 1030 | unsigned int priority, |
994 | const struct GNUNET_MessageHeader *msg, | 1031 | const struct GNUNET_MessageHeader *msg, |
995 | int is_internal, struct NeighbourList *neighbour) | 1032 | int is_internal, struct NeighborList *neighbor) |
996 | { | 1033 | { |
997 | struct MessageQueue *mq; | 1034 | struct MessageQueue *mq; |
998 | struct MessageQueue *mqe; | 1035 | struct MessageQueue *mqe; |
@@ -1001,12 +1038,12 @@ transmit_to_peer (struct TransportClient *client, | |||
1001 | #if DEBUG_TRANSPORT | 1038 | #if DEBUG_TRANSPORT |
1002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1003 | _("Sending message of type %u to peer `%4s'\n"), | 1040 | _("Sending message of type %u to peer `%4s'\n"), |
1004 | ntohs (msg->type), GNUNET_i2s (&neighbour->id)); | 1041 | ntohs (msg->type), GNUNET_i2s (&neighbor->id)); |
1005 | #endif | 1042 | #endif |
1006 | if (client != NULL) | 1043 | if (client != NULL) |
1007 | { | 1044 | { |
1008 | /* check for duplicate submission */ | 1045 | /* check for duplicate submission */ |
1009 | mq = neighbour->messages; | 1046 | mq = neighbor->messages; |
1010 | while (NULL != mq) | 1047 | while (NULL != mq) |
1011 | { | 1048 | { |
1012 | if (mq->client == client) | 1049 | if (mq->client == client) |
@@ -1024,20 +1061,20 @@ transmit_to_peer (struct TransportClient *client, | |||
1024 | m = GNUNET_malloc (ntohs (msg->size)); | 1061 | m = GNUNET_malloc (ntohs (msg->size)); |
1025 | memcpy (m, msg, ntohs (msg->size)); | 1062 | memcpy (m, msg, ntohs (msg->size)); |
1026 | mq->message = m; | 1063 | mq->message = m; |
1027 | mq->neighbour = neighbour; | 1064 | mq->neighbor = neighbor; |
1028 | mq->internal_msg = is_internal; | 1065 | mq->internal_msg = is_internal; |
1029 | mq->priority = priority; | 1066 | mq->priority = priority; |
1030 | 1067 | ||
1031 | /* find tail */ | 1068 | /* find tail */ |
1032 | mqe = neighbour->messages; | 1069 | mqe = neighbor->messages; |
1033 | if (mqe != NULL) | 1070 | if (mqe != NULL) |
1034 | while (mqe->next != NULL) | 1071 | while (mqe->next != NULL) |
1035 | mqe = mqe->next; | 1072 | mqe = mqe->next; |
1036 | if (mqe == NULL) | 1073 | if (mqe == NULL) |
1037 | { | 1074 | { |
1038 | /* new head */ | 1075 | /* new head */ |
1039 | neighbour->messages = mq; | 1076 | neighbor->messages = mq; |
1040 | try_transmission_to_peer (neighbour); | 1077 | try_transmission_to_peer (neighbor); |
1041 | } | 1078 | } |
1042 | else | 1079 | else |
1043 | { | 1080 | { |
@@ -1092,7 +1129,7 @@ refresh_hello () | |||
1092 | { | 1129 | { |
1093 | struct GNUNET_HELLO_Message *hello; | 1130 | struct GNUNET_HELLO_Message *hello; |
1094 | struct TransportClient *cpos; | 1131 | struct TransportClient *cpos; |
1095 | struct NeighbourList *npos; | 1132 | struct NeighborList *npos; |
1096 | struct GeneratorContext gc; | 1133 | struct GeneratorContext gc; |
1097 | 1134 | ||
1098 | #if DEBUG_TRANSPORT | 1135 | #if DEBUG_TRANSPORT |
@@ -1116,12 +1153,12 @@ refresh_hello () | |||
1116 | our_hello = hello; | 1153 | our_hello = hello; |
1117 | our_hello_version++; | 1154 | our_hello_version++; |
1118 | GNUNET_PEERINFO_add_peer (cfg, sched, &my_identity, our_hello); | 1155 | GNUNET_PEERINFO_add_peer (cfg, sched, &my_identity, our_hello); |
1119 | npos = neighbours; | 1156 | npos = neighbors; |
1120 | while (npos != NULL) | 1157 | while (npos != NULL) |
1121 | { | 1158 | { |
1122 | #if DEBUG_TRANSPORT | 1159 | #if DEBUG_TRANSPORT |
1123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1124 | "Transmitting updated `%s' to neighbour `%4s'\n", | 1161 | "Transmitting updated `%s' to neighbor `%4s'\n", |
1125 | "HELLO", GNUNET_i2s (&npos->id)); | 1162 | "HELLO", GNUNET_i2s (&npos->id)); |
1126 | #endif | 1163 | #endif |
1127 | transmit_to_peer (NULL, 0, | 1164 | transmit_to_peer (NULL, 0, |
@@ -1365,7 +1402,7 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1365 | struct GNUNET_TIME_Absolute first; | 1402 | struct GNUNET_TIME_Absolute first; |
1366 | struct GNUNET_HELLO_Message *hello; | 1403 | struct GNUNET_HELLO_Message *hello; |
1367 | struct GNUNET_PeerIdentity pid; | 1404 | struct GNUNET_PeerIdentity pid; |
1368 | struct NeighbourList *n; | 1405 | struct NeighborList *n; |
1369 | 1406 | ||
1370 | #if DEBUG_TRANSPORT | 1407 | #if DEBUG_TRANSPORT |
1371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
@@ -1395,7 +1432,7 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1395 | "HELLO", GNUNET_i2s (&pid)); | 1432 | "HELLO", GNUNET_i2s (&pid)); |
1396 | #endif | 1433 | #endif |
1397 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); | 1434 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); |
1398 | n = find_neighbour (&pid); | 1435 | n = find_neighbor (&pid, NULL, 0); |
1399 | if (NULL != n) | 1436 | if (NULL != n) |
1400 | try_transmission_to_peer (n); | 1437 | try_transmission_to_peer (n); |
1401 | GNUNET_free (hello); | 1438 | GNUNET_free (hello); |
@@ -1452,10 +1489,10 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1452 | * by the other peer in human-readable format) | 1489 | * by the other peer in human-readable format) |
1453 | */ | 1490 | */ |
1454 | static void | 1491 | static void |
1455 | plugin_env_notify_validation (void *cls, | 1492 | handle_pong (void *cls, const struct GNUNET_MessageHeader *message, |
1456 | const char *name, | 1493 | const struct GNUNET_PeerIdentity *peer, |
1457 | const struct GNUNET_PeerIdentity *peer, | 1494 | const char *sender_address, |
1458 | uint32_t challenge, const char *sender_addr) | 1495 | size_t sender_address_len) |
1459 | { | 1496 | { |
1460 | unsigned int not_done; | 1497 | unsigned int not_done; |
1461 | int matched; | 1498 | int matched; |
@@ -1463,6 +1500,7 @@ plugin_env_notify_validation (void *cls, | |||
1463 | struct ValidationAddress *va; | 1500 | struct ValidationAddress *va; |
1464 | struct GNUNET_PeerIdentity id; | 1501 | struct GNUNET_PeerIdentity id; |
1465 | 1502 | ||
1503 | int challenge = 1; /* FIXME: Pull this number out of the PONG message */ | ||
1466 | pos = pending_validations; | 1504 | pos = pending_validations; |
1467 | while (pos != NULL) | 1505 | while (pos != NULL) |
1468 | { | 1506 | { |
@@ -1499,8 +1537,8 @@ plugin_env_notify_validation (void *cls, | |||
1499 | #endif | 1537 | #endif |
1500 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 1538 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
1501 | _ | 1539 | _ |
1502 | ("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), | 1540 | ("Another peer saw us using the address `%s' via `FIXME'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), |
1503 | sender_addr, name); | 1541 | sender_address); |
1504 | va->ok = GNUNET_YES; | 1542 | va->ok = GNUNET_YES; |
1505 | va->expiration = | 1543 | va->expiration = |
1506 | GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); | 1544 | GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); |
@@ -1611,6 +1649,32 @@ run_validation (void *cls, | |||
1611 | return GNUNET_OK; | 1649 | return GNUNET_OK; |
1612 | } | 1650 | } |
1613 | 1651 | ||
1652 | /* | ||
1653 | * @param cls handle to the plugin (for sending) | ||
1654 | * @param target the peer identity of the peer we are sending to | ||
1655 | * @param challenge the challenge number | ||
1656 | * @param timeout how long to await validation? | ||
1657 | * @param addr the address to validate | ||
1658 | * @param addrlen the length of the address | ||
1659 | * | ||
1660 | * Perform address validation, which means sending a PING PONG to | ||
1661 | * the address via the transport plugin. If not validated, then | ||
1662 | * do not count this as a good peer/address... | ||
1663 | * | ||
1664 | */ | ||
1665 | static void | ||
1666 | validate_address (void *cls, struct ValidationAddress *va, | ||
1667 | const struct GNUNET_PeerIdentity *target, | ||
1668 | struct GNUNET_TIME_Relative timeout, | ||
1669 | const void *addr, size_t addrlen) | ||
1670 | { | ||
1671 | /* struct Plugin *plugin = cls; | ||
1672 | int challenge = va->challenge; */ | ||
1673 | |||
1674 | |||
1675 | return; | ||
1676 | } | ||
1677 | |||
1614 | 1678 | ||
1615 | /** | 1679 | /** |
1616 | * Check if addresses in validated hello "h" overlap with | 1680 | * Check if addresses in validated hello "h" overlap with |
@@ -1677,13 +1741,11 @@ check_hello_validated (void *cls, | |||
1677 | #endif | 1741 | #endif |
1678 | tp = find_transport (va->transport_name); | 1742 | tp = find_transport (va->transport_name); |
1679 | GNUNET_assert (tp != NULL); | 1743 | GNUNET_assert (tp != NULL); |
1680 | if (GNUNET_OK != | 1744 | /* This validation should happen inside the transport, not from the plugin! */ |
1681 | tp->api->validate (tp->api->cls, | 1745 | validate_address (tp->api->cls, va, &apeer, |
1682 | &apeer, | 1746 | HELLO_VERIFICATION_TIMEOUT, |
1683 | va->challenge, | 1747 | &va[1], va->addr_len); |
1684 | HELLO_VERIFICATION_TIMEOUT, | 1748 | /* va->ok = GNUNET_SYSERR; will be set by validate_address! */ |
1685 | &va[1], va->addr_len)) | ||
1686 | va->ok = GNUNET_SYSERR; | ||
1687 | va = va->next; | 1749 | va = va->next; |
1688 | } | 1750 | } |
1689 | GNUNET_SCHEDULER_add_delayed (sched, | 1751 | GNUNET_SCHEDULER_add_delayed (sched, |
@@ -1775,24 +1837,24 @@ process_hello (struct TransportPlugin *plugin, | |||
1775 | 1837 | ||
1776 | 1838 | ||
1777 | /** | 1839 | /** |
1778 | * The peer specified by the given neighbour has timed-out or a plugin | 1840 | * The peer specified by the given neighbor has timed-out or a plugin |
1779 | * has disconnected. We may either need to do nothing (other plugins | 1841 | * has disconnected. We may either need to do nothing (other plugins |
1780 | * still up), or trigger a full disconnect and clean up. This | 1842 | * still up), or trigger a full disconnect and clean up. This |
1781 | * function updates our state and do the necessary notifications. | 1843 | * function updates our state and do the necessary notifications. |
1782 | * Also notifies our clients that the neighbour is now officially | 1844 | * Also notifies our clients that the neighbor is now officially |
1783 | * gone. | 1845 | * gone. |
1784 | * | 1846 | * |
1785 | * @param n the neighbour list entry for the peer | 1847 | * @param n the neighbor list entry for the peer |
1786 | * @param check should we just check if all plugins | 1848 | * @param check should we just check if all plugins |
1787 | * disconnected or must we ask all plugins to | 1849 | * disconnected or must we ask all plugins to |
1788 | * disconnect? | 1850 | * disconnect? |
1789 | */ | 1851 | */ |
1790 | static void | 1852 | static void |
1791 | disconnect_neighbour (struct NeighbourList *n, int check) | 1853 | disconnect_neighbor (struct NeighborList *n, int check) |
1792 | { | 1854 | { |
1793 | struct ReadyList *rpos; | 1855 | struct ReadyList *rpos; |
1794 | struct NeighbourList *npos; | 1856 | struct NeighborList *npos; |
1795 | struct NeighbourList *nprev; | 1857 | struct NeighborList *nprev; |
1796 | struct MessageQueue *mq; | 1858 | struct MessageQueue *mq; |
1797 | 1859 | ||
1798 | if (GNUNET_YES == check) | 1860 | if (GNUNET_YES == check) |
@@ -1810,9 +1872,9 @@ disconnect_neighbour (struct NeighbourList *n, int check) | |||
1810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1811 | "Disconnecting from `%4s'\n", GNUNET_i2s (&n->id)); | 1873 | "Disconnecting from `%4s'\n", GNUNET_i2s (&n->id)); |
1812 | #endif | 1874 | #endif |
1813 | /* remove n from neighbours list */ | 1875 | /* remove n from neighbors list */ |
1814 | nprev = NULL; | 1876 | nprev = NULL; |
1815 | npos = neighbours; | 1877 | npos = neighbors; |
1816 | while ((npos != NULL) && (npos != n)) | 1878 | while ((npos != NULL) && (npos != n)) |
1817 | { | 1879 | { |
1818 | nprev = npos; | 1880 | nprev = npos; |
@@ -1820,7 +1882,7 @@ disconnect_neighbour (struct NeighbourList *n, int check) | |||
1820 | } | 1882 | } |
1821 | GNUNET_assert (npos != NULL); | 1883 | GNUNET_assert (npos != NULL); |
1822 | if (nprev == NULL) | 1884 | if (nprev == NULL) |
1823 | neighbours = n->next; | 1885 | neighbors = n->next; |
1824 | else | 1886 | else |
1825 | nprev->next = n->next; | 1887 | nprev->next = n->next; |
1826 | 1888 | ||
@@ -1831,7 +1893,7 @@ disconnect_neighbour (struct NeighbourList *n, int check) | |||
1831 | while (NULL != (rpos = n->plugins)) | 1893 | while (NULL != (rpos = n->plugins)) |
1832 | { | 1894 | { |
1833 | n->plugins = rpos->next; | 1895 | n->plugins = rpos->next; |
1834 | GNUNET_assert (rpos->neighbour == n); | 1896 | GNUNET_assert (rpos->neighbor == n); |
1835 | if (GNUNET_YES == rpos->connected) | 1897 | if (GNUNET_YES == rpos->connected) |
1836 | rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id); | 1898 | rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id); |
1837 | GNUNET_free (rpos); | 1899 | GNUNET_free (rpos); |
@@ -1841,7 +1903,7 @@ disconnect_neighbour (struct NeighbourList *n, int check) | |||
1841 | while (NULL != (mq = n->messages)) | 1903 | while (NULL != (mq = n->messages)) |
1842 | { | 1904 | { |
1843 | n->messages = mq->next; | 1905 | n->messages = mq->next; |
1844 | GNUNET_assert (mq->neighbour == n); | 1906 | GNUNET_assert (mq->neighbor == n); |
1845 | GNUNET_free (mq); | 1907 | GNUNET_free (mq); |
1846 | } | 1908 | } |
1847 | if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 1909 | if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1854,17 +1916,17 @@ disconnect_neighbour (struct NeighbourList *n, int check) | |||
1854 | /** | 1916 | /** |
1855 | * Add an entry for each of our transport plugins | 1917 | * Add an entry for each of our transport plugins |
1856 | * (that are able to send) to the list of plugins | 1918 | * (that are able to send) to the list of plugins |
1857 | * for this neighbour. | 1919 | * for this neighbor. |
1858 | * | 1920 | * |
1859 | * @param neighbour to initialize | 1921 | * @param neighbor to initialize |
1860 | */ | 1922 | */ |
1861 | static void | 1923 | static void |
1862 | add_plugins (struct NeighbourList *neighbour) | 1924 | add_plugins (struct NeighborList *neighbor) |
1863 | { | 1925 | { |
1864 | struct TransportPlugin *tp; | 1926 | struct TransportPlugin *tp; |
1865 | struct ReadyList *rl; | 1927 | struct ReadyList *rl; |
1866 | 1928 | ||
1867 | neighbour->retry_plugins_time | 1929 | neighbor->retry_plugins_time |
1868 | = GNUNET_TIME_relative_to_absolute (PLUGIN_RETRY_FREQUENCY); | 1930 | = GNUNET_TIME_relative_to_absolute (PLUGIN_RETRY_FREQUENCY); |
1869 | tp = plugins; | 1931 | tp = plugins; |
1870 | while (tp != NULL) | 1932 | while (tp != NULL) |
@@ -1872,10 +1934,10 @@ add_plugins (struct NeighbourList *neighbour) | |||
1872 | if (tp->api->send != NULL) | 1934 | if (tp->api->send != NULL) |
1873 | { | 1935 | { |
1874 | rl = GNUNET_malloc (sizeof (struct ReadyList)); | 1936 | rl = GNUNET_malloc (sizeof (struct ReadyList)); |
1875 | rl->next = neighbour->plugins; | 1937 | rl->next = neighbor->plugins; |
1876 | neighbour->plugins = rl; | 1938 | neighbor->plugins = rl; |
1877 | rl->plugin = tp; | 1939 | rl->plugin = tp; |
1878 | rl->neighbour = neighbour; | 1940 | rl->neighbor = neighbor; |
1879 | rl->transmit_ready = GNUNET_YES; | 1941 | rl->transmit_ready = GNUNET_YES; |
1880 | } | 1942 | } |
1881 | tp = tp->next; | 1943 | tp = tp->next; |
@@ -1884,42 +1946,42 @@ add_plugins (struct NeighbourList *neighbour) | |||
1884 | 1946 | ||
1885 | 1947 | ||
1886 | static void | 1948 | static void |
1887 | neighbour_timeout_task (void *cls, | 1949 | neighbor_timeout_task (void *cls, |
1888 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1950 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1889 | { | 1951 | { |
1890 | struct NeighbourList *n = cls; | 1952 | struct NeighborList *n = cls; |
1891 | 1953 | ||
1892 | #if DEBUG_TRANSPORT | 1954 | #if DEBUG_TRANSPORT |
1893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1955 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1894 | "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id)); | 1956 | "Neighbor `%4s' has timed out!\n", GNUNET_i2s (&n->id)); |
1895 | #endif | 1957 | #endif |
1896 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1958 | n->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1897 | disconnect_neighbour (n, GNUNET_NO); | 1959 | disconnect_neighbor (n, GNUNET_NO); |
1898 | } | 1960 | } |
1899 | 1961 | ||
1900 | 1962 | ||
1901 | /** | 1963 | /** |
1902 | * Create a fresh entry in our neighbour list for the given peer. | 1964 | * Create a fresh entry in our neighbor list for the given peer. |
1903 | * Will try to transmit our current HELLO to the new neighbour. Also | 1965 | * Will try to transmit our current HELLO to the new neighbor. Also |
1904 | * notifies our clients about the new "connection". | 1966 | * notifies our clients about the new "connection". |
1905 | * | 1967 | * |
1906 | * @param peer the peer for which we create the entry | 1968 | * @param peer the peer for which we create the entry |
1907 | * @return the new neighbour list entry | 1969 | * @return the new neighbor list entry |
1908 | */ | 1970 | */ |
1909 | static struct NeighbourList * | 1971 | static struct NeighborList * |
1910 | setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) | 1972 | setup_new_neighbor (const struct GNUNET_PeerIdentity *peer, const char *addr, size_t sender_address_len) |
1911 | { | 1973 | { |
1912 | struct NeighbourList *n; | 1974 | struct NeighborList *n; |
1913 | 1975 | ||
1914 | #if DEBUG_TRANSPORT | 1976 | #if DEBUG_TRANSPORT |
1915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 1977 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
1916 | "Setting up new neighbour `%4s', sending our HELLO to introduce ourselves\n", | 1978 | "Setting up new neighbor `%4s', sending our HELLO to introduce ourselves\n", |
1917 | GNUNET_i2s (peer)); | 1979 | GNUNET_i2s (peer)); |
1918 | #endif | 1980 | #endif |
1919 | GNUNET_assert (our_hello != NULL); | 1981 | GNUNET_assert (our_hello != NULL); |
1920 | n = GNUNET_malloc (sizeof (struct NeighbourList)); | 1982 | n = GNUNET_malloc (sizeof (struct NeighborList)); |
1921 | n->next = neighbours; | 1983 | n->next = neighbors; |
1922 | neighbours = n; | 1984 | neighbors = n; |
1923 | n->id = *peer; | 1985 | n->id = *peer; |
1924 | n->last_quota_update = GNUNET_TIME_absolute_get (); | 1986 | n->last_quota_update = GNUNET_TIME_absolute_get (); |
1925 | n->peer_timeout = | 1987 | n->peer_timeout = |
@@ -1929,7 +1991,7 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
1929 | add_plugins (n); | 1991 | add_plugins (n); |
1930 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, | 1992 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched, |
1931 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1993 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1932 | &neighbour_timeout_task, n); | 1994 | &neighbor_timeout_task, n); |
1933 | transmit_to_peer (NULL, 0, | 1995 | transmit_to_peer (NULL, 0, |
1934 | (const struct GNUNET_MessageHeader *) our_hello, | 1996 | (const struct GNUNET_MessageHeader *) our_hello, |
1935 | GNUNET_YES, n); | 1997 | GNUNET_YES, n); |
@@ -1937,6 +1999,20 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
1937 | return n; | 1999 | return n; |
1938 | } | 2000 | } |
1939 | 2001 | ||
2002 | /* | ||
2003 | * We have received a PING message from someone. Need to send a PONG message | ||
2004 | * in response to the peer by any means necessary. Of course, with something | ||
2005 | * like TCP where a connection exists, we may want to send it that way. But | ||
2006 | * we may not be able to make that distinction... | ||
2007 | */ | ||
2008 | static int handle_ping(void *cls, const struct GNUNET_MessageHeader *message, | ||
2009 | const struct GNUNET_PeerIdentity *peer, | ||
2010 | const char *sender_address, | ||
2011 | size_t sender_address_len) | ||
2012 | { | ||
2013 | |||
2014 | return GNUNET_OK; | ||
2015 | } | ||
1940 | 2016 | ||
1941 | /** | 2017 | /** |
1942 | * Function called by the plugin for each received message. | 2018 | * Function called by the plugin for each received message. |
@@ -1945,19 +2021,22 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
1945 | * and generally forward to our receive callback. | 2021 | * and generally forward to our receive callback. |
1946 | * | 2022 | * |
1947 | * @param cls the "struct TransportPlugin *" we gave to the plugin | 2023 | * @param cls the "struct TransportPlugin *" we gave to the plugin |
1948 | * @param latency estimated latency for communicating with the | ||
1949 | * given peer | ||
1950 | * @param peer (claimed) identity of the other peer | ||
1951 | * @param message the message, NULL if peer was disconnected | 2024 | * @param message the message, NULL if peer was disconnected |
2025 | * @param distance the transport cost to this peer (not latency!) | ||
2026 | * @param sender_address the address that the sender reported | ||
2027 | * (opaque to transport service) | ||
2028 | * @param sender_address_len the length of the sender address | ||
2029 | * @param peer (claimed) identity of the other peer | ||
1952 | * @return the new service_context that the plugin should use | 2030 | * @return the new service_context that the plugin should use |
1953 | * for future receive calls for messages from this | 2031 | * for future receive calls for messages from this |
1954 | * particular peer | 2032 | * particular peer |
2033 | * | ||
1955 | */ | 2034 | */ |
1956 | static void | 2035 | static void |
1957 | plugin_env_receive (void *cls, | 2036 | plugin_env_receive (void *cls, const struct GNUNET_MessageHeader *message, |
1958 | struct GNUNET_TIME_Relative latency, | ||
1959 | const struct GNUNET_PeerIdentity *peer, | 2037 | const struct GNUNET_PeerIdentity *peer, |
1960 | const struct GNUNET_MessageHeader *message) | 2038 | unsigned int distance, const char *sender_address, |
2039 | size_t sender_address_len) | ||
1961 | { | 2040 | { |
1962 | const struct GNUNET_MessageHeader ack = { | 2041 | const struct GNUNET_MessageHeader ack = { |
1963 | htons (sizeof (struct GNUNET_MessageHeader)), | 2042 | htons (sizeof (struct GNUNET_MessageHeader)), |
@@ -1968,14 +2047,14 @@ plugin_env_receive (void *cls, | |||
1968 | struct TransportClient *cpos; | 2047 | struct TransportClient *cpos; |
1969 | struct InboundMessage *im; | 2048 | struct InboundMessage *im; |
1970 | uint16_t msize; | 2049 | uint16_t msize; |
1971 | struct NeighbourList *n; | 2050 | struct NeighborList *n; |
1972 | 2051 | ||
1973 | n = find_neighbour (peer); | 2052 | n = find_neighbor (peer, sender_address, sender_address_len); |
1974 | if (n == NULL) | 2053 | if (n == NULL) |
1975 | { | 2054 | { |
1976 | if (message == NULL) | 2055 | if (message == NULL) |
1977 | return; /* disconnect of peer already marked down */ | 2056 | return; /* disconnect of peer already marked down */ |
1978 | n = setup_new_neighbour (peer); | 2057 | n = setup_new_neighbor (peer, sender_address, sender_address_len); |
1979 | } | 2058 | } |
1980 | service_context = n->plugins; | 2059 | service_context = n->plugins; |
1981 | while ((service_context != NULL) && (plugin != service_context->plugin)) | 2060 | while ((service_context != NULL) && (plugin != service_context->plugin)) |
@@ -1991,7 +2070,7 @@ plugin_env_receive (void *cls, | |||
1991 | /* TODO: call stats */ | 2070 | /* TODO: call stats */ |
1992 | if (service_context != NULL) | 2071 | if (service_context != NULL) |
1993 | service_context->connected = GNUNET_NO; | 2072 | service_context->connected = GNUNET_NO; |
1994 | disconnect_neighbour (n, GNUNET_YES); | 2073 | disconnect_neighbor (n, GNUNET_YES); |
1995 | return; | 2074 | return; |
1996 | } | 2075 | } |
1997 | #if DEBUG_TRANSPORT | 2076 | #if DEBUG_TRANSPORT |
@@ -2011,7 +2090,7 @@ plugin_env_receive (void *cls, | |||
2011 | = | 2090 | = |
2012 | GNUNET_TIME_relative_to_absolute | 2091 | GNUNET_TIME_relative_to_absolute |
2013 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2092 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
2014 | service_context->latency = latency; | 2093 | /* service_context->latency = latency; */ /* This value should be set by us! */ |
2015 | } | 2094 | } |
2016 | /* update traffic received amount ... */ | 2095 | /* update traffic received amount ... */ |
2017 | msize = ntohs (message->size); | 2096 | msize = ntohs (message->size); |
@@ -2023,7 +2102,7 @@ plugin_env_receive (void *cls, | |||
2023 | n->timeout_task = | 2102 | n->timeout_task = |
2024 | GNUNET_SCHEDULER_add_delayed (sched, | 2103 | GNUNET_SCHEDULER_add_delayed (sched, |
2025 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 2104 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
2026 | &neighbour_timeout_task, n); | 2105 | &neighbor_timeout_task, n); |
2027 | update_quota (n); | 2106 | update_quota (n); |
2028 | if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) | 2107 | if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) |
2029 | { | 2108 | { |
@@ -2034,7 +2113,7 @@ plugin_env_receive (void *cls, | |||
2034 | ("Dropping incoming message due to repeated bandwidth quota violations.\n")); | 2113 | ("Dropping incoming message due to repeated bandwidth quota violations.\n")); |
2035 | /* TODO: call stats */ | 2114 | /* TODO: call stats */ |
2036 | GNUNET_assert ((service_context == NULL) || | 2115 | GNUNET_assert ((service_context == NULL) || |
2037 | (NULL != service_context->neighbour)); | 2116 | (NULL != service_context->neighbor)); |
2038 | return; | 2117 | return; |
2039 | } | 2118 | } |
2040 | switch (ntohs (message->type)) | 2119 | switch (ntohs (message->type)) |
@@ -2053,6 +2132,11 @@ plugin_env_receive (void *cls, | |||
2053 | #endif | 2132 | #endif |
2054 | transmit_to_peer (NULL, 0, &ack, GNUNET_YES, n); | 2133 | transmit_to_peer (NULL, 0, &ack, GNUNET_YES, n); |
2055 | break; | 2134 | break; |
2135 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: | ||
2136 | handle_ping(plugin, message, peer, sender_address, sender_address_len); | ||
2137 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | ||
2138 | handle_pong(plugin, message, peer, sender_address, sender_address_len); | ||
2139 | //plugin_env_notify_validation(); | ||
2056 | case GNUNET_MESSAGE_TYPE_TRANSPORT_ACK: | 2140 | case GNUNET_MESSAGE_TYPE_TRANSPORT_ACK: |
2057 | n->saw_ack = GNUNET_YES; | 2141 | n->saw_ack = GNUNET_YES; |
2058 | /* intentional fall-through! */ | 2142 | /* intentional fall-through! */ |
@@ -2066,7 +2150,7 @@ plugin_env_receive (void *cls, | |||
2066 | im = GNUNET_malloc (sizeof (struct InboundMessage) + msize); | 2150 | im = GNUNET_malloc (sizeof (struct InboundMessage) + msize); |
2067 | im->header.size = htons (sizeof (struct InboundMessage) + msize); | 2151 | im->header.size = htons (sizeof (struct InboundMessage) + msize); |
2068 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); | 2152 | im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); |
2069 | im->latency = GNUNET_TIME_relative_hton (latency); | 2153 | im->latency = n->latency; |
2070 | im->peer = *peer; | 2154 | im->peer = *peer; |
2071 | memcpy (&im[1], message, msize); | 2155 | memcpy (&im[1], message, msize); |
2072 | 2156 | ||
@@ -2079,7 +2163,7 @@ plugin_env_receive (void *cls, | |||
2079 | GNUNET_free (im); | 2163 | GNUNET_free (im); |
2080 | } | 2164 | } |
2081 | GNUNET_assert ((service_context == NULL) || | 2165 | GNUNET_assert ((service_context == NULL) || |
2082 | (NULL != service_context->neighbour)); | 2166 | (NULL != service_context->neighbor)); |
2083 | } | 2167 | } |
2084 | 2168 | ||
2085 | 2169 | ||
@@ -2098,7 +2182,7 @@ handle_start (void *cls, | |||
2098 | { | 2182 | { |
2099 | struct TransportClient *c; | 2183 | struct TransportClient *c; |
2100 | struct ConnectInfoMessage cim; | 2184 | struct ConnectInfoMessage cim; |
2101 | struct NeighbourList *n; | 2185 | struct NeighborList *n; |
2102 | struct InboundMessage *im; | 2186 | struct InboundMessage *im; |
2103 | struct GNUNET_MessageHeader *ack; | 2187 | struct GNUNET_MessageHeader *ack; |
2104 | 2188 | ||
@@ -2146,7 +2230,7 @@ handle_start (void *cls, | |||
2146 | ack = (struct GNUNET_MessageHeader *) &im[1]; | 2230 | ack = (struct GNUNET_MessageHeader *) &im[1]; |
2147 | ack->size = htons (sizeof (struct GNUNET_MessageHeader)); | 2231 | ack->size = htons (sizeof (struct GNUNET_MessageHeader)); |
2148 | ack->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ACK); | 2232 | ack->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ACK); |
2149 | for (n = neighbours; n != NULL; n = n->next) | 2233 | for (n = neighbors; n != NULL; n = n->next) |
2150 | { | 2234 | { |
2151 | cim.id = n->id; | 2235 | cim.id = n->id; |
2152 | transmit_to_client (c, &cim.header, GNUNET_NO); | 2236 | transmit_to_client (c, &cim.header, GNUNET_NO); |
@@ -2198,7 +2282,7 @@ handle_send (void *cls, | |||
2198 | const struct GNUNET_MessageHeader *message) | 2282 | const struct GNUNET_MessageHeader *message) |
2199 | { | 2283 | { |
2200 | struct TransportClient *tc; | 2284 | struct TransportClient *tc; |
2201 | struct NeighbourList *n; | 2285 | struct NeighborList *n; |
2202 | const struct OutboundMessage *obm; | 2286 | const struct OutboundMessage *obm; |
2203 | const struct GNUNET_MessageHeader *obmm; | 2287 | const struct GNUNET_MessageHeader *obmm; |
2204 | uint16_t size; | 2288 | uint16_t size; |
@@ -2226,9 +2310,9 @@ handle_send (void *cls, | |||
2226 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2310 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2227 | return; | 2311 | return; |
2228 | } | 2312 | } |
2229 | n = find_neighbour (&obm->peer); | 2313 | n = find_neighbor (&obm->peer, NULL, 0); |
2230 | if (n == NULL) | 2314 | if (n == NULL) |
2231 | n = setup_new_neighbour (&obm->peer); | 2315 | n = setup_new_neighbor (&obm->peer, NULL, 0); |
2232 | tc = clients; | 2316 | tc = clients; |
2233 | while ((tc != NULL) && (tc->client != client)) | 2317 | while ((tc != NULL) && (tc->client != client)) |
2234 | tc = tc->next; | 2318 | tc = tc->next; |
@@ -2258,7 +2342,7 @@ handle_set_quota (void *cls, | |||
2258 | { | 2342 | { |
2259 | const struct QuotaSetMessage *qsm = | 2343 | const struct QuotaSetMessage *qsm = |
2260 | (const struct QuotaSetMessage *) message; | 2344 | (const struct QuotaSetMessage *) message; |
2261 | struct NeighbourList *n; | 2345 | struct NeighborList *n; |
2262 | struct TransportPlugin *p; | 2346 | struct TransportPlugin *p; |
2263 | struct ReadyList *rl; | 2347 | struct ReadyList *rl; |
2264 | 2348 | ||
@@ -2267,7 +2351,7 @@ handle_set_quota (void *cls, | |||
2267 | "Received `%s' request from client for peer `%4s'\n", | 2351 | "Received `%s' request from client for peer `%4s'\n", |
2268 | "SET_QUOTA", GNUNET_i2s (&qsm->peer)); | 2352 | "SET_QUOTA", GNUNET_i2s (&qsm->peer)); |
2269 | #endif | 2353 | #endif |
2270 | n = find_neighbour (&qsm->peer); | 2354 | n = find_neighbor (&qsm->peer, NULL, 0); |
2271 | if (n == NULL) | 2355 | if (n == NULL) |
2272 | { | 2356 | { |
2273 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2357 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -2309,8 +2393,14 @@ handle_try_connect (void *cls, | |||
2309 | "Received `%s' request from client %p asking to connect to `%4s'\n", | 2393 | "Received `%s' request from client %p asking to connect to `%4s'\n", |
2310 | "TRY_CONNECT", client, GNUNET_i2s (&tcm->peer)); | 2394 | "TRY_CONNECT", client, GNUNET_i2s (&tcm->peer)); |
2311 | #endif | 2395 | #endif |
2312 | if (NULL == find_neighbour (&tcm->peer)) | 2396 | if (NULL == find_neighbor (&tcm->peer, NULL, 0)) |
2313 | setup_new_neighbour (&tcm->peer); | 2397 | setup_new_neighbor (&tcm->peer, NULL, 0); /* Can we set up a truly _new_ neighbor without |
2398 | knowing its address? Should we ask the plugin | ||
2399 | for more information about this peer? I don't | ||
2400 | think we can... Or set up new peer should only | ||
2401 | happen when transport notifies us of an address, | ||
2402 | and this setup should check for an address in | ||
2403 | the existing list only */ | ||
2314 | #if DEBUG_TRANSPORT | 2404 | #if DEBUG_TRANSPORT |
2315 | else | 2405 | else |
2316 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2406 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -2430,13 +2520,10 @@ create_environment (struct TransportPlugin *plug) | |||
2430 | { | 2520 | { |
2431 | plug->env.cfg = cfg; | 2521 | plug->env.cfg = cfg; |
2432 | plug->env.sched = sched; | 2522 | plug->env.sched = sched; |
2433 | plug->env.my_public_key = &my_public_key; | ||
2434 | plug->env.my_private_key = my_private_key; | ||
2435 | plug->env.my_identity = &my_identity; | 2523 | plug->env.my_identity = &my_identity; |
2436 | plug->env.cls = plug; | 2524 | plug->env.cls = plug; |
2437 | plug->env.receive = &plugin_env_receive; | 2525 | plug->env.receive = &plugin_env_receive; |
2438 | plug->env.notify_address = &plugin_env_notify_address; | 2526 | plug->env.notify_address = &plugin_env_notify_address; |
2439 | plug->env.notify_validation = &plugin_env_notify_validation; | ||
2440 | plug->env.default_quota_in = | 2527 | plug->env.default_quota_in = |
2441 | (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); | 2528 | (GNUNET_CONSTANTS_DEFAULT_BPM_IN_OUT + 59999) / (60 * 1000); |
2442 | plug->env.max_connections = max_connect_per_transport; | 2529 | plug->env.max_connections = max_connect_per_transport; |
diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index 25defc431..b04cab990 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h | |||
@@ -56,16 +56,15 @@ | |||
56 | * @param peer (claimed) identity of the other peer | 56 | * @param peer (claimed) identity of the other peer |
57 | * @param message the message, NULL if peer was disconnected | 57 | * @param message the message, NULL if peer was disconnected |
58 | */ | 58 | */ |
59 | typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, | 59 | typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, const struct |
60 | unsigned int distance, | 60 | GNUNET_MessageHeader * |
61 | const char *sender_address, | 61 | message, |
62 | size_t sender_address_len, | ||
63 | const struct | 62 | const struct |
64 | GNUNET_PeerIdentity * | 63 | GNUNET_PeerIdentity * |
65 | peer, | 64 | peer, |
66 | const struct | 65 | unsigned int distance, |
67 | GNUNET_MessageHeader * | 66 | const char *sender_address, |
68 | message); | 67 | size_t sender_address_len); |
69 | 68 | ||
70 | 69 | ||
71 | 70 | ||
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 817077f58..7ce02c757 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -40,7 +40,7 @@ | |||
40 | /** | 40 | /** |
41 | * How long until we give up on transmitting the message? | 41 | * How long until we give up on transmitting the message? |
42 | */ | 42 | */ |
43 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 43 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
44 | 44 | ||
45 | #define MTYPE 12345 | 45 | #define MTYPE 12345 |
46 | 46 | ||
@@ -159,6 +159,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
159 | "-c", cfgname, NULL); | 159 | "-c", cfgname, NULL); |
160 | #endif | 160 | #endif |
161 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 161 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
162 | |||
162 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, | 163 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, |
163 | p, | 164 | p, |
164 | ¬ify_receive, | 165 | ¬ify_receive, |
@@ -230,6 +231,31 @@ exchange_hello (void *cls, | |||
230 | GNUNET_TRANSPORT_get_hello (p2.th, TIMEOUT, &exchange_hello_last, &p2); | 231 | GNUNET_TRANSPORT_get_hello (p2.th, TIMEOUT, &exchange_hello_last, &p2); |
231 | } | 232 | } |
232 | 233 | ||
234 | static void | ||
235 | setTransportOptions(char * filename) | ||
236 | { | ||
237 | struct GNUNET_CONFIGURATION_Handle * tempcfg; | ||
238 | |||
239 | tempcfg = GNUNET_CONFIGURATION_create(); | ||
240 | GNUNET_CONFIGURATION_load (tempcfg, filename); | ||
241 | |||
242 | unsigned long long curr_port; | ||
243 | GNUNET_CONFIGURATION_get_value_number(tempcfg, "transport", "port", &curr_port); | ||
244 | |||
245 | if (is_udp) | ||
246 | { | ||
247 | fprintf(stderr, "setting transport udp plugins\n"); | ||
248 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "plugins", "udp"); | ||
249 | GNUNET_CONFIGURATION_set_value_number(tempcfg, "transport-udp", "PORT", curr_port + 3); | ||
250 | } | ||
251 | else if (is_tcp) | ||
252 | { | ||
253 | GNUNET_CONFIGURATION_set_value_string(tempcfg, "transport", "plugins", "tcp"); | ||
254 | GNUNET_CONFIGURATION_set_value_number(tempcfg, "transport-tcp", "port", curr_port + 3); | ||
255 | } | ||
256 | GNUNET_CONFIGURATION_write(tempcfg, filename); | ||
257 | return; | ||
258 | } | ||
233 | 259 | ||
234 | static void | 260 | static void |
235 | run (void *cls, | 261 | run (void *cls, |
@@ -240,6 +266,10 @@ run (void *cls, | |||
240 | GNUNET_assert (ok == 1); | 266 | GNUNET_assert (ok == 1); |
241 | OKPP; | 267 | OKPP; |
242 | sched = s; | 268 | sched = s; |
269 | |||
270 | setTransportOptions("test_transport_api_peer1.conf"); | ||
271 | setTransportOptions("test_transport_api_peer2.conf"); | ||
272 | |||
243 | setup_peer (&p1, "test_transport_api_peer1.conf"); | 273 | setup_peer (&p1, "test_transport_api_peer1.conf"); |
244 | setup_peer (&p2, "test_transport_api_peer2.conf"); | 274 | setup_peer (&p2, "test_transport_api_peer2.conf"); |
245 | GNUNET_TRANSPORT_get_hello (p1.th, TIMEOUT, &exchange_hello, &p1); | 275 | GNUNET_TRANSPORT_get_hello (p1.th, TIMEOUT, &exchange_hello, &p1); |
@@ -257,10 +287,10 @@ stop_arm (struct PeerContext *p) | |||
257 | GNUNET_CONFIGURATION_destroy (p->cfg); | 287 | GNUNET_CONFIGURATION_destroy (p->cfg); |
258 | } | 288 | } |
259 | 289 | ||
260 | |||
261 | static int | 290 | static int |
262 | check () | 291 | check () |
263 | { | 292 | { |
293 | |||
264 | char *const argv[] = { "test-transport-api", | 294 | char *const argv[] = { "test-transport-api", |
265 | "-c", | 295 | "-c", |
266 | "test_transport_api_data.conf", | 296 | "test_transport_api_data.conf", |
@@ -269,6 +299,9 @@ check () | |||
269 | #endif | 299 | #endif |
270 | NULL | 300 | NULL |
271 | }; | 301 | }; |
302 | |||
303 | setTransportOptions("test_transport_api_data.conf"); | ||
304 | |||
272 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 305 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
273 | GNUNET_GETOPT_OPTION_END | 306 | GNUNET_GETOPT_OPTION_END |
274 | }; | 307 | }; |
@@ -287,13 +320,13 @@ main (int argc, char *argv[]) | |||
287 | { | 320 | { |
288 | int ret; | 321 | int ret; |
289 | 322 | ||
290 | if (strstr(argv[0], "test_transport_api_tcp") == 0) | 323 | if (strstr(argv[0], "tcp") != NULL) |
291 | { | 324 | { |
292 | is_tcp = GNUNET_YES; | 325 | is_tcp = GNUNET_YES; |
293 | } | 326 | } |
294 | else if (strstr(argv[0], "test_transport_api_udp") == 0) | 327 | else if (strstr(argv[0], "udp") != NULL) |
295 | { | 328 | { |
296 | is_udp = GNUNET_NO; | 329 | is_udp = GNUNET_YES; |
297 | } | 330 | } |
298 | 331 | ||
299 | 332 | ||