diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 09:52:10 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-29 09:52:10 +0000 |
commit | ba232c9d203303cd2beb2994fc49c5d5b700d85c (patch) | |
tree | 9cfb172b64e2870aa244fc9a3eb546486a887342 /src | |
parent | 623df97886da9ee06724b7860a1a2463737b750e (diff) | |
download | gnunet-ba232c9d203303cd2beb2994fc49c5d5b700d85c.tar.gz gnunet-ba232c9d203303cd2beb2994fc49c5d5b700d85c.zip |
api clean up next steps
Diffstat (limited to 'src')
-rw-r--r-- | src/core/gnunet-core-list-connections.c | 8 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 5 | ||||
-rw-r--r-- | src/transport/Makefile.am | 5 | ||||
-rw-r--r-- | src/transport/transport_api_address_iterate.c | 169 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 209 | ||||
-rw-r--r-- | src/transport/transport_api_address_to_string.c (renamed from src/transport/transport_api_peer_address_lookup.c) | 111 |
6 files changed, 220 insertions, 287 deletions
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c index 3f3288d79..8f00c0a18 100644 --- a/src/core/gnunet-core-list-connections.c +++ b/src/core/gnunet-core-list-connections.c | |||
@@ -137,8 +137,12 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
137 | #endif | 137 | #endif |
138 | pc = GNUNET_malloc (sizeof (struct PrintContext)); | 138 | pc = GNUNET_malloc (sizeof (struct PrintContext)); |
139 | pc->peer = *peer; | 139 | pc->peer = *peer; |
140 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, peer, GNUNET_TIME_UNIT_MINUTES, | 140 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, |
141 | &process_resolved_address, pc); | 141 | peer, |
142 | GNUNET_YES, | ||
143 | GNUNET_TIME_UNIT_MINUTES, | ||
144 | &process_resolved_address, | ||
145 | pc); | ||
142 | } | 146 | } |
143 | #if VERBOSE | 147 | #if VERBOSE |
144 | else | 148 | else |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index b0d9e34b0..7e7fc7fa6 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -310,8 +310,7 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct | |||
310 | 310 | ||
311 | 311 | ||
312 | /** | 312 | /** |
313 | * Return all the known addresses for a peer. FIXME: document better! | 313 | * Return all the known addresses for a peer. |
314 | * FIXME: use better name! | ||
315 | * CHANGE: Returns the address(es) that we are currently using for this | 314 | * CHANGE: Returns the address(es) that we are currently using for this |
316 | * peer. Upon completion, the 'AddressLookUpCallback' is called one more | 315 | * peer. Upon completion, the 'AddressLookUpCallback' is called one more |
317 | * time with 'NULL' for the address and the peer. After this, the operation must no | 316 | * time with 'NULL' for the address and the peer. After this, the operation must no |
@@ -329,7 +328,7 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct | |||
329 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 328 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * |
330 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, | 329 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
331 | const struct GNUNET_PeerIdentity *peer, | 330 | const struct GNUNET_PeerIdentity *peer, |
332 | // FIXME: add argument: one_shot | 331 | int one_shot, |
333 | struct GNUNET_TIME_Relative timeout, | 332 | struct GNUNET_TIME_Relative timeout, |
334 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, | 333 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, |
335 | void *peer_address_callback_cls); | 334 | void *peer_address_callback_cls); |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index b836812ff..72a319b44 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -83,9 +83,8 @@ libgnunettransporttesting_la_LDFLAGS = \ | |||
83 | libgnunettransport_la_SOURCES = \ | 83 | libgnunettransport_la_SOURCES = \ |
84 | transport_api.c transport.h \ | 84 | transport_api.c transport.h \ |
85 | transport_api_blacklist.c \ | 85 | transport_api_blacklist.c \ |
86 | transport_api_address_lookup.c \ | 86 | transport_api_address_to_string.c \ |
87 | transport_api_peer_address_lookup.c \ | 87 | transport_api_address_lookup.c |
88 | transport_api_address_iterate.c | ||
89 | libgnunettransport_la_LIBADD = \ | 88 | libgnunettransport_la_LIBADD = \ |
90 | $(top_builddir)/src/hello/libgnunethello.la \ | 89 | $(top_builddir)/src/hello/libgnunethello.la \ |
91 | $(top_builddir)/src/util/libgnunetutil.la \ | 90 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c deleted file mode 100644 index a79319163..000000000 --- a/src/transport/transport_api_address_iterate.c +++ /dev/null | |||
@@ -1,169 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/transport_api_address_iterate.c | ||
23 | * @brief api for asking transport service to iterate over all | ||
24 | * known addresses | ||
25 | * | ||
26 | * This api provides a single function call to ask the transport | ||
27 | * service to list all peers and their known addresses, as pretty | ||
28 | * printed by the appropriate plugin. Reports whether or not the | ||
29 | * address is connected as well. | ||
30 | */ | ||
31 | |||
32 | #include "platform.h" | ||
33 | #include "gnunet_client_lib.h" | ||
34 | #include "gnunet_arm_service.h" | ||
35 | #include "gnunet_hello_lib.h" | ||
36 | #include "gnunet_protocols.h" | ||
37 | #include "gnunet_server_lib.h" | ||
38 | #include "gnunet_time_lib.h" | ||
39 | #include "gnunet_transport_service.h" | ||
40 | #include "transport.h" | ||
41 | |||
42 | /** | ||
43 | * Context for the address lookup. | ||
44 | */ | ||
45 | struct AddressLookupCtx | ||
46 | { | ||
47 | /** | ||
48 | * Function to call with the human-readable address. | ||
49 | */ | ||
50 | GNUNET_TRANSPORT_AddressLookUpCallback cb; | ||
51 | |||
52 | /** | ||
53 | * Closure for cb. | ||
54 | */ | ||
55 | void *cb_cls; | ||
56 | |||
57 | /** | ||
58 | * Connection to the service. | ||
59 | */ | ||
60 | struct GNUNET_CLIENT_Connection *client; | ||
61 | |||
62 | /** | ||
63 | * When should this operation time out? | ||
64 | */ | ||
65 | struct GNUNET_TIME_Absolute timeout; | ||
66 | }; | ||
67 | |||
68 | |||
69 | /** | ||
70 | * Function called with responses from the service. | ||
71 | * | ||
72 | * @param cls our 'struct AddressLookupCtx*' | ||
73 | * @param msg NULL on timeout or error, otherwise presumably a | ||
74 | * message with the human-readable peer and address | ||
75 | */ | ||
76 | static void | ||
77 | peer_address_response_processor (void *cls, | ||
78 | const struct GNUNET_MessageHeader *msg) | ||
79 | { | ||
80 | struct AddressLookupCtx *alucb = cls; | ||
81 | struct AddressIterateResponseMessage *arm; | ||
82 | struct GNUNET_HELLO_Address * address; | ||
83 | uint16_t size; | ||
84 | |||
85 | if (msg == NULL) | ||
86 | { | ||
87 | alucb->cb (alucb->cb_cls, NULL); | ||
88 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
89 | GNUNET_free (alucb); | ||
90 | return; | ||
91 | } | ||
92 | |||
93 | GNUNET_break (ntohs (msg->type) == | ||
94 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
95 | size = ntohs (msg->size); | ||
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u\n", | ||
97 | ntohs (msg->type), size); | ||
98 | if (size == sizeof (struct GNUNET_MessageHeader)) | ||
99 | { | ||
100 | /* done! */ | ||
101 | alucb->cb (alucb->cb_cls, NULL); | ||
102 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
103 | GNUNET_free (alucb); | ||
104 | return; | ||
105 | } | ||
106 | if (size < sizeof (struct AddressIterateResponseMessage)) | ||
107 | { | ||
108 | /* invalid reply */ | ||
109 | GNUNET_break (0); | ||
110 | alucb->cb (alucb->cb_cls, NULL); | ||
111 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
112 | GNUNET_free (alucb); | ||
113 | return; | ||
114 | } | ||
115 | |||
116 | arm = (struct AddressIterateResponseMessage *) &msg[1]; | ||
117 | address = (struct GNUNET_HELLO_Address *) &arm[1]; | ||
118 | |||
119 | /* expect more replies */ | ||
120 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | ||
121 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | ||
122 | alucb->cb (alucb->cb_cls, address); | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Return all the known addresses for a peer. | ||
128 | * | ||
129 | * @param cfg configuration to use | ||
130 | * @param timeout how long is the lookup allowed to take at most | ||
131 | * @param peer_address_callback function to call with the results | ||
132 | * @param peer_address_callback_cls closure for peer_address_callback | ||
133 | */ | ||
134 | void | ||
135 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
136 | struct GNUNET_TIME_Relative timeout, | ||
137 | GNUNET_TRANSPORT_AddressLookUpCallback | ||
138 | peer_address_callback, | ||
139 | void *peer_address_callback_cls) | ||
140 | { | ||
141 | struct AddressIterateMessage msg; | ||
142 | struct GNUNET_TIME_Absolute abs_timeout; | ||
143 | struct AddressLookupCtx *peer_address_lookup_cb; | ||
144 | struct GNUNET_CLIENT_Connection *client; | ||
145 | |||
146 | client = GNUNET_CLIENT_connect ("transport", cfg); | ||
147 | if (client == NULL) | ||
148 | { | ||
149 | peer_address_callback (peer_address_callback_cls, NULL); | ||
150 | return; | ||
151 | } | ||
152 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
153 | |||
154 | msg.header.size = htons (sizeof (struct AddressIterateMessage)); | ||
155 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); | ||
156 | msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); | ||
157 | peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx)); | ||
158 | peer_address_lookup_cb->cb = peer_address_callback; | ||
159 | peer_address_lookup_cb->cb_cls = peer_address_callback_cls; | ||
160 | peer_address_lookup_cb->timeout = abs_timeout; | ||
161 | peer_address_lookup_cb->client = client; | ||
162 | GNUNET_assert (GNUNET_OK == | ||
163 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, | ||
164 | timeout, GNUNET_YES, | ||
165 | &peer_address_response_processor, | ||
166 | peer_address_lookup_cb)); | ||
167 | } | ||
168 | |||
169 | /* end of transport_api_address_iterate.c */ | ||
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 259c77152..385abd423 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -17,6 +17,18 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | ||
22 | * @file transport/transport_api_peer_address_lookup.c | ||
23 | * @brief given a peer id, get all known addresses from transport service | ||
24 | * | ||
25 | * This api provides the ability to query the transport service about | ||
26 | * the status of connections to a specific peer. Calls back with a | ||
27 | * pretty printed string of the address, as formatted by the appropriate | ||
28 | * transport plugin, and whether or not the address given is currently | ||
29 | * in the 'connected' state (according to the transport service). | ||
30 | */ | ||
31 | |||
20 | #include "platform.h" | 32 | #include "platform.h" |
21 | #include "gnunet_client_lib.h" | 33 | #include "gnunet_client_lib.h" |
22 | #include "gnunet_arm_service.h" | 34 | #include "gnunet_arm_service.h" |
@@ -30,12 +42,12 @@ | |||
30 | /** | 42 | /** |
31 | * Context for the address lookup. | 43 | * Context for the address lookup. |
32 | */ | 44 | */ |
33 | struct GNUNET_TRANSPORT_AddressToStringContext | 45 | struct GNUNET_TRANSPORT_PeerAddressLookupContext |
34 | { | 46 | { |
35 | /** | 47 | /** |
36 | * Function to call with the human-readable address. | 48 | * Function to call with the human-readable address. |
37 | */ | 49 | */ |
38 | GNUNET_TRANSPORT_AddressToStringCallback cb; | 50 | GNUNET_TRANSPORT_AddressLookUpCallback cb; |
39 | 51 | ||
40 | /** | 52 | /** |
41 | * Closure for cb. | 53 | * Closure for cb. |
@@ -57,15 +69,16 @@ struct GNUNET_TRANSPORT_AddressToStringContext | |||
57 | /** | 69 | /** |
58 | * Function called with responses from the service. | 70 | * Function called with responses from the service. |
59 | * | 71 | * |
60 | * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*' | 72 | * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*' |
61 | * @param msg NULL on timeout or error, otherwise presumably a | 73 | * @param msg NULL on timeout or error, otherwise presumably a |
62 | * message with the human-readable address | 74 | * message with the human-readable address |
63 | */ | 75 | */ |
64 | static void | 76 | static void |
65 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | 77 | peer_address_response_processor (void *cls, |
78 | const struct GNUNET_MessageHeader *msg) | ||
66 | { | 79 | { |
67 | struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; | 80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; |
68 | const char *address; | 81 | const struct GNUNET_HELLO_Address *address; |
69 | uint16_t size; | 82 | uint16_t size; |
70 | 83 | ||
71 | if (msg == NULL) | 84 | if (msg == NULL) |
@@ -81,86 +94,72 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) | |||
81 | if (size == sizeof (struct GNUNET_MessageHeader)) | 94 | if (size == sizeof (struct GNUNET_MessageHeader)) |
82 | { | 95 | { |
83 | /* done! */ | 96 | /* done! */ |
84 | alucb->cb (alucb->cb_cls, NULL); | 97 | alucb->cb (alucb->cb_cls, NULL ); |
85 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
86 | GNUNET_free (alucb); | 99 | GNUNET_free (alucb); |
87 | return; | 100 | return; |
88 | } | 101 | } |
89 | address = (const char *) &msg[1]; | 102 | address = (const struct GNUNET_HELLO_Address *) &msg[1]; |
103 | #if 0 | ||
90 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 104 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') |
91 | { | 105 | { |
92 | /* invalid reply */ | 106 | /* invalid reply */ |
93 | GNUNET_break (0); | 107 | GNUNET_break (0); |
94 | alucb->cb (alucb->cb_cls, NULL); | 108 | alucb->cb (alucb->cb_cls, NULL ); |
95 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 109 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
96 | GNUNET_free (alucb); | 110 | GNUNET_free (alucb); |
97 | return; | 111 | return; |
98 | } | 112 | } |
113 | #endif | ||
99 | /* expect more replies */ | 114 | /* expect more replies */ |
100 | GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, | 115 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, |
101 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 116 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); |
102 | alucb->cb (alucb->cb_cls, address); | 117 | |
118 | /* REFACTOR FIX THIS */ | ||
119 | alucb->cb (alucb->cb_cls, address ); | ||
103 | } | 120 | } |
104 | 121 | ||
105 | 122 | ||
106 | /** | 123 | /** |
107 | * Convert a binary address into a human readable address. | 124 | * Return all the known addresses for a peer. |
108 | * | 125 | * |
109 | * @param cfg configuration to use | 126 | * @param cfg configuration to use |
110 | * @param address address to convert (binary format) | 127 | * @param peer peer identity to look up the addresses of |
111 | * @param addressLen number of bytes in address | ||
112 | * @param numeric should (IP) addresses be displayed in numeric form | ||
113 | * (otherwise do reverse DNS lookup) | ||
114 | * @param nameTrans name of the transport to which the address belongs | ||
115 | * @param timeout how long is the lookup allowed to take at most | 128 | * @param timeout how long is the lookup allowed to take at most |
116 | * @param aluc function to call with the results | 129 | * @param peer_address_callback function to call with the results |
117 | * @param aluc_cls closure for aluc | 130 | * @param peer_address_callback_cls closure for peer_address_callback |
118 | * @return handle to cancel the operation, NULL on error | 131 | * @return handle to cancel the operation, NULL on error |
119 | */ | 132 | */ |
120 | struct GNUNET_TRANSPORT_AddressToStringContext * | 133 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * |
121 | GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, | 134 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, |
122 | const struct GNUNET_HELLO_Address *address, | 135 | const struct GNUNET_PeerIdentity *peer, |
123 | int numeric, | 136 | int one_shot, |
124 | struct GNUNET_TIME_Relative timeout, | 137 | struct GNUNET_TIME_Relative timeout, |
125 | GNUNET_TRANSPORT_AddressToStringCallback aluc, | 138 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, |
126 | void *aluc_cls) | 139 | void *peer_address_callback_cls) |
127 | { | 140 | { |
128 | size_t len; | 141 | struct PeerAddressLookupMessage msg; |
129 | size_t alen; | 142 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc; |
130 | struct AddressLookupMessage *msg; | ||
131 | struct GNUNET_TRANSPORT_AddressToStringContext *alc; | ||
132 | struct GNUNET_CLIENT_Connection *client; | 143 | struct GNUNET_CLIENT_Connection *client; |
133 | char *addrbuf; | ||
134 | 144 | ||
135 | alen = GNUNET_HELLO_address_get_size (address); | ||
136 | len = sizeof (struct AddressLookupMessage) + alen; | ||
137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
138 | { | ||
139 | GNUNET_break (0); | ||
140 | return NULL; | ||
141 | } | ||
142 | client = GNUNET_CLIENT_connect ("transport", cfg); | 145 | client = GNUNET_CLIENT_connect ("transport", cfg); |
143 | if (client == NULL) | 146 | if (client == NULL) |
144 | return NULL; | 147 | return NULL; |
145 | msg = GNUNET_malloc (len); | 148 | msg.header.size = htons (sizeof (struct PeerAddressLookupMessage)); |
146 | msg->header.size = htons (len); | 149 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP); |
147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); | 150 | msg.reserved = htonl (0); |
148 | msg->numeric_only = htonl (numeric); | 151 | msg.timeout = GNUNET_TIME_relative_hton (timeout); |
149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); | 152 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
150 | msg->addrlen = htonl (alen); | 153 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); |
151 | addrbuf = (char *) &msg[1]; | 154 | alc->cb = peer_address_callback; |
152 | memcpy (addrbuf, address, alen); | 155 | alc->cb_cls = peer_address_callback_cls; |
153 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); | ||
154 | alc->cb = aluc; | ||
155 | alc->cb_cls = aluc_cls; | ||
156 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 156 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
157 | alc->client = client; | 157 | alc->client = client; |
158 | GNUNET_assert (GNUNET_OK == | 158 | GNUNET_assert (GNUNET_OK == |
159 | GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, | 159 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, |
160 | timeout, GNUNET_YES, | 160 | timeout, GNUNET_YES, |
161 | &address_response_processor, | 161 | &peer_address_response_processor, |
162 | alc)); | 162 | alc)); |
163 | GNUNET_free (msg); | ||
164 | return alc; | 163 | return alc; |
165 | } | 164 | } |
166 | 165 | ||
@@ -171,14 +170,112 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf | |||
171 | * @param alc handle for the request to cancel | 170 | * @param alc handle for the request to cancel |
172 | */ | 171 | */ |
173 | void | 172 | void |
174 | GNUNET_TRANSPORT_address_to_string_cancel (struct | 173 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct |
175 | GNUNET_TRANSPORT_AddressToStringContext | 174 | GNUNET_TRANSPORT_PeerAddressLookupContext |
176 | *alc) | 175 | *alc) |
177 | { | 176 | { |
178 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); | 177 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); |
179 | GNUNET_free (alc); | 178 | GNUNET_free (alc); |
180 | } | 179 | } |
181 | 180 | ||
181 | /** | ||
182 | * Function called with responses from the service. | ||
183 | * | ||
184 | * @param cls our 'struct AddressLookupCtx*' | ||
185 | * @param msg NULL on timeout or error, otherwise presumably a | ||
186 | * message with the human-readable peer and address | ||
187 | */ | ||
188 | static void | ||
189 | peer_address_iteration_response_processor (void *cls, | ||
190 | const struct GNUNET_MessageHeader *msg) | ||
191 | { | ||
192 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; | ||
193 | struct AddressIterateResponseMessage *arm; | ||
194 | struct GNUNET_HELLO_Address * address; | ||
195 | uint16_t size; | ||
196 | |||
197 | if (msg == NULL) | ||
198 | { | ||
199 | alucb->cb (alucb->cb_cls, NULL); | ||
200 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
201 | GNUNET_free (alucb); | ||
202 | return; | ||
203 | } | ||
204 | |||
205 | GNUNET_break (ntohs (msg->type) == | ||
206 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
207 | size = ntohs (msg->size); | ||
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u\n", | ||
209 | ntohs (msg->type), size); | ||
210 | if (size == sizeof (struct GNUNET_MessageHeader)) | ||
211 | { | ||
212 | /* done! */ | ||
213 | alucb->cb (alucb->cb_cls, NULL); | ||
214 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
215 | GNUNET_free (alucb); | ||
216 | return; | ||
217 | } | ||
218 | if (size < sizeof (struct AddressIterateResponseMessage)) | ||
219 | { | ||
220 | /* invalid reply */ | ||
221 | GNUNET_break (0); | ||
222 | alucb->cb (alucb->cb_cls, NULL); | ||
223 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | ||
224 | GNUNET_free (alucb); | ||
225 | return; | ||
226 | } | ||
227 | |||
228 | arm = (struct AddressIterateResponseMessage *) &msg[1]; | ||
229 | address = (struct GNUNET_HELLO_Address *) &arm[1]; | ||
230 | |||
231 | /* expect more replies */ | ||
232 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | ||
233 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | ||
234 | alucb->cb (alucb->cb_cls, address); | ||
235 | } | ||
236 | |||
182 | 237 | ||
238 | /** | ||
239 | * Return all the known addresses for a peer. | ||
240 | * | ||
241 | * @param cfg configuration to use | ||
242 | * @param timeout how long is the lookup allowed to take at most | ||
243 | * @param peer_address_callback function to call with the results | ||
244 | * @param peer_address_callback_cls closure for peer_address_callback | ||
245 | */ | ||
246 | void | ||
247 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
248 | struct GNUNET_TIME_Relative timeout, | ||
249 | GNUNET_TRANSPORT_AddressLookUpCallback | ||
250 | peer_address_callback, | ||
251 | void *peer_address_callback_cls) | ||
252 | { | ||
253 | struct AddressIterateMessage msg; | ||
254 | struct GNUNET_TIME_Absolute abs_timeout; | ||
255 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *peer_address_lookup_cb; | ||
256 | struct GNUNET_CLIENT_Connection *client; | ||
257 | |||
258 | client = GNUNET_CLIENT_connect ("transport", cfg); | ||
259 | if (client == NULL) | ||
260 | { | ||
261 | peer_address_callback (peer_address_callback_cls, NULL); | ||
262 | return; | ||
263 | } | ||
264 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
265 | |||
266 | msg.header.size = htons (sizeof (struct AddressIterateMessage)); | ||
267 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); | ||
268 | msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); | ||
269 | peer_address_lookup_cb = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | ||
270 | peer_address_lookup_cb->cb = peer_address_callback; | ||
271 | peer_address_lookup_cb->cb_cls = peer_address_callback_cls; | ||
272 | peer_address_lookup_cb->timeout = abs_timeout; | ||
273 | peer_address_lookup_cb->client = client; | ||
274 | GNUNET_assert (GNUNET_OK == | ||
275 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, | ||
276 | timeout, GNUNET_YES, | ||
277 | &peer_address_iteration_response_processor, | ||
278 | peer_address_lookup_cb)); | ||
279 | } | ||
183 | 280 | ||
184 | /* end of transport_api_address_lookup.c */ | 281 | /* end of transport_api_peer_address_lookup.c */ |
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_address_to_string.c index 66af497f5..259c77152 100644 --- a/src/transport/transport_api_peer_address_lookup.c +++ b/src/transport/transport_api_address_to_string.c | |||
@@ -17,18 +17,6 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | |||
21 | /** | ||
22 | * @file transport/transport_api_peer_address_lookup.c | ||
23 | * @brief given a peer id, get all known addresses from transport service | ||
24 | * | ||
25 | * This api provides the ability to query the transport service about | ||
26 | * the status of connections to a specific peer. Calls back with a | ||
27 | * pretty printed string of the address, as formatted by the appropriate | ||
28 | * transport plugin, and whether or not the address given is currently | ||
29 | * in the 'connected' state (according to the transport service). | ||
30 | */ | ||
31 | |||
32 | #include "platform.h" | 20 | #include "platform.h" |
33 | #include "gnunet_client_lib.h" | 21 | #include "gnunet_client_lib.h" |
34 | #include "gnunet_arm_service.h" | 22 | #include "gnunet_arm_service.h" |
@@ -42,12 +30,12 @@ | |||
42 | /** | 30 | /** |
43 | * Context for the address lookup. | 31 | * Context for the address lookup. |
44 | */ | 32 | */ |
45 | struct GNUNET_TRANSPORT_PeerAddressLookupContext | 33 | struct GNUNET_TRANSPORT_AddressToStringContext |
46 | { | 34 | { |
47 | /** | 35 | /** |
48 | * Function to call with the human-readable address. | 36 | * Function to call with the human-readable address. |
49 | */ | 37 | */ |
50 | GNUNET_TRANSPORT_AddressLookUpCallback cb; | 38 | GNUNET_TRANSPORT_AddressToStringCallback cb; |
51 | 39 | ||
52 | /** | 40 | /** |
53 | * Closure for cb. | 41 | * Closure for cb. |
@@ -69,16 +57,15 @@ struct GNUNET_TRANSPORT_PeerAddressLookupContext | |||
69 | /** | 57 | /** |
70 | * Function called with responses from the service. | 58 | * Function called with responses from the service. |
71 | * | 59 | * |
72 | * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*' | 60 | * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*' |
73 | * @param msg NULL on timeout or error, otherwise presumably a | 61 | * @param msg NULL on timeout or error, otherwise presumably a |
74 | * message with the human-readable address | 62 | * message with the human-readable address |
75 | */ | 63 | */ |
76 | static void | 64 | static void |
77 | peer_address_response_processor (void *cls, | 65 | address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) |
78 | const struct GNUNET_MessageHeader *msg) | ||
79 | { | 66 | { |
80 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls; | 67 | struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; |
81 | const struct GNUNET_HELLO_Address *address; | 68 | const char *address; |
82 | uint16_t size; | 69 | uint16_t size; |
83 | 70 | ||
84 | if (msg == NULL) | 71 | if (msg == NULL) |
@@ -94,71 +81,86 @@ peer_address_response_processor (void *cls, | |||
94 | if (size == sizeof (struct GNUNET_MessageHeader)) | 81 | if (size == sizeof (struct GNUNET_MessageHeader)) |
95 | { | 82 | { |
96 | /* done! */ | 83 | /* done! */ |
97 | alucb->cb (alucb->cb_cls, NULL ); | 84 | alucb->cb (alucb->cb_cls, NULL); |
98 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 85 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
99 | GNUNET_free (alucb); | 86 | GNUNET_free (alucb); |
100 | return; | 87 | return; |
101 | } | 88 | } |
102 | address = (const struct GNUNET_HELLO_Address *) &msg[1]; | 89 | address = (const char *) &msg[1]; |
103 | #if 0 | ||
104 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') | 90 | if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') |
105 | { | 91 | { |
106 | /* invalid reply */ | 92 | /* invalid reply */ |
107 | GNUNET_break (0); | 93 | GNUNET_break (0); |
108 | alucb->cb (alucb->cb_cls, NULL ); | 94 | alucb->cb (alucb->cb_cls, NULL); |
109 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); | 95 | GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); |
110 | GNUNET_free (alucb); | 96 | GNUNET_free (alucb); |
111 | return; | 97 | return; |
112 | } | 98 | } |
113 | #endif | ||
114 | /* expect more replies */ | 99 | /* expect more replies */ |
115 | GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb, | 100 | GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb, |
116 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); | 101 | GNUNET_TIME_absolute_get_remaining (alucb->timeout)); |
117 | 102 | alucb->cb (alucb->cb_cls, address); | |
118 | /* REFACTOR FIX THIS */ | ||
119 | alucb->cb (alucb->cb_cls, address ); | ||
120 | } | 103 | } |
121 | 104 | ||
122 | 105 | ||
123 | /** | 106 | /** |
124 | * Return all the known addresses for a peer. | 107 | * Convert a binary address into a human readable address. |
125 | * | 108 | * |
126 | * @param cfg configuration to use | 109 | * @param cfg configuration to use |
127 | * @param peer peer identity to look up the addresses of | 110 | * @param address address to convert (binary format) |
111 | * @param addressLen number of bytes in address | ||
112 | * @param numeric should (IP) addresses be displayed in numeric form | ||
113 | * (otherwise do reverse DNS lookup) | ||
114 | * @param nameTrans name of the transport to which the address belongs | ||
128 | * @param timeout how long is the lookup allowed to take at most | 115 | * @param timeout how long is the lookup allowed to take at most |
129 | * @param peer_address_callback function to call with the results | 116 | * @param aluc function to call with the results |
130 | * @param peer_address_callback_cls closure for peer_address_callback | 117 | * @param aluc_cls closure for aluc |
131 | * @return handle to cancel the operation, NULL on error | 118 | * @return handle to cancel the operation, NULL on error |
132 | */ | 119 | */ |
133 | struct GNUNET_TRANSPORT_PeerAddressLookupContext * | 120 | struct GNUNET_TRANSPORT_AddressToStringContext * |
134 | GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg, | 121 | GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, |
135 | const struct GNUNET_PeerIdentity *peer, | 122 | const struct GNUNET_HELLO_Address *address, |
136 | struct GNUNET_TIME_Relative timeout, | 123 | int numeric, |
137 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, | 124 | struct GNUNET_TIME_Relative timeout, |
138 | void *peer_address_callback_cls) | 125 | GNUNET_TRANSPORT_AddressToStringCallback aluc, |
126 | void *aluc_cls) | ||
139 | { | 127 | { |
140 | struct PeerAddressLookupMessage msg; | 128 | size_t len; |
141 | struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc; | 129 | size_t alen; |
130 | struct AddressLookupMessage *msg; | ||
131 | struct GNUNET_TRANSPORT_AddressToStringContext *alc; | ||
142 | struct GNUNET_CLIENT_Connection *client; | 132 | struct GNUNET_CLIENT_Connection *client; |
133 | char *addrbuf; | ||
143 | 134 | ||
135 | alen = GNUNET_HELLO_address_get_size (address); | ||
136 | len = sizeof (struct AddressLookupMessage) + alen; | ||
137 | if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
138 | { | ||
139 | GNUNET_break (0); | ||
140 | return NULL; | ||
141 | } | ||
144 | client = GNUNET_CLIENT_connect ("transport", cfg); | 142 | client = GNUNET_CLIENT_connect ("transport", cfg); |
145 | if (client == NULL) | 143 | if (client == NULL) |
146 | return NULL; | 144 | return NULL; |
147 | msg.header.size = htons (sizeof (struct PeerAddressLookupMessage)); | 145 | msg = GNUNET_malloc (len); |
148 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP); | 146 | msg->header.size = htons (len); |
149 | msg.reserved = htonl (0); | 147 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); |
150 | msg.timeout = GNUNET_TIME_relative_hton (timeout); | 148 | msg->numeric_only = htonl (numeric); |
151 | memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 149 | msg->timeout = GNUNET_TIME_relative_hton (timeout); |
152 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext)); | 150 | msg->addrlen = htonl (alen); |
153 | alc->cb = peer_address_callback; | 151 | addrbuf = (char *) &msg[1]; |
154 | alc->cb_cls = peer_address_callback_cls; | 152 | memcpy (addrbuf, address, alen); |
153 | alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext)); | ||
154 | alc->cb = aluc; | ||
155 | alc->cb_cls = aluc_cls; | ||
155 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 156 | alc->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
156 | alc->client = client; | 157 | alc->client = client; |
157 | GNUNET_assert (GNUNET_OK == | 158 | GNUNET_assert (GNUNET_OK == |
158 | GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, | 159 | GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, |
159 | timeout, GNUNET_YES, | 160 | timeout, GNUNET_YES, |
160 | &peer_address_response_processor, | 161 | &address_response_processor, |
161 | alc)); | 162 | alc)); |
163 | GNUNET_free (msg); | ||
162 | return alc; | 164 | return alc; |
163 | } | 165 | } |
164 | 166 | ||
@@ -169,13 +171,14 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha | |||
169 | * @param alc handle for the request to cancel | 171 | * @param alc handle for the request to cancel |
170 | */ | 172 | */ |
171 | void | 173 | void |
172 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct | 174 | GNUNET_TRANSPORT_address_to_string_cancel (struct |
173 | GNUNET_TRANSPORT_PeerAddressLookupContext | 175 | GNUNET_TRANSPORT_AddressToStringContext |
174 | *alc) | 176 | *alc) |
175 | { | 177 | { |
176 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); | 178 | GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO); |
177 | GNUNET_free (alc); | 179 | GNUNET_free (alc); |
178 | } | 180 | } |
179 | 181 | ||
180 | 182 | ||
181 | /* end of transport_api_peer_address_lookup.c */ | 183 | |
184 | /* end of transport_api_address_lookup.c */ | ||