diff options
Diffstat (limited to 'src/transport/transport_api_address_lookup.c')
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 98 |
1 files changed, 40 insertions, 58 deletions
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 489ba8a5a..7cd61e896 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -65,6 +65,7 @@ struct GNUNET_TRANSPORT_PeerIterateContext | |||
65 | struct GNUNET_TIME_Absolute timeout; | 65 | struct GNUNET_TIME_Absolute timeout; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | |||
68 | /** | 69 | /** |
69 | * Function called with responses from the service. | 70 | * Function called with responses from the service. |
70 | * | 71 | * |
@@ -79,13 +80,16 @@ peer_address_response_processor (void *cls, | |||
79 | struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; | 80 | struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls; |
80 | struct AddressIterateResponseMessage *air_msg; | 81 | struct AddressIterateResponseMessage *air_msg; |
81 | struct GNUNET_HELLO_Address *address; | 82 | struct GNUNET_HELLO_Address *address; |
83 | const char *addr; | ||
84 | const char *transport_name; | ||
82 | uint16_t size; | 85 | uint16_t size; |
86 | size_t alen; | ||
87 | size_t tlen; | ||
83 | 88 | ||
84 | if (msg == NULL) | 89 | if (msg == NULL) |
85 | { | 90 | { |
86 | pal_ctx->cb (pal_ctx->cb_cls, NULL); | 91 | pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); |
87 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | 92 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); |
88 | GNUNET_free (pal_ctx); | ||
89 | return; | 93 | return; |
90 | } | 94 | } |
91 | size = ntohs (msg->size); | 95 | size = ntohs (msg->size); |
@@ -93,54 +97,53 @@ peer_address_response_processor (void *cls, | |||
93 | if (size == sizeof (struct GNUNET_MessageHeader)) | 97 | if (size == sizeof (struct GNUNET_MessageHeader)) |
94 | { | 98 | { |
95 | /* done! */ | 99 | /* done! */ |
96 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | 100 | pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); |
97 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | 101 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); |
98 | GNUNET_free (pal_ctx); | ||
99 | return; | 102 | return; |
100 | } | 103 | } |
101 | 104 | ||
102 | if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage)) | 105 | if ( (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage)) || |
106 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE) ) | ||
103 | { | 107 | { |
104 | GNUNET_break_op (0); | 108 | GNUNET_break (0); |
105 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | 109 | pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); |
106 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | 110 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); |
107 | GNUNET_free (pal_ctx); | ||
108 | return; | 111 | return; |
109 | } | 112 | } |
110 | 113 | ||
111 | air_msg = (struct AddressIterateResponseMessage *) &msg[1]; | 114 | air_msg = (struct AddressIterateResponseMessage *) msg; |
112 | size_t tlen = ntohl(air_msg->pluginlen); | 115 | tlen = ntohl(air_msg->pluginlen); |
113 | size_t alen = ntohl(air_msg->addrlen); | 116 | alen = ntohl(air_msg->addrlen); |
114 | 117 | ||
115 | if (size != sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage) + tlen + alen) | 118 | if (size != sizeof (struct AddressIterateResponseMessage) + tlen + alen) |
116 | { | 119 | { |
117 | GNUNET_break_op (0); | 120 | GNUNET_break (0); |
118 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | 121 | pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); |
119 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | 122 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); |
120 | GNUNET_free (pal_ctx); | ||
121 | return; | 123 | return; |
122 | } | 124 | } |
123 | 125 | ||
124 | char * addr = (char *) &air_msg[1]; | 126 | addr = (const char *) &air_msg[1]; |
125 | char * transport_name = &addr[alen]; | 127 | transport_name = &addr[alen]; |
126 | 128 | ||
127 | if (transport_name[tlen-1] != '\0') | 129 | if (transport_name[tlen-1] != '\0') |
128 | { | 130 | { |
129 | GNUNET_break_op (0); | 131 | GNUNET_break_op (0); |
130 | pal_ctx->cb (pal_ctx->cb_cls, NULL ); | 132 | pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL); |
131 | GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO); | 133 | GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pal_ctx); |
132 | GNUNET_free (pal_ctx); | ||
133 | return; | 134 | return; |
134 | } | 135 | } |
135 | 136 | ||
136 | address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen); | ||
137 | |||
138 | /* expect more replies */ | 137 | /* expect more replies */ |
139 | GNUNET_CLIENT_receive (pal_ctx->client, &peer_address_response_processor, pal_ctx, | 138 | GNUNET_CLIENT_receive (pal_ctx->client, |
139 | &peer_address_response_processor, pal_ctx, | ||
140 | GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); | 140 | GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout)); |
141 | 141 | ||
142 | pal_ctx->cb (pal_ctx->cb_cls, address); | 142 | /* notify client */ |
143 | GNUNET_free (address); | 143 | address = GNUNET_HELLO_address_allocate (&air_msg->peer, |
144 | transport_name, addr, alen); | ||
145 | pal_ctx->cb (pal_ctx->cb_cls, &air_msg->peer, address); | ||
146 | GNUNET_HELLO_address_free (address); | ||
144 | } | 147 | } |
145 | 148 | ||
146 | 149 | ||
@@ -174,23 +177,24 @@ GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Ha | |||
174 | struct GNUNET_CLIENT_Connection *client; | 177 | struct GNUNET_CLIENT_Connection *client; |
175 | struct GNUNET_TIME_Absolute abs_timeout; | 178 | struct GNUNET_TIME_Absolute abs_timeout; |
176 | 179 | ||
177 | client = GNUNET_CLIENT_connect ("transport", cfg); | 180 | if (GNUNET_YES != one_shot) |
178 | if (client == NULL) | ||
179 | { | 181 | { |
180 | peer_address_callback (peer_address_callback_cls, NULL); | 182 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
183 | "Address monitoring not implemented\n"); | ||
181 | return NULL; | 184 | return NULL; |
182 | } | 185 | } |
183 | 186 | client = GNUNET_CLIENT_connect ("transport", cfg); | |
187 | if (client == NULL) | ||
188 | return NULL; | ||
184 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 189 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
185 | |||
186 | msg.header.size = htons (sizeof (struct AddressIterateMessage)); | 190 | msg.header.size = htons (sizeof (struct AddressIterateMessage)); |
187 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); | 191 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); |
192 | msg.one_shot = htonl (one_shot); | ||
188 | msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); | 193 | msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); |
189 | if (peer == NULL) | 194 | if (peer == NULL) |
190 | memset (&msg.peer, 0 , sizeof (struct GNUNET_PeerIdentity)); | 195 | memset (&msg.peer, 0 , sizeof (struct GNUNET_PeerIdentity)); |
191 | else | 196 | else |
192 | memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity)); | 197 | msg.peer = *peer; |
193 | |||
194 | pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext)); | 198 | pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext)); |
195 | pal_ctx->cb = peer_address_callback; | 199 | pal_ctx->cb = peer_address_callback; |
196 | pal_ctx->cb_cls = peer_address_callback_cls; | 200 | pal_ctx->cb_cls = peer_address_callback_cls; |
@@ -219,27 +223,5 @@ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct | |||
219 | GNUNET_free (alc); | 223 | GNUNET_free (alc); |
220 | } | 224 | } |
221 | 225 | ||
222 | /** | ||
223 | * Return all addresses for all peers. | ||
224 | * | ||
225 | * @param cfg configuration to use | ||
226 | * @param timeout how long is the lookup allowed to take at most | ||
227 | * @param peer_address_callback function to call with the results | ||
228 | * @param peer_address_callback_cls closure for peer_address_callback | ||
229 | */ | ||
230 | void | ||
231 | GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
232 | struct GNUNET_TIME_Relative timeout, | ||
233 | GNUNET_TRANSPORT_PeerIterateCallback | ||
234 | peer_address_callback, | ||
235 | void *peer_address_callback_cls) | ||
236 | { | ||
237 | GNUNET_TRANSPORT_peer_get_active_addresses (cfg, | ||
238 | NULL, | ||
239 | GNUNET_YES, | ||
240 | timeout, | ||
241 | peer_address_callback, | ||
242 | peer_address_callback_cls); | ||
243 | } | ||
244 | 226 | ||
245 | /* end of transport_api_peer_address_lookup.c */ | 227 | /* end of transport_api_peer_address_lookup.c */ |