diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 09:37:54 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 09:37:54 +0000 |
commit | 623df97886da9ee06724b7860a1a2463737b750e (patch) | |
tree | a7638265a42b7b276d10403078411e4f4d8973d8 /src | |
parent | 51b7d6d6e0d50e77a3fc948af68ae02f325684ac (diff) | |
download | gnunet-623df97886da9ee06724b7860a1a2463737b750e.tar.gz gnunet-623df97886da9ee06724b7860a1a2463737b750e.zip |
first steps to transport_api cleanup
compiles but no guarante to work!
Diffstat (limited to 'src')
-rw-r--r-- | src/core/gnunet-core-list-connections.c | 7 | ||||
-rw-r--r-- | src/hello/address.c | 15 | ||||
-rw-r--r-- | src/include/gnunet_hello_lib.h | 8 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 53 | ||||
-rw-r--r-- | src/peerinfo-tool/gnunet-peerinfo.c | 8 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 14 | ||||
-rw-r--r-- | src/transport/transport_api_address_iterate.c | 29 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 35 | ||||
-rw-r--r-- | src/transport/transport_api_peer_address_lookup.c | 25 |
9 files changed, 97 insertions, 97 deletions
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c index 79490bcc5..3f3288d79 100644 --- a/src/core/gnunet-core-list-connections.c +++ b/src/core/gnunet-core-list-connections.c | |||
@@ -97,7 +97,7 @@ dump_pc (struct PrintContext *pc) | |||
97 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | 97 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string |
98 | */ | 98 | */ |
99 | static void | 99 | static void |
100 | process_resolved_address (void *cls, const char *address) | 100 | process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address) |
101 | { | 101 | { |
102 | struct PrintContext *pc = cls; | 102 | struct PrintContext *pc = cls; |
103 | struct AddressStringList *new_address; | 103 | struct AddressStringList *new_address; |
@@ -112,7 +112,8 @@ process_resolved_address (void *cls, const char *address) | |||
112 | #if VERBOSE | 112 | #if VERBOSE |
113 | fprintf (stderr, "Received address %s\n", address); | 113 | fprintf (stderr, "Received address %s\n", address); |
114 | #endif | 114 | #endif |
115 | new_address->address_string = GNUNET_strdup (address); | 115 | // FIXME : GNUNET_TRANSPORT_address_to_string |
116 | new_address->address_string = GNUNET_strdup ("FIXME"); | ||
116 | GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, | 117 | GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, |
117 | new_address); | 118 | new_address); |
118 | } | 119 | } |
@@ -136,7 +137,7 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
136 | #endif | 137 | #endif |
137 | pc = GNUNET_malloc (sizeof (struct PrintContext)); | 138 | pc = GNUNET_malloc (sizeof (struct PrintContext)); |
138 | pc->peer = *peer; | 139 | pc->peer = *peer; |
139 | GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, GNUNET_TIME_UNIT_MINUTES, | 140 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, peer, GNUNET_TIME_UNIT_MINUTES, |
140 | &process_resolved_address, pc); | 141 | &process_resolved_address, pc); |
141 | } | 142 | } |
142 | #if VERBOSE | 143 | #if VERBOSE |
diff --git a/src/hello/address.c b/src/hello/address.c index 5cfa10185..b511ca9df 100644 --- a/src/hello/address.c +++ b/src/hello/address.c | |||
@@ -63,6 +63,21 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | |||
63 | 63 | ||
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Get the size of an address struct. | ||
67 | * | ||
68 | * @param address address | ||
69 | * @return the size | ||
70 | */ | ||
71 | size_t | ||
72 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address) | ||
73 | { | ||
74 | return sizeof (struct GNUNET_HELLO_Address) + | ||
75 | address->address_length + | ||
76 | strlen(address->transport_name) + 1; | ||
77 | } | ||
78 | |||
79 | |||
80 | /** | ||
66 | * Copy an address struct. | 81 | * Copy an address struct. |
67 | * | 82 | * |
68 | * @param address address to copy | 83 | * @param address address to copy |
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index 886a41093..09f5f1c7d 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h | |||
@@ -111,6 +111,14 @@ GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, | |||
111 | const struct GNUNET_HELLO_Address *a2); | 111 | const struct GNUNET_HELLO_Address *a2); |
112 | 112 | ||
113 | 113 | ||
114 | /** | ||
115 | * Get the size of an address struct. | ||
116 | * | ||
117 | * @param address address | ||
118 | * @return the size | ||
119 | */ | ||
120 | size_t | ||
121 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address); | ||
114 | 122 | ||
115 | /** | 123 | /** |
116 | * Free an address. | 124 | * Free an address. |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 1de59d796..b0d9e34b0 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -104,8 +104,7 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, | |||
104 | * @param cls closure | 104 | * @param cls closure |
105 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | 105 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string |
106 | */ | 106 | */ |
107 | // RENAME: AddressToStringCallback | 107 | typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, |
108 | typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, | ||
109 | const char *address); | 108 | const char *address); |
110 | 109 | ||
111 | 110 | ||
@@ -119,16 +118,9 @@ typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, | |||
119 | * @param addrlen address length | 118 | * @param addrlen address length |
120 | */ | 119 | */ |
121 | // FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others) | 120 | // FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others) |
122 | // FIXME: rename: remove "Binary" | ||
123 | // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO) | 121 | // FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO) |
124 | typedef void (*GNUNET_TRANSPORT_AddressLookUpBinaryCallback) (void *cls, | 122 | typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls, |
125 | const struct | 123 | const struct GNUNET_HELLO_Address *address); |
126 | GNUNET_PeerIdentity | ||
127 | * peer, | ||
128 | const char | ||
129 | *transport, | ||
130 | const void *addr, | ||
131 | size_t addrlen); | ||
132 | 124 | ||
133 | 125 | ||
134 | /** | 126 | /** |
@@ -280,7 +272,7 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
280 | /** | 272 | /** |
281 | * Handle to cancel a pending address lookup. | 273 | * Handle to cancel a pending address lookup. |
282 | */ | 274 | */ |
283 | struct GNUNET_TRANSPORT_AddressLookupContext; | 275 | struct GNUNET_TRANSPORT_AddressToStringContext; |
284 | 276 | ||
285 | 277 | ||
286 | /** | 278 | /** |
@@ -297,14 +289,12 @@ struct GNUNET_TRANSPORT_AddressLookupContext; | |||
297 | * @param aluc_cls closure for aluc | 289 | * @param aluc_cls closure for aluc |
298 | * @return handle to cancel the operation, NULL on error | 290 | * @return handle to cancel the operation, NULL on error |
299 | */ | 291 | */ |
300 | // FIXME: use 'GNUNET_HELLO_Address' here! | 292 | struct GNUNET_TRANSPORT_AddressToStringContext * |
301 | // => rename: address_to_string | 293 | GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, |
302 | struct GNUNET_TRANSPORT_AddressLookupContext * | 294 | const struct GNUNET_HELLO_Address *address, |
303 | GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 295 | int numeric, |
304 | const char *address, size_t addressLen, | ||
305 | int numeric, const char *nameTrans, | ||
306 | struct GNUNET_TIME_Relative timeout, | 296 | struct GNUNET_TIME_Relative timeout, |
307 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, | 297 | GNUNET_TRANSPORT_AddressToStringCallback aluc, |
308 | void *aluc_cls); | 298 | void *aluc_cls); |
309 | 299 | ||
310 | 300 | ||
@@ -314,18 +304,12 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
314 | * @param alc handle for the request to cancel | 304 | * @param alc handle for the request to cancel |
315 | */ | 305 | */ |
316 | void | 306 | void |
317 | GNUNET_TRANSPORT_address_lookup_cancel (struct | 307 | GNUNET_TRANSPORT_address_to_string_cancel (struct |
318 | GNUNET_TRANSPORT_AddressLookupContext | 308 | GNUNET_TRANSPORT_AddressToStringContext |
319 | *alc); | 309 | *alc); |
320 | 310 | ||
321 | 311 | ||
322 | /** | 312 | /** |
323 | * Handle to cancel a pending address lookup. | ||
324 | */ | ||
325 | struct GNUNET_TRANSPORT_AddressLookupContext; | ||
326 | |||
327 | |||
328 | /** | ||
329 | * Return all the known addresses for a peer. FIXME: document better! | 313 | * Return all the known addresses for a peer. FIXME: document better! |
330 | * FIXME: use better name! | 314 | * FIXME: use better name! |
331 | * CHANGE: Returns the address(es) that we are currently using for this | 315 | * CHANGE: Returns the address(es) that we are currently using for this |
@@ -342,17 +326,12 @@ struct GNUNET_TRANSPORT_AddressLookupContext; | |||
342 | * @param peer_address_callback function to call with the results | 326 | * @param peer_address_callback function to call with the results |
343 | * @param peer_address_callback_cls closure for peer_address_callback | 327 | * @param peer_address_callback_cls closure for peer_address_callback |
344 | */ | 328 | */ |
345 | // RENAME: peer_get_active_addresses | ||
346 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 329 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * |
347 | GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | 330 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
348 | *cfg, | ||
349 | const struct GNUNET_PeerIdentity *peer, | 331 | const struct GNUNET_PeerIdentity *peer, |
350 | // FIXME: add argument: one_shot | 332 | // FIXME: add argument: one_shot |
351 | struct GNUNET_TIME_Relative timeout, | 333 | struct GNUNET_TIME_Relative timeout, |
352 | // FIXME: change to the 'Binary' lookup callback (which will | 334 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, |
353 | // be renamed, so the argument type actually won't change) | ||
354 | GNUNET_TRANSPORT_AddressLookUpCallback | ||
355 | peer_address_callback, | ||
356 | void *peer_address_callback_cls); | 335 | void *peer_address_callback_cls); |
357 | 336 | ||
358 | 337 | ||
@@ -362,9 +341,9 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | |||
362 | * @param alc handle for the request to cancel | 341 | * @param alc handle for the request to cancel |
363 | */ | 342 | */ |
364 | void | 343 | void |
365 | GNUNET_TRANSPORT_peer_address_lookup_cancel (struct | 344 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct |
366 | GNUNET_TRANSPORT_PeerAddressLookupContext | 345 | GNUNET_TRANSPORT_PeerAddressLookupContext |
367 | *alc); | 346 | *alc); |
368 | 347 | ||
369 | 348 | ||
370 | /** | 349 | /** |
@@ -381,7 +360,7 @@ GNUNET_TRANSPORT_peer_address_lookup_cancel (struct | |||
381 | void | 360 | void |
382 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 361 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
383 | struct GNUNET_TIME_Relative timeout, | 362 | struct GNUNET_TIME_Relative timeout, |
384 | GNUNET_TRANSPORT_AddressLookUpBinaryCallback | 363 | GNUNET_TRANSPORT_AddressLookUpCallback |
385 | peer_address_callback, | 364 | peer_address_callback, |
386 | void *peer_address_callback_cls); | 365 | void *peer_address_callback_cls); |
387 | 366 | ||
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index e40615a9b..d54eb1081 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c | |||
@@ -126,11 +126,9 @@ print_address (void *cls, | |||
126 | struct GNUNET_TIME_Absolute expiration) | 126 | struct GNUNET_TIME_Absolute expiration) |
127 | { | 127 | { |
128 | struct PrintContext *pc = cls; | 128 | struct PrintContext *pc = cls; |
129 | 129 | GNUNET_TRANSPORT_address_to_string (cfg, | |
130 | GNUNET_TRANSPORT_address_lookup (cfg, | 130 | address, |
131 | address->address, | 131 | no_resolve, |
132 | address->address_length, no_resolve, | ||
133 | address->transport_name, | ||
134 | GNUNET_TIME_relative_multiply | 132 | GNUNET_TIME_relative_multiply |
135 | (GNUNET_TIME_UNIT_SECONDS, 10), | 133 | (GNUNET_TIME_UNIT_SECONDS, 10), |
136 | &process_resolved_address, pc); | 134 | &process_resolved_address, pc); |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 4c9e8566c..1dc85a903 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -443,11 +443,15 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
443 | * @param addrlen number of bytes in addr | 443 | * @param addrlen number of bytes in addr |
444 | */ | 444 | */ |
445 | static void | 445 | static void |
446 | process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | 446 | process_address (void *cls, const struct GNUNET_HELLO_Address *address) |
447 | const char *transport, const void *addr, size_t addrlen) | ||
448 | { | 447 | { |
449 | if ((peer != NULL) || (transport != NULL) || | 448 | if ((address->transport_name != NULL) || |
450 | ((addr != NULL) && (addrlen > 0))) | 449 | ((address->address != NULL) && (address->address_length > 0))) |
450 | { | ||
451 | /* Call GNUNET_TRANSPORT_address_to_string to convert to human readable */ | ||
452 | //GNUNET_TRANSPORT_address_to_string(cfg, address, GNUNET_NO) | ||
453 | |||
454 | #if 0 | ||
451 | fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), | 455 | fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"), |
452 | (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", | 456 | (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", |
453 | (transport != NULL) ? transport : "<unknown>", ((addr != NULL) && | 457 | (transport != NULL) ? transport : "<unknown>", ((addr != NULL) && |
@@ -456,6 +460,8 @@ process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
456 | NULL)) ? | 460 | NULL)) ? |
457 | "how do i resolve the name without transport service?" : | 461 | "how do i resolve the name without transport service?" : |
458 | "<unknown>"); | 462 | "<unknown>"); |
463 | #endif | ||
464 | } | ||
459 | } | 465 | } |
460 | 466 | ||
461 | 467 | ||
diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c index 3c3f97c28..a79319163 100644 --- a/src/transport/transport_api_address_iterate.c +++ b/src/transport/transport_api_address_iterate.c | |||
@@ -47,7 +47,7 @@ struct AddressLookupCtx | |||
47 | /** | 47 | /** |
48 | * Function to call with the human-readable address. | 48 | * Function to call with the human-readable address. |
49 | */ | 49 | */ |
50 | GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb; | 50 | GNUNET_TRANSPORT_AddressLookUpCallback cb; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Closure for cb. | 53 | * Closure for cb. |
@@ -78,17 +78,13 @@ peer_address_response_processor (void *cls, | |||
78 | const struct GNUNET_MessageHeader *msg) | 78 | const struct GNUNET_MessageHeader *msg) |
79 | { | 79 | { |
80 | struct AddressLookupCtx *alucb = cls; | 80 | struct AddressLookupCtx *alucb = cls; |
81 | struct AddressIterateResponseMessage *address; | 81 | struct AddressIterateResponseMessage *arm; |
82 | struct GNUNET_HELLO_Address * address; | ||
82 | uint16_t size; | 83 | uint16_t size; |
83 | char *transport; | ||
84 | |||
85 | //size_t transport_len; | ||
86 | //void * addr; | ||
87 | size_t addrlen; | ||
88 | 84 | ||
89 | if (msg == NULL) | 85 | if (msg == NULL) |
90 | { | 86 | { |
91 | alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); | 87 | alucb->cb (alucb->cb_cls, NULL); |
92 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 88 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
93 | GNUNET_free (alucb); | 89 | GNUNET_free (alucb); |
94 | return; | 90 | return; |
@@ -102,7 +98,7 @@ peer_address_response_processor (void *cls, | |||
102 | if (size == sizeof (struct GNUNET_MessageHeader)) | 98 | if (size == sizeof (struct GNUNET_MessageHeader)) |
103 | { | 99 | { |
104 | /* done! */ | 100 | /* done! */ |
105 | alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); | 101 | alucb->cb (alucb->cb_cls, NULL); |
106 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 102 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
107 | GNUNET_free (alucb); | 103 | GNUNET_free (alucb); |
108 | return; | 104 | return; |
@@ -111,22 +107,19 @@ peer_address_response_processor (void *cls, | |||
111 | { | 107 | { |
112 | /* invalid reply */ | 108 | /* invalid reply */ |
113 | GNUNET_break (0); | 109 | GNUNET_break (0); |
114 | alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0); | 110 | alucb->cb (alucb->cb_cls, NULL); |
115 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 111 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
116 | GNUNET_free (alucb); | 112 | GNUNET_free (alucb); |
117 | return; | 113 | return; |
118 | } | 114 | } |
119 | 115 | ||
120 | address = (struct AddressIterateResponseMessage *) &msg[1]; | 116 | arm = (struct AddressIterateResponseMessage *) &msg[1]; |
121 | 117 | address = (struct GNUNET_HELLO_Address *) &arm[1]; | |
122 | transport = (char *) &address[0]; | ||
123 | //transport_len = ntohs(address->pluginlen); | ||
124 | addrlen = ntohs (address->addrlen); | ||
125 | 118 | ||
126 | /* expect more replies */ | 119 | /* expect more replies */ |
127 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | 120 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, |
128 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 121 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); |
129 | alucb->cb (alucb->cb_cls, &address->peer, transport, NULL, addrlen); | 122 | alucb->cb (alucb->cb_cls, address); |
130 | } | 123 | } |
131 | 124 | ||
132 | 125 | ||
@@ -141,7 +134,7 @@ peer_address_response_processor (void *cls, | |||
141 | void | 134 | void |
142 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 135 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
143 | struct GNUNET_TIME_Relative timeout, | 136 | struct GNUNET_TIME_Relative timeout, |
144 | GNUNET_TRANSPORT_AddressLookUpBinaryCallback | 137 | GNUNET_TRANSPORT_AddressLookUpCallback |
145 | peer_address_callback, | 138 | peer_address_callback, |
146 | void *peer_address_callback_cls) | 139 | void *peer_address_callback_cls) |
147 | { | 140 | { |
@@ -153,7 +146,7 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
153 | client = GNUNET_CLIENT_connect ("transport", cfg); | 146 | client = GNUNET_CLIENT_connect ("transport", cfg); |
154 | if (client == NULL) | 147 | if (client == NULL) |
155 | { | 148 | { |
156 | peer_address_callback (peer_address_callback_cls, NULL, NULL, NULL, 0); | 149 | peer_address_callback (peer_address_callback_cls, NULL); |
157 | return; | 150 | return; |
158 | } | 151 | } |
159 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 152 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 968a4324f..259c77152 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -30,12 +30,12 @@ | |||
30 | /** | 30 | /** |
31 | * Context for the address lookup. | 31 | * Context for the address lookup. |
32 | */ | 32 | */ |
33 | struct GNUNET_TRANSPORT_AddressLookupContext | 33 | struct GNUNET_TRANSPORT_AddressToStringContext |
34 | { | 34 | { |
35 | /** | 35 | /** |
36 | * Function to call with the human-readable address. | 36 | * Function to call with the human-readable address. |
37 | */ | 37 | */ |
38 | GNUNET_TRANSPORT_AddressLookUpCallback cb; | 38 | GNUNET_TRANSPORT_AddressToStringCallback cb; |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Closure for cb. | 41 | * Closure for cb. |
@@ -64,7 +64,7 @@ struct GNUNET_TRANSPORT_AddressLookupContext | |||
64 | static void | 64 | static void |
65 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | 65 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) |
66 | { | 66 | { |
67 | struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls; | 67 | struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; |
68 | const char *address; | 68 | const char *address; |
69 | uint16_t size; | 69 | uint16_t size; |
70 | 70 | ||
@@ -117,23 +117,23 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | |||
117 | * @param aluc_cls closure for aluc | 117 | * @param aluc_cls closure for aluc |
118 | * @return handle to cancel the operation, NULL on error | 118 | * @return handle to cancel the operation, NULL on error |
119 | */ | 119 | */ |
120 | struct GNUNET_TRANSPORT_AddressLookupContext * | 120 | struct GNUNET_TRANSPORT_AddressToStringContext * |
121 | GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 121 | GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, |
122 | const char *address, size_t addressLen, | 122 | const struct GNUNET_HELLO_Address *address, |
123 | int numeric, const char *nameTrans, | 123 | int numeric, |
124 | struct GNUNET_TIME_Relative timeout, | 124 | struct GNUNET_TIME_Relative timeout, |
125 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, | 125 | GNUNET_TRANSPORT_AddressToStringCallback aluc, |
126 | void *aluc_cls) | 126 | void *aluc_cls) |
127 | { | 127 | { |
128 | size_t slen; | ||
129 | size_t len; | 128 | size_t len; |
129 | size_t alen; | ||
130 | struct AddressLookupMessage *msg; | 130 | struct AddressLookupMessage *msg; |
131 | struct GNUNET_TRANSPORT_AddressLookupContext *alc; | 131 | struct GNUNET_TRANSPORT_AddressToStringContext *alc; |
132 | struct GNUNET_CLIENT_Connection *client; | 132 | struct GNUNET_CLIENT_Connection *client; |
133 | char *addrbuf; | 133 | char *addrbuf; |
134 | 134 | ||
135 | slen = strlen (nameTrans) + 1; | 135 | alen = GNUNET_HELLO_address_get_size (address); |
136 | len = sizeof (struct AddressLookupMessage) + addressLen + slen; | 136 | len = sizeof (struct AddressLookupMessage) + alen; |
137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
138 | { | 138 | { |
139 | GNUNET_break (0); | 139 | GNUNET_break (0); |
@@ -147,11 +147,10 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); | 147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); |
148 | msg->numeric_only = htonl (numeric); | 148 | msg->numeric_only = htonl (numeric); |
149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); | 149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); |
150 | msg->addrlen = htonl (addressLen); | 150 | msg->addrlen = htonl (alen); |
151 | addrbuf = (char *) &msg[1]; | 151 | addrbuf = (char *) &msg[1]; |
152 | memcpy (addrbuf, address, addressLen); | 152 | memcpy (addrbuf, address, alen); |
153 | memcpy (&addrbuf[addressLen], nameTrans, slen); | 153 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); |
154 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext)); | ||
155 | alc->cb = aluc; | 154 | alc->cb = aluc; |
156 | alc->cb_cls = aluc_cls; | 155 | alc->cb_cls = aluc_cls; |
157 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 156 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -172,8 +171,8 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
172 | * @param alc handle for the request to cancel | 171 | * @param alc handle for the request to cancel |
173 | */ | 172 | */ |
174 | void | 173 | void |
175 | GNUNET_TRANSPORT_address_lookup_cancel (struct | 174 | GNUNET_TRANSPORT_address_to_string_cancel (struct |
176 | GNUNET_TRANSPORT_AddressLookupContext | 175 | GNUNET_TRANSPORT_AddressToStringContext |
177 | *alc) | 176 | *alc) |
178 | { | 177 | { |
179 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); | 178 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); |
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c index 0df922085..66af497f5 100644 --- a/src/transport/transport_api_peer_address_lookup.c +++ b/src/transport/transport_api_peer_address_lookup.c | |||
@@ -78,7 +78,7 @@ peer_address_response_processor (void *cls, | |||
78 | const struct GNUNET_MessageHeader *msg) | 78 | const struct GNUNET_MessageHeader *msg) |
79 | { | 79 | { |
80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; | 80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; |
81 | const char *address; | 81 | const struct GNUNET_HELLO_Address *address; |
82 | uint16_t size; | 82 | uint16_t size; |
83 | 83 | ||
84 | if (msg == NULL) | 84 | if (msg == NULL) |
@@ -94,25 +94,29 @@ peer_address_response_processor (void *cls, | |||
94 | if (size == sizeof (struct GNUNET_MessageHeader)) | 94 | if (size == sizeof (struct GNUNET_MessageHeader)) |
95 | { | 95 | { |
96 | /* done! */ | 96 | /* done! */ |
97 | alucb->cb (alucb->cb_cls, NULL); | 97 | alucb->cb (alucb->cb_cls, NULL ); |
98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
99 | GNUNET_free (alucb); | 99 | GNUNET_free (alucb); |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | address = (const char *) &msg[1]; | 102 | address = (const struct GNUNET_HELLO_Address *) &msg[1]; |
103 | #if 0 | ||
103 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 104 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') |
104 | { | 105 | { |
105 | /* invalid reply */ | 106 | /* invalid reply */ |
106 | GNUNET_break (0); | 107 | GNUNET_break (0); |
107 | alucb->cb (alucb->cb_cls, NULL); | 108 | alucb->cb (alucb->cb_cls, NULL ); |
108 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 109 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
109 | GNUNET_free (alucb); | 110 | GNUNET_free (alucb); |
110 | return; | 111 | return; |
111 | } | 112 | } |
113 | #endif | ||
112 | /* expect more replies */ | 114 | /* expect more replies */ |
113 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | 115 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, |
114 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 116 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); |
115 | alucb->cb (alucb->cb_cls, address); | 117 | |
118 | /* REFACTOR FIX THIS */ | ||
119 | alucb->cb (alucb->cb_cls, address ); | ||
116 | } | 120 | } |
117 | 121 | ||
118 | 122 | ||
@@ -127,12 +131,10 @@ peer_address_response_processor (void *cls, | |||
127 | * @return handle to cancel the operation, NULL on error | 131 | * @return handle to cancel the operation, NULL on error |
128 | */ | 132 | */ |
129 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 133 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * |
130 | GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | 134 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
131 | *cfg, | ||
132 | const struct GNUNET_PeerIdentity *peer, | 135 | const struct GNUNET_PeerIdentity *peer, |
133 | struct GNUNET_TIME_Relative timeout, | 136 | struct GNUNET_TIME_Relative timeout, |
134 | GNUNET_TRANSPORT_AddressLookUpCallback | 137 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, |
135 | peer_address_callback, | ||
136 | void *peer_address_callback_cls) | 138 | void *peer_address_callback_cls) |
137 | { | 139 | { |
138 | struct PeerAddressLookupMessage msg; | 140 | struct PeerAddressLookupMessage msg; |
@@ -147,8 +149,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | |||
147 | msg.reserved = htonl (0); | 149 | msg.reserved = htonl (0); |
148 | msg.timeout = GNUNET_TIME_relative_hton (timeout); | 150 | msg.timeout = GNUNET_TIME_relative_hton (timeout); |
149 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 151 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
150 | alc = | 152 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); |
151 | GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | ||
152 | alc->cb = peer_address_callback; | 153 | alc->cb = peer_address_callback; |
153 | alc->cb_cls = peer_address_callback_cls; | 154 | alc->cb_cls = peer_address_callback_cls; |
154 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 155 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
@@ -168,7 +169,7 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle | |||
168 | * @param alc handle for the request to cancel | 169 | * @param alc handle for the request to cancel |
169 | */ | 170 | */ |
170 | void | 171 | void |
171 | GNUNET_TRANSPORT_peer_address_lookup_cancel (struct | 172 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct |
172 | GNUNET_TRANSPORT_PeerAddressLookupContext | 173 | GNUNET_TRANSPORT_PeerAddressLookupContext |
173 | *alc) | 174 | *alc) |
174 | { | 175 | { |