diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-12 12:47:14 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-12 12:47:14 +0000 |
commit | b0fdd8eba09319b893fab2dd4945d6dab9cd704c (patch) | |
tree | b89a3e325e3a45801a9d7b6ae0951de69fbbcf63 | |
parent | ccdfb051fa386bb44024d53540b0a29ab7bd725e (diff) | |
download | gnunet-b0fdd8eba09319b893fab2dd4945d6dab9cd704c.tar.gz gnunet-b0fdd8eba09319b893fab2dd4945d6dab9cd704c.zip |
switch api
-rw-r--r-- | src/ats/ats_api.c | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht.c | 1 | ||||
-rw-r--r-- | src/include/gnunet_ats_service.h | 2 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 161 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.h | 21 |
5 files changed, 144 insertions, 42 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c index 36b215e5b..f748a558b 100644 --- a/src/ats/ats_api.c +++ b/src/ats/ats_api.c | |||
@@ -737,6 +737,7 @@ notify_valid (void *cls, | |||
737 | ar->plugin_name, | 737 | ar->plugin_name, |
738 | ar->plugin_addr, | 738 | ar->plugin_addr, |
739 | ar->plugin_addr_len, | 739 | ar->plugin_addr_len, |
740 | GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), | ||
740 | ar->ats, ar->ats_count); | 741 | ar->ats, ar->ats_count); |
741 | return GNUNET_OK; | 742 | return GNUNET_OK; |
742 | } | 743 | } |
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 626ca79f4..83cb84c9c 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c | |||
@@ -2281,6 +2281,7 @@ route_result_message (struct GNUNET_MessageHeader *msg, | |||
2281 | return 0; | 2281 | return 0; |
2282 | } | 2282 | } |
2283 | 2283 | ||
2284 | |||
2284 | /** | 2285 | /** |
2285 | * Iterator for local get request results, | 2286 | * Iterator for local get request results, |
2286 | * | 2287 | * |
diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 64ed9a9a3..0001bd1e5 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h | |||
@@ -99,6 +99,7 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc); | |||
99 | * @param plugin_name name of the plugin, NULL if we have no suggestion | 99 | * @param plugin_name name of the plugin, NULL if we have no suggestion |
100 | * @param plugin_addr suggested address, NULL if we have no suggestion | 100 | * @param plugin_addr suggested address, NULL if we have no suggestion |
101 | * @param plugin_addr_len number of bytes in plugin_addr | 101 | * @param plugin_addr_len number of bytes in plugin_addr |
102 | * @param bandwidth assigned outbound bandwidth for the connection | ||
102 | * @param ats performance data for the address (as far as known) | 103 | * @param ats performance data for the address (as far as known) |
103 | * @param ats_count number of performance records in 'ats' | 104 | * @param ats_count number of performance records in 'ats' |
104 | */ | 105 | */ |
@@ -108,6 +109,7 @@ typedef void (*GNUNET_ATS_AddressSuggestionCallback)(void *cls, | |||
108 | const char *plugin_name, | 109 | const char *plugin_name, |
109 | const void *plugin_addr, | 110 | const void *plugin_addr, |
110 | size_t plugin_addr_len, | 111 | size_t plugin_addr_len, |
112 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth, | ||
111 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 113 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
112 | uint32_t ats_count); | 114 | uint32_t ats_count); |
113 | 115 | ||
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 2d23ebfa1..8290ccc7e 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -137,6 +137,26 @@ struct NeighbourMapEntry | |||
137 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 137 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * Active session for communicating with the peer. | ||
141 | */ | ||
142 | struct Session *session; | ||
143 | |||
144 | /** | ||
145 | * Name of the plugin we currently use. | ||
146 | */ | ||
147 | char *plugin_name; | ||
148 | |||
149 | /** | ||
150 | * Address used for communicating with the peer, NULL for inbound connections. | ||
151 | */ | ||
152 | void *addr; | ||
153 | |||
154 | /** | ||
155 | * Number of bytes in 'addr'. | ||
156 | */ | ||
157 | size_t addrlen; | ||
158 | |||
159 | /** | ||
140 | * Public key for this peer. Valid only if the respective flag is set below. | 160 | * Public key for this peer. Valid only if the respective flag is set below. |
141 | */ | 161 | */ |
142 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | 162 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; |
@@ -347,6 +367,18 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
347 | GNUNET_array_grow (n->ats, | 367 | GNUNET_array_grow (n->ats, |
348 | n->ats_count, | 368 | n->ats_count, |
349 | 0); | 369 | 0); |
370 | if (NULL != n->plugin_name) | ||
371 | { | ||
372 | GNUNET_free (n->plugin_name); | ||
373 | n->plugin_name = NULL; | ||
374 | } | ||
375 | if (NULL != n->addr) | ||
376 | { | ||
377 | GNUNET_free (n->addr); | ||
378 | n->addr = NULL; | ||
379 | n->addrlen = 0; | ||
380 | } | ||
381 | n->session = NULL; | ||
350 | GNUNET_free (n); | 382 | GNUNET_free (n); |
351 | } | 383 | } |
352 | 384 | ||
@@ -394,6 +426,50 @@ GST_neighbours_stop () | |||
394 | 426 | ||
395 | 427 | ||
396 | /** | 428 | /** |
429 | * For an existing neighbour record, set the active connection to | ||
430 | * the given address. | ||
431 | * | ||
432 | * @param plugin_name name of transport that delivered the PONG | ||
433 | * @param address address of the other peer, NULL if other peer | ||
434 | * connected to us | ||
435 | * @param address_len number of bytes in address | ||
436 | * @param ats performance data | ||
437 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
438 | */ | ||
439 | void | ||
440 | GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | ||
441 | const char *plugin_name, | ||
442 | const void *address, | ||
443 | size_t address_len, | ||
444 | struct Session *session, | ||
445 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
446 | uint32_t ats_count) | ||
447 | { | ||
448 | struct NeighbourMapEntry *n; | ||
449 | |||
450 | n = lookup_neighbour (peer); | ||
451 | if (NULL == n) | ||
452 | { | ||
453 | GNUNET_break (0); | ||
454 | return; | ||
455 | } | ||
456 | GNUNET_free_non_null (n->addr); | ||
457 | n->addr = GNUNET_malloc (address_len); | ||
458 | memcpy (n->addr, address, address_len); | ||
459 | n->addrlen = address_len; | ||
460 | n->session = session; | ||
461 | GNUNET_array_grow (n->ats, | ||
462 | n->ats_count, | ||
463 | ats_count); | ||
464 | memcpy (n->ats, | ||
465 | ats, | ||
466 | ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | ||
467 | GNUNET_free_non_null (n->plugin_name); | ||
468 | n->plugin_name = GNUNET_strdup (plugin_name); | ||
469 | } | ||
470 | |||
471 | |||
472 | /** | ||
397 | * Try to connect to the target peer using the given address | 473 | * Try to connect to the target peer using the given address |
398 | * (if is valid). | 474 | * (if is valid). |
399 | * | 475 | * |
@@ -403,6 +479,7 @@ GST_neighbours_stop () | |||
403 | * @param plugin_name name of the plugin | 479 | * @param plugin_name name of the plugin |
404 | * @param plugin_address binary address | 480 | * @param plugin_address binary address |
405 | * @param plugin_address_len length of address | 481 | * @param plugin_address_len length of address |
482 | * @param bandwidth available bandwidth | ||
406 | * @param ats performance data for the address (as far as known) | 483 | * @param ats performance data for the address (as far as known) |
407 | * @param ats_count number of performance records in 'ats' | 484 | * @param ats_count number of performance records in 'ats' |
408 | */ | 485 | */ |
@@ -413,6 +490,7 @@ try_connect_using_address (void *cls, | |||
413 | const char *plugin_name, | 490 | const char *plugin_name, |
414 | const void *plugin_address, | 491 | const void *plugin_address, |
415 | size_t plugin_address_len, | 492 | size_t plugin_address_len, |
493 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth, | ||
416 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 494 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
417 | uint32_t ats_count) | 495 | uint32_t ats_count) |
418 | { | 496 | { |
@@ -424,8 +502,19 @@ try_connect_using_address (void *cls, | |||
424 | n->public_key = *public_key; | 502 | n->public_key = *public_key; |
425 | n->public_key_valid = GNUNET_YES; | 503 | n->public_key_valid = GNUNET_YES; |
426 | } | 504 | } |
427 | /* FIXME: do connect! */ | 505 | GST_neighbours_switch_to_address (target, |
428 | 506 | plugin_name, | |
507 | plugin_address, | ||
508 | plugin_address_len, | ||
509 | NULL, | ||
510 | ats, ats_count); | ||
511 | if (GNUNET_YES == n->is_connected) | ||
512 | return; | ||
513 | n->is_connected = GNUNET_YES; | ||
514 | connect_notify_cb (callback_cls, | ||
515 | target, | ||
516 | n->ats, | ||
517 | n->ats_count); | ||
429 | } | 518 | } |
430 | 519 | ||
431 | 520 | ||
@@ -467,7 +556,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
467 | sizeof (struct GNUNET_PeerIdentity))); | 556 | sizeof (struct GNUNET_PeerIdentity))); |
468 | n = lookup_neighbour (target); | 557 | n = lookup_neighbour (target); |
469 | if ( (NULL != n) || | 558 | if ( (NULL != n) || |
470 | (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value > 0) ) | 559 | (GNUNET_YES == n->is_connected) ) |
471 | return; /* already connected */ | 560 | return; /* already connected */ |
472 | if (n == NULL) | 561 | if (n == NULL) |
473 | { | 562 | { |
@@ -693,6 +782,7 @@ neighbour_idle_timeout_task (void *cls, | |||
693 | * @param sender_address address of the other peer, NULL if other peer | 782 | * @param sender_address address of the other peer, NULL if other peer |
694 | * connected to us | 783 | * connected to us |
695 | * @param sender_address_len number of bytes in sender_address | 784 | * @param sender_address_len number of bytes in sender_address |
785 | * @param bandwidth bandwidth for the connection | ||
696 | * @param ats performance data | 786 | * @param ats performance data |
697 | * @param ats_count number of entries in ats (excluding 0-termination) | 787 | * @param ats_count number of entries in ats (excluding 0-termination) |
698 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | 788 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not |
@@ -717,17 +807,9 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | |||
717 | return GNUNET_SYSERR; | 807 | return GNUNET_SYSERR; |
718 | } | 808 | } |
719 | n = lookup_neighbour (sender); | 809 | n = lookup_neighbour (sender); |
720 | if ( (NULL != n) || | 810 | if ( (NULL != n) && |
721 | (n->is_connected == GNUNET_YES) ) | 811 | (n->is_connected == GNUNET_YES) ) |
722 | { | 812 | return GNUNET_OK; /* ats will consider switching and tell us */ |
723 | /* already connected */ | ||
724 | if (session != NULL) | ||
725 | { | ||
726 | // FIXME: ATS: switch session!? | ||
727 | // FIXME: merge/update ats? | ||
728 | } | ||
729 | return GNUNET_OK; | ||
730 | } | ||
731 | if (n == NULL) | 813 | if (n == NULL) |
732 | { | 814 | { |
733 | n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); | 815 | n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); |
@@ -742,38 +824,33 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | |||
742 | &n->id.hashPubKey, | 824 | &n->id.hashPubKey, |
743 | n, | 825 | n, |
744 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 826 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
745 | if (NULL == ats) | ||
746 | { | ||
747 | GNUNET_array_grow (n->ats, | ||
748 | n->ats_count, | ||
749 | 1); | ||
750 | } | ||
751 | else | ||
752 | { | ||
753 | GNUNET_array_grow (n->ats, | ||
754 | n->ats_count, | ||
755 | ats_count); | ||
756 | memcpy (n->ats, | ||
757 | ats, | ||
758 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * ats_count); | ||
759 | } | ||
760 | } | 827 | } |
761 | if (session != NULL) | 828 | GST_neighbours_switch_to_address (sender, |
829 | plugin_name, | ||
830 | sender_address, | ||
831 | sender_address_len, | ||
832 | session, | ||
833 | ats, ats_count); | ||
834 | if (NULL != session) | ||
762 | { | 835 | { |
763 | // FIXME: ATS: switch session!? | 836 | /* inbound bi-directional connection, just use it */ |
764 | // n->session = session; | 837 | n->is_connected = GNUNET_YES; |
838 | connect_notify_cb (callback_cls, | ||
839 | sender, | ||
840 | n->ats, | ||
841 | n->ats_count); | ||
842 | n->peer_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
843 | if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) | ||
844 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
845 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
846 | &neighbour_idle_timeout_task, | ||
847 | n); | ||
848 | } | ||
849 | else | ||
850 | { | ||
851 | /* try to establish our connection back to the initiator */ | ||
852 | GST_neighbours_try_connect (sender); | ||
765 | } | 853 | } |
766 | n->peer_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
767 | if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) | ||
768 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
769 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
770 | &neighbour_idle_timeout_task, | ||
771 | n); | ||
772 | n->is_connected = GNUNET_YES; | ||
773 | connect_notify_cb (callback_cls, | ||
774 | sender, | ||
775 | n->ats, | ||
776 | n->ats_count); | ||
777 | return GNUNET_OK; | 854 | return GNUNET_OK; |
778 | } | 855 | } |
779 | 856 | ||
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 76e5e7336..8c038ef20 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h | |||
@@ -173,6 +173,27 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender, | |||
173 | 173 | ||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * For an existing neighbour record, set the active connection to | ||
177 | * the given address. | ||
178 | * | ||
179 | * @param plugin_name name of transport that delivered the PONG | ||
180 | * @param address address of the other peer, NULL if other peer | ||
181 | * connected to us | ||
182 | * @param address_len number of bytes in address | ||
183 | * @param ats performance data | ||
184 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
185 | */ | ||
186 | void | ||
187 | GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | ||
188 | const char *plugin_name, | ||
189 | const void *address, | ||
190 | size_t address_len, | ||
191 | struct Session *session, | ||
192 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
193 | uint32_t ats_count); | ||
194 | |||
195 | |||
196 | /** | ||
176 | * We have received a DISCONNECT. Set the peer to disconnected. | 197 | * We have received a DISCONNECT. Set the peer to disconnected. |
177 | * | 198 | * |
178 | * @param sender peer sending the PONG | 199 | * @param sender peer sending the PONG |