diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-12 10:00:39 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-12 10:00:39 +0000 |
commit | 180f2e637029d045e3c72dc3e13fddb1f9f30141 (patch) | |
tree | 91356b1fe1c93c8ff69f6136d454d5d12e5978a2 /src | |
parent | f76896d09afabb721219d3217037cc7a7f26d570 (diff) | |
download | gnunet-180f2e637029d045e3c72dc3e13fddb1f9f30141.tar.gz gnunet-180f2e637029d045e3c72dc3e13fddb1f9f30141.zip |
moving API around to make ATS implementable and separable
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport_ats-new.c | 166 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_ats-new.h | 58 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 7 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 38 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.c | 162 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_validation.h | 22 |
6 files changed, 293 insertions, 160 deletions
diff --git a/src/transport/gnunet-service-transport_ats-new.c b/src/transport/gnunet-service-transport_ats-new.c index 7d99ab913..3a8bc7497 100644 --- a/src/transport/gnunet-service-transport_ats-new.c +++ b/src/transport/gnunet-service-transport_ats-new.c | |||
@@ -34,6 +34,11 @@ struct AllocationRecord | |||
34 | { | 34 | { |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Public key of the peer. | ||
38 | */ | ||
39 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; | ||
40 | |||
41 | /** | ||
37 | * Performance information associated with this address (array). | 42 | * Performance information associated with this address (array). |
38 | */ | 43 | */ |
39 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 44 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
@@ -77,6 +82,35 @@ struct AllocationRecord | |||
77 | 82 | ||
78 | 83 | ||
79 | /** | 84 | /** |
85 | * Opaque handle to stop incremental validation address callbacks. | ||
86 | */ | ||
87 | struct GST_AtsSuggestionContext | ||
88 | { | ||
89 | |||
90 | /** | ||
91 | * Function to call with our final suggestion. | ||
92 | */ | ||
93 | GST_AtsAddressSuggestionCallback cb; | ||
94 | |||
95 | /** | ||
96 | * Closure for 'cb'. | ||
97 | */ | ||
98 | void *cb_cls; | ||
99 | |||
100 | /** | ||
101 | * Global ATS handle. | ||
102 | */ | ||
103 | struct GST_AtsHandle *atc; | ||
104 | |||
105 | /** | ||
106 | * Which peer are we monitoring? | ||
107 | */ | ||
108 | struct GNUNET_PeerIdentity target; | ||
109 | |||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
80 | * Handle to the ATS subsystem. | 114 | * Handle to the ATS subsystem. |
81 | */ | 115 | */ |
82 | struct GST_AtsHandle | 116 | struct GST_AtsHandle |
@@ -103,6 +137,12 @@ struct GST_AtsHandle | |||
103 | struct GNUNET_CONTAINER_MultiHashMap *peers; | 137 | struct GNUNET_CONTAINER_MultiHashMap *peers; |
104 | 138 | ||
105 | /** | 139 | /** |
140 | * Map of PeerIdentities to 'struct GST_AtsSuggestionContext's. | ||
141 | */ | ||
142 | struct GNUNET_CONTAINER_MultiHashMap *notify_map; | ||
143 | |||
144 | |||
145 | /** | ||
106 | * Task scheduled to update our bandwidth assignment. | 146 | * Task scheduled to update our bandwidth assignment. |
107 | */ | 147 | */ |
108 | GNUNET_SCHEDULER_TaskIdentifier ba_task; | 148 | GNUNET_SCHEDULER_TaskIdentifier ba_task; |
@@ -228,6 +268,82 @@ update_bandwidth_assignment (struct GST_AtsHandle *atc, | |||
228 | 268 | ||
229 | 269 | ||
230 | /** | 270 | /** |
271 | * Function called with feasbile addresses we might want to suggest. | ||
272 | * | ||
273 | * @param cls the 'struct GST_AtsSuggestionContext' | ||
274 | * @param key identity of the peer | ||
275 | * @param value a 'struct AllocationRecord' for the peer | ||
276 | * @return GNUNET_NO if we're done, GNUNET_YES if we did not suggest an address yet | ||
277 | */ | ||
278 | static int | ||
279 | suggest_address (void *cls, | ||
280 | const GNUNET_HashCode *key, | ||
281 | void *value) | ||
282 | { | ||
283 | struct GST_AtsSuggestionContest *asc = cls; | ||
284 | struct AllocationRecord *ar = value; | ||
285 | |||
286 | // FIXME... | ||
287 | return GNUNET_YES; | ||
288 | } | ||
289 | |||
290 | |||
291 | /** | ||
292 | * We would like to establish a new connection with a peer. | ||
293 | * ATS should suggest a good address to begin with. | ||
294 | * | ||
295 | * @param atc handle | ||
296 | * @param peer identity of the new peer | ||
297 | * @param cb function to call with the address | ||
298 | * @param cb_cls closure for cb | ||
299 | */ | ||
300 | struct GST_AtsSuggestionContext * | ||
301 | GST_ats_suggest_address (struct GST_AtsHandle *atc, | ||
302 | const struct GNUNET_PeerIdentity *peer, | ||
303 | GST_AtsAddressSuggestionCallback cb, | ||
304 | void *cb_cls) | ||
305 | { | ||
306 | struct GST_AtsSuggestionContext *asc; | ||
307 | |||
308 | asc = GNUNET_malloc (sizeof (struct GST_AtsSuggestionContext)); | ||
309 | asc->cb = cb; | ||
310 | asc->cb_cls = cb_cls; | ||
311 | asc->atc = atc; | ||
312 | asc->target = *peer; | ||
313 | GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, | ||
314 | &peer->hashPubKey, | ||
315 | &suggest_address, | ||
316 | asc); | ||
317 | if (NULL == asc->cb) | ||
318 | { | ||
319 | GNUNET_free (asc); | ||
320 | return NULL; | ||
321 | } | ||
322 | GNUNET_CONTAINER_multihashmap_put (atc->notify_map, | ||
323 | &peer->hashPubKey, | ||
324 | asc, | ||
325 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
326 | return asc; | ||
327 | } | ||
328 | |||
329 | |||
330 | /** | ||
331 | * Cancel suggestion request. | ||
332 | * | ||
333 | * @param asc handle of the request to cancel | ||
334 | */ | ||
335 | void | ||
336 | GST_ats_suggest_address_cancel (struct GST_AtsSuggestionContext *asc) | ||
337 | { | ||
338 | GNUNET_assert (GNUNET_OK == | ||
339 | GNUNET_CONTAINER_multihashmap_remove (asc->atc->notify_map, | ||
340 | &asc->target.hashPubKey, | ||
341 | asc)); | ||
342 | GNUNET_free (asc); | ||
343 | } | ||
344 | |||
345 | |||
346 | /** | ||
231 | * Initialize the ATS subsystem. | 347 | * Initialize the ATS subsystem. |
232 | * | 348 | * |
233 | * @param cfg configuration to use | 349 | * @param cfg configuration to use |
@@ -294,6 +410,9 @@ GST_ats_shutdown (struct GST_AtsHandle *atc) | |||
294 | &destroy_allocation_record, | 410 | &destroy_allocation_record, |
295 | NULL); | 411 | NULL); |
296 | GNUNET_CONTAINER_multihashmap_destroy (atc->peers); | 412 | GNUNET_CONTAINER_multihashmap_destroy (atc->peers); |
413 | GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0); | ||
414 | GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map); | ||
415 | atc->notify_map = NULL; | ||
297 | GNUNET_free (atc); | 416 | GNUNET_free (atc); |
298 | } | 417 | } |
299 | 418 | ||
@@ -377,7 +496,8 @@ update_session (void *cls, | |||
377 | * @param ats_count number of performance records in 'ats' | 496 | * @param ats_count number of performance records in 'ats' |
378 | */ | 497 | */ |
379 | static struct AllocationRecord * | 498 | static struct AllocationRecord * |
380 | create_allocation_record (const char *plugin_name, | 499 | create_allocation_record (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, |
500 | const char *plugin_name, | ||
381 | struct Session *session, | 501 | struct Session *session, |
382 | const void *plugin_addr, | 502 | const void *plugin_addr, |
383 | size_t plugin_addr_len, | 503 | size_t plugin_addr_len, |
@@ -387,6 +507,7 @@ create_allocation_record (const char *plugin_name, | |||
387 | struct AllocationRecord *ar; | 507 | struct AllocationRecord *ar; |
388 | 508 | ||
389 | ar = GNUNET_malloc (sizeof (struct AllocationRecord) + plugin_addr_len); | 509 | ar = GNUNET_malloc (sizeof (struct AllocationRecord) + plugin_addr_len); |
510 | ar->public_key = *public_key; | ||
390 | ar->plugin_name = GNUNET_strdup (plugin_name); | 511 | ar->plugin_name = GNUNET_strdup (plugin_name); |
391 | ar->plugin_addr = &ar[1]; | 512 | ar->plugin_addr = &ar[1]; |
392 | memcpy (&ar[1], plugin_addr, plugin_addr_len); | 513 | memcpy (&ar[1], plugin_addr, plugin_addr_len); |
@@ -433,6 +554,7 @@ disconnect_peer (void *cls, | |||
433 | * Calculate bandwidth assignments including the new peer. | 554 | * Calculate bandwidth assignments including the new peer. |
434 | * | 555 | * |
435 | * @param atc handle | 556 | * @param atc handle |
557 | * @param public_key public key of the peer | ||
436 | * @param peer identity of the new peer | 558 | * @param peer identity of the new peer |
437 | * @param plugin_name name of the currently used transport plugin | 559 | * @param plugin_name name of the currently used transport plugin |
438 | * @param session session in use (if available) | 560 | * @param session session in use (if available) |
@@ -443,6 +565,7 @@ disconnect_peer (void *cls, | |||
443 | */ | 565 | */ |
444 | void | 566 | void |
445 | GST_ats_peer_connect (struct GST_AtsHandle *atc, | 567 | GST_ats_peer_connect (struct GST_AtsHandle *atc, |
568 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
446 | const struct GNUNET_PeerIdentity *peer, | 569 | const struct GNUNET_PeerIdentity *peer, |
447 | const char *plugin_name, | 570 | const char *plugin_name, |
448 | struct Session *session, | 571 | struct Session *session, |
@@ -457,7 +580,8 @@ GST_ats_peer_connect (struct GST_AtsHandle *atc, | |||
457 | (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, | 580 | (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, |
458 | &disconnect_peer, | 581 | &disconnect_peer, |
459 | atc); | 582 | atc); |
460 | ar = create_allocation_record (plugin_name, | 583 | ar = create_allocation_record (public_key, |
584 | plugin_name, | ||
461 | session, | 585 | session, |
462 | plugin_addr, | 586 | plugin_addr, |
463 | plugin_addr_len, | 587 | plugin_addr_len, |
@@ -576,6 +700,33 @@ GST_ats_session_destroyed (struct GST_AtsHandle *atc, | |||
576 | 700 | ||
577 | 701 | ||
578 | /** | 702 | /** |
703 | * Notify validation watcher that an entry is now valid | ||
704 | * | ||
705 | * @param cls 'struct ValidationEntry' that is now valid | ||
706 | * @param key peer identity (unused) | ||
707 | * @param value a 'GST_ValidationIteratorContext' to notify | ||
708 | * @return GNUNET_YES (continue to iterate) | ||
709 | */ | ||
710 | static int | ||
711 | notify_valid (void *cls, | ||
712 | const GNUNET_HashCode *key, | ||
713 | void *value) | ||
714 | { | ||
715 | struct AllocationRecord *ar = cls; | ||
716 | struct GST_AtsSuggestionContext *asc = value; | ||
717 | |||
718 | asc->cb (asc->cb_cls, | ||
719 | &ar->public_key, | ||
720 | &asc->target, | ||
721 | ar->plugin_name, | ||
722 | ar->plugin_addr, | ||
723 | ar->plugin_addr_len, | ||
724 | ar->ats, ar->ats_count); | ||
725 | return GNUNET_OK; | ||
726 | } | ||
727 | |||
728 | |||
729 | /** | ||
579 | * We have updated performance statistics for a given address. Note | 730 | * We have updated performance statistics for a given address. Note |
580 | * that this function can be called for addresses that are currently | 731 | * that this function can be called for addresses that are currently |
581 | * in use as well as addresses that are valid but not actively in use. | 732 | * in use as well as addresses that are valid but not actively in use. |
@@ -584,7 +735,8 @@ GST_ats_session_destroyed (struct GST_AtsHandle *atc, | |||
584 | * for later use). Update bandwidth assignments. | 735 | * for later use). Update bandwidth assignments. |
585 | * | 736 | * |
586 | * @param atc handle | 737 | * @param atc handle |
587 | * @param peer identity of the new peer | 738 | * @param public_key public key of the peer |
739 | * @param peer identity of the peer | ||
588 | * @param plugin_name name of the transport plugin | 740 | * @param plugin_name name of the transport plugin |
589 | * @param session session handle (if available) | 741 | * @param session session handle (if available) |
590 | * @param plugin_addr address (if available) | 742 | * @param plugin_addr address (if available) |
@@ -594,6 +746,7 @@ GST_ats_session_destroyed (struct GST_AtsHandle *atc, | |||
594 | */ | 746 | */ |
595 | void | 747 | void |
596 | GST_ats_address_update (struct GST_AtsHandle *atc, | 748 | GST_ats_address_update (struct GST_AtsHandle *atc, |
749 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
597 | const struct GNUNET_PeerIdentity *peer, | 750 | const struct GNUNET_PeerIdentity *peer, |
598 | const char *plugin_name, | 751 | const char *plugin_name, |
599 | struct Session *session, | 752 | struct Session *session, |
@@ -605,7 +758,8 @@ GST_ats_address_update (struct GST_AtsHandle *atc, | |||
605 | struct AllocationRecord *ar; | 758 | struct AllocationRecord *ar; |
606 | struct UpdateSessionContext usc; | 759 | struct UpdateSessionContext usc; |
607 | 760 | ||
608 | ar = create_allocation_record (plugin_name, | 761 | ar = create_allocation_record (public_key, |
762 | plugin_name, | ||
609 | session, | 763 | session, |
610 | plugin_addr, | 764 | plugin_addr, |
611 | plugin_addr_len, | 765 | plugin_addr_len, |
@@ -626,6 +780,10 @@ GST_ats_address_update (struct GST_AtsHandle *atc, | |||
626 | &peer->hashPubKey, | 780 | &peer->hashPubKey, |
627 | ar, | 781 | ar, |
628 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 782 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
783 | GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map, | ||
784 | &peer->hashPubKey, | ||
785 | ¬ify_valid, | ||
786 | ar); | ||
629 | } | 787 | } |
630 | 788 | ||
631 | /* end of file gnunet-service-transport_ats.c */ | 789 | /* end of file gnunet-service-transport_ats.c */ |
diff --git a/src/transport/gnunet-service-transport_ats-new.h b/src/transport/gnunet-service-transport_ats-new.h index b3f004989..ed72dd171 100644 --- a/src/transport/gnunet-service-transport_ats-new.h +++ b/src/transport/gnunet-service-transport_ats-new.h | |||
@@ -80,6 +80,7 @@ GST_ats_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
80 | GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb, | 80 | GNUNET_TRANSPORT_ATS_AllocationNotification alloc_cb, |
81 | void *alloc_cb_cls); | 81 | void *alloc_cb_cls); |
82 | 82 | ||
83 | |||
83 | /** | 84 | /** |
84 | * Shutdown the ATS subsystem. | 85 | * Shutdown the ATS subsystem. |
85 | * | 86 | * |
@@ -90,11 +91,65 @@ GST_ats_shutdown (struct GST_AtsHandle *atc); | |||
90 | 91 | ||
91 | 92 | ||
92 | /** | 93 | /** |
94 | * Signature of a function that takes an address suggestion | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param public_key public key of the peer | ||
98 | * @param peer identity of the new peer | ||
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 | ||
101 | * @param plugin_addr_len number of bytes in plugin_addr | ||
102 | * @param ats performance data for the address (as far as known) | ||
103 | * @param ats_count number of performance records in 'ats' | ||
104 | */ | ||
105 | typedef void (*GST_AtsAddressSuggestionCallback)(void *cls, | ||
106 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
107 | const struct GNUNET_PeerIdentity *peer, | ||
108 | const char *plugin_name, | ||
109 | const void *plugin_addr, | ||
110 | size_t plugin_addr_len, | ||
111 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
112 | uint32_t ats_count); | ||
113 | |||
114 | |||
115 | /** | ||
116 | * Handle to cancel suggestion request. | ||
117 | */ | ||
118 | struct GST_AtsSuggestionContext; | ||
119 | |||
120 | |||
121 | /** | ||
122 | * We would like to establish a new connection with a peer. | ||
123 | * ATS should suggest a good address to begin with. | ||
124 | * | ||
125 | * @param atc handle | ||
126 | * @param peer identity of the new peer | ||
127 | * @param cb function to call with the address | ||
128 | * @param cb_cls closure for cb | ||
129 | */ | ||
130 | struct GST_AtsSuggestionContext * | ||
131 | GST_ats_suggest_address (struct GST_AtsHandle *atc, | ||
132 | const struct GNUNET_PeerIdentity *peer, | ||
133 | GST_AtsAddressSuggestionCallback cb, | ||
134 | void *cb_cls); | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Cancel suggestion request. | ||
139 | * | ||
140 | * @param asc handle of the request to cancel | ||
141 | */ | ||
142 | void | ||
143 | GST_ats_suggest_address_cancel (struct GST_AtsSuggestionContext *asc); | ||
144 | |||
145 | |||
146 | /** | ||
93 | * We established a new connection with a peer (for example, because | 147 | * We established a new connection with a peer (for example, because |
94 | * core asked for it or because the other peer connected to us). | 148 | * core asked for it or because the other peer connected to us). |
95 | * Calculate bandwidth assignments including the new peer. | 149 | * Calculate bandwidth assignments including the new peer. |
96 | * | 150 | * |
97 | * @param atc handle | 151 | * @param atc handle |
152 | * @param public_key public key of the peer | ||
98 | * @param peer identity of the new peer | 153 | * @param peer identity of the new peer |
99 | * @param plugin_name name of the currently used transport plugin | 154 | * @param plugin_name name of the currently used transport plugin |
100 | * @param session session in use (if available) | 155 | * @param session session in use (if available) |
@@ -105,6 +160,7 @@ GST_ats_shutdown (struct GST_AtsHandle *atc); | |||
105 | */ | 160 | */ |
106 | void | 161 | void |
107 | GST_ats_peer_connect (struct GST_AtsHandle *atc, | 162 | GST_ats_peer_connect (struct GST_AtsHandle *atc, |
163 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
108 | const struct GNUNET_PeerIdentity *peer, | 164 | const struct GNUNET_PeerIdentity *peer, |
109 | const char *plugin_name, | 165 | const char *plugin_name, |
110 | struct Session *session, | 166 | struct Session *session, |
@@ -149,6 +205,7 @@ GST_ats_session_destroyed (struct GST_AtsHandle *atc, | |||
149 | * for later use). Update bandwidth assignments. | 205 | * for later use). Update bandwidth assignments. |
150 | * | 206 | * |
151 | * @param atc handle | 207 | * @param atc handle |
208 | * @param public_key public key of the peer | ||
152 | * @param peer identity of the new peer | 209 | * @param peer identity of the new peer |
153 | * @param plugin_name name of the transport plugin | 210 | * @param plugin_name name of the transport plugin |
154 | * @param session session handle (if available) | 211 | * @param session session handle (if available) |
@@ -159,6 +216,7 @@ GST_ats_session_destroyed (struct GST_AtsHandle *atc, | |||
159 | */ | 216 | */ |
160 | void | 217 | void |
161 | GST_ats_address_update (struct GST_AtsHandle *atc, | 218 | GST_ats_address_update (struct GST_AtsHandle *atc, |
219 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | ||
162 | const struct GNUNET_PeerIdentity *peer, | 220 | const struct GNUNET_PeerIdentity *peer, |
163 | const char *plugin_name, | 221 | const char *plugin_name, |
164 | struct Session *session, | 222 | struct Session *session, |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 209b507cc..64592d5d6 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -745,10 +745,9 @@ GST_clients_handle_peer_address_lookup (void *cls, | |||
745 | peer_address_lookup = (const struct PeerAddressLookupMessage *) message; | 745 | peer_address_lookup = (const struct PeerAddressLookupMessage *) message; |
746 | GNUNET_break (ntohl (peer_address_lookup->reserved) == 0); | 746 | GNUNET_break (ntohl (peer_address_lookup->reserved) == 0); |
747 | tc = GNUNET_SERVER_transmit_context_create (client); | 747 | tc = GNUNET_SERVER_transmit_context_create (client); |
748 | (void) GST_validation_get_addresses (&peer_address_lookup->peer, | 748 | GST_validation_get_addresses (&peer_address_lookup->peer, |
749 | GNUNET_YES, | 749 | &send_address_to_client, |
750 | &send_address_to_client, | 750 | tc); |
751 | tc); | ||
752 | GNUNET_SERVER_transmit_context_append_data (tc, | 751 | GNUNET_SERVER_transmit_context_append_data (tc, |
753 | NULL, 0, | 752 | NULL, 0, |
754 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 753 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index a7c1136f2..cff2bb595 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -126,10 +126,10 @@ struct NeighbourMapEntry | |||
126 | struct MessageQueue *messages_tail; | 126 | struct MessageQueue *messages_tail; |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * Context for validation address iteration. | 129 | * Context for address suggestion. |
130 | * NULL after we are connected. | 130 | * NULL after we are connected. |
131 | */ | 131 | */ |
132 | struct GST_ValidationIteratorContext *vic; | 132 | struct GST_AtsSuggestionContext *asc; |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Performance data for the peer. | 135 | * Performance data for the peer. |
@@ -339,10 +339,10 @@ disconnect_neighbour (struct NeighbourMapEntry *n) | |||
339 | mq); | 339 | mq); |
340 | GNUNET_free (mq); | 340 | GNUNET_free (mq); |
341 | } | 341 | } |
342 | if (NULL != n->vic) | 342 | if (NULL != n->asc) |
343 | { | 343 | { |
344 | GST_validation_get_addresses_cancel (n->vic); | 344 | GST_ats_suggest_address_cancel (n->asc); |
345 | n->vic = NULL; | 345 | n->asc = NULL; |
346 | } | 346 | } |
347 | GNUNET_array_grow (n->ats, | 347 | GNUNET_array_grow (n->ats, |
348 | n->ats_count, | 348 | n->ats_count, |
@@ -400,35 +400,31 @@ GST_neighbours_stop () | |||
400 | * @param cls the 'struct NeighbourMapEntry' of the target | 400 | * @param cls the 'struct NeighbourMapEntry' of the target |
401 | * @param public_key public key for the peer, never NULL | 401 | * @param public_key public key for the peer, never NULL |
402 | * @param target identity of the target peer | 402 | * @param target identity of the target peer |
403 | * @param valid_until is ZERO if we never validated the address, | ||
404 | * otherwise a time up to when we consider it (or was) valid | ||
405 | * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) | ||
406 | * is ZERO if the address is considered valid (no validation needed) | ||
407 | * otherwise a time in the future if we're currently denying re-validation | ||
408 | * @param plugin_name name of the plugin | 403 | * @param plugin_name name of the plugin |
409 | * @param plugin_address binary address | 404 | * @param plugin_address binary address |
410 | * @param plugin_address_len length of address | 405 | * @param plugin_address_len length of address |
406 | * @param ats performance data for the address (as far as known) | ||
407 | * @param ats_count number of performance records in 'ats' | ||
411 | */ | 408 | */ |
412 | static void | 409 | static void |
413 | try_connect_using_address (void *cls, | 410 | try_connect_using_address (void *cls, |
414 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | 411 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, |
415 | const struct GNUNET_PeerIdentity *target, | 412 | const struct GNUNET_PeerIdentity *target, |
416 | struct GNUNET_TIME_Absolute valid_until, | ||
417 | struct GNUNET_TIME_Absolute validation_block, | ||
418 | const char *plugin_name, | 413 | const char *plugin_name, |
419 | const void *plugin_address, | 414 | const void *plugin_address, |
420 | size_t plugin_address_len) | 415 | size_t plugin_address_len, |
416 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | ||
417 | uint32_t ats_count) | ||
421 | { | 418 | { |
422 | struct NeighbourMapEntry *n = cls; | 419 | struct NeighbourMapEntry *n = cls; |
423 | 420 | ||
421 | n->asc = NULL; | ||
424 | if (n->public_key_valid == GNUNET_NO) | 422 | if (n->public_key_valid == GNUNET_NO) |
425 | { | 423 | { |
426 | n->public_key = *public_key; | 424 | n->public_key = *public_key; |
427 | n->public_key_valid = GNUNET_YES; | 425 | n->public_key_valid = GNUNET_YES; |
428 | } | 426 | } |
429 | if (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value == 0) | 427 | /* FIXME: do connect! */ |
430 | return; /* address is not valid right now */ | ||
431 | /* FIXME: do ATS here! */ | ||
432 | 428 | ||
433 | } | 429 | } |
434 | 430 | ||
@@ -488,12 +484,12 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
488 | n, | 484 | n, |
489 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 485 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
490 | } | 486 | } |
491 | if (n->vic != NULL) | 487 | if (n->asc != NULL) |
492 | return; /* already trying */ | 488 | return; /* already trying */ |
493 | n->vic = GST_validation_get_addresses (target, | 489 | n->asc = GST_ats_suggest_address (GST_ats, |
494 | GNUNET_NO, | 490 | target, |
495 | &try_connect_using_address, | 491 | &try_connect_using_address, |
496 | n); | 492 | n); |
497 | } | 493 | } |
498 | 494 | ||
499 | 495 | ||
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index 13d48bce2..1a619a901 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunet-service-transport_validation.h" | 27 | #include "gnunet-service-transport_validation.h" |
28 | #include "gnunet-service-transport_plugins.h" | 28 | #include "gnunet-service-transport_plugins.h" |
29 | #include "gnunet-service-transport_hello.h" | 29 | #include "gnunet-service-transport_hello.h" |
30 | #include "gnunet-service-transport_ats-new.h" | ||
30 | #include "gnunet-service-transport.h" | 31 | #include "gnunet-service-transport.h" |
31 | #include "gnunet_hello_lib.h" | 32 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_peerinfo_service.h" | 33 | #include "gnunet_peerinfo_service.h" |
@@ -249,28 +250,6 @@ struct CheckHelloValidatedContext | |||
249 | 250 | ||
250 | 251 | ||
251 | /** | 252 | /** |
252 | * Opaque handle to stop incremental validation address callbacks. | ||
253 | */ | ||
254 | struct GST_ValidationIteratorContext | ||
255 | { | ||
256 | /** | ||
257 | * Function to call on each address. | ||
258 | */ | ||
259 | GST_ValidationAddressCallback cb; | ||
260 | |||
261 | /** | ||
262 | * Closure for 'cb'. | ||
263 | */ | ||
264 | void *cb_cls; | ||
265 | |||
266 | /** | ||
267 | * Which peer are we monitoring? | ||
268 | */ | ||
269 | struct GNUNET_PeerIdentity target; | ||
270 | }; | ||
271 | |||
272 | |||
273 | /** | ||
274 | * Head of linked list of HELLOs awaiting validation. | 253 | * Head of linked list of HELLOs awaiting validation. |
275 | */ | 254 | */ |
276 | static struct CheckHelloValidatedContext *chvc_head; | 255 | static struct CheckHelloValidatedContext *chvc_head; |
@@ -288,11 +267,6 @@ static struct CheckHelloValidatedContext *chvc_tail; | |||
288 | static struct GNUNET_CONTAINER_MultiHashMap *validation_map; | 267 | static struct GNUNET_CONTAINER_MultiHashMap *validation_map; |
289 | 268 | ||
290 | /** | 269 | /** |
291 | * Map of PeerIdentities to 'struct GST_ValidationIteratorContext's. | ||
292 | */ | ||
293 | static struct GNUNET_CONTAINER_MultiHashMap *notify_map; | ||
294 | |||
295 | /** | ||
296 | * Context for peerinfo iteration. | 270 | * Context for peerinfo iteration. |
297 | */ | 271 | */ |
298 | static struct GNUNET_PEERINFO_NotifyContext *pnc; | 272 | static struct GNUNET_PEERINFO_NotifyContext *pnc; |
@@ -409,34 +383,6 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub | |||
409 | 383 | ||
410 | 384 | ||
411 | /** | 385 | /** |
412 | * Notify validation watcher that an entry is now valid | ||
413 | * | ||
414 | * @param cls 'struct ValidationEntry' that is now valid | ||
415 | * @param key peer identity (unused) | ||
416 | * @param value a 'GST_ValidationIteratorContext' to notify | ||
417 | * @return GNUNET_YES (continue to iterate) | ||
418 | */ | ||
419 | static int | ||
420 | notify_valid (void *cls, | ||
421 | const GNUNET_HashCode *key, | ||
422 | void *value) | ||
423 | { | ||
424 | struct ValidationEntry *ve = cls; | ||
425 | struct GST_ValidationIteratorContext *vic = value; | ||
426 | |||
427 | vic->cb (vic->cb_cls, | ||
428 | &ve->public_key, | ||
429 | &vic->target, | ||
430 | ve->valid_until, | ||
431 | ve->validation_block, | ||
432 | ve->transport_name, | ||
433 | ve->addr, | ||
434 | ve->addrlen); | ||
435 | return GNUNET_OK; | ||
436 | } | ||
437 | |||
438 | |||
439 | /** | ||
440 | * Iterator which adds the given address to the set of validated | 386 | * Iterator which adds the given address to the set of validated |
441 | * addresses. | 387 | * addresses. |
442 | * | 388 | * |
@@ -472,10 +418,14 @@ add_valid_address (void *cls, | |||
472 | ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); | 418 | ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); |
473 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, | 419 | ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, |
474 | expiration); | 420 | expiration); |
475 | GNUNET_CONTAINER_multihashmap_get_multiple (notify_map, | 421 | GST_ats_address_update (GST_ats, |
476 | &pid.hashPubKey, | 422 | &public_key, |
477 | ¬ify_valid, | 423 | &pid, |
478 | ve); | 424 | tname, |
425 | NULL, | ||
426 | addr, | ||
427 | addrlen, | ||
428 | NULL, 0); | ||
479 | return GNUNET_OK; | 429 | return GNUNET_OK; |
480 | } | 430 | } |
481 | 431 | ||
@@ -512,7 +462,6 @@ void | |||
512 | GST_validation_start () | 462 | GST_validation_start () |
513 | { | 463 | { |
514 | validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE); | 464 | validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE); |
515 | notify_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE); | ||
516 | pnc = GNUNET_PEERINFO_notify (GST_cfg, | 465 | pnc = GNUNET_PEERINFO_notify (GST_cfg, |
517 | &process_peerinfo_hello, | 466 | &process_peerinfo_hello, |
518 | NULL); | 467 | NULL); |
@@ -558,9 +507,6 @@ GST_validation_stop () | |||
558 | NULL); | 507 | NULL); |
559 | GNUNET_CONTAINER_multihashmap_destroy (validation_map); | 508 | GNUNET_CONTAINER_multihashmap_destroy (validation_map); |
560 | validation_map = NULL; | 509 | validation_map = NULL; |
561 | GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (notify_map) == 0); | ||
562 | GNUNET_CONTAINER_multihashmap_destroy (notify_map); | ||
563 | notify_map = NULL; | ||
564 | while (NULL != (chvc = chvc_head)) | 510 | while (NULL != (chvc = chvc_head)) |
565 | { | 511 | { |
566 | GNUNET_CONTAINER_DLL_remove (chvc_head, | 512 | GNUNET_CONTAINER_DLL_remove (chvc_head, |
@@ -801,10 +747,9 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
801 | gettext_noop ("# PONGs multicast to all available addresses"), | 747 | gettext_noop ("# PONGs multicast to all available addresses"), |
802 | 1, | 748 | 1, |
803 | GNUNET_NO); | 749 | GNUNET_NO); |
804 | (void) GST_validation_get_addresses (sender, | 750 | GST_validation_get_addresses (sender, |
805 | GNUNET_YES, | 751 | &multicast_pong, |
806 | &multicast_pong, | 752 | pong); |
807 | pong); | ||
808 | GNUNET_free (pong); | 753 | GNUNET_free (pong); |
809 | } | 754 | } |
810 | 755 | ||
@@ -1092,6 +1037,14 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1092 | 1037 | ||
1093 | /* validity achieved, remember it! */ | 1038 | /* validity achieved, remember it! */ |
1094 | ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); | 1039 | ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); |
1040 | GST_ats_address_update (GST_ats, | ||
1041 | &ve->public_key, | ||
1042 | &ve->pid, | ||
1043 | ve->transport_name, | ||
1044 | NULL, | ||
1045 | ve->addr, | ||
1046 | ve->addrlen, | ||
1047 | NULL, 0); /* FIXME: compute and add latency here... */ | ||
1095 | 1048 | ||
1096 | /* build HELLO to store in PEERINFO */ | 1049 | /* build HELLO to store in PEERINFO */ |
1097 | hello = GNUNET_HELLO_create (&ve->public_key, | 1050 | hello = GNUNET_HELLO_create (&ve->public_key, |
@@ -1146,6 +1099,24 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) | |||
1146 | 1099 | ||
1147 | 1100 | ||
1148 | /** | 1101 | /** |
1102 | * Closure for 'iterate_addresses' | ||
1103 | */ | ||
1104 | struct IteratorContext | ||
1105 | { | ||
1106 | /** | ||
1107 | * Function to call on each address. | ||
1108 | */ | ||
1109 | GST_ValidationAddressCallback cb; | ||
1110 | |||
1111 | /** | ||
1112 | * Closure for 'cb'. | ||
1113 | */ | ||
1114 | void *cb_cls; | ||
1115 | |||
1116 | }; | ||
1117 | |||
1118 | |||
1119 | /** | ||
1149 | * Call the callback in the closure for each validation entry. | 1120 | * Call the callback in the closure for each validation entry. |
1150 | * | 1121 | * |
1151 | * @param cls the 'struct GST_ValidationIteratorContext' | 1122 | * @param cls the 'struct GST_ValidationIteratorContext' |
@@ -1158,17 +1129,17 @@ iterate_addresses (void *cls, | |||
1158 | const GNUNET_HashCode *key, | 1129 | const GNUNET_HashCode *key, |
1159 | void *value) | 1130 | void *value) |
1160 | { | 1131 | { |
1161 | struct GST_ValidationIteratorContext *vic = cls; | 1132 | struct IteratorContext *ic = cls; |
1162 | struct ValidationEntry *ve = value; | 1133 | struct ValidationEntry *ve = value; |
1163 | 1134 | ||
1164 | vic->cb (vic->cb_cls, | 1135 | ic->cb (ic->cb_cls, |
1165 | &ve->public_key, | 1136 | &ve->public_key, |
1166 | &ve->pid, | 1137 | &ve->pid, |
1167 | ve->valid_until, | 1138 | ve->valid_until, |
1168 | ve->validation_block, | 1139 | ve->validation_block, |
1169 | ve->transport_name, | 1140 | ve->transport_name, |
1170 | ve->addr, | 1141 | ve->addr, |
1171 | ve->addrlen); | 1142 | ve->addrlen); |
1172 | return GNUNET_OK; | 1143 | return GNUNET_OK; |
1173 | } | 1144 | } |
1174 | 1145 | ||
@@ -1185,48 +1156,19 @@ iterate_addresses (void *cls, | |||
1185 | * @param cb_cls closure for 'cb' | 1156 | * @param cb_cls closure for 'cb' |
1186 | * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES | 1157 | * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES |
1187 | */ | 1158 | */ |
1188 | struct GST_ValidationIteratorContext * | 1159 | void |
1189 | GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, | 1160 | GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, |
1190 | int snapshot_only, | ||
1191 | GST_ValidationAddressCallback cb, | 1161 | GST_ValidationAddressCallback cb, |
1192 | void *cb_cls) | 1162 | void *cb_cls) |
1193 | { | 1163 | { |
1194 | struct GST_ValidationIteratorContext *vic; | 1164 | struct IteratorContext ic; |
1195 | 1165 | ||
1196 | vic = GNUNET_malloc (sizeof (struct GST_ValidationIteratorContext)); | 1166 | ic.cb = cb; |
1197 | vic->cb = cb; | 1167 | ic.cb_cls = cb_cls; |
1198 | vic->cb_cls = cb_cls; | ||
1199 | vic->target = *target; | ||
1200 | GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, | 1168 | GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, |
1201 | &target->hashPubKey, | 1169 | &target->hashPubKey, |
1202 | &iterate_addresses, | 1170 | &iterate_addresses, |
1203 | vic); | 1171 | &ic); |
1204 | if (GNUNET_YES == snapshot_only) | ||
1205 | { | ||
1206 | GNUNET_free (vic); | ||
1207 | return NULL; | ||
1208 | } | ||
1209 | GNUNET_CONTAINER_multihashmap_put (notify_map, | ||
1210 | &target->hashPubKey, | ||
1211 | vic, | ||
1212 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1213 | return vic; | ||
1214 | } | ||
1215 | |||
1216 | |||
1217 | /** | ||
1218 | * Cancel an active validation address iteration. | ||
1219 | * | ||
1220 | * @param ctx the context of the operation that is cancelled | ||
1221 | */ | ||
1222 | void | ||
1223 | GST_validation_get_addresses_cancel (struct GST_ValidationIteratorContext *ctx) | ||
1224 | { | ||
1225 | GNUNET_assert (GNUNET_OK == | ||
1226 | GNUNET_CONTAINER_multihashmap_remove (notify_map, | ||
1227 | &ctx->target.hashPubKey, | ||
1228 | ctx)); | ||
1229 | GNUNET_free (ctx); | ||
1230 | } | 1172 | } |
1231 | 1173 | ||
1232 | 1174 | ||
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index 77c5164f9..5ab2e9163 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h | |||
@@ -95,12 +95,6 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello); | |||
95 | 95 | ||
96 | 96 | ||
97 | /** | 97 | /** |
98 | * Opaque handle to stop incremental validation address callbacks. | ||
99 | */ | ||
100 | struct GST_ValidationIteratorContext; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Function called for each address (or address status change) that | 98 | * Function called for each address (or address status change) that |
105 | * the validation module is aware of (for the given target). | 99 | * the validation module is aware of (for the given target). |
106 | * | 100 | * |
@@ -128,32 +122,18 @@ typedef void (*GST_ValidationAddressCallback)(void *cls, | |||
128 | 122 | ||
129 | /** | 123 | /** |
130 | * Call the given function for each address for the given target. | 124 | * Call the given function for each address for the given target. |
131 | * Can either give a snapshot (synchronous API) or be continuous. | ||
132 | * | 125 | * |
133 | * @param target peer information is requested for | 126 | * @param target peer information is requested for |
134 | * @param snapshot_only GNUNET_YES to iterate over addresses once, GNUNET_NO to | ||
135 | * continue to give information about addresses as it evolves | ||
136 | * @param cb function to call; will not be called after this function returns | 127 | * @param cb function to call; will not be called after this function returns |
137 | * if snapshot_only is GNUNET_YES | 128 | * if snapshot_only is GNUNET_YES |
138 | * @param cb_cls closure for 'cb' | 129 | * @param cb_cls closure for 'cb' |
139 | * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES | 130 | * @return context to cancel, NULL if 'snapshot_only' is GNUNET_YES |
140 | */ | 131 | */ |
141 | struct GST_ValidationIteratorContext * | 132 | void |
142 | GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, | 133 | GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, |
143 | int snapshot_only, | ||
144 | GST_ValidationAddressCallback cb, | 134 | GST_ValidationAddressCallback cb, |
145 | void *cb_cls); | 135 | void *cb_cls); |
146 | 136 | ||
147 | 137 | ||
148 | /** | ||
149 | * Cancel an active validation address iteration. | ||
150 | * | ||
151 | * @param ctx the context of the operation that is cancelled | ||
152 | */ | ||
153 | void | ||
154 | GST_validation_get_addresses_cancel (struct GST_ValidationIteratorContext *ctx); | ||
155 | |||
156 | |||
157 | |||
158 | #endif | 138 | #endif |
159 | /* end of file gnunet-service-transport_validation.h */ | 139 | /* end of file gnunet-service-transport_validation.h */ |