diff options
Diffstat (limited to 'src')
20 files changed, 2464 insertions, 3103 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index a5ce3fa4a..2c2d90dc4 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
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 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/gnunet-service-transport.c | 22 | * @file transport/gnunet-service-transport.c |
@@ -40,7 +40,6 @@ | |||
40 | #include "gnunet-service-transport_manipulation.h" | 40 | #include "gnunet-service-transport_manipulation.h" |
41 | #include "transport.h" | 41 | #include "transport.h" |
42 | 42 | ||
43 | |||
44 | /** | 43 | /** |
45 | * Information we need for an asynchronous session kill. | 44 | * Information we need for an asynchronous session kill. |
46 | */ | 45 | */ |
@@ -72,7 +71,6 @@ struct SessionKiller | |||
72 | GNUNET_SCHEDULER_TaskIdentifier task; | 71 | GNUNET_SCHEDULER_TaskIdentifier task; |
73 | }; | 72 | }; |
74 | 73 | ||
75 | |||
76 | /* globals */ | 74 | /* globals */ |
77 | 75 | ||
78 | /** | 76 | /** |
@@ -130,7 +128,6 @@ static struct SessionKiller *sk_head; | |||
130 | */ | 128 | */ |
131 | static struct SessionKiller *sk_tail; | 129 | static struct SessionKiller *sk_tail; |
132 | 130 | ||
133 | |||
134 | /** | 131 | /** |
135 | * Transmit our HELLO message to the given (connected) neighbour. | 132 | * Transmit our HELLO message to the given (connected) neighbour. |
136 | * | 133 | * |
@@ -144,24 +141,21 @@ static struct SessionKiller *sk_tail; | |||
144 | */ | 141 | */ |
145 | static void | 142 | static void |
146 | transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, | 143 | transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, |
147 | const struct GNUNET_HELLO_Address *address, | 144 | const struct GNUNET_HELLO_Address *address, |
148 | enum GNUNET_TRANSPORT_PeerState state, | 145 | enum GNUNET_TRANSPORT_PeerState state, |
149 | struct GNUNET_TIME_Absolute state_timeout, | 146 | struct GNUNET_TIME_Absolute state_timeout, |
150 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 147 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
151 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 148 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
152 | { | 149 | { |
153 | const struct GNUNET_MessageHeader *hello = cls; | 150 | const struct GNUNET_MessageHeader *hello = cls; |
154 | 151 | ||
155 | if ( GNUNET_NO == GST_neighbours_test_connected(target) ) | 152 | if (GNUNET_NO == GST_neighbours_test_connected (target)) |
156 | return; | 153 | return; |
157 | 154 | ||
158 | GST_neighbours_send (target, | 155 | GST_neighbours_send (target, hello, ntohs (hello->size), hello_expiration, |
159 | hello, | 156 | NULL, NULL ); |
160 | ntohs (hello->size), | ||
161 | hello_expiration, NULL, NULL); | ||
162 | } | 157 | } |
163 | 158 | ||
164 | |||
165 | /** | 159 | /** |
166 | * My HELLO has changed. Tell everyone who should know. | 160 | * My HELLO has changed. Tell everyone who should know. |
167 | * | 161 | * |
@@ -169,14 +163,12 @@ transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, | |||
169 | * @param hello new HELLO | 163 | * @param hello new HELLO |
170 | */ | 164 | */ |
171 | static void | 165 | static void |
172 | process_hello_update (void *cls, | 166 | process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) |
173 | const struct GNUNET_MessageHeader *hello) | ||
174 | { | 167 | { |
175 | GST_clients_broadcast (hello, GNUNET_NO); | 168 | GST_clients_broadcast (hello, GNUNET_NO); |
176 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); | 169 | GST_neighbours_iterate (&transmit_our_hello, (void *) hello); |
177 | } | 170 | } |
178 | 171 | ||
179 | |||
180 | /** | 172 | /** |
181 | * We received some payload. Prepare to pass it on to our clients. | 173 | * We received some payload. Prepare to pass it on to our clients. |
182 | * | 174 | * |
@@ -188,30 +180,26 @@ process_hello_update (void *cls, | |||
188 | */ | 180 | */ |
189 | static struct GNUNET_TIME_Relative | 181 | static struct GNUNET_TIME_Relative |
190 | process_payload (const struct GNUNET_PeerIdentity *peer, | 182 | process_payload (const struct GNUNET_PeerIdentity *peer, |
191 | const struct GNUNET_HELLO_Address *address, | 183 | const struct GNUNET_HELLO_Address *address, struct Session *session, |
192 | struct Session *session, | 184 | const struct GNUNET_MessageHeader *message) |
193 | const struct GNUNET_MessageHeader *message) | ||
194 | { | 185 | { |
195 | struct GNUNET_TIME_Relative ret; | 186 | struct GNUNET_TIME_Relative ret; |
196 | int do_forward; | 187 | int do_forward; |
197 | struct InboundMessage *im; | 188 | struct InboundMessage *im; |
198 | size_t msg_size = ntohs (message->size); | 189 | size_t msg_size = ntohs (message->size); |
199 | size_t size = | 190 | size_t size = sizeof(struct InboundMessage) + msg_size; |
200 | sizeof (struct InboundMessage) + msg_size; | ||
201 | char buf[size] GNUNET_ALIGN; | 191 | char buf[size] GNUNET_ALIGN; |
202 | 192 | ||
203 | do_forward = GNUNET_SYSERR; | 193 | do_forward = GNUNET_SYSERR; |
204 | ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); | 194 | ret = GST_neighbours_calculate_receive_delay (peer, msg_size, &do_forward); |
205 | if (! GST_neighbours_test_connected (peer)) | 195 | if (!GST_neighbours_test_connected (peer)) |
206 | { | 196 | { |
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 197 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
208 | "Discarded %u bytes type %u payload from peer `%s'\n", | 198 | "Discarded %u bytes type %u payload from peer `%s'\n", msg_size, |
209 | msg_size, | 199 | ntohs (message->type), GNUNET_i2s (peer)); |
210 | ntohs (message->type), GNUNET_i2s (peer)); | 200 | GNUNET_STATISTICS_update (GST_stats, gettext_noop |
211 | GNUNET_STATISTICS_update (GST_stats, | 201 | ("# bytes payload discarded due to not connected peer"), msg_size, |
212 | gettext_noop | 202 | GNUNET_NO); |
213 | ("# bytes payload discarded due to not connected peer"), | ||
214 | msg_size, GNUNET_NO); | ||
215 | return ret; | 203 | return ret; |
216 | } | 204 | } |
217 | 205 | ||
@@ -228,7 +216,6 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
228 | return ret; | 216 | return ret; |
229 | } | 217 | } |
230 | 218 | ||
231 | |||
232 | /** | 219 | /** |
233 | * Task to asynchronously terminate a session. | 220 | * Task to asynchronously terminate a session. |
234 | * | 221 | * |
@@ -236,19 +223,16 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
236 | * @param tc scheduler context | 223 | * @param tc scheduler context |
237 | */ | 224 | */ |
238 | static void | 225 | static void |
239 | kill_session_task (void *cls, | 226 | kill_session_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
240 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
241 | { | 227 | { |
242 | struct SessionKiller *sk = cls; | 228 | struct SessionKiller *sk = cls; |
243 | 229 | ||
244 | sk->task = GNUNET_SCHEDULER_NO_TASK; | 230 | sk->task = GNUNET_SCHEDULER_NO_TASK; |
245 | GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); | 231 | GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); |
246 | sk->plugin->disconnect_session (sk->plugin->cls, | 232 | sk->plugin->disconnect_session (sk->plugin->cls, sk->session); |
247 | sk->session); | 233 | GNUNET_free(sk); |
248 | GNUNET_free (sk); | ||
249 | } | 234 | } |
250 | 235 | ||
251 | |||
252 | /** | 236 | /** |
253 | * Force plugin to terminate session due to communication | 237 | * Force plugin to terminate session due to communication |
254 | * issue. | 238 | * issue. |
@@ -257,8 +241,7 @@ kill_session_task (void *cls, | |||
257 | * @param session session to termiante | 241 | * @param session session to termiante |
258 | */ | 242 | */ |
259 | static void | 243 | static void |
260 | kill_session (const char *plugin_name, | 244 | kill_session (const char *plugin_name, struct Session *session) |
261 | struct Session *session) | ||
262 | { | 245 | { |
263 | struct GNUNET_TRANSPORT_PluginFunctions *plugin; | 246 | struct GNUNET_TRANSPORT_PluginFunctions *plugin; |
264 | struct SessionKiller *sk; | 247 | struct SessionKiller *sk; |
@@ -269,19 +252,17 @@ kill_session (const char *plugin_name, | |||
269 | plugin = GST_plugins_find (plugin_name); | 252 | plugin = GST_plugins_find (plugin_name); |
270 | if (NULL == plugin) | 253 | if (NULL == plugin) |
271 | { | 254 | { |
272 | GNUNET_break (0); | 255 | GNUNET_break(0); |
273 | return; | 256 | return; |
274 | } | 257 | } |
275 | /* need to issue disconnect asynchronously */ | 258 | /* need to issue disconnect asynchronously */ |
276 | sk = GNUNET_new (struct SessionKiller); | 259 | sk = GNUNET_new (struct SessionKiller); |
277 | sk->session = session; | 260 | sk->session = session; |
278 | sk->plugin = plugin; | 261 | sk->plugin = plugin; |
279 | sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, | 262 | sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk); |
280 | sk); | 263 | GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk); |
281 | GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk); | ||
282 | } | 264 | } |
283 | 265 | ||
284 | |||
285 | /** | 266 | /** |
286 | * Function called by the transport for each received message. | 267 | * Function called by the transport for each received message. |
287 | * | 268 | * |
@@ -303,35 +284,25 @@ kill_session (const char *plugin_name, | |||
303 | */ | 284 | */ |
304 | struct GNUNET_TIME_Relative | 285 | struct GNUNET_TIME_Relative |
305 | GST_receive_callback (void *cls, | 286 | GST_receive_callback (void *cls, |
306 | const struct GNUNET_PeerIdentity *peer, | 287 | const struct GNUNET_HELLO_Address *address, |
307 | const struct GNUNET_MessageHeader *message, | ||
308 | struct Session *session, | 288 | struct Session *session, |
309 | const char *sender_address, | 289 | const struct GNUNET_MessageHeader *message) |
310 | uint16_t sender_address_len) | ||
311 | { | 290 | { |
312 | const char *plugin_name = cls; | 291 | const char *plugin_name = cls; |
313 | struct GNUNET_TIME_Relative ret; | 292 | struct GNUNET_TIME_Relative ret; |
314 | struct GNUNET_HELLO_Address address; | ||
315 | uint16_t type; | 293 | uint16_t type; |
316 | 294 | ||
317 | address.peer = *peer; | ||
318 | address.address = sender_address; | ||
319 | address.address_length = sender_address_len; | ||
320 | address.transport_name = plugin_name; | ||
321 | ret = GNUNET_TIME_UNIT_ZERO; | 295 | ret = GNUNET_TIME_UNIT_ZERO; |
322 | if (NULL == message) | 296 | if (NULL == message) |
323 | goto end; | 297 | goto end; |
324 | type = ntohs (message->type); | 298 | type = ntohs (message->type); |
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 299 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
326 | "Received Message with type %u from peer `%s'\n", | 300 | "Received Message with type %u from peer `%s'\n", type, |
327 | type, | 301 | GNUNET_i2s (&address->peer)); |
328 | GNUNET_i2s (peer)); | ||
329 | 302 | ||
330 | GNUNET_STATISTICS_update (GST_stats, | 303 | GNUNET_STATISTICS_update (GST_stats, gettext_noop |
331 | gettext_noop | 304 | ("# bytes total received"), ntohs (message->size), GNUNET_NO); |
332 | ("# bytes total received"), | 305 | GST_neighbours_notify_data_recv (&address->peer, address, session, message); |
333 | ntohs (message->size), GNUNET_NO); | ||
334 | GST_neighbours_notify_data_recv (peer, &address, session, message); | ||
335 | 306 | ||
336 | switch (type) | 307 | switch (type) |
337 | { | 308 | { |
@@ -339,85 +310,76 @@ GST_receive_callback (void *cls, | |||
339 | /* Legacy HELLO message, discard */ | 310 | /* Legacy HELLO message, discard */ |
340 | return ret; | 311 | return ret; |
341 | case GNUNET_MESSAGE_TYPE_HELLO: | 312 | case GNUNET_MESSAGE_TYPE_HELLO: |
342 | if (GNUNET_OK != | 313 | if (GNUNET_OK != GST_validation_handle_hello (message)) |
343 | GST_validation_handle_hello (message)) | ||
344 | { | 314 | { |
345 | GNUNET_break_op (0); | 315 | GNUNET_break_op(0); |
346 | kill_session (plugin_name, session); | 316 | kill_session (plugin_name, session); |
347 | } | 317 | } |
348 | return ret; | 318 | return ret; |
349 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: | 319 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: |
350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 320 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
351 | "Processing `%s' from `%s'\n", "PING", | 321 | "Processing `%s' from `%s'\n", "PING", GST_plugins_a2s (address)); |
352 | (sender_address != | 322 | if (GNUNET_OK |
353 | NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING); | 323 | != GST_validation_handle_ping (&address->peer, message, address, session)) |
354 | if (GNUNET_OK != | ||
355 | GST_validation_handle_ping (peer, message, &address, session)) | ||
356 | kill_session (plugin_name, session); | 324 | kill_session (plugin_name, session); |
357 | break; | 325 | break; |
358 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | 326 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: |
359 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 327 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
360 | "Processing `%s' from `%s'\n", "PONG", | 328 | "Processing `%s' from `%s'\n", "PONG", |
361 | (sender_address != | 329 | GST_plugins_a2s (address)); |
362 | NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING); | 330 | if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) |
363 | if (GNUNET_OK != | ||
364 | GST_validation_handle_pong (peer, message)) | ||
365 | { | 331 | { |
366 | GNUNET_break_op (0); | 332 | GNUNET_break_op(0); |
367 | kill_session (plugin_name, session); | 333 | kill_session (plugin_name, session); |
368 | } | 334 | } |
369 | break; | 335 | break; |
370 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: | 336 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: |
371 | if (GNUNET_OK != | 337 | if (GNUNET_OK |
372 | GST_neighbours_handle_connect (message, peer, &address, session)) | 338 | != GST_neighbours_handle_connect (message, &address->peer, address, session)) |
373 | { | 339 | { |
374 | GNUNET_break_op (0); | 340 | GNUNET_break_op(0); |
375 | kill_session (plugin_name, session); | 341 | kill_session (plugin_name, session); |
376 | } | 342 | } |
377 | break; | 343 | break; |
378 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: | 344 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: |
379 | if (GNUNET_OK != | 345 | if (GNUNET_OK |
380 | GST_neighbours_handle_connect_ack (message, peer, &address, session)) | 346 | != GST_neighbours_handle_connect_ack (message, &address->peer, address, session)) |
381 | { | 347 | { |
382 | kill_session (plugin_name, session); | 348 | kill_session (plugin_name, session); |
383 | } | 349 | } |
384 | break; | 350 | break; |
385 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: | 351 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: |
386 | if (GNUNET_OK != | 352 | if (GNUNET_OK |
387 | GST_neighbours_handle_session_ack (message, peer, &address, session)) | 353 | != GST_neighbours_handle_session_ack (message, &address->peer, address, session)) |
388 | { | 354 | { |
389 | GNUNET_break_op (0); | 355 | GNUNET_break_op(0); |
390 | kill_session (plugin_name, session); | 356 | kill_session (plugin_name, session); |
391 | } | 357 | } |
392 | break; | 358 | break; |
393 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 359 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
394 | GST_neighbours_handle_disconnect_message (peer, message); | 360 | GST_neighbours_handle_disconnect_message (&address->peer, message); |
395 | break; | 361 | break; |
396 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: | 362 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: |
397 | GST_neighbours_keepalive (peer, message); | 363 | GST_neighbours_keepalive (&address->peer, message); |
398 | break; | 364 | break; |
399 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: | 365 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: |
400 | GST_neighbours_keepalive_response (peer, message); | 366 | GST_neighbours_keepalive_response (&address->peer, message); |
401 | break; | 367 | break; |
402 | default: | 368 | default: |
403 | /* should be payload */ | 369 | /* should be payload */ |
404 | GNUNET_STATISTICS_update (GST_stats, | 370 | GNUNET_STATISTICS_update (GST_stats, gettext_noop |
405 | gettext_noop | 371 | ("# bytes payload received"), ntohs (message->size), GNUNET_NO); |
406 | ("# bytes payload received"), | 372 | GST_neighbours_notify_payload_recv (&address->peer, address, session, message); |
407 | ntohs (message->size), GNUNET_NO); | 373 | ret = process_payload (&address->peer, address, session, message); |
408 | GST_neighbours_notify_payload_recv (peer, &address, session, message); | ||
409 | ret = process_payload (peer, &address, session, message); | ||
410 | break; | 374 | break; |
411 | } | 375 | } |
412 | end: | 376 | end: |
413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 377 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
414 | "Allowing receive from peer %s to continue in %s\n", | 378 | "Allowing receive from peer %s to continue in %s\n", GNUNET_i2s (&address->peer), |
415 | GNUNET_i2s (peer), | 379 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); |
416 | GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); | ||
417 | return ret; | 380 | return ret; |
418 | } | 381 | } |
419 | 382 | ||
420 | |||
421 | /** | 383 | /** |
422 | * Function that will be called for each address the transport | 384 | * Function that will be called for each address the transport |
423 | * is aware that it might be reachable under. Update our HELLO. | 385 | * is aware that it might be reachable under. Update our HELLO. |
@@ -425,26 +387,15 @@ end: | |||
425 | * @param cls name of the plugin (const char*) | 387 | * @param cls name of the plugin (const char*) |
426 | * @param add_remove should the address added (YES) or removed (NO) from the | 388 | * @param add_remove should the address added (YES) or removed (NO) from the |
427 | * set of valid addresses? | 389 | * set of valid addresses? |
428 | * @param addr one of the addresses of the host | 390 | * @param address the address to add or remove |
429 | * the specific address format depends on the transport | ||
430 | * @param addrlen length of the @a addr | ||
431 | * @param dest_plugin destination plugin to use this address with | ||
432 | */ | 391 | */ |
433 | static void | 392 | static void |
434 | plugin_env_address_change_notification (void *cls, int add_remove, | 393 | plugin_env_address_change_notification (void *cls, int add_remove, |
435 | const void *addr, size_t addrlen, | 394 | const struct GNUNET_HELLO_Address *address) |
436 | const char *dest_plugin) | ||
437 | { | 395 | { |
438 | struct GNUNET_HELLO_Address address; | 396 | GST_hello_modify_addresses (add_remove, address); |
439 | |||
440 | address.peer = GST_my_identity; | ||
441 | address.transport_name = dest_plugin; | ||
442 | address.address = addr; | ||
443 | address.address_length = addrlen; | ||
444 | GST_hello_modify_addresses (add_remove, &address); | ||
445 | } | 397 | } |
446 | 398 | ||
447 | |||
448 | /** | 399 | /** |
449 | * Function that will be called whenever the plugin internally | 400 | * Function that will be called whenever the plugin internally |
450 | * cleans up a session pointer and hence the service needs to | 401 | * cleans up a session pointer and hence the service needs to |
@@ -460,22 +411,21 @@ plugin_env_address_change_notification (void *cls, int add_remove, | |||
460 | */ | 411 | */ |
461 | static void | 412 | static void |
462 | plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | 413 | plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, |
463 | struct Session *session) | 414 | struct Session *session) |
464 | { | 415 | { |
465 | const char *transport_name = cls; | 416 | const char *transport_name = cls; |
466 | struct GNUNET_HELLO_Address address; | 417 | struct GNUNET_HELLO_Address address; |
467 | struct SessionKiller *sk; | 418 | struct SessionKiller *sk; |
468 | 419 | ||
469 | GNUNET_assert (strlen (transport_name) > 0); | 420 | GNUNET_assert(strlen (transport_name) > 0); |
470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 421 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' ended \n", |
471 | "Session %p to peer `%s' ended \n", | 422 | session, GNUNET_i2s (peer)); |
472 | session, | ||
473 | GNUNET_i2s (peer)); | ||
474 | if (NULL != session) | 423 | if (NULL != session) |
475 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 424 | GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
476 | "transport-ats", | 425 | "transport-ats", "Telling ATS to destroy session %p from peer %s\n", |
477 | "Telling ATS to destroy session %p from peer %s\n", | 426 | session, GNUNET_i2s (peer)); |
478 | session, GNUNET_i2s (peer)); | 427 | |
428 | memset (&address, '\0', sizeof (address)); | ||
479 | address.peer = *peer; | 429 | address.peer = *peer; |
480 | address.address = NULL; | 430 | address.address = NULL; |
481 | address.address_length = 0; | 431 | address.address_length = 0; |
@@ -488,15 +438,14 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
488 | { | 438 | { |
489 | if (sk->session == session) | 439 | if (sk->session == session) |
490 | { | 440 | { |
491 | GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); | 441 | GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk); |
492 | GNUNET_SCHEDULER_cancel (sk->task); | 442 | GNUNET_SCHEDULER_cancel (sk->task); |
493 | GNUNET_free (sk); | 443 | GNUNET_free(sk); |
494 | break; | 444 | break; |
495 | } | 445 | } |
496 | } | 446 | } |
497 | } | 447 | } |
498 | 448 | ||
499 | |||
500 | /** | 449 | /** |
501 | * Function that will be called to figure if an address is an loopback, | 450 | * Function that will be called to figure if an address is an loopback, |
502 | * LAN, WAN etc. address | 451 | * LAN, WAN etc. address |
@@ -507,9 +456,8 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
507 | * @return ATS Information containing the network type | 456 | * @return ATS Information containing the network type |
508 | */ | 457 | */ |
509 | static struct GNUNET_ATS_Information | 458 | static struct GNUNET_ATS_Information |
510 | plugin_env_address_to_type (void *cls, | 459 | plugin_env_address_to_type (void *cls, const struct sockaddr *addr, |
511 | const struct sockaddr *addr, | 460 | size_t addrlen) |
512 | size_t addrlen) | ||
513 | { | 461 | { |
514 | struct GNUNET_ATS_Information ats; | 462 | struct GNUNET_ATS_Information ats; |
515 | 463 | ||
@@ -517,24 +465,23 @@ plugin_env_address_to_type (void *cls, | |||
517 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); | 465 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); |
518 | if (NULL == GST_ats) | 466 | if (NULL == GST_ats) |
519 | { | 467 | { |
520 | GNUNET_break (0); | 468 | GNUNET_break(0); |
521 | return ats; | 469 | return ats; |
522 | } | 470 | } |
523 | if (((addr->sa_family != AF_INET) && (addrlen != sizeof (struct sockaddr_in))) && | 471 | if (((addr->sa_family != AF_INET) && (addrlen != sizeof(struct sockaddr_in))) |
524 | ((addr->sa_family != AF_INET6) && (addrlen != sizeof (struct sockaddr_in6))) && | 472 | && ((addr->sa_family != AF_INET6) |
525 | (addr->sa_family != AF_UNIX)) | 473 | && (addrlen != sizeof(struct sockaddr_in6))) |
474 | && (addr->sa_family != AF_UNIX)) | ||
526 | { | 475 | { |
527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 476 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
528 | "Malformed address with length %u `%s'\n", | 477 | "Malformed address with length %u `%s'\n", addrlen, |
529 | addrlen, | 478 | GNUNET_a2s (addr, addrlen)); |
530 | GNUNET_a2s (addr, addrlen)); | 479 | GNUNET_break(0); |
531 | GNUNET_break (0); | ||
532 | return ats; | 480 | return ats; |
533 | } | 481 | } |
534 | return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen); | 482 | return GNUNET_ATS_address_get_type (GST_ats, addr, addrlen); |
535 | } | 483 | } |
536 | 484 | ||
537 | |||
538 | /** | 485 | /** |
539 | * Notify ATS about the new address including the network this address is | 486 | * Notify ATS about the new address including the network this address is |
540 | * located in. | 487 | * located in. |
@@ -546,9 +493,8 @@ plugin_env_address_to_type (void *cls, | |||
546 | */ | 493 | */ |
547 | void | 494 | void |
548 | GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | 495 | GST_ats_add_address (const struct GNUNET_HELLO_Address *address, |
549 | struct Session *session, | 496 | struct Session *session, const struct GNUNET_ATS_Information *ats, |
550 | const struct GNUNET_ATS_Information *ats, | 497 | uint32_t ats_count) |
551 | uint32_t ats_count) | ||
552 | { | 498 | { |
553 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 499 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
554 | struct GNUNET_ATS_Information ats2[ats_count + 1]; | 500 | struct GNUNET_ATS_Information ats2[ats_count + 1]; |
@@ -557,48 +503,43 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | |||
557 | /* valid new address, let ATS know! */ | 503 | /* valid new address, let ATS know! */ |
558 | if (NULL == address->transport_name) | 504 | if (NULL == address->transport_name) |
559 | { | 505 | { |
560 | GNUNET_break (0); | 506 | GNUNET_break(0); |
561 | return; | 507 | return; |
562 | } | 508 | } |
563 | if (NULL == (papi = GST_plugins_find (address->transport_name))) | 509 | if (NULL == (papi = GST_plugins_find (address->transport_name))) |
564 | { | 510 | { |
565 | /* we don't have the plugin for this address */ | 511 | /* we don't have the plugin for this address */ |
566 | GNUNET_break (0); | 512 | GNUNET_break(0); |
567 | return; | 513 | return; |
568 | } | 514 | } |
569 | 515 | ||
570 | if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session)) | 516 | if (GNUNET_YES == GNUNET_ATS_session_known (GST_ats, address, session)) |
571 | { | 517 | { |
572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 518 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
573 | "ATS already knows the address, not passing it on again\n"); | 519 | "ATS already knows the address, not passing it on again\n"); |
574 | return; | 520 | return; |
575 | } | 521 | } |
576 | 522 | ||
577 | net = papi->get_network (NULL, session); | 523 | net = papi->get_network (NULL, session); |
578 | if (GNUNET_ATS_NET_UNSPECIFIED == net) | 524 | if (GNUNET_ATS_NET_UNSPECIFIED == net) |
579 | { | 525 | { |
580 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 526 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
581 | _("Could not obtain a valid network for `%s' %s (%s)\n"), | 527 | _("Could not obtain a valid network for `%s' %s (%s)\n"), |
582 | GNUNET_i2s (&address->peer), | 528 | GNUNET_i2s (&address->peer), GST_plugins_a2s (address), |
583 | GST_plugins_a2s (address), | 529 | address->transport_name); |
584 | address->transport_name); | 530 | GNUNET_break(0); |
585 | GNUNET_break (0); | ||
586 | } | 531 | } |
587 | ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | 532 | ats2[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); |
588 | ats2[0].value = htonl(net); | 533 | ats2[0].value = htonl (net); |
589 | memcpy (&ats2[1], ats, sizeof (struct GNUNET_ATS_Information) * ats_count); | 534 | memcpy (&ats2[1], ats, sizeof(struct GNUNET_ATS_Information) * ats_count); |
590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 535 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
591 | "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", | 536 | "Notifying ATS about peer `%s''s new address `%s' session %p in network %s\n", |
592 | GNUNET_i2s (&address->peer), | 537 | GNUNET_i2s (&address->peer), |
593 | (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), | 538 | (0 == address->address_length) ? "<inbound>" : GST_plugins_a2s (address), |
594 | session, | 539 | session, GNUNET_ATS_print_network_type (net)); |
595 | GNUNET_ATS_print_network_type(net)); | 540 | GNUNET_ATS_address_add (GST_ats, address, session, ats2, ats_count + 1); |
596 | GNUNET_ATS_address_add (GST_ats, | ||
597 | address, session, | ||
598 | ats2, ats_count + 1); | ||
599 | } | 541 | } |
600 | 542 | ||
601 | |||
602 | /** | 543 | /** |
603 | * Notify ATS about property changes to an address | 544 | * Notify ATS about property changes to an address |
604 | * | 545 | * |
@@ -610,10 +551,8 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address, | |||
610 | */ | 551 | */ |
611 | void | 552 | void |
612 | GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, | 553 | GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, |
613 | const struct GNUNET_HELLO_Address *address, | 554 | const struct GNUNET_HELLO_Address *address, struct Session *session, |
614 | struct Session *session, | 555 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
615 | const struct GNUNET_ATS_Information *ats, | ||
616 | uint32_t ats_count) | ||
617 | { | 556 | { |
618 | struct GNUNET_ATS_Information *ats_new; | 557 | struct GNUNET_ATS_Information *ats_new; |
619 | 558 | ||
@@ -622,26 +561,23 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, | |||
622 | 561 | ||
623 | /* Call to manipulation to manipulate ATS information */ | 562 | /* Call to manipulation to manipulate ATS information */ |
624 | ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats, | 563 | ats_new = GST_manipulation_manipulate_metrics (peer, address, session, ats, |
625 | ats_count); | 564 | ats_count); |
626 | if (NULL == ats_new) | 565 | if (NULL == ats_new) |
627 | { | 566 | { |
628 | GNUNET_break(0); | 567 | GNUNET_break(0); |
629 | return; | 568 | return; |
630 | } | 569 | } |
631 | if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, | 570 | if (GNUNET_NO == GNUNET_ATS_address_update (GST_ats, address, session, |
632 | address, session, ats_new, ats_count)) | 571 | ats_new, ats_count)) |
633 | { | 572 | { |
634 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 573 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
635 | _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"), | 574 | _("Address or session unknown: failed to update properties for peer `%s' plugin `%s' address `%s' session %p\n"), |
636 | GNUNET_i2s (peer), | 575 | GNUNET_i2s (peer), address->transport_name, GST_plugins_a2s (address), |
637 | address->transport_name, | 576 | session); |
638 | GST_plugins_a2s (address), | ||
639 | session); | ||
640 | } | 577 | } |
641 | GNUNET_free (ats_new); | 578 | GNUNET_free(ats_new); |
642 | } | 579 | } |
643 | 580 | ||
644 | |||
645 | /** | 581 | /** |
646 | * Function that will be called to figure if an address is an loopback, | 582 | * Function that will be called to figure if an address is an loopback, |
647 | * LAN, WAN etc. address | 583 | * LAN, WAN etc. address |
@@ -656,63 +592,37 @@ GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer, | |||
656 | */ | 592 | */ |
657 | static void | 593 | static void |
658 | plugin_env_update_metrics (void *cls, | 594 | plugin_env_update_metrics (void *cls, |
659 | const struct GNUNET_PeerIdentity *peer, | 595 | const struct GNUNET_HELLO_Address *address, |
660 | const void *address, | 596 | struct Session *session, |
661 | uint16_t address_len, | 597 | const struct GNUNET_ATS_Information *ats, |
662 | struct Session *session, | 598 | uint32_t ats_count) |
663 | const struct GNUNET_ATS_Information *ats, | ||
664 | uint32_t ats_count) | ||
665 | { | 599 | { |
666 | const char *plugin_name = cls; | ||
667 | struct GNUNET_HELLO_Address haddress; | ||
668 | |||
669 | if ((NULL == ats) || (0 == ats_count)) | 600 | if ((NULL == ats) || (0 == ats_count)) |
670 | return; | 601 | return; |
671 | GNUNET_assert (NULL != GST_ats); | 602 | GNUNET_assert(NULL != GST_ats); |
672 | |||
673 | haddress.peer = *peer; | ||
674 | haddress.address = address; | ||
675 | haddress.address_length = address_len; | ||
676 | haddress.transport_name = plugin_name; | ||
677 | |||
678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
679 | "Updating metrics for peer `%s' address %s session %p\n", | ||
680 | GNUNET_i2s (peer), | ||
681 | GST_plugins_a2s (&haddress), | ||
682 | session); | ||
683 | GST_ats_update_metrics (peer, &haddress, session, ats, ats_count); | ||
684 | } | ||
685 | 603 | ||
604 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
605 | "Updating metrics for peer `%s' address %s session %p\n", | ||
606 | GNUNET_i2s (&address->peer), GST_plugins_a2s (address), session); | ||
607 | GST_ats_update_metrics (&address->peer, address, session, ats, ats_count); | ||
608 | } | ||
686 | 609 | ||
687 | /** | 610 | /** |
688 | * Plugin tells transport service about a new (inbound) session | 611 | * Plugin tells transport service about a new inbound session |
689 | * | 612 | * |
690 | * @param cls unused | 613 | * @param cls unused |
691 | * @param peer the peer | 614 | * @param address the address |
692 | * @param plugin plugin name | ||
693 | * @param address address | ||
694 | * @param address_len @a address length | ||
695 | * @param session the new session | 615 | * @param session the new session |
696 | * @param ats ats information | 616 | * @param ats ats information |
697 | * @param ats_count number of @a ats information | 617 | * @param ats_count number of @a ats information |
698 | */ | 618 | */ |
699 | static void | 619 | static void |
700 | plugin_env_session_start (void *cls, | 620 | plugin_env_session_start (void *cls, struct GNUNET_HELLO_Address *address, |
701 | const struct GNUNET_PeerIdentity *peer, | 621 | struct Session *session, const struct GNUNET_ATS_Information *ats, |
702 | const char *plugin, | 622 | uint32_t ats_count) |
703 | const void *address, uint16_t address_len, | ||
704 | struct Session *session, | ||
705 | const struct GNUNET_ATS_Information *ats, | ||
706 | uint32_t ats_count) | ||
707 | { | 623 | { |
708 | struct GNUNET_HELLO_Address *addr; | 624 | int inbound; |
709 | 625 | if (NULL == address) | |
710 | if (NULL == peer) | ||
711 | { | ||
712 | GNUNET_break(0); | ||
713 | return; | ||
714 | } | ||
715 | if (NULL == plugin) | ||
716 | { | 626 | { |
717 | GNUNET_break(0); | 627 | GNUNET_break(0); |
718 | return; | 628 | return; |
@@ -723,17 +633,18 @@ plugin_env_session_start (void *cls, | |||
723 | return; | 633 | return; |
724 | } | 634 | } |
725 | 635 | ||
726 | addr = GNUNET_HELLO_address_allocate (peer, plugin, address, address_len); | 636 | if (GNUNET_HELLO_ADDRESS_INFO_INBOUND |
727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 637 | == (address->local_info & GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
728 | "Notification from plugin `%s' about new session %p from peer `%s' address `%s'\n", | 638 | inbound = GNUNET_YES; |
729 | plugin, | 639 | else |
730 | session, | 640 | inbound = GNUNET_NO; |
731 | GNUNET_i2s (peer), | ||
732 | GST_plugins_a2s (addr)); | ||
733 | GST_ats_add_address (addr, session, ats, ats_count); | ||
734 | GNUNET_free(addr); | ||
735 | } | ||
736 | 641 | ||
642 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
643 | "Notification from plugin `%s' about new %s session %p from peer `%s' address `%s'\n", | ||
644 | address->transport_name, (GNUNET_YES == inbound) ? "inbound" : "outbound", | ||
645 | session, GNUNET_i2s (&address->peer), GST_plugins_a2s (address)); | ||
646 | GST_ats_add_address (address, session, ats, ats_count); | ||
647 | } | ||
737 | 648 | ||
738 | /** | 649 | /** |
739 | * Function called by ATS to notify the callee that the | 650 | * Function called by ATS to notify the callee that the |
@@ -753,14 +664,11 @@ plugin_env_session_start (void *cls, | |||
753 | * @param ats_count number of @a ats elements | 664 | * @param ats_count number of @a ats elements |
754 | */ | 665 | */ |
755 | static void | 666 | static void |
756 | ats_request_address_change (void *cls, | 667 | ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, |
757 | const struct GNUNET_PeerIdentity *peer, | 668 | const struct GNUNET_HELLO_Address *address, struct Session *session, |
758 | const struct GNUNET_HELLO_Address *address, | 669 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
759 | struct Session *session, | 670 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
760 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 671 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
761 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
762 | const struct GNUNET_ATS_Information *ats, | ||
763 | uint32_t ats_count) | ||
764 | { | 672 | { |
765 | uint32_t bw_in = ntohl (bandwidth_in.value__); | 673 | uint32_t bw_in = ntohl (bandwidth_in.value__); |
766 | uint32_t bw_out = ntohl (bandwidth_out.value__); | 674 | uint32_t bw_out = ntohl (bandwidth_out.value__); |
@@ -768,19 +676,17 @@ ats_request_address_change (void *cls, | |||
768 | /* ATS tells me to disconnect from peer */ | 676 | /* ATS tells me to disconnect from peer */ |
769 | if ((0 == bw_in) && (0 == bw_out)) | 677 | if ((0 == bw_in) && (0 == bw_out)) |
770 | { | 678 | { |
771 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 679 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
772 | "ATS tells me to disconnect from peer `%s'\n", | 680 | "ATS tells me to disconnect from peer `%s'\n", |
773 | GNUNET_i2s (&address->peer)); | 681 | GNUNET_i2s (&address->peer)); |
774 | GST_neighbours_force_disconnect (&address->peer); | 682 | GST_neighbours_force_disconnect (&address->peer); |
775 | return; | 683 | return; |
776 | } | 684 | } |
777 | 685 | ||
778 | GST_neighbours_switch_to_address (&address->peer, address, session, ats, | 686 | GST_neighbours_switch_to_address (&address->peer, address, session, ats, |
779 | ats_count, bandwidth_in, | 687 | ats_count, bandwidth_in, bandwidth_out); |
780 | bandwidth_out); | ||
781 | } | 688 | } |
782 | 689 | ||
783 | |||
784 | /** | 690 | /** |
785 | * Function called to notify transport users that another | 691 | * Function called to notify transport users that another |
786 | * peer connected to us. | 692 | * peer connected to us. |
@@ -792,19 +698,19 @@ ats_request_address_change (void *cls, | |||
792 | */ | 698 | */ |
793 | static void | 699 | static void |
794 | neighbours_connect_notification (void *cls, | 700 | neighbours_connect_notification (void *cls, |
795 | const struct GNUNET_PeerIdentity *peer, | 701 | const struct GNUNET_PeerIdentity *peer, |
796 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 702 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
797 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 703 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
798 | { | 704 | { |
799 | size_t len = sizeof (struct ConnectInfoMessage); | 705 | size_t len = sizeof(struct ConnectInfoMessage); |
800 | char buf[len] GNUNET_ALIGN; | 706 | char buf[len] GNUNET_ALIGN; |
801 | struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; | 707 | struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; |
802 | 708 | ||
803 | connections++; | 709 | connections++; |
804 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 710 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
805 | "We are now connected to peer `%s' and %u peers in total\n", | 711 | "We are now connected to peer `%s' and %u peers in total\n", |
806 | GNUNET_i2s (peer), connections); | 712 | GNUNET_i2s (peer), connections); |
807 | connect_msg->header.size = htons (sizeof (buf)); | 713 | connect_msg->header.size = htons (sizeof(buf)); |
808 | connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | 714 | connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
809 | connect_msg->id = *peer; | 715 | connect_msg->id = *peer; |
810 | connect_msg->quota_in = bandwidth_in; | 716 | connect_msg->quota_in = bandwidth_in; |
@@ -812,7 +718,6 @@ neighbours_connect_notification (void *cls, | |||
812 | GST_clients_broadcast (&connect_msg->header, GNUNET_NO); | 718 | GST_clients_broadcast (&connect_msg->header, GNUNET_NO); |
813 | } | 719 | } |
814 | 720 | ||
815 | |||
816 | /** | 721 | /** |
817 | * Function called to notify transport users that another | 722 | * Function called to notify transport users that another |
818 | * peer disconnected from us. | 723 | * peer disconnected from us. |
@@ -822,24 +727,23 @@ neighbours_connect_notification (void *cls, | |||
822 | */ | 727 | */ |
823 | static void | 728 | static void |
824 | neighbours_disconnect_notification (void *cls, | 729 | neighbours_disconnect_notification (void *cls, |
825 | const struct GNUNET_PeerIdentity *peer) | 730 | const struct GNUNET_PeerIdentity *peer) |
826 | { | 731 | { |
827 | struct DisconnectInfoMessage disconnect_msg; | 732 | struct DisconnectInfoMessage disconnect_msg; |
828 | 733 | ||
829 | connections--; | 734 | connections--; |
830 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 735 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
831 | "Peer `%s' disconnected and we are connected to %u peers\n", | 736 | "Peer `%s' disconnected and we are connected to %u peers\n", |
832 | GNUNET_i2s (peer), connections); | 737 | GNUNET_i2s (peer), connections); |
833 | 738 | ||
834 | GST_manipulation_peer_disconnect (peer); | 739 | GST_manipulation_peer_disconnect (peer); |
835 | disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage)); | 740 | disconnect_msg.header.size = htons (sizeof(struct DisconnectInfoMessage)); |
836 | disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); | 741 | disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); |
837 | disconnect_msg.reserved = htonl (0); | 742 | disconnect_msg.reserved = htonl (0); |
838 | disconnect_msg.peer = *peer; | 743 | disconnect_msg.peer = *peer; |
839 | GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); | 744 | GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); |
840 | } | 745 | } |
841 | 746 | ||
842 | |||
843 | /** | 747 | /** |
844 | * Function called to notify transport users that a neighbour peer changed its | 748 | * Function called to notify transport users that a neighbour peer changed its |
845 | * active address. | 749 | * active address. |
@@ -854,24 +758,23 @@ neighbours_disconnect_notification (void *cls, | |||
854 | */ | 758 | */ |
855 | static void | 759 | static void |
856 | neighbours_changed_notification (void *cls, | 760 | neighbours_changed_notification (void *cls, |
857 | const struct GNUNET_PeerIdentity *peer, | 761 | const struct GNUNET_PeerIdentity *peer, |
858 | const struct GNUNET_HELLO_Address *address, | 762 | const struct GNUNET_HELLO_Address *address, |
859 | enum GNUNET_TRANSPORT_PeerState state, | 763 | enum GNUNET_TRANSPORT_PeerState state, |
860 | struct GNUNET_TIME_Absolute state_timeout, | 764 | struct GNUNET_TIME_Absolute state_timeout, |
861 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 765 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
862 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 766 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) |
863 | { | 767 | { |
864 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 768 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
865 | "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", | 769 | "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", |
866 | GNUNET_i2s (peer), | 770 | GNUNET_i2s (peer), |
867 | (NULL != address) ? GST_plugins_a2s (address) : "<none>", | 771 | (NULL != address) ? GST_plugins_a2s (address) : "<none>", |
868 | GNUNET_TRANSPORT_p2s(state), | 772 | GNUNET_TRANSPORT_p2s (state), |
869 | GNUNET_STRINGS_absolute_time_to_string(state_timeout)); | 773 | GNUNET_STRINGS_absolute_time_to_string (state_timeout)); |
870 | 774 | ||
871 | GST_clients_broadcast_peer_notification (peer, address, state, state_timeout); | 775 | GST_clients_broadcast_peer_notification (peer, address, state, state_timeout); |
872 | } | 776 | } |
873 | 777 | ||
874 | |||
875 | /** | 778 | /** |
876 | * Function called when the service shuts down. Unloads our plugins | 779 | * Function called when the service shuts down. Unloads our plugins |
877 | * and cancels pending validations. | 780 | * and cancels pending validations. |
@@ -905,13 +808,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
905 | } | 808 | } |
906 | if (NULL != GST_my_private_key) | 809 | if (NULL != GST_my_private_key) |
907 | { | 810 | { |
908 | GNUNET_free (GST_my_private_key); | 811 | GNUNET_free(GST_my_private_key); |
909 | GST_my_private_key = NULL; | 812 | GST_my_private_key = NULL; |
910 | } | 813 | } |
911 | GST_server = NULL; | 814 | GST_server = NULL; |
912 | } | 815 | } |
913 | 816 | ||
914 | |||
915 | /** | 817 | /** |
916 | * Initiate transport service. | 818 | * Initiate transport service. |
917 | * | 819 | * |
@@ -921,7 +823,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
921 | */ | 823 | */ |
922 | static void | 824 | static void |
923 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 825 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
924 | const struct GNUNET_CONFIGURATION_Handle *c) | 826 | const struct GNUNET_CONFIGURATION_Handle *c) |
925 | { | 827 | { |
926 | char *keyfile; | 828 | char *keyfile; |
927 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 829 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
@@ -932,42 +834,42 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
932 | 834 | ||
933 | /* setup globals */ | 835 | /* setup globals */ |
934 | GST_cfg = c; | 836 | GST_cfg = c; |
935 | if (GNUNET_OK != | 837 | if (GNUNET_OK |
936 | GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", | 838 | != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", |
937 | &keyfile)) | 839 | &keyfile)) |
938 | { | 840 | { |
939 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 841 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
940 | _("Transport service is lacking key configuration settings. Exiting.\n")); | 842 | _("Transport service is lacking key configuration settings. Exiting.\n")); |
941 | GNUNET_SCHEDULER_shutdown (); | 843 | GNUNET_SCHEDULER_shutdown (); |
942 | return; | 844 | return; |
943 | } | 845 | } |
944 | if (GNUNET_OK != | 846 | if (GNUNET_OK |
945 | GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", | 847 | != GNUNET_CONFIGURATION_get_value_time (c, "transport", |
946 | &hello_expiration)) | 848 | "HELLO_EXPIRATION", &hello_expiration)) |
947 | { | 849 | { |
948 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; | 850 | hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; |
949 | } | 851 | } |
950 | GST_server = server; | 852 | GST_server = server; |
951 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 853 | pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); |
952 | GNUNET_free (keyfile); | 854 | GNUNET_free(keyfile); |
953 | GNUNET_assert (NULL != pk); | 855 | GNUNET_assert(NULL != pk); |
954 | GST_my_private_key = pk; | 856 | GST_my_private_key = pk; |
955 | 857 | ||
956 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); | 858 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); |
957 | GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); | 859 | GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); |
958 | GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, | 860 | GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, |
959 | &GST_my_identity.public_key); | 861 | &GST_my_identity.public_key); |
960 | GNUNET_assert (NULL != GST_my_private_key); | 862 | GNUNET_assert(NULL != GST_my_private_key); |
961 | 863 | ||
962 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 864 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "My identity is `%4s'\n", |
963 | "My identity is `%4s'\n", GNUNET_i2s (&GST_my_identity)); | 865 | GNUNET_i2s (&GST_my_identity)); |
964 | 866 | ||
965 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 867 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
966 | NULL); | 868 | NULL ); |
967 | if (NULL == GST_peerinfo) | 869 | if (NULL == GST_peerinfo) |
968 | { | 870 | { |
969 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 871 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
970 | _("Could not access PEERINFO service. Exiting.\n")); | 872 | _("Could not access PEERINFO service. Exiting.\n")); |
971 | GNUNET_SCHEDULER_shutdown (); | 873 | GNUNET_SCHEDULER_shutdown (); |
972 | return; | 874 | return; |
973 | } | 875 | } |
@@ -980,51 +882,50 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
980 | { | 882 | { |
981 | max_fd_rlimit = r_file.rlim_cur; | 883 | max_fd_rlimit = r_file.rlim_cur; |
982 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
983 | "Maximum number of open files was: %u/%u\n", | 885 | "Maximum number of open files was: %u/%u\n", |
984 | r_file.rlim_cur, | 886 | r_file.rlim_cur, |
985 | r_file.rlim_max); | 887 | r_file.rlim_max); |
986 | } | 888 | } |
987 | max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ | 889 | max_fd_rlimit = (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ |
988 | #endif | 890 | #endif |
989 | GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD", &max_fd_cfg); | 891 | GNUNET_CONFIGURATION_get_value_number (GST_cfg, "transport", "MAX_FD", |
892 | &max_fd_cfg); | ||
990 | 893 | ||
991 | if (max_fd_cfg > max_fd_rlimit) | 894 | if (max_fd_cfg > max_fd_rlimit) |
992 | max_fd = max_fd_cfg; | 895 | max_fd = max_fd_cfg; |
993 | else | 896 | else |
994 | max_fd = max_fd_rlimit; | 897 | max_fd = max_fd_rlimit; |
995 | if (max_fd < DEFAULT_MAX_FDS) | 898 | if (max_fd < DEFAULT_MAX_FDS) |
996 | max_fd = DEFAULT_MAX_FDS; | 899 | max_fd = DEFAULT_MAX_FDS; |
997 | 900 | ||
998 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 901 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
999 | "Limiting number of sockets to %u: validation %u, neighbors: %u\n", | 902 | "Limiting number of sockets to %u: validation %u, neighbors: %u\n", |
1000 | max_fd, (max_fd / 3) , (max_fd / 3) * 2); | 903 | max_fd, (max_fd / 3), (max_fd / 3) * 2); |
1001 | 904 | ||
1002 | friend_only = GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology","FRIENDS-ONLY"); | 905 | friend_only = GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", |
906 | "FRIENDS-ONLY"); | ||
1003 | if (GNUNET_SYSERR == friend_only) | 907 | if (GNUNET_SYSERR == friend_only) |
1004 | friend_only = GNUNET_NO; /* According to topology defaults */ | 908 | friend_only = GNUNET_NO; /* According to topology defaults */ |
1005 | /* start subsystems */ | 909 | /* start subsystems */ |
1006 | GST_hello_start (friend_only, &process_hello_update, NULL); | 910 | GST_hello_start (friend_only, &process_hello_update, NULL ); |
1007 | GNUNET_assert (NULL != GST_hello_get()); | 911 | GNUNET_assert(NULL != GST_hello_get()); |
1008 | GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity); | 912 | GST_blacklist_start (GST_server, GST_cfg, &GST_my_identity); |
1009 | GST_ats = | 913 | GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, |
1010 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | 914 | NULL ); |
1011 | GST_manipulation_init (GST_cfg); | 915 | GST_manipulation_init (GST_cfg); |
1012 | GST_plugins_load (&GST_manipulation_recv, | 916 | GST_plugins_load (&GST_manipulation_recv, |
1013 | &plugin_env_address_change_notification, | 917 | &plugin_env_address_change_notification, |
1014 | &plugin_env_session_start, | 918 | &plugin_env_session_start, |
1015 | &plugin_env_session_end, | 919 | &plugin_env_session_end, |
1016 | &plugin_env_address_to_type, | 920 | &plugin_env_address_to_type, |
1017 | &plugin_env_update_metrics); | 921 | &plugin_env_update_metrics); |
1018 | GST_neighbours_start (NULL, | 922 | GST_neighbours_start (NULL, &neighbours_connect_notification, |
1019 | &neighbours_connect_notification, | 923 | &neighbours_disconnect_notification, &neighbours_changed_notification, |
1020 | &neighbours_disconnect_notification, | 924 | (max_fd / 3) * 2); |
1021 | &neighbours_changed_notification, | ||
1022 | (max_fd / 3) * 2); | ||
1023 | GST_clients_start (GST_server); | 925 | GST_clients_start (GST_server); |
1024 | GST_validation_start ((max_fd / 3)); | 926 | GST_validation_start ((max_fd / 3)); |
1025 | } | 927 | } |
1026 | 928 | ||
1027 | |||
1028 | /** | 929 | /** |
1029 | * The main function for the transport service. | 930 | * The main function for the transport service. |
1030 | * | 931 | * |
@@ -1033,11 +934,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1033 | * @return 0 ok, 1 on error | 934 | * @return 0 ok, 1 on error |
1034 | */ | 935 | */ |
1035 | int | 936 | int |
1036 | main (int argc, char *const *argv) | 937 | main (int argc, char * const *argv) |
1037 | { | 938 | { |
1038 | return (GNUNET_OK == | 939 | return |
1039 | GNUNET_SERVICE_run (argc, argv, "transport", | 940 | (GNUNET_OK |
1040 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 941 | == GNUNET_SERVICE_run (argc, argv, "transport", |
942 | GNUNET_SERVICE_OPTION_NONE, &run, NULL )) ? 0 : 1; | ||
1041 | } | 943 | } |
1042 | 944 | ||
1043 | /* end of file gnunet-service-transport.c */ | 945 | /* end of file gnunet-service-transport.c */ |
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h index 75b387381..34ed61f9e 100644 --- a/src/transport/gnunet-service-transport.h +++ b/src/transport/gnunet-service-transport.h | |||
@@ -72,12 +72,12 @@ extern struct GNUNET_ATS_SchedulingHandle *GST_ats; | |||
72 | */ | 72 | */ |
73 | typedef void | 73 | typedef void |
74 | (*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls, | 74 | (*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls, |
75 | const struct GNUNET_PeerIdentity *peer, | 75 | const struct GNUNET_PeerIdentity *peer, |
76 | const struct GNUNET_HELLO_Address *address, | 76 | const struct GNUNET_HELLO_Address *address, |
77 | enum GNUNET_TRANSPORT_PeerState state, | 77 | enum GNUNET_TRANSPORT_PeerState state, |
78 | struct GNUNET_TIME_Absolute state_timeout, | 78 | struct GNUNET_TIME_Absolute state_timeout, |
79 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 79 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
80 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); | 80 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); |
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
@@ -103,11 +103,9 @@ typedef void | |||
103 | */ | 103 | */ |
104 | struct GNUNET_TIME_Relative | 104 | struct GNUNET_TIME_Relative |
105 | GST_receive_callback (void *cls, | 105 | GST_receive_callback (void *cls, |
106 | const struct GNUNET_PeerIdentity *peer, | 106 | const struct GNUNET_HELLO_Address *address, |
107 | const struct GNUNET_MessageHeader *message, | 107 | struct Session *session, |
108 | struct Session *session, | 108 | const struct GNUNET_MessageHeader *message); |
109 | const char *sender_address, | ||
110 | uint16_t sender_address_len); | ||
111 | 109 | ||
112 | 110 | ||
113 | /** | 111 | /** |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 1fbd56c24..ca7a40539 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -885,8 +885,10 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer | |||
885 | msg->peer = *peer; | 885 | msg->peer = *peer; |
886 | msg->addrlen = htonl (alen); | 886 | msg->addrlen = htonl (alen); |
887 | msg->pluginlen = htonl (tlen); | 887 | msg->pluginlen = htonl (tlen); |
888 | |||
888 | if (NULL != address) | 889 | if (NULL != address) |
889 | { | 890 | { |
891 | msg->local_address_info = htonl((uint32_t) address->local_info); | ||
890 | addr = (char *) &msg[1]; | 892 | addr = (char *) &msg[1]; |
891 | memcpy (addr, address->address, alen); | 893 | memcpy (addr, address->address, alen); |
892 | memcpy (&addr[alen], address->transport_name, tlen); | 894 | memcpy (&addr[alen], address->transport_name, tlen); |
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index 4521047c9..06171d306 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c | |||
@@ -529,9 +529,10 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_PeerIdentity *peer, | |||
529 | * @return manipulated delay for next receive | 529 | * @return manipulated delay for next receive |
530 | */ | 530 | */ |
531 | struct GNUNET_TIME_Relative | 531 | struct GNUNET_TIME_Relative |
532 | GST_manipulation_recv(void *cls, const struct GNUNET_PeerIdentity *peer, | 532 | GST_manipulation_recv (void *cls, |
533 | const struct GNUNET_MessageHeader *message, struct Session *session, | 533 | const struct GNUNET_HELLO_Address *address, |
534 | const char *sender_address, uint16_t sender_address_len) | 534 | struct Session *session, |
535 | const struct GNUNET_MessageHeader *message) | ||
535 | { | 536 | { |
536 | struct TM_Peer *tmp; | 537 | struct TM_Peer *tmp; |
537 | uint32_t p_recv_delay; | 538 | uint32_t p_recv_delay; |
@@ -547,7 +548,7 @@ GST_manipulation_recv(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
547 | else | 548 | else |
548 | m_delay = GNUNET_TIME_UNIT_ZERO; | 549 | m_delay = GNUNET_TIME_UNIT_ZERO; |
549 | 550 | ||
550 | if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer))) | 551 | if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, &address->peer))) |
551 | { | 552 | { |
552 | /* Manipulate receive delay */ | 553 | /* Manipulate receive delay */ |
553 | p_recv_delay = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_RECEIVE); | 554 | p_recv_delay = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_RECEIVE); |
@@ -555,14 +556,15 @@ GST_manipulation_recv(void *cls, const struct GNUNET_PeerIdentity *peer, | |||
555 | m_delay.rel_value_us = p_recv_delay; /* Peer specific delay */ | 556 | m_delay.rel_value_us = p_recv_delay; /* Peer specific delay */ |
556 | } | 557 | } |
557 | 558 | ||
558 | quota_delay = GST_receive_callback(cls, peer, message, session, | 559 | quota_delay = GST_receive_callback(cls, address, session, message); |
559 | sender_address, sender_address_len); | ||
560 | 560 | ||
561 | if (quota_delay.rel_value_us > m_delay.rel_value_us) | 561 | if (quota_delay.rel_value_us > m_delay.rel_value_us) |
562 | m_delay = quota_delay; | 562 | m_delay = quota_delay; |
563 | 563 | ||
564 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 564 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
565 | "Delaying next receive for peer `%s' for %s\n", GNUNET_i2s (peer), GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES)); | 565 | "Delaying next receive for peer `%s' for %s\n", |
566 | GNUNET_i2s (&address->peer), | ||
567 | GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES)); | ||
566 | return m_delay; | 568 | return m_delay; |
567 | 569 | ||
568 | } | 570 | } |
diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h index 4fe68ade1..3b6beb8b7 100644 --- a/src/transport/gnunet-service-transport_manipulation.h +++ b/src/transport/gnunet-service-transport_manipulation.h | |||
@@ -79,11 +79,9 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target, | |||
79 | */ | 79 | */ |
80 | struct GNUNET_TIME_Relative | 80 | struct GNUNET_TIME_Relative |
81 | GST_manipulation_recv (void *cls, | 81 | GST_manipulation_recv (void *cls, |
82 | const struct GNUNET_PeerIdentity *peer, | 82 | const struct GNUNET_HELLO_Address *address, |
83 | const struct GNUNET_MessageHeader *message, | 83 | struct Session *session, |
84 | struct Session *session, | 84 | const struct GNUNET_MessageHeader *message); |
85 | const char *sender_address, | ||
86 | uint16_t sender_address_len); | ||
87 | 85 | ||
88 | /** | 86 | /** |
89 | * Function that will be called to manipulate ATS information according to | 87 | * Function that will be called to manipulate ATS information according to |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index a386d7de0..af59b5fec 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -2300,11 +2300,11 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | |||
2300 | return; | 2300 | return; |
2301 | } | 2301 | } |
2302 | 2302 | ||
2303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2303 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2304 | "ATS tells us to switch to address '%s/%s' session %p for " | 2304 | "ATS tells us to switch to %s address '%s' session %p for " |
2305 | "peer `%s' in state %s/%d (quota in/out %u %u )\n", | 2305 | "peer `%s' in state %s/%d (quota in/out %u %u )\n", |
2306 | (address->address_length != 0) ? GST_plugins_a2s (address): "<inbound>", | 2306 | (GNUNET_HELLO_ADDRESS_INFO_INBOUND == (GNUNET_HELLO_ADDRESS_INFO_INBOUND & address->local_info)) ? "inbound" : "", |
2307 | address->transport_name, | 2307 | GST_plugins_a2s (address), |
2308 | session, | 2308 | session, |
2309 | GNUNET_i2s (peer), | 2309 | GNUNET_i2s (peer), |
2310 | GNUNET_TRANSPORT_p2s (n->state), | 2310 | GNUNET_TRANSPORT_p2s (n->state), |
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index c86bf67ff..80953e5ea 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c | |||
@@ -986,6 +986,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, | |||
986 | addrend++; | 986 | addrend++; |
987 | slen = strlen (addr) + 1; | 987 | slen = strlen (addr) + 1; |
988 | alen -= slen; | 988 | alen -= slen; |
989 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | ||
989 | address.address = addrend; | 990 | address.address = addrend; |
990 | address.address_length = alen; | 991 | address.address_length = alen; |
991 | address.transport_name = addr; | 992 | address.transport_name = addr; |
@@ -1298,6 +1299,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, | |||
1298 | address.address = addr; | 1299 | address.address = addr; |
1299 | address.address_length = addrlen; | 1300 | address.address_length = addrlen; |
1300 | address.transport_name = tname; | 1301 | address.transport_name = tname; |
1302 | address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; | ||
1301 | ve = find_validation_entry (NULL, &address); | 1303 | ve = find_validation_entry (NULL, &address); |
1302 | if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) | 1304 | if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) |
1303 | { | 1305 | { |
diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c index a7d3cf3f5..f301d55b3 100644 --- a/src/transport/plugin_transport_bluetooth.c +++ b/src/transport/plugin_transport_bluetooth.c | |||
@@ -355,7 +355,9 @@ struct MacEndpoint | |||
355 | /** | 355 | /** |
356 | * peer mac address | 356 | * peer mac address |
357 | */ | 357 | */ |
358 | struct WlanAddress addr; | 358 | //struct WlanAddress addr; |
359 | |||
360 | struct GNUNET_HELLO_Address *address; | ||
359 | 361 | ||
360 | /** | 362 | /** |
361 | * Message delay for fragmentation context | 363 | * Message delay for fragmentation context |
@@ -605,8 +607,8 @@ send_ack (void *cls, uint32_t msg_id, | |||
605 | get_radiotap_header (endpoint, radio_header, size); | 607 | get_radiotap_header (endpoint, radio_header, size); |
606 | get_wlan_header (endpoint->plugin, | 608 | get_wlan_header (endpoint->plugin, |
607 | &radio_header->frame, | 609 | &radio_header->frame, |
608 | &endpoint->addr.mac, | 610 | endpoint->address->address, |
609 | size); | 611 | endpoint->address->address_length); |
610 | memcpy (&radio_header[1], hdr, msize); | 612 | memcpy (&radio_header[1], hdr, msize); |
611 | if (NULL != | 613 | if (NULL != |
612 | GNUNET_HELPER_send (endpoint->plugin->suid_helper, | 614 | GNUNET_HELPER_send (endpoint->plugin->suid_helper, |
@@ -742,7 +744,7 @@ create_session (struct MacEndpoint *endpoint, | |||
742 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 744 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
743 | "Created new session for peer `%s' with endpoint %s\n", | 745 | "Created new session for peer `%s' with endpoint %s\n", |
744 | GNUNET_i2s (peer), | 746 | GNUNET_i2s (peer), |
745 | mac_to_string (&endpoint->addr.mac)); | 747 | mac_to_string (endpoint->address->address)); |
746 | return session; | 748 | return session; |
747 | } | 749 | } |
748 | 750 | ||
@@ -793,8 +795,8 @@ transmit_fragment (void *cls, | |||
793 | get_radiotap_header (endpoint, radio_header, size); | 795 | get_radiotap_header (endpoint, radio_header, size); |
794 | get_wlan_header (endpoint->plugin, | 796 | get_wlan_header (endpoint->plugin, |
795 | &radio_header->frame, | 797 | &radio_header->frame, |
796 | &endpoint->addr.mac, | 798 | endpoint->address->address, |
797 | size); | 799 | endpoint->address->address_length); |
798 | memcpy (&radio_header[1], hdr, msize); | 800 | memcpy (&radio_header[1], hdr, msize); |
799 | GNUNET_assert (NULL == fm->sh); | 801 | GNUNET_assert (NULL == fm->sh); |
800 | fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, | 802 | fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, |
@@ -999,10 +1001,11 @@ create_macendpoint (struct Plugin *plugin, | |||
999 | struct MacEndpoint *pos; | 1001 | struct MacEndpoint *pos; |
1000 | 1002 | ||
1001 | for (pos = plugin->mac_head; NULL != pos; pos = pos->next) | 1003 | for (pos = plugin->mac_head; NULL != pos; pos = pos->next) |
1002 | if (0 == memcmp (addr, &pos->addr, sizeof (struct WlanAddress))) | 1004 | if (0 == memcmp (addr, &pos->address->address, sizeof (struct WlanAddress))) |
1003 | return pos; | 1005 | return pos; |
1004 | pos = GNUNET_new (struct MacEndpoint); | 1006 | pos = GNUNET_new (struct MacEndpoint); |
1005 | pos->addr = *addr; | 1007 | pos->address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, addr, |
1008 | sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1006 | pos->plugin = plugin; | 1009 | pos->plugin = plugin; |
1007 | pos->defrag = | 1010 | pos->defrag = |
1008 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, | 1011 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, |
@@ -1244,23 +1247,20 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1244 | "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", | 1247 | "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", |
1245 | (unsigned int) msize, | 1248 | (unsigned int) msize, |
1246 | GNUNET_i2s (&tmpsource), | 1249 | GNUNET_i2s (&tmpsource), |
1247 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1250 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address, |
1251 | mas->endpoint->address->address_length)); | ||
1248 | 1252 | ||
1249 | GNUNET_STATISTICS_update (plugin->env->stats, | 1253 | GNUNET_STATISTICS_update (plugin->env->stats, |
1250 | _("# HELLO messages received via Bluetooth"), 1, | 1254 | _("# HELLO messages received via Bluetooth"), 1, |
1251 | GNUNET_NO); | 1255 | GNUNET_NO); |
1252 | plugin->env->receive (plugin->env->cls, | 1256 | plugin->env->receive (plugin->env->cls, |
1253 | &tmpsource, | 1257 | mas->endpoint->address, |
1254 | hdr, | 1258 | mas->session, |
1255 | mas->session, | 1259 | hdr); |
1256 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | ||
1257 | (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); | ||
1258 | plugin->env->update_address_metrics (plugin->env->cls, | 1260 | plugin->env->update_address_metrics (plugin->env->cls, |
1259 | &tmpsource, | 1261 | mas->endpoint->address, |
1260 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | 1262 | mas->session, |
1261 | (mas->endpoint == NULL) ? 0 : sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress), | 1263 | &ats, 1); |
1262 | mas->session, | ||
1263 | &ats, 1); | ||
1264 | break; | 1264 | break; |
1265 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 1265 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
1266 | if (NULL == mas->endpoint) | 1266 | if (NULL == mas->endpoint) |
@@ -1271,7 +1271,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1271 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1271 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1272 | "Processing %u bytes of FRAGMENT from MAC %s\n", | 1272 | "Processing %u bytes of FRAGMENT from MAC %s\n", |
1273 | (unsigned int) msize, | 1273 | (unsigned int) msize, |
1274 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1274 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1275 | mas->endpoint->address->address_length)); | ||
1275 | GNUNET_STATISTICS_update (plugin->env->stats, | 1276 | GNUNET_STATISTICS_update (plugin->env->stats, |
1276 | _("# fragments received via Bluetooth"), 1, GNUNET_NO); | 1277 | _("# fragments received via Bluetooth"), 1, GNUNET_NO); |
1277 | (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, | 1278 | (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, |
@@ -1292,7 +1293,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1292 | { | 1293 | { |
1293 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1294 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1294 | "Got last ACK, finished message transmission to `%s' (%p)\n", | 1295 | "Got last ACK, finished message transmission to `%s' (%p)\n", |
1295 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress)), | 1296 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1297 | mas->endpoint->address->address_length), | ||
1296 | fm); | 1298 | fm); |
1297 | mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); | 1299 | mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); |
1298 | if (NULL != fm->cont) | 1300 | if (NULL != fm->cont) |
@@ -1307,13 +1309,15 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1307 | { | 1309 | { |
1308 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1310 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1309 | "Got an ACK, message transmission to `%s' not yet finished\n", | 1311 | "Got an ACK, message transmission to `%s' not yet finished\n", |
1310 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1312 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1313 | mas->endpoint->address->address_length)); | ||
1311 | break; | 1314 | break; |
1312 | } | 1315 | } |
1313 | } | 1316 | } |
1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1317 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1315 | "ACK not matched against any active fragmentation with MAC `%s'\n", | 1318 | "ACK not matched against any active fragmentation with MAC `%s'\n", |
1316 | bluetooth_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1319 | bluetooth_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1320 | mas->endpoint->address->address_length)); | ||
1317 | break; | 1321 | break; |
1318 | case GNUNET_MESSAGE_TYPE_WLAN_DATA: | 1322 | case GNUNET_MESSAGE_TYPE_WLAN_DATA: |
1319 | if (NULL == mas->endpoint) | 1323 | if (NULL == mas->endpoint) |
@@ -1373,17 +1377,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1373 | (unsigned int) ntohs (hdr->type), | 1377 | (unsigned int) ntohs (hdr->type), |
1374 | GNUNET_i2s (&mas->session->target)); | 1378 | GNUNET_i2s (&mas->session->target)); |
1375 | plugin->env->receive (plugin->env->cls, | 1379 | plugin->env->receive (plugin->env->cls, |
1376 | &mas->session->target, | 1380 | mas->endpoint->address, |
1377 | hdr, | ||
1378 | mas->session, | 1381 | mas->session, |
1379 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | 1382 | hdr); |
1380 | (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress)); | ||
1381 | plugin->env->update_address_metrics (plugin->env->cls, | 1383 | plugin->env->update_address_metrics (plugin->env->cls, |
1382 | &mas->session->target, | 1384 | mas->endpoint->address, |
1383 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | 1385 | mas->session, |
1384 | (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress), | 1386 | &ats, 1); |
1385 | mas->session, | ||
1386 | &ats, 1); | ||
1387 | break; | 1387 | break; |
1388 | } | 1388 | } |
1389 | return GNUNET_OK; | 1389 | return GNUNET_OK; |
@@ -1402,6 +1402,7 @@ handle_helper_message (void *cls, void *client, | |||
1402 | const struct GNUNET_MessageHeader *hdr) | 1402 | const struct GNUNET_MessageHeader *hdr) |
1403 | { | 1403 | { |
1404 | struct Plugin *plugin = cls; | 1404 | struct Plugin *plugin = cls; |
1405 | struct GNUNET_HELLO_Address *address; | ||
1405 | const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; | 1406 | const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; |
1406 | const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; | 1407 | const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; |
1407 | struct WlanAddress wa; | 1408 | struct WlanAddress wa; |
@@ -1428,24 +1429,26 @@ handle_helper_message (void *cls, void *client, | |||
1428 | memset (&wa, 0, sizeof (struct WlanAddress)); | 1429 | memset (&wa, 0, sizeof (struct WlanAddress)); |
1429 | wa.mac = plugin->mac_address; | 1430 | wa.mac = plugin->mac_address; |
1430 | wa.options = htonl(plugin->options); | 1431 | wa.options = htonl(plugin->options); |
1431 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, | 1432 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1432 | &wa, | 1433 | PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); |
1433 | sizeof (wa), | 1434 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); |
1434 | "bluetooth"); | 1435 | GNUNET_HELLO_address_free (address); |
1435 | } | 1436 | } |
1436 | plugin->mac_address = cm->mac; | 1437 | plugin->mac_address = cm->mac; |
1437 | plugin->have_mac = GNUNET_YES; | 1438 | plugin->have_mac = GNUNET_YES; |
1438 | memset (&wa, 0, sizeof (struct WlanAddress)); | 1439 | memset (&wa, 0, sizeof (struct WlanAddress)); |
1439 | wa.mac = plugin->mac_address; | 1440 | wa.mac = plugin->mac_address; |
1440 | wa.options = htonl(plugin->options); | 1441 | wa.options = htonl(plugin->options); |
1442 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | ||
1443 | PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1444 | |||
1441 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1445 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1442 | "Received BT_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", | 1446 | "Received BT_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", |
1443 | mac_to_string (&cm->mac), | 1447 | mac_to_string (&cm->mac), |
1444 | GNUNET_i2s (plugin->env->my_identity)); | 1448 | GNUNET_i2s (plugin->env->my_identity)); |
1445 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, | 1449 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); |
1446 | &wa, | 1450 | GNUNET_HELLO_address_free (address); |
1447 | sizeof (struct WlanAddress), | 1451 | |
1448 | "bluetooth"); | ||
1449 | break; | 1452 | break; |
1450 | case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: | 1453 | case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: |
1451 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1454 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1682,7 +1685,8 @@ bluetooth_plugin_address_pretty_printer (void *cls, const char *type, | |||
1682 | void * | 1685 | void * |
1683 | libgnunet_plugin_transport_bluetooth_done (void *cls) | 1686 | libgnunet_plugin_transport_bluetooth_done (void *cls) |
1684 | { | 1687 | { |
1685 | struct WlanAddress wa; | 1688 | struct WlanAddress wa; |
1689 | struct GNUNET_HELLO_Address *address; | ||
1686 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1690 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1687 | struct Plugin *plugin = api->cls; | 1691 | struct Plugin *plugin = api->cls; |
1688 | struct MacEndpoint *endpoint; | 1692 | struct MacEndpoint *endpoint; |
@@ -1696,14 +1700,17 @@ libgnunet_plugin_transport_bluetooth_done (void *cls) | |||
1696 | 1700 | ||
1697 | if (GNUNET_YES == plugin->have_mac) | 1701 | if (GNUNET_YES == plugin->have_mac) |
1698 | { | 1702 | { |
1699 | memset (&wa, 0, sizeof (wa)); | 1703 | memset (&wa, 0, sizeof(wa)); |
1700 | wa.options = htonl (plugin->options); | 1704 | wa.options = htonl (plugin->options); |
1701 | wa.mac = plugin->mac_address; | 1705 | wa.mac = plugin->mac_address; |
1702 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, | 1706 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1703 | &wa, | 1707 | PLUGIN_NAME, &wa, sizeof (struct WlanAddress), |
1704 | sizeof (struct WlanAddress), | 1708 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1705 | "bluetooth"); | 1709 | |
1706 | plugin->have_mac = GNUNET_NO; | 1710 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); |
1711 | plugin->have_mac = GNUNET_NO; | ||
1712 | |||
1713 | GNUNET_HELLO_address_free (address); | ||
1707 | } | 1714 | } |
1708 | 1715 | ||
1709 | if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task) | 1716 | if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task) |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index ba7fd45a3..bd4487614 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -155,12 +155,7 @@ struct Session | |||
155 | /** | 155 | /** |
156 | * Address | 156 | * Address |
157 | */ | 157 | */ |
158 | struct HttpAddress *addr; | 158 | struct GNUNET_HELLO_Address *address; |
159 | |||
160 | /** | ||
161 | * Address length | ||
162 | */ | ||
163 | size_t addrlen; | ||
164 | 159 | ||
165 | /** | 160 | /** |
166 | * ATS network type in NBO | 161 | * ATS network type in NBO |
@@ -587,7 +582,7 @@ client_delete_session (struct Session *s) | |||
587 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 582 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
588 | s->msg_tk = NULL; | 583 | s->msg_tk = NULL; |
589 | } | 584 | } |
590 | GNUNET_free (s->addr); | 585 | GNUNET_HELLO_address_free (s->address); |
591 | GNUNET_free (s->url); | 586 | GNUNET_free (s->url); |
592 | GNUNET_free (s); | 587 | GNUNET_free (s); |
593 | } | 588 | } |
@@ -761,10 +756,11 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, | |||
761 | struct Session *pos; | 756 | struct Session *pos; |
762 | 757 | ||
763 | for (pos = plugin->head; NULL != pos; pos = pos->next) | 758 | for (pos = plugin->head; NULL != pos; pos = pos->next) |
759 | { | ||
764 | if ((0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) && | 760 | if ((0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) && |
765 | (address->address_length == pos->addrlen) && | 761 | (0 == GNUNET_HELLO_address_cmp(address, pos->address))) |
766 | (0 == memcmp (address->address, pos->addr, pos->addrlen))) | ||
767 | return pos; | 762 | return pos; |
763 | } | ||
768 | return NULL; | 764 | return NULL; |
769 | } | 765 | } |
770 | 766 | ||
@@ -923,14 +919,10 @@ client_receive_mst_cb (void *cls, void *client, | |||
923 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 919 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
924 | atsi.value = s->ats_address_network_type; | 920 | atsi.value = s->ats_address_network_type; |
925 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); | 921 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); |
926 | delay = s->plugin->env->receive (plugin->env->cls, &s->target, message, | ||
927 | s, (const char *) s->addr, s->addrlen); | ||
928 | 922 | ||
923 | delay = s->plugin->env->receive (plugin->env->cls, s->address, s, message); | ||
929 | plugin->env->update_address_metrics (plugin->env->cls, | 924 | plugin->env->update_address_metrics (plugin->env->cls, |
930 | &s->target, | 925 | s->address, s, |
931 | s->addr, | ||
932 | s->addrlen, | ||
933 | s, | ||
934 | &atsi, 1); | 926 | &atsi, 1); |
935 | 927 | ||
936 | GNUNET_asprintf (&stat_txt, | 928 | GNUNET_asprintf (&stat_txt, |
@@ -949,8 +941,8 @@ client_receive_mst_cb (void *cls, void *client, | |||
949 | "Client: peer `%s' address `%s' next read delayed for %s\n", | 941 | "Client: peer `%s' address `%s' next read delayed for %s\n", |
950 | GNUNET_i2s (&s->target), | 942 | GNUNET_i2s (&s->target), |
951 | http_common_plugin_address_to_string (NULL, | 943 | http_common_plugin_address_to_string (NULL, |
952 | s->plugin->protocol, | 944 | s->plugin->protocol, s->address->address, |
953 | s->addr, s->addrlen), | 945 | s->address->address_length), |
954 | GNUNET_STRINGS_relative_time_to_string (delay, | 946 | GNUNET_STRINGS_relative_time_to_string (delay, |
955 | GNUNET_YES)); | 947 | GNUNET_YES)); |
956 | } | 948 | } |
@@ -1241,8 +1233,8 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1241 | static int | 1233 | static int |
1242 | client_connect_get (struct Session *s) | 1234 | client_connect_get (struct Session *s) |
1243 | { | 1235 | { |
1244 | |||
1245 | CURLMcode mret; | 1236 | CURLMcode mret; |
1237 | |||
1246 | /* create get connection */ | 1238 | /* create get connection */ |
1247 | s->client_get = curl_easy_init (); | 1239 | s->client_get = curl_easy_init (); |
1248 | s->get.s = s; | 1240 | s->get.s = s; |
@@ -1254,16 +1246,21 @@ client_connect_get (struct Session *s) | |||
1254 | #endif | 1246 | #endif |
1255 | #if BUILD_HTTPS | 1247 | #if BUILD_HTTPS |
1256 | curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 1248 | curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
1257 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == | ||
1258 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | ||
1259 | { | 1249 | { |
1260 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L); | 1250 | struct HttpAddress *ha; |
1261 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L); | 1251 | ha = (struct HttpAddress *) s->address->address; |
1262 | } | 1252 | |
1263 | else | 1253 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == |
1264 | { | 1254 | (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
1265 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); | 1255 | { |
1266 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); | 1256 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L); |
1257 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L); | ||
1258 | } | ||
1259 | else | ||
1260 | { | ||
1261 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); | ||
1262 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); | ||
1263 | } | ||
1267 | } | 1264 | } |
1268 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); | 1265 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); |
1269 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); | 1266 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); |
@@ -1334,16 +1331,21 @@ client_connect_put (struct Session *s) | |||
1334 | #endif | 1331 | #endif |
1335 | #if BUILD_HTTPS | 1332 | #if BUILD_HTTPS |
1336 | curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 1333 | curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
1337 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == | ||
1338 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | ||
1339 | { | 1334 | { |
1340 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L); | 1335 | struct HttpAddress *ha; |
1341 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L); | 1336 | ha = (struct HttpAddress *) s->address->address; |
1342 | } | 1337 | |
1343 | else | 1338 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == |
1344 | { | 1339 | (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
1345 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); | 1340 | { |
1346 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); | 1341 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L); |
1342 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L); | ||
1343 | } | ||
1344 | else | ||
1345 | { | ||
1346 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); | ||
1347 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); | ||
1348 | } | ||
1347 | } | 1349 | } |
1348 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); | 1350 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); |
1349 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); | 1351 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); |
@@ -1403,8 +1405,7 @@ client_connect (struct Session *s) | |||
1403 | 1405 | ||
1404 | /* create url */ | 1406 | /* create url */ |
1405 | if (NULL == http_common_plugin_address_to_string (NULL, | 1407 | if (NULL == http_common_plugin_address_to_string (NULL, |
1406 | plugin->protocol, | 1408 | plugin->protocol, s->address->address, s->address->address_length)) |
1407 | s->addr, s->addrlen)) | ||
1408 | { | 1409 | { |
1409 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1410 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1410 | plugin->name, | 1411 | plugin->name, |
@@ -1414,7 +1415,8 @@ client_connect (struct Session *s) | |||
1414 | } | 1415 | } |
1415 | 1416 | ||
1416 | GNUNET_asprintf (&s->url, "%s/%s;%u", | 1417 | GNUNET_asprintf (&s->url, "%s/%s;%u", |
1417 | http_common_plugin_address_to_url (NULL, s->addr, s->addrlen), | 1418 | http_common_plugin_address_to_url (NULL, s->address->address, |
1419 | s->address->address_length), | ||
1418 | GNUNET_i2s_full (plugin->env->my_identity), | 1420 | GNUNET_i2s_full (plugin->env->my_identity), |
1419 | plugin->last_tag); | 1421 | plugin->last_tag); |
1420 | 1422 | ||
@@ -1567,9 +1569,7 @@ http_client_plugin_get_session (void *cls, | |||
1567 | s = GNUNET_new (struct Session); | 1569 | s = GNUNET_new (struct Session); |
1568 | s->target = address->peer; | 1570 | s->target = address->peer; |
1569 | s->plugin = plugin; | 1571 | s->plugin = plugin; |
1570 | s->addr = GNUNET_malloc (address->address_length); | 1572 | s->address = GNUNET_HELLO_address_copy (address); |
1571 | memcpy (s->addr, address->address, address->address_length); | ||
1572 | s->addrlen = address->address_length; | ||
1573 | s->ats_address_network_type = ats.value; | 1573 | s->ats_address_network_type = ats.value; |
1574 | s->put_paused = GNUNET_NO; | 1574 | s->put_paused = GNUNET_NO; |
1575 | s->put_tmp_disconnecting = GNUNET_NO; | 1575 | s->put_tmp_disconnecting = GNUNET_NO; |
@@ -1579,8 +1579,9 @@ http_client_plugin_get_session (void *cls, | |||
1579 | s); | 1579 | s); |
1580 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1580 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1581 | "Created new session %p for `%s' address `%s''\n", | 1581 | "Created new session %p for `%s' address `%s''\n", |
1582 | s, | 1582 | s, http_common_plugin_address_to_string (NULL, |
1583 | http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen), | 1583 | plugin->protocol, s->address->address, |
1584 | s->address->address_length), | ||
1584 | GNUNET_i2s (&s->target)); | 1585 | GNUNET_i2s (&s->target)); |
1585 | 1586 | ||
1586 | /* add new session */ | 1587 | /* add new session */ |
@@ -1591,7 +1592,9 @@ http_client_plugin_get_session (void *cls, | |||
1591 | { | 1592 | { |
1592 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, | 1593 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, |
1593 | "Cannot connect to peer `%s' address `%s''\n", | 1594 | "Cannot connect to peer `%s' address `%s''\n", |
1594 | http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen), | 1595 | http_common_plugin_address_to_string (NULL, |
1596 | plugin->protocol, s->address->address, | ||
1597 | s->address->address_length), | ||
1595 | GNUNET_i2s (&s->target)); | 1598 | GNUNET_i2s (&s->target)); |
1596 | client_delete_session (s); | 1599 | client_delete_session (s); |
1597 | return NULL; | 1600 | return NULL; |
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h index 473516502..c3fa1bba4 100644 --- a/src/transport/plugin_transport_http_common.h +++ b/src/transport/plugin_transport_http_common.h | |||
@@ -59,7 +59,7 @@ | |||
59 | #define HTTP_DEFAULT_PORT 80 | 59 | #define HTTP_DEFAULT_PORT 80 |
60 | #define HTTPS_DEFAULT_PORT 443 | 60 | #define HTTPS_DEFAULT_PORT 443 |
61 | 61 | ||
62 | enum HTTP_OPTIONS | 62 | enum HTTP_ADDRESS_OPTIONS |
63 | { | 63 | { |
64 | HTTP_OPTIONS_NONE = 0, | 64 | HTTP_OPTIONS_NONE = 0, |
65 | HTTP_OPTIONS_VERIFY_CERTIFICATE = 1 | 65 | HTTP_OPTIONS_VERIFY_CERTIFICATE = 1 |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 15c0323c6..bdc1074ed 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -113,12 +113,7 @@ struct Session | |||
113 | /** | 113 | /** |
114 | * Address | 114 | * Address |
115 | */ | 115 | */ |
116 | void *addr; | 116 | struct GNUNET_HELLO_Address *address; |
117 | |||
118 | /** | ||
119 | * Address length | ||
120 | */ | ||
121 | size_t addrlen; | ||
122 | 117 | ||
123 | /** | 118 | /** |
124 | * Unique HTTP/S connection tag for this connection | 119 | * Unique HTTP/S connection tag for this connection |
@@ -263,7 +258,7 @@ struct HTTP_Server_Plugin | |||
263 | * External hostname the plugin can be connected to, can be different to | 258 | * External hostname the plugin can be connected to, can be different to |
264 | * the host's FQDN, used e.g. for reverse proxying | 259 | * the host's FQDN, used e.g. for reverse proxying |
265 | */ | 260 | */ |
266 | struct HttpAddress *ext_addr; | 261 | struct GNUNET_HELLO_Address *ext_addr; |
267 | 262 | ||
268 | /** | 263 | /** |
269 | * Notify transport only about external address | 264 | * Notify transport only about external address |
@@ -271,11 +266,6 @@ struct HTTP_Server_Plugin | |||
271 | unsigned int external_only; | 266 | unsigned int external_only; |
272 | 267 | ||
273 | /** | 268 | /** |
274 | * External address length | ||
275 | */ | ||
276 | size_t ext_addr_len; | ||
277 | |||
278 | /** | ||
279 | * use IPv6 | 269 | * use IPv6 |
280 | */ | 270 | */ |
281 | uint16_t use_ipv6; | 271 | uint16_t use_ipv6; |
@@ -668,8 +658,8 @@ http_server_plugin_address_suggested (void *cls, | |||
668 | 658 | ||
669 | if ((NULL != plugin->ext_addr) && | 659 | if ((NULL != plugin->ext_addr) && |
670 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, | 660 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, |
671 | plugin->ext_addr, | 661 | plugin->ext_addr->address, |
672 | plugin->ext_addr_len))) | 662 | plugin->ext_addr->address_length))) |
673 | { | 663 | { |
674 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ | 664 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ |
675 | if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != | 665 | if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != |
@@ -743,7 +733,7 @@ server_delete_session (void *cls, | |||
743 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 733 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
744 | s->msg_tk = NULL; | 734 | s->msg_tk = NULL; |
745 | } | 735 | } |
746 | GNUNET_free (s->addr); | 736 | GNUNET_HELLO_address_free (s->address); |
747 | GNUNET_free_non_null (s->server_recv); | 737 | GNUNET_free_non_null (s->server_recv); |
748 | GNUNET_free_non_null (s->server_send); | 738 | GNUNET_free_non_null (s->server_send); |
749 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 739 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1082,10 +1072,11 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1082 | struct Session *s = NULL; | 1072 | struct Session *s = NULL; |
1083 | struct ServerConnection *sc = NULL; | 1073 | struct ServerConnection *sc = NULL; |
1084 | const union MHD_ConnectionInfo *conn_info; | 1074 | const union MHD_ConnectionInfo *conn_info; |
1085 | struct GNUNET_ATS_Information ats; | ||
1086 | struct HttpAddress *addr; | 1075 | struct HttpAddress *addr; |
1087 | size_t addr_len; | 1076 | |
1077 | struct GNUNET_ATS_Information ats; | ||
1088 | struct GNUNET_PeerIdentity target; | 1078 | struct GNUNET_PeerIdentity target; |
1079 | size_t addr_len; | ||
1089 | uint32_t tag = 0; | 1080 | uint32_t tag = 0; |
1090 | int direction = GNUNET_SYSERR; | 1081 | int direction = GNUNET_SYSERR; |
1091 | unsigned int to; | 1082 | unsigned int to; |
@@ -1175,8 +1166,8 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1175 | s = GNUNET_new (struct Session); | 1166 | s = GNUNET_new (struct Session); |
1176 | memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); | 1167 | memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); |
1177 | s->plugin = plugin; | 1168 | s->plugin = plugin; |
1178 | s->addr = addr; | 1169 | s->address = GNUNET_HELLO_address_allocate (&s->target, PLUGIN_NAME, |
1179 | s->addrlen = addr_len; | 1170 | addr, addr_len, GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
1180 | s->ats_address_network_type = ats.value; | 1171 | s->ats_address_network_type = ats.value; |
1181 | s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; | 1172 | s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; |
1182 | s->tag = tag; | 1173 | s->tag = tag; |
@@ -1212,7 +1203,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1212 | if ((NULL != s->server_send) && (NULL != s->server_recv)) | 1203 | if ((NULL != s->server_send) && (NULL != s->server_recv)) |
1213 | { | 1204 | { |
1214 | s->connect_in_progress = GNUNET_NO; /* PUT and GET are connected */ | 1205 | s->connect_in_progress = GNUNET_NO; /* PUT and GET are connected */ |
1215 | plugin->env->session_start (NULL, &s->target, PLUGIN_NAME, NULL, 0 ,s, NULL, 0); | 1206 | plugin->env->session_start (NULL, s->address ,s, NULL, 0); |
1216 | } | 1207 | } |
1217 | 1208 | ||
1218 | if ((NULL == s->server_recv) || (NULL == s->server_send)) | 1209 | if ((NULL == s->server_recv) || (NULL == s->server_send)) |
@@ -1353,15 +1344,8 @@ server_receive_mst_cb (void *cls, void *client, | |||
1353 | atsi.value = s->ats_address_network_type; | 1344 | atsi.value = s->ats_address_network_type; |
1354 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); | 1345 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); |
1355 | 1346 | ||
1356 | 1347 | delay = plugin->env->receive (plugin->env->cls, s->address, s, message); | |
1357 | delay = plugin->env->receive (plugin->env->cls, | 1348 | plugin->env->update_address_metrics (plugin->env->cls, s->address, s, &atsi, 1); |
1358 | &s->target, | ||
1359 | message, | ||
1360 | s, NULL, 0); | ||
1361 | |||
1362 | plugin->env->update_address_metrics (plugin->env->cls, | ||
1363 | &s->target, | ||
1364 | NULL, 0, s, &atsi, 1); | ||
1365 | 1349 | ||
1366 | GNUNET_asprintf (&stat_txt, "# bytes received via %s_server", plugin->protocol); | 1350 | GNUNET_asprintf (&stat_txt, "# bytes received via %s_server", plugin->protocol); |
1367 | GNUNET_STATISTICS_update (plugin->env->stats, | 1351 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -1376,8 +1360,8 @@ server_receive_mst_cb (void *cls, void *client, | |||
1376 | "Peer `%s' address `%s' next read delayed for %s\n", | 1360 | "Peer `%s' address `%s' next read delayed for %s\n", |
1377 | GNUNET_i2s (&s->target), | 1361 | GNUNET_i2s (&s->target), |
1378 | http_common_plugin_address_to_string (NULL, | 1362 | http_common_plugin_address_to_string (NULL, |
1379 | plugin->protocol, | 1363 | plugin->protocol, s->address->address, |
1380 | s->addr, s->addrlen), | 1364 | s->address->address_length), |
1381 | GNUNET_STRINGS_relative_time_to_string (delay, | 1365 | GNUNET_STRINGS_relative_time_to_string (delay, |
1382 | GNUNET_YES)); | 1366 | GNUNET_YES)); |
1383 | } | 1367 | } |
@@ -1485,9 +1469,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1485 | s, sc, | 1469 | s, sc, |
1486 | GNUNET_i2s (&s->target), | 1470 | GNUNET_i2s (&s->target), |
1487 | http_common_plugin_address_to_string (NULL, | 1471 | http_common_plugin_address_to_string (NULL, |
1488 | plugin->protocol, | 1472 | plugin->protocol, s->address->address, |
1489 | s->addr, | 1473 | s->address->address_length)); |
1490 | s->addrlen)); | ||
1491 | sc->connected = GNUNET_YES; | 1474 | sc->connected = GNUNET_YES; |
1492 | return MHD_YES; | 1475 | return MHD_YES; |
1493 | } | 1476 | } |
@@ -1499,9 +1482,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1499 | s, sc, | 1482 | s, sc, |
1500 | GNUNET_i2s (&s->target), | 1483 | GNUNET_i2s (&s->target), |
1501 | http_common_plugin_address_to_string (NULL, | 1484 | http_common_plugin_address_to_string (NULL, |
1502 | plugin->protocol, | 1485 | plugin->protocol, s->address->address, |
1503 | s->addr, | 1486 | s->address->address_length)); |
1504 | s->addrlen)); | ||
1505 | sc->connected = GNUNET_NO; | 1487 | sc->connected = GNUNET_NO; |
1506 | /* Sent HTTP/1.1: 200 OK as PUT Response\ */ | 1488 | /* Sent HTTP/1.1: 200 OK as PUT Response\ */ |
1507 | response = MHD_create_response_from_data (strlen ("Thank you!"), | 1489 | response = MHD_create_response_from_data (strlen ("Thank you!"), |
@@ -1519,9 +1501,8 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1519 | s, sc, | 1501 | s, sc, |
1520 | GNUNET_i2s (&s->target), | 1502 | GNUNET_i2s (&s->target), |
1521 | http_common_plugin_address_to_string (NULL, | 1503 | http_common_plugin_address_to_string (NULL, |
1522 | plugin->protocol, | 1504 | plugin->protocol, s->address->address, |
1523 | s->addr, | 1505 | s->address->address_length), |
1524 | s->addrlen), | ||
1525 | *upload_data_size); | 1506 | *upload_data_size); |
1526 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 1507 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
1527 | 1508 | ||
@@ -1597,8 +1578,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1597 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", | 1578 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", |
1598 | GNUNET_i2s (&s->target), s->server_send, | 1579 | GNUNET_i2s (&s->target), s->server_send, |
1599 | http_common_plugin_address_to_string (NULL, | 1580 | http_common_plugin_address_to_string (NULL, |
1600 | plugin->protocol, | 1581 | plugin->protocol, s->address->address, |
1601 | s->addr, s->addrlen)); | 1582 | s->address->address_length)); |
1602 | s->server_send = NULL; | 1583 | s->server_send = NULL; |
1603 | if (NULL != (s->server_recv)) | 1584 | if (NULL != (s->server_recv)) |
1604 | { | 1585 | { |
@@ -1617,8 +1598,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1617 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", | 1598 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", |
1618 | GNUNET_i2s (&s->target), s->server_recv, | 1599 | GNUNET_i2s (&s->target), s->server_recv, |
1619 | http_common_plugin_address_to_string (NULL, | 1600 | http_common_plugin_address_to_string (NULL, |
1620 | plugin->protocol, | 1601 | plugin->protocol, s->address->address, |
1621 | s->addr, s->addrlen)); | 1602 | s->address->address_length)); |
1622 | s->server_recv = NULL; | 1603 | s->server_recv = NULL; |
1623 | /* Do not terminate session when PUT disconnects | 1604 | /* Do not terminate session when PUT disconnects |
1624 | if (NULL != (s->server_send)) | 1605 | if (NULL != (s->server_send)) |
@@ -1647,8 +1628,8 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1647 | "Peer `%s' on address `%s' disconnected\n", | 1628 | "Peer `%s' on address `%s' disconnected\n", |
1648 | GNUNET_i2s (&s->target), | 1629 | GNUNET_i2s (&s->target), |
1649 | http_common_plugin_address_to_string (NULL, | 1630 | http_common_plugin_address_to_string (NULL, |
1650 | plugin->protocol, | 1631 | plugin->protocol, s->address->address, |
1651 | s->addr, s->addrlen)); | 1632 | s->address->address_length)); |
1652 | 1633 | ||
1653 | if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) | 1634 | if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) |
1654 | { | 1635 | { |
@@ -2217,6 +2198,7 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2217 | socklen_t addrlen) | 2198 | socklen_t addrlen) |
2218 | { | 2199 | { |
2219 | struct HTTP_Server_Plugin *plugin = cls; | 2200 | struct HTTP_Server_Plugin *plugin = cls; |
2201 | struct GNUNET_HELLO_Address *address; | ||
2220 | struct HttpAddressWrapper *w = NULL; | 2202 | struct HttpAddressWrapper *w = NULL; |
2221 | 2203 | ||
2222 | w = GNUNET_new (struct HttpAddressWrapper); | 2204 | w = GNUNET_new (struct HttpAddressWrapper); |
@@ -2234,11 +2216,17 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2234 | http_common_plugin_address_to_string (NULL, | 2216 | http_common_plugin_address_to_string (NULL, |
2235 | plugin->protocol, | 2217 | plugin->protocol, |
2236 | w->address, w->addrlen)); | 2218 | w->address, w->addrlen)); |
2219 | /* modify our published address list */ | ||
2237 | #if BUILD_HTTPS | 2220 | #if BUILD_HTTPS |
2238 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); | 2221 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
2222 | "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2239 | #else | 2223 | #else |
2240 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client"); | 2224 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
2225 | "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2241 | #endif | 2226 | #endif |
2227 | |||
2228 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | ||
2229 | GNUNET_HELLO_address_free (address); | ||
2242 | } | 2230 | } |
2243 | 2231 | ||
2244 | 2232 | ||
@@ -2255,6 +2243,7 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2255 | socklen_t addrlen) | 2243 | socklen_t addrlen) |
2256 | { | 2244 | { |
2257 | struct HTTP_Server_Plugin *plugin = cls; | 2245 | struct HTTP_Server_Plugin *plugin = cls; |
2246 | struct GNUNET_HELLO_Address *address; | ||
2258 | struct HttpAddressWrapper *w = plugin->addr_head; | 2247 | struct HttpAddressWrapper *w = plugin->addr_head; |
2259 | size_t saddr_len; | 2248 | size_t saddr_len; |
2260 | void * saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen); | 2249 | void * saddr = http_common_address_from_socket (plugin->protocol, addr, addrlen); |
@@ -2278,12 +2267,20 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2278 | http_common_plugin_address_to_string (NULL, | 2267 | http_common_plugin_address_to_string (NULL, |
2279 | plugin->protocol, | 2268 | plugin->protocol, |
2280 | w->address, w->addrlen)); | 2269 | w->address, w->addrlen)); |
2270 | |||
2271 | |||
2281 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); | 2272 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); |
2273 | |||
2274 | /* modify our published address list */ | ||
2282 | #if BUILD_HTTPS | 2275 | #if BUILD_HTTPS |
2283 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); | 2276 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
2277 | "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2284 | #else | 2278 | #else |
2285 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "http_client"); | 2279 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
2280 | "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2286 | #endif | 2281 | #endif |
2282 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | ||
2283 | GNUNET_HELLO_address_free (address); | ||
2287 | GNUNET_free (w->address); | 2284 | GNUNET_free (w->address); |
2288 | GNUNET_free (w); | 2285 | GNUNET_free (w); |
2289 | } | 2286 | } |
@@ -2660,6 +2657,8 @@ static void | |||
2660 | server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2657 | server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2661 | { | 2658 | { |
2662 | struct HTTP_Server_Plugin *plugin = cls; | 2659 | struct HTTP_Server_Plugin *plugin = cls; |
2660 | struct HttpAddress *ext_addr; | ||
2661 | size_t ext_addr_len; | ||
2663 | unsigned int urlen; | 2662 | unsigned int urlen; |
2664 | char *url; | 2663 | char *url; |
2665 | 2664 | ||
@@ -2670,26 +2669,30 @@ server_notify_external_hostname (void *cls, const struct GNUNET_SCHEDULER_TaskCo | |||
2670 | GNUNET_asprintf(&url, "%s://%s", plugin->protocol, plugin->external_hostname); | 2669 | GNUNET_asprintf(&url, "%s://%s", plugin->protocol, plugin->external_hostname); |
2671 | 2670 | ||
2672 | urlen = strlen (url) + 1; | 2671 | urlen = strlen (url) + 1; |
2673 | plugin->ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); | 2672 | ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); |
2674 | plugin->ext_addr->options = htonl(plugin->options); | 2673 | ext_addr->options = htonl(plugin->options); |
2675 | plugin->ext_addr->urlen = htonl (urlen); | 2674 | ext_addr->urlen = htonl (urlen); |
2676 | plugin->ext_addr_len = sizeof (struct HttpAddress) + urlen; | 2675 | ext_addr_len = sizeof (struct HttpAddress) + urlen; |
2677 | memcpy (&plugin->ext_addr[1], url, urlen); | 2676 | memcpy (&ext_addr[1], url, urlen); |
2678 | GNUNET_free (url); | 2677 | GNUNET_free (url); |
2678 | |||
2679 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2679 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2680 | "Notifying transport about external hostname address `%s'\n", plugin->external_hostname); | 2680 | "Notifying transport about external hostname address `%s'\n", plugin->external_hostname); |
2681 | 2681 | ||
2682 | #if BUILD_HTTPS | 2682 | #if BUILD_HTTPS |
2683 | if (GNUNET_YES == plugin->verify_external_hostname) | 2683 | if (GNUNET_YES == plugin->verify_external_hostname) |
2684 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name, | 2684 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name, |
2685 | "Enabling SSL verification for external hostname address `%s'\n", plugin->external_hostname); | 2685 | "Enabling SSL verification for external hostname address `%s'\n", |
2686 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, | 2686 | plugin->external_hostname); |
2687 | plugin->ext_addr, plugin->ext_addr_len, | 2687 | plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
2688 | "https_client"); | 2688 | "https_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE ); |
2689 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr); | ||
2690 | GNUNET_free (ext_addr); | ||
2689 | #else | 2691 | #else |
2690 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, | 2692 | plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
2691 | plugin->ext_addr, plugin->ext_addr_len, | 2693 | "http_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE ); |
2692 | "http_client"); | 2694 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr); |
2695 | GNUNET_free (ext_addr); | ||
2693 | #endif | 2696 | #endif |
2694 | } | 2697 | } |
2695 | 2698 | ||
@@ -3013,21 +3016,19 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3013 | "Notifying transport to remove address `%s'\n", | 3016 | "Notifying transport to remove address `%s'\n", |
3014 | http_common_plugin_address_to_string (NULL, | 3017 | http_common_plugin_address_to_string (NULL, |
3015 | plugin->protocol, | 3018 | plugin->protocol, |
3016 | plugin->ext_addr, | 3019 | plugin->ext_addr->address, |
3017 | plugin->ext_addr_len)); | 3020 | plugin->ext_addr->address_length)); |
3018 | #if BUILD_HTTPS | 3021 | #if BUILD_HTTPS |
3019 | plugin->env->notify_address (plugin->env->cls, | 3022 | plugin->env->notify_address (plugin->env->cls, |
3020 | GNUNET_NO, | 3023 | GNUNET_NO, |
3021 | plugin->ext_addr, | 3024 | plugin->ext_addr); |
3022 | plugin->ext_addr_len, | ||
3023 | "https_client"); | ||
3024 | #else | 3025 | #else |
3025 | plugin->env->notify_address (plugin->env->cls, | 3026 | plugin->env->notify_address (plugin->env->cls, |
3026 | GNUNET_NO, | 3027 | GNUNET_NO, |
3027 | plugin->ext_addr, | 3028 | plugin->ext_addr); |
3028 | plugin->ext_addr_len, | ||
3029 | "http_client"); | ||
3030 | #endif | 3029 | #endif |
3030 | GNUNET_HELLO_address_free (plugin->ext_addr); | ||
3031 | plugin->ext_addr = NULL; | ||
3031 | } | 3032 | } |
3032 | 3033 | ||
3033 | /* Stop to report addresses to transport service */ | 3034 | /* Stop to report addresses to transport service */ |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index a969bdd22..a2fbc7c8a 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002--2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2002--2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
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 | /** | 20 | /** |
21 | * @file transport/plugin_transport_tcp.c | 21 | * @file transport/plugin_transport_tcp.c |
22 | * @brief Implementation of the TCP transport service | 22 | * @brief Implementation of the TCP transport service |
@@ -47,7 +47,6 @@ | |||
47 | */ | 47 | */ |
48 | #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 48 | #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
49 | 49 | ||
50 | |||
51 | GNUNET_NETWORK_STRUCT_BEGIN | 50 | GNUNET_NETWORK_STRUCT_BEGIN |
52 | 51 | ||
53 | /** | 52 | /** |
@@ -72,7 +71,6 @@ struct WelcomeMessage | |||
72 | 71 | ||
73 | }; | 72 | }; |
74 | 73 | ||
75 | |||
76 | /** | 74 | /** |
77 | * Basically a WELCOME message, but with the purpose | 75 | * Basically a WELCOME message, but with the purpose |
78 | * of giving the waiting peer a client handle to use | 76 | * of giving the waiting peer a client handle to use |
@@ -129,7 +127,6 @@ struct TCPProbeContext | |||
129 | struct Plugin *plugin; | 127 | struct Plugin *plugin; |
130 | }; | 128 | }; |
131 | 129 | ||
132 | |||
133 | GNUNET_NETWORK_STRUCT_BEGIN | 130 | GNUNET_NETWORK_STRUCT_BEGIN |
134 | 131 | ||
135 | /** | 132 | /** |
@@ -154,7 +151,6 @@ struct IPv4TcpAddress | |||
154 | 151 | ||
155 | }; | 152 | }; |
156 | 153 | ||
157 | |||
158 | /** | 154 | /** |
159 | * Network format for IPv6 addresses. | 155 | * Network format for IPv6 addresses. |
160 | */ | 156 | */ |
@@ -183,7 +179,6 @@ GNUNET_NETWORK_STRUCT_END | |||
183 | */ | 179 | */ |
184 | struct Plugin; | 180 | struct Plugin; |
185 | 181 | ||
186 | |||
187 | /** | 182 | /** |
188 | * Information kept for each message that is yet to | 183 | * Information kept for each message that is yet to |
189 | * be transmitted. | 184 | * be transmitted. |
@@ -232,7 +227,6 @@ struct PendingMessage | |||
232 | 227 | ||
233 | }; | 228 | }; |
234 | 229 | ||
235 | |||
236 | /** | 230 | /** |
237 | * Session handle for TCP connections. | 231 | * Session handle for TCP connections. |
238 | */ | 232 | */ |
@@ -291,19 +285,19 @@ struct Session | |||
291 | */ | 285 | */ |
292 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 286 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
293 | 287 | ||
288 | struct GNUNET_HELLO_Address *address; | ||
289 | |||
294 | /** | 290 | /** |
295 | * Address of the other peer (either based on our 'connect' | 291 | * Address of the other peer (either based on our 'connect' |
296 | * call or on our 'accept' call). | 292 | * call or on our 'accept' call). |
297 | * | 293 | * |
298 | * struct IPv4TcpAddress or struct IPv6TcpAddress | 294 | * struct IPv4TcpAddress or struct IPv6TcpAddress |
299 | */ | 295 | */ |
300 | void *addr; | 296 | //void *addr; |
301 | |||
302 | /** | 297 | /** |
303 | * Length of @e addr. | 298 | * Length of @e addr. |
304 | */ | 299 | */ |
305 | size_t addrlen; | 300 | //size_t addrlen; |
306 | |||
307 | /** | 301 | /** |
308 | * Last activity on this connection. Used to select preferred | 302 | * Last activity on this connection. Used to select preferred |
309 | * connection. | 303 | * connection. |
@@ -316,11 +310,6 @@ struct Session | |||
316 | int expecting_welcome; | 310 | int expecting_welcome; |
317 | 311 | ||
318 | /** | 312 | /** |
319 | * Was this a connection that was inbound (we accepted)? (#GNUNET_YES/#GNUNET_NO) | ||
320 | */ | ||
321 | int inbound; | ||
322 | |||
323 | /** | ||
324 | * Was this session created using NAT traversal? | 313 | * Was this session created using NAT traversal? |
325 | */ | 314 | */ |
326 | int is_nat; | 315 | int is_nat; |
@@ -331,7 +320,6 @@ struct Session | |||
331 | enum GNUNET_ATS_Network_Type ats_address_network_type; | 320 | enum GNUNET_ATS_Network_Type ats_address_network_type; |
332 | }; | 321 | }; |
333 | 322 | ||
334 | |||
335 | /** | 323 | /** |
336 | * Encapsulation of all of the state of the plugin. | 324 | * Encapsulation of all of the state of the plugin. |
337 | */ | 325 | */ |
@@ -421,7 +409,6 @@ struct Plugin | |||
421 | 409 | ||
422 | }; | 410 | }; |
423 | 411 | ||
424 | |||
425 | /** | 412 | /** |
426 | * Function called for a quick conversion of the binary address to | 413 | * Function called for a quick conversion of the binary address to |
427 | * a numeric address. Note that the caller must not free the | 414 | * a numeric address. Note that the caller must not free the |
@@ -434,10 +421,7 @@ struct Plugin | |||
434 | * @return string representing the same address | 421 | * @return string representing the same address |
435 | */ | 422 | */ |
436 | static const char * | 423 | static const char * |
437 | tcp_address_to_string (void *cls, | 424 | tcp_address_to_string (void *cls, const void *addr, size_t addrlen); |
438 | const void *addr, | ||
439 | size_t addrlen); | ||
440 | |||
441 | 425 | ||
442 | /** | 426 | /** |
443 | * Function to check if an inbound connection is acceptable. | 427 | * Function to check if an inbound connection is acceptable. |
@@ -453,20 +437,19 @@ tcp_address_to_string (void *cls, | |||
453 | */ | 437 | */ |
454 | static int | 438 | static int |
455 | plugin_tcp_access_check (void *cls, | 439 | plugin_tcp_access_check (void *cls, |
456 | const struct GNUNET_CONNECTION_Credentials *ucred, | 440 | const struct GNUNET_CONNECTION_Credentials *ucred, |
457 | const struct sockaddr *addr, socklen_t addrlen) | 441 | const struct sockaddr *addr, socklen_t addrlen) |
458 | { | 442 | { |
459 | struct Plugin *plugin = cls; | 443 | struct Plugin *plugin = cls; |
460 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 444 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
461 | "Accepting new incoming TCP connection from `%s'\n", | 445 | "Accepting new incoming TCP connection from `%s'\n", |
462 | GNUNET_a2s (addr, addrlen)); | 446 | GNUNET_a2s (addr, addrlen)); |
463 | if (plugin->cur_connections >= plugin->max_connections) | 447 | if (plugin->cur_connections >= plugin->max_connections) |
464 | return GNUNET_NO; | 448 | return GNUNET_NO; |
465 | plugin->cur_connections ++; | 449 | plugin->cur_connections++; |
466 | return GNUNET_YES; | 450 | return GNUNET_YES; |
467 | } | 451 | } |
468 | 452 | ||
469 | |||
470 | /** | 453 | /** |
471 | * Our external IP address/port mapping has changed. | 454 | * Our external IP address/port mapping has changed. |
472 | * | 455 | * |
@@ -478,50 +461,51 @@ plugin_tcp_access_check (void *cls, | |||
478 | */ | 461 | */ |
479 | static void | 462 | static void |
480 | tcp_nat_port_map_callback (void *cls, int add_remove, | 463 | tcp_nat_port_map_callback (void *cls, int add_remove, |
481 | const struct sockaddr *addr, | 464 | const struct sockaddr *addr, socklen_t addrlen) |
482 | socklen_t addrlen) | ||
483 | { | 465 | { |
484 | struct Plugin *plugin = cls; | 466 | struct Plugin *plugin = cls; |
467 | struct GNUNET_HELLO_Address *address; | ||
485 | struct IPv4TcpAddress t4; | 468 | struct IPv4TcpAddress t4; |
486 | struct IPv6TcpAddress t6; | 469 | struct IPv6TcpAddress t6; |
487 | void *arg; | 470 | void *arg; |
488 | size_t args; | 471 | size_t args; |
489 | 472 | ||
490 | LOG (GNUNET_ERROR_TYPE_INFO, | 473 | LOG(GNUNET_ERROR_TYPE_INFO, "NAT notification to %s address `%s'\n", |
491 | "NAT notification to %s address `%s'\n", | 474 | (GNUNET_YES == add_remove) ? "add" : "remove", |
492 | (GNUNET_YES == add_remove) ? "add" : "remove", | 475 | GNUNET_a2s (addr, addrlen)); |
493 | GNUNET_a2s (addr, addrlen)); | ||
494 | /* convert 'addr' to our internal format */ | 476 | /* convert 'addr' to our internal format */ |
495 | switch (addr->sa_family) | 477 | switch (addr->sa_family) |
496 | { | 478 | { |
497 | case AF_INET: | 479 | case AF_INET: |
498 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 480 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); |
499 | memset (&t4,0, sizeof (t4)); | 481 | memset (&t4, 0, sizeof(t4)); |
500 | t4.options = htonl (myoptions); | 482 | t4.options = htonl (myoptions); |
501 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 483 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
502 | t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; | 484 | t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; |
503 | arg = &t4; | 485 | arg = &t4; |
504 | args = sizeof (t4); | 486 | args = sizeof(t4); |
505 | break; | 487 | break; |
506 | case AF_INET6: | 488 | case AF_INET6: |
507 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 489 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); |
508 | memset (&t6, 0, sizeof (t6)); | 490 | memset (&t6, 0, sizeof(t6)); |
509 | memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, | 491 | memcpy (&t6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, |
510 | sizeof (struct in6_addr)); | 492 | sizeof(struct in6_addr)); |
511 | t6.options = htonl (myoptions); | 493 | t6.options = htonl (myoptions); |
512 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 494 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
513 | arg = &t6; | 495 | arg = &t6; |
514 | args = sizeof (t6); | 496 | args = sizeof(t6); |
515 | break; | 497 | break; |
516 | default: | 498 | default: |
517 | GNUNET_break (0); | 499 | GNUNET_break(0); |
518 | return; | 500 | return; |
519 | } | 501 | } |
520 | /* modify our published address list */ | 502 | /* modify our published address list */ |
521 | plugin->env->notify_address (plugin->env->cls, add_remove, arg, args, "tcp"); | 503 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
504 | PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
505 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | ||
506 | GNUNET_HELLO_address_free(address); | ||
522 | } | 507 | } |
523 | 508 | ||
524 | |||
525 | /** | 509 | /** |
526 | * Function called for a quick conversion of the binary address to | 510 | * Function called for a quick conversion of the binary address to |
527 | * a numeric address. Note that the caller must not free the | 511 | * a numeric address. Note that the caller must not free the |
@@ -549,52 +533,44 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
549 | 533 | ||
550 | switch (addrlen) | 534 | switch (addrlen) |
551 | { | 535 | { |
552 | case sizeof (struct IPv6TcpAddress): | 536 | case sizeof(struct IPv6TcpAddress): |
553 | t6 = addr; | 537 | t6 = addr; |
554 | af = AF_INET6; | 538 | af = AF_INET6; |
555 | port = ntohs (t6->t6_port); | 539 | port = ntohs (t6->t6_port); |
556 | options = ntohl (t6->options); | 540 | options = ntohl (t6->options); |
557 | memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); | 541 | memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); |
558 | sb = &a6; | 542 | sb = &a6; |
559 | break; | 543 | break; |
560 | case sizeof (struct IPv4TcpAddress): | 544 | case sizeof(struct IPv4TcpAddress): |
561 | t4 = addr; | 545 | t4 = addr; |
562 | af = AF_INET; | 546 | af = AF_INET; |
563 | port = ntohs (t4->t4_port); | 547 | port = ntohs (t4->t4_port); |
564 | options = ntohl (t4->options); | 548 | options = ntohl (t4->options); |
565 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); | 549 | memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); |
566 | sb = &a4; | 550 | sb = &a4; |
567 | break; | 551 | break; |
568 | case 0: | 552 | case 0: |
569 | { | 553 | { |
570 | GNUNET_snprintf (rbuf, sizeof (rbuf), "%s", | 554 | GNUNET_snprintf (rbuf, sizeof(rbuf), "%s", |
571 | TRANSPORT_SESSION_INBOUND_STRING); | 555 | TRANSPORT_SESSION_INBOUND_STRING); |
572 | return rbuf; | 556 | return rbuf; |
573 | } | 557 | } |
574 | default: | 558 | default: |
575 | LOG (GNUNET_ERROR_TYPE_WARNING, | 559 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Unexpected address length: %u bytes\n"), |
576 | _("Unexpected address length: %u bytes\n"), | 560 | (unsigned int ) addrlen); |
577 | (unsigned int) addrlen); | 561 | return NULL ; |
578 | return NULL; | ||
579 | } | 562 | } |
580 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) | 563 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) |
581 | { | 564 | { |
582 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 565 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
583 | return NULL; | 566 | return NULL ; |
584 | } | 567 | } |
585 | GNUNET_snprintf (rbuf, | 568 | GNUNET_snprintf (rbuf, sizeof(rbuf), |
586 | sizeof (rbuf), | 569 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options, |
587 | (af == AF_INET6) | 570 | buf, port); |
588 | ? "%s.%u.[%s]:%u" | ||
589 | : "%s.%u.%s:%u", | ||
590 | PLUGIN_NAME, | ||
591 | options, | ||
592 | buf, | ||
593 | port); | ||
594 | return rbuf; | 571 | return rbuf; |
595 | } | 572 | } |
596 | 573 | ||
597 | |||
598 | /** | 574 | /** |
599 | * Function called to convert a string address to | 575 | * Function called to convert a string address to |
600 | * a binary address. | 576 | * a binary address. |
@@ -608,10 +584,8 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
608 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 584 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
609 | */ | 585 | */ |
610 | static int | 586 | static int |
611 | tcp_string_to_address (void *cls, | 587 | tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen, |
612 | const char *addr, | 588 | void **buf, size_t *added) |
613 | uint16_t addrlen, | ||
614 | void **buf, size_t *added) | ||
615 | { | 589 | { |
616 | struct sockaddr_storage socket_address; | 590 | struct sockaddr_storage socket_address; |
617 | char *address; | 591 | char *address; |
@@ -625,82 +599,81 @@ tcp_string_to_address (void *cls, | |||
625 | optionstr = NULL; | 599 | optionstr = NULL; |
626 | if ((NULL == addr) || (addrlen == 0)) | 600 | if ((NULL == addr) || (addrlen == 0)) |
627 | { | 601 | { |
628 | GNUNET_break (0); | 602 | GNUNET_break(0); |
629 | return GNUNET_SYSERR; | 603 | return GNUNET_SYSERR; |
630 | } | 604 | } |
631 | if ('\0' != addr[addrlen - 1]) | 605 | if ('\0' != addr[addrlen - 1]) |
632 | { | 606 | { |
633 | GNUNET_break (0); | 607 | GNUNET_break(0); |
634 | return GNUNET_SYSERR; | 608 | return GNUNET_SYSERR; |
635 | } | 609 | } |
636 | if (strlen (addr) != addrlen - 1) | 610 | if (strlen (addr) != addrlen - 1) |
637 | { | 611 | { |
638 | GNUNET_break (0); | 612 | GNUNET_break(0); |
639 | return GNUNET_SYSERR; | 613 | return GNUNET_SYSERR; |
640 | } | 614 | } |
641 | plugin = GNUNET_strdup (addr); | 615 | plugin = GNUNET_strdup (addr); |
642 | optionstr = strchr (plugin, '.'); | 616 | optionstr = strchr (plugin, '.'); |
643 | if (NULL == optionstr) | 617 | if (NULL == optionstr) |
644 | { | 618 | { |
645 | GNUNET_break (0); | 619 | GNUNET_break(0); |
646 | GNUNET_free (plugin); | 620 | GNUNET_free(plugin); |
647 | return GNUNET_SYSERR; | 621 | return GNUNET_SYSERR; |
648 | } | 622 | } |
649 | optionstr[0] = '\0'; | 623 | optionstr[0] = '\0'; |
650 | optionstr ++; | 624 | optionstr++; |
651 | options = atol (optionstr); | 625 | options = atol (optionstr); |
652 | address = strchr (optionstr, '.'); | 626 | address = strchr (optionstr, '.'); |
653 | if (NULL == address) | 627 | if (NULL == address) |
654 | { | 628 | { |
655 | GNUNET_break (0); | 629 | GNUNET_break(0); |
656 | GNUNET_free (plugin); | 630 | GNUNET_free(plugin); |
657 | return GNUNET_SYSERR; | 631 | return GNUNET_SYSERR; |
658 | } | 632 | } |
659 | address[0] = '\0'; | 633 | address[0] = '\0'; |
660 | address ++; | 634 | address++; |
661 | 635 | ||
662 | if (GNUNET_OK != | 636 | if (GNUNET_OK |
663 | GNUNET_STRINGS_to_address_ip (address, strlen (address), | 637 | != GNUNET_STRINGS_to_address_ip (address, strlen (address), |
664 | &socket_address)) | 638 | &socket_address)) |
665 | { | 639 | { |
666 | GNUNET_break (0); | 640 | GNUNET_break(0); |
667 | GNUNET_free (plugin); | 641 | GNUNET_free(plugin); |
668 | return GNUNET_SYSERR; | 642 | return GNUNET_SYSERR; |
669 | } | 643 | } |
670 | 644 | ||
671 | GNUNET_free (plugin); | 645 | GNUNET_free(plugin); |
672 | switch (socket_address.ss_family) | 646 | switch (socket_address.ss_family) |
673 | { | 647 | { |
674 | case AF_INET: | 648 | case AF_INET: |
675 | { | 649 | { |
676 | struct IPv4TcpAddress *t4; | 650 | struct IPv4TcpAddress *t4; |
677 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; | 651 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; |
678 | t4 = GNUNET_new (struct IPv4TcpAddress); | 652 | t4 = GNUNET_new (struct IPv4TcpAddress); |
679 | t4->options = htonl (options); | 653 | t4->options = htonl (options); |
680 | t4->ipv4_addr = in4->sin_addr.s_addr; | 654 | t4->ipv4_addr = in4->sin_addr.s_addr; |
681 | t4->t4_port = in4->sin_port; | 655 | t4->t4_port = in4->sin_port; |
682 | *buf = t4; | 656 | *buf = t4; |
683 | *added = sizeof (struct IPv4TcpAddress); | 657 | *added = sizeof(struct IPv4TcpAddress); |
684 | return GNUNET_OK; | 658 | return GNUNET_OK; |
685 | } | 659 | } |
686 | case AF_INET6: | 660 | case AF_INET6: |
687 | { | 661 | { |
688 | struct IPv6TcpAddress *t6; | 662 | struct IPv6TcpAddress *t6; |
689 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; | 663 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; |
690 | t6 = GNUNET_new (struct IPv6TcpAddress); | 664 | t6 = GNUNET_new (struct IPv6TcpAddress); |
691 | t6->options = htonl (options); | 665 | t6->options = htonl (options); |
692 | t6->ipv6_addr = in6->sin6_addr; | 666 | t6->ipv6_addr = in6->sin6_addr; |
693 | t6->t6_port = in6->sin6_port; | 667 | t6->t6_port = in6->sin6_port; |
694 | *buf = t6; | 668 | *buf = t6; |
695 | *added = sizeof (struct IPv6TcpAddress); | 669 | *added = sizeof(struct IPv6TcpAddress); |
696 | return GNUNET_OK; | 670 | return GNUNET_OK; |
697 | } | 671 | } |
698 | default: | 672 | default: |
699 | return GNUNET_SYSERR; | 673 | return GNUNET_SYSERR; |
700 | } | 674 | } |
701 | } | 675 | } |
702 | 676 | ||
703 | |||
704 | /** | 677 | /** |
705 | * Closure for #session_lookup_by_client_it(). | 678 | * Closure for #session_lookup_by_client_it(). |
706 | */ | 679 | */ |
@@ -717,11 +690,9 @@ struct SessionClientCtx | |||
717 | struct Session *ret; | 690 | struct Session *ret; |
718 | }; | 691 | }; |
719 | 692 | ||
720 | |||
721 | static int | 693 | static int |
722 | session_lookup_by_client_it (void *cls, | 694 | session_lookup_by_client_it (void *cls, const struct GNUNET_PeerIdentity *key, |
723 | const struct GNUNET_PeerIdentity *key, | 695 | void *value) |
724 | void *value) | ||
725 | { | 696 | { |
726 | struct SessionClientCtx *sc_ctx = cls; | 697 | struct SessionClientCtx *sc_ctx = cls; |
727 | struct Session *s = value; | 698 | struct Session *s = value; |
@@ -734,7 +705,6 @@ session_lookup_by_client_it (void *cls, | |||
734 | return GNUNET_YES; | 705 | return GNUNET_YES; |
735 | } | 706 | } |
736 | 707 | ||
737 | |||
738 | /** | 708 | /** |
739 | * Find the session handle for the given client. | 709 | * Find the session handle for the given client. |
740 | * Currently uses both the hashmap and the client | 710 | * Currently uses both the hashmap and the client |
@@ -747,7 +717,7 @@ session_lookup_by_client_it (void *cls, | |||
747 | */ | 717 | */ |
748 | static struct Session * | 718 | static struct Session * |
749 | lookup_session_by_client (struct Plugin *plugin, | 719 | lookup_session_by_client (struct Plugin *plugin, |
750 | struct GNUNET_SERVER_Client *client) | 720 | struct GNUNET_SERVER_Client *client) |
751 | { | 721 | { |
752 | struct Session *ret; | 722 | struct Session *ret; |
753 | struct SessionClientCtx sc_ctx; | 723 | struct SessionClientCtx sc_ctx; |
@@ -756,13 +726,12 @@ lookup_session_by_client (struct Plugin *plugin, | |||
756 | sc_ctx.client = client; | 726 | sc_ctx.client = client; |
757 | sc_ctx.ret = NULL; | 727 | sc_ctx.ret = NULL; |
758 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, | 728 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
759 | &session_lookup_by_client_it, &sc_ctx); | 729 | &session_lookup_by_client_it, &sc_ctx); |
760 | /* check both methods yield the same result */ | 730 | /* check both methods yield the same result */ |
761 | GNUNET_break (ret == sc_ctx.ret); | 731 | GNUNET_break(ret == sc_ctx.ret); |
762 | return sc_ctx.ret; | 732 | return sc_ctx.ret; |
763 | } | 733 | } |
764 | 734 | ||
765 | |||
766 | /** | 735 | /** |
767 | * Functions with this signature are called whenever we need | 736 | * Functions with this signature are called whenever we need |
768 | * to close a session due to a disconnect or failure to | 737 | * to close a session due to a disconnect or failure to |
@@ -773,16 +742,15 @@ lookup_session_by_client (struct Plugin *plugin, | |||
773 | * @return #GNUNET_OK on success | 742 | * @return #GNUNET_OK on success |
774 | */ | 743 | */ |
775 | static int | 744 | static int |
776 | tcp_disconnect_session (void *cls, | 745 | tcp_disconnect_session (void *cls, struct Session *session) |
777 | struct Session *session) | ||
778 | { | 746 | { |
779 | struct Plugin *plugin = cls; | 747 | struct Plugin *plugin = cls; |
780 | struct PendingMessage *pm; | 748 | struct PendingMessage *pm; |
781 | 749 | ||
782 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 750 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
783 | "Disconnecting session of peer `%s' address `%s'\n", | 751 | "Disconnecting session of peer `%s' address `%s'\n", |
784 | GNUNET_i2s (&session->target), | 752 | GNUNET_i2s (&session->target), |
785 | tcp_address_to_string (NULL, session->addr, session->addrlen)); | 753 | tcp_address_to_string (NULL, session->address->address, session->address->address_length)); |
786 | 754 | ||
787 | if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task) | 755 | if (GNUNET_SCHEDULER_NO_TASK != session->timeout_task) |
788 | { | 756 | { |
@@ -790,25 +758,20 @@ tcp_disconnect_session (void *cls, | |||
790 | session->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 758 | session->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
791 | } | 759 | } |
792 | 760 | ||
793 | if (GNUNET_YES == | 761 | if (GNUNET_YES |
794 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, | 762 | == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, |
795 | &session->target, | 763 | &session->target, session)) |
796 | session)) | ||
797 | { | 764 | { |
798 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 765 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
799 | gettext_noop ("# TCP sessions active"), -1, | 766 | gettext_noop ("# TCP sessions active"), -1, GNUNET_NO); |
800 | GNUNET_NO); | ||
801 | } | 767 | } |
802 | else | 768 | else |
803 | { | 769 | { |
804 | GNUNET_assert (GNUNET_YES == | 770 | GNUNET_assert( |
805 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, | 771 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session)); |
806 | &session->target, | ||
807 | session)); | ||
808 | } | 772 | } |
809 | if (NULL != session->client) | 773 | if (NULL != session->client) |
810 | GNUNET_SERVER_client_set_user_context (session->client, | 774 | GNUNET_SERVER_client_set_user_context(session->client, (void *) NULL); |
811 | (void *) NULL); | ||
812 | 775 | ||
813 | /* clean up state */ | 776 | /* clean up state */ |
814 | if (NULL != session->transmit_handle) | 777 | if (NULL != session->transmit_handle) |
@@ -817,7 +780,7 @@ tcp_disconnect_session (void *cls, | |||
817 | session->transmit_handle = NULL; | 780 | session->transmit_handle = NULL; |
818 | } | 781 | } |
819 | session->plugin->env->session_end (session->plugin->env->cls, | 782 | session->plugin->env->session_end (session->plugin->env->cls, |
820 | &session->target, session); | 783 | &session->target, session); |
821 | 784 | ||
822 | if (GNUNET_SCHEDULER_NO_TASK != session->nat_connection_timeout) | 785 | if (GNUNET_SCHEDULER_NO_TASK != session->nat_connection_timeout) |
823 | { | 786 | { |
@@ -827,26 +790,22 @@ tcp_disconnect_session (void *cls, | |||
827 | 790 | ||
828 | while (NULL != (pm = session->pending_messages_head)) | 791 | while (NULL != (pm = session->pending_messages_head)) |
829 | { | 792 | { |
830 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 793 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
831 | pm->transmit_cont != | 794 | pm->transmit_cont != NULL ? "Could not deliver message to `%4s'.\n" : "Could not deliver message to `%4s', notifying.\n", |
832 | NULL ? "Could not deliver message to `%4s'.\n" : | 795 | GNUNET_i2s (&session->target)); |
833 | "Could not deliver message to `%4s', notifying.\n", | ||
834 | GNUNET_i2s (&session->target)); | ||
835 | GNUNET_STATISTICS_update (session->plugin->env->stats, | ||
836 | gettext_noop ("# bytes currently in TCP buffers"), | ||
837 | -(int64_t) pm->message_size, GNUNET_NO); | ||
838 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 796 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
839 | gettext_noop | 797 | gettext_noop ("# bytes currently in TCP buffers"), |
840 | ("# bytes discarded by TCP (disconnect)"), | 798 | -(int64_t) pm->message_size, GNUNET_NO); |
841 | pm->message_size, GNUNET_NO); | 799 | GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop |
842 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 800 | ("# bytes discarded by TCP (disconnect)"), pm->message_size, GNUNET_NO); |
843 | session->pending_messages_tail, pm); | 801 | GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, |
802 | session->pending_messages_tail, pm); | ||
844 | if (NULL != pm->transmit_cont) | 803 | if (NULL != pm->transmit_cont) |
845 | pm->transmit_cont (pm->transmit_cont_cls, &session->target, | 804 | pm->transmit_cont (pm->transmit_cont_cls, &session->target, GNUNET_SYSERR, |
846 | GNUNET_SYSERR, pm->message_size, 0); | 805 | pm->message_size, 0); |
847 | GNUNET_free (pm); | 806 | GNUNET_free(pm); |
848 | } | 807 | } |
849 | if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK) | 808 | if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK ) |
850 | { | 809 | { |
851 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); | 810 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
852 | if (NULL != session->client) | 811 | if (NULL != session->client) |
@@ -858,13 +817,12 @@ tcp_disconnect_session (void *cls, | |||
858 | GNUNET_SERVER_client_drop (session->client); | 817 | GNUNET_SERVER_client_drop (session->client); |
859 | session->client = NULL; | 818 | session->client = NULL; |
860 | } | 819 | } |
861 | GNUNET_free_non_null (session->addr); | 820 | GNUNET_HELLO_address_free(session->address); |
862 | GNUNET_assert (NULL == session->transmit_handle); | 821 | GNUNET_assert(NULL == session->transmit_handle); |
863 | GNUNET_free (session); | 822 | GNUNET_free(session); |
864 | return GNUNET_OK; | 823 | return GNUNET_OK; |
865 | } | 824 | } |
866 | 825 | ||
867 | |||
868 | /** | 826 | /** |
869 | * Function that is called to get the keepalive factor. | 827 | * Function that is called to get the keepalive factor. |
870 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to | 828 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to |
@@ -879,7 +837,6 @@ tcp_query_keepalive_factor (void *cls) | |||
879 | return 3; | 837 | return 3; |
880 | } | 838 | } |
881 | 839 | ||
882 | |||
883 | /** | 840 | /** |
884 | * Session was idle, so disconnect it | 841 | * Session was idle, so disconnect it |
885 | * | 842 | * |
@@ -887,22 +844,18 @@ tcp_query_keepalive_factor (void *cls) | |||
887 | * @param tc scheduler context | 844 | * @param tc scheduler context |
888 | */ | 845 | */ |
889 | static void | 846 | static void |
890 | session_timeout (void *cls, | 847 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
891 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
892 | { | 848 | { |
893 | struct Session *s = cls; | 849 | struct Session *s = cls; |
894 | 850 | ||
895 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 851 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 852 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
897 | "Session %p was idle for %s, disconnecting\n", | 853 | "Session %p was idle for %s, disconnecting\n", s, |
898 | s, | 854 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); |
899 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
900 | GNUNET_YES)); | ||
901 | /* call session destroy function */ | 855 | /* call session destroy function */ |
902 | tcp_disconnect_session (s->plugin, s); | 856 | tcp_disconnect_session (s->plugin, s); |
903 | } | 857 | } |
904 | 858 | ||
905 | |||
906 | /** | 859 | /** |
907 | * Increment session timeout due to activity | 860 | * Increment session timeout due to activity |
908 | * | 861 | * |
@@ -911,19 +864,15 @@ session_timeout (void *cls, | |||
911 | static void | 864 | static void |
912 | reschedule_session_timeout (struct Session *s) | 865 | reschedule_session_timeout (struct Session *s) |
913 | { | 866 | { |
914 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | 867 | GNUNET_assert(GNUNET_SCHEDULER_NO_TASK != s->timeout_task); |
915 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 868 | GNUNET_SCHEDULER_cancel (s->timeout_task); |
916 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 869 | s->timeout_task = GNUNET_SCHEDULER_add_delayed ( |
917 | &session_timeout, | 870 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, s); |
918 | s); | 871 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 872 | "Timeout rescheduled for session %p set to %s\n", s, |
920 | "Timeout rescheduled for session %p set to %s\n", | 873 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); |
921 | s, | ||
922 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
923 | GNUNET_YES)); | ||
924 | } | 874 | } |
925 | 875 | ||
926 | |||
927 | /** | 876 | /** |
928 | * Create a new session. Also queues a welcome message. | 877 | * Create a new session. Also queues a welcome message. |
929 | * | 878 | * |
@@ -936,22 +885,20 @@ reschedule_session_timeout (struct Session *s) | |||
936 | * @return new session object | 885 | * @return new session object |
937 | */ | 886 | */ |
938 | static struct Session * | 887 | static struct Session * |
939 | create_session (struct Plugin *plugin, | 888 | create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, |
940 | const struct GNUNET_PeerIdentity *target, | 889 | struct GNUNET_SERVER_Client *client, int is_nat) |
941 | struct GNUNET_SERVER_Client *client, int is_nat) | ||
942 | { | 890 | { |
943 | struct Session *session; | 891 | struct Session *session; |
944 | struct PendingMessage *pm; | 892 | struct PendingMessage *pm; |
945 | struct WelcomeMessage welcome; | 893 | struct WelcomeMessage welcome; |
946 | 894 | ||
947 | if (GNUNET_YES != is_nat) | 895 | if (GNUNET_YES != is_nat) |
948 | GNUNET_assert (NULL != client); | 896 | GNUNET_assert(NULL != client); |
949 | else | 897 | else |
950 | GNUNET_assert (NULL == client); | 898 | GNUNET_assert(NULL == client); |
951 | 899 | ||
952 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 900 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session for peer `%4s'\n", |
953 | "Creating new session for peer `%4s'\n", | 901 | GNUNET_i2s (target)); |
954 | GNUNET_i2s (target)); | ||
955 | session = GNUNET_new (struct Session); | 902 | session = GNUNET_new (struct Session); |
956 | session->last_activity = GNUNET_TIME_absolute_get (); | 903 | session->last_activity = GNUNET_TIME_absolute_get (); |
957 | session->plugin = plugin; | 904 | session->plugin = plugin; |
@@ -961,32 +908,29 @@ create_session (struct Plugin *plugin, | |||
961 | session->expecting_welcome = GNUNET_YES; | 908 | session->expecting_welcome = GNUNET_YES; |
962 | session->ats_address_network_type = GNUNET_ATS_NET_UNSPECIFIED; | 909 | session->ats_address_network_type = GNUNET_ATS_NET_UNSPECIFIED; |
963 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + | 910 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + |
964 | sizeof (struct WelcomeMessage)); | 911 | sizeof (struct WelcomeMessage)); |
965 | pm->msg = (const char *) &pm[1]; | 912 | pm->msg = (const char *) &pm[1]; |
966 | pm->message_size = sizeof (struct WelcomeMessage); | 913 | pm->message_size = sizeof(struct WelcomeMessage); |
967 | welcome.header.size = htons (sizeof (struct WelcomeMessage)); | 914 | welcome.header.size = htons (sizeof(struct WelcomeMessage)); |
968 | welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); | 915 | welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); |
969 | welcome.clientIdentity = *plugin->env->my_identity; | 916 | welcome.clientIdentity = *plugin->env->my_identity; |
970 | memcpy (&pm[1], &welcome, sizeof (welcome)); | 917 | memcpy (&pm[1], &welcome, sizeof(welcome)); |
971 | pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 918 | pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
972 | GNUNET_STATISTICS_update (plugin->env->stats, | 919 | GNUNET_STATISTICS_update (plugin->env->stats, |
973 | gettext_noop ("# bytes currently in TCP buffers"), | 920 | gettext_noop ("# bytes currently in TCP buffers"), pm->message_size, |
974 | pm->message_size, GNUNET_NO); | 921 | GNUNET_NO); |
975 | GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, | 922 | GNUNET_CONTAINER_DLL_insert(session->pending_messages_head, |
976 | session->pending_messages_tail, pm); | 923 | session->pending_messages_tail, pm); |
977 | if (GNUNET_YES != is_nat) | 924 | if (GNUNET_YES != is_nat) |
978 | { | 925 | { |
979 | GNUNET_STATISTICS_update (plugin->env->stats, | 926 | GNUNET_STATISTICS_update (plugin->env->stats, |
980 | gettext_noop ("# TCP sessions active"), 1, | 927 | gettext_noop ("# TCP sessions active"), 1, GNUNET_NO); |
981 | GNUNET_NO); | ||
982 | } | 928 | } |
983 | session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 929 | session->timeout_task = GNUNET_SCHEDULER_add_delayed ( |
984 | &session_timeout, | 930 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); |
985 | session); | ||
986 | return session; | 931 | return session; |
987 | } | 932 | } |
988 | 933 | ||
989 | |||
990 | /** | 934 | /** |
991 | * If we have pending messages, ask the server to | 935 | * If we have pending messages, ask the server to |
992 | * transmit them (schedule the respective tasks, etc.) | 936 | * transmit them (schedule the respective tasks, etc.) |
@@ -996,7 +940,6 @@ create_session (struct Plugin *plugin, | |||
996 | static void | 940 | static void |
997 | process_pending_messages (struct Session *session); | 941 | process_pending_messages (struct Session *session); |
998 | 942 | ||
999 | |||
1000 | /** | 943 | /** |
1001 | * Function called to notify a client about the socket | 944 | * Function called to notify a client about the socket |
1002 | * being ready to queue more data. "buf" will be | 945 | * being ready to queue more data. "buf" will be |
@@ -1025,24 +968,24 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1025 | plugin = session->plugin; | 968 | plugin = session->plugin; |
1026 | if (NULL == buf) | 969 | if (NULL == buf) |
1027 | { | 970 | { |
1028 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 971 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1029 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", | 972 | "Timeout trying to transmit to peer `%4s', discarding message queue.\n", |
1030 | GNUNET_i2s (&session->target)); | 973 | GNUNET_i2s (&session->target)); |
1031 | /* timeout; cancel all messages that have already expired */ | 974 | /* timeout; cancel all messages that have already expired */ |
1032 | hd = NULL; | 975 | hd = NULL; |
1033 | tl = NULL; | 976 | tl = NULL; |
1034 | ret = 0; | 977 | ret = 0; |
1035 | now = GNUNET_TIME_absolute_get (); | 978 | now = GNUNET_TIME_absolute_get (); |
1036 | while ((NULL != (pos = session->pending_messages_head)) && | 979 | while ((NULL != (pos = session->pending_messages_head)) |
1037 | (pos->timeout.abs_value_us <= now.abs_value_us)) | 980 | && (pos->timeout.abs_value_us <= now.abs_value_us)) |
1038 | { | 981 | { |
1039 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 982 | GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, |
1040 | session->pending_messages_tail, pos); | 983 | session->pending_messages_tail, pos); |
1041 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 984 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1042 | "Failed to transmit %u byte message to `%4s'.\n", | 985 | "Failed to transmit %u byte message to `%4s'.\n", pos->message_size, |
1043 | pos->message_size, GNUNET_i2s (&session->target)); | 986 | GNUNET_i2s (&session->target)); |
1044 | ret += pos->message_size; | 987 | ret += pos->message_size; |
1045 | GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); | 988 | GNUNET_CONTAINER_DLL_insert_after(hd, tl, tl, pos); |
1046 | } | 989 | } |
1047 | /* do this call before callbacks (so that if callbacks destroy | 990 | /* do this call before callbacks (so that if callbacks destroy |
1048 | * session, they have a chance to cancel actions done by this | 991 | * session, they have a chance to cancel actions done by this |
@@ -1053,18 +996,17 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1053 | * the callbacks may abort the session */ | 996 | * the callbacks may abort the session */ |
1054 | while (NULL != (pos = hd)) | 997 | while (NULL != (pos = hd)) |
1055 | { | 998 | { |
1056 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); | 999 | GNUNET_CONTAINER_DLL_remove(hd, tl, pos); |
1057 | if (pos->transmit_cont != NULL) | 1000 | if (pos->transmit_cont != NULL ) |
1058 | pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR, pos->message_size, 0); | 1001 | pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR, |
1059 | GNUNET_free (pos); | 1002 | pos->message_size, 0); |
1003 | GNUNET_free(pos); | ||
1060 | } | 1004 | } |
1061 | GNUNET_STATISTICS_update (plugin->env->stats, | 1005 | GNUNET_STATISTICS_update (plugin->env->stats, |
1062 | gettext_noop ("# bytes currently in TCP buffers"), | 1006 | gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, |
1063 | -(int64_t) ret, GNUNET_NO); | 1007 | GNUNET_NO); |
1064 | GNUNET_STATISTICS_update (plugin->env->stats, | 1008 | GNUNET_STATISTICS_update (plugin->env->stats, gettext_noop |
1065 | gettext_noop | 1009 | ("# bytes discarded by TCP (timeout)"), ret, GNUNET_NO); |
1066 | ("# bytes discarded by TCP (timeout)"), ret, | ||
1067 | GNUNET_NO); | ||
1068 | return 0; | 1010 | return 0; |
1069 | } | 1011 | } |
1070 | /* copy all pending messages that would fit */ | 1012 | /* copy all pending messages that would fit */ |
@@ -1076,18 +1018,17 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1076 | { | 1018 | { |
1077 | if (ret + pos->message_size > size) | 1019 | if (ret + pos->message_size > size) |
1078 | break; | 1020 | break; |
1079 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 1021 | GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, |
1080 | session->pending_messages_tail, pos); | 1022 | session->pending_messages_tail, pos); |
1081 | GNUNET_assert (size >= pos->message_size); | 1023 | GNUNET_assert(size >= pos->message_size); |
1082 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1024 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Transmitting message of type %u\n", |
1083 | "Transmitting message of type %u\n", | 1025 | ntohs (((struct GNUNET_MessageHeader * ) pos->msg)->type)); |
1084 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type)); | ||
1085 | /* FIXME: this memcpy can be up to 7% of our total runtime */ | 1026 | /* FIXME: this memcpy can be up to 7% of our total runtime */ |
1086 | memcpy (cbuf, pos->msg, pos->message_size); | 1027 | memcpy (cbuf, pos->msg, pos->message_size); |
1087 | cbuf += pos->message_size; | 1028 | cbuf += pos->message_size; |
1088 | ret += pos->message_size; | 1029 | ret += pos->message_size; |
1089 | size -= pos->message_size; | 1030 | size -= pos->message_size; |
1090 | GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); | 1031 | GNUNET_CONTAINER_DLL_insert_tail(hd, tl, pos); |
1091 | } | 1032 | } |
1092 | /* schedule 'continuation' before callbacks so that callbacks that | 1033 | /* schedule 'continuation' before callbacks so that callbacks that |
1093 | * cancel everything don't cause us to use a session that no longer | 1034 | * cancel everything don't cause us to use a session that no longer |
@@ -1099,25 +1040,23 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1099 | * we should not use 'session' after this point */ | 1040 | * we should not use 'session' after this point */ |
1100 | while (NULL != (pos = hd)) | 1041 | while (NULL != (pos = hd)) |
1101 | { | 1042 | { |
1102 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); | 1043 | GNUNET_CONTAINER_DLL_remove(hd, tl, pos); |
1103 | if (pos->transmit_cont != NULL) | 1044 | if (pos->transmit_cont != NULL ) |
1104 | pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK, pos->message_size, pos->message_size); /* FIXME: include TCP overhead */ | 1045 | pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK, |
1105 | GNUNET_free (pos); | 1046 | pos->message_size, pos->message_size); /* FIXME: include TCP overhead */ |
1047 | GNUNET_free(pos); | ||
1106 | } | 1048 | } |
1107 | GNUNET_assert (hd == NULL); | 1049 | GNUNET_assert(hd == NULL); |
1108 | GNUNET_assert (tl == NULL); | 1050 | GNUNET_assert(tl == NULL); |
1109 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n", | 1051 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n", ret); |
1110 | ret); | ||
1111 | GNUNET_STATISTICS_update (plugin->env->stats, | 1052 | GNUNET_STATISTICS_update (plugin->env->stats, |
1112 | gettext_noop ("# bytes currently in TCP buffers"), | 1053 | gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, |
1113 | -(int64_t) ret, GNUNET_NO); | 1054 | GNUNET_NO); |
1114 | GNUNET_STATISTICS_update (plugin->env->stats, | 1055 | GNUNET_STATISTICS_update (plugin->env->stats, |
1115 | gettext_noop ("# bytes transmitted via TCP"), ret, | 1056 | gettext_noop ("# bytes transmitted via TCP"), ret, GNUNET_NO); |
1116 | GNUNET_NO); | ||
1117 | return ret; | 1057 | return ret; |
1118 | } | 1058 | } |
1119 | 1059 | ||
1120 | |||
1121 | /** | 1060 | /** |
1122 | * If we have pending messages, ask the server to | 1061 | * If we have pending messages, ask the server to |
1123 | * transmit them (schedule the respective tasks, etc.) | 1062 | * transmit them (schedule the respective tasks, etc.) |
@@ -1129,20 +1068,17 @@ process_pending_messages (struct Session *session) | |||
1129 | { | 1068 | { |
1130 | struct PendingMessage *pm; | 1069 | struct PendingMessage *pm; |
1131 | 1070 | ||
1132 | GNUNET_assert (NULL != session->client); | 1071 | GNUNET_assert(NULL != session->client); |
1133 | if (NULL != session->transmit_handle) | 1072 | if (NULL != session->transmit_handle) |
1134 | return; | 1073 | return; |
1135 | if (NULL == (pm = session->pending_messages_head)) | 1074 | if (NULL == (pm = session->pending_messages_head)) |
1136 | return; | 1075 | return; |
1137 | 1076 | ||
1138 | session->transmit_handle = | 1077 | session->transmit_handle = GNUNET_SERVER_notify_transmit_ready ( |
1139 | GNUNET_SERVER_notify_transmit_ready (session->client, pm->message_size, | 1078 | session->client, pm->message_size, |
1140 | GNUNET_TIME_absolute_get_remaining | 1079 | GNUNET_TIME_absolute_get_remaining (pm->timeout), &do_transmit, session); |
1141 | (pm->timeout), &do_transmit, | ||
1142 | session); | ||
1143 | } | 1080 | } |
1144 | 1081 | ||
1145 | |||
1146 | #if EXTRA_CHECKS | 1082 | #if EXTRA_CHECKS |
1147 | /** | 1083 | /** |
1148 | * Closure for #session_it(). | 1084 | * Closure for #session_it(). |
@@ -1160,7 +1096,6 @@ struct FindSessionContext | |||
1160 | int res; | 1096 | int res; |
1161 | }; | 1097 | }; |
1162 | 1098 | ||
1163 | |||
1164 | /** | 1099 | /** |
1165 | * Function called to check if a session is in our maps. | 1100 | * Function called to check if a session is in our maps. |
1166 | * | 1101 | * |
@@ -1170,9 +1105,7 @@ struct FindSessionContext | |||
1170 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session | 1105 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session |
1171 | */ | 1106 | */ |
1172 | static int | 1107 | static int |
1173 | session_it (void *cls, | 1108 | session_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
1174 | const struct GNUNET_PeerIdentity *key, | ||
1175 | void *value) | ||
1176 | { | 1109 | { |
1177 | struct FindSessionContext *res = cls; | 1110 | struct FindSessionContext *res = cls; |
1178 | struct Session *session = value; | 1111 | struct Session *session = value; |
@@ -1185,7 +1118,6 @@ session_it (void *cls, | |||
1185 | return GNUNET_YES; | 1118 | return GNUNET_YES; |
1186 | } | 1119 | } |
1187 | 1120 | ||
1188 | |||
1189 | /** | 1121 | /** |
1190 | * Check that the given session is known to the plugin and | 1122 | * Check that the given session is known to the plugin and |
1191 | * is in one of our maps. | 1123 | * is in one of our maps. |
@@ -1195,30 +1127,28 @@ session_it (void *cls, | |||
1195 | * @return #GNUNET_OK if all is well, #GNUNET_SYSERR if the session is invalid | 1127 | * @return #GNUNET_OK if all is well, #GNUNET_SYSERR if the session is invalid |
1196 | */ | 1128 | */ |
1197 | static int | 1129 | static int |
1198 | find_session (struct Plugin *plugin, | 1130 | find_session (struct Plugin *plugin, struct Session *session) |
1199 | struct Session *session) | ||
1200 | { | 1131 | { |
1201 | struct FindSessionContext session_map_res; | 1132 | struct FindSessionContext session_map_res; |
1202 | struct FindSessionContext nat_map_res; | 1133 | struct FindSessionContext nat_map_res; |
1203 | 1134 | ||
1204 | session_map_res.s = session; | 1135 | session_map_res.s = session; |
1205 | session_map_res.res = GNUNET_SYSERR; | 1136 | session_map_res.res = GNUNET_SYSERR; |
1206 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, | 1137 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_it, |
1207 | &session_it, &session_map_res); | 1138 | &session_map_res); |
1208 | if (GNUNET_SYSERR != session_map_res.res) | 1139 | if (GNUNET_SYSERR != session_map_res.res) |
1209 | return GNUNET_OK; | 1140 | return GNUNET_OK; |
1210 | nat_map_res.s = session; | 1141 | nat_map_res.s = session; |
1211 | nat_map_res.res = GNUNET_SYSERR; | 1142 | nat_map_res.res = GNUNET_SYSERR; |
1212 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, | 1143 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, &session_it, |
1213 | &session_it, &nat_map_res); | 1144 | &nat_map_res); |
1214 | if (GNUNET_SYSERR != nat_map_res.res) | 1145 | if (GNUNET_SYSERR != nat_map_res.res) |
1215 | return GNUNET_OK; | 1146 | return GNUNET_OK; |
1216 | GNUNET_break (0); | 1147 | GNUNET_break(0); |
1217 | return GNUNET_SYSERR; | 1148 | return GNUNET_SYSERR; |
1218 | } | 1149 | } |
1219 | #endif | 1150 | #endif |
1220 | 1151 | ||
1221 | |||
1222 | /** | 1152 | /** |
1223 | * Function that can be used by the transport service to transmit | 1153 | * Function that can be used by the transport service to transmit |
1224 | * a message using the plugin. Note that in the case of a | 1154 | * a message using the plugin. Note that in the case of a |
@@ -1247,12 +1177,9 @@ find_session (struct Plugin *plugin, | |||
1247 | * and does NOT mean that the message was not transmitted (DV) | 1177 | * and does NOT mean that the message was not transmitted (DV) |
1248 | */ | 1178 | */ |
1249 | static ssize_t | 1179 | static ssize_t |
1250 | tcp_plugin_send (void *cls, | 1180 | tcp_plugin_send (void *cls, struct Session *session, const char *msgbuf, |
1251 | struct Session *session, | 1181 | size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, |
1252 | const char *msgbuf, size_t msgbuf_size, | 1182 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
1253 | unsigned int priority, | ||
1254 | struct GNUNET_TIME_Relative to, | ||
1255 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | ||
1256 | { | 1183 | { |
1257 | struct Plugin * plugin = cls; | 1184 | struct Plugin * plugin = cls; |
1258 | struct PendingMessage *pm; | 1185 | struct PendingMessage *pm; |
@@ -1260,9 +1187,8 @@ tcp_plugin_send (void *cls, | |||
1260 | #if EXTRA_CHECKS | 1187 | #if EXTRA_CHECKS |
1261 | if (GNUNET_SYSERR == find_session (plugin, session)) | 1188 | if (GNUNET_SYSERR == find_session (plugin, session)) |
1262 | { | 1189 | { |
1263 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1190 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Trying to send with invalid session %p\n")); |
1264 | _("Trying to send with invalid session %p\n")); | 1191 | GNUNET_assert(0); |
1265 | GNUNET_assert (0); | ||
1266 | return GNUNET_SYSERR; | 1192 | return GNUNET_SYSERR; |
1267 | } | 1193 | } |
1268 | #endif | 1194 | #endif |
@@ -1275,63 +1201,55 @@ tcp_plugin_send (void *cls, | |||
1275 | pm->transmit_cont = cont; | 1201 | pm->transmit_cont = cont; |
1276 | pm->transmit_cont_cls = cont_cls; | 1202 | pm->transmit_cont_cls = cont_cls; |
1277 | 1203 | ||
1278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1204 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1279 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 1205 | "Asked to transmit %u bytes to `%s', added message to list.\n", |
1280 | msgbuf_size, GNUNET_i2s (&session->target)); | 1206 | msgbuf_size, GNUNET_i2s (&session->target)); |
1281 | 1207 | ||
1282 | if (GNUNET_YES == | 1208 | if (GNUNET_YES |
1283 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | 1209 | == GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
1284 | &session->target, | 1210 | &session->target, session)) |
1285 | session)) | ||
1286 | { | 1211 | { |
1287 | GNUNET_assert (NULL != session->client); | 1212 | GNUNET_assert(NULL != session->client); |
1288 | GNUNET_SERVER_client_set_timeout (session->client, | 1213 | GNUNET_SERVER_client_set_timeout (session->client, |
1289 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1214 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1290 | GNUNET_STATISTICS_update (plugin->env->stats, | 1215 | GNUNET_STATISTICS_update (plugin->env->stats, |
1291 | gettext_noop ("# bytes currently in TCP buffers"), | 1216 | gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, |
1292 | msgbuf_size, GNUNET_NO); | 1217 | GNUNET_NO); |
1293 | 1218 | ||
1294 | /* append pm to pending_messages list */ | 1219 | /* append pm to pending_messages list */ |
1295 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, | 1220 | GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, |
1296 | session->pending_messages_tail, pm); | 1221 | session->pending_messages_tail, pm); |
1297 | 1222 | ||
1298 | process_pending_messages (session); | 1223 | process_pending_messages (session); |
1299 | return msgbuf_size; | 1224 | return msgbuf_size; |
1300 | } | 1225 | } |
1301 | else if (GNUNET_YES == | 1226 | else if (GNUNET_YES |
1302 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, | 1227 | == GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, |
1303 | &session->target, | 1228 | &session->target, session)) |
1304 | session)) | ||
1305 | { | 1229 | { |
1306 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1230 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1307 | "This NAT WAIT session for peer `%s' is not yet ready!\n", | 1231 | "This NAT WAIT session for peer `%s' is not yet ready!\n", |
1308 | GNUNET_i2s (&session->target)); | 1232 | GNUNET_i2s (&session->target)); |
1309 | GNUNET_STATISTICS_update (plugin->env->stats, | 1233 | GNUNET_STATISTICS_update (plugin->env->stats, |
1310 | gettext_noop ("# bytes currently in TCP buffers"), | 1234 | gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, |
1311 | msgbuf_size, GNUNET_NO); | 1235 | GNUNET_NO); |
1312 | 1236 | ||
1313 | /* append pm to pending_messages list */ | 1237 | /* append pm to pending_messages list */ |
1314 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, | 1238 | GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, |
1315 | session->pending_messages_tail, pm); | 1239 | session->pending_messages_tail, pm); |
1316 | return msgbuf_size; | 1240 | return msgbuf_size; |
1317 | } | 1241 | } |
1318 | else | 1242 | else |
1319 | { | 1243 | { |
1320 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1244 | LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); |
1321 | "Invalid session %p\n", session); | ||
1322 | if (NULL != cont) | 1245 | if (NULL != cont) |
1323 | cont (cont_cls, | 1246 | cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); |
1324 | &session->target, | 1247 | GNUNET_break(0); |
1325 | GNUNET_SYSERR, | 1248 | GNUNET_free(pm); |
1326 | pm->message_size, | ||
1327 | 0); | ||
1328 | GNUNET_break (0); | ||
1329 | GNUNET_free (pm); | ||
1330 | return GNUNET_SYSERR; /* session does not exist here */ | 1249 | return GNUNET_SYSERR; /* session does not exist here */ |
1331 | } | 1250 | } |
1332 | } | 1251 | } |
1333 | 1252 | ||
1334 | |||
1335 | /** | 1253 | /** |
1336 | * Closure for #session_lookup_it(). | 1254 | * Closure for #session_lookup_it(). |
1337 | */ | 1255 | */ |
@@ -1340,19 +1258,14 @@ struct SessionItCtx | |||
1340 | /** | 1258 | /** |
1341 | * Address we are looking for. | 1259 | * Address we are looking for. |
1342 | */ | 1260 | */ |
1343 | void *addr; | 1261 | const struct GNUNET_HELLO_Address *address; |
1344 | |||
1345 | /** | ||
1346 | * Number of bytes in @e addr. | ||
1347 | */ | ||
1348 | size_t addrlen; | ||
1349 | 1262 | ||
1350 | /** | 1263 | /** |
1351 | * Where to store the session (if we found it). | 1264 | * Where to store the session (if we found it). |
1352 | */ | 1265 | */ |
1353 | struct Session *result; | 1266 | struct Session *result; |
1354 | }; | ||
1355 | 1267 | ||
1268 | }; | ||
1356 | 1269 | ||
1357 | /** | 1270 | /** |
1358 | * Look for a session by address. | 1271 | * Look for a session by address. |
@@ -1363,23 +1276,19 @@ struct SessionItCtx | |||
1363 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session | 1276 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session |
1364 | */ | 1277 | */ |
1365 | static int | 1278 | static int |
1366 | session_lookup_it (void *cls, | 1279 | session_lookup_it (void *cls, const struct GNUNET_PeerIdentity *key, |
1367 | const struct GNUNET_PeerIdentity *key, | 1280 | void *value) |
1368 | void *value) | ||
1369 | { | 1281 | { |
1370 | struct SessionItCtx * si_ctx = cls; | 1282 | struct SessionItCtx * si_ctx = cls; |
1371 | struct Session * session = value; | 1283 | struct Session * session = value; |
1372 | 1284 | ||
1373 | if (session->addrlen != si_ctx->addrlen) | 1285 | if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) |
1374 | return GNUNET_YES; | ||
1375 | if (0 != memcmp (session->addr, si_ctx->addr, si_ctx->addrlen)) | ||
1376 | return GNUNET_YES; | 1286 | return GNUNET_YES; |
1377 | /* Found existing session */ | 1287 | /* Found existing session */ |
1378 | si_ctx->result = session; | 1288 | si_ctx->result = session; |
1379 | return GNUNET_NO; | 1289 | return GNUNET_NO; |
1380 | } | 1290 | } |
1381 | 1291 | ||
1382 | |||
1383 | /** | 1292 | /** |
1384 | * Task cleaning up a NAT connection attempt after timeout | 1293 | * Task cleaning up a NAT connection attempt after timeout |
1385 | * | 1294 | * |
@@ -1387,26 +1296,21 @@ session_lookup_it (void *cls, | |||
1387 | * @param tc scheduler context (unused) | 1296 | * @param tc scheduler context (unused) |
1388 | */ | 1297 | */ |
1389 | static void | 1298 | static void |
1390 | nat_connect_timeout (void *cls, | 1299 | nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1391 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1392 | { | 1300 | { |
1393 | struct Session *session = cls; | 1301 | struct Session *session = cls; |
1394 | 1302 | ||
1395 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; | 1303 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; |
1396 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1304 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1397 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", | 1305 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", |
1398 | GNUNET_i2s (&session->target), | 1306 | GNUNET_i2s (&session->target), |
1399 | tcp_address_to_string (NULL, | 1307 | tcp_address_to_string (NULL, session->address->address, session->address->address_length)); |
1400 | session->addr, session->addrlen)); | 1308 | tcp_disconnect_session (session->plugin, session); |
1401 | tcp_disconnect_session (session->plugin, | ||
1402 | session); | ||
1403 | } | 1309 | } |
1404 | 1310 | ||
1405 | |||
1406 | static void | 1311 | static void |
1407 | tcp_plugin_update_session_timeout (void *cls, | 1312 | tcp_plugin_update_session_timeout (void *cls, |
1408 | const struct GNUNET_PeerIdentity *peer, | 1313 | const struct GNUNET_PeerIdentity *peer, struct Session *session) |
1409 | struct Session *session) | ||
1410 | { | 1314 | { |
1411 | struct Plugin *plugin = cls; | 1315 | struct Plugin *plugin = cls; |
1412 | 1316 | ||
@@ -1415,7 +1319,6 @@ tcp_plugin_update_session_timeout (void *cls, | |||
1415 | reschedule_session_timeout (session); | 1319 | reschedule_session_timeout (session); |
1416 | } | 1320 | } |
1417 | 1321 | ||
1418 | |||
1419 | /** | 1322 | /** |
1420 | * Create a new session to transmit data to the target | 1323 | * Create a new session to transmit data to the target |
1421 | * This session will used to send data to this peer and the plugin will | 1324 | * This session will used to send data to this peer and the plugin will |
@@ -1426,8 +1329,7 @@ tcp_plugin_update_session_timeout (void *cls, | |||
1426 | * @return the session if the address is valid, NULL otherwise | 1329 | * @return the session if the address is valid, NULL otherwise |
1427 | */ | 1330 | */ |
1428 | static struct Session * | 1331 | static struct Session * |
1429 | tcp_plugin_get_session (void *cls, | 1332 | tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
1430 | const struct GNUNET_HELLO_Address *address) | ||
1431 | { | 1333 | { |
1432 | struct Plugin *plugin = cls; | 1334 | struct Plugin *plugin = cls; |
1433 | struct Session *session = NULL; | 1335 | struct Session *session = NULL; |
@@ -1444,48 +1346,44 @@ tcp_plugin_get_session (void *cls, | |||
1444 | size_t addrlen; | 1346 | size_t addrlen; |
1445 | 1347 | ||
1446 | addrlen = address->address_length; | 1348 | addrlen = address->address_length; |
1447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1349 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1448 | "Trying to get session for `%s' address of peer `%s'\n", | 1350 | "Trying to get session for `%s' address of peer `%s'\n", |
1449 | tcp_address_to_string(NULL, address->address, address->address_length), | 1351 | tcp_address_to_string(NULL, address->address, address->address_length), |
1450 | GNUNET_i2s (&address->peer)); | 1352 | GNUNET_i2s (&address->peer)); |
1451 | 1353 | ||
1452 | /* look for existing session */ | 1354 | /* look for existing session */ |
1453 | if (GNUNET_YES == | 1355 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, |
1454 | GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, | 1356 | &address->peer)) |
1455 | &address->peer)) | ||
1456 | { | 1357 | { |
1457 | struct SessionItCtx si_ctx; | 1358 | struct SessionItCtx si_ctx; |
1458 | 1359 | ||
1459 | si_ctx.addr = (void *) address->address; | 1360 | si_ctx.address = address; |
1460 | si_ctx.addrlen = address->address_length; | ||
1461 | |||
1462 | si_ctx.result = NULL; | 1361 | si_ctx.result = NULL; |
1463 | 1362 | ||
1464 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, | 1363 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, |
1465 | &address->peer, | 1364 | &address->peer, &session_lookup_it, &si_ctx); |
1466 | &session_lookup_it, &si_ctx); | 1365 | if (si_ctx.result != NULL ) |
1467 | if (si_ctx.result != NULL) | ||
1468 | { | 1366 | { |
1469 | session = si_ctx.result; | 1367 | session = si_ctx.result; |
1470 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1368 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1471 | "Found existing session for `%s' address `%s' session %p\n", | 1369 | "Found existing session for `%s' address `%s' session %p\n", |
1472 | GNUNET_i2s (&address->peer), | 1370 | GNUNET_i2s (&address->peer), |
1473 | tcp_address_to_string(NULL, address->address, address->address_length), | 1371 | tcp_address_to_string(NULL, address->address, address->address_length), |
1474 | session); | 1372 | session); |
1475 | return session; | 1373 | return session; |
1476 | } | 1374 | } |
1477 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1375 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1478 | "Existing sessions did not match address `%s' or peer `%s'\n", | 1376 | "Existing sessions did not match address `%s' or peer `%s'\n", |
1479 | tcp_address_to_string(NULL, address->address, address->address_length), | 1377 | tcp_address_to_string(NULL, address->address, address->address_length), |
1480 | GNUNET_i2s (&address->peer)); | 1378 | GNUNET_i2s (&address->peer)); |
1481 | } | 1379 | } |
1482 | 1380 | ||
1483 | if (addrlen == sizeof (struct IPv6TcpAddress)) | 1381 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
1484 | { | 1382 | { |
1485 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 1383 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ |
1486 | t6 = address->address; | 1384 | t6 = address->address; |
1487 | af = AF_INET6; | 1385 | af = AF_INET6; |
1488 | memset (&a6, 0, sizeof (a6)); | 1386 | memset (&a6, 0, sizeof(a6)); |
1489 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1387 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1490 | a6.sin6_len = sizeof (a6); | 1388 | a6.sin6_len = sizeof (a6); |
1491 | #endif | 1389 | #endif |
@@ -1493,16 +1391,16 @@ tcp_plugin_get_session (void *cls, | |||
1493 | a6.sin6_port = t6->t6_port; | 1391 | a6.sin6_port = t6->t6_port; |
1494 | if (t6->t6_port == 0) | 1392 | if (t6->t6_port == 0) |
1495 | is_natd = GNUNET_YES; | 1393 | is_natd = GNUNET_YES; |
1496 | memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); | 1394 | memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); |
1497 | sb = &a6; | 1395 | sb = &a6; |
1498 | sbs = sizeof (a6); | 1396 | sbs = sizeof(a6); |
1499 | } | 1397 | } |
1500 | else if (addrlen == sizeof (struct IPv4TcpAddress)) | 1398 | else if (addrlen == sizeof(struct IPv4TcpAddress)) |
1501 | { | 1399 | { |
1502 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 1400 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ |
1503 | t4 = address->address; | 1401 | t4 = address->address; |
1504 | af = AF_INET; | 1402 | af = AF_INET; |
1505 | memset (&a4, 0, sizeof (a4)); | 1403 | memset (&a4, 0, sizeof(a4)); |
1506 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1404 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1507 | a4.sin_len = sizeof (a4); | 1405 | a4.sin_len = sizeof (a4); |
1508 | #endif | 1406 | #endif |
@@ -1512,144 +1410,123 @@ tcp_plugin_get_session (void *cls, | |||
1512 | is_natd = GNUNET_YES; | 1410 | is_natd = GNUNET_YES; |
1513 | a4.sin_addr.s_addr = t4->ipv4_addr; | 1411 | a4.sin_addr.s_addr = t4->ipv4_addr; |
1514 | sb = &a4; | 1412 | sb = &a4; |
1515 | sbs = sizeof (a4); | 1413 | sbs = sizeof(a4); |
1516 | } | 1414 | } |
1517 | else | 1415 | else |
1518 | { | 1416 | { |
1519 | GNUNET_STATISTICS_update (plugin->env->stats, | 1417 | GNUNET_STATISTICS_update (plugin->env->stats, gettext_noop |
1520 | gettext_noop | 1418 | ("# requests to create session with invalid address"), 1, GNUNET_NO); |
1521 | ("# requests to create session with invalid address"), | 1419 | return NULL ; |
1522 | 1, GNUNET_NO); | ||
1523 | return NULL; | ||
1524 | } | 1420 | } |
1525 | 1421 | ||
1526 | ats = plugin->env->get_address_type (plugin->env->cls, sb, sbs); | 1422 | ats = plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
1527 | 1423 | ||
1528 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) | 1424 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) |
1529 | { | 1425 | { |
1530 | /* NAT client only works with IPv4 addresses */ | 1426 | /* NAT client only works with IPv4 addresses */ |
1531 | return NULL; | 1427 | return NULL ; |
1532 | } | 1428 | } |
1533 | 1429 | ||
1534 | if (plugin->cur_connections >= plugin->max_connections) | 1430 | if (plugin->cur_connections >= plugin->max_connections) |
1535 | { | 1431 | { |
1536 | /* saturated */ | 1432 | /* saturated */ |
1537 | return NULL; | 1433 | return NULL ; |
1538 | } | 1434 | } |
1539 | 1435 | ||
1540 | if ((is_natd == GNUNET_YES) && | 1436 | if ((is_natd == GNUNET_YES) |
1541 | (GNUNET_YES == | 1437 | && (GNUNET_YES |
1542 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, | 1438 | == GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
1543 | &address->peer))) | 1439 | &address->peer))) |
1544 | { | 1440 | { |
1545 | /* Only do one NAT punch attempt per peer identity */ | 1441 | /* Only do one NAT punch attempt per peer identity */ |
1546 | return NULL; | 1442 | return NULL ; |
1547 | } | 1443 | } |
1548 | 1444 | ||
1549 | if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && | 1445 | if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && |
1550 | (GNUNET_NO == | 1446 | (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
1551 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, | 1447 | &address->peer))) |
1552 | &address->peer))) | ||
1553 | { | 1448 | { |
1554 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1449 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1555 | "Found valid IPv4 NAT address (creating session)!\n") ; | 1450 | "Found valid IPv4 NAT address (creating session)!\n"); |
1556 | session = create_session (plugin, | 1451 | session = create_session (plugin, &address->peer, NULL, GNUNET_YES); |
1557 | &address->peer, | 1452 | session->address = GNUNET_HELLO_address_copy (address); |
1558 | NULL, | 1453 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( |
1559 | GNUNET_YES); | 1454 | ats.value); |
1560 | session->addrlen = 0; | 1455 | GNUNET_break( |
1561 | session->addr = NULL; | 1456 | session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
1562 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); | ||
1563 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | ||
1564 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, | 1457 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, |
1565 | &nat_connect_timeout, | 1458 | &nat_connect_timeout, session); |
1566 | session); | 1459 | GNUNET_assert(session != NULL); |
1567 | GNUNET_assert (session != NULL); | 1460 | GNUNET_assert( |
1568 | GNUNET_assert (GNUNET_OK == | 1461 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, &session->target, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1569 | GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, | ||
1570 | &session->target, | ||
1571 | session, | ||
1572 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1573 | 1462 | ||
1574 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1463 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1575 | "Created NAT WAIT connection to `%4s' at `%s'\n", | 1464 | "Created NAT WAIT connection to `%4s' at `%s'\n", |
1576 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); | 1465 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); |
1577 | 1466 | ||
1578 | if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4)) | 1467 | if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4)) |
1579 | return session; | 1468 | return session; |
1580 | else | 1469 | else |
1581 | { | 1470 | { |
1582 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1471 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1583 | "Running NAT client for `%4s' at `%s' failed\n", | 1472 | "Running NAT client for `%4s' at `%s' failed\n", |
1584 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); | 1473 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); |
1585 | tcp_disconnect_session (plugin, session); | 1474 | tcp_disconnect_session (plugin, session); |
1586 | return NULL; | 1475 | return NULL ; |
1587 | } | 1476 | } |
1588 | } | 1477 | } |
1589 | 1478 | ||
1590 | /* create new outbound session */ | 1479 | /* create new outbound session */ |
1591 | GNUNET_assert (plugin->cur_connections <= plugin->max_connections); | 1480 | GNUNET_assert(plugin->cur_connections <= plugin->max_connections); |
1592 | sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); | 1481 | sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); |
1593 | if (NULL == sa) | 1482 | if (NULL == sa) |
1594 | { | 1483 | { |
1595 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1484 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1596 | "Failed to create connection to `%4s' at `%s'\n", | 1485 | "Failed to create connection to `%4s' at `%s'\n", |
1597 | GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); | 1486 | GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); |
1598 | return NULL; | 1487 | return NULL ; |
1599 | } | 1488 | } |
1600 | plugin->cur_connections++; | 1489 | plugin->cur_connections++; |
1601 | if (plugin->cur_connections == plugin->max_connections) | 1490 | if (plugin->cur_connections == plugin->max_connections) |
1602 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ | 1491 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ |
1603 | 1492 | ||
1604 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1493 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1605 | "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", | 1494 | "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", |
1606 | GNUNET_i2s (&address->peer), | 1495 | GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); |
1607 | GNUNET_a2s (sb, sbs)); | 1496 | |
1608 | 1497 | session = create_session (plugin, &address->peer, | |
1609 | session = create_session (plugin, | 1498 | GNUNET_SERVER_connect_socket (plugin->server, sa), GNUNET_NO); |
1610 | &address->peer, | 1499 | session->address = GNUNET_HELLO_address_copy (address); |
1611 | GNUNET_SERVER_connect_socket (plugin->server, sa), | 1500 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( |
1612 | GNUNET_NO); | 1501 | ats.value); |
1613 | session->addr = GNUNET_malloc (addrlen); | 1502 | GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
1614 | memcpy (session->addr, address->address, addrlen); | 1503 | GNUNET_SERVER_client_set_user_context(session->client, session); |
1615 | session->addrlen = addrlen; | 1504 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, |
1616 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); | 1505 | session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1617 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | 1506 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1618 | GNUNET_SERVER_client_set_user_context (session->client, session); | 1507 | "Creating new session for `%s' address `%s' session %p\n", |
1619 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 1508 | GNUNET_i2s (&address->peer), |
1620 | &session->target, | 1509 | tcp_address_to_string(NULL, address->address, address->address_length), |
1621 | session, | 1510 | session); |
1622 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1623 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1624 | "Creating new session for `%s' address `%s' session %p\n", | ||
1625 | GNUNET_i2s (&address->peer), | ||
1626 | tcp_address_to_string(NULL, address->address, address->address_length), | ||
1627 | session); | ||
1628 | /* Send TCP Welcome */ | 1511 | /* Send TCP Welcome */ |
1629 | process_pending_messages (session); | 1512 | process_pending_messages (session); |
1630 | 1513 | ||
1631 | return session; | 1514 | return session; |
1632 | } | 1515 | } |
1633 | 1516 | ||
1634 | |||
1635 | static int | 1517 | static int |
1636 | session_disconnect_it (void *cls, | 1518 | session_disconnect_it (void *cls, const struct GNUNET_PeerIdentity *key, |
1637 | const struct GNUNET_PeerIdentity *key, | 1519 | void *value) |
1638 | void *value) | ||
1639 | { | 1520 | { |
1640 | struct Plugin *plugin = cls; | 1521 | struct Plugin *plugin = cls; |
1641 | struct Session *session = value; | 1522 | struct Session *session = value; |
1642 | 1523 | ||
1643 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1524 | GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop |
1644 | gettext_noop | 1525 | ("# transport-service disconnect requests for TCP"), 1, GNUNET_NO); |
1645 | ("# transport-service disconnect requests for TCP"), | 1526 | tcp_disconnect_session (plugin, session); |
1646 | 1, GNUNET_NO); | ||
1647 | tcp_disconnect_session (plugin, | ||
1648 | session); | ||
1649 | return GNUNET_YES; | 1527 | return GNUNET_YES; |
1650 | } | 1528 | } |
1651 | 1529 | ||
1652 | |||
1653 | /** | 1530 | /** |
1654 | * Function that can be called to force a disconnect from the | 1531 | * Function that can be called to force a disconnect from the |
1655 | * specified neighbour. This should also cancel all previously | 1532 | * specified neighbour. This should also cancel all previously |
@@ -1667,21 +1544,18 @@ session_disconnect_it (void *cls, | |||
1667 | * to be cancelled | 1544 | * to be cancelled |
1668 | */ | 1545 | */ |
1669 | static void | 1546 | static void |
1670 | tcp_plugin_disconnect (void *cls, | 1547 | tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
1671 | const struct GNUNET_PeerIdentity *target) | ||
1672 | { | 1548 | { |
1673 | struct Plugin *plugin = cls; | 1549 | struct Plugin *plugin = cls; |
1674 | 1550 | ||
1675 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1551 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s'\n", |
1676 | "Disconnecting peer `%4s'\n", | 1552 | GNUNET_i2s (target)); |
1677 | GNUNET_i2s (target)); | ||
1678 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, target, | 1553 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, target, |
1679 | &session_disconnect_it, plugin); | 1554 | &session_disconnect_it, plugin); |
1680 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, target, | 1555 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, target, |
1681 | &session_disconnect_it, plugin); | 1556 | &session_disconnect_it, plugin); |
1682 | } | 1557 | } |
1683 | 1558 | ||
1684 | |||
1685 | /** | 1559 | /** |
1686 | * Running pretty printers: head | 1560 | * Running pretty printers: head |
1687 | */ | 1561 | */ |
@@ -1743,10 +1617,8 @@ struct PrettyPrinterContext | |||
1743 | uint32_t options; | 1617 | uint32_t options; |
1744 | }; | 1618 | }; |
1745 | 1619 | ||
1746 | |||
1747 | static void | 1620 | static void |
1748 | ppc_cancel_task (void *cls, | 1621 | ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1749 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1750 | { | 1622 | { |
1751 | struct PrettyPrinterContext *ppc = cls; | 1623 | struct PrettyPrinterContext *ppc = cls; |
1752 | 1624 | ||
@@ -1756,11 +1628,10 @@ ppc_cancel_task (void *cls, | |||
1756 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); | 1628 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); |
1757 | ppc->resolver_handle = NULL; | 1629 | ppc->resolver_handle = NULL; |
1758 | } | 1630 | } |
1759 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 1631 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); |
1760 | GNUNET_free (ppc); | 1632 | GNUNET_free(ppc); |
1761 | } | 1633 | } |
1762 | 1634 | ||
1763 | |||
1764 | /** | 1635 | /** |
1765 | * Append our port and forward the result. | 1636 | * Append our port and forward the result. |
1766 | * | 1637 | * |
@@ -1776,12 +1647,12 @@ append_port (void *cls, const char *hostname) | |||
1776 | 1647 | ||
1777 | if (NULL == hostname) | 1648 | if (NULL == hostname) |
1778 | { | 1649 | { |
1779 | ppc->asc (ppc->asc_cls, NULL); | 1650 | ppc->asc (ppc->asc_cls, NULL ); |
1780 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 1651 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); |
1781 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); | 1652 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); |
1782 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1653 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1783 | ppc->resolver_handle = NULL; | 1654 | ppc->resolver_handle = NULL; |
1784 | GNUNET_free (ppc); | 1655 | GNUNET_free(ppc); |
1785 | return; | 1656 | return; |
1786 | } | 1657 | } |
1787 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | 1658 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) |
@@ -1789,29 +1660,20 @@ append_port (void *cls, const char *hostname) | |||
1789 | break; | 1660 | break; |
1790 | if (NULL == cur) | 1661 | if (NULL == cur) |
1791 | { | 1662 | { |
1792 | GNUNET_break (0); | 1663 | GNUNET_break(0); |
1793 | return; | 1664 | return; |
1794 | } | 1665 | } |
1795 | 1666 | ||
1796 | if (GNUNET_YES == ppc->ipv6) | 1667 | if (GNUNET_YES == ppc->ipv6) |
1797 | GNUNET_asprintf (&ret, | 1668 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, |
1798 | "%s.%u.[%s]:%d", | 1669 | ppc->port); |
1799 | PLUGIN_NAME, | ||
1800 | ppc->options, | ||
1801 | hostname, | ||
1802 | ppc->port); | ||
1803 | else | 1670 | else |
1804 | GNUNET_asprintf (&ret, | 1671 | GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, |
1805 | "%s.%u.%s:%d", | 1672 | ppc->port); |
1806 | PLUGIN_NAME, | ||
1807 | ppc->options, | ||
1808 | hostname, | ||
1809 | ppc->port); | ||
1810 | ppc->asc (ppc->asc_cls, ret); | 1673 | ppc->asc (ppc->asc_cls, ret); |
1811 | GNUNET_free (ret); | 1674 | GNUNET_free(ret); |
1812 | } | 1675 | } |
1813 | 1676 | ||
1814 | |||
1815 | /** | 1677 | /** |
1816 | * Convert the transports address to a nice, human-readable | 1678 | * Convert the transports address to a nice, human-readable |
1817 | * format. | 1679 | * format. |
@@ -1828,11 +1690,9 @@ append_port (void *cls, const char *hostname) | |||
1828 | */ | 1690 | */ |
1829 | static void | 1691 | static void |
1830 | tcp_plugin_address_pretty_printer (void *cls, const char *type, | 1692 | tcp_plugin_address_pretty_printer (void *cls, const char *type, |
1831 | const void *addr, size_t addrlen, | 1693 | const void *addr, size_t addrlen, int numeric, |
1832 | int numeric, | 1694 | struct GNUNET_TIME_Relative timeout, |
1833 | struct GNUNET_TIME_Relative timeout, | 1695 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) |
1834 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
1835 | void *asc_cls) | ||
1836 | { | 1696 | { |
1837 | struct PrettyPrinterContext *ppc; | 1697 | struct PrettyPrinterContext *ppc; |
1838 | const void *sb; | 1698 | const void *sb; |
@@ -1844,45 +1704,45 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, | |||
1844 | uint16_t port; | 1704 | uint16_t port; |
1845 | uint32_t options; | 1705 | uint32_t options; |
1846 | 1706 | ||
1847 | if (addrlen == sizeof (struct IPv6TcpAddress)) | 1707 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
1848 | { | 1708 | { |
1849 | t6 = addr; | 1709 | t6 = addr; |
1850 | memset (&a6, 0, sizeof (a6)); | 1710 | memset (&a6, 0, sizeof(a6)); |
1851 | a6.sin6_family = AF_INET6; | 1711 | a6.sin6_family = AF_INET6; |
1852 | a6.sin6_port = t6->t6_port; | 1712 | a6.sin6_port = t6->t6_port; |
1853 | memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); | 1713 | memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); |
1854 | port = ntohs (t6->t6_port); | 1714 | port = ntohs (t6->t6_port); |
1855 | options = ntohl (t6->options); | 1715 | options = ntohl (t6->options); |
1856 | sb = &a6; | 1716 | sb = &a6; |
1857 | sbs = sizeof (a6); | 1717 | sbs = sizeof(a6); |
1858 | } | 1718 | } |
1859 | else if (addrlen == sizeof (struct IPv4TcpAddress)) | 1719 | else if (addrlen == sizeof(struct IPv4TcpAddress)) |
1860 | { | 1720 | { |
1861 | t4 = addr; | 1721 | t4 = addr; |
1862 | memset (&a4, 0, sizeof (a4)); | 1722 | memset (&a4, 0, sizeof(a4)); |
1863 | a4.sin_family = AF_INET; | 1723 | a4.sin_family = AF_INET; |
1864 | a4.sin_port = t4->t4_port; | 1724 | a4.sin_port = t4->t4_port; |
1865 | a4.sin_addr.s_addr = t4->ipv4_addr; | 1725 | a4.sin_addr.s_addr = t4->ipv4_addr; |
1866 | port = ntohs (t4->t4_port); | 1726 | port = ntohs (t4->t4_port); |
1867 | options = ntohl (t4->options); | 1727 | options = ntohl (t4->options); |
1868 | sb = &a4; | 1728 | sb = &a4; |
1869 | sbs = sizeof (a4); | 1729 | sbs = sizeof(a4); |
1870 | } | 1730 | } |
1871 | else if (0 == addrlen) | 1731 | else if (0 == addrlen) |
1872 | { | 1732 | { |
1873 | asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); | 1733 | asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); |
1874 | asc (asc_cls, NULL); | 1734 | asc (asc_cls, NULL ); |
1875 | return; | 1735 | return; |
1876 | } | 1736 | } |
1877 | else | 1737 | else |
1878 | { | 1738 | { |
1879 | /* invalid address */ | 1739 | /* invalid address */ |
1880 | GNUNET_break_op (0); | 1740 | GNUNET_break_op(0); |
1881 | asc (asc_cls, NULL); | 1741 | asc (asc_cls, NULL ); |
1882 | return; | 1742 | return; |
1883 | } | 1743 | } |
1884 | ppc = GNUNET_new (struct PrettyPrinterContext); | 1744 | ppc = GNUNET_new (struct PrettyPrinterContext); |
1885 | if (addrlen == sizeof (struct IPv6TcpAddress)) | 1745 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
1886 | ppc->ipv6 = GNUNET_YES; | 1746 | ppc->ipv6 = GNUNET_YES; |
1887 | else | 1747 | else |
1888 | ppc->ipv6 = GNUNET_NO; | 1748 | ppc->ipv6 = GNUNET_NO; |
@@ -1890,24 +1750,22 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type, | |||
1890 | ppc->asc_cls = asc_cls; | 1750 | ppc->asc_cls = asc_cls; |
1891 | ppc->port = port; | 1751 | ppc->port = port; |
1892 | ppc->options = options; | 1752 | ppc->options = options; |
1893 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(timeout, 2), | 1753 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( |
1894 | &ppc_cancel_task, ppc); | 1754 | GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); |
1895 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, | 1755 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, |
1896 | timeout, | 1756 | timeout, &append_port, ppc); |
1897 | &append_port, ppc); | ||
1898 | if (NULL != ppc->resolver_handle) | 1757 | if (NULL != ppc->resolver_handle) |
1899 | { | 1758 | { |
1900 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding request %p\n", ppc); | 1759 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding request %p\n", ppc); |
1901 | GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc); | 1760 | GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); |
1902 | } | 1761 | } |
1903 | else | 1762 | else |
1904 | { | 1763 | { |
1905 | GNUNET_break (0); | 1764 | GNUNET_break(0); |
1906 | GNUNET_free (ppc); | 1765 | GNUNET_free(ppc); |
1907 | } | 1766 | } |
1908 | } | 1767 | } |
1909 | 1768 | ||
1910 | |||
1911 | /** | 1769 | /** |
1912 | * Check if the given port is plausible (must be either our listen | 1770 | * Check if the given port is plausible (must be either our listen |
1913 | * port or our advertised port), or any port if we are behind NAT | 1771 | * port or our advertised port), or any port if we are behind NAT |
@@ -1926,7 +1784,6 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1926 | return GNUNET_SYSERR; | 1784 | return GNUNET_SYSERR; |
1927 | } | 1785 | } |
1928 | 1786 | ||
1929 | |||
1930 | /** | 1787 | /** |
1931 | * Function that will be called to check if a binary address for this | 1788 | * Function that will be called to check if a binary address for this |
1932 | * plugin is well-formed and corresponds to an address for THIS peer | 1789 | * plugin is well-formed and corresponds to an address for THIS peer |
@@ -1949,26 +1806,26 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1949 | struct IPv4TcpAddress *v4; | 1806 | struct IPv4TcpAddress *v4; |
1950 | struct IPv6TcpAddress *v6; | 1807 | struct IPv6TcpAddress *v6; |
1951 | 1808 | ||
1952 | if ((addrlen != sizeof (struct IPv4TcpAddress)) && | 1809 | if ((addrlen != sizeof(struct IPv4TcpAddress)) |
1953 | (addrlen != sizeof (struct IPv6TcpAddress))) | 1810 | && (addrlen != sizeof(struct IPv6TcpAddress))) |
1954 | { | 1811 | { |
1955 | GNUNET_break_op (0); | 1812 | GNUNET_break_op(0); |
1956 | return GNUNET_SYSERR; | 1813 | return GNUNET_SYSERR; |
1957 | } | 1814 | } |
1958 | 1815 | ||
1959 | if (addrlen == sizeof (struct IPv4TcpAddress)) | 1816 | if (addrlen == sizeof(struct IPv4TcpAddress)) |
1960 | { | 1817 | { |
1961 | v4 = (struct IPv4TcpAddress *) addr; | 1818 | v4 = (struct IPv4TcpAddress *) addr; |
1962 | if (0 != memcmp (&v4->options, &myoptions, sizeof (myoptions))) | 1819 | if (0 != memcmp (&v4->options, &myoptions, sizeof(myoptions))) |
1963 | { | 1820 | { |
1964 | GNUNET_break (0); | 1821 | GNUNET_break(0); |
1965 | return GNUNET_SYSERR; | 1822 | return GNUNET_SYSERR; |
1966 | } | 1823 | } |
1967 | if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) | 1824 | if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) |
1968 | return GNUNET_SYSERR; | 1825 | return GNUNET_SYSERR; |
1969 | if (GNUNET_OK != | 1826 | if (GNUNET_OK |
1970 | GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, | 1827 | != GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, |
1971 | sizeof (struct in_addr))) | 1828 | sizeof(struct in_addr))) |
1972 | return GNUNET_SYSERR; | 1829 | return GNUNET_SYSERR; |
1973 | } | 1830 | } |
1974 | else | 1831 | else |
@@ -1976,25 +1833,24 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1976 | v6 = (struct IPv6TcpAddress *) addr; | 1833 | v6 = (struct IPv6TcpAddress *) addr; |
1977 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | 1834 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
1978 | { | 1835 | { |
1979 | GNUNET_break_op (0); | 1836 | GNUNET_break_op(0); |
1980 | return GNUNET_SYSERR; | 1837 | return GNUNET_SYSERR; |
1981 | } | 1838 | } |
1982 | if (0 != memcmp (&v6->options, &myoptions, sizeof (myoptions))) | 1839 | if (0 != memcmp (&v6->options, &myoptions, sizeof(myoptions))) |
1983 | { | 1840 | { |
1984 | GNUNET_break (0); | 1841 | GNUNET_break(0); |
1985 | return GNUNET_SYSERR; | 1842 | return GNUNET_SYSERR; |
1986 | } | 1843 | } |
1987 | if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port))) | 1844 | if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port))) |
1988 | return GNUNET_SYSERR; | 1845 | return GNUNET_SYSERR; |
1989 | if (GNUNET_OK != | 1846 | if (GNUNET_OK |
1990 | GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, | 1847 | != GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, |
1991 | sizeof (struct in6_addr))) | 1848 | sizeof(struct in6_addr))) |
1992 | return GNUNET_SYSERR; | 1849 | return GNUNET_SYSERR; |
1993 | } | 1850 | } |
1994 | return GNUNET_OK; | 1851 | return GNUNET_OK; |
1995 | } | 1852 | } |
1996 | 1853 | ||
1997 | |||
1998 | /** | 1854 | /** |
1999 | * We've received a nat probe from this peer via TCP. Finish | 1855 | * We've received a nat probe from this peer via TCP. Finish |
2000 | * creating the client session and resume sending of queued | 1856 | * creating the client session and resume sending of queued |
@@ -2005,9 +1861,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
2005 | * @param message the actual message | 1861 | * @param message the actual message |
2006 | */ | 1862 | */ |
2007 | static void | 1863 | static void |
2008 | handle_tcp_nat_probe (void *cls, | 1864 | handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, |
2009 | struct GNUNET_SERVER_Client *client, | 1865 | const struct GNUNET_MessageHeader *message) |
2010 | const struct GNUNET_MessageHeader *message) | ||
2011 | { | 1866 | { |
2012 | struct Plugin *plugin = cls; | 1867 | struct Plugin *plugin = cls; |
2013 | struct Session *session; | 1868 | struct Session *session; |
@@ -2019,45 +1874,40 @@ handle_tcp_nat_probe (void *cls, | |||
2019 | const struct sockaddr_in *s4; | 1874 | const struct sockaddr_in *s4; |
2020 | const struct sockaddr_in6 *s6; | 1875 | const struct sockaddr_in6 *s6; |
2021 | 1876 | ||
2022 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1877 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); |
2023 | "Received NAT probe\n"); | ||
2024 | /* We have received a TCP NAT probe, meaning we (hopefully) initiated | 1878 | /* We have received a TCP NAT probe, meaning we (hopefully) initiated |
2025 | * a connection to this peer by running gnunet-nat-client. This peer | 1879 | * a connection to this peer by running gnunet-nat-client. This peer |
2026 | * received the punch message and now wants us to use the new connection | 1880 | * received the punch message and now wants us to use the new connection |
2027 | * as the default for that peer. Do so and then send a WELCOME message | 1881 | * as the default for that peer. Do so and then send a WELCOME message |
2028 | * so we can really be connected! | 1882 | * so we can really be connected! |
2029 | */ | 1883 | */ |
2030 | if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage)) | 1884 | if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage)) |
2031 | { | 1885 | { |
2032 | GNUNET_break_op (0); | 1886 | GNUNET_break_op(0); |
2033 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1887 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2034 | return; | 1888 | return; |
2035 | } | 1889 | } |
2036 | 1890 | ||
2037 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; | 1891 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; |
2038 | if (0 == | 1892 | if (0 == memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, |
2039 | memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, | 1893 | sizeof(struct GNUNET_PeerIdentity))) |
2040 | sizeof (struct GNUNET_PeerIdentity))) | ||
2041 | { | 1894 | { |
2042 | /* refuse connections from ourselves */ | 1895 | /* refuse connections from ourselves */ |
2043 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1896 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2044 | return; | 1897 | return; |
2045 | } | 1898 | } |
2046 | 1899 | ||
2047 | session = | 1900 | session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, |
2048 | GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, | 1901 | &tcp_nat_probe->clientIdentity); |
2049 | &tcp_nat_probe->clientIdentity); | 1902 | if (session == NULL ) |
2050 | if (session == NULL) | ||
2051 | { | 1903 | { |
2052 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1904 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); |
2053 | "Did NOT find session for NAT probe!\n"); | ||
2054 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1905 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2055 | return; | 1906 | return; |
2056 | } | 1907 | } |
2057 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1908 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); |
2058 | "Found session for NAT probe!\n"); | ||
2059 | 1909 | ||
2060 | if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK) | 1910 | if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK ) |
2061 | { | 1911 | { |
2062 | GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); | 1912 | GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); |
2063 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; | 1913 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; |
@@ -2065,24 +1915,19 @@ handle_tcp_nat_probe (void *cls, | |||
2065 | 1915 | ||
2066 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 1916 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
2067 | { | 1917 | { |
2068 | GNUNET_break (0); | 1918 | GNUNET_break(0); |
2069 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1919 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2070 | tcp_disconnect_session (plugin, session); | 1920 | tcp_disconnect_session (plugin, session); |
2071 | return; | 1921 | return; |
2072 | } | 1922 | } |
2073 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove | 1923 | GNUNET_assert( |
2074 | (plugin->nat_wait_conns, | 1924 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &tcp_nat_probe->clientIdentity, session) == GNUNET_YES); |
2075 | &tcp_nat_probe->clientIdentity, | 1925 | GNUNET_SERVER_client_set_user_context(client, session); |
2076 | session) == GNUNET_YES); | 1926 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, |
2077 | GNUNET_SERVER_client_set_user_context (client, session); | 1927 | session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2078 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | ||
2079 | &session->target, session, | ||
2080 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2081 | session->last_activity = GNUNET_TIME_absolute_get (); | 1928 | session->last_activity = GNUNET_TIME_absolute_get (); |
2082 | session->inbound = GNUNET_NO; | 1929 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found address `%s' for incoming connection\n", |
2083 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1930 | GNUNET_a2s (vaddr, alen)); |
2084 | "Found address `%s' for incoming connection\n", | ||
2085 | GNUNET_a2s (vaddr, alen)); | ||
2086 | switch (((const struct sockaddr *) vaddr)->sa_family) | 1931 | switch (((const struct sockaddr *) vaddr)->sa_family) |
2087 | { | 1932 | { |
2088 | case AF_INET: | 1933 | case AF_INET: |
@@ -2091,39 +1936,38 @@ handle_tcp_nat_probe (void *cls, | |||
2091 | t4->options = 0; | 1936 | t4->options = 0; |
2092 | t4->t4_port = s4->sin_port; | 1937 | t4->t4_port = s4->sin_port; |
2093 | t4->ipv4_addr = s4->sin_addr.s_addr; | 1938 | t4->ipv4_addr = s4->sin_addr.s_addr; |
2094 | session->addr = t4; | 1939 | session->address = GNUNET_HELLO_address_allocate ( |
2095 | session->addrlen = sizeof (struct IPv4TcpAddress); | 1940 | &tcp_nat_probe->clientIdentity, PLUGIN_NAME, &t4, |
1941 | sizeof(struct IPv4TcpAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2096 | break; | 1942 | break; |
2097 | case AF_INET6: | 1943 | case AF_INET6: |
2098 | s6 = vaddr; | 1944 | s6 = vaddr; |
2099 | t6 = GNUNET_new (struct IPv6TcpAddress); | 1945 | t6 = GNUNET_new (struct IPv6TcpAddress); |
2100 | t6->options = 0; | 1946 | t6->options = 0; |
2101 | t6->t6_port = s6->sin6_port; | 1947 | t6->t6_port = s6->sin6_port; |
2102 | memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); | 1948 | memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); |
2103 | session->addr = t6; | 1949 | session->address = GNUNET_HELLO_address_allocate ( |
2104 | session->addrlen = sizeof (struct IPv6TcpAddress); | 1950 | &tcp_nat_probe->clientIdentity, PLUGIN_NAME, &t6, |
1951 | sizeof(struct IPv6TcpAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2105 | break; | 1952 | break; |
2106 | default: | 1953 | default: |
2107 | GNUNET_break_op (0); | 1954 | GNUNET_break_op(0); |
2108 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1955 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); |
2109 | "Bad address for incoming connection!\n"); | 1956 | GNUNET_free(vaddr); |
2110 | GNUNET_free (vaddr); | ||
2111 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1957 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2112 | tcp_disconnect_session (plugin, session); | 1958 | tcp_disconnect_session (plugin, session); |
2113 | return; | 1959 | return; |
2114 | } | 1960 | } |
2115 | GNUNET_free (vaddr); | 1961 | GNUNET_free(vaddr); |
2116 | GNUNET_break (NULL == session->client); | 1962 | GNUNET_break(NULL == session->client); |
2117 | GNUNET_SERVER_client_keep (client); | 1963 | GNUNET_SERVER_client_keep (client); |
2118 | session->client = client; | 1964 | session->client = client; |
2119 | GNUNET_STATISTICS_update (plugin->env->stats, | 1965 | GNUNET_STATISTICS_update (plugin->env->stats, |
2120 | gettext_noop ("# TCP sessions active"), 1, | 1966 | gettext_noop ("# TCP sessions active"), 1, GNUNET_NO); |
2121 | GNUNET_NO); | ||
2122 | process_pending_messages (session); | 1967 | process_pending_messages (session); |
2123 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1968 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2124 | } | 1969 | } |
2125 | 1970 | ||
2126 | |||
2127 | /** | 1971 | /** |
2128 | * We've received a welcome from this peer via TCP. Possibly create a | 1972 | * We've received a welcome from this peer via TCP. Possibly create a |
2129 | * fresh client record and send back our welcome. | 1973 | * fresh client record and send back our welcome. |
@@ -2134,135 +1978,120 @@ handle_tcp_nat_probe (void *cls, | |||
2134 | */ | 1978 | */ |
2135 | static void | 1979 | static void |
2136 | handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | 1980 | handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, |
2137 | const struct GNUNET_MessageHeader *message) | 1981 | const struct GNUNET_MessageHeader *message) |
2138 | { | 1982 | { |
2139 | struct Plugin *plugin = cls; | 1983 | struct Plugin *plugin = cls; |
2140 | const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; | 1984 | const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; |
2141 | struct Session *session; | 1985 | struct Session *session; |
2142 | size_t alen; | 1986 | size_t alen; |
2143 | void *vaddr; | 1987 | void *vaddr; |
2144 | struct IPv4TcpAddress *t4; | 1988 | struct IPv4TcpAddress t4; |
2145 | struct IPv6TcpAddress *t6; | 1989 | struct IPv6TcpAddress t6; |
2146 | const struct sockaddr_in *s4; | 1990 | const struct sockaddr_in *s4; |
2147 | const struct sockaddr_in6 *s6; | 1991 | const struct sockaddr_in6 *s6; |
2148 | struct GNUNET_ATS_Information ats; | 1992 | struct GNUNET_ATS_Information ats; |
2149 | 1993 | ||
2150 | if (0 == | 1994 | if (0 == memcmp (&wm->clientIdentity, plugin->env->my_identity, |
2151 | memcmp (&wm->clientIdentity, plugin->env->my_identity, | 1995 | sizeof(struct GNUNET_PeerIdentity))) |
2152 | sizeof (struct GNUNET_PeerIdentity))) | ||
2153 | { | 1996 | { |
2154 | /* refuse connections from ourselves */ | 1997 | /* refuse connections from ourselves */ |
2155 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1998 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2156 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 1999 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
2157 | { | 2000 | { |
2158 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2001 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2159 | "Received %s message from my own identity `%4s' on address `%s'\n", | 2002 | "Received %s message from my own identity `%4s' on address `%s'\n", |
2160 | "WELCOME", GNUNET_i2s (&wm->clientIdentity), GNUNET_a2s (vaddr, alen)); | 2003 | "WELCOME", GNUNET_i2s (&wm->clientIdentity), |
2161 | GNUNET_free (vaddr); | 2004 | GNUNET_a2s (vaddr, alen)); |
2005 | GNUNET_free(vaddr); | ||
2162 | } | 2006 | } |
2163 | GNUNET_break_op (0); | 2007 | GNUNET_break_op(0); |
2164 | return; | 2008 | return; |
2165 | } | 2009 | } |
2166 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2010 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received %s message from `%4s' %p\n", "WELCOME", |
2167 | "Received %s message from `%4s' %p\n", "WELCOME", | 2011 | GNUNET_i2s (&wm->clientIdentity), client); |
2168 | GNUNET_i2s (&wm->clientIdentity), client); | ||
2169 | GNUNET_STATISTICS_update (plugin->env->stats, | 2012 | GNUNET_STATISTICS_update (plugin->env->stats, |
2170 | gettext_noop ("# TCP WELCOME messages received"), 1, | 2013 | gettext_noop ("# TCP WELCOME messages received"), 1, GNUNET_NO); |
2171 | GNUNET_NO); | ||
2172 | session = lookup_session_by_client (plugin, client); | 2014 | session = lookup_session_by_client (plugin, client); |
2173 | if (NULL != session) | 2015 | if (NULL != session) |
2174 | { | 2016 | { |
2175 | if (GNUNET_OK == | 2017 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
2176 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
2177 | { | 2018 | { |
2178 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2019 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for peer `%s'\n", |
2179 | "Found existing session %p for peer `%s'\n", | 2020 | session, GNUNET_a2s (vaddr, alen)); |
2180 | session, | 2021 | GNUNET_free(vaddr); |
2181 | GNUNET_a2s (vaddr, alen)); | ||
2182 | GNUNET_free (vaddr); | ||
2183 | } | 2022 | } |
2184 | } | 2023 | } |
2185 | else | 2024 | else |
2186 | { | 2025 | { |
2187 | GNUNET_SERVER_client_keep (client); | 2026 | GNUNET_SERVER_client_keep (client); |
2188 | if (NULL != plugin->service) /* Otherwise value is incremented in tcp_access_check */ | 2027 | if (NULL != plugin->service) /* Otherwise value is incremented in tcp_access_check */ |
2189 | plugin->cur_connections++; | 2028 | plugin->cur_connections++; |
2190 | if (plugin->cur_connections == plugin->max_connections) | 2029 | if (plugin->cur_connections == plugin->max_connections) |
2191 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ | 2030 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ |
2192 | 2031 | ||
2193 | session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO); | 2032 | session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO); |
2194 | session->inbound = GNUNET_YES; | ||
2195 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 2033 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
2196 | { | 2034 | { |
2197 | if (alen == sizeof (struct sockaddr_in)) | 2035 | if (alen == sizeof(struct sockaddr_in)) |
2198 | { | 2036 | { |
2199 | s4 = vaddr; | 2037 | s4 = vaddr; |
2200 | t4 = GNUNET_new (struct IPv4TcpAddress); | 2038 | memset (&t4, '\0', sizeof (t4)); |
2201 | t4->options = htonl (0); | 2039 | t4.options = htonl (0); |
2202 | t4->t4_port = s4->sin_port; | 2040 | t4.t4_port = s4->sin_port; |
2203 | t4->ipv4_addr = s4->sin_addr.s_addr; | 2041 | t4.ipv4_addr = s4->sin_addr.s_addr; |
2204 | session->addr = t4; | 2042 | session->address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
2205 | session->addrlen = sizeof (struct IPv4TcpAddress); | 2043 | PLUGIN_NAME, &t4, sizeof(struct IPv4TcpAddress), |
2044 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
2206 | } | 2045 | } |
2207 | else if (alen == sizeof (struct sockaddr_in6)) | 2046 | else if (alen == sizeof(struct sockaddr_in6)) |
2208 | { | 2047 | { |
2209 | s6 = vaddr; | 2048 | s6 = vaddr; |
2210 | t6 = GNUNET_new (struct IPv6TcpAddress); | 2049 | memset (&t6, '\0', sizeof (t6)); |
2211 | t6->options = htonl (0); | 2050 | t6.options = htonl (0); |
2212 | t6->t6_port = s6->sin6_port; | 2051 | t6.t6_port = s6->sin6_port; |
2213 | memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); | 2052 | memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); |
2214 | session->addr = t6; | 2053 | session->address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
2215 | session->addrlen = sizeof (struct IPv6TcpAddress); | 2054 | PLUGIN_NAME, &t6, sizeof(struct IPv6TcpAddress), |
2055 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
2216 | } | 2056 | } |
2217 | 2057 | ||
2218 | ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen); | 2058 | ats = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); |
2219 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl (ats.value); | 2059 | session->ats_address_network_type = (enum GNUNET_ATS_Network_Type) ntohl ( |
2220 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2060 | ats.value); |
2221 | "Creating new session %p for peer `%s'\n", | 2061 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new session %p for peer `%s'\n", |
2222 | session, | 2062 | session, GNUNET_a2s (vaddr, alen)); |
2223 | GNUNET_a2s (vaddr, alen)); | 2063 | GNUNET_free(vaddr); |
2224 | GNUNET_free (vaddr); | 2064 | GNUNET_SERVER_client_set_user_context(session->client, session); |
2225 | GNUNET_SERVER_client_set_user_context (session->client, session); | 2065 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, &session->target, |
2226 | GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 2066 | session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2227 | &session->target, | ||
2228 | session, | ||
2229 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2230 | } | 2067 | } |
2231 | else | 2068 | else |
2232 | { | 2069 | { |
2233 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2070 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2234 | "Did not obtain TCP socket address for incoming connection\n"); | 2071 | "Did not obtain TCP socket address for incoming connection\n"); |
2235 | GNUNET_break (0); | 2072 | GNUNET_break(0); |
2236 | } | 2073 | } |
2237 | } | 2074 | } |
2238 | 2075 | ||
2239 | if (session->expecting_welcome != GNUNET_YES) | 2076 | if (session->expecting_welcome != GNUNET_YES) |
2240 | { | 2077 | { |
2241 | GNUNET_break_op (0); | 2078 | GNUNET_break_op(0); |
2242 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2079 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2243 | GNUNET_break (0); | 2080 | GNUNET_break(0); |
2244 | return; | 2081 | return; |
2245 | } | 2082 | } |
2246 | session->last_activity = GNUNET_TIME_absolute_get (); | 2083 | session->last_activity = GNUNET_TIME_absolute_get (); |
2247 | session->expecting_welcome = GNUNET_NO; | 2084 | session->expecting_welcome = GNUNET_NO; |
2248 | 2085 | ||
2249 | /* Notify transport and ATS about new session */ | 2086 | /* Notify transport and ATS about new session */ |
2250 | if (GNUNET_YES == session->inbound) | 2087 | plugin->env->session_start (NULL, session->address, session, &ats, 1); |
2251 | { | 2088 | |
2252 | plugin->env->session_start (NULL, | ||
2253 | &wm->clientIdentity, | ||
2254 | PLUGIN_NAME, | ||
2255 | (GNUNET_YES == session->inbound) ? NULL : session->addr, | ||
2256 | (GNUNET_YES == session->inbound) ? 0 : session->addrlen, | ||
2257 | session, &ats, 1); | ||
2258 | } | ||
2259 | process_pending_messages (session); | 2089 | process_pending_messages (session); |
2260 | GNUNET_SERVER_client_set_timeout (client, | 2090 | GNUNET_SERVER_client_set_timeout (client, |
2261 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2091 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
2262 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2092 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2263 | } | 2093 | } |
2264 | 2094 | ||
2265 | |||
2266 | /** | 2095 | /** |
2267 | * Task to signal the server that we can continue | 2096 | * Task to signal the server that we can continue |
2268 | * receiving from the TCP client now. | 2097 | * receiving from the TCP client now. |
@@ -2271,8 +2100,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2271 | * @param tc task context (unused) | 2100 | * @param tc task context (unused) |
2272 | */ | 2101 | */ |
2273 | static void | 2102 | static void |
2274 | delayed_done (void *cls, | 2103 | delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2275 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2276 | { | 2104 | { |
2277 | struct Session *session = cls; | 2105 | struct Session *session = cls; |
2278 | 2106 | ||
@@ -2282,7 +2110,6 @@ delayed_done (void *cls, | |||
2282 | GNUNET_SERVER_receive_done (session->client, GNUNET_OK); | 2110 | GNUNET_SERVER_receive_done (session->client, GNUNET_OK); |
2283 | } | 2111 | } |
2284 | 2112 | ||
2285 | |||
2286 | /** | 2113 | /** |
2287 | * We've received data for this peer via TCP. Unbox, | 2114 | * We've received data for this peer via TCP. Unbox, |
2288 | * compute latency and forward. | 2115 | * compute latency and forward. |
@@ -2293,7 +2120,7 @@ delayed_done (void *cls, | |||
2293 | */ | 2120 | */ |
2294 | static void | 2121 | static void |
2295 | handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | 2122 | handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, |
2296 | const struct GNUNET_MessageHeader *message) | 2123 | const struct GNUNET_MessageHeader *message) |
2297 | { | 2124 | { |
2298 | struct Plugin *plugin = cls; | 2125 | struct Plugin *plugin = cls; |
2299 | struct Session *session; | 2126 | struct Session *session; |
@@ -2301,8 +2128,8 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
2301 | uint16_t type; | 2128 | uint16_t type; |
2302 | 2129 | ||
2303 | type = ntohs (message->type); | 2130 | type = ntohs (message->type); |
2304 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || | 2131 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) |
2305 | (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) | 2132 | || (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) |
2306 | { | 2133 | { |
2307 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ | 2134 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ |
2308 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2135 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -2316,12 +2143,11 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
2316 | size_t alen; | 2143 | size_t alen; |
2317 | 2144 | ||
2318 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2145 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
2319 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2146 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2320 | "Received unexpected %u bytes of type %u from `%s'\n", | 2147 | "Received unexpected %u bytes of type %u from `%s'\n", |
2321 | (unsigned int) ntohs (message->size), | 2148 | (unsigned int ) ntohs (message->size), |
2322 | (unsigned int) ntohs (message->type), | 2149 | (unsigned int ) ntohs (message->type), GNUNET_a2s (vaddr, alen)); |
2323 | GNUNET_a2s(vaddr, alen)); | 2150 | GNUNET_break_op(0); |
2324 | GNUNET_break_op (0); | ||
2325 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2151 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2326 | GNUNET_free_non_null(vaddr); | 2152 | GNUNET_free_non_null(vaddr); |
2327 | return; | 2153 | return; |
@@ -2333,48 +2159,38 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
2333 | size_t alen; | 2159 | size_t alen; |
2334 | 2160 | ||
2335 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2161 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
2336 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2162 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2337 | "Received unexpected %u bytes of type %u from `%s'\n", | 2163 | "Received unexpected %u bytes of type %u from `%s'\n", |
2338 | (unsigned int) ntohs (message->size), | 2164 | (unsigned int ) ntohs (message->size), |
2339 | (unsigned int) ntohs (message->type), | 2165 | (unsigned int ) ntohs (message->type), GNUNET_a2s (vaddr, alen)); |
2340 | GNUNET_a2s(vaddr, alen)); | 2166 | GNUNET_break_op(0); |
2341 | GNUNET_break_op (0); | ||
2342 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2167 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2343 | GNUNET_free_non_null(vaddr); | 2168 | GNUNET_free_non_null(vaddr); |
2344 | return; | 2169 | return; |
2345 | } | 2170 | } |
2346 | 2171 | ||
2347 | session->last_activity = GNUNET_TIME_absolute_get (); | 2172 | session->last_activity = GNUNET_TIME_absolute_get (); |
2348 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2173 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2349 | "Passing %u bytes of type %u from `%4s' to transport service.\n", | 2174 | "Passing %u bytes of type %u from `%4s' to transport service.\n", |
2350 | (unsigned int) ntohs (message->size), | 2175 | (unsigned int ) ntohs (message->size), |
2351 | (unsigned int) ntohs (message->type), | 2176 | (unsigned int ) ntohs (message->type), GNUNET_i2s (&session->target)); |
2352 | GNUNET_i2s (&session->target)); | ||
2353 | 2177 | ||
2354 | GNUNET_STATISTICS_update (plugin->env->stats, | 2178 | GNUNET_STATISTICS_update (plugin->env->stats, |
2355 | gettext_noop ("# bytes received via TCP"), | 2179 | gettext_noop ("# bytes received via TCP"), ntohs (message->size), |
2356 | ntohs (message->size), GNUNET_NO); | 2180 | GNUNET_NO); |
2357 | struct GNUNET_ATS_Information distance; | 2181 | struct GNUNET_ATS_Information distance; |
2358 | 2182 | ||
2359 | distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 2183 | distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
2360 | distance.value = htonl ((uint32_t) session->ats_address_network_type); | 2184 | distance.value = htonl ((uint32_t) session->ats_address_network_type); |
2361 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | 2185 | GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
2362 | 2186 | ||
2363 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | 2187 | GNUNET_assert( |
2364 | &session->target, | 2188 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
2365 | session)); | 2189 | &session->target, session)); |
2366 | 2190 | ||
2367 | delay = plugin->env->receive (plugin->env->cls, | 2191 | delay = plugin->env->receive (plugin->env->cls, session->address, session, message); |
2368 | &session->target, | 2192 | plugin->env->update_address_metrics (plugin->env->cls, session->address, |
2369 | message, | 2193 | session, &distance, 1); |
2370 | session, | ||
2371 | (GNUNET_YES == session->inbound) ? NULL : session->addr, | ||
2372 | (GNUNET_YES == session->inbound) ? 0 : session->addrlen); | ||
2373 | plugin->env->update_address_metrics (plugin->env->cls, | ||
2374 | &session->target, | ||
2375 | (GNUNET_YES == session->inbound) ? NULL : session->addr, | ||
2376 | (GNUNET_YES == session->inbound) ? 0 : session->addrlen, | ||
2377 | session, &distance, 1); | ||
2378 | reschedule_session_timeout (session); | 2194 | reschedule_session_timeout (session); |
2379 | if (0 == delay.rel_value_us) | 2195 | if (0 == delay.rel_value_us) |
2380 | { | 2196 | { |
@@ -2382,17 +2198,15 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client, | |||
2382 | } | 2198 | } |
2383 | else | 2199 | else |
2384 | { | 2200 | { |
2385 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2201 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Throttling receiving from `%s' for %s\n", |
2386 | "Throttling receiving from `%s' for %s\n", | 2202 | GNUNET_i2s (&session->target), |
2387 | GNUNET_i2s (&session->target), | 2203 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
2388 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); | ||
2389 | GNUNET_SERVER_disable_receive_done_warning (client); | 2204 | GNUNET_SERVER_disable_receive_done_warning (client); |
2390 | session->receive_delay_task = | 2205 | session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, |
2391 | GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); | 2206 | &delayed_done, session); |
2392 | } | 2207 | } |
2393 | } | 2208 | } |
2394 | 2209 | ||
2395 | |||
2396 | /** | 2210 | /** |
2397 | * Functions with this signature are called whenever a peer | 2211 | * Functions with this signature are called whenever a peer |
2398 | * is disconnected on the network level. | 2212 | * is disconnected on the network level. |
@@ -2406,36 +2220,30 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2406 | struct Plugin *plugin = cls; | 2220 | struct Plugin *plugin = cls; |
2407 | struct Session *session; | 2221 | struct Session *session; |
2408 | 2222 | ||
2409 | if (client == NULL) | 2223 | if (client == NULL ) |
2410 | return; | 2224 | return; |
2411 | session = lookup_session_by_client (plugin, client); | 2225 | session = lookup_session_by_client (plugin, client); |
2412 | if (session == NULL) | 2226 | if (session == NULL ) |
2413 | return; /* unknown, nothing to do */ | 2227 | return; /* unknown, nothing to do */ |
2414 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2228 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2415 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", | 2229 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", |
2416 | GNUNET_i2s (&session->target), | 2230 | GNUNET_i2s (&session->target), |
2417 | (session->addr != | 2231 | tcp_address_to_string (session->plugin, session->address->address, |
2418 | NULL) ? tcp_address_to_string (session->plugin, | 2232 | session->address->address_length)); |
2419 | session->addr, | ||
2420 | session->addrlen) : | ||
2421 | "*"); | ||
2422 | 2233 | ||
2423 | if (plugin->cur_connections == plugin->max_connections) | 2234 | if (plugin->cur_connections == plugin->max_connections) |
2424 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ | 2235 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ |
2425 | 2236 | ||
2426 | if (plugin->cur_connections < 1) | 2237 | if (plugin->cur_connections < 1) |
2427 | GNUNET_break (0); | 2238 | GNUNET_break(0); |
2428 | else | 2239 | else |
2429 | plugin->cur_connections--; | 2240 | plugin->cur_connections--; |
2430 | 2241 | ||
2431 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 2242 | GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop |
2432 | gettext_noop | 2243 | ("# network-level TCP disconnect events"), 1, GNUNET_NO); |
2433 | ("# network-level TCP disconnect events"), 1, | ||
2434 | GNUNET_NO); | ||
2435 | tcp_disconnect_session (plugin, session); | 2244 | tcp_disconnect_session (plugin, session); |
2436 | } | 2245 | } |
2437 | 2246 | ||
2438 | |||
2439 | /** | 2247 | /** |
2440 | * We can now send a probe message, copy into buffer to really send. | 2248 | * We can now send a probe message, copy into buffer to really send. |
2441 | * | 2249 | * |
@@ -2452,24 +2260,23 @@ notify_send_probe (void *cls, size_t size, void *buf) | |||
2452 | size_t ret; | 2260 | size_t ret; |
2453 | 2261 | ||
2454 | tcp_probe_ctx->transmit_handle = NULL; | 2262 | tcp_probe_ctx->transmit_handle = NULL; |
2455 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail, | 2263 | GNUNET_CONTAINER_DLL_remove(plugin->probe_head, plugin->probe_tail, |
2456 | tcp_probe_ctx); | 2264 | tcp_probe_ctx); |
2457 | if (buf == NULL) | 2265 | if (buf == NULL ) |
2458 | { | 2266 | { |
2459 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); | 2267 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); |
2460 | GNUNET_free (tcp_probe_ctx); | 2268 | GNUNET_free(tcp_probe_ctx); |
2461 | return 0; | 2269 | return 0; |
2462 | } | 2270 | } |
2463 | GNUNET_assert (size >= sizeof (tcp_probe_ctx->message)); | 2271 | GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); |
2464 | memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message)); | 2272 | memcpy (buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); |
2465 | GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, | 2273 | GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, |
2466 | tcp_probe_ctx->sock); | 2274 | tcp_probe_ctx->sock); |
2467 | ret = sizeof (tcp_probe_ctx->message); | 2275 | ret = sizeof(tcp_probe_ctx->message); |
2468 | GNUNET_free (tcp_probe_ctx); | 2276 | GNUNET_free(tcp_probe_ctx); |
2469 | return ret; | 2277 | return ret; |
2470 | } | 2278 | } |
2471 | 2279 | ||
2472 | |||
2473 | /** | 2280 | /** |
2474 | * Function called by the NAT subsystem suggesting another peer wants | 2281 | * Function called by the NAT subsystem suggesting another peer wants |
2475 | * to connect to us via connection reversal. Try to connect back to the | 2282 | * to connect to us via connection reversal. Try to connect back to the |
@@ -2481,7 +2288,7 @@ notify_send_probe (void *cls, size_t size, void *buf) | |||
2481 | */ | 2288 | */ |
2482 | static void | 2289 | static void |
2483 | try_connection_reversal (void *cls, const struct sockaddr *addr, | 2290 | try_connection_reversal (void *cls, const struct sockaddr *addr, |
2484 | socklen_t addrlen) | 2291 | socklen_t addrlen) |
2485 | { | 2292 | { |
2486 | struct Plugin *plugin = cls; | 2293 | struct Plugin *plugin = cls; |
2487 | struct GNUNET_CONNECTION_Handle *sock; | 2294 | struct GNUNET_CONNECTION_Handle *sock; |
@@ -2492,7 +2299,7 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, | |||
2492 | * that wants to connect to us! Send a message to establish a connection. | 2299 | * that wants to connect to us! Send a message to establish a connection. |
2493 | */ | 2300 | */ |
2494 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); | 2301 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); |
2495 | if (sock == NULL) | 2302 | if (sock == NULL ) |
2496 | { | 2303 | { |
2497 | /* failed for some odd reason (out of sockets?); ignore attempt */ | 2304 | /* failed for some odd reason (out of sockets?); ignore attempt */ |
2498 | return; | 2305 | return; |
@@ -2501,27 +2308,22 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, | |||
2501 | /* FIXME: do we need to track these probe context objects so that | 2308 | /* FIXME: do we need to track these probe context objects so that |
2502 | * we can clean them up on plugin unload? */ | 2309 | * we can clean them up on plugin unload? */ |
2503 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); | 2310 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); |
2504 | tcp_probe_ctx->message.header.size = | 2311 | tcp_probe_ctx->message.header.size = htons ( |
2505 | htons (sizeof (struct TCP_NAT_ProbeMessage)); | 2312 | sizeof(struct TCP_NAT_ProbeMessage)); |
2506 | tcp_probe_ctx->message.header.type = | 2313 | tcp_probe_ctx->message.header.type = htons ( |
2507 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); | 2314 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); |
2508 | memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, | 2315 | memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, |
2509 | sizeof (struct GNUNET_PeerIdentity)); | 2316 | sizeof(struct GNUNET_PeerIdentity)); |
2510 | tcp_probe_ctx->plugin = plugin; | 2317 | tcp_probe_ctx->plugin = plugin; |
2511 | tcp_probe_ctx->sock = sock; | 2318 | tcp_probe_ctx->sock = sock; |
2512 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, plugin->probe_tail, | 2319 | GNUNET_CONTAINER_DLL_insert(plugin->probe_head, plugin->probe_tail, |
2513 | tcp_probe_ctx); | 2320 | tcp_probe_ctx); |
2514 | tcp_probe_ctx->transmit_handle = | 2321 | tcp_probe_ctx->transmit_handle = GNUNET_CONNECTION_notify_transmit_ready ( |
2515 | GNUNET_CONNECTION_notify_transmit_ready (sock, | 2322 | sock, ntohs (tcp_probe_ctx->message.header.size), |
2516 | ntohs (tcp_probe_ctx-> | 2323 | GNUNET_TIME_UNIT_FOREVER_REL, ¬ify_send_probe, tcp_probe_ctx); |
2517 | message.header.size), | ||
2518 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2519 | ¬ify_send_probe, | ||
2520 | tcp_probe_ctx); | ||
2521 | 2324 | ||
2522 | } | 2325 | } |
2523 | 2326 | ||
2524 | |||
2525 | /** | 2327 | /** |
2526 | * Function obtain the network type for a session | 2328 | * Function obtain the network type for a session |
2527 | * | 2329 | * |
@@ -2530,14 +2332,12 @@ try_connection_reversal (void *cls, const struct sockaddr *addr, | |||
2530 | * @return the network type in HBO or #GNUNET_SYSERR | 2332 | * @return the network type in HBO or #GNUNET_SYSERR |
2531 | */ | 2333 | */ |
2532 | static enum GNUNET_ATS_Network_Type | 2334 | static enum GNUNET_ATS_Network_Type |
2533 | tcp_get_network (void *cls, | 2335 | tcp_get_network (void *cls, struct Session *session) |
2534 | struct Session *session) | ||
2535 | { | 2336 | { |
2536 | GNUNET_assert (NULL != session); | 2337 | GNUNET_assert(NULL != session); |
2537 | return session->ats_address_network_type; | 2338 | return session->ats_address_network_type; |
2538 | } | 2339 | } |
2539 | 2340 | ||
2540 | |||
2541 | /** | 2341 | /** |
2542 | * Entry point for the plugin. | 2342 | * Entry point for the plugin. |
2543 | * | 2343 | * |
@@ -2547,14 +2347,12 @@ tcp_get_network (void *cls, | |||
2547 | void * | 2347 | void * |
2548 | libgnunet_plugin_transport_tcp_init (void *cls) | 2348 | libgnunet_plugin_transport_tcp_init (void *cls) |
2549 | { | 2349 | { |
2550 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { | 2350 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { { |
2551 | {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, | 2351 | &handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, |
2552 | sizeof (struct WelcomeMessage)}, | 2352 | sizeof(struct WelcomeMessage) }, { &handle_tcp_nat_probe, NULL, |
2553 | {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, | 2353 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, |
2554 | sizeof (struct TCP_NAT_ProbeMessage)}, | 2354 | sizeof(struct TCP_NAT_ProbeMessage) }, { &handle_tcp_data, NULL, |
2555 | {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, | 2355 | GNUNET_MESSAGE_TYPE_ALL, 0 }, { NULL, NULL, 0, 0 } }; |
2556 | {NULL, NULL, 0, 0} | ||
2557 | }; | ||
2558 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 2356 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
2559 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 2357 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
2560 | struct Plugin *plugin; | 2358 | struct Plugin *plugin; |
@@ -2569,11 +2367,10 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2569 | struct sockaddr **addrs; | 2367 | struct sockaddr **addrs; |
2570 | socklen_t *addrlens; | 2368 | socklen_t *addrlens; |
2571 | 2369 | ||
2572 | |||
2573 | if (NULL == env->receive) | 2370 | if (NULL == env->receive) |
2574 | { | 2371 | { |
2575 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 2372 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
2576 | initialze the plugin or the API */ | 2373 | initialze the plugin or the API */ |
2577 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2374 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2578 | api->cls = NULL; | 2375 | api->cls = NULL; |
2579 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2376 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
@@ -2582,26 +2379,24 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2582 | return api; | 2379 | return api; |
2583 | } | 2380 | } |
2584 | 2381 | ||
2585 | GNUNET_assert (NULL != env->cfg); | 2382 | GNUNET_assert(NULL != env->cfg); |
2586 | if (GNUNET_OK != | 2383 | if (GNUNET_OK |
2587 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", | 2384 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", |
2588 | "MAX_CONNECTIONS", | 2385 | "MAX_CONNECTIONS", &max_connections)) |
2589 | &max_connections)) | ||
2590 | max_connections = 128; | 2386 | max_connections = 128; |
2591 | 2387 | ||
2592 | aport = 0; | 2388 | aport = 0; |
2593 | if ((GNUNET_OK != | 2389 | if ((GNUNET_OK |
2594 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", "PORT", | 2390 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", |
2595 | &bport)) || (bport > 65535) || | 2391 | "PORT", &bport)) || (bport > 65535) |
2596 | ((GNUNET_OK == | 2392 | || ((GNUNET_OK |
2597 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", | 2393 | == GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", |
2598 | "ADVERTISED-PORT", &aport)) && | 2394 | "ADVERTISED-PORT", &aport)) && (aport > 65535))) |
2599 | (aport > 65535))) | 2395 | { |
2600 | { | 2396 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2601 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2397 | _("Require valid port number for service `%s' in configuration!\n"), |
2602 | _("Require valid port number for service `%s' in configuration!\n"), | 2398 | "transport-tcp"); |
2603 | "transport-tcp"); | 2399 | return NULL ; |
2604 | return NULL; | ||
2605 | } | 2400 | } |
2606 | if (aport == 0) | 2401 | if (aport == 0) |
2607 | aport = bport; | 2402 | aport = bport; |
@@ -2609,12 +2404,12 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2609 | aport = 0; | 2404 | aport = 0; |
2610 | if (bport != 0) | 2405 | if (bport != 0) |
2611 | { | 2406 | { |
2612 | service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, GNUNET_SERVICE_OPTION_NONE); | 2407 | service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, |
2613 | if (service == NULL) | 2408 | GNUNET_SERVICE_OPTION_NONE); |
2409 | if (service == NULL ) | ||
2614 | { | 2410 | { |
2615 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2411 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n")); |
2616 | _("Failed to start service.\n")); | 2412 | return NULL ; |
2617 | return NULL; | ||
2618 | } | 2413 | } |
2619 | } | 2414 | } |
2620 | else | 2415 | else |
@@ -2624,42 +2419,42 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2624 | myoptions = 0; | 2419 | myoptions = 0; |
2625 | 2420 | ||
2626 | plugin = GNUNET_new (struct Plugin); | 2421 | plugin = GNUNET_new (struct Plugin); |
2627 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); | 2422 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, |
2423 | GNUNET_YES); | ||
2628 | plugin->max_connections = max_connections; | 2424 | plugin->max_connections = max_connections; |
2629 | plugin->cur_connections = 0; | 2425 | plugin->cur_connections = 0; |
2630 | plugin->open_port = bport; | 2426 | plugin->open_port = bport; |
2631 | plugin->adv_port = aport; | 2427 | plugin->adv_port = aport; |
2632 | plugin->env = env; | 2428 | plugin->env = env; |
2633 | plugin->lsock = NULL; | 2429 | plugin->lsock = NULL; |
2634 | if ((service != NULL) && | 2430 | if ((service != NULL )&& |
2635 | (GNUNET_SYSERR != | 2431 | (GNUNET_SYSERR != |
2636 | (ret_s = | 2432 | (ret_s = |
2637 | GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs, | 2433 | GNUNET_SERVICE_get_server_addresses ("transport-tcp", env->cfg, &addrs, |
2638 | &addrlens)))) | 2434 | &addrlens)))){ |
2639 | { | 2435 | for (ret = ret_s-1; ret >= 0; ret--) |
2640 | for (ret = ret_s-1; ret >= 0; ret--) | 2436 | LOG (GNUNET_ERROR_TYPE_INFO, |
2641 | LOG (GNUNET_ERROR_TYPE_INFO, | 2437 | "Binding to address `%s'\n", |
2642 | "Binding to address `%s'\n", | 2438 | GNUNET_a2s (addrs[ret], addrlens[ret])); |
2643 | GNUNET_a2s (addrs[ret], addrlens[ret])); | 2439 | plugin->nat = |
2644 | plugin->nat = | 2440 | GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret_s, |
2645 | GNUNET_NAT_register (env->cfg, GNUNET_YES, aport, (unsigned int) ret_s, | 2441 | (const struct sockaddr **) addrs, addrlens, |
2646 | (const struct sockaddr **) addrs, addrlens, | 2442 | &tcp_nat_port_map_callback, |
2647 | &tcp_nat_port_map_callback, | 2443 | &try_connection_reversal, plugin); |
2648 | &try_connection_reversal, plugin); | 2444 | for (ret = ret_s -1; ret >= 0; ret--) |
2649 | for (ret = ret_s -1; ret >= 0; ret--) | 2445 | { |
2650 | { | 2446 | GNUNET_assert (addrs[ret] != NULL); |
2651 | GNUNET_assert (addrs[ret] != NULL); | 2447 | GNUNET_free (addrs[ret]); |
2652 | GNUNET_free (addrs[ret]); | 2448 | } |
2653 | } | 2449 | GNUNET_free_non_null (addrs); |
2654 | GNUNET_free_non_null (addrs); | 2450 | GNUNET_free_non_null (addrlens); |
2655 | GNUNET_free_non_null (addrlens); | 2451 | } |
2656 | } | 2452 | else |
2657 | else | 2453 | { |
2658 | { | 2454 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, |
2659 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 2455 | GNUNET_YES, 0, 0, NULL, NULL, NULL, |
2660 | GNUNET_YES, 0, 0, NULL, NULL, NULL, | 2456 | &try_connection_reversal, plugin); |
2661 | &try_connection_reversal, plugin); | 2457 | } |
2662 | } | ||
2663 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2458 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2664 | api->cls = plugin; | 2459 | api->cls = plugin; |
2665 | api->send = &tcp_plugin_send; | 2460 | api->send = &tcp_plugin_send; |
@@ -2681,51 +2476,48 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2681 | } | 2476 | } |
2682 | else | 2477 | else |
2683 | { | 2478 | { |
2684 | if (GNUNET_OK != | 2479 | if (GNUNET_OK |
2685 | GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", | 2480 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", |
2686 | "TIMEOUT", &idle_timeout)) | 2481 | "TIMEOUT", &idle_timeout)) |
2687 | { | 2482 | { |
2688 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 2483 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "transport-tcp", |
2689 | "transport-tcp", "TIMEOUT"); | 2484 | "TIMEOUT"); |
2690 | if (plugin->nat != NULL) | 2485 | if (plugin->nat != NULL ) |
2691 | GNUNET_NAT_unregister (plugin->nat); | 2486 | GNUNET_NAT_unregister (plugin->nat); |
2692 | GNUNET_free (plugin); | 2487 | GNUNET_free(plugin); |
2693 | GNUNET_free (api); | 2488 | GNUNET_free(api); |
2694 | return NULL; | 2489 | return NULL ; |
2695 | } | 2490 | } |
2696 | plugin->server = | 2491 | plugin->server = GNUNET_SERVER_create_with_sockets ( |
2697 | GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, plugin, | 2492 | &plugin_tcp_access_check, plugin, NULL, idle_timeout, GNUNET_YES); |
2698 | NULL, idle_timeout, GNUNET_YES); | ||
2699 | } | 2493 | } |
2700 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); | 2494 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); |
2701 | memcpy (plugin->handlers, my_handlers, sizeof (my_handlers)); | 2495 | memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); |
2702 | for (i = 0; | 2496 | for (i = 0; |
2703 | i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler); | 2497 | i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); |
2704 | i++) | 2498 | i++) |
2705 | plugin->handlers[i].callback_cls = plugin; | 2499 | plugin->handlers[i].callback_cls = plugin; |
2706 | 2500 | ||
2707 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); | 2501 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); |
2708 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); | 2502 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); |
2709 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); | 2503 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, |
2504 | GNUNET_YES); | ||
2710 | if (bport != 0) | 2505 | if (bport != 0) |
2711 | LOG (GNUNET_ERROR_TYPE_INFO, | 2506 | LOG(GNUNET_ERROR_TYPE_INFO, _("TCP transport listening on port %llu\n"), |
2712 | _("TCP transport listening on port %llu\n"), bport); | 2507 | bport); |
2713 | else | 2508 | else |
2714 | LOG (GNUNET_ERROR_TYPE_INFO, | 2509 | LOG(GNUNET_ERROR_TYPE_INFO, |
2715 | _("TCP transport not listening on any port (client only)\n")); | 2510 | _("TCP transport not listening on any port (client only)\n")); |
2716 | if (aport != bport) | 2511 | if (aport != bport) |
2717 | LOG (GNUNET_ERROR_TYPE_INFO, | 2512 | LOG(GNUNET_ERROR_TYPE_INFO, |
2718 | _("TCP transport advertises itself as being on port %llu\n"), | 2513 | _("TCP transport advertises itself as being on port %llu\n"), aport); |
2719 | aport); | ||
2720 | /* Initially set connections to 0 */ | 2514 | /* Initially set connections to 0 */ |
2721 | GNUNET_assert (NULL != plugin->env->stats); | 2515 | GNUNET_assert(NULL != plugin->env->stats); |
2722 | GNUNET_STATISTICS_set (plugin->env->stats, | 2516 | GNUNET_STATISTICS_set (plugin->env->stats, |
2723 | gettext_noop ("# TCP sessions active"), 0, | 2517 | gettext_noop ("# TCP sessions active"), 0, GNUNET_NO); |
2724 | GNUNET_NO); | ||
2725 | return api; | 2518 | return api; |
2726 | } | 2519 | } |
2727 | 2520 | ||
2728 | |||
2729 | /** | 2521 | /** |
2730 | * Exit point from the plugin. | 2522 | * Exit point from the plugin. |
2731 | * | 2523 | * |
@@ -2743,50 +2535,49 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
2743 | 2535 | ||
2744 | if (NULL == plugin) | 2536 | if (NULL == plugin) |
2745 | { | 2537 | { |
2746 | GNUNET_free (api); | 2538 | GNUNET_free(api); |
2747 | return NULL; | 2539 | return NULL ; |
2748 | } | 2540 | } |
2749 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2541 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); |
2750 | "Shutting down TCP plugin\n"); | ||
2751 | 2542 | ||
2752 | /* Removing leftover sessions */ | 2543 | /* Removing leftover sessions */ |
2753 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, | 2544 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
2754 | &session_disconnect_it, plugin); | 2545 | &session_disconnect_it, plugin); |
2755 | /* Removing leftover NAT sessions */ | 2546 | /* Removing leftover NAT sessions */ |
2756 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, | 2547 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, |
2757 | &session_disconnect_it, plugin); | 2548 | &session_disconnect_it, plugin); |
2758 | 2549 | ||
2759 | next = ppc_dll_head; | 2550 | next = ppc_dll_head; |
2760 | for (cur = next; NULL != cur; cur = next) | 2551 | for (cur = next; NULL != cur; cur = next) |
2761 | { | 2552 | { |
2762 | next = cur->next; | 2553 | next = cur->next; |
2763 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); | 2554 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); |
2764 | if (NULL != cur->resolver_handle) | 2555 | if (NULL != cur->resolver_handle) |
2765 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | 2556 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
2766 | GNUNET_SCHEDULER_cancel (cur->timeout_task); | 2557 | GNUNET_SCHEDULER_cancel (cur->timeout_task); |
2767 | GNUNET_free (cur); | 2558 | GNUNET_free(cur); |
2768 | GNUNET_break (0); | 2559 | GNUNET_break(0); |
2769 | } | 2560 | } |
2770 | 2561 | ||
2771 | if (plugin->service != NULL) | 2562 | if (plugin->service != NULL ) |
2772 | GNUNET_SERVICE_stop (plugin->service); | 2563 | GNUNET_SERVICE_stop (plugin->service); |
2773 | else | 2564 | else |
2774 | GNUNET_SERVER_destroy (plugin->server); | 2565 | GNUNET_SERVER_destroy (plugin->server); |
2775 | GNUNET_free (plugin->handlers); | 2566 | GNUNET_free(plugin->handlers); |
2776 | if (plugin->nat != NULL) | 2567 | if (plugin->nat != NULL ) |
2777 | GNUNET_NAT_unregister (plugin->nat); | 2568 | GNUNET_NAT_unregister (plugin->nat); |
2778 | while (NULL != (tcp_probe = plugin->probe_head)) | 2569 | while (NULL != (tcp_probe = plugin->probe_head)) |
2779 | { | 2570 | { |
2780 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, plugin->probe_tail, | 2571 | GNUNET_CONTAINER_DLL_remove(plugin->probe_head, plugin->probe_tail, |
2781 | tcp_probe); | 2572 | tcp_probe); |
2782 | GNUNET_CONNECTION_destroy (tcp_probe->sock); | 2573 | GNUNET_CONNECTION_destroy (tcp_probe->sock); |
2783 | GNUNET_free (tcp_probe); | 2574 | GNUNET_free(tcp_probe); |
2784 | } | 2575 | } |
2785 | GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); | 2576 | GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); |
2786 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); | 2577 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); |
2787 | GNUNET_free (plugin); | 2578 | GNUNET_free(plugin); |
2788 | GNUNET_free (api); | 2579 | GNUNET_free(api); |
2789 | return NULL; | 2580 | return NULL ; |
2790 | } | 2581 | } |
2791 | 2582 | ||
2792 | /* end of plugin_transport_tcp.c */ | 2583 | /* end of plugin_transport_tcp.c */ |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index d3a8d1017..836cf2ad5 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
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 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/plugin_transport_udp.c | 22 | * @file transport/plugin_transport_udp.c |
@@ -44,8 +44,6 @@ | |||
44 | 44 | ||
45 | #define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 45 | #define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
46 | 46 | ||
47 | #define PLUGIN_NAME "udp" | ||
48 | |||
49 | /** | 47 | /** |
50 | * Number of messages we can defragment in parallel. We only really | 48 | * Number of messages we can defragment in parallel. We only really |
51 | * defragment 1 message at a time, but if messages get re-ordered, we | 49 | * defragment 1 message at a time, but if messages get re-ordered, we |
@@ -127,7 +125,6 @@ struct PrettyPrinterContext | |||
127 | uint32_t options; | 125 | uint32_t options; |
128 | }; | 126 | }; |
129 | 127 | ||
130 | |||
131 | enum UDP_MessageType | 128 | enum UDP_MessageType |
132 | { | 129 | { |
133 | UNDEFINED = 0, | 130 | UNDEFINED = 0, |
@@ -138,7 +135,6 @@ enum UDP_MessageType | |||
138 | MSG_BEACON = 5 | 135 | MSG_BEACON = 5 |
139 | }; | 136 | }; |
140 | 137 | ||
141 | |||
142 | struct Session | 138 | struct Session |
143 | { | 139 | { |
144 | /** | 140 | /** |
@@ -157,11 +153,6 @@ struct Session | |||
157 | struct UDP_FragmentationContext *frag_ctx; | 153 | struct UDP_FragmentationContext *frag_ctx; |
158 | 154 | ||
159 | /** | 155 | /** |
160 | * Address of the other peer | ||
161 | */ | ||
162 | const struct sockaddr *sock_addr; | ||
163 | |||
164 | /** | ||
165 | * Desired delay for next sending we send to other peer | 156 | * Desired delay for next sending we send to other peer |
166 | */ | 157 | */ |
167 | struct GNUNET_TIME_Relative flow_delay_for_other_peer; | 158 | struct GNUNET_TIME_Relative flow_delay_for_other_peer; |
@@ -188,10 +179,7 @@ struct Session | |||
188 | 179 | ||
189 | struct GNUNET_ATS_Information ats; | 180 | struct GNUNET_ATS_Information ats; |
190 | 181 | ||
191 | /** | 182 | struct GNUNET_HELLO_Address *address; |
192 | * Number of bytes in @e sock_addr. | ||
193 | */ | ||
194 | size_t addrlen; | ||
195 | 183 | ||
196 | /** | 184 | /** |
197 | * Reference counter to indicate that this session is | 185 | * Reference counter to indicate that this session is |
@@ -208,22 +196,17 @@ struct Session | |||
208 | * @e rc is non-zero). | 196 | * @e rc is non-zero). |
209 | */ | 197 | */ |
210 | int in_destroy; | 198 | int in_destroy; |
211 | |||
212 | int inbound; | ||
213 | }; | 199 | }; |
214 | 200 | ||
215 | |||
216 | /** | 201 | /** |
217 | * Closure for #session_cmp_it(). | 202 | * Closure for #session_cmp_it(). |
218 | */ | 203 | */ |
219 | struct SessionCompareContext | 204 | struct SessionCompareContext |
220 | { | 205 | { |
221 | struct Session *res; | 206 | struct Session *res; |
222 | const struct GNUNET_HELLO_Address *addr; | 207 | const struct GNUNET_HELLO_Address *address; |
223 | int inbound; | ||
224 | }; | 208 | }; |
225 | 209 | ||
226 | |||
227 | /** | 210 | /** |
228 | * Closure for #process_inbound_tokenized_messages(). | 211 | * Closure for #process_inbound_tokenized_messages(). |
229 | */ | 212 | */ |
@@ -251,7 +234,6 @@ struct SourceInformation | |||
251 | 234 | ||
252 | }; | 235 | }; |
253 | 236 | ||
254 | |||
255 | /** | 237 | /** |
256 | * Closure for #find_receive_context(). | 238 | * Closure for #find_receive_context(). |
257 | */ | 239 | */ |
@@ -276,8 +258,6 @@ struct FindReceiveContext | |||
276 | 258 | ||
277 | }; | 259 | }; |
278 | 260 | ||
279 | |||
280 | |||
281 | /** | 261 | /** |
282 | * Data structure to track defragmentation contexts based | 262 | * Data structure to track defragmentation contexts based |
283 | * on the source of the UDP traffic. | 263 | * on the source of the UDP traffic. |
@@ -312,8 +292,6 @@ struct DefragContext | |||
312 | size_t addr_len; | 292 | size_t addr_len; |
313 | }; | 293 | }; |
314 | 294 | ||
315 | |||
316 | |||
317 | /** | 295 | /** |
318 | * Context to send fragmented messages | 296 | * Context to send fragmented messages |
319 | */ | 297 | */ |
@@ -373,7 +351,6 @@ struct UDP_FragmentationContext | |||
373 | 351 | ||
374 | }; | 352 | }; |
375 | 353 | ||
376 | |||
377 | struct UDP_MessageWrapper | 354 | struct UDP_MessageWrapper |
378 | { | 355 | { |
379 | /** | 356 | /** |
@@ -437,7 +414,6 @@ struct UDP_MessageWrapper | |||
437 | struct UDP_FragmentationContext *frag_ctx; | 414 | struct UDP_FragmentationContext *frag_ctx; |
438 | }; | 415 | }; |
439 | 416 | ||
440 | |||
441 | /** | 417 | /** |
442 | * UDP ACK Message-Packet header (after defragmentation). | 418 | * UDP ACK Message-Packet header (after defragmentation). |
443 | */ | 419 | */ |
@@ -465,13 +441,11 @@ struct UDP_ACK_Message | |||
465 | */ | 441 | */ |
466 | static uint32_t myoptions; | 442 | static uint32_t myoptions; |
467 | 443 | ||
468 | |||
469 | /** | 444 | /** |
470 | * Encapsulation of all of the state of the plugin. | 445 | * Encapsulation of all of the state of the plugin. |
471 | */ | 446 | */ |
472 | struct Plugin * plugin; | 447 | struct Plugin * plugin; |
473 | 448 | ||
474 | |||
475 | /** | 449 | /** |
476 | * We have been notified that our readset has something to read. We don't | 450 | * We have been notified that our readset has something to read. We don't |
477 | * know which socket needs to be read, so we have to check each one | 451 | * know which socket needs to be read, so we have to check each one |
@@ -483,7 +457,6 @@ struct Plugin * plugin; | |||
483 | static void | 457 | static void |
484 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 458 | udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
485 | 459 | ||
486 | |||
487 | /** | 460 | /** |
488 | * We have been notified that our readset has something to read. We don't | 461 | * We have been notified that our readset has something to read. We don't |
489 | * know which socket needs to be read, so we have to check each one | 462 | * know which socket needs to be read, so we have to check each one |
@@ -495,7 +468,6 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
495 | static void | 468 | static void |
496 | udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 469 | udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
497 | 470 | ||
498 | |||
499 | /** | 471 | /** |
500 | * (re)schedule select tasks for this plugin. | 472 | * (re)schedule select tasks for this plugin. |
501 | * | 473 | * |
@@ -514,40 +486,41 @@ schedule_select (struct Plugin *plugin) | |||
514 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; | 486 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; |
515 | for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) | 487 | for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) |
516 | min_delay = GNUNET_TIME_relative_min (min_delay, | 488 | min_delay = GNUNET_TIME_relative_min (min_delay, |
517 | GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer)); | 489 | GNUNET_TIME_absolute_get_remaining ( |
490 | udpw->session->flow_delay_from_other_peer)); | ||
518 | 491 | ||
519 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) | 492 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) |
520 | GNUNET_SCHEDULER_cancel(plugin->select_task); | 493 | GNUNET_SCHEDULER_cancel (plugin->select_task); |
521 | 494 | ||
522 | /* Schedule with: | 495 | /* Schedule with: |
523 | * - write active set if message is ready | 496 | * - write active set if message is ready |
524 | * - timeout minimum delay */ | 497 | * - timeout minimum delay */ |
525 | plugin->select_task = | 498 | plugin->select_task = GNUNET_SCHEDULER_add_select ( |
526 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 499 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
527 | (0 == min_delay.rel_value_us) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay, | 500 | (0 == min_delay.rel_value_us) ? |
528 | plugin->rs_v4, | 501 | GNUNET_TIME_UNIT_FOREVER_REL : min_delay, plugin->rs_v4, |
529 | (0 == min_delay.rel_value_us) ? plugin->ws_v4 : NULL, | 502 | (0 == min_delay.rel_value_us) ? plugin->ws_v4 : NULL, |
530 | &udp_plugin_select, plugin); | 503 | &udp_plugin_select, plugin); |
531 | } | 504 | } |
532 | if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) | 505 | if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) |
533 | { | 506 | { |
534 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; | 507 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; |
535 | for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) | 508 | for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) |
536 | min_delay = GNUNET_TIME_relative_min (min_delay, | 509 | min_delay = GNUNET_TIME_relative_min (min_delay, |
537 | GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer)); | 510 | GNUNET_TIME_absolute_get_remaining ( |
511 | udpw->session->flow_delay_from_other_peer)); | ||
538 | 512 | ||
539 | if (GNUNET_SCHEDULER_NO_TASK != plugin->select_task_v6) | 513 | if (GNUNET_SCHEDULER_NO_TASK != plugin->select_task_v6) |
540 | GNUNET_SCHEDULER_cancel(plugin->select_task_v6); | 514 | GNUNET_SCHEDULER_cancel (plugin->select_task_v6); |
541 | plugin->select_task_v6 = | 515 | plugin->select_task_v6 = GNUNET_SCHEDULER_add_select ( |
542 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 516 | GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
543 | (0 == min_delay.rel_value_us) ? GNUNET_TIME_UNIT_FOREVER_REL : min_delay, | 517 | (0 == min_delay.rel_value_us) ? |
544 | plugin->rs_v6, | 518 | GNUNET_TIME_UNIT_FOREVER_REL : min_delay, plugin->rs_v6, |
545 | (0 == min_delay.rel_value_us) ? plugin->ws_v6 : NULL, | 519 | (0 == min_delay.rel_value_us) ? plugin->ws_v6 : NULL, |
546 | &udp_plugin_select_v6, plugin); | 520 | &udp_plugin_select_v6, plugin); |
547 | } | 521 | } |
548 | } | 522 | } |
549 | 523 | ||
550 | |||
551 | /** | 524 | /** |
552 | * Function called for a quick conversion of the binary address to | 525 | * Function called for a quick conversion of the binary address to |
553 | * a numeric address. Note that the caller must not free the | 526 | * a numeric address. Note that the caller must not free the |
@@ -573,37 +546,36 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
573 | uint16_t port; | 546 | uint16_t port; |
574 | uint32_t options; | 547 | uint32_t options; |
575 | 548 | ||
576 | if ((NULL != addr) && (addrlen == sizeof (struct IPv6UdpAddress))) | 549 | if ((NULL != addr) && (addrlen == sizeof(struct IPv6UdpAddress))) |
577 | { | 550 | { |
578 | t6 = addr; | 551 | t6 = addr; |
579 | af = AF_INET6; | 552 | af = AF_INET6; |
580 | options = ntohl (t6->options); | 553 | options = ntohl (t6->options); |
581 | port = ntohs (t6->u6_port); | 554 | port = ntohs (t6->u6_port); |
582 | memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); | 555 | memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); |
583 | sb = &a6; | 556 | sb = &a6; |
584 | } | 557 | } |
585 | else if ((NULL != addr) && (addrlen == sizeof (struct IPv4UdpAddress))) | 558 | else if ((NULL != addr) && (addrlen == sizeof(struct IPv4UdpAddress))) |
586 | { | 559 | { |
587 | t4 = addr; | 560 | t4 = addr; |
588 | af = AF_INET; | 561 | af = AF_INET; |
589 | options = ntohl (t4->options); | 562 | options = ntohl (t4->options); |
590 | port = ntohs (t4->u4_port); | 563 | port = ntohs (t4->u4_port); |
591 | memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); | 564 | memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); |
592 | sb = &a4; | 565 | sb = &a4; |
593 | } | 566 | } |
594 | else | 567 | else |
595 | { | 568 | { |
596 | return NULL; | 569 | return NULL ; |
597 | } | 570 | } |
598 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); | 571 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
599 | 572 | ||
600 | GNUNET_snprintf (rbuf, sizeof (rbuf), | 573 | GNUNET_snprintf (rbuf, sizeof(rbuf), |
601 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", | 574 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", PLUGIN_NAME, options, |
602 | PLUGIN_NAME, options, buf, port); | 575 | buf, port); |
603 | return rbuf; | 576 | return rbuf; |
604 | } | 577 | } |
605 | 578 | ||
606 | |||
607 | /** | 579 | /** |
608 | * Function called to convert a string address to | 580 | * Function called to convert a string address to |
609 | * a binary address. | 581 | * a binary address. |
@@ -633,87 +605,85 @@ udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
633 | 605 | ||
634 | if ((NULL == addr) || (addrlen == 0)) | 606 | if ((NULL == addr) || (addrlen == 0)) |
635 | { | 607 | { |
636 | GNUNET_break (0); | 608 | GNUNET_break(0); |
637 | return GNUNET_SYSERR; | 609 | return GNUNET_SYSERR; |
638 | } | 610 | } |
639 | if ('\0' != addr[addrlen - 1]) | 611 | if ('\0' != addr[addrlen - 1]) |
640 | { | 612 | { |
641 | GNUNET_break (0); | 613 | GNUNET_break(0); |
642 | return GNUNET_SYSERR; | 614 | return GNUNET_SYSERR; |
643 | } | 615 | } |
644 | if (strlen (addr) != addrlen - 1) | 616 | if (strlen (addr) != addrlen - 1) |
645 | { | 617 | { |
646 | GNUNET_break (0); | 618 | GNUNET_break(0); |
647 | return GNUNET_SYSERR; | 619 | return GNUNET_SYSERR; |
648 | } | 620 | } |
649 | plugin = GNUNET_strdup (addr); | 621 | plugin = GNUNET_strdup (addr); |
650 | optionstr = strchr (plugin, '.'); | 622 | optionstr = strchr (plugin, '.'); |
651 | if (NULL == optionstr) | 623 | if (NULL == optionstr) |
652 | { | 624 | { |
653 | GNUNET_break (0); | 625 | GNUNET_break(0); |
654 | GNUNET_free (plugin); | 626 | GNUNET_free(plugin); |
655 | return GNUNET_SYSERR; | 627 | return GNUNET_SYSERR; |
656 | } | 628 | } |
657 | optionstr[0] = '\0'; | 629 | optionstr[0] = '\0'; |
658 | optionstr ++; | 630 | optionstr++; |
659 | options = atol (optionstr); | 631 | options = atol (optionstr); |
660 | address = strchr (optionstr, '.'); | 632 | address = strchr (optionstr, '.'); |
661 | if (NULL == address) | 633 | if (NULL == address) |
662 | { | 634 | { |
663 | GNUNET_break (0); | 635 | GNUNET_break(0); |
664 | GNUNET_free (plugin); | 636 | GNUNET_free(plugin); |
665 | return GNUNET_SYSERR; | 637 | return GNUNET_SYSERR; |
666 | } | 638 | } |
667 | address[0] = '\0'; | 639 | address[0] = '\0'; |
668 | address ++; | 640 | address++; |
669 | 641 | ||
670 | if (GNUNET_OK != | 642 | if (GNUNET_OK |
671 | GNUNET_STRINGS_to_address_ip (address, strlen (address), | 643 | != GNUNET_STRINGS_to_address_ip (address, strlen (address), |
672 | &socket_address)) | 644 | &socket_address)) |
673 | { | 645 | { |
674 | GNUNET_break (0); | 646 | GNUNET_break(0); |
675 | GNUNET_free (plugin); | 647 | GNUNET_free(plugin); |
676 | return GNUNET_SYSERR; | 648 | return GNUNET_SYSERR; |
677 | } | 649 | } |
678 | 650 | ||
679 | GNUNET_free (plugin); | 651 | GNUNET_free(plugin); |
680 | 652 | ||
681 | switch (socket_address.ss_family) | 653 | switch (socket_address.ss_family) |
682 | { | 654 | { |
683 | case AF_INET: | 655 | case AF_INET: |
684 | { | 656 | { |
685 | struct IPv4UdpAddress *u4; | 657 | struct IPv4UdpAddress *u4; |
686 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; | 658 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; |
687 | u4 = GNUNET_new (struct IPv4UdpAddress); | 659 | u4 = GNUNET_new (struct IPv4UdpAddress); |
688 | u4->options = htonl (options); | 660 | u4->options = htonl (options); |
689 | u4->ipv4_addr = in4->sin_addr.s_addr; | 661 | u4->ipv4_addr = in4->sin_addr.s_addr; |
690 | u4->u4_port = in4->sin_port; | 662 | u4->u4_port = in4->sin_port; |
691 | *buf = u4; | 663 | *buf = u4; |
692 | *added = sizeof (struct IPv4UdpAddress); | 664 | *added = sizeof(struct IPv4UdpAddress); |
693 | return GNUNET_OK; | 665 | return GNUNET_OK; |
694 | } | 666 | } |
695 | case AF_INET6: | 667 | case AF_INET6: |
696 | { | 668 | { |
697 | struct IPv6UdpAddress *u6; | 669 | struct IPv6UdpAddress *u6; |
698 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; | 670 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; |
699 | u6 = GNUNET_new (struct IPv6UdpAddress); | 671 | u6 = GNUNET_new (struct IPv6UdpAddress); |
700 | u6->options = htonl (options); | 672 | u6->options = htonl (options); |
701 | u6->ipv6_addr = in6->sin6_addr; | 673 | u6->ipv6_addr = in6->sin6_addr; |
702 | u6->u6_port = in6->sin6_port; | 674 | u6->u6_port = in6->sin6_port; |
703 | *buf = u6; | 675 | *buf = u6; |
704 | *added = sizeof (struct IPv6UdpAddress); | 676 | *added = sizeof(struct IPv6UdpAddress); |
705 | return GNUNET_OK; | 677 | return GNUNET_OK; |
706 | } | 678 | } |
707 | default: | 679 | default: |
708 | GNUNET_break (0); | 680 | GNUNET_break(0); |
709 | return GNUNET_SYSERR; | 681 | return GNUNET_SYSERR; |
710 | } | 682 | } |
711 | } | 683 | } |
712 | 684 | ||
713 | |||
714 | static void | 685 | static void |
715 | ppc_cancel_task (void *cls, | 686 | ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
716 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
717 | { | 687 | { |
718 | struct PrettyPrinterContext *ppc = cls; | 688 | struct PrettyPrinterContext *ppc = cls; |
719 | 689 | ||
@@ -723,11 +693,10 @@ ppc_cancel_task (void *cls, | |||
723 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); | 693 | GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); |
724 | ppc->resolver_handle = NULL; | 694 | ppc->resolver_handle = NULL; |
725 | } | 695 | } |
726 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 696 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); |
727 | GNUNET_free (ppc); | 697 | GNUNET_free(ppc); |
728 | } | 698 | } |
729 | 699 | ||
730 | |||
731 | /** | 700 | /** |
732 | * Append our port and forward the result. | 701 | * Append our port and forward the result. |
733 | * | 702 | * |
@@ -741,14 +710,14 @@ append_port (void *cls, const char *hostname) | |||
741 | struct PrettyPrinterContext *cur; | 710 | struct PrettyPrinterContext *cur; |
742 | char *ret; | 711 | char *ret; |
743 | 712 | ||
744 | if (hostname == NULL) | 713 | if (hostname == NULL ) |
745 | { | 714 | { |
746 | ppc->asc (ppc->asc_cls, NULL); | 715 | ppc->asc (ppc->asc_cls, NULL ); |
747 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 716 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, ppc); |
748 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); | 717 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); |
749 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 718 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
750 | ppc->resolver_handle = NULL; | 719 | ppc->resolver_handle = NULL; |
751 | GNUNET_free (ppc); | 720 | GNUNET_free(ppc); |
752 | return; | 721 | return; |
753 | } | 722 | } |
754 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | 723 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) |
@@ -758,30 +727,20 @@ append_port (void *cls, const char *hostname) | |||
758 | } | 727 | } |
759 | if (NULL == cur) | 728 | if (NULL == cur) |
760 | { | 729 | { |
761 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 730 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc); |
762 | "Invalid callback for PPC %p \n", ppc); | ||
763 | return; | 731 | return; |
764 | } | 732 | } |
765 | 733 | ||
766 | if (GNUNET_YES == ppc->ipv6) | 734 | if (GNUNET_YES == ppc->ipv6) |
767 | GNUNET_asprintf (&ret, | 735 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, |
768 | "%s.%u.[%s]:%d", | 736 | ppc->port); |
769 | PLUGIN_NAME, | ||
770 | ppc->options, | ||
771 | hostname, | ||
772 | ppc->port); | ||
773 | else | 737 | else |
774 | GNUNET_asprintf (&ret, | 738 | GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, |
775 | "%s.%u.%s:%d", | 739 | ppc->port); |
776 | PLUGIN_NAME, | ||
777 | ppc->options, | ||
778 | hostname, | ||
779 | ppc->port); | ||
780 | ppc->asc (ppc->asc_cls, ret); | 740 | ppc->asc (ppc->asc_cls, ret); |
781 | GNUNET_free (ret); | 741 | GNUNET_free(ret); |
782 | } | 742 | } |
783 | 743 | ||
784 | |||
785 | /** | 744 | /** |
786 | * Convert the transports address to a nice, human-readable | 745 | * Convert the transports address to a nice, human-readable |
787 | * format. | 746 | * format. |
@@ -798,11 +757,9 @@ append_port (void *cls, const char *hostname) | |||
798 | */ | 757 | */ |
799 | static void | 758 | static void |
800 | udp_plugin_address_pretty_printer (void *cls, const char *type, | 759 | udp_plugin_address_pretty_printer (void *cls, const char *type, |
801 | const void *addr, size_t addrlen, | 760 | const void *addr, size_t addrlen, int numeric, |
802 | int numeric, | 761 | struct GNUNET_TIME_Relative timeout, |
803 | struct GNUNET_TIME_Relative timeout, | 762 | GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) |
804 | GNUNET_TRANSPORT_AddressStringCallback asc, | ||
805 | void *asc_cls) | ||
806 | { | 763 | { |
807 | struct PrettyPrinterContext *ppc; | 764 | struct PrettyPrinterContext *ppc; |
808 | const void *sb; | 765 | const void *sb; |
@@ -814,25 +771,25 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
814 | uint16_t port; | 771 | uint16_t port; |
815 | uint32_t options; | 772 | uint32_t options; |
816 | 773 | ||
817 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 774 | if (addrlen == sizeof(struct IPv6UdpAddress)) |
818 | { | 775 | { |
819 | u6 = addr; | 776 | u6 = addr; |
820 | memset (&a6, 0, sizeof (a6)); | 777 | memset (&a6, 0, sizeof(a6)); |
821 | a6.sin6_family = AF_INET6; | 778 | a6.sin6_family = AF_INET6; |
822 | #if HAVE_SOCKADDR_IN_SIN_LEN | 779 | #if HAVE_SOCKADDR_IN_SIN_LEN |
823 | a6.sin6_len = sizeof (a6); | 780 | a6.sin6_len = sizeof (a6); |
824 | #endif | 781 | #endif |
825 | a6.sin6_port = u6->u6_port; | 782 | a6.sin6_port = u6->u6_port; |
826 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); | 783 | memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); |
827 | port = ntohs (u6->u6_port); | 784 | port = ntohs (u6->u6_port); |
828 | options = ntohl (u6->options); | 785 | options = ntohl (u6->options); |
829 | sb = &a6; | 786 | sb = &a6; |
830 | sbs = sizeof (a6); | 787 | sbs = sizeof(a6); |
831 | } | 788 | } |
832 | else if (addrlen == sizeof (struct IPv4UdpAddress)) | 789 | else if (addrlen == sizeof(struct IPv4UdpAddress)) |
833 | { | 790 | { |
834 | u4 = addr; | 791 | u4 = addr; |
835 | memset (&a4, 0, sizeof (a4)); | 792 | memset (&a4, 0, sizeof(a4)); |
836 | a4.sin_family = AF_INET; | 793 | a4.sin_family = AF_INET; |
837 | #if HAVE_SOCKADDR_IN_SIN_LEN | 794 | #if HAVE_SOCKADDR_IN_SIN_LEN |
838 | a4.sin_len = sizeof (a4); | 795 | a4.sin_len = sizeof (a4); |
@@ -842,13 +799,13 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
842 | port = ntohs (u4->u4_port); | 799 | port = ntohs (u4->u4_port); |
843 | options = ntohl (u4->options); | 800 | options = ntohl (u4->options); |
844 | sb = &a4; | 801 | sb = &a4; |
845 | sbs = sizeof (a4); | 802 | sbs = sizeof(a4); |
846 | } | 803 | } |
847 | else | 804 | else |
848 | { | 805 | { |
849 | /* invalid address */ | 806 | /* invalid address */ |
850 | GNUNET_break_op (0); | 807 | GNUNET_break_op(0); |
851 | asc (asc_cls, NULL); | 808 | asc (asc_cls, NULL ); |
852 | return; | 809 | return; |
853 | } | 810 | } |
854 | ppc = GNUNET_new (struct PrettyPrinterContext); | 811 | ppc = GNUNET_new (struct PrettyPrinterContext); |
@@ -856,26 +813,23 @@ udp_plugin_address_pretty_printer (void *cls, const char *type, | |||
856 | ppc->asc_cls = asc_cls; | 813 | ppc->asc_cls = asc_cls; |
857 | ppc->port = port; | 814 | ppc->port = port; |
858 | ppc->options = options; | 815 | ppc->options = options; |
859 | if (addrlen == sizeof (struct IPv6UdpAddress)) | 816 | if (addrlen == sizeof(struct IPv6UdpAddress)) |
860 | ppc->ipv6 = GNUNET_YES; | 817 | ppc->ipv6 = GNUNET_YES; |
861 | else | 818 | else |
862 | ppc->ipv6 = GNUNET_NO; | 819 | ppc->ipv6 = GNUNET_NO; |
863 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(timeout, 2), | 820 | ppc->timeout_task = GNUNET_SCHEDULER_add_delayed ( |
864 | &ppc_cancel_task, ppc); | 821 | GNUNET_TIME_relative_multiply (timeout, 2), &ppc_cancel_task, ppc); |
865 | GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc); | 822 | GNUNET_CONTAINER_DLL_insert(ppc_dll_head, ppc_dll_tail, ppc); |
866 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, | 823 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, |
867 | !numeric, | 824 | timeout, &append_port, ppc); |
868 | timeout, | ||
869 | &append_port, ppc); | ||
870 | } | 825 | } |
871 | 826 | ||
872 | |||
873 | static void | 827 | static void |
874 | call_continuation (struct UDP_MessageWrapper *udpw, int result) | 828 | call_continuation (struct UDP_MessageWrapper *udpw, int result) |
875 | { | 829 | { |
876 | size_t overhead; | 830 | size_t overhead; |
877 | 831 | ||
878 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 832 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
879 | "Calling continuation for %u byte message to `%s' with result %s\n", | 833 | "Calling continuation for %u byte message to `%s' with result %s\n", |
880 | udpw->payload_size, GNUNET_i2s (&udpw->session->target), | 834 | udpw->payload_size, GNUNET_i2s (&udpw->session->target), |
881 | (GNUNET_OK == result) ? "OK" : "SYSERR"); | 835 | (GNUNET_OK == result) ? "OK" : "SYSERR"); |
@@ -885,160 +839,148 @@ call_continuation (struct UDP_MessageWrapper *udpw, int result) | |||
885 | else | 839 | else |
886 | overhead = udpw->msg_size; | 840 | overhead = udpw->msg_size; |
887 | 841 | ||
888 | switch (result) { | 842 | switch (result) |
889 | case GNUNET_OK: | 843 | { |
890 | switch (udpw->msg_type) { | 844 | case GNUNET_OK: |
891 | case MSG_UNFRAGMENTED: | 845 | switch (udpw->msg_type) |
892 | if (NULL != udpw->cont) | 846 | { |
893 | { | 847 | case MSG_UNFRAGMENTED: |
894 | /* Transport continuation */ | 848 | if (NULL != udpw->cont) |
895 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | 849 | { |
896 | udpw->payload_size, udpw->msg_size); | 850 | /* Transport continuation */ |
897 | } | 851 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, |
898 | GNUNET_STATISTICS_update (plugin->env->stats, | 852 | udpw->payload_size, udpw->msg_size); |
899 | "# UDP, unfragmented msgs, messages, sent, success", | ||
900 | 1, GNUNET_NO); | ||
901 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
902 | "# UDP, unfragmented msgs, bytes payload, sent, success", | ||
903 | udpw->payload_size, GNUNET_NO); | ||
904 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
905 | "# UDP, unfragmented msgs, bytes overhead, sent, success", | ||
906 | overhead, GNUNET_NO); | ||
907 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
908 | "# UDP, total, bytes overhead, sent", | ||
909 | overhead, GNUNET_NO); | ||
910 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
911 | "# UDP, total, bytes payload, sent", | ||
912 | udpw->payload_size, GNUNET_NO); | ||
913 | break; | ||
914 | case MSG_FRAGMENTED_COMPLETE: | ||
915 | GNUNET_assert (NULL != udpw->frag_ctx); | ||
916 | if (udpw->frag_ctx->cont != NULL) | ||
917 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, GNUNET_OK, | ||
918 | udpw->frag_ctx->payload_size, udpw->frag_ctx->on_wire_size); | ||
919 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
920 | "# UDP, fragmented msgs, messages, sent, success", | ||
921 | 1, GNUNET_NO); | ||
922 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
923 | "# UDP, fragmented msgs, bytes payload, sent, success", | ||
924 | udpw->payload_size, GNUNET_NO); | ||
925 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
926 | "# UDP, fragmented msgs, bytes overhead, sent, success", | ||
927 | overhead, GNUNET_NO); | ||
928 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
929 | "# UDP, total, bytes overhead, sent", | ||
930 | overhead, GNUNET_NO); | ||
931 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
932 | "# UDP, total, bytes payload, sent", | ||
933 | udpw->payload_size, GNUNET_NO); | ||
934 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
935 | "# UDP, fragmented msgs, messages, pending", | ||
936 | -1, GNUNET_NO); | ||
937 | break; | ||
938 | case MSG_FRAGMENTED: | ||
939 | /* Fragmented message: enqueue next fragment */ | ||
940 | if (NULL != udpw->cont) | ||
941 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | ||
942 | udpw->payload_size, udpw->msg_size); | ||
943 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
944 | "# UDP, fragmented msgs, fragments, sent, success", | ||
945 | 1, GNUNET_NO); | ||
946 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
947 | "# UDP, fragmented msgs, fragments bytes, sent, success", | ||
948 | udpw->msg_size, GNUNET_NO); | ||
949 | break; | ||
950 | case MSG_ACK: | ||
951 | /* No continuation */ | ||
952 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
953 | "# UDP, ACK msgs, messages, sent, success", | ||
954 | 1, GNUNET_NO); | ||
955 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
956 | "# UDP, ACK msgs, bytes overhead, sent, success", | ||
957 | overhead, GNUNET_NO); | ||
958 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
959 | "# UDP, total, bytes overhead, sent", | ||
960 | overhead, GNUNET_NO); | ||
961 | break; | ||
962 | case MSG_BEACON: | ||
963 | GNUNET_break (0); | ||
964 | break; | ||
965 | default: | ||
966 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
967 | "ERROR: %u\n", udpw->msg_type); | ||
968 | GNUNET_break (0); | ||
969 | break; | ||
970 | } | 853 | } |
854 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
855 | "# UDP, unfragmented msgs, messages, sent, success", 1, GNUNET_NO); | ||
856 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
857 | "# UDP, unfragmented msgs, bytes payload, sent, success", | ||
858 | udpw->payload_size, GNUNET_NO); | ||
859 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
860 | "# UDP, unfragmented msgs, bytes overhead, sent, success", overhead, | ||
861 | GNUNET_NO); | ||
862 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
863 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); | ||
864 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
865 | "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); | ||
971 | break; | 866 | break; |
972 | case GNUNET_SYSERR: | 867 | case MSG_FRAGMENTED_COMPLETE: |
973 | switch (udpw->msg_type) { | 868 | GNUNET_assert(NULL != udpw->frag_ctx); |
974 | case MSG_UNFRAGMENTED: | 869 | if (udpw->frag_ctx->cont != NULL ) |
975 | /* Unfragmented message: failed to send */ | 870 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, |
976 | if (NULL != udpw->cont) | 871 | GNUNET_OK, udpw->frag_ctx->payload_size, |
977 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | 872 | udpw->frag_ctx->on_wire_size); |
978 | udpw->payload_size, overhead); | 873 | GNUNET_STATISTICS_update (plugin->env->stats, |
979 | GNUNET_STATISTICS_update (plugin->env->stats, | 874 | "# UDP, fragmented msgs, messages, sent, success", 1, GNUNET_NO); |
980 | "# UDP, unfragmented msgs, messages, sent, failure", | 875 | GNUNET_STATISTICS_update (plugin->env->stats, |
981 | 1, GNUNET_NO); | 876 | "# UDP, fragmented msgs, bytes payload, sent, success", |
982 | GNUNET_STATISTICS_update (plugin->env->stats, | 877 | udpw->payload_size, GNUNET_NO); |
983 | "# UDP, unfragmented msgs, bytes payload, sent, failure", | 878 | GNUNET_STATISTICS_update (plugin->env->stats, |
984 | udpw->payload_size, GNUNET_NO); | 879 | "# UDP, fragmented msgs, bytes overhead, sent, success", overhead, |
985 | GNUNET_STATISTICS_update (plugin->env->stats, | 880 | GNUNET_NO); |
986 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", | 881 | GNUNET_STATISTICS_update (plugin->env->stats, |
987 | overhead, GNUNET_NO); | 882 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); |
988 | break; | 883 | GNUNET_STATISTICS_update (plugin->env->stats, |
989 | case MSG_FRAGMENTED_COMPLETE: | 884 | "# UDP, total, bytes payload, sent", udpw->payload_size, GNUNET_NO); |
990 | GNUNET_assert (NULL != udpw->frag_ctx); | 885 | GNUNET_STATISTICS_update (plugin->env->stats, |
991 | if (udpw->frag_ctx->cont != NULL) | 886 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); |
992 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, GNUNET_SYSERR, | 887 | break; |
993 | udpw->frag_ctx->payload_size, udpw->frag_ctx->on_wire_size); | 888 | case MSG_FRAGMENTED: |
994 | GNUNET_STATISTICS_update (plugin->env->stats, | 889 | /* Fragmented message: enqueue next fragment */ |
995 | "# UDP, fragmented msgs, messages, sent, failure", | 890 | if (NULL != udpw->cont) |
996 | 1, GNUNET_NO); | 891 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, |
997 | GNUNET_STATISTICS_update (plugin->env->stats, | 892 | udpw->payload_size, udpw->msg_size); |
998 | "# UDP, fragmented msgs, bytes payload, sent, failure", | 893 | GNUNET_STATISTICS_update (plugin->env->stats, |
999 | udpw->payload_size, GNUNET_NO); | 894 | "# UDP, fragmented msgs, fragments, sent, success", 1, GNUNET_NO); |
1000 | GNUNET_STATISTICS_update (plugin->env->stats, | 895 | GNUNET_STATISTICS_update (plugin->env->stats, |
1001 | "# UDP, fragmented msgs, bytes payload, sent, failure", | 896 | "# UDP, fragmented msgs, fragments bytes, sent, success", |
1002 | overhead, GNUNET_NO); | 897 | udpw->msg_size, GNUNET_NO); |
1003 | GNUNET_STATISTICS_update (plugin->env->stats, | 898 | break; |
1004 | "# UDP, fragmented msgs, bytes payload, sent, failure", | 899 | case MSG_ACK: |
1005 | overhead, GNUNET_NO); | 900 | /* No continuation */ |
1006 | GNUNET_STATISTICS_update (plugin->env->stats, | 901 | GNUNET_STATISTICS_update (plugin->env->stats, |
1007 | "# UDP, fragmented msgs, messages, pending", | 902 | "# UDP, ACK msgs, messages, sent, success", 1, GNUNET_NO); |
1008 | -1, GNUNET_NO); | 903 | GNUNET_STATISTICS_update (plugin->env->stats, |
1009 | break; | 904 | "# UDP, ACK msgs, bytes overhead, sent, success", overhead, |
1010 | case MSG_FRAGMENTED: | 905 | GNUNET_NO); |
1011 | GNUNET_assert (NULL != udpw->frag_ctx); | 906 | GNUNET_STATISTICS_update (plugin->env->stats, |
1012 | /* Fragmented message: failed to send */ | 907 | "# UDP, total, bytes overhead, sent", overhead, GNUNET_NO); |
1013 | GNUNET_STATISTICS_update (plugin->env->stats, | 908 | break; |
1014 | "# UDP, fragmented msgs, fragments, sent, failure", | 909 | case MSG_BEACON: |
1015 | 1, GNUNET_NO); | 910 | GNUNET_break(0); |
1016 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
1017 | "# UDP, fragmented msgs, fragments bytes, sent, failure", | ||
1018 | udpw->msg_size, GNUNET_NO); | ||
1019 | break; | ||
1020 | case MSG_ACK: | ||
1021 | /* ACK message: failed to send */ | ||
1022 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
1023 | "# UDP, ACK msgs, messages, sent, failure", | ||
1024 | 1, GNUNET_NO); | ||
1025 | break; | ||
1026 | case MSG_BEACON: | ||
1027 | /* Beacon message: failed to send */ | ||
1028 | GNUNET_break (0); | ||
1029 | break; | ||
1030 | default: | ||
1031 | GNUNET_break (0); | ||
1032 | break; | ||
1033 | } | ||
1034 | break; | 911 | break; |
1035 | default: | 912 | default: |
1036 | GNUNET_break (0); | 913 | LOG(GNUNET_ERROR_TYPE_ERROR, "ERROR: %u\n", udpw->msg_type); |
914 | GNUNET_break(0); | ||
1037 | break; | 915 | break; |
916 | } | ||
917 | break; | ||
918 | case GNUNET_SYSERR: | ||
919 | switch (udpw->msg_type) | ||
920 | { | ||
921 | case MSG_UNFRAGMENTED: | ||
922 | /* Unfragmented message: failed to send */ | ||
923 | if (NULL != udpw->cont) | ||
924 | udpw->cont (udpw->cont_cls, &udpw->session->target, result, | ||
925 | udpw->payload_size, overhead); | ||
926 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
927 | "# UDP, unfragmented msgs, messages, sent, failure", 1, GNUNET_NO); | ||
928 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
929 | "# UDP, unfragmented msgs, bytes payload, sent, failure", | ||
930 | udpw->payload_size, GNUNET_NO); | ||
931 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
932 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", overhead, | ||
933 | GNUNET_NO); | ||
934 | break; | ||
935 | case MSG_FRAGMENTED_COMPLETE: | ||
936 | GNUNET_assert(NULL != udpw->frag_ctx); | ||
937 | if (udpw->frag_ctx->cont != NULL ) | ||
938 | udpw->frag_ctx->cont (udpw->frag_ctx->cont_cls, &udpw->session->target, | ||
939 | GNUNET_SYSERR, udpw->frag_ctx->payload_size, | ||
940 | udpw->frag_ctx->on_wire_size); | ||
941 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
942 | "# UDP, fragmented msgs, messages, sent, failure", 1, GNUNET_NO); | ||
943 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
944 | "# UDP, fragmented msgs, bytes payload, sent, failure", | ||
945 | udpw->payload_size, GNUNET_NO); | ||
946 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
947 | "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, | ||
948 | GNUNET_NO); | ||
949 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
950 | "# UDP, fragmented msgs, bytes payload, sent, failure", overhead, | ||
951 | GNUNET_NO); | ||
952 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
953 | "# UDP, fragmented msgs, messages, pending", -1, GNUNET_NO); | ||
954 | break; | ||
955 | case MSG_FRAGMENTED: | ||
956 | GNUNET_assert(NULL != udpw->frag_ctx); | ||
957 | /* Fragmented message: failed to send */ | ||
958 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
959 | "# UDP, fragmented msgs, fragments, sent, failure", 1, GNUNET_NO); | ||
960 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
961 | "# UDP, fragmented msgs, fragments bytes, sent, failure", | ||
962 | udpw->msg_size, GNUNET_NO); | ||
963 | break; | ||
964 | case MSG_ACK: | ||
965 | /* ACK message: failed to send */ | ||
966 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
967 | "# UDP, ACK msgs, messages, sent, failure", 1, GNUNET_NO); | ||
968 | break; | ||
969 | case MSG_BEACON: | ||
970 | /* Beacon message: failed to send */ | ||
971 | GNUNET_break(0); | ||
972 | break; | ||
973 | default: | ||
974 | GNUNET_break(0); | ||
975 | break; | ||
976 | } | ||
977 | break; | ||
978 | default: | ||
979 | GNUNET_break(0); | ||
980 | break; | ||
1038 | } | 981 | } |
1039 | } | 982 | } |
1040 | 983 | ||
1041 | |||
1042 | /** | 984 | /** |
1043 | * Check if the given port is plausible (must be either our listen | 985 | * Check if the given port is plausible (must be either our listen |
1044 | * port or our advertised port). If it is neither, we return | 986 | * port or our advertised port). If it is neither, we return |
@@ -1056,7 +998,6 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1056 | return GNUNET_SYSERR; | 998 | return GNUNET_SYSERR; |
1057 | } | 999 | } |
1058 | 1000 | ||
1059 | |||
1060 | /** | 1001 | /** |
1061 | * Function that will be called to check if a binary address for this | 1002 | * Function that will be called to check if a binary address for this |
1062 | * plugin is well-formed and corresponds to an address for THIS peer | 1003 | * plugin is well-formed and corresponds to an address for THIS peer |
@@ -1074,28 +1015,26 @@ check_port (struct Plugin *plugin, uint16_t in_port) | |||
1074 | * | 1015 | * |
1075 | */ | 1016 | */ |
1076 | static int | 1017 | static int |
1077 | udp_plugin_check_address (void *cls, | 1018 | udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
1078 | const void *addr, | ||
1079 | size_t addrlen) | ||
1080 | { | 1019 | { |
1081 | struct Plugin *plugin = cls; | 1020 | struct Plugin *plugin = cls; |
1082 | struct IPv4UdpAddress *v4; | 1021 | struct IPv4UdpAddress *v4; |
1083 | struct IPv6UdpAddress *v6; | 1022 | struct IPv6UdpAddress *v6; |
1084 | 1023 | ||
1085 | if ((addrlen != sizeof (struct IPv4UdpAddress)) && | 1024 | if ((addrlen != sizeof(struct IPv4UdpAddress)) |
1086 | (addrlen != sizeof (struct IPv6UdpAddress))) | 1025 | && (addrlen != sizeof(struct IPv6UdpAddress))) |
1087 | { | 1026 | { |
1088 | GNUNET_break_op (0); | 1027 | GNUNET_break_op(0); |
1089 | return GNUNET_SYSERR; | 1028 | return GNUNET_SYSERR; |
1090 | } | 1029 | } |
1091 | if (addrlen == sizeof (struct IPv4UdpAddress)) | 1030 | if (addrlen == sizeof(struct IPv4UdpAddress)) |
1092 | { | 1031 | { |
1093 | v4 = (struct IPv4UdpAddress *) addr; | 1032 | v4 = (struct IPv4UdpAddress *) addr; |
1094 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) | 1033 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) |
1095 | return GNUNET_SYSERR; | 1034 | return GNUNET_SYSERR; |
1096 | if (GNUNET_OK != | 1035 | if (GNUNET_OK |
1097 | GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, | 1036 | != GNUNET_NAT_test_address (plugin->nat, &v4->ipv4_addr, |
1098 | sizeof (struct in_addr))) | 1037 | sizeof(struct in_addr))) |
1099 | return GNUNET_SYSERR; | 1038 | return GNUNET_SYSERR; |
1100 | } | 1039 | } |
1101 | else | 1040 | else |
@@ -1103,20 +1042,19 @@ udp_plugin_check_address (void *cls, | |||
1103 | v6 = (struct IPv6UdpAddress *) addr; | 1042 | v6 = (struct IPv6UdpAddress *) addr; |
1104 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | 1043 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
1105 | { | 1044 | { |
1106 | GNUNET_break_op (0); | 1045 | GNUNET_break_op(0); |
1107 | return GNUNET_SYSERR; | 1046 | return GNUNET_SYSERR; |
1108 | } | 1047 | } |
1109 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) | 1048 | if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port))) |
1110 | return GNUNET_SYSERR; | 1049 | return GNUNET_SYSERR; |
1111 | if (GNUNET_OK != | 1050 | if (GNUNET_OK |
1112 | GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, | 1051 | != GNUNET_NAT_test_address (plugin->nat, &v6->ipv6_addr, |
1113 | sizeof (struct in6_addr))) | 1052 | sizeof(struct in6_addr))) |
1114 | return GNUNET_SYSERR; | 1053 | return GNUNET_SYSERR; |
1115 | } | 1054 | } |
1116 | return GNUNET_OK; | 1055 | return GNUNET_OK; |
1117 | } | 1056 | } |
1118 | 1057 | ||
1119 | |||
1120 | /** | 1058 | /** |
1121 | * Function to free last resources associated with a session. | 1059 | * Function to free last resources associated with a session. |
1122 | * | 1060 | * |
@@ -1127,39 +1065,35 @@ free_session (struct Session *s) | |||
1127 | { | 1065 | { |
1128 | if (NULL != s->frag_ctx) | 1066 | if (NULL != s->frag_ctx) |
1129 | { | 1067 | { |
1130 | GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); | 1068 | GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL ); |
1131 | GNUNET_free (s->frag_ctx); | 1069 | GNUNET_free(s->frag_ctx); |
1132 | s->frag_ctx = NULL; | 1070 | s->frag_ctx = NULL; |
1133 | } | 1071 | } |
1134 | GNUNET_free (s); | 1072 | GNUNET_free(s); |
1135 | } | 1073 | } |
1136 | 1074 | ||
1137 | |||
1138 | static void | 1075 | static void |
1139 | dequeue (struct Plugin *plugin, | 1076 | dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) |
1140 | struct UDP_MessageWrapper * udpw) | ||
1141 | { | 1077 | { |
1142 | if (plugin->bytes_in_buffer < udpw->msg_size) | 1078 | if (plugin->bytes_in_buffer < udpw->msg_size) |
1143 | GNUNET_break (0); | 1079 | GNUNET_break(0); |
1144 | else | 1080 | else |
1145 | { | 1081 | { |
1146 | GNUNET_STATISTICS_update (plugin->env->stats, | 1082 | GNUNET_STATISTICS_update (plugin->env->stats, |
1147 | "# UDP, total, bytes in buffers", | 1083 | "# UDP, total, bytes in buffers", -(long long) udpw->msg_size, |
1148 | - (long long) udpw->msg_size, GNUNET_NO); | 1084 | GNUNET_NO); |
1149 | plugin->bytes_in_buffer -= udpw->msg_size; | 1085 | plugin->bytes_in_buffer -= udpw->msg_size; |
1150 | } | 1086 | } |
1151 | GNUNET_STATISTICS_update (plugin->env->stats, | 1087 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", |
1152 | "# UDP, total, msgs in buffers", | 1088 | -1, GNUNET_NO); |
1153 | -1, GNUNET_NO); | 1089 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) |
1154 | if (udpw->session->addrlen == sizeof (struct sockaddr_in)) | 1090 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head, |
1155 | GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, | 1091 | plugin->ipv4_queue_tail, udpw); |
1156 | plugin->ipv4_queue_tail, udpw); | 1092 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) |
1157 | if (udpw->session->addrlen == sizeof (struct sockaddr_in6)) | 1093 | GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head, |
1158 | GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, | 1094 | plugin->ipv6_queue_tail, udpw); |
1159 | plugin->ipv6_queue_tail, udpw); | ||
1160 | } | 1095 | } |
1161 | 1096 | ||
1162 | |||
1163 | static void | 1097 | static void |
1164 | fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | 1098 | fragmented_message_done (struct UDP_FragmentationContext *fc, int result) |
1165 | { | 1099 | { |
@@ -1168,13 +1102,12 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1168 | struct UDP_MessageWrapper dummy; | 1102 | struct UDP_MessageWrapper dummy; |
1169 | struct Session *s = fc->session; | 1103 | struct Session *s = fc->session; |
1170 | 1104 | ||
1171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1105 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1172 | "%p : Fragmented message removed with result %s\n", | 1106 | "%p : Fragmented message removed with result %s\n", fc, |
1173 | fc, | 1107 | (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); |
1174 | (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); | ||
1175 | 1108 | ||
1176 | /* Call continuation for fragmented message */ | 1109 | /* Call continuation for fragmented message */ |
1177 | memset (&dummy, 0, sizeof (dummy)); | 1110 | memset (&dummy, 0, sizeof(dummy)); |
1178 | dummy.msg_type = MSG_FRAGMENTED_COMPLETE; | 1111 | dummy.msg_type = MSG_FRAGMENTED_COMPLETE; |
1179 | dummy.msg_size = s->frag_ctx->on_wire_size; | 1112 | dummy.msg_size = s->frag_ctx->on_wire_size; |
1180 | dummy.payload_size = s->frag_ctx->payload_size; | 1113 | dummy.payload_size = s->frag_ctx->payload_size; |
@@ -1186,46 +1119,43 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1186 | call_continuation (&dummy, result); | 1119 | call_continuation (&dummy, result); |
1187 | 1120 | ||
1188 | /* Remove leftover fragments from queue */ | 1121 | /* Remove leftover fragments from queue */ |
1189 | if (s->addrlen == sizeof (struct sockaddr_in6)) | 1122 | if (s->address->address_length == sizeof(struct sockaddr_in6)) |
1190 | { | 1123 | { |
1191 | udpw = plugin->ipv6_queue_head; | 1124 | udpw = plugin->ipv6_queue_head; |
1192 | while (NULL != udpw) | 1125 | while (NULL != udpw) |
1193 | { | 1126 | { |
1194 | tmp = udpw->next; | 1127 | tmp = udpw->next; |
1195 | if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == s->frag_ctx)) | 1128 | if ((udpw->frag_ctx != NULL )&& (udpw->frag_ctx == s->frag_ctx)){ |
1196 | { | 1129 | dequeue (plugin, udpw); |
1197 | dequeue (plugin, udpw); | 1130 | call_continuation (udpw, GNUNET_SYSERR); |
1198 | call_continuation (udpw, GNUNET_SYSERR); | 1131 | GNUNET_free (udpw); |
1199 | GNUNET_free (udpw); | 1132 | } |
1200 | } | ||
1201 | udpw = tmp; | 1133 | udpw = tmp; |
1202 | } | 1134 | } |
1203 | } | 1135 | } |
1204 | if (s->addrlen == sizeof (struct sockaddr_in)) | 1136 | if (s->address->address_length == sizeof(struct sockaddr_in)) |
1205 | { | 1137 | { |
1206 | udpw = plugin->ipv4_queue_head; | 1138 | udpw = plugin->ipv4_queue_head; |
1207 | while (udpw!= NULL) | 1139 | while (udpw != NULL ) |
1208 | { | 1140 | { |
1209 | tmp = udpw->next; | 1141 | tmp = udpw->next; |
1210 | if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == s->frag_ctx)) | 1142 | if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == s->frag_ctx)) |
1211 | { | 1143 | { |
1212 | dequeue (plugin, udpw); | 1144 | dequeue (plugin, udpw); |
1213 | call_continuation (udpw, GNUNET_SYSERR); | 1145 | call_continuation (udpw, GNUNET_SYSERR); |
1214 | GNUNET_free (udpw); | 1146 | GNUNET_free(udpw); |
1215 | } | 1147 | } |
1216 | udpw = tmp; | 1148 | udpw = tmp; |
1217 | } | 1149 | } |
1218 | } | 1150 | } |
1219 | 1151 | ||
1220 | /* Destroy fragmentation context */ | 1152 | /* Destroy fragmentation context */ |
1221 | GNUNET_FRAGMENT_context_destroy (fc->frag, | 1153 | GNUNET_FRAGMENT_context_destroy (fc->frag, &s->last_expected_msg_delay, |
1222 | &s->last_expected_msg_delay, | 1154 | &s->last_expected_ack_delay); |
1223 | &s->last_expected_ack_delay); | ||
1224 | s->frag_ctx = NULL; | 1155 | s->frag_ctx = NULL; |
1225 | GNUNET_free (fc); | 1156 | GNUNET_free(fc); |
1226 | } | 1157 | } |
1227 | 1158 | ||
1228 | |||
1229 | /** | 1159 | /** |
1230 | * Functions with this signature are called whenever we need | 1160 | * Functions with this signature are called whenever we need |
1231 | * to close a session due to a disconnect or failure to | 1161 | * to close a session due to a disconnect or failure to |
@@ -1236,19 +1166,16 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1236 | * @return #GNUNET_OK on success | 1166 | * @return #GNUNET_OK on success |
1237 | */ | 1167 | */ |
1238 | static int | 1168 | static int |
1239 | udp_disconnect_session (void *cls, | 1169 | udp_disconnect_session (void *cls, struct Session *s) |
1240 | struct Session *s) | ||
1241 | { | 1170 | { |
1242 | struct Plugin *plugin = cls; | 1171 | struct Plugin *plugin = cls; |
1243 | struct UDP_MessageWrapper *udpw; | 1172 | struct UDP_MessageWrapper *udpw; |
1244 | struct UDP_MessageWrapper *next; | 1173 | struct UDP_MessageWrapper *next; |
1245 | 1174 | ||
1246 | GNUNET_assert (GNUNET_YES != s->in_destroy); | 1175 | GNUNET_assert(GNUNET_YES != s->in_destroy); |
1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1176 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p to peer `%s' address ended\n", s, |
1248 | "Session %p to peer `%s' address ended\n", | 1177 | GNUNET_i2s (&s->target), |
1249 | s, | 1178 | GNUNET_a2s (s->address->address, s->address->address_length)); |
1250 | GNUNET_i2s (&s->target), | ||
1251 | GNUNET_a2s (s->sock_addr, s->addrlen)); | ||
1252 | /* stop timeout task */ | 1179 | /* stop timeout task */ |
1253 | if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) | 1180 | if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) |
1254 | { | 1181 | { |
@@ -1269,7 +1196,7 @@ udp_disconnect_session (void *cls, | |||
1269 | { | 1196 | { |
1270 | dequeue (plugin, udpw); | 1197 | dequeue (plugin, udpw); |
1271 | call_continuation (udpw, GNUNET_SYSERR); | 1198 | call_continuation (udpw, GNUNET_SYSERR); |
1272 | GNUNET_free (udpw); | 1199 | GNUNET_free(udpw); |
1273 | } | 1200 | } |
1274 | } | 1201 | } |
1275 | next = plugin->ipv6_queue_head; | 1202 | next = plugin->ipv6_queue_head; |
@@ -1280,7 +1207,7 @@ udp_disconnect_session (void *cls, | |||
1280 | { | 1207 | { |
1281 | dequeue (plugin, udpw); | 1208 | dequeue (plugin, udpw); |
1282 | call_continuation (udpw, GNUNET_SYSERR); | 1209 | call_continuation (udpw, GNUNET_SYSERR); |
1283 | GNUNET_free (udpw); | 1210 | GNUNET_free(udpw); |
1284 | } | 1211 | } |
1285 | } | 1212 | } |
1286 | plugin->env->session_end (plugin->env->cls, &s->target, s); | 1213 | plugin->env->session_end (plugin->env->cls, &s->target, s); |
@@ -1290,29 +1217,27 @@ udp_disconnect_session (void *cls, | |||
1290 | if (NULL != s->frag_ctx->cont) | 1217 | if (NULL != s->frag_ctx->cont) |
1291 | { | 1218 | { |
1292 | s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR, | 1219 | s->frag_ctx->cont (s->frag_ctx->cont_cls, &s->target, GNUNET_SYSERR, |
1293 | s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); | 1220 | s->frag_ctx->payload_size, s->frag_ctx->on_wire_size); |
1294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1221 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1295 | "Calling continuation for fragemented message to `%s' with result SYSERR\n", | 1222 | "Calling continuation for fragemented message to `%s' with result SYSERR\n", |
1296 | GNUNET_i2s (&s->target)); | 1223 | GNUNET_i2s (&s->target)); |
1297 | } | 1224 | } |
1298 | } | 1225 | } |
1299 | 1226 | ||
1300 | GNUNET_assert (GNUNET_YES == | 1227 | GNUNET_assert( |
1301 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, | 1228 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); |
1302 | &s->target, | 1229 | GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", |
1303 | s)); | 1230 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); |
1304 | GNUNET_STATISTICS_set (plugin->env->stats, | ||
1305 | "# UDP, sessions active", | ||
1306 | GNUNET_CONTAINER_multipeermap_size(plugin->sessions), | ||
1307 | GNUNET_NO); | ||
1308 | if (s->rc > 0) | 1231 | if (s->rc > 0) |
1309 | s->in_destroy = GNUNET_YES; | 1232 | s->in_destroy = GNUNET_YES; |
1310 | else | 1233 | else |
1234 | { | ||
1235 | GNUNET_HELLO_address_free (s->address); | ||
1311 | free_session (s); | 1236 | free_session (s); |
1237 | } | ||
1312 | return GNUNET_OK; | 1238 | return GNUNET_OK; |
1313 | } | 1239 | } |
1314 | 1240 | ||
1315 | |||
1316 | /** | 1241 | /** |
1317 | * Function that is called to get the keepalive factor. | 1242 | * Function that is called to get the keepalive factor. |
1318 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to | 1243 | * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to |
@@ -1327,7 +1252,6 @@ udp_query_keepalive_factor (void *cls) | |||
1327 | return 15; | 1252 | return 15; |
1328 | } | 1253 | } |
1329 | 1254 | ||
1330 | |||
1331 | /** | 1255 | /** |
1332 | * Destroy a session, plugin is being unloaded. | 1256 | * Destroy a session, plugin is being unloaded. |
1333 | * | 1257 | * |
@@ -1337,9 +1261,8 @@ udp_query_keepalive_factor (void *cls) | |||
1337 | * @return #GNUNET_OK (continue to iterate) | 1261 | * @return #GNUNET_OK (continue to iterate) |
1338 | */ | 1262 | */ |
1339 | static int | 1263 | static int |
1340 | disconnect_and_free_it (void *cls, | 1264 | disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, |
1341 | const struct GNUNET_PeerIdentity *key, | 1265 | void *value) |
1342 | void *value) | ||
1343 | { | 1266 | { |
1344 | struct Plugin *plugin = cls; | 1267 | struct Plugin *plugin = cls; |
1345 | 1268 | ||
@@ -1347,7 +1270,6 @@ disconnect_and_free_it (void *cls, | |||
1347 | return GNUNET_OK; | 1270 | return GNUNET_OK; |
1348 | } | 1271 | } |
1349 | 1272 | ||
1350 | |||
1351 | /** | 1273 | /** |
1352 | * Disconnect from a remote node. Clean up session if we have one for | 1274 | * Disconnect from a remote node. Clean up session if we have one for |
1353 | * this peer. | 1275 | * this peer. |
@@ -1357,20 +1279,17 @@ disconnect_and_free_it (void *cls, | |||
1357 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 1279 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1358 | */ | 1280 | */ |
1359 | static void | 1281 | static void |
1360 | udp_disconnect (void *cls, | 1282 | udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
1361 | const struct GNUNET_PeerIdentity *target) | ||
1362 | { | 1283 | { |
1363 | struct Plugin *plugin = cls; | 1284 | struct Plugin *plugin = cls; |
1364 | 1285 | ||
1365 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1286 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer `%s'\n", |
1366 | "Disconnecting from peer `%s'\n", | 1287 | GNUNET_i2s (target)); |
1367 | GNUNET_i2s (target)); | ||
1368 | /* Clean up sessions */ | 1288 | /* Clean up sessions */ |
1369 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, | 1289 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, |
1370 | &disconnect_and_free_it, plugin); | 1290 | &disconnect_and_free_it, plugin); |
1371 | } | 1291 | } |
1372 | 1292 | ||
1373 | |||
1374 | /** | 1293 | /** |
1375 | * Session was idle, so disconnect it | 1294 | * Session was idle, so disconnect it |
1376 | * | 1295 | * |
@@ -1378,23 +1297,18 @@ udp_disconnect (void *cls, | |||
1378 | * @param tc scheduler context | 1297 | * @param tc scheduler context |
1379 | */ | 1298 | */ |
1380 | static void | 1299 | static void |
1381 | session_timeout (void *cls, | 1300 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1382 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1383 | { | 1301 | { |
1384 | struct Session *s = cls; | 1302 | struct Session *s = cls; |
1385 | 1303 | ||
1386 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1304 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1305 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1388 | "Session %p was idle for %s, disconnecting\n", | 1306 | "Session %p was idle for %s, disconnecting\n", s, |
1389 | s, | 1307 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, GNUNET_YES)); |
1390 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, | ||
1391 | GNUNET_YES)); | ||
1392 | /* call session destroy function */ | 1308 | /* call session destroy function */ |
1393 | udp_disconnect_session (s->plugin, | 1309 | udp_disconnect_session (s->plugin, s); |
1394 | s); | ||
1395 | } | 1310 | } |
1396 | 1311 | ||
1397 | |||
1398 | /** | 1312 | /** |
1399 | * Increment session timeout due to activity | 1313 | * Increment session timeout due to activity |
1400 | * | 1314 | * |
@@ -1405,155 +1319,51 @@ reschedule_session_timeout (struct Session *s) | |||
1405 | { | 1319 | { |
1406 | if (GNUNET_YES == s->in_destroy) | 1320 | if (GNUNET_YES == s->in_destroy) |
1407 | return; | 1321 | return; |
1408 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | 1322 | GNUNET_assert(GNUNET_SCHEDULER_NO_TASK != s->timeout_task); |
1409 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 1323 | GNUNET_SCHEDULER_cancel (s->timeout_task); |
1410 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, | 1324 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, |
1411 | &session_timeout, | 1325 | &session_timeout, s); |
1412 | s); | 1326 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Timeout restarted for session %p\n", s); |
1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1414 | "Timeout restarted for session %p\n", | ||
1415 | s); | ||
1416 | } | 1327 | } |
1417 | 1328 | ||
1418 | |||
1419 | static struct Session * | 1329 | static struct Session * |
1420 | create_session (struct Plugin *plugin, | 1330 | create_session (struct Plugin *plugin, |
1421 | const struct GNUNET_PeerIdentity *target, | 1331 | const struct GNUNET_HELLO_Address *address) |
1422 | const void *addr, size_t addrlen, | ||
1423 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | ||
1424 | { | 1332 | { |
1425 | struct Session *s; | 1333 | struct Session *s; |
1426 | const struct IPv4UdpAddress *t4; | ||
1427 | const struct IPv6UdpAddress *t6; | ||
1428 | struct sockaddr_in *v4; | ||
1429 | struct sockaddr_in6 *v6; | ||
1430 | size_t len; | ||
1431 | |||
1432 | if (NULL == addr) | ||
1433 | { | ||
1434 | GNUNET_break (0); | ||
1435 | return NULL; | ||
1436 | } | ||
1437 | 1334 | ||
1438 | switch (addrlen) | 1335 | s = GNUNET_new (struct Session); |
1439 | { | 1336 | s->address = GNUNET_HELLO_address_copy (address); |
1440 | case sizeof (struct IPv4UdpAddress): | 1337 | s->target = address->peer; |
1441 | if (NULL == plugin->sockv4) | 1338 | s->last_expected_ack_delay = GNUNET_TIME_relative_multiply ( |
1442 | { | 1339 | GNUNET_TIME_UNIT_MILLISECONDS, 250); |
1443 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1444 | "Could not create session for peer `%s' address `%s': IPv4 is not enabled\n", | ||
1445 | GNUNET_i2s(target), | ||
1446 | udp_address_to_string (NULL, addr, addrlen)); | ||
1447 | return NULL; | ||
1448 | } | ||
1449 | t4 = addr; | ||
1450 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); | ||
1451 | s->plugin = plugin; | ||
1452 | len = sizeof (struct sockaddr_in); | ||
1453 | v4 = (struct sockaddr_in *) &s[1]; | ||
1454 | v4->sin_family = AF_INET; | ||
1455 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1456 | v4->sin_len = sizeof (struct sockaddr_in); | ||
1457 | #endif | ||
1458 | v4->sin_port = t4->u4_port; | ||
1459 | v4->sin_addr.s_addr = t4->ipv4_addr; | ||
1460 | s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v4, sizeof (struct sockaddr_in)); | ||
1461 | break; | ||
1462 | case sizeof (struct IPv6UdpAddress): | ||
1463 | if (NULL == plugin->sockv6) | ||
1464 | { | ||
1465 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1466 | "Could not create session for peer `%s' address `%s': IPv6 is not enabled\n", | ||
1467 | GNUNET_i2s(target), | ||
1468 | udp_address_to_string(NULL, addr, addrlen)); | ||
1469 | return NULL; | ||
1470 | } | ||
1471 | t6 = addr; | ||
1472 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); | ||
1473 | s->plugin = plugin; | ||
1474 | len = sizeof (struct sockaddr_in6); | ||
1475 | v6 = (struct sockaddr_in6 *) &s[1]; | ||
1476 | v6->sin6_family = AF_INET6; | ||
1477 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1478 | v6->sin6_len = sizeof (struct sockaddr_in6); | ||
1479 | #endif | ||
1480 | v6->sin6_port = t6->u6_port; | ||
1481 | v6->sin6_addr = t6->ipv6_addr; | ||
1482 | s->ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) v6, sizeof (struct sockaddr_in6)); | ||
1483 | break; | ||
1484 | default: | ||
1485 | /* Must have a valid address to send to */ | ||
1486 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
1487 | gettext_noop | ||
1488 | ("# requests to create session with invalid address"), | ||
1489 | 1, GNUNET_NO); | ||
1490 | return NULL; | ||
1491 | } | ||
1492 | s->addrlen = len; | ||
1493 | s->target = *target; | ||
1494 | s->sock_addr = (const struct sockaddr *) &s[1]; | ||
1495 | s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); | ||
1496 | s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; | 1340 | s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; |
1497 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; | 1341 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO_ABS; |
1498 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; | 1342 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; |
1499 | s->inbound = GNUNET_NO; | 1343 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, |
1500 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, | 1344 | &session_timeout, s); |
1501 | &session_timeout, | ||
1502 | s); | ||
1503 | return s; | 1345 | return s; |
1504 | } | 1346 | } |
1505 | 1347 | ||
1506 | |||
1507 | static int | 1348 | static int |
1508 | session_cmp_it (void *cls, | 1349 | session_cmp_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) |
1509 | const struct GNUNET_PeerIdentity * key, | ||
1510 | void *value) | ||
1511 | { | 1350 | { |
1512 | struct SessionCompareContext * cctx = cls; | 1351 | struct SessionCompareContext * cctx = cls; |
1513 | const struct GNUNET_HELLO_Address *address = cctx->addr; | 1352 | const struct GNUNET_HELLO_Address *address = cctx->address; |
1514 | struct Session *s = value; | 1353 | struct Session *s = value; |
1515 | socklen_t s_addrlen = s->addrlen; | ||
1516 | |||
1517 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1518 | "Comparing address %s <-> %s\n", | ||
1519 | udp_address_to_string (NULL, (void *) address->address, | ||
1520 | address->address_length), | ||
1521 | GNUNET_a2s (s->sock_addr, s->addrlen)); | ||
1522 | if (s->inbound != cctx->inbound) | ||
1523 | return GNUNET_YES; | ||
1524 | if ((address->address_length == sizeof (struct IPv4UdpAddress)) && | ||
1525 | (s_addrlen == sizeof (struct sockaddr_in))) | ||
1526 | { | ||
1527 | struct IPv4UdpAddress * u4 = NULL; | ||
1528 | u4 = (struct IPv4UdpAddress *) address->address; | ||
1529 | GNUNET_assert (NULL != u4); | ||
1530 | const struct sockaddr_in *s4 = (const struct sockaddr_in *) s->sock_addr; | ||
1531 | if ((0 == memcmp ((const void *) &u4->ipv4_addr,(const void *) &s4->sin_addr, sizeof (struct in_addr))) && | ||
1532 | (u4->u4_port == s4->sin_port)) | ||
1533 | { | ||
1534 | cctx->res = s; | ||
1535 | return GNUNET_NO; | ||
1536 | } | ||
1537 | 1354 | ||
1538 | } | 1355 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Comparing address %s <-> %s\n", |
1539 | if ((address->address_length == sizeof (struct IPv6UdpAddress)) && | 1356 | udp_address_to_string (NULL, (void *) address->address, address->address_length), |
1540 | (s_addrlen == sizeof (struct sockaddr_in6))) | 1357 | udp_address_to_string (NULL, s->address->address, s->address->address_length)); |
1358 | |||
1359 | if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address)) | ||
1541 | { | 1360 | { |
1542 | struct IPv6UdpAddress * u6 = NULL; | 1361 | cctx->res = s; |
1543 | u6 = (struct IPv6UdpAddress *) address->address; | 1362 | return GNUNET_NO; |
1544 | GNUNET_assert (NULL != u6); | ||
1545 | const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) s->sock_addr; | ||
1546 | if ((0 == memcmp (&u6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr))) && | ||
1547 | (u6->u6_port == s6->sin6_port)) | ||
1548 | { | ||
1549 | cctx->res = s; | ||
1550 | return GNUNET_NO; | ||
1551 | } | ||
1552 | } | 1363 | } |
1553 | return GNUNET_YES; | 1364 | return GNUNET_YES; |
1554 | } | 1365 | } |
1555 | 1366 | ||
1556 | |||
1557 | /** | 1367 | /** |
1558 | * Function obtain the network type for a session | 1368 | * Function obtain the network type for a session |
1559 | * | 1369 | * |
@@ -1562,13 +1372,11 @@ session_cmp_it (void *cls, | |||
1562 | * @return the network type | 1372 | * @return the network type |
1563 | */ | 1373 | */ |
1564 | static enum GNUNET_ATS_Network_Type | 1374 | static enum GNUNET_ATS_Network_Type |
1565 | udp_get_network (void *cls, | 1375 | udp_get_network (void *cls, struct Session *session) |
1566 | struct Session *session) | ||
1567 | { | 1376 | { |
1568 | return ntohl (session->ats.value); | 1377 | return ntohl (session->ats.value); |
1569 | } | 1378 | } |
1570 | 1379 | ||
1571 | |||
1572 | /** | 1380 | /** |
1573 | * Creates a new outbound session the transport service will use to | 1381 | * Creates a new outbound session the transport service will use to |
1574 | * send data to the peer | 1382 | * send data to the peer |
@@ -1580,107 +1388,130 @@ udp_get_network (void *cls, | |||
1580 | */ | 1388 | */ |
1581 | static struct Session * | 1389 | static struct Session * |
1582 | udp_plugin_lookup_session (void *cls, | 1390 | udp_plugin_lookup_session (void *cls, |
1583 | const struct GNUNET_HELLO_Address *address, | 1391 | const struct GNUNET_HELLO_Address *address) |
1584 | int inbound) | ||
1585 | { | 1392 | { |
1586 | struct Plugin * plugin = cls; | 1393 | struct Plugin * plugin = cls; |
1587 | struct IPv6UdpAddress * udp_a6; | 1394 | struct IPv6UdpAddress * udp_a6; |
1588 | struct IPv4UdpAddress * udp_a4; | 1395 | struct IPv4UdpAddress * udp_a4; |
1589 | 1396 | ||
1590 | GNUNET_assert (plugin != NULL); | 1397 | GNUNET_assert(plugin != NULL); |
1591 | GNUNET_assert (address != NULL); | 1398 | GNUNET_assert(address != NULL); |
1592 | 1399 | ||
1593 | 1400 | if ((address->address == NULL )|| | |
1594 | if ((address->address == NULL) || | 1401 | ((address->address_length != sizeof (struct IPv4UdpAddress)) && |
1595 | ((address->address_length != sizeof (struct IPv4UdpAddress)) && | 1402 | (address->address_length != sizeof (struct IPv6UdpAddress)))){ |
1596 | (address->address_length != sizeof (struct IPv6UdpAddress)))) | 1403 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1597 | { | 1404 | _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), |
1598 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1405 | address->address_length, |
1599 | _("Trying to create session for address of unexpected length %u (should be %u or %u)\n"), | 1406 | sizeof (struct IPv4UdpAddress), |
1600 | address->address_length, | 1407 | sizeof (struct IPv6UdpAddress)); |
1601 | sizeof (struct IPv4UdpAddress), | 1408 | return NULL; |
1602 | sizeof (struct IPv6UdpAddress)); | 1409 | } |
1603 | return NULL; | ||
1604 | } | ||
1605 | 1410 | ||
1606 | if (address->address_length == sizeof (struct IPv4UdpAddress)) | 1411 | if (address->address_length == sizeof(struct IPv4UdpAddress)) |
1607 | { | 1412 | { |
1608 | if (plugin->sockv4 == NULL) | 1413 | if (plugin->sockv4 == NULL ) |
1609 | return NULL; | 1414 | return NULL ; |
1610 | udp_a4 = (struct IPv4UdpAddress *) address->address; | 1415 | udp_a4 = (struct IPv4UdpAddress *) address->address; |
1611 | if (udp_a4->u4_port == 0) | 1416 | if (udp_a4->u4_port == 0) |
1612 | return NULL; | 1417 | return NULL ; |
1613 | } | 1418 | } |
1614 | 1419 | ||
1615 | if (address->address_length == sizeof (struct IPv6UdpAddress)) | 1420 | if (address->address_length == sizeof(struct IPv6UdpAddress)) |
1616 | { | 1421 | { |
1617 | if (plugin->sockv6 == NULL) | 1422 | if (plugin->sockv6 == NULL ) |
1618 | return NULL; | 1423 | return NULL ; |
1619 | udp_a6 = (struct IPv6UdpAddress *) address->address; | 1424 | udp_a6 = (struct IPv6UdpAddress *) address->address; |
1620 | if (udp_a6->u6_port == 0) | 1425 | if (udp_a6->u6_port == 0) |
1621 | return NULL; | 1426 | return NULL ; |
1622 | } | 1427 | } |
1623 | 1428 | ||
1624 | /* check if session already exists */ | 1429 | /* check if session already exists */ |
1625 | struct SessionCompareContext cctx; | 1430 | struct SessionCompareContext cctx; |
1626 | cctx.addr = address; | 1431 | cctx.address = address; |
1627 | cctx.res = NULL; | 1432 | cctx.res = NULL; |
1628 | cctx.inbound = inbound; | 1433 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1629 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1434 | "Looking for existing session for peer `%s' `%s' \n", |
1630 | "Looking for existing session for peer `%s' `%s' \n", | 1435 | GNUNET_i2s (&address->peer), |
1631 | GNUNET_i2s (&address->peer), | 1436 | udp_address_to_string(NULL, address->address, address->address_length)); |
1632 | udp_address_to_string(NULL, address->address, address->address_length)); | 1437 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, &address->peer, |
1633 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions, &address->peer, session_cmp_it, &cctx); | 1438 | session_cmp_it, &cctx); |
1634 | if (cctx.res != NULL) | 1439 | if (cctx.res != NULL ) |
1635 | { | 1440 | { |
1636 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); | 1441 | LOG(GNUNET_ERROR_TYPE_ERROR, "Found existing session %p\n", cctx.res); |
1637 | return cctx.res; | 1442 | return cctx.res; |
1638 | } | 1443 | } |
1639 | return NULL; | 1444 | return NULL ; |
1640 | } | 1445 | } |
1641 | 1446 | ||
1447 | static int | ||
1448 | udp_address_is_inbound (const struct GNUNET_HELLO_Address *address) | ||
1449 | { | ||
1450 | if (GNUNET_HELLO_ADDRESS_INFO_INBOUND == (address->local_info & GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
1451 | return GNUNET_YES; | ||
1452 | else | ||
1453 | return GNUNET_NO; | ||
1454 | } | ||
1642 | 1455 | ||
1643 | static struct Session * | 1456 | static struct Session * |
1644 | udp_plugin_create_session (void *cls, | 1457 | udp_plugin_create_session (void *cls, |
1645 | const struct GNUNET_HELLO_Address *address, | 1458 | const struct GNUNET_HELLO_Address *address) |
1646 | int inbound) | ||
1647 | { | 1459 | { |
1648 | struct Session *s; | 1460 | struct Session *s; |
1461 | struct IPv4UdpAddress *udp_v4; | ||
1462 | struct IPv6UdpAddress *udp_v6; | ||
1463 | |||
1464 | s = create_session (plugin, address); | ||
1465 | if (sizeof (struct IPv4UdpAddress) == address->address_length) | ||
1466 | { | ||
1467 | struct sockaddr_in v4; | ||
1468 | udp_v4 = (struct IPv4UdpAddress *) address->address; | ||
1469 | memset (&v4, '\0', sizeof (v4)); | ||
1470 | v4.sin_family = AF_INET; | ||
1471 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1472 | v4->sin_len = sizeof (struct sockaddr_in); | ||
1473 | #endif | ||
1474 | v4.sin_port = udp_v4->u4_port; | ||
1475 | v4.sin_addr.s_addr = udp_v4->ipv4_addr; | ||
1476 | s->ats = plugin->env->get_address_type (plugin->env->cls, | ||
1477 | (const struct sockaddr *) &v4, sizeof (v4)); | ||
1478 | } | ||
1479 | else if (sizeof (struct IPv6UdpAddress) == address->address_length) | ||
1480 | { | ||
1481 | struct sockaddr_in6 v6; | ||
1482 | udp_v6 = (struct IPv6UdpAddress *) address->address; | ||
1483 | memset (&v6, '\0', sizeof (v6)); | ||
1484 | v6.sin6_family = AF_INET6; | ||
1485 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1486 | v6->sin_len = sizeof (struct sockaddr_in6); | ||
1487 | #endif | ||
1488 | v6.sin6_port = udp_v6->u6_port; | ||
1489 | v6.sin6_addr = udp_v6->ipv6_addr; | ||
1490 | s->ats = plugin->env->get_address_type (plugin->env->cls, | ||
1491 | (const struct sockaddr *) &v6, sizeof (v6)); | ||
1492 | } | ||
1649 | 1493 | ||
1650 | s = create_session (plugin, | ||
1651 | &address->peer, | ||
1652 | address->address, | ||
1653 | address->address_length, | ||
1654 | NULL, NULL); | ||
1655 | if (NULL == s) | 1494 | if (NULL == s) |
1656 | return NULL; /* protocol not supported or address invalid */ | 1495 | return NULL ; /* protocol not supported or address invalid */ |
1657 | s->inbound = inbound; | 1496 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1658 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1497 | "Creating new %s session %p for peer `%s' address `%s'\n", |
1659 | "Creating new %s session %p for peer `%s' address `%s'\n", | 1498 | (GNUNET_YES == udp_address_is_inbound(address)) ? "inbound" : "outbound", |
1660 | (GNUNET_YES == s->inbound) ? "inbound" : "outbound", | 1499 | s, GNUNET_i2s (&address->peer), |
1661 | s, | 1500 | udp_address_to_string(NULL,address->address,address->address_length)); |
1662 | GNUNET_i2s(&address->peer), | 1501 | GNUNET_assert( |
1663 | udp_address_to_string(NULL,address->address,address->address_length)); | 1502 | GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, &s->target, s, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
1664 | GNUNET_assert (GNUNET_OK == | 1503 | GNUNET_STATISTICS_set (plugin->env->stats, "# UDP, sessions active", |
1665 | GNUNET_CONTAINER_multipeermap_put (plugin->sessions, | 1504 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), GNUNET_NO); |
1666 | &s->target, | ||
1667 | s, | ||
1668 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | ||
1669 | GNUNET_STATISTICS_set(plugin->env->stats, | ||
1670 | "# UDP, sessions active", | ||
1671 | GNUNET_CONTAINER_multipeermap_size(plugin->sessions), | ||
1672 | GNUNET_NO); | ||
1673 | return s; | 1505 | return s; |
1674 | } | 1506 | } |
1675 | 1507 | ||
1676 | static void | 1508 | static void |
1677 | udp_plugin_update_session_timeout (void *cls, | 1509 | udp_plugin_update_session_timeout (void *cls, |
1678 | const struct GNUNET_PeerIdentity *peer, | 1510 | const struct GNUNET_PeerIdentity *peer, struct Session *session) |
1679 | struct Session *session) | ||
1680 | { | 1511 | { |
1681 | if (GNUNET_YES | 1512 | if (GNUNET_YES |
1682 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, | 1513 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, peer, |
1683 | peer, session)) | 1514 | session)) |
1684 | { | 1515 | { |
1685 | GNUNET_break(0); | 1516 | GNUNET_break(0); |
1686 | return; | 1517 | return; |
@@ -1699,52 +1530,46 @@ udp_plugin_update_session_timeout (void *cls, | |||
1699 | * @return the session or NULL of max connections exceeded | 1530 | * @return the session or NULL of max connections exceeded |
1700 | */ | 1531 | */ |
1701 | static struct Session * | 1532 | static struct Session * |
1702 | udp_plugin_get_session (void *cls, | 1533 | udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
1703 | const struct GNUNET_HELLO_Address *address) | ||
1704 | { | 1534 | { |
1705 | struct Session *s; | 1535 | struct Session *s; |
1706 | 1536 | ||
1707 | if (NULL == address) | 1537 | if (NULL == address) |
1708 | { | 1538 | { |
1709 | GNUNET_break (0); | 1539 | GNUNET_break(0); |
1710 | return NULL; | 1540 | return NULL ; |
1711 | } | 1541 | } |
1712 | if ((address->address_length != sizeof (struct IPv4UdpAddress)) && | 1542 | if ((address->address_length != sizeof(struct IPv4UdpAddress)) |
1713 | (address->address_length != sizeof (struct IPv6UdpAddress))) | 1543 | && (address->address_length != sizeof(struct IPv6UdpAddress))) |
1714 | return NULL; | 1544 | return NULL ; |
1715 | 1545 | ||
1716 | /* otherwise create new */ | 1546 | /* otherwise create new */ |
1717 | if (NULL != (s = udp_plugin_lookup_session (cls, address, GNUNET_NO))) | 1547 | if (NULL != (s = udp_plugin_lookup_session (cls, address))) |
1718 | return s; | 1548 | return s; |
1719 | return udp_plugin_create_session (cls, address, GNUNET_NO); | 1549 | return udp_plugin_create_session (cls, address); |
1720 | } | 1550 | } |
1721 | 1551 | ||
1722 | |||
1723 | static void | 1552 | static void |
1724 | enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | 1553 | enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) |
1725 | { | 1554 | { |
1726 | if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) | 1555 | if (plugin->bytes_in_buffer + udpw->msg_size > INT64_MAX) |
1727 | GNUNET_break (0); | 1556 | GNUNET_break(0); |
1728 | else | 1557 | else |
1729 | { | 1558 | { |
1730 | GNUNET_STATISTICS_update (plugin->env->stats, | 1559 | GNUNET_STATISTICS_update (plugin->env->stats, |
1731 | "# UDP, total, bytes in buffers", | 1560 | "# UDP, total, bytes in buffers", udpw->msg_size, GNUNET_NO); |
1732 | udpw->msg_size, GNUNET_NO); | ||
1733 | plugin->bytes_in_buffer += udpw->msg_size; | 1561 | plugin->bytes_in_buffer += udpw->msg_size; |
1734 | } | 1562 | } |
1735 | GNUNET_STATISTICS_update (plugin->env->stats, | 1563 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, msgs in buffers", |
1736 | "# UDP, total, msgs in buffers", | 1564 | 1, GNUNET_NO); |
1737 | 1, GNUNET_NO); | 1565 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in)) |
1738 | if (udpw->session->addrlen == sizeof (struct sockaddr_in)) | 1566 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, |
1739 | GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, | 1567 | plugin->ipv4_queue_tail, udpw); |
1740 | plugin->ipv4_queue_tail, udpw); | 1568 | if (udpw->session->address->address_length == sizeof(struct sockaddr_in6)) |
1741 | if (udpw->session->addrlen == sizeof (struct sockaddr_in6)) | 1569 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head, |
1742 | GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, | 1570 | plugin->ipv6_queue_tail, udpw); |
1743 | plugin->ipv6_queue_tail, udpw); | ||
1744 | } | 1571 | } |
1745 | 1572 | ||
1746 | |||
1747 | |||
1748 | /** | 1573 | /** |
1749 | * Fragment message was transmitted via UDP, let fragmentation know | 1574 | * Fragment message was transmitted via UDP, let fragmentation know |
1750 | * to send the next fragment now. | 1575 | * to send the next fragment now. |
@@ -1756,16 +1581,14 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | |||
1756 | * @param physical bytes physical sent | 1581 | * @param physical bytes physical sent |
1757 | */ | 1582 | */ |
1758 | static void | 1583 | static void |
1759 | send_next_fragment (void *cls, | 1584 | send_next_fragment (void *cls, const struct GNUNET_PeerIdentity *target, |
1760 | const struct GNUNET_PeerIdentity *target, | 1585 | int result, size_t payload, size_t physical) |
1761 | int result, size_t payload, size_t physical) | ||
1762 | { | 1586 | { |
1763 | struct UDP_MessageWrapper *udpw = cls; | 1587 | struct UDP_MessageWrapper *udpw = cls; |
1764 | 1588 | ||
1765 | GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); | 1589 | GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); |
1766 | } | 1590 | } |
1767 | 1591 | ||
1768 | |||
1769 | /** | 1592 | /** |
1770 | * Function that is called with messages created by the fragmentation | 1593 | * Function that is called with messages created by the fragmentation |
1771 | * module. In the case of the 'proc' callback of the | 1594 | * module. In the case of the 'proc' callback of the |
@@ -1783,9 +1606,8 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1783 | struct UDP_MessageWrapper * udpw; | 1606 | struct UDP_MessageWrapper * udpw; |
1784 | size_t msg_len = ntohs (msg->size); | 1607 | size_t msg_len = ntohs (msg->size); |
1785 | 1608 | ||
1786 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1609 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); |
1787 | "Enqueuing fragment with %u bytes\n", msg_len); | 1610 | frag_ctx->fragments_used++; |
1788 | frag_ctx->fragments_used ++; | ||
1789 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); | 1611 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); |
1790 | udpw->session = frag_ctx->session; | 1612 | udpw->session = frag_ctx->session; |
1791 | udpw->msg_buf = (char *) &udpw[1]; | 1613 | udpw->msg_buf = (char *) &udpw[1]; |
@@ -1801,7 +1623,6 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1801 | schedule_select (plugin); | 1623 | schedule_select (plugin); |
1802 | } | 1624 | } |
1803 | 1625 | ||
1804 | |||
1805 | /** | 1626 | /** |
1806 | * Function that can be used by the transport service to transmit | 1627 | * Function that can be used by the transport service to transmit |
1807 | * a message using the plugin. Note that in the case of a | 1628 | * a message using the plugin. Note that in the case of a |
@@ -1830,42 +1651,38 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) | |||
1830 | * and does NOT mean that the message was not transmitted (DV) | 1651 | * and does NOT mean that the message was not transmitted (DV) |
1831 | */ | 1652 | */ |
1832 | static ssize_t | 1653 | static ssize_t |
1833 | udp_plugin_send (void *cls, | 1654 | udp_plugin_send (void *cls, struct Session *s, const char *msgbuf, |
1834 | struct Session *s, | 1655 | size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, |
1835 | const char *msgbuf, size_t msgbuf_size, | 1656 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
1836 | unsigned int priority, | ||
1837 | struct GNUNET_TIME_Relative to, | ||
1838 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | ||
1839 | { | 1657 | { |
1840 | struct Plugin *plugin = cls; | 1658 | struct Plugin *plugin = cls; |
1841 | size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); | 1659 | size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); |
1842 | struct UDP_FragmentationContext * frag_ctx; | 1660 | struct UDP_FragmentationContext * frag_ctx; |
1843 | struct UDP_MessageWrapper * udpw; | 1661 | struct UDP_MessageWrapper * udpw; |
1844 | struct UDPMessage *udp; | 1662 | struct UDPMessage *udp; |
1845 | char mbuf[udpmlen]; | 1663 | char mbuf[udpmlen]; |
1846 | GNUNET_assert (plugin != NULL); | 1664 | GNUNET_assert(plugin != NULL); |
1847 | GNUNET_assert (s != NULL); | 1665 | GNUNET_assert(s != NULL); |
1848 | 1666 | ||
1849 | if ((s->addrlen == sizeof (struct sockaddr_in6)) && (plugin->sockv6 == NULL)) | 1667 | if ((s->address->address_length == sizeof(struct sockaddr_in6)) && (plugin->sockv6 == NULL )) |
1850 | return GNUNET_SYSERR; | 1668 | return GNUNET_SYSERR; |
1851 | if ((s->addrlen == sizeof (struct sockaddr_in)) && (plugin->sockv4 == NULL)) | 1669 | if ((s->address->address_length == sizeof(struct sockaddr_in)) && (plugin->sockv4 == NULL )) |
1852 | return GNUNET_SYSERR; | 1670 | return GNUNET_SYSERR; |
1853 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1671 | if (udpmlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1854 | { | 1672 | { |
1855 | GNUNET_break (0); | 1673 | GNUNET_break(0); |
1856 | return GNUNET_SYSERR; | 1674 | return GNUNET_SYSERR; |
1857 | } | 1675 | } |
1858 | if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions, &s->target, s)) | 1676 | if (GNUNET_YES |
1677 | != GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, | ||
1678 | &s->target, s)) | ||
1859 | { | 1679 | { |
1860 | GNUNET_break (0); | 1680 | GNUNET_break(0); |
1861 | return GNUNET_SYSERR; | 1681 | return GNUNET_SYSERR; |
1862 | } | 1682 | } |
1863 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1683 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1864 | "UDP transmits %u-byte message to `%s' using address `%s'\n", | 1684 | "UDP transmits %u-byte message to `%s' using address `%s'\n", udpmlen, |
1865 | udpmlen, | 1685 | GNUNET_i2s (&s->target), udp_address_to_string (NULL, s->address->address, s->address->address_length)); |
1866 | GNUNET_i2s (&s->target), | ||
1867 | GNUNET_a2s(s->sock_addr, s->addrlen)); | ||
1868 | |||
1869 | 1686 | ||
1870 | /* Message */ | 1687 | /* Message */ |
1871 | udp = (struct UDPMessage *) mbuf; | 1688 | udp = (struct UDPMessage *) mbuf; |
@@ -1889,26 +1706,25 @@ udp_plugin_send (void *cls, | |||
1889 | udpw->msg_buf = (char *) &udpw[1]; | 1706 | udpw->msg_buf = (char *) &udpw[1]; |
1890 | udpw->msg_size = udpmlen; /* message size with UDP overhead */ | 1707 | udpw->msg_size = udpmlen; /* message size with UDP overhead */ |
1891 | udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ | 1708 | udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ |
1892 | udpw->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); | 1709 | udpw->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); |
1893 | udpw->cont = cont; | 1710 | udpw->cont = cont; |
1894 | udpw->cont_cls = cont_cls; | 1711 | udpw->cont_cls = cont_cls; |
1895 | udpw->frag_ctx = NULL; | 1712 | udpw->frag_ctx = NULL; |
1896 | udpw->msg_type = MSG_UNFRAGMENTED; | 1713 | udpw->msg_type = MSG_UNFRAGMENTED; |
1897 | memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage)); | 1714 | memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage)); |
1898 | memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], msgbuf, msgbuf_size); | 1715 | memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], msgbuf, msgbuf_size); |
1899 | enqueue (plugin, udpw); | 1716 | enqueue (plugin, udpw); |
1900 | 1717 | ||
1901 | GNUNET_STATISTICS_update (plugin->env->stats, | 1718 | GNUNET_STATISTICS_update (plugin->env->stats, |
1902 | "# UDP, unfragmented msgs, messages, attempt", | 1719 | "# UDP, unfragmented msgs, messages, attempt", 1, GNUNET_NO); |
1903 | 1, GNUNET_NO); | ||
1904 | GNUNET_STATISTICS_update (plugin->env->stats, | 1720 | GNUNET_STATISTICS_update (plugin->env->stats, |
1905 | "# UDP, unfragmented msgs, bytes payload, attempt", | 1721 | "# UDP, unfragmented msgs, bytes payload, attempt", udpw->payload_size, |
1906 | udpw->payload_size, GNUNET_NO); | 1722 | GNUNET_NO); |
1907 | } | 1723 | } |
1908 | else | 1724 | else |
1909 | { | 1725 | { |
1910 | /* fragmented message */ | 1726 | /* fragmented message */ |
1911 | if (s->frag_ctx != NULL) | 1727 | if (s->frag_ctx != NULL ) |
1912 | return GNUNET_SYSERR; | 1728 | return GNUNET_SYSERR; |
1913 | memcpy (&udp[1], msgbuf, msgbuf_size); | 1729 | memcpy (&udp[1], msgbuf, msgbuf_size); |
1914 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); | 1730 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); |
@@ -1916,93 +1732,87 @@ udp_plugin_send (void *cls, | |||
1916 | frag_ctx->session = s; | 1732 | frag_ctx->session = s; |
1917 | frag_ctx->cont = cont; | 1733 | frag_ctx->cont = cont; |
1918 | frag_ctx->cont_cls = cont_cls; | 1734 | frag_ctx->cont_cls = cont_cls; |
1919 | frag_ctx->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to); | 1735 | frag_ctx->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
1736 | to); | ||
1920 | frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ | 1737 | frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ |
1921 | frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ | 1738 | frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ |
1922 | frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, | 1739 | frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, |
1923 | UDP_MTU, | 1740 | UDP_MTU, &plugin->tracker, s->last_expected_msg_delay, |
1924 | &plugin->tracker, | 1741 | s->last_expected_ack_delay, &udp->header, &enqueue_fragment, frag_ctx); |
1925 | s->last_expected_msg_delay, | ||
1926 | s->last_expected_ack_delay, | ||
1927 | &udp->header, | ||
1928 | &enqueue_fragment, | ||
1929 | frag_ctx); | ||
1930 | s->frag_ctx = frag_ctx; | 1742 | s->frag_ctx = frag_ctx; |
1931 | GNUNET_STATISTICS_update (plugin->env->stats, | 1743 | GNUNET_STATISTICS_update (plugin->env->stats, |
1932 | "# UDP, fragmented msgs, messages, pending", | 1744 | "# UDP, fragmented msgs, messages, pending", 1, GNUNET_NO); |
1933 | 1, GNUNET_NO); | ||
1934 | GNUNET_STATISTICS_update (plugin->env->stats, | 1745 | GNUNET_STATISTICS_update (plugin->env->stats, |
1935 | "# UDP, fragmented msgs, messages, attempt", | 1746 | "# UDP, fragmented msgs, messages, attempt", 1, GNUNET_NO); |
1936 | 1, GNUNET_NO); | ||
1937 | GNUNET_STATISTICS_update (plugin->env->stats, | 1747 | GNUNET_STATISTICS_update (plugin->env->stats, |
1938 | "# UDP, fragmented msgs, bytes payload, attempt", | 1748 | "# UDP, fragmented msgs, bytes payload, attempt", |
1939 | frag_ctx->payload_size, GNUNET_NO); | 1749 | frag_ctx->payload_size, GNUNET_NO); |
1940 | } | 1750 | } |
1941 | schedule_select (plugin); | 1751 | schedule_select (plugin); |
1942 | return udpmlen; | 1752 | return udpmlen; |
1943 | } | 1753 | } |
1944 | 1754 | ||
1945 | |||
1946 | /** | 1755 | /** |
1947 | * Our external IP address/port mapping has changed. | 1756 | * Our external IP address/port mapping has changed. |
1948 | * | 1757 | * |
1949 | * @param cls closure, the 'struct LocalAddrList' | 1758 | * @param cls closure, the 'struct LocalAddrList' |
1950 | * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean | 1759 | * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean |
1951 | * the previous (now invalid) one | 1760 | * the previous (now invalid) one |
1952 | * @param addr either the previous or the new public IP address | 1761 | * @param address either the previous or the new public IP address |
1953 | * @param addrlen actual lenght of the address | 1762 | * @param addrlen actual lenght of the address |
1954 | */ | 1763 | */ |
1955 | static void | 1764 | static void |
1956 | udp_nat_port_map_callback (void *cls, int add_remove, | 1765 | udp_nat_port_map_callback (void *cls, int add_remove, |
1957 | const struct sockaddr *addr, socklen_t addrlen) | 1766 | const struct sockaddr *addr, socklen_t addrlen) |
1958 | { | 1767 | { |
1959 | struct Plugin *plugin = cls; | 1768 | struct Plugin *plugin = cls; |
1769 | struct GNUNET_HELLO_Address *address; | ||
1960 | struct IPv4UdpAddress u4; | 1770 | struct IPv4UdpAddress u4; |
1961 | struct IPv6UdpAddress u6; | 1771 | struct IPv6UdpAddress u6; |
1962 | void *arg; | 1772 | void *arg; |
1963 | size_t args; | 1773 | size_t args; |
1964 | 1774 | ||
1965 | LOG (GNUNET_ERROR_TYPE_INFO, | 1775 | LOG(GNUNET_ERROR_TYPE_INFO, "NAT notification to %s address `%s'\n", |
1966 | "NAT notification to %s address `%s'\n", | 1776 | (GNUNET_YES == add_remove) ? "add" : "remove", |
1967 | (GNUNET_YES == add_remove) ? "add" : "remove", | 1777 | GNUNET_a2s (addr, addrlen)); |
1968 | GNUNET_a2s (addr, addrlen)); | ||
1969 | 1778 | ||
1970 | /* convert 'addr' to our internal format */ | 1779 | /* convert 'address' to our internal format */ |
1971 | switch (addr->sa_family) | 1780 | switch (addr->sa_family) |
1972 | { | 1781 | { |
1973 | case AF_INET: | 1782 | case AF_INET: |
1974 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | 1783 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); |
1975 | memset (&u4, 0, sizeof (u4)); | 1784 | memset (&u4, 0, sizeof(u4)); |
1976 | u4.options = htonl(myoptions); | 1785 | u4.options = htonl (myoptions); |
1977 | u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 1786 | u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
1978 | u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; | 1787 | u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; |
1979 | if (0 == ((struct sockaddr_in *) addr)->sin_port) | 1788 | if (0 == ((struct sockaddr_in *) addr)->sin_port) |
1980 | return; | 1789 | return; |
1981 | arg = &u4; | 1790 | arg = &u4; |
1982 | args = sizeof (struct IPv4UdpAddress); | 1791 | args = sizeof(struct IPv4UdpAddress); |
1983 | break; | 1792 | break; |
1984 | case AF_INET6: | 1793 | case AF_INET6: |
1985 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 1794 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); |
1986 | memset (&u4, 0, sizeof (u4)); | 1795 | memset (&u4, 0, sizeof(u4)); |
1987 | u6.options = htonl(myoptions); | 1796 | u6.options = htonl (myoptions); |
1988 | if (0 == ((struct sockaddr_in6 *) addr)->sin6_port) | 1797 | if (0 == ((struct sockaddr_in6 *) addr)->sin6_port) |
1989 | return; | 1798 | return; |
1990 | memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, | 1799 | memcpy (&u6.ipv6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr, |
1991 | sizeof (struct in6_addr)); | 1800 | sizeof(struct in6_addr)); |
1992 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 1801 | u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
1993 | arg = &u6; | 1802 | arg = &u6; |
1994 | args = sizeof (struct IPv6UdpAddress); | 1803 | args = sizeof(struct IPv6UdpAddress); |
1995 | break; | 1804 | break; |
1996 | default: | 1805 | default: |
1997 | GNUNET_break (0); | 1806 | GNUNET_break(0); |
1998 | return; | 1807 | return; |
1999 | } | 1808 | } |
2000 | /* modify our published address list */ | 1809 | /* modify our published address list */ |
2001 | plugin->env->notify_address (plugin->env->cls, add_remove, arg, args, "udp"); | 1810 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1811 | PLUGIN_NAME, arg, args, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1812 | plugin->env->notify_address (plugin->env->cls, add_remove, address); | ||
1813 | GNUNET_HELLO_address_free (address); | ||
2002 | } | 1814 | } |
2003 | 1815 | ||
2004 | |||
2005 | |||
2006 | /** | 1816 | /** |
2007 | * Message tokenizer has broken up an incomming message. Pass it on | 1817 | * Message tokenizer has broken up an incomming message. Pass it on |
2008 | * to the service. | 1818 | * to the service. |
@@ -2014,37 +1824,26 @@ udp_nat_port_map_callback (void *cls, int add_remove, | |||
2014 | */ | 1824 | */ |
2015 | static int | 1825 | static int |
2016 | process_inbound_tokenized_messages (void *cls, void *client, | 1826 | process_inbound_tokenized_messages (void *cls, void *client, |
2017 | const struct GNUNET_MessageHeader *hdr) | 1827 | const struct GNUNET_MessageHeader *hdr) |
2018 | { | 1828 | { |
2019 | struct Plugin *plugin = cls; | 1829 | struct Plugin *plugin = cls; |
2020 | struct SourceInformation *si = client; | 1830 | struct SourceInformation *si = client; |
2021 | struct GNUNET_TIME_Relative delay; | 1831 | struct GNUNET_TIME_Relative delay; |
2022 | 1832 | ||
2023 | GNUNET_assert (si->session != NULL); | 1833 | GNUNET_assert(si->session != NULL); |
2024 | if (GNUNET_YES == si->session->in_destroy) | 1834 | if (GNUNET_YES == si->session->in_destroy) |
2025 | return GNUNET_OK; | 1835 | return GNUNET_OK; |
2026 | /* setup ATS */ | 1836 | /* setup ATS */ |
2027 | GNUNET_break (ntohl(si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED); | 1837 | GNUNET_break(ntohl (si->session->ats.value) != GNUNET_ATS_NET_UNSPECIFIED); |
2028 | reschedule_session_timeout (si->session); | 1838 | reschedule_session_timeout (si->session); |
2029 | delay = plugin->env->receive (plugin->env->cls, | 1839 | delay = plugin->env->receive (plugin->env->cls, si->session->address, si->session, hdr); |
2030 | &si->sender, | ||
2031 | hdr, | ||
2032 | si->session, | ||
2033 | (GNUNET_YES == si->session->inbound) | ||
2034 | ? NULL : si->arg, | ||
2035 | (GNUNET_YES == si->session->inbound) | ||
2036 | ? 0 : si->args); | ||
2037 | plugin->env->update_address_metrics (plugin->env->cls, | 1840 | plugin->env->update_address_metrics (plugin->env->cls, |
2038 | &si->sender, | 1841 | si->session->address, si->session, |
2039 | (GNUNET_YES == si->session->inbound) ? NULL : si->arg, | 1842 | &si->session->ats, 1); |
2040 | (GNUNET_YES == si->session->inbound) ? 0 : si->args, | ||
2041 | si->session, | ||
2042 | &si->session->ats, 1); | ||
2043 | si->session->flow_delay_for_other_peer = delay; | 1843 | si->session->flow_delay_for_other_peer = delay; |
2044 | return GNUNET_OK; | 1844 | return GNUNET_OK; |
2045 | } | 1845 | } |
2046 | 1846 | ||
2047 | |||
2048 | /** | 1847 | /** |
2049 | * We've received a UDP Message. Process it (pass contents to main service). | 1848 | * We've received a UDP Message. Process it (pass contents to main service). |
2050 | * | 1849 | * |
@@ -2055,11 +1854,11 @@ process_inbound_tokenized_messages (void *cls, void *client, | |||
2055 | */ | 1854 | */ |
2056 | static void | 1855 | static void |
2057 | process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | 1856 | process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, |
2058 | const struct sockaddr *sender_addr, | 1857 | const struct sockaddr *sender_addr, socklen_t sender_addr_len) |
2059 | socklen_t sender_addr_len) | ||
2060 | { | 1858 | { |
2061 | struct SourceInformation si; | 1859 | struct SourceInformation si; |
2062 | struct Session * s; | 1860 | struct Session * s; |
1861 | struct GNUNET_HELLO_Address *address; | ||
2063 | struct IPv4UdpAddress u4; | 1862 | struct IPv4UdpAddress u4; |
2064 | struct IPv6UdpAddress u6; | 1863 | struct IPv6UdpAddress u6; |
2065 | const void *arg; | 1864 | const void *arg; |
@@ -2067,13 +1866,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2067 | 1866 | ||
2068 | if (0 != ntohl (msg->reserved)) | 1867 | if (0 != ntohl (msg->reserved)) |
2069 | { | 1868 | { |
2070 | GNUNET_break_op (0); | 1869 | GNUNET_break_op(0); |
2071 | return; | 1870 | return; |
2072 | } | 1871 | } |
2073 | if (ntohs (msg->header.size) < | 1872 | if (ntohs (msg->header.size) |
2074 | sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) | 1873 | < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) |
2075 | { | 1874 | { |
2076 | GNUNET_break_op (0); | 1875 | GNUNET_break_op(0); |
2077 | return; | 1876 | return; |
2078 | } | 1877 | } |
2079 | 1878 | ||
@@ -2081,40 +1880,40 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2081 | switch (sender_addr->sa_family) | 1880 | switch (sender_addr->sa_family) |
2082 | { | 1881 | { |
2083 | case AF_INET: | 1882 | case AF_INET: |
2084 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in)); | 1883 | GNUNET_assert(sender_addr_len == sizeof(struct sockaddr_in)); |
2085 | memset (&u4, 0, sizeof (u4)); | 1884 | memset (&u4, 0, sizeof(u4)); |
2086 | u6.options = htonl (0); | 1885 | u6.options = htonl (0); |
2087 | u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; | 1886 | u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; |
2088 | u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; | 1887 | u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; |
2089 | arg = &u4; | 1888 | arg = &u4; |
2090 | args = sizeof (u4); | 1889 | args = sizeof(u4); |
2091 | break; | 1890 | break; |
2092 | case AF_INET6: | 1891 | case AF_INET6: |
2093 | GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6)); | 1892 | GNUNET_assert(sender_addr_len == sizeof(struct sockaddr_in6)); |
2094 | memset (&u6, 0, sizeof (u6)); | 1893 | memset (&u6, 0, sizeof(u6)); |
2095 | u6.options = htonl (0); | 1894 | u6.options = htonl (0); |
2096 | u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr; | 1895 | u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr; |
2097 | u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; | 1896 | u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; |
2098 | arg = &u6; | 1897 | arg = &u6; |
2099 | args = sizeof (u6); | 1898 | args = sizeof(u6); |
2100 | break; | 1899 | break; |
2101 | default: | 1900 | default: |
2102 | GNUNET_break (0); | 1901 | GNUNET_break(0); |
2103 | return; | 1902 | return; |
2104 | } | 1903 | } |
2105 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1904 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2106 | "Received message with %u bytes from peer `%s' at `%s'\n", | 1905 | "Received message with %u bytes from peer `%s' at `%s'\n", |
2107 | (unsigned int) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), | 1906 | (unsigned int ) ntohs (msg->header.size), GNUNET_i2s (&msg->sender), |
2108 | GNUNET_a2s (sender_addr, sender_addr_len)); | 1907 | GNUNET_a2s (sender_addr, sender_addr_len)); |
2109 | 1908 | ||
2110 | struct GNUNET_HELLO_Address * address = GNUNET_HELLO_address_allocate(&msg->sender, "udp", arg, args); | 1909 | address = GNUNET_HELLO_address_allocate ( &msg->sender, PLUGIN_NAME, |
2111 | if (NULL == (s = udp_plugin_lookup_session (plugin, address, GNUNET_YES))) | 1910 | arg, args, GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
1911 | if (NULL == (s = udp_plugin_lookup_session (plugin, address))) | ||
2112 | { | 1912 | { |
2113 | s = udp_plugin_create_session (plugin, address, GNUNET_YES); | 1913 | s = udp_plugin_create_session (plugin, address); |
2114 | plugin->env->session_start (NULL, &address->peer, PLUGIN_NAME, | 1914 | plugin->env->session_start (NULL, address, s, NULL, 0); |
2115 | address->address, address->address_length, s, NULL, 0); | ||
2116 | } | 1915 | } |
2117 | GNUNET_free (address); | 1916 | GNUNET_free(address); |
2118 | 1917 | ||
2119 | /* iterate over all embedded messages */ | 1918 | /* iterate over all embedded messages */ |
2120 | si.session = s; | 1919 | si.session = s; |
@@ -2122,18 +1921,14 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2122 | si.arg = arg; | 1921 | si.arg = arg; |
2123 | si.args = args; | 1922 | si.args = args; |
2124 | s->rc++; | 1923 | s->rc++; |
2125 | GNUNET_SERVER_mst_receive (plugin->mst, | 1924 | GNUNET_SERVER_mst_receive (plugin->mst, &si, (const char *) &msg[1], |
2126 | &si, | 1925 | ntohs (msg->header.size) - sizeof(struct UDPMessage), GNUNET_YES, |
2127 | (const char *) &msg[1], | 1926 | GNUNET_NO); |
2128 | ntohs (msg->header.size) - sizeof (struct UDPMessage), | ||
2129 | GNUNET_YES, | ||
2130 | GNUNET_NO); | ||
2131 | s->rc--; | 1927 | s->rc--; |
2132 | if ( (0 == s->rc) && (GNUNET_YES == s->in_destroy)) | 1928 | if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) |
2133 | free_session (s); | 1929 | free_session (s); |
2134 | } | 1930 | } |
2135 | 1931 | ||
2136 | |||
2137 | /** | 1932 | /** |
2138 | * Scan the heap for a receive context with the given address. | 1933 | * Scan the heap for a receive context with the given address. |
2139 | * | 1934 | * |
@@ -2146,13 +1941,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, | |||
2146 | */ | 1941 | */ |
2147 | static int | 1942 | static int |
2148 | find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | 1943 | find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, |
2149 | void *element, GNUNET_CONTAINER_HeapCostType cost) | 1944 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
2150 | { | 1945 | { |
2151 | struct FindReceiveContext *frc = cls; | 1946 | struct FindReceiveContext *frc = cls; |
2152 | struct DefragContext *e = element; | 1947 | struct DefragContext *e = element; |
2153 | 1948 | ||
2154 | if ((frc->addr_len == e->addr_len) && | 1949 | if ((frc->addr_len == e->addr_len) |
2155 | (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) | 1950 | && (0 == memcmp (frc->addr, e->src_addr, frc->addr_len))) |
2156 | { | 1951 | { |
2157 | frc->rc = e; | 1952 | frc->rc = e; |
2158 | return GNUNET_NO; | 1953 | return GNUNET_NO; |
@@ -2160,7 +1955,6 @@ find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | |||
2160 | return GNUNET_YES; | 1955 | return GNUNET_YES; |
2161 | } | 1956 | } |
2162 | 1957 | ||
2163 | |||
2164 | /** | 1958 | /** |
2165 | * Process a defragmented message. | 1959 | * Process a defragmented message. |
2166 | * | 1960 | * |
@@ -2174,35 +1968,30 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) | |||
2174 | 1968 | ||
2175 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) | 1969 | if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) |
2176 | { | 1970 | { |
2177 | GNUNET_break (0); | 1971 | GNUNET_break(0); |
2178 | return; | 1972 | return; |
2179 | } | 1973 | } |
2180 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | 1974 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) |
2181 | { | 1975 | { |
2182 | GNUNET_break (0); | 1976 | GNUNET_break(0); |
2183 | return; | 1977 | return; |
2184 | } | 1978 | } |
2185 | process_udp_message (rc->plugin, (const struct UDPMessage *) msg, | 1979 | process_udp_message (rc->plugin, (const struct UDPMessage *) msg, |
2186 | rc->src_addr, rc->addr_len); | 1980 | rc->src_addr, rc->addr_len); |
2187 | } | 1981 | } |
2188 | 1982 | ||
2189 | |||
2190 | struct LookupContext | 1983 | struct LookupContext |
2191 | { | 1984 | { |
2192 | struct Session *res; | 1985 | struct Session *res; |
2193 | 1986 | ||
2194 | const struct sockaddr * addr; | 1987 | const struct GNUNET_HELLO_Address *address; |
2195 | |||
2196 | size_t addrlen; | ||
2197 | 1988 | ||
2198 | int must_have_frag_ctx; | 1989 | int must_have_frag_ctx; |
2199 | }; | 1990 | }; |
2200 | 1991 | ||
2201 | |||
2202 | static int | 1992 | static int |
2203 | lookup_session_by_addr_it (void *cls, | 1993 | lookup_session_by_addr_it (void *cls, const struct GNUNET_PeerIdentity *key, |
2204 | const struct GNUNET_PeerIdentity *key, | 1994 | void *value) |
2205 | void *value) | ||
2206 | { | 1995 | { |
2207 | struct LookupContext *l_ctx = cls; | 1996 | struct LookupContext *l_ctx = cls; |
2208 | struct Session * s = value; | 1997 | struct Session * s = value; |
@@ -2210,15 +1999,7 @@ lookup_session_by_addr_it (void *cls, | |||
2210 | if ((GNUNET_YES == l_ctx->must_have_frag_ctx) && (NULL == s->frag_ctx)) | 1999 | if ((GNUNET_YES == l_ctx->must_have_frag_ctx) && (NULL == s->frag_ctx)) |
2211 | return GNUNET_YES; | 2000 | return GNUNET_YES; |
2212 | 2001 | ||
2213 | /* | 2002 | if (0 == GNUNET_HELLO_address_cmp (s->address, l_ctx->address)) |
2214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Comparing session: have %s %s %p<-> want %s\n", | ||
2215 | GNUNET_a2s(s->sock_addr, s->addrlen), | ||
2216 | (GNUNET_YES == s->inbound) ? "inbound" : "outbound", | ||
2217 | s->frag_ctx, | ||
2218 | GNUNET_a2s(l_ctx->addr, l_ctx->addrlen)); | ||
2219 | */ | ||
2220 | if ((s->addrlen == l_ctx->addrlen) && | ||
2221 | (0 == memcmp (s->sock_addr, l_ctx->addr, s->addrlen))) | ||
2222 | { | 2003 | { |
2223 | l_ctx->res = s; | 2004 | l_ctx->res = s; |
2224 | return GNUNET_YES; | 2005 | return GNUNET_YES; |
@@ -2226,7 +2007,6 @@ lookup_session_by_addr_it (void *cls, | |||
2226 | return GNUNET_YES; | 2007 | return GNUNET_YES; |
2227 | } | 2008 | } |
2228 | 2009 | ||
2229 | |||
2230 | /** | 2010 | /** |
2231 | * Transmit an acknowledgement. | 2011 | * Transmit an acknowledgement. |
2232 | * | 2012 | * |
@@ -2238,20 +2018,19 @@ static void | |||
2238 | ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | 2018 | ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) |
2239 | { | 2019 | { |
2240 | struct DefragContext *rc = cls; | 2020 | struct DefragContext *rc = cls; |
2241 | size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); | 2021 | size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size); |
2242 | struct UDP_ACK_Message *udp_ack; | 2022 | struct UDP_ACK_Message *udp_ack; |
2243 | uint32_t delay = 0; | 2023 | uint32_t delay = 0; |
2244 | struct UDP_MessageWrapper *udpw; | 2024 | struct UDP_MessageWrapper *udpw; |
2245 | struct Session *s; | 2025 | struct Session *s; |
2246 | struct LookupContext l_ctx; | 2026 | struct LookupContext l_ctx; |
2247 | 2027 | ||
2248 | l_ctx.addr = rc->src_addr; | 2028 | l_ctx.address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, rc->src_addr, |
2249 | l_ctx.addrlen = rc->addr_len; | 2029 | rc->addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE); |
2250 | l_ctx.res = NULL; | 2030 | l_ctx.res = NULL; |
2251 | l_ctx.must_have_frag_ctx = GNUNET_NO; | 2031 | l_ctx.must_have_frag_ctx = GNUNET_NO; |
2252 | GNUNET_CONTAINER_multipeermap_iterate (rc->plugin->sessions, | 2032 | GNUNET_CONTAINER_multipeermap_iterate (rc->plugin->sessions, |
2253 | &lookup_session_by_addr_it, | 2033 | &lookup_session_by_addr_it, &l_ctx); |
2254 | &l_ctx); | ||
2255 | s = l_ctx.res; | 2034 | s = l_ctx.res; |
2256 | 2035 | ||
2257 | if (NULL == s) | 2036 | if (NULL == s) |
@@ -2260,20 +2039,15 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
2260 | if (s->flow_delay_for_other_peer.rel_value_us <= UINT32_MAX) | 2039 | if (s->flow_delay_for_other_peer.rel_value_us <= UINT32_MAX) |
2261 | delay = s->flow_delay_for_other_peer.rel_value_us; | 2040 | delay = s->flow_delay_for_other_peer.rel_value_us; |
2262 | 2041 | ||
2263 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2042 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending ACK to `%s' including delay of %s\n", |
2264 | "Sending ACK to `%s' including delay of %s\n", | 2043 | GNUNET_a2s (rc->src_addr, (rc->src_addr->sa_family == AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6)), |
2265 | GNUNET_a2s (rc->src_addr, | 2044 | GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, GNUNET_YES)); |
2266 | (rc->src_addr->sa_family == | ||
2267 | AF_INET) ? sizeof (struct sockaddr_in) : sizeof (struct | ||
2268 | sockaddr_in6)), | ||
2269 | GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, | ||
2270 | GNUNET_YES)); | ||
2271 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); | 2045 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); |
2272 | udpw->msg_size = msize; | 2046 | udpw->msg_size = msize; |
2273 | udpw->payload_size = 0; | 2047 | udpw->payload_size = 0; |
2274 | udpw->session = s; | 2048 | udpw->session = s; |
2275 | udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 2049 | udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
2276 | udpw->msg_buf = (char *)&udpw[1]; | 2050 | udpw->msg_buf = (char *) &udpw[1]; |
2277 | udpw->msg_type = MSG_ACK; | 2051 | udpw->msg_type = MSG_ACK; |
2278 | udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; | 2052 | udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; |
2279 | udp_ack->header.size = htons ((uint16_t) msize); | 2053 | udp_ack->header.size = htons ((uint16_t) msize); |
@@ -2284,28 +2058,21 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) | |||
2284 | enqueue (rc->plugin, udpw); | 2058 | enqueue (rc->plugin, udpw); |
2285 | } | 2059 | } |
2286 | 2060 | ||
2287 | |||
2288 | static void | 2061 | static void |
2289 | read_process_msg (struct Plugin *plugin, | 2062 | read_process_msg (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, |
2290 | const struct GNUNET_MessageHeader *msg, | 2063 | const struct sockaddr *addr, socklen_t fromlen) |
2291 | const struct sockaddr *addr, | ||
2292 | socklen_t fromlen) | ||
2293 | { | 2064 | { |
2294 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | 2065 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) |
2295 | { | 2066 | { |
2296 | GNUNET_break_op (0); | 2067 | GNUNET_break_op(0); |
2297 | return; | 2068 | return; |
2298 | } | 2069 | } |
2299 | process_udp_message (plugin, (const struct UDPMessage *) msg, | 2070 | process_udp_message (plugin, (const struct UDPMessage *) msg, addr, fromlen); |
2300 | addr, fromlen); | ||
2301 | } | 2071 | } |
2302 | 2072 | ||
2303 | |||
2304 | static void | 2073 | static void |
2305 | read_process_ack (struct Plugin *plugin, | 2074 | read_process_ack (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, |
2306 | const struct GNUNET_MessageHeader *msg, | 2075 | const struct sockaddr *addr, socklen_t fromlen) |
2307 | const struct sockaddr *addr, | ||
2308 | socklen_t fromlen) | ||
2309 | { | 2076 | { |
2310 | const struct GNUNET_MessageHeader *ack; | 2077 | const struct GNUNET_MessageHeader *ack; |
2311 | const struct UDP_ACK_Message *udp_ack; | 2078 | const struct UDP_ACK_Message *udp_ack; |
@@ -2313,70 +2080,64 @@ read_process_ack (struct Plugin *plugin, | |||
2313 | struct Session *s; | 2080 | struct Session *s; |
2314 | struct GNUNET_TIME_Relative flow_delay; | 2081 | struct GNUNET_TIME_Relative flow_delay; |
2315 | 2082 | ||
2316 | if (ntohs (msg->size) < | 2083 | if (ntohs (msg->size) |
2317 | sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader)) | 2084 | < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) |
2318 | { | 2085 | { |
2319 | GNUNET_break_op (0); | 2086 | GNUNET_break_op(0); |
2320 | return; | 2087 | return; |
2321 | } | 2088 | } |
2322 | udp_ack = (const struct UDP_ACK_Message *) msg; | 2089 | udp_ack = (const struct UDP_ACK_Message *) msg; |
2323 | l_ctx.addr = (const struct sockaddr *) addr; | 2090 | |
2324 | l_ctx.addrlen = fromlen; | 2091 | l_ctx.address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, |
2092 | (const struct sockaddr *) addr, fromlen, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
2325 | l_ctx.res = NULL; | 2093 | l_ctx.res = NULL; |
2326 | l_ctx.must_have_frag_ctx = GNUNET_YES; | 2094 | l_ctx.must_have_frag_ctx = GNUNET_YES; |
2327 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, | 2095 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, |
2328 | &lookup_session_by_addr_it, | 2096 | &lookup_session_by_addr_it, &l_ctx); |
2329 | &l_ctx); | ||
2330 | s = l_ctx.res; | 2097 | s = l_ctx.res; |
2331 | if ((NULL == s) || (NULL == s->frag_ctx)) | 2098 | if ((NULL == s) || (NULL == s->frag_ctx)) |
2332 | { | 2099 | { |
2333 | return; | 2100 | return; |
2334 | } | 2101 | } |
2335 | 2102 | ||
2336 | |||
2337 | flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); | 2103 | flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); |
2338 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2104 | LOG(GNUNET_ERROR_TYPE_DEBUG, "We received a sending delay of %s\n", |
2339 | "We received a sending delay of %s\n", | 2105 | GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES)); |
2340 | GNUNET_STRINGS_relative_time_to_string (flow_delay, | 2106 | s->flow_delay_from_other_peer = GNUNET_TIME_relative_to_absolute (flow_delay); |
2341 | GNUNET_YES)); | ||
2342 | s->flow_delay_from_other_peer = | ||
2343 | GNUNET_TIME_relative_to_absolute (flow_delay); | ||
2344 | 2107 | ||
2345 | ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; | 2108 | ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; |
2346 | if (ntohs (ack->size) != | 2109 | if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message)) |
2347 | ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) | ||
2348 | { | 2110 | { |
2349 | GNUNET_break_op (0); | 2111 | GNUNET_break_op(0); |
2350 | return; | 2112 | return; |
2351 | } | 2113 | } |
2352 | 2114 | ||
2353 | if (0 != memcmp (&l_ctx.res->target, &udp_ack->sender, sizeof (struct GNUNET_PeerIdentity))) | 2115 | if (0 |
2354 | GNUNET_break (0); | 2116 | != memcmp (&l_ctx.res->target, &udp_ack->sender, |
2117 | sizeof(struct GNUNET_PeerIdentity))) | ||
2118 | GNUNET_break(0); | ||
2355 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) | 2119 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) |
2356 | { | 2120 | { |
2357 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2121 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2358 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", | 2122 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", |
2359 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), | 2123 | (unsigned int ) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), |
2360 | GNUNET_a2s (addr, fromlen)); | 2124 | GNUNET_a2s (addr, fromlen)); |
2361 | /* Expect more ACKs to arrive */ | 2125 | /* Expect more ACKs to arrive */ |
2362 | return; | 2126 | return; |
2363 | } | 2127 | } |
2364 | 2128 | ||
2365 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2129 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Message full ACK'ed\n", |
2366 | "Message full ACK'ed\n", | 2130 | (unsigned int ) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), |
2367 | (unsigned int) ntohs (msg->size), GNUNET_i2s (&udp_ack->sender), | 2131 | GNUNET_a2s (addr, fromlen)); |
2368 | GNUNET_a2s (addr, fromlen)); | ||
2369 | 2132 | ||
2370 | /* Remove fragmented message after successful sending */ | 2133 | /* Remove fragmented message after successful sending */ |
2371 | fragmented_message_done (s->frag_ctx, GNUNET_OK); | 2134 | fragmented_message_done (s->frag_ctx, GNUNET_OK); |
2372 | } | 2135 | } |
2373 | 2136 | ||
2374 | |||
2375 | static void | 2137 | static void |
2376 | read_process_fragment (struct Plugin *plugin, | 2138 | read_process_fragment (struct Plugin *plugin, |
2377 | const struct GNUNET_MessageHeader *msg, | 2139 | const struct GNUNET_MessageHeader *msg, const struct sockaddr *addr, |
2378 | const struct sockaddr *addr, | 2140 | socklen_t fromlen) |
2379 | socklen_t fromlen) | ||
2380 | { | 2141 | { |
2381 | struct DefragContext *d_ctx; | 2142 | struct DefragContext *d_ctx; |
2382 | struct GNUNET_TIME_Absolute now; | 2143 | struct GNUNET_TIME_Absolute now; |
@@ -2386,17 +2147,15 @@ read_process_fragment (struct Plugin *plugin, | |||
2386 | frc.addr = addr; | 2147 | frc.addr = addr; |
2387 | frc.addr_len = fromlen; | 2148 | frc.addr_len = fromlen; |
2388 | 2149 | ||
2389 | LOG (GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", | 2150 | LOG(GNUNET_ERROR_TYPE_DEBUG, "UDP processes %u-byte fragment from `%s'\n", |
2390 | (unsigned int) ntohs (msg->size), | 2151 | (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); |
2391 | GNUNET_a2s (addr, fromlen)); | ||
2392 | /* Lookup existing receive context for this address */ | 2152 | /* Lookup existing receive context for this address */ |
2393 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, | 2153 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, &find_receive_context, |
2394 | &find_receive_context, | 2154 | &frc); |
2395 | &frc); | ||
2396 | now = GNUNET_TIME_absolute_get (); | 2155 | now = GNUNET_TIME_absolute_get (); |
2397 | d_ctx = frc.rc; | 2156 | d_ctx = frc.rc; |
2398 | 2157 | ||
2399 | if (d_ctx == NULL) | 2158 | if (d_ctx == NULL ) |
2400 | { | 2159 | { |
2401 | /* Create a new defragmentation context */ | 2160 | /* Create a new defragmentation context */ |
2402 | d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + fromlen); | 2161 | d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + fromlen); |
@@ -2404,46 +2163,39 @@ read_process_fragment (struct Plugin *plugin, | |||
2404 | d_ctx->src_addr = (const struct sockaddr *) &d_ctx[1]; | 2163 | d_ctx->src_addr = (const struct sockaddr *) &d_ctx[1]; |
2405 | d_ctx->addr_len = fromlen; | 2164 | d_ctx->addr_len = fromlen; |
2406 | d_ctx->plugin = plugin; | 2165 | d_ctx->plugin = plugin; |
2407 | d_ctx->defrag = | 2166 | d_ctx->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, |
2408 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, UDP_MTU, | 2167 | UDP_MTU, UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx, &fragment_msg_proc, |
2409 | UDP_MAX_MESSAGES_IN_DEFRAG, d_ctx, | 2168 | &ack_proc); |
2410 | &fragment_msg_proc, &ack_proc); | 2169 | d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx, |
2411 | d_ctx->hnode = | 2170 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); |
2412 | GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, d_ctx, | 2171 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2413 | (GNUNET_CONTAINER_HeapCostType) | 2172 | "Created new defragmentation context for %u-byte fragment from `%s'\n", |
2414 | now.abs_value_us); | 2173 | (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); |
2415 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2416 | "Created new defragmentation context for %u-byte fragment from `%s'\n", | ||
2417 | (unsigned int) ntohs (msg->size), | ||
2418 | GNUNET_a2s (addr, fromlen)); | ||
2419 | } | 2174 | } |
2420 | else | 2175 | else |
2421 | { | 2176 | { |
2422 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2177 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2423 | "Found existing defragmentation context for %u-byte fragment from `%s'\n", | 2178 | "Found existing defragmentation context for %u-byte fragment from `%s'\n", |
2424 | (unsigned int) ntohs (msg->size), | 2179 | (unsigned int ) ntohs (msg->size), GNUNET_a2s (addr, fromlen)); |
2425 | GNUNET_a2s (addr, fromlen)); | ||
2426 | } | 2180 | } |
2427 | 2181 | ||
2428 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) | 2182 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) |
2429 | { | 2183 | { |
2430 | /* keep this 'rc' from expiring */ | 2184 | /* keep this 'rc' from expiring */ |
2431 | GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, d_ctx->hnode, | 2185 | GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, d_ctx->hnode, |
2432 | (GNUNET_CONTAINER_HeapCostType) | 2186 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); |
2433 | now.abs_value_us); | ||
2434 | } | 2187 | } |
2435 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > | 2188 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > |
2436 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) | 2189 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) |
2437 | { | 2190 | { |
2438 | /* remove 'rc' that was inactive the longest */ | 2191 | /* remove 'rc' that was inactive the longest */ |
2439 | d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); | 2192 | d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); |
2440 | GNUNET_assert (NULL != d_ctx); | 2193 | GNUNET_assert(NULL != d_ctx); |
2441 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); | 2194 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); |
2442 | GNUNET_free (d_ctx); | 2195 | GNUNET_free(d_ctx); |
2443 | } | 2196 | } |
2444 | } | 2197 | } |
2445 | 2198 | ||
2446 | |||
2447 | /** | 2199 | /** |
2448 | * Read and process a message from the given socket. | 2200 | * Read and process a message from the given socket. |
2449 | * | 2201 | * |
@@ -2459,10 +2211,10 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
2459 | ssize_t size; | 2211 | ssize_t size; |
2460 | const struct GNUNET_MessageHeader *msg; | 2212 | const struct GNUNET_MessageHeader *msg; |
2461 | 2213 | ||
2462 | fromlen = sizeof (addr); | 2214 | fromlen = sizeof(addr); |
2463 | memset (&addr, 0, sizeof (addr)); | 2215 | memset (&addr, 0, sizeof(addr)); |
2464 | size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), | 2216 | size = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof(buf), |
2465 | (struct sockaddr *) &addr, &fromlen); | 2217 | (struct sockaddr *) &addr, &fromlen); |
2466 | #if MINGW | 2218 | #if MINGW |
2467 | /* On SOCK_DGRAM UDP sockets recvfrom might fail with a | 2219 | /* On SOCK_DGRAM UDP sockets recvfrom might fail with a |
2468 | * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) | 2220 | * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) |
@@ -2475,146 +2227,134 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
2475 | * Unreachable message. | 2227 | * Unreachable message. |
2476 | */ | 2228 | */ |
2477 | if ( (-1 == size) && (ECONNRESET == errno) ) | 2229 | if ( (-1 == size) && (ECONNRESET == errno) ) |
2478 | return; | 2230 | return; |
2479 | #endif | 2231 | #endif |
2480 | if (-1 == size) | 2232 | if (-1 == size) |
2481 | { | 2233 | { |
2482 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2234 | LOG(GNUNET_ERROR_TYPE_DEBUG, "UDP failed to receive data: %s\n", |
2483 | "UDP failed to receive data: %s\n", STRERROR (errno)); | 2235 | STRERROR (errno)); |
2484 | /* Connection failure or something. Not a protocol violation. */ | 2236 | /* Connection failure or something. Not a protocol violation. */ |
2485 | return; | 2237 | return; |
2486 | } | 2238 | } |
2487 | if (size < sizeof (struct GNUNET_MessageHeader)) | 2239 | if (size < sizeof(struct GNUNET_MessageHeader)) |
2488 | { | 2240 | { |
2489 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2241 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2490 | "UDP got %u bytes, which is not enough for a GNUnet message header\n", | 2242 | "UDP got %u bytes, which is not enough for a GNUnet message header\n", |
2491 | (unsigned int) size); | 2243 | (unsigned int ) size); |
2492 | /* _MAY_ be a connection failure (got partial message) */ | 2244 | /* _MAY_ be a connection failure (got partial message) */ |
2493 | /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ | 2245 | /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ |
2494 | GNUNET_break_op (0); | 2246 | GNUNET_break_op(0); |
2495 | return; | 2247 | return; |
2496 | } | 2248 | } |
2497 | msg = (const struct GNUNET_MessageHeader *) buf; | 2249 | msg = (const struct GNUNET_MessageHeader *) buf; |
2498 | 2250 | ||
2499 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2251 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2500 | "UDP received %u-byte message from `%s' type %u\n", | 2252 | "UDP received %u-byte message from `%s' type %u\n", (unsigned int ) size, |
2501 | (unsigned int) size, | 2253 | GNUNET_a2s ((const struct sockaddr * ) &addr, fromlen), |
2502 | GNUNET_a2s ((const struct sockaddr *) &addr, fromlen), | 2254 | ntohs (msg->type)); |
2503 | ntohs (msg->type)); | ||
2504 | 2255 | ||
2505 | if (size != ntohs (msg->size)) | 2256 | if (size != ntohs (msg->size)) |
2506 | { | 2257 | { |
2507 | GNUNET_break_op (0); | 2258 | GNUNET_break_op(0); |
2508 | return; | 2259 | return; |
2509 | } | 2260 | } |
2510 | 2261 | ||
2511 | GNUNET_STATISTICS_update (plugin->env->stats, | 2262 | GNUNET_STATISTICS_update (plugin->env->stats, "# UDP, total, bytes, received", |
2512 | "# UDP, total, bytes, received", | 2263 | size, GNUNET_NO); |
2513 | size, GNUNET_NO); | ||
2514 | 2264 | ||
2515 | switch (ntohs (msg->type)) | 2265 | switch (ntohs (msg->type)) |
2516 | { | 2266 | { |
2517 | case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: | 2267 | case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: |
2518 | if (GNUNET_YES == plugin->enable_broadcasting_receiving) | 2268 | if (GNUNET_YES == plugin->enable_broadcasting_receiving) |
2519 | udp_broadcast_receive (plugin, buf, size, | 2269 | udp_broadcast_receive (plugin, buf, size, (const struct sockaddr *) &addr, |
2520 | (const struct sockaddr *) &addr, fromlen); | 2270 | fromlen); |
2521 | return; | 2271 | return; |
2522 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: | 2272 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: |
2523 | read_process_msg (plugin, msg, | 2273 | read_process_msg (plugin, msg, (const struct sockaddr *) &addr, fromlen); |
2524 | (const struct sockaddr *) &addr, fromlen); | ||
2525 | return; | 2274 | return; |
2526 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: | 2275 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: |
2527 | read_process_ack (plugin, msg, | 2276 | read_process_ack (plugin, msg, (const struct sockaddr *) &addr, fromlen); |
2528 | (const struct sockaddr *) &addr, fromlen); | ||
2529 | return; | 2277 | return; |
2530 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 2278 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
2531 | read_process_fragment (plugin, msg, | 2279 | read_process_fragment (plugin, msg, (const struct sockaddr *) &addr, |
2532 | (const struct sockaddr *) &addr, fromlen); | 2280 | fromlen); |
2533 | return; | 2281 | return; |
2534 | default: | 2282 | default: |
2535 | GNUNET_break_op (0); | 2283 | GNUNET_break_op(0); |
2536 | return; | 2284 | return; |
2537 | } | 2285 | } |
2538 | } | 2286 | } |
2539 | 2287 | ||
2540 | |||
2541 | static struct UDP_MessageWrapper * | 2288 | static struct UDP_MessageWrapper * |
2542 | remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | 2289 | remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, |
2543 | struct GNUNET_NETWORK_Handle *sock) | 2290 | struct GNUNET_NETWORK_Handle *sock) |
2544 | { | 2291 | { |
2545 | struct UDP_MessageWrapper *udpw = NULL; | 2292 | struct UDP_MessageWrapper *udpw = NULL; |
2546 | struct GNUNET_TIME_Relative remaining; | 2293 | struct GNUNET_TIME_Relative remaining; |
2547 | 2294 | ||
2548 | udpw = head; | 2295 | udpw = head; |
2549 | while (udpw != NULL) | 2296 | while (udpw != NULL ) |
2550 | { | 2297 | { |
2551 | /* Find messages with timeout */ | 2298 | /* Find messages with timeout */ |
2552 | remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); | 2299 | remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); |
2553 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) | 2300 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) |
2554 | { | 2301 | { |
2555 | /* Message timed out */ | 2302 | /* Message timed out */ |
2556 | switch (udpw->msg_type) { | 2303 | switch (udpw->msg_type) |
2557 | case MSG_UNFRAGMENTED: | 2304 | { |
2558 | GNUNET_STATISTICS_update (plugin->env->stats, | 2305 | case MSG_UNFRAGMENTED: |
2559 | "# UDP, total, bytes, sent, timeout", | 2306 | GNUNET_STATISTICS_update (plugin->env->stats, |
2560 | udpw->msg_size, GNUNET_NO); | 2307 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); |
2561 | GNUNET_STATISTICS_update (plugin->env->stats, | 2308 | GNUNET_STATISTICS_update (plugin->env->stats, |
2562 | "# UDP, total, messages, sent, timeout", | 2309 | "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); |
2563 | 1, GNUNET_NO); | 2310 | GNUNET_STATISTICS_update (plugin->env->stats, |
2564 | GNUNET_STATISTICS_update (plugin->env->stats, | 2311 | "# UDP, unfragmented msgs, messages, sent, timeout", 1, GNUNET_NO); |
2565 | "# UDP, unfragmented msgs, messages, sent, timeout", | 2312 | GNUNET_STATISTICS_update (plugin->env->stats, |
2566 | 1, GNUNET_NO); | 2313 | "# UDP, unfragmented msgs, bytes, sent, timeout", |
2567 | GNUNET_STATISTICS_update (plugin->env->stats, | 2314 | udpw->payload_size, GNUNET_NO); |
2568 | "# UDP, unfragmented msgs, bytes, sent, timeout", | 2315 | /* Not fragmented message */ |
2569 | udpw->payload_size, GNUNET_NO); | 2316 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2570 | /* Not fragmented message */ | 2317 | "Message for peer `%s' with size %u timed out\n", |
2571 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2318 | GNUNET_i2s (&udpw->session->target), udpw->payload_size); |
2572 | "Message for peer `%s' with size %u timed out\n", | 2319 | call_continuation (udpw, GNUNET_SYSERR); |
2573 | GNUNET_i2s(&udpw->session->target), udpw->payload_size); | 2320 | /* Remove message */ |
2574 | call_continuation (udpw, GNUNET_SYSERR); | 2321 | dequeue (plugin, udpw); |
2575 | /* Remove message */ | 2322 | GNUNET_free(udpw); |
2576 | dequeue (plugin, udpw); | 2323 | break; |
2577 | GNUNET_free (udpw); | 2324 | case MSG_FRAGMENTED: |
2578 | break; | 2325 | /* Fragmented message */ |
2579 | case MSG_FRAGMENTED: | 2326 | GNUNET_STATISTICS_update (plugin->env->stats, |
2580 | /* Fragmented message */ | 2327 | "# UDP, total, bytes, sent, timeout", udpw->frag_ctx->on_wire_size, |
2581 | GNUNET_STATISTICS_update (plugin->env->stats, | 2328 | GNUNET_NO); |
2582 | "# UDP, total, bytes, sent, timeout", | 2329 | GNUNET_STATISTICS_update (plugin->env->stats, |
2583 | udpw->frag_ctx->on_wire_size, GNUNET_NO); | 2330 | "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); |
2584 | GNUNET_STATISTICS_update (plugin->env->stats, | 2331 | call_continuation (udpw, GNUNET_SYSERR); |
2585 | "# UDP, total, messages, sent, timeout", | 2332 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2586 | 1, GNUNET_NO); | 2333 | "Fragment for message for peer `%s' with size %u timed out\n", |
2587 | call_continuation (udpw, GNUNET_SYSERR); | 2334 | GNUNET_i2s (&udpw->session->target), udpw->frag_ctx->payload_size); |
2588 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2335 | |
2589 | "Fragment for message for peer `%s' with size %u timed out\n", | 2336 | GNUNET_STATISTICS_update (plugin->env->stats, |
2590 | GNUNET_i2s(&udpw->session->target), udpw->frag_ctx->payload_size); | 2337 | "# UDP, fragmented msgs, messages, sent, timeout", 1, GNUNET_NO); |
2591 | 2338 | GNUNET_STATISTICS_update (plugin->env->stats, | |
2592 | 2339 | "# UDP, fragmented msgs, bytes, sent, timeout", | |
2593 | GNUNET_STATISTICS_update (plugin->env->stats, | 2340 | udpw->frag_ctx->payload_size, GNUNET_NO); |
2594 | "# UDP, fragmented msgs, messages, sent, timeout", | 2341 | /* Remove fragmented message due to timeout */ |
2595 | 1, GNUNET_NO); | 2342 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); |
2596 | GNUNET_STATISTICS_update (plugin->env->stats, | 2343 | break; |
2597 | "# UDP, fragmented msgs, bytes, sent, timeout", | 2344 | case MSG_ACK: |
2598 | udpw->frag_ctx->payload_size, GNUNET_NO); | 2345 | GNUNET_STATISTICS_update (plugin->env->stats, |
2599 | /* Remove fragmented message due to timeout */ | 2346 | "# UDP, total, bytes, sent, timeout", udpw->msg_size, GNUNET_NO); |
2600 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); | 2347 | GNUNET_STATISTICS_update (plugin->env->stats, |
2601 | break; | 2348 | "# UDP, total, messages, sent, timeout", 1, GNUNET_NO); |
2602 | case MSG_ACK: | 2349 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2603 | GNUNET_STATISTICS_update (plugin->env->stats, | 2350 | "ACK Message for peer `%s' with size %u timed out\n", |
2604 | "# UDP, total, bytes, sent, timeout", | 2351 | GNUNET_i2s (&udpw->session->target), udpw->payload_size); |
2605 | udpw->msg_size, GNUNET_NO); | 2352 | call_continuation (udpw, GNUNET_SYSERR); |
2606 | GNUNET_STATISTICS_update (plugin->env->stats, | 2353 | dequeue (plugin, udpw); |
2607 | "# UDP, total, messages, sent, timeout", | 2354 | GNUNET_free(udpw); |
2608 | 1, GNUNET_NO); | 2355 | break; |
2609 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2356 | default: |
2610 | "ACK Message for peer `%s' with size %u timed out\n", | 2357 | break; |
2611 | GNUNET_i2s(&udpw->session->target), udpw->payload_size); | ||
2612 | call_continuation (udpw, GNUNET_SYSERR); | ||
2613 | dequeue (plugin, udpw); | ||
2614 | GNUNET_free (udpw); | ||
2615 | break; | ||
2616 | default: | ||
2617 | break; | ||
2618 | } | 2358 | } |
2619 | if (sock == plugin->sockv4) | 2359 | if (sock == plugin->sockv4) |
2620 | udpw = plugin->ipv4_queue_head; | 2360 | udpw = plugin->ipv4_queue_head; |
@@ -2622,33 +2362,32 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2622 | udpw = plugin->ipv6_queue_head; | 2362 | udpw = plugin->ipv6_queue_head; |
2623 | else | 2363 | else |
2624 | { | 2364 | { |
2625 | GNUNET_break (0); /* should never happen */ | 2365 | GNUNET_break(0); /* should never happen */ |
2626 | udpw = NULL; | 2366 | udpw = NULL; |
2627 | } | 2367 | } |
2628 | GNUNET_STATISTICS_update (plugin->env->stats, | 2368 | GNUNET_STATISTICS_update (plugin->env->stats, |
2629 | "# messages dismissed due to timeout", | 2369 | "# messages dismissed due to timeout", 1, GNUNET_NO); |
2630 | 1, GNUNET_NO); | ||
2631 | } | 2370 | } |
2632 | else | 2371 | else |
2633 | { | 2372 | { |
2634 | /* Message did not time out, check flow delay */ | 2373 | /* Message did not time out, check flow delay */ |
2635 | remaining = GNUNET_TIME_absolute_get_remaining (udpw->session->flow_delay_from_other_peer); | 2374 | remaining = GNUNET_TIME_absolute_get_remaining ( |
2375 | udpw->session->flow_delay_from_other_peer); | ||
2636 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) | 2376 | if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) |
2637 | { | 2377 | { |
2638 | /* this message is not delayed */ | 2378 | /* this message is not delayed */ |
2639 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2379 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2640 | "Message for peer `%s' (%u bytes) is not delayed \n", | 2380 | "Message for peer `%s' (%u bytes) is not delayed \n", |
2641 | GNUNET_i2s(&udpw->session->target), udpw->payload_size); | 2381 | GNUNET_i2s (&udpw->session->target), udpw->payload_size); |
2642 | break; /* Found message to send, break */ | 2382 | break; /* Found message to send, break */ |
2643 | } | 2383 | } |
2644 | else | 2384 | else |
2645 | { | 2385 | { |
2646 | /* Message is delayed, try next */ | 2386 | /* Message is delayed, try next */ |
2647 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2387 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2648 | "Message for peer `%s' (%u bytes) is delayed for %s\n", | 2388 | "Message for peer `%s' (%u bytes) is delayed for %s\n", |
2649 | GNUNET_i2s(&udpw->session->target), udpw->payload_size, | 2389 | GNUNET_i2s (&udpw->session->target), udpw->payload_size, |
2650 | GNUNET_STRINGS_relative_time_to_string (remaining, | 2390 | GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); |
2651 | GNUNET_YES)); | ||
2652 | udpw = udpw->next; | 2391 | udpw = udpw->next; |
2653 | } | 2392 | } |
2654 | } | 2393 | } |
@@ -2656,54 +2395,51 @@ remove_timeout_messages_and_select (struct UDP_MessageWrapper *head, | |||
2656 | return udpw; | 2395 | return udpw; |
2657 | } | 2396 | } |
2658 | 2397 | ||
2659 | |||
2660 | static void | 2398 | static void |
2661 | analyze_send_error (struct Plugin *plugin, | 2399 | analyze_send_error (struct Plugin *plugin, const struct sockaddr * sa, |
2662 | const struct sockaddr * sa, | 2400 | socklen_t slen, int error) |
2663 | socklen_t slen, | ||
2664 | int error) | ||
2665 | { | 2401 | { |
2666 | static int network_down_error; | 2402 | static int network_down_error; |
2667 | struct GNUNET_ATS_Information type; | 2403 | struct GNUNET_ATS_Information type; |
2668 | 2404 | ||
2669 | type = plugin->env->get_address_type (plugin->env->cls,sa, slen); | 2405 | type = plugin->env->get_address_type (plugin->env->cls, sa, slen); |
2670 | if (((GNUNET_ATS_NET_LAN == ntohl(type.value)) || (GNUNET_ATS_NET_WAN == ntohl(type.value))) && | 2406 | if (((GNUNET_ATS_NET_LAN == ntohl (type.value)) |
2671 | ((ENETUNREACH == errno) || (ENETDOWN == errno))) | 2407 | || (GNUNET_ATS_NET_WAN == ntohl (type.value))) |
2672 | { | 2408 | && ((ENETUNREACH == errno)|| (ENETDOWN == errno))) |
2673 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) | 2409 | { |
2674 | { | 2410 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in))) |
2675 | /* IPv4: "Network unreachable" or "Network down" | 2411 | { |
2676 | * | 2412 | /* IPv4: "Network unreachable" or "Network down" |
2677 | * This indicates we do not have connectivity | 2413 | * |
2678 | */ | 2414 | * This indicates we do not have connectivity |
2679 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2415 | */ |
2680 | _("UDP could not transmit message to `%s': " | 2416 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2681 | "Network seems down, please check your network configuration\n"), | 2417 | _("UDP could not transmit message to `%s': " |
2682 | GNUNET_a2s (sa, slen)); | 2418 | "Network seems down, please check your network configuration\n"), |
2683 | } | 2419 | GNUNET_a2s (sa, slen)); |
2684 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) | 2420 | } |
2685 | { | 2421 | if ((network_down_error == GNUNET_NO) && (slen == sizeof (struct sockaddr_in6))) |
2686 | /* IPv6: "Network unreachable" or "Network down" | 2422 | { |
2687 | * | 2423 | /* IPv6: "Network unreachable" or "Network down" |
2688 | * This indicates that this system is IPv6 enabled, but does not | 2424 | * |
2689 | * have a valid global IPv6 address assigned or we do not have | 2425 | * This indicates that this system is IPv6 enabled, but does not |
2690 | * connectivity | 2426 | * have a valid global IPv6 address assigned or we do not have |
2691 | */ | 2427 | * connectivity |
2692 | 2428 | */ | |
2693 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2429 | |
2694 | _("UDP could not transmit IPv6 message! " | 2430 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2695 | "Please check your network configuration and disable IPv6 if your " | 2431 | _("UDP could not transmit IPv6 message! " |
2696 | "connection does not have a global IPv6 address\n")); | 2432 | "Please check your network configuration and disable IPv6 if your " |
2697 | } | 2433 | "connection does not have a global IPv6 address\n")); |
2698 | } | 2434 | } |
2699 | else | 2435 | } |
2700 | { | 2436 | else |
2701 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2437 | { |
2702 | "UDP could not transmit message to `%s': `%s'\n", | 2438 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2703 | GNUNET_a2s (sa, slen), STRERROR (error)); | 2439 | "UDP could not transmit message to `%s': `%s'\n", |
2704 | } | 2440 | GNUNET_a2s (sa, slen), STRERROR (error)); |
2705 | } | 2441 | } |
2706 | 2442 | } | |
2707 | 2443 | ||
2708 | static size_t | 2444 | static size_t |
2709 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | 2445 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) |
@@ -2715,53 +2451,51 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) | |||
2715 | struct UDP_MessageWrapper *udpw = NULL; | 2451 | struct UDP_MessageWrapper *udpw = NULL; |
2716 | 2452 | ||
2717 | /* Find message to send */ | 2453 | /* Find message to send */ |
2718 | udpw = remove_timeout_messages_and_select ((sock == plugin->sockv4) ? plugin->ipv4_queue_head : plugin->ipv6_queue_head, | 2454 | udpw = remove_timeout_messages_and_select ( |
2719 | sock); | 2455 | (sock == plugin->sockv4) ? |
2456 | plugin->ipv4_queue_head : plugin->ipv6_queue_head, sock); | ||
2720 | if (NULL == udpw) | 2457 | if (NULL == udpw) |
2721 | return 0; /* No message to send */ | 2458 | return 0; /* No message to send */ |
2722 | 2459 | ||
2723 | sa = udpw->session->sock_addr; | 2460 | sa = udpw->session->address->address; |
2724 | slen = udpw->session->addrlen; | 2461 | slen = udpw->session->address->address_length; |
2725 | 2462 | ||
2726 | sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, slen); | 2463 | sent = GNUNET_NETWORK_socket_sendto (sock, udpw->msg_buf, udpw->msg_size, sa, |
2464 | slen); | ||
2727 | 2465 | ||
2728 | if (GNUNET_SYSERR == sent) | 2466 | if (GNUNET_SYSERR == sent) |
2729 | { | 2467 | { |
2730 | /* Failure */ | 2468 | /* Failure */ |
2731 | analyze_send_error (plugin, sa, slen, errno); | 2469 | analyze_send_error (plugin, sa, slen, errno); |
2732 | call_continuation(udpw, GNUNET_SYSERR); | 2470 | call_continuation (udpw, GNUNET_SYSERR); |
2733 | GNUNET_STATISTICS_update (plugin->env->stats, | 2471 | GNUNET_STATISTICS_update (plugin->env->stats, |
2734 | "# UDP, total, bytes, sent, failure", | 2472 | "# UDP, total, bytes, sent, failure", sent, GNUNET_NO); |
2735 | sent, GNUNET_NO); | ||
2736 | GNUNET_STATISTICS_update (plugin->env->stats, | 2473 | GNUNET_STATISTICS_update (plugin->env->stats, |
2737 | "# UDP, total, messages, sent, failure", | 2474 | "# UDP, total, messages, sent, failure", 1, GNUNET_NO); |
2738 | 1, GNUNET_NO); | ||
2739 | } | 2475 | } |
2740 | else | 2476 | else |
2741 | { | 2477 | { |
2742 | /* Success */ | 2478 | /* Success */ |
2743 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2479 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2744 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", | 2480 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", |
2745 | (unsigned int) (udpw->msg_size), GNUNET_i2s(&udpw->session->target) ,GNUNET_a2s (sa, slen), (int) sent, | 2481 | (unsigned int ) (udpw->msg_size), GNUNET_i2s (&udpw->session->target), |
2746 | (sent < 0) ? STRERROR (errno) : "ok"); | 2482 | GNUNET_a2s (sa, slen), (int ) sent, |
2483 | (sent < 0) ? STRERROR (errno) : "ok"); | ||
2747 | GNUNET_STATISTICS_update (plugin->env->stats, | 2484 | GNUNET_STATISTICS_update (plugin->env->stats, |
2748 | "# UDP, total, bytes, sent, success", | 2485 | "# UDP, total, bytes, sent, success", sent, GNUNET_NO); |
2749 | sent, GNUNET_NO); | ||
2750 | GNUNET_STATISTICS_update (plugin->env->stats, | 2486 | GNUNET_STATISTICS_update (plugin->env->stats, |
2751 | "# UDP, total, messages, sent, success", | 2487 | "# UDP, total, messages, sent, success", 1, GNUNET_NO); |
2752 | 1, GNUNET_NO); | ||
2753 | if (NULL != udpw->frag_ctx) | 2488 | if (NULL != udpw->frag_ctx) |
2754 | udpw->frag_ctx->on_wire_size += udpw->msg_size; | 2489 | udpw->frag_ctx->on_wire_size += udpw->msg_size; |
2755 | call_continuation (udpw, GNUNET_OK); | 2490 | call_continuation (udpw, GNUNET_OK); |
2756 | } | 2491 | } |
2757 | dequeue (plugin, udpw); | 2492 | dequeue (plugin, udpw); |
2758 | GNUNET_free (udpw); | 2493 | GNUNET_free(udpw); |
2759 | udpw = NULL; | 2494 | udpw = NULL; |
2760 | 2495 | ||
2761 | return sent; | 2496 | return sent; |
2762 | } | 2497 | } |
2763 | 2498 | ||
2764 | |||
2765 | /** | 2499 | /** |
2766 | * We have been notified that our readset has something to read. We don't | 2500 | * We have been notified that our readset has something to read. We don't |
2767 | * know which socket needs to be read, so we have to check each one | 2501 | * know which socket needs to be read, so we have to check each one |
@@ -2778,19 +2512,17 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2778 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | 2512 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; |
2779 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 2513 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
2780 | return; | 2514 | return; |
2781 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && | 2515 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
2782 | (NULL != plugin->sockv4) && | 2516 | && (NULL != plugin->sockv4) |
2783 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)) ) | 2517 | && (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) |
2784 | udp_select_read (plugin, plugin->sockv4); | 2518 | udp_select_read (plugin, plugin->sockv4); |
2785 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && | 2519 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) |
2786 | (NULL != plugin->sockv4) && | 2520 | && (NULL != plugin->sockv4) && (NULL != plugin->ipv4_queue_head) |
2787 | (NULL != plugin->ipv4_queue_head) && | 2521 | && (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4))) |
2788 | (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv4)) ) | ||
2789 | udp_select_send (plugin, plugin->sockv4); | 2522 | udp_select_send (plugin, plugin->sockv4); |
2790 | schedule_select (plugin); | 2523 | schedule_select (plugin); |
2791 | } | 2524 | } |
2792 | 2525 | ||
2793 | |||
2794 | /** | 2526 | /** |
2795 | * We have been notified that our readset has something to read. We don't | 2527 | * We have been notified that our readset has something to read. We don't |
2796 | * know which socket needs to be read, so we have to check each one | 2528 | * know which socket needs to be read, so we have to check each one |
@@ -2807,26 +2539,23 @@ udp_plugin_select_v6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2807 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 2539 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
2808 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 2540 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
2809 | return; | 2541 | return; |
2810 | if ( ((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) && | 2542 | if (((tc->reason & GNUNET_SCHEDULER_REASON_READ_READY) != 0) |
2811 | (NULL != plugin->sockv6) && | 2543 | && (NULL != plugin->sockv6) |
2812 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)) ) | 2544 | && (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) |
2813 | udp_select_read (plugin, plugin->sockv6); | 2545 | udp_select_read (plugin, plugin->sockv6); |
2814 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) && | 2546 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) |
2815 | (NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL) && | 2547 | && (NULL != plugin->sockv6) && (plugin->ipv6_queue_head != NULL )&& |
2816 | (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)) ) | 2548 | (GNUNET_NETWORK_fdset_isset (tc->write_ready, plugin->sockv6)) )udp_select_send (plugin, plugin->sockv6); |
2817 | udp_select_send (plugin, plugin->sockv6); | ||
2818 | schedule_select (plugin); | 2549 | schedule_select (plugin); |
2819 | } | 2550 | } |
2820 | 2551 | ||
2821 | |||
2822 | /** | 2552 | /** |
2823 | * | 2553 | * |
2824 | * @return number of sockets that were successfully bound | 2554 | * @return number of sockets that were successfully bound |
2825 | */ | 2555 | */ |
2826 | static int | 2556 | static int |
2827 | setup_sockets (struct Plugin *plugin, | 2557 | setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, |
2828 | const struct sockaddr_in6 *bind_v6, | 2558 | const struct sockaddr_in *bind_v4) |
2829 | const struct sockaddr_in *bind_v4) | ||
2830 | { | 2559 | { |
2831 | int tries; | 2560 | int tries; |
2832 | int sockets_created = 0; | 2561 | int sockets_created = 0; |
@@ -2845,46 +2574,52 @@ setup_sockets (struct Plugin *plugin, | |||
2845 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | 2574 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); |
2846 | if (NULL == plugin->sockv6) | 2575 | if (NULL == plugin->sockv6) |
2847 | { | 2576 | { |
2848 | LOG (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv6 since it is not supported on this system!\n"); | 2577 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2578 | "Disabling IPv6 since it is not supported on this system!\n"); | ||
2849 | plugin->enable_ipv6 = GNUNET_NO; | 2579 | plugin->enable_ipv6 = GNUNET_NO; |
2850 | } | 2580 | } |
2851 | else | 2581 | else |
2852 | { | 2582 | { |
2853 | memset (&server_addrv6, '\0', sizeof (struct sockaddr_in6)); | 2583 | memset (&server_addrv6, '\0', sizeof(struct sockaddr_in6)); |
2854 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2584 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2855 | server_addrv6.sin6_len = sizeof (struct sockaddr_in6); | 2585 | server_addrv6.sin6_len = sizeof (struct sockaddr_in6); |
2856 | #endif | 2586 | #endif |
2857 | server_addrv6.sin6_family = AF_INET6; | 2587 | server_addrv6.sin6_family = AF_INET6; |
2858 | if (NULL != bind_v6) | 2588 | if (NULL != bind_v6) |
2859 | server_addrv6.sin6_addr = bind_v6->sin6_addr; | 2589 | server_addrv6.sin6_addr = bind_v6->sin6_addr; |
2860 | else | 2590 | else |
2861 | server_addrv6.sin6_addr = in6addr_any; | 2591 | server_addrv6.sin6_addr = in6addr_any; |
2862 | 2592 | ||
2863 | if (0 == plugin->port) /* autodetect */ | 2593 | if (0 == plugin->port) /* autodetect */ |
2864 | server_addrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2594 | server_addrv6.sin6_port = htons ( |
2595 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | ||
2596 | + 32000); | ||
2865 | else | 2597 | else |
2866 | server_addrv6.sin6_port = htons (plugin->port); | 2598 | server_addrv6.sin6_port = htons (plugin->port); |
2867 | addrlen = sizeof (struct sockaddr_in6); | 2599 | addrlen = sizeof(struct sockaddr_in6); |
2868 | server_addr = (struct sockaddr *) &server_addrv6; | 2600 | server_addr = (struct sockaddr *) &server_addrv6; |
2869 | 2601 | ||
2870 | tries = 0; | 2602 | tries = 0; |
2871 | while (tries < 10) | 2603 | while (tries < 10) |
2872 | { | 2604 | { |
2873 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 `%s'\n", | 2605 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv6 `%s'\n", |
2874 | GNUNET_a2s (server_addr, addrlen)); | 2606 | GNUNET_a2s (server_addr, addrlen)); |
2875 | /* binding */ | 2607 | /* binding */ |
2876 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6, | 2608 | if (GNUNET_OK |
2877 | server_addr, addrlen)) | 2609 | == GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, |
2878 | break; | 2610 | addrlen)) |
2879 | eno = errno; | 2611 | break; |
2880 | if (0 != plugin->port) | 2612 | eno = errno; |
2881 | { | 2613 | if (0 != plugin->port) |
2882 | tries = 10; /* fail */ | 2614 | { |
2883 | break; /* bind failed on specific port */ | 2615 | tries = 10; /* fail */ |
2884 | } | 2616 | break; /* bind failed on specific port */ |
2885 | /* autodetect */ | 2617 | } |
2886 | server_addrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2618 | /* autodetect */ |
2887 | tries ++; | 2619 | server_addrv6.sin6_port = htons ( |
2620 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | ||
2621 | + 32000); | ||
2622 | tries++; | ||
2888 | } | 2623 | } |
2889 | if (tries >= 10) | 2624 | if (tries >= 10) |
2890 | { | 2625 | { |
@@ -2893,21 +2628,18 @@ setup_sockets (struct Plugin *plugin, | |||
2893 | plugin->sockv6 = NULL; | 2628 | plugin->sockv6 = NULL; |
2894 | } | 2629 | } |
2895 | 2630 | ||
2896 | if (plugin->sockv6 != NULL) | 2631 | if (plugin->sockv6 != NULL ) |
2897 | { | 2632 | { |
2898 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2633 | LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv6 socket created on port %s\n", |
2899 | "IPv6 socket created on port %s\n", | 2634 | GNUNET_a2s (server_addr, addrlen)); |
2900 | GNUNET_a2s (server_addr, addrlen)); | ||
2901 | addrs[sockets_created] = (struct sockaddr *) &server_addrv6; | 2635 | addrs[sockets_created] = (struct sockaddr *) &server_addrv6; |
2902 | addrlens[sockets_created] = sizeof (struct sockaddr_in6); | 2636 | addrlens[sockets_created] = sizeof(struct sockaddr_in6); |
2903 | sockets_created++; | 2637 | sockets_created++; |
2904 | } | 2638 | } |
2905 | else | 2639 | else |
2906 | { | 2640 | { |
2907 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2641 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to bind UDP socket to %s: %s\n", |
2908 | "Failed to bind UDP socket to %s: %s\n", | 2642 | GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); |
2909 | GNUNET_a2s (server_addr, addrlen), | ||
2910 | STRERROR (eno)); | ||
2911 | } | 2643 | } |
2912 | } | 2644 | } |
2913 | } | 2645 | } |
@@ -2917,13 +2649,14 @@ setup_sockets (struct Plugin *plugin, | |||
2917 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); | 2649 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); |
2918 | if (NULL == plugin->sockv4) | 2650 | if (NULL == plugin->sockv4) |
2919 | { | 2651 | { |
2920 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | 2652 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket"); |
2921 | LOG (GNUNET_ERROR_TYPE_WARNING, "Disabling IPv4 since it is not supported on this system!\n"); | 2653 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2654 | "Disabling IPv4 since it is not supported on this system!\n"); | ||
2922 | plugin->enable_ipv4 = GNUNET_NO; | 2655 | plugin->enable_ipv4 = GNUNET_NO; |
2923 | } | 2656 | } |
2924 | else | 2657 | else |
2925 | { | 2658 | { |
2926 | memset (&server_addrv4, '\0', sizeof (struct sockaddr_in)); | 2659 | memset (&server_addrv4, '\0', sizeof(struct sockaddr_in)); |
2927 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2660 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2928 | server_addrv4.sin_len = sizeof (struct sockaddr_in); | 2661 | server_addrv4.sin_len = sizeof (struct sockaddr_in); |
2929 | #endif | 2662 | #endif |
@@ -2935,34 +2668,37 @@ setup_sockets (struct Plugin *plugin, | |||
2935 | 2668 | ||
2936 | if (0 == plugin->port) | 2669 | if (0 == plugin->port) |
2937 | /* autodetect */ | 2670 | /* autodetect */ |
2938 | server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2671 | server_addrv4.sin_port = htons ( |
2672 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) | ||
2673 | + 32000); | ||
2939 | else | 2674 | else |
2940 | server_addrv4.sin_port = htons (plugin->port); | 2675 | server_addrv4.sin_port = htons (plugin->port); |
2941 | 2676 | ||
2942 | 2677 | addrlen = sizeof(struct sockaddr_in); | |
2943 | addrlen = sizeof (struct sockaddr_in); | ||
2944 | server_addr = (struct sockaddr *) &server_addrv4; | 2678 | server_addr = (struct sockaddr *) &server_addrv4; |
2945 | 2679 | ||
2946 | tries = 0; | 2680 | tries = 0; |
2947 | while (tries < 10) | 2681 | while (tries < 10) |
2948 | { | 2682 | { |
2949 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", | 2683 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Binding to IPv4 `%s'\n", |
2950 | GNUNET_a2s (server_addr, addrlen)); | 2684 | GNUNET_a2s (server_addr, addrlen)); |
2951 | 2685 | ||
2952 | /* binding */ | 2686 | /* binding */ |
2953 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4, | 2687 | if (GNUNET_OK |
2954 | server_addr, addrlen)) | 2688 | == GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen)) |
2955 | break; | 2689 | break; |
2956 | eno = errno; | 2690 | eno = errno; |
2957 | if (0 != plugin->port) | 2691 | if (0 != plugin->port) |
2958 | { | 2692 | { |
2959 | tries = 10; /* fail */ | 2693 | tries = 10; /* fail */ |
2960 | break; /* bind failed on specific port */ | 2694 | break; /* bind failed on specific port */ |
2961 | } | 2695 | } |
2962 | 2696 | ||
2963 | /* autodetect */ | 2697 | /* autodetect */ |
2964 | server_addrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); | 2698 | server_addrv4.sin_port = htons ( |
2965 | tries ++; | 2699 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) |
2700 | + 32000); | ||
2701 | tries++; | ||
2966 | } | 2702 | } |
2967 | 2703 | ||
2968 | if (tries >= 10) | 2704 | if (tries >= 10) |
@@ -2972,40 +2708,39 @@ setup_sockets (struct Plugin *plugin, | |||
2972 | plugin->sockv4 = NULL; | 2708 | plugin->sockv4 = NULL; |
2973 | } | 2709 | } |
2974 | 2710 | ||
2975 | if (plugin->sockv4 != NULL) | 2711 | if (plugin->sockv4 != NULL ) |
2976 | { | 2712 | { |
2977 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2713 | LOG(GNUNET_ERROR_TYPE_DEBUG, "IPv4 socket created on port %s\n", |
2978 | "IPv4 socket created on port %s\n", GNUNET_a2s (server_addr, addrlen)); | 2714 | GNUNET_a2s (server_addr, addrlen)); |
2979 | addrs[sockets_created] = (struct sockaddr *) &server_addrv4; | 2715 | addrs[sockets_created] = (struct sockaddr *) &server_addrv4; |
2980 | addrlens[sockets_created] = sizeof (struct sockaddr_in); | 2716 | addrlens[sockets_created] = sizeof(struct sockaddr_in); |
2981 | sockets_created++; | 2717 | sockets_created++; |
2982 | } | 2718 | } |
2983 | else | 2719 | else |
2984 | { | 2720 | { |
2985 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2721 | LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to bind UDP socket to %s: %s\n", |
2986 | "Failed to bind UDP socket to %s: %s\n", | 2722 | GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); |
2987 | GNUNET_a2s (server_addr, addrlen), STRERROR (eno)); | ||
2988 | } | 2723 | } |
2989 | } | 2724 | } |
2990 | 2725 | ||
2991 | if (0 == sockets_created) | 2726 | if (0 == sockets_created) |
2992 | { | 2727 | { |
2993 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); | 2728 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); |
2994 | return 0; /* No sockets created, return */ | 2729 | return 0; /* No sockets created, return */ |
2995 | } | 2730 | } |
2996 | 2731 | ||
2997 | /* Create file descriptors */ | 2732 | /* Create file descriptors */ |
2998 | if (plugin->enable_ipv4 == GNUNET_YES) | 2733 | if (plugin->enable_ipv4 == GNUNET_YES) |
2999 | { | 2734 | { |
3000 | plugin->rs_v4 = GNUNET_NETWORK_fdset_create (); | 2735 | plugin->rs_v4 = GNUNET_NETWORK_fdset_create (); |
3001 | plugin->ws_v4 = GNUNET_NETWORK_fdset_create (); | 2736 | plugin->ws_v4 = GNUNET_NETWORK_fdset_create (); |
3002 | GNUNET_NETWORK_fdset_zero (plugin->rs_v4); | 2737 | GNUNET_NETWORK_fdset_zero (plugin->rs_v4); |
3003 | GNUNET_NETWORK_fdset_zero (plugin->ws_v4); | 2738 | GNUNET_NETWORK_fdset_zero (plugin->ws_v4); |
3004 | if (NULL != plugin->sockv4) | 2739 | if (NULL != plugin->sockv4) |
3005 | { | 2740 | { |
3006 | GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4); | 2741 | GNUNET_NETWORK_fdset_set (plugin->rs_v4, plugin->sockv4); |
3007 | GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4); | 2742 | GNUNET_NETWORK_fdset_set (plugin->ws_v4, plugin->sockv4); |
3008 | } | 2743 | } |
3009 | } | 2744 | } |
3010 | 2745 | ||
3011 | if (plugin->enable_ipv6 == GNUNET_YES) | 2746 | if (plugin->enable_ipv6 == GNUNET_YES) |
@@ -3022,16 +2757,13 @@ setup_sockets (struct Plugin *plugin, | |||
3022 | } | 2757 | } |
3023 | 2758 | ||
3024 | schedule_select (plugin); | 2759 | schedule_select (plugin); |
3025 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 2760 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, GNUNET_NO, plugin->port, |
3026 | GNUNET_NO, plugin->port, | 2761 | sockets_created, (const struct sockaddr **) addrs, addrlens, |
3027 | sockets_created, | 2762 | &udp_nat_port_map_callback, NULL, plugin); |
3028 | (const struct sockaddr **) addrs, addrlens, | ||
3029 | &udp_nat_port_map_callback, NULL, plugin); | ||
3030 | 2763 | ||
3031 | return sockets_created; | 2764 | return sockets_created; |
3032 | } | 2765 | } |
3033 | 2766 | ||
3034 | |||
3035 | /** | 2767 | /** |
3036 | * The exported method. Makes the core api available via a global and | 2768 | * The exported method. Makes the core api available via a global and |
3037 | * returns the udp transport API. | 2769 | * returns the udp transport API. |
@@ -3064,7 +2796,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3064 | if (NULL == env->receive) | 2796 | if (NULL == env->receive) |
3065 | { | 2797 | { |
3066 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 2798 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
3067 | initialze the plugin or the API */ | 2799 | initialze the plugin or the API */ |
3068 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2800 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3069 | api->cls = NULL; | 2801 | api->cls = NULL; |
3070 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; | 2802 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; |
@@ -3073,106 +2805,105 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3073 | return api; | 2805 | return api; |
3074 | } | 2806 | } |
3075 | 2807 | ||
3076 | GNUNET_assert (NULL != env->stats); | 2808 | GNUNET_assert(NULL != env->stats); |
3077 | 2809 | ||
3078 | /* Get port number: port == 0 : autodetect a port, | 2810 | /* Get port number: port == 0 : autodetect a port, |
3079 | * > 0 : use this port, not given : 2086 default */ | 2811 | * > 0 : use this port, not given : 2086 default */ |
3080 | if (GNUNET_OK != | 2812 | if (GNUNET_OK |
3081 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", | 2813 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
3082 | &port)) | 2814 | "PORT", &port)) |
3083 | port = 2086; | 2815 | port = 2086; |
3084 | if (GNUNET_OK != | 2816 | if (GNUNET_OK |
3085 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 2817 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
3086 | "ADVERTISED_PORT", &aport)) | 2818 | "ADVERTISED_PORT", &aport)) |
3087 | aport = port; | 2819 | aport = port; |
3088 | if (port > 65535) | 2820 | if (port > 65535) |
3089 | { | 2821 | { |
3090 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2822 | LOG(GNUNET_ERROR_TYPE_WARNING, |
3091 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, | 2823 | _("Given `%s' option is out of range: %llu > %u\n"), "PORT", port, |
3092 | 65535); | 2824 | 65535); |
3093 | return NULL; | 2825 | return NULL ; |
3094 | } | 2826 | } |
3095 | 2827 | ||
3096 | /* Protocols */ | 2828 | /* Protocols */ |
3097 | if ((GNUNET_YES == | 2829 | if ((GNUNET_YES |
3098 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", | 2830 | == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6"))) |
3099 | "DISABLEV6"))) | ||
3100 | enable_v6 = GNUNET_NO; | 2831 | enable_v6 = GNUNET_NO; |
3101 | else | 2832 | else |
3102 | enable_v6 = GNUNET_YES; | 2833 | enable_v6 = GNUNET_YES; |
3103 | 2834 | ||
3104 | /* Addresses */ | 2835 | /* Addresses */ |
3105 | have_bind4 = GNUNET_NO; | 2836 | have_bind4 = GNUNET_NO; |
3106 | memset (&server_addrv4, 0, sizeof (server_addrv4)); | 2837 | memset (&server_addrv4, 0, sizeof(server_addrv4)); |
3107 | if (GNUNET_YES == | 2838 | if (GNUNET_YES |
3108 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 2839 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
3109 | "BINDTO", &bind4_address)) | 2840 | "BINDTO", &bind4_address)) |
3110 | { | 2841 | { |
3111 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2842 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3112 | "Binding udp plugin to specific address: `%s'\n", | 2843 | "Binding udp plugin to specific address: `%s'\n", bind4_address); |
3113 | bind4_address); | ||
3114 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) | 2844 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) |
3115 | { | 2845 | { |
3116 | GNUNET_free (bind4_address); | 2846 | GNUNET_free(bind4_address); |
3117 | return NULL; | 2847 | return NULL ; |
3118 | } | 2848 | } |
3119 | have_bind4 = GNUNET_YES; | 2849 | have_bind4 = GNUNET_YES; |
3120 | } | 2850 | } |
3121 | GNUNET_free_non_null (bind4_address); | 2851 | GNUNET_free_non_null(bind4_address); |
3122 | have_bind6 = GNUNET_NO; | 2852 | have_bind6 = GNUNET_NO; |
3123 | memset (&server_addrv6, 0, sizeof (server_addrv6)); | 2853 | memset (&server_addrv6, 0, sizeof(server_addrv6)); |
3124 | if (GNUNET_YES == | 2854 | if (GNUNET_YES |
3125 | GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 2855 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
3126 | "BINDTO6", &bind6_address)) | 2856 | "BINDTO6", &bind6_address)) |
3127 | { | 2857 | { |
3128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2858 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
3129 | "Binding udp plugin to specific address: `%s'\n", | 2859 | "Binding udp plugin to specific address: `%s'\n", bind6_address); |
3130 | bind6_address); | 2860 | if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) |
3131 | if (1 != | ||
3132 | inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) | ||
3133 | { | 2861 | { |
3134 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), | 2862 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid IPv6 address: `%s'\n"), |
3135 | bind6_address); | 2863 | bind6_address); |
3136 | GNUNET_free (bind6_address); | 2864 | GNUNET_free(bind6_address); |
3137 | return NULL; | 2865 | return NULL ; |
3138 | } | 2866 | } |
3139 | have_bind6 = GNUNET_YES; | 2867 | have_bind6 = GNUNET_YES; |
3140 | } | 2868 | } |
3141 | GNUNET_free_non_null (bind6_address); | 2869 | GNUNET_free_non_null(bind6_address); |
3142 | 2870 | ||
3143 | /* Initialize my flags */ | 2871 | /* Initialize my flags */ |
3144 | myoptions = 0; | 2872 | myoptions = 0; |
3145 | 2873 | ||
3146 | /* Enable neighbour discovery */ | 2874 | /* Enable neighbour discovery */ |
3147 | enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", | 2875 | enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3148 | "BROADCAST"); | 2876 | "transport-udp", "BROADCAST"); |
3149 | if (enable_broadcasting == GNUNET_SYSERR) | 2877 | if (enable_broadcasting == GNUNET_SYSERR) |
3150 | enable_broadcasting = GNUNET_NO; | 2878 | enable_broadcasting = GNUNET_NO; |
3151 | 2879 | ||
3152 | enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "transport-udp", | 2880 | enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3153 | "BROADCAST_RECEIVE"); | 2881 | "transport-udp", "BROADCAST_RECEIVE"); |
3154 | if (enable_broadcasting_recv == GNUNET_SYSERR) | 2882 | if (enable_broadcasting_recv == GNUNET_SYSERR) |
3155 | enable_broadcasting_recv = GNUNET_YES; | 2883 | enable_broadcasting_recv = GNUNET_YES; |
3156 | 2884 | ||
3157 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", | 2885 | if (GNUNET_SYSERR |
3158 | "BROADCAST_INTERVAL", &fancy_interval)) | 2886 | == GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-udp", |
2887 | "BROADCAST_INTERVAL", &fancy_interval)) | ||
3159 | { | 2888 | { |
3160 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2889 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
3161 | } | 2890 | } |
3162 | else | 2891 | else |
3163 | { | 2892 | { |
3164 | if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_time_to_relative(fancy_interval, &interval)) | 2893 | if (GNUNET_SYSERR |
3165 | { | 2894 | == GNUNET_STRINGS_fancy_time_to_relative (fancy_interval, &interval)) |
3166 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 2895 | { |
3167 | } | 2896 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
3168 | GNUNET_free (fancy_interval); | 2897 | } |
2898 | GNUNET_free(fancy_interval); | ||
3169 | } | 2899 | } |
3170 | 2900 | ||
3171 | /* Maximum datarate */ | 2901 | /* Maximum datarate */ |
3172 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 2902 | if (GNUNET_OK |
3173 | "MAX_BPS", &udp_max_bps)) | 2903 | != GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
2904 | "MAX_BPS", &udp_max_bps)) | ||
3174 | { | 2905 | { |
3175 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | 2906 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
3176 | } | 2907 | } |
3177 | 2908 | ||
3178 | p = GNUNET_new (struct Plugin); | 2909 | p = GNUNET_new (struct Plugin); |
@@ -3185,7 +2916,8 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3185 | p->enable_broadcasting_receiving = enable_broadcasting_recv; | 2916 | p->enable_broadcasting_receiving = enable_broadcasting_recv; |
3186 | p->env = env; | 2917 | p->env = env; |
3187 | p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 2918 | p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
3188 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2919 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create ( |
2920 | GNUNET_CONTAINER_HEAP_ORDER_MIN); | ||
3189 | p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); | 2921 | p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); |
3190 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, | 2922 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, |
3191 | GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); | 2923 | GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); |
@@ -3197,7 +2929,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3197 | if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) | 2929 | if ((res == 0) || ((p->sockv4 == NULL )&& (p->sockv6 == NULL))) |
3198 | { | 2930 | { |
3199 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2931 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3200 | _("Failed to create network sockets, plugin failed\n")); | 2932 | _("Failed to create network sockets, plugin failed\n")); |
3201 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); | 2933 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); |
3202 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); | 2934 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); |
3203 | GNUNET_SERVER_mst_destroy (p->mst); | 2935 | GNUNET_SERVER_mst_destroy (p->mst); |
@@ -3225,23 +2957,19 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3225 | return api; | 2957 | return api; |
3226 | } | 2958 | } |
3227 | 2959 | ||
3228 | |||
3229 | static int | 2960 | static int |
3230 | heap_cleanup_iterator (void *cls, | 2961 | heap_cleanup_iterator (void *cls, struct GNUNET_CONTAINER_HeapNode *node, |
3231 | struct GNUNET_CONTAINER_HeapNode *node, | 2962 | void *element, GNUNET_CONTAINER_HeapCostType cost) |
3232 | void *element, | ||
3233 | GNUNET_CONTAINER_HeapCostType cost) | ||
3234 | { | 2963 | { |
3235 | struct DefragContext * d_ctx = element; | 2964 | struct DefragContext * d_ctx = element; |
3236 | 2965 | ||
3237 | GNUNET_CONTAINER_heap_remove_node (node); | 2966 | GNUNET_CONTAINER_heap_remove_node (node); |
3238 | GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag); | 2967 | GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); |
3239 | GNUNET_free (d_ctx); | 2968 | GNUNET_free(d_ctx); |
3240 | 2969 | ||
3241 | return GNUNET_YES; | 2970 | return GNUNET_YES; |
3242 | } | 2971 | } |
3243 | 2972 | ||
3244 | |||
3245 | /** | 2973 | /** |
3246 | * The exported method. Makes the core api available via a global and | 2974 | * The exported method. Makes the core api available via a global and |
3247 | * returns the udp transport API. | 2975 | * returns the udp transport API. |
@@ -3259,17 +2987,17 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3259 | 2987 | ||
3260 | if (NULL == plugin) | 2988 | if (NULL == plugin) |
3261 | { | 2989 | { |
3262 | GNUNET_free (api); | 2990 | GNUNET_free(api); |
3263 | return NULL; | 2991 | return NULL ; |
3264 | } | 2992 | } |
3265 | 2993 | ||
3266 | stop_broadcast (plugin); | 2994 | stop_broadcast (plugin); |
3267 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) | 2995 | if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK ) |
3268 | { | 2996 | { |
3269 | GNUNET_SCHEDULER_cancel (plugin->select_task); | 2997 | GNUNET_SCHEDULER_cancel (plugin->select_task); |
3270 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; | 2998 | plugin->select_task = GNUNET_SCHEDULER_NO_TASK; |
3271 | } | 2999 | } |
3272 | if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK) | 3000 | if (plugin->select_task_v6 != GNUNET_SCHEDULER_NO_TASK ) |
3273 | { | 3001 | { |
3274 | GNUNET_SCHEDULER_cancel (plugin->select_task_v6); | 3002 | GNUNET_SCHEDULER_cancel (plugin->select_task_v6); |
3275 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 3003 | plugin->select_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
@@ -3280,7 +3008,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3280 | { | 3008 | { |
3281 | if (NULL != plugin->sockv4) | 3009 | if (NULL != plugin->sockv4) |
3282 | { | 3010 | { |
3283 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); | 3011 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); |
3284 | plugin->sockv4 = NULL; | 3012 | plugin->sockv4 = NULL; |
3285 | } | 3013 | } |
3286 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); | 3014 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); |
@@ -3290,7 +3018,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3290 | { | 3018 | { |
3291 | if (NULL != plugin->sockv6) | 3019 | if (NULL != plugin->sockv6) |
3292 | { | 3020 | { |
3293 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); | 3021 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); |
3294 | plugin->sockv6 = NULL; | 3022 | plugin->sockv6 = NULL; |
3295 | 3023 | ||
3296 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); | 3024 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); |
@@ -3304,60 +3032,60 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3304 | } | 3032 | } |
3305 | if (NULL != plugin->defrag_ctxs) | 3033 | if (NULL != plugin->defrag_ctxs) |
3306 | { | 3034 | { |
3307 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, | 3035 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, heap_cleanup_iterator, |
3308 | heap_cleanup_iterator, NULL); | 3036 | NULL ); |
3309 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); | 3037 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); |
3310 | plugin->defrag_ctxs = NULL; | 3038 | plugin->defrag_ctxs = NULL; |
3311 | } | 3039 | } |
3312 | if (plugin->mst != NULL) | 3040 | if (plugin->mst != NULL ) |
3313 | { | 3041 | { |
3314 | GNUNET_SERVER_mst_destroy(plugin->mst); | 3042 | GNUNET_SERVER_mst_destroy (plugin->mst); |
3315 | plugin->mst = NULL; | 3043 | plugin->mst = NULL; |
3316 | } | 3044 | } |
3317 | 3045 | ||
3318 | /* Clean up leftover messages */ | 3046 | /* Clean up leftover messages */ |
3319 | struct UDP_MessageWrapper * udpw; | 3047 | struct UDP_MessageWrapper * udpw; |
3320 | udpw = plugin->ipv4_queue_head; | 3048 | udpw = plugin->ipv4_queue_head; |
3321 | while (udpw != NULL) | 3049 | while (udpw != NULL ) |
3322 | { | 3050 | { |
3323 | struct UDP_MessageWrapper *tmp = udpw->next; | 3051 | struct UDP_MessageWrapper *tmp = udpw->next; |
3324 | dequeue (plugin, udpw); | 3052 | dequeue (plugin, udpw); |
3325 | call_continuation(udpw, GNUNET_SYSERR); | 3053 | call_continuation (udpw, GNUNET_SYSERR); |
3326 | GNUNET_free (udpw); | 3054 | GNUNET_free(udpw); |
3327 | 3055 | ||
3328 | udpw = tmp; | 3056 | udpw = tmp; |
3329 | } | 3057 | } |
3330 | udpw = plugin->ipv6_queue_head; | 3058 | udpw = plugin->ipv6_queue_head; |
3331 | while (udpw != NULL) | 3059 | while (udpw != NULL ) |
3332 | { | 3060 | { |
3333 | struct UDP_MessageWrapper *tmp = udpw->next; | 3061 | struct UDP_MessageWrapper *tmp = udpw->next; |
3334 | dequeue (plugin, udpw); | 3062 | dequeue (plugin, udpw); |
3335 | call_continuation(udpw, GNUNET_SYSERR); | 3063 | call_continuation (udpw, GNUNET_SYSERR); |
3336 | GNUNET_free (udpw); | 3064 | GNUNET_free(udpw); |
3337 | 3065 | ||
3338 | udpw = tmp; | 3066 | udpw = tmp; |
3339 | } | 3067 | } |
3340 | 3068 | ||
3341 | /* Clean up sessions */ | 3069 | /* Clean up sessions */ |
3342 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3070 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up sessions\n"); |
3343 | "Cleaning up sessions\n"); | 3071 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, |
3344 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, &disconnect_and_free_it, plugin); | 3072 | &disconnect_and_free_it, plugin); |
3345 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); | 3073 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); |
3346 | 3074 | ||
3347 | next = ppc_dll_head; | 3075 | next = ppc_dll_head; |
3348 | for (cur = next; NULL != cur; cur = next) | 3076 | for (cur = next; NULL != cur; cur = next) |
3349 | { | 3077 | { |
3350 | next = cur->next; | 3078 | next = cur->next; |
3351 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); | 3079 | GNUNET_CONTAINER_DLL_remove(ppc_dll_head, ppc_dll_tail, cur); |
3352 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | 3080 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
3353 | GNUNET_SCHEDULER_cancel (cur->timeout_task); | 3081 | GNUNET_SCHEDULER_cancel (cur->timeout_task); |
3354 | GNUNET_free (cur); | 3082 | GNUNET_free(cur); |
3355 | GNUNET_break (0); | 3083 | GNUNET_break(0); |
3356 | } | 3084 | } |
3357 | 3085 | ||
3358 | plugin->nat = NULL; | 3086 | plugin->nat = NULL; |
3359 | GNUNET_free (plugin); | 3087 | GNUNET_free(plugin); |
3360 | GNUNET_free (api); | 3088 | GNUNET_free(api); |
3361 | #if DEBUG_MALLOC | 3089 | #if DEBUG_MALLOC |
3362 | struct Allocation *allocation; | 3090 | struct Allocation *allocation; |
3363 | while (NULL != ahead) | 3091 | while (NULL != ahead) |
@@ -3374,8 +3102,7 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3374 | GNUNET_free (allocator); | 3102 | GNUNET_free (allocator); |
3375 | } | 3103 | } |
3376 | #endif | 3104 | #endif |
3377 | return NULL; | 3105 | return NULL ; |
3378 | } | 3106 | } |
3379 | 3107 | ||
3380 | |||
3381 | /* end of plugin_transport_udp.c */ | 3108 | /* end of plugin_transport_udp.c */ |
diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h index 8f78ed4bc..1994fa5e2 100644 --- a/src/transport/plugin_transport_udp.h +++ b/src/transport/plugin_transport_udp.h | |||
@@ -41,6 +41,8 @@ | |||
41 | 41 | ||
42 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) | 42 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) |
43 | 43 | ||
44 | #define PLUGIN_NAME "udp" | ||
45 | |||
44 | #define DEBUG_UDP GNUNET_NO | 46 | #define DEBUG_UDP GNUNET_NO |
45 | #define DEBUG_UDP_BROADCASTING GNUNET_NO | 47 | #define DEBUG_UDP_BROADCASTING GNUNET_NO |
46 | 48 | ||
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index c17a3ccff..669ebdb01 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c | |||
@@ -135,6 +135,7 @@ broadcast_ipv6_mst_cb (void *cls, void *client, | |||
135 | { | 135 | { |
136 | struct Plugin *plugin = cls; | 136 | struct Plugin *plugin = cls; |
137 | struct Mstv6Context *mc = client; | 137 | struct Mstv6Context *mc = client; |
138 | struct GNUNET_HELLO_Address *address; | ||
138 | const struct GNUNET_MessageHeader *hello; | 139 | const struct GNUNET_MessageHeader *hello; |
139 | const struct UDP_Beacon_Message *msg; | 140 | const struct UDP_Beacon_Message *msg; |
140 | struct GNUNET_ATS_Information atsi; | 141 | struct GNUNET_ATS_Information atsi; |
@@ -155,19 +156,12 @@ broadcast_ipv6_mst_cb (void *cls, void *client, | |||
155 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); | 156 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); |
156 | 157 | ||
157 | hello = (struct GNUNET_MessageHeader *) &msg[1]; | 158 | hello = (struct GNUNET_MessageHeader *) &msg[1]; |
158 | plugin->env->receive (plugin->env->cls, | 159 | address = GNUNET_HELLO_address_allocate (&msg->sender, PLUGIN_NAME, |
159 | &msg->sender, | 160 | (const char *) &mc->addr, sizeof (mc->addr), GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
160 | hello, | 161 | plugin->env->receive (plugin->env->cls, address, NULL, hello); |
161 | NULL, | 162 | plugin->env->update_address_metrics (plugin->env->cls, address, |
162 | (const char *) &mc->addr, | 163 | NULL, &atsi, 1); |
163 | sizeof (mc->addr)); | 164 | GNUNET_HELLO_address_free (address); |
164 | plugin->env->update_address_metrics (plugin->env->cls, | ||
165 | &msg->sender, | ||
166 | (const char *) &mc->addr, | ||
167 | sizeof (mc->addr), | ||
168 | NULL, | ||
169 | &atsi, 1); | ||
170 | |||
171 | GNUNET_STATISTICS_update (plugin->env->stats, | 165 | GNUNET_STATISTICS_update (plugin->env->stats, |
172 | _ | 166 | _ |
173 | ("# IPv6 multicast HELLO beacons received via udp"), | 167 | ("# IPv6 multicast HELLO beacons received via udp"), |
@@ -183,6 +177,7 @@ broadcast_ipv4_mst_cb (void *cls, void *client, | |||
183 | { | 177 | { |
184 | struct Plugin *plugin = cls; | 178 | struct Plugin *plugin = cls; |
185 | struct Mstv4Context *mc = client; | 179 | struct Mstv4Context *mc = client; |
180 | struct GNUNET_HELLO_Address *address; | ||
186 | const struct GNUNET_MessageHeader *hello; | 181 | const struct GNUNET_MessageHeader *hello; |
187 | const struct UDP_Beacon_Message *msg; | 182 | const struct UDP_Beacon_Message *msg; |
188 | struct GNUNET_ATS_Information atsi; | 183 | struct GNUNET_ATS_Information atsi; |
@@ -204,19 +199,12 @@ broadcast_ipv4_mst_cb (void *cls, void *client, | |||
204 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); | 199 | GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED); |
205 | 200 | ||
206 | hello = (struct GNUNET_MessageHeader *) &msg[1]; | 201 | hello = (struct GNUNET_MessageHeader *) &msg[1]; |
207 | plugin->env->receive (plugin->env->cls, | 202 | address = GNUNET_HELLO_address_allocate (&msg->sender, PLUGIN_NAME, |
208 | &msg->sender, | 203 | (const char *) &mc->addr, sizeof (mc->addr), GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
209 | hello, | 204 | plugin->env->receive (plugin->env->cls, address, NULL, hello); |
210 | NULL, | 205 | plugin->env->update_address_metrics (plugin->env->cls, address, |
211 | (const char *) &mc->addr, | 206 | NULL, &atsi, 1); |
212 | sizeof (mc->addr)); | 207 | GNUNET_HELLO_address_free (address); |
213 | |||
214 | plugin->env->update_address_metrics (plugin->env->cls, | ||
215 | &msg->sender, | ||
216 | (const char *) &mc->addr, | ||
217 | sizeof (mc->addr), | ||
218 | NULL, | ||
219 | &atsi, 1); | ||
220 | 208 | ||
221 | GNUNET_STATISTICS_update (plugin->env->stats, | 209 | GNUNET_STATISTICS_update (plugin->env->stats, |
222 | _("# IPv4 broadcast HELLO beacons received via udp"), | 210 | _("# IPv4 broadcast HELLO beacons received via udp"), |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 3a2fa6516..384787ae9 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -103,11 +103,7 @@ struct Session | |||
103 | 103 | ||
104 | struct Plugin * plugin; | 104 | struct Plugin * plugin; |
105 | 105 | ||
106 | struct UnixAddress *addr; | 106 | struct GNUNET_HELLO_Address *address; |
107 | |||
108 | size_t addrlen; | ||
109 | |||
110 | int inbound; | ||
111 | 107 | ||
112 | /** | 108 | /** |
113 | * Session timeout task | 109 | * Session timeout task |
@@ -468,17 +464,9 @@ struct LookupCtx | |||
468 | /** | 464 | /** |
469 | * Location to store the session, if found. | 465 | * Location to store the session, if found. |
470 | */ | 466 | */ |
471 | struct Session *s; | 467 | struct Session *res; |
472 | |||
473 | /** | ||
474 | * Address we are looking for. | ||
475 | */ | ||
476 | const struct UnixAddress *ua; | ||
477 | 468 | ||
478 | /** | 469 | struct GNUNET_HELLO_Address *address; |
479 | * Number of bytes in @e ua | ||
480 | */ | ||
481 | size_t ua_len; | ||
482 | }; | 470 | }; |
483 | 471 | ||
484 | 472 | ||
@@ -496,20 +484,13 @@ lookup_session_it (void *cls, | |||
496 | void *value) | 484 | void *value) |
497 | { | 485 | { |
498 | struct LookupCtx *lctx = cls; | 486 | struct LookupCtx *lctx = cls; |
499 | struct Session *t = value; | 487 | struct Session *s = value; |
500 | |||
501 | if (t->addrlen != lctx->ua_len) | ||
502 | { | ||
503 | GNUNET_break (0); | ||
504 | return GNUNET_YES; | ||
505 | } | ||
506 | 488 | ||
507 | if (0 == memcmp (t->addr, lctx->ua, lctx->ua_len)) | 489 | if (0 == GNUNET_HELLO_address_cmp (lctx->address, s->address)) |
508 | { | 490 | { |
509 | lctx->s = t; | 491 | lctx->res = s; |
510 | return GNUNET_NO; | 492 | return GNUNET_NO; |
511 | } | 493 | } |
512 | GNUNET_break (0); | ||
513 | return GNUNET_YES; | 494 | return GNUNET_YES; |
514 | } | 495 | } |
515 | 496 | ||
@@ -525,18 +506,16 @@ lookup_session_it (void *cls, | |||
525 | */ | 506 | */ |
526 | static struct Session * | 507 | static struct Session * |
527 | lookup_session (struct Plugin *plugin, | 508 | lookup_session (struct Plugin *plugin, |
528 | const struct GNUNET_PeerIdentity *sender, | 509 | struct GNUNET_HELLO_Address *address) |
529 | const struct UnixAddress *ua, size_t ua_len) | ||
530 | { | 510 | { |
531 | struct LookupCtx lctx; | 511 | struct LookupCtx lctx; |
532 | 512 | ||
533 | lctx.s = NULL; | 513 | lctx.address = address; |
534 | lctx.ua = ua; | 514 | lctx.res = NULL; |
535 | lctx.ua_len = ua_len; | ||
536 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 515 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, |
537 | sender, | 516 | &address->peer, |
538 | &lookup_session_it, &lctx); | 517 | &lookup_session_it, &lctx); |
539 | return lctx.s; | 518 | return lctx.res; |
540 | } | 519 | } |
541 | 520 | ||
542 | 521 | ||
@@ -561,7 +540,7 @@ unix_session_disconnect (void *cls, | |||
561 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 540 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
562 | "Disconnecting session for peer `%s' `%s'\n", | 541 | "Disconnecting session for peer `%s' `%s'\n", |
563 | GNUNET_i2s (&s->target), | 542 | GNUNET_i2s (&s->target), |
564 | s->addr); | 543 | unix_address_to_string (NULL, s->address->address, s->address->address_length) ); |
565 | plugin->env->session_end (plugin->env->cls, &s->target, s); | 544 | plugin->env->session_end (plugin->env->cls, &s->target, s); |
566 | removed = GNUNET_NO; | 545 | removed = GNUNET_NO; |
567 | next = plugin->msg_head; | 546 | next = plugin->msg_head; |
@@ -594,6 +573,7 @@ unix_session_disconnect (void *cls, | |||
594 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 573 | GNUNET_SCHEDULER_cancel (s->timeout_task); |
595 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 574 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
596 | } | 575 | } |
576 | GNUNET_HELLO_address_free (s->address); | ||
597 | GNUNET_free (s); | 577 | GNUNET_free (s); |
598 | return GNUNET_OK; | 578 | return GNUNET_OK; |
599 | } | 579 | } |
@@ -746,12 +726,7 @@ struct GetSessionIteratorContext | |||
746 | /** | 726 | /** |
747 | * Address information. | 727 | * Address information. |
748 | */ | 728 | */ |
749 | const char *address; | 729 | const struct GNUNET_HELLO_Address *address; |
750 | |||
751 | /** | ||
752 | * Number of bytes in @e address | ||
753 | */ | ||
754 | size_t addrlen; | ||
755 | }; | 730 | }; |
756 | 731 | ||
757 | 732 | ||
@@ -771,8 +746,7 @@ get_session_it (void *cls, | |||
771 | struct GetSessionIteratorContext *gsi = cls; | 746 | struct GetSessionIteratorContext *gsi = cls; |
772 | struct Session *s = value; | 747 | struct Session *s = value; |
773 | 748 | ||
774 | if ((GNUNET_NO == s->inbound) && (gsi->addrlen == s->addrlen) && | 749 | if (0 == GNUNET_HELLO_address_cmp(s->address, gsi->address)) |
775 | (0 == memcmp (gsi->address, s->addr, s->addrlen)) ) | ||
776 | { | 750 | { |
777 | gsi->res = s; | 751 | gsi->res = s; |
778 | return GNUNET_NO; | 752 | return GNUNET_NO; |
@@ -868,27 +842,23 @@ unix_plugin_get_session (void *cls, | |||
868 | } | 842 | } |
869 | 843 | ||
870 | /* Check if already existing */ | 844 | /* Check if already existing */ |
871 | gsi.address = (const char *) address->address; | 845 | gsi.address = address; |
872 | gsi.addrlen = address->address_length; | ||
873 | gsi.res = NULL; | 846 | gsi.res = NULL; |
874 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 847 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, |
875 | &address->peer, | 848 | &address->peer, |
876 | &get_session_it, &gsi); | 849 | &get_session_it, &gsi); |
877 | if (NULL != gsi.res) | 850 | if (NULL != gsi.res) |
878 | { | 851 | { |
879 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 852 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n", |
880 | "Found existing session\n"); | 853 | gsi.res, |
854 | unix_address_to_string (NULL, address->address, address->address_length)); | ||
881 | return gsi.res; | 855 | return gsi.res; |
882 | } | 856 | } |
883 | 857 | ||
884 | /* create a new session */ | 858 | /* create a new session */ |
885 | s = GNUNET_malloc (sizeof (struct Session) + address->address_length); | 859 | s = GNUNET_new (struct Session); |
886 | s->addr = (struct UnixAddress *) &s[1]; | 860 | s->target = address->peer; |
887 | s->addrlen = address->address_length; | 861 | s->address = GNUNET_HELLO_address_copy (address); |
888 | s->plugin = plugin; | ||
889 | s->inbound = GNUNET_NO; | ||
890 | memcpy (s->addr, address->address, address->address_length); | ||
891 | memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); | ||
892 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); | 862 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); |
893 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 863 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
894 | &session_timeout, | 864 | &session_timeout, |
@@ -918,7 +888,6 @@ unix_plugin_update_session_timeout (void *cls, | |||
918 | &session->target, | 888 | &session->target, |
919 | session)) | 889 | session)) |
920 | return; | 890 | return; |
921 | |||
922 | reschedule_session_timeout (session); | 891 | reschedule_session_timeout (session); |
923 | } | 892 | } |
924 | 893 | ||
@@ -970,7 +939,8 @@ unix_plugin_send (void *cls, | |||
970 | LOG (GNUNET_ERROR_TYPE_ERROR, | 939 | LOG (GNUNET_ERROR_TYPE_ERROR, |
971 | "Invalid session for peer `%s' `%s'\n", | 940 | "Invalid session for peer `%s' `%s'\n", |
972 | GNUNET_i2s (&session->target), | 941 | GNUNET_i2s (&session->target), |
973 | (const char *) session->addr); | 942 | unix_address_to_string(NULL, session->address->address, |
943 | session->address->address_length)); | ||
974 | GNUNET_break (0); | 944 | GNUNET_break (0); |
975 | return GNUNET_SYSERR; | 945 | return GNUNET_SYSERR; |
976 | } | 946 | } |
@@ -978,7 +948,8 @@ unix_plugin_send (void *cls, | |||
978 | "Sending %u bytes with session for peer `%s' `%s'\n", | 948 | "Sending %u bytes with session for peer `%s' `%s'\n", |
979 | msgbuf_size, | 949 | msgbuf_size, |
980 | GNUNET_i2s (&session->target), | 950 | GNUNET_i2s (&session->target), |
981 | (const char *) session->addr); | 951 | unix_address_to_string(NULL, session->address->address, |
952 | session->address->address_length)); | ||
982 | ssize = sizeof (struct UNIXMessage) + msgbuf_size; | 953 | ssize = sizeof (struct UNIXMessage) + msgbuf_size; |
983 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); | 954 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); |
984 | message->header.size = htons (ssize); | 955 | message->header.size = htons (ssize); |
@@ -1025,7 +996,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1025 | const struct UnixAddress *ua, size_t ua_len) | 996 | const struct UnixAddress *ua, size_t ua_len) |
1026 | { | 997 | { |
1027 | struct Session *s = NULL; | 998 | struct Session *s = NULL; |
1028 | struct GNUNET_HELLO_Address * addr; | 999 | struct GNUNET_HELLO_Address *address; |
1029 | 1000 | ||
1030 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); | 1001 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); |
1031 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); | 1002 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); |
@@ -1037,31 +1008,23 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1037 | ntohs (currhdr->size), | 1008 | ntohs (currhdr->size), |
1038 | GNUNET_NO); | 1009 | GNUNET_NO); |
1039 | 1010 | ||
1040 | addr = GNUNET_HELLO_address_allocate (sender, | 1011 | /* Look for existing session */ |
1041 | "unix", | 1012 | address = GNUNET_HELLO_address_allocate (sender, PLUGIN_NAME, ua, ua_len, |
1042 | ua, | 1013 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ |
1043 | ua_len); | 1014 | s = lookup_session (plugin, address); |
1044 | s = lookup_session (plugin, sender, ua, ua_len); | 1015 | |
1045 | if (NULL == s) | 1016 | if (NULL == s) |
1046 | { | 1017 | { |
1047 | s = unix_plugin_get_session (plugin, addr); | 1018 | s = unix_plugin_get_session (plugin, address); |
1048 | s->inbound = GNUNET_YES; | ||
1049 | /* Notify transport and ATS about new inbound session */ | 1019 | /* Notify transport and ATS about new inbound session */ |
1050 | plugin->env->session_start (NULL, sender, | 1020 | plugin->env->session_start (NULL, s->address, s, &plugin->ats_network, 1); |
1051 | PLUGIN_NAME, ua, ua_len, s, &plugin->ats_network, 1); | ||
1052 | } | 1021 | } |
1022 | GNUNET_HELLO_address_free (address); | ||
1053 | reschedule_session_timeout (s); | 1023 | reschedule_session_timeout (s); |
1054 | 1024 | ||
1055 | plugin->env->receive (plugin->env->cls, sender, currhdr, s, | 1025 | plugin->env->receive (plugin->env->cls, s->address, s, currhdr); |
1056 | (GNUNET_YES == s->inbound) ? NULL : (const char *) ua, | 1026 | plugin->env->update_address_metrics (plugin->env->cls, s->address, s, |
1057 | (GNUNET_YES == s->inbound) ? 0 : ua_len); | 1027 | &plugin->ats_network, 1); |
1058 | |||
1059 | plugin->env->update_address_metrics (plugin->env->cls, sender, | ||
1060 | (GNUNET_YES == s->inbound) ? NULL : (const char *) ua, | ||
1061 | (GNUNET_YES == s->inbound) ? 0 : ua_len, | ||
1062 | s, &plugin->ats_network, 1); | ||
1063 | |||
1064 | GNUNET_free (addr); | ||
1065 | } | 1028 | } |
1066 | 1029 | ||
1067 | 1030 | ||
@@ -1193,8 +1156,8 @@ unix_plugin_select_write (struct Plugin *plugin) | |||
1193 | msgw->msgsize, | 1156 | msgw->msgsize, |
1194 | msgw->priority, | 1157 | msgw->priority, |
1195 | msgw->timeout, | 1158 | msgw->timeout, |
1196 | msgw->session->addr, | 1159 | msgw->session->address->address, |
1197 | msgw->session->addrlen, | 1160 | msgw->session->address->address_length, |
1198 | msgw->payload, | 1161 | msgw->payload, |
1199 | msgw->cont, msgw->cont_cls); | 1162 | msgw->cont, msgw->cont_cls); |
1200 | 1163 | ||
@@ -1517,6 +1480,7 @@ address_notification (void *cls, | |||
1517 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1480 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1518 | { | 1481 | { |
1519 | struct Plugin *plugin = cls; | 1482 | struct Plugin *plugin = cls; |
1483 | struct GNUNET_HELLO_Address *address; | ||
1520 | size_t len; | 1484 | size_t len; |
1521 | struct UnixAddress *ua; | 1485 | struct UnixAddress *ua; |
1522 | 1486 | ||
@@ -1527,16 +1491,19 @@ address_notification (void *cls, | |||
1527 | memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); | 1491 | memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); |
1528 | 1492 | ||
1529 | plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; | 1493 | plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK; |
1530 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, | 1494 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1531 | ua, len, "unix"); | 1495 | PLUGIN_NAME, ua, len, GNUNET_HELLO_ADDRESS_INFO_NONE); |
1496 | |||
1497 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); | ||
1532 | GNUNET_free (ua); | 1498 | GNUNET_free (ua); |
1499 | GNUNET_free (address); | ||
1533 | } | 1500 | } |
1534 | 1501 | ||
1535 | 1502 | ||
1536 | /** | 1503 | /** |
1537 | * Increment session timeout due to activity | 1504 | * Increment session timeout due to activity |
1538 | * | 1505 | * |
1539 | * @param s session for which the timeout should be moved | 1506 | * @param res session for which the timeout should be moved |
1540 | */ | 1507 | */ |
1541 | static void | 1508 | static void |
1542 | reschedule_session_timeout (struct Session *s) | 1509 | reschedule_session_timeout (struct Session *s) |
@@ -1672,6 +1639,7 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1672 | { | 1639 | { |
1673 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1640 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1674 | struct Plugin *plugin = api->cls; | 1641 | struct Plugin *plugin = api->cls; |
1642 | struct GNUNET_HELLO_Address *address; | ||
1675 | struct UNIXMessageWrapper * msgw; | 1643 | struct UNIXMessageWrapper * msgw; |
1676 | struct UnixAddress *ua; | 1644 | struct UnixAddress *ua; |
1677 | size_t len; | 1645 | size_t len; |
@@ -1687,10 +1655,13 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1687 | ua->options = htonl (myoptions); | 1655 | ua->options = htonl (myoptions); |
1688 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | 1656 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); |
1689 | memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); | 1657 | memcpy (&ua[1], plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); |
1658 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | ||
1659 | PLUGIN_NAME, ua, len, GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1660 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); | ||
1690 | 1661 | ||
1691 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, | 1662 | GNUNET_free (address); |
1692 | ua, len, "unix"); | ||
1693 | GNUNET_free (ua); | 1663 | GNUNET_free (ua); |
1664 | |||
1694 | while (NULL != (msgw = plugin->msg_head)) | 1665 | while (NULL != (msgw = plugin->msg_head)) |
1695 | { | 1666 | { |
1696 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); | 1667 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 1fafc4070..1026eb584 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -351,7 +351,9 @@ struct MacEndpoint | |||
351 | /** | 351 | /** |
352 | * peer mac address | 352 | * peer mac address |
353 | */ | 353 | */ |
354 | struct WlanAddress addr; | 354 | //struct WlanAddress addr; |
355 | |||
356 | struct GNUNET_HELLO_Address *address; | ||
355 | 357 | ||
356 | /** | 358 | /** |
357 | * Inbound or outbound session | 359 | * Inbound or outbound session |
@@ -612,8 +614,8 @@ send_ack (void *cls, uint32_t msg_id, | |||
612 | get_radiotap_header (endpoint, radio_header, size); | 614 | get_radiotap_header (endpoint, radio_header, size); |
613 | get_wlan_header (endpoint->plugin, | 615 | get_wlan_header (endpoint->plugin, |
614 | &radio_header->frame, | 616 | &radio_header->frame, |
615 | &endpoint->addr.mac, | 617 | endpoint->address->address, |
616 | size); | 618 | endpoint->address->address_length); |
617 | memcpy (&radio_header[1], hdr, msize); | 619 | memcpy (&radio_header[1], hdr, msize); |
618 | if (NULL != | 620 | if (NULL != |
619 | GNUNET_HELPER_send (endpoint->plugin->suid_helper, | 621 | GNUNET_HELPER_send (endpoint->plugin->suid_helper, |
@@ -789,10 +791,11 @@ create_session (struct MacEndpoint *endpoint, | |||
789 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); | 791 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, session); |
790 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 792 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
791 | "Created new %s session %p for peer `%s' with endpoint %s\n", | 793 | "Created new %s session %p for peer `%s' with endpoint %s\n", |
794 | |||
792 | (GNUNET_YES == inbound) ? "inbound" : "outbound", | 795 | (GNUNET_YES == inbound) ? "inbound" : "outbound", |
793 | session, | 796 | session, |
794 | GNUNET_i2s (peer), | 797 | GNUNET_i2s (peer), |
795 | mac_to_string (&endpoint->addr.mac)); | 798 | mac_to_string (endpoint->address->address)); |
796 | 799 | ||
797 | return session; | 800 | return session; |
798 | } | 801 | } |
@@ -870,8 +873,8 @@ transmit_fragment (void *cls, | |||
870 | get_radiotap_header (endpoint, radio_header, size); | 873 | get_radiotap_header (endpoint, radio_header, size); |
871 | get_wlan_header (endpoint->plugin, | 874 | get_wlan_header (endpoint->plugin, |
872 | &radio_header->frame, | 875 | &radio_header->frame, |
873 | &endpoint->addr.mac, | 876 | endpoint->address->address, |
874 | size); | 877 | endpoint->address->address_length); |
875 | memcpy (&radio_header[1], hdr, msize); | 878 | memcpy (&radio_header[1], hdr, msize); |
876 | GNUNET_assert (NULL == fm->sh); | 879 | GNUNET_assert (NULL == fm->sh); |
877 | fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, | 880 | fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, |
@@ -1072,15 +1075,16 @@ macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1072 | */ | 1075 | */ |
1073 | static struct MacEndpoint * | 1076 | static struct MacEndpoint * |
1074 | create_macendpoint (struct Plugin *plugin, | 1077 | create_macendpoint (struct Plugin *plugin, |
1075 | const struct WlanAddress *addr) | 1078 | const struct GNUNET_HELLO_Address *address) |
1076 | { | 1079 | { |
1077 | struct MacEndpoint *pos; | 1080 | struct MacEndpoint *pos; |
1078 | 1081 | ||
1079 | for (pos = plugin->mac_head; NULL != pos; pos = pos->next) | 1082 | for (pos = plugin->mac_head; NULL != pos; pos = pos->next) |
1080 | if (0 == memcmp (addr, &pos->addr, sizeof (struct WlanAddress))) | 1083 | if (0 == memcmp (address->address, pos->address->address, |
1084 | pos->address->address_length)) | ||
1081 | return pos; | 1085 | return pos; |
1082 | pos = GNUNET_new (struct MacEndpoint); | 1086 | pos = GNUNET_new (struct MacEndpoint); |
1083 | pos->addr = *addr; | 1087 | pos->address = GNUNET_HELLO_address_copy (address); |
1084 | pos->plugin = plugin; | 1088 | pos->plugin = plugin; |
1085 | pos->defrag = | 1089 | pos->defrag = |
1086 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, | 1090 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, WLAN_MTU, |
@@ -1090,8 +1094,7 @@ create_macendpoint (struct Plugin *plugin, | |||
1090 | &send_ack); | 1094 | &send_ack); |
1091 | 1095 | ||
1092 | pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; | 1096 | pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; |
1093 | pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 1097 | pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100); |
1094 | 100); | ||
1095 | pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); | 1098 | pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); |
1096 | pos->timeout_task = | 1099 | pos->timeout_task = |
1097 | GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout, | 1100 | GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout, |
@@ -1100,9 +1103,8 @@ create_macendpoint (struct Plugin *plugin, | |||
1100 | plugin->mac_count++; | 1103 | plugin->mac_count++; |
1101 | GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"), | 1104 | GNUNET_STATISTICS_update (plugin->env->stats, _("# WLAN MAC endpoints allocated"), |
1102 | 1, GNUNET_NO); | 1105 | 1, GNUNET_NO); |
1103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1106 | LOG (GNUNET_ERROR_TYPE_DEBUG, "New MAC endpoint `%s'\n", |
1104 | "New MAC endpoint `%s'\n", | 1107 | wlan_plugin_address_to_string(NULL, address->address, address->address_length)); |
1105 | wlan_plugin_address_to_string(NULL, addr, sizeof (struct WlanAddress))); | ||
1106 | return pos; | 1108 | return pos; |
1107 | } | 1109 | } |
1108 | 1110 | ||
@@ -1149,7 +1151,7 @@ wlan_plugin_get_session (void *cls, | |||
1149 | "Service asked to create session for peer `%s' with MAC `%s'\n", | 1151 | "Service asked to create session for peer `%s' with MAC `%s'\n", |
1150 | GNUNET_i2s (&address->peer), | 1152 | GNUNET_i2s (&address->peer), |
1151 | wlan_plugin_address_to_string(NULL, address->address, address->address_length)); | 1153 | wlan_plugin_address_to_string(NULL, address->address, address->address_length)); |
1152 | endpoint = create_macendpoint (plugin, address->address); | 1154 | endpoint = create_macendpoint (plugin, address); |
1153 | return get_session (endpoint, &address->peer, GNUNET_NO); | 1155 | return get_session (endpoint, &address->peer, GNUNET_NO); |
1154 | } | 1156 | } |
1155 | 1157 | ||
@@ -1261,6 +1263,7 @@ static int | |||
1261 | process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 1263 | process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
1262 | { | 1264 | { |
1263 | struct Plugin *plugin = cls; | 1265 | struct Plugin *plugin = cls; |
1266 | struct GNUNET_HELLO_Address *address; | ||
1264 | struct MacAndSession *mas = client; | 1267 | struct MacAndSession *mas = client; |
1265 | struct MacAndSession xmas; | 1268 | struct MacAndSession xmas; |
1266 | struct GNUNET_ATS_Information ats; | 1269 | struct GNUNET_ATS_Information ats; |
@@ -1291,21 +1294,18 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1291 | "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", | 1294 | "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", |
1292 | (unsigned int) msize, | 1295 | (unsigned int) msize, |
1293 | GNUNET_i2s (&tmpsource), | 1296 | GNUNET_i2s (&tmpsource), |
1294 | wlan_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1297 | wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, mas->endpoint->address->address_length)); |
1295 | 1298 | ||
1296 | GNUNET_STATISTICS_update (plugin->env->stats, | 1299 | GNUNET_STATISTICS_update (plugin->env->stats, |
1297 | _("# HELLO messages received via WLAN"), 1, | 1300 | _("# HELLO messages received via WLAN"), 1, |
1298 | GNUNET_NO); | 1301 | GNUNET_NO); |
1302 | |||
1299 | plugin->env->receive (plugin->env->cls, | 1303 | plugin->env->receive (plugin->env->cls, |
1300 | &tmpsource, | 1304 | mas->endpoint->address, |
1301 | hdr, | 1305 | mas->session, |
1302 | mas->session, | 1306 | hdr); |
1303 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | ||
1304 | (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress)); | ||
1305 | plugin->env->update_address_metrics (plugin->env->cls, | 1307 | plugin->env->update_address_metrics (plugin->env->cls, |
1306 | &tmpsource, | 1308 | mas->endpoint->address, |
1307 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | ||
1308 | (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress), | ||
1309 | mas->session, | 1309 | mas->session, |
1310 | &ats, 1); | 1310 | &ats, 1); |
1311 | break; | 1311 | break; |
@@ -1318,7 +1318,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1318 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1318 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1319 | "Processing %u bytes of FRAGMENT from MAC %s\n", | 1319 | "Processing %u bytes of FRAGMENT from MAC %s\n", |
1320 | (unsigned int) msize, | 1320 | (unsigned int) msize, |
1321 | wlan_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1321 | wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1322 | mas->endpoint->address->address_length)); | ||
1322 | GNUNET_STATISTICS_update (plugin->env->stats, | 1323 | GNUNET_STATISTICS_update (plugin->env->stats, |
1323 | _("# fragments received via WLAN"), 1, GNUNET_NO); | 1324 | _("# fragments received via WLAN"), 1, GNUNET_NO); |
1324 | (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, | 1325 | (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, |
@@ -1339,7 +1340,8 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1339 | { | 1340 | { |
1340 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1341 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1341 | "Got last ACK, finished message transmission to `%s' (%p)\n", | 1342 | "Got last ACK, finished message transmission to `%s' (%p)\n", |
1342 | wlan_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress)), | 1343 | wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1344 | mas->endpoint->address->address_length), | ||
1343 | fm); | 1345 | fm); |
1344 | mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); | 1346 | mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); |
1345 | if (NULL != fm->cont) | 1347 | if (NULL != fm->cont) |
@@ -1354,13 +1356,15 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1354 | { | 1356 | { |
1355 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1357 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1356 | "Got an ACK, message transmission to `%s' not yet finished\n", | 1358 | "Got an ACK, message transmission to `%s' not yet finished\n", |
1357 | wlan_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1359 | wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1360 | mas->endpoint->address->address_length)); | ||
1358 | break; | 1361 | break; |
1359 | } | 1362 | } |
1360 | } | 1363 | } |
1361 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1364 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1362 | "ACK not matched against any active fragmentation with MAC `%s'\n", | 1365 | "ACK not matched against any active fragmentation with MAC `%s'\n", |
1363 | wlan_plugin_address_to_string (NULL, &mas->endpoint->addr, sizeof (struct WlanAddress))); | 1366 | wlan_plugin_address_to_string (NULL, mas->endpoint->address->address, |
1367 | mas->endpoint->address->address_length)); | ||
1364 | break; | 1368 | break; |
1365 | case GNUNET_MESSAGE_TYPE_WLAN_DATA: | 1369 | case GNUNET_MESSAGE_TYPE_WLAN_DATA: |
1366 | if (NULL == mas->endpoint) | 1370 | if (NULL == mas->endpoint) |
@@ -1395,12 +1399,14 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1395 | if (NULL == (xmas.session = lookup_session (mas->endpoint, &wlanheader->sender, GNUNET_YES))) | 1399 | if (NULL == (xmas.session = lookup_session (mas->endpoint, &wlanheader->sender, GNUNET_YES))) |
1396 | { | 1400 | { |
1397 | xmas.session = create_session (mas->endpoint, &wlanheader->sender, GNUNET_YES); | 1401 | xmas.session = create_session (mas->endpoint, &wlanheader->sender, GNUNET_YES); |
1398 | plugin->env->session_start (NULL, &wlanheader->sender, | 1402 | address = GNUNET_HELLO_address_allocate (&wlanheader->sender, PLUGIN_NAME, |
1399 | PLUGIN_NAME, &mas->endpoint->addr, | 1403 | &mas->endpoint->address, sizeof (struct WlanAddress), |
1400 | sizeof (struct WlanAddress), xmas.session, NULL, 0); | 1404 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1405 | plugin->env->session_start (NULL, address, xmas.session, NULL, 0); | ||
1401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1406 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1402 | "Notifying transport about peer `%s''s new inbound session %p \n", | 1407 | "Notifying transport about peer `%s''s new inbound session %p \n", |
1403 | GNUNET_i2s (&wlanheader->sender), xmas.session); | 1408 | GNUNET_i2s (&wlanheader->sender), xmas.session); |
1409 | GNUNET_HELLO_address_free (address); | ||
1404 | } | 1410 | } |
1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1411 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1406 | "Processing %u bytes of WLAN DATA from peer `%s'\n", | 1412 | "Processing %u bytes of WLAN DATA from peer `%s'\n", |
@@ -1429,17 +1435,13 @@ process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
1429 | (unsigned int) ntohs (hdr->type), | 1435 | (unsigned int) ntohs (hdr->type), |
1430 | GNUNET_i2s (&mas->session->target)); | 1436 | GNUNET_i2s (&mas->session->target)); |
1431 | plugin->env->receive (plugin->env->cls, | 1437 | plugin->env->receive (plugin->env->cls, |
1432 | &mas->session->target, | 1438 | mas->session->mac->address, |
1433 | hdr, | 1439 | mas->session, |
1434 | mas->session, | 1440 | hdr); |
1435 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | ||
1436 | (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress)); | ||
1437 | plugin->env->update_address_metrics (plugin->env->cls, | 1441 | plugin->env->update_address_metrics (plugin->env->cls, |
1438 | &mas->session->target, | 1442 | mas->session->mac->address, |
1439 | (mas->endpoint == NULL) ? NULL : (const char *) &mas->endpoint->addr, | 1443 | mas->session, |
1440 | (mas->endpoint == NULL) ? 0 : sizeof (struct WlanAddress), | 1444 | &ats, 1); |
1441 | mas->session, | ||
1442 | &ats, 1); | ||
1443 | break; | 1445 | break; |
1444 | } | 1446 | } |
1445 | return GNUNET_OK; | 1447 | return GNUNET_OK; |
@@ -1458,6 +1460,7 @@ handle_helper_message (void *cls, void *client, | |||
1458 | const struct GNUNET_MessageHeader *hdr) | 1460 | const struct GNUNET_MessageHeader *hdr) |
1459 | { | 1461 | { |
1460 | struct Plugin *plugin = cls; | 1462 | struct Plugin *plugin = cls; |
1463 | struct GNUNET_HELLO_Address *address; | ||
1461 | const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; | 1464 | const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rxinfo; |
1462 | const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; | 1465 | const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *cm; |
1463 | struct WlanAddress wa; | 1466 | struct WlanAddress wa; |
@@ -1484,24 +1487,26 @@ handle_helper_message (void *cls, void *client, | |||
1484 | memset (&wa, 0, sizeof (struct WlanAddress)); | 1487 | memset (&wa, 0, sizeof (struct WlanAddress)); |
1485 | wa.mac = plugin->mac_address; | 1488 | wa.mac = plugin->mac_address; |
1486 | wa.options = htonl(plugin->options); | 1489 | wa.options = htonl(plugin->options); |
1487 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, | 1490 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1488 | &wa, | 1491 | PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); |
1489 | sizeof (wa), | 1492 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); |
1490 | "wlan"); | 1493 | GNUNET_HELLO_address_free (address); |
1491 | } | 1494 | } |
1492 | plugin->mac_address = cm->mac; | 1495 | plugin->mac_address = cm->mac; |
1493 | plugin->have_mac = GNUNET_YES; | 1496 | plugin->have_mac = GNUNET_YES; |
1497 | |||
1494 | memset (&wa, 0, sizeof (struct WlanAddress)); | 1498 | memset (&wa, 0, sizeof (struct WlanAddress)); |
1495 | wa.mac = plugin->mac_address; | 1499 | wa.mac = plugin->mac_address; |
1496 | wa.options = htonl(plugin->options); | 1500 | wa.options = htonl(plugin->options); |
1501 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | ||
1502 | PLUGIN_NAME, &wa, sizeof (wa), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1503 | |||
1497 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1504 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1498 | "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", | 1505 | "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", |
1499 | mac_to_string (&cm->mac), | 1506 | mac_to_string (&cm->mac), |
1500 | GNUNET_i2s (plugin->env->my_identity)); | 1507 | GNUNET_i2s (plugin->env->my_identity)); |
1501 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, | 1508 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); |
1502 | &wa, | 1509 | GNUNET_HELLO_address_free (address); |
1503 | sizeof (struct WlanAddress), | ||
1504 | "wlan"); | ||
1505 | break; | 1510 | break; |
1506 | case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: | 1511 | case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: |
1507 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1512 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1551,7 +1556,10 @@ handle_helper_message (void *cls, void *client, | |||
1551 | mac_to_string (&rxinfo->frame.addr2)); | 1556 | mac_to_string (&rxinfo->frame.addr2)); |
1552 | wa.mac = rxinfo->frame.addr2; | 1557 | wa.mac = rxinfo->frame.addr2; |
1553 | wa.options = htonl (0); | 1558 | wa.options = htonl (0); |
1554 | mas.endpoint = create_macendpoint (plugin, &wa); | 1559 | address = GNUNET_HELLO_address_allocate (NULL, PLUGIN_NAME, &wa, |
1560 | sizeof (struct WlanAddress), GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
1561 | mas.endpoint = create_macendpoint (plugin, address); | ||
1562 | GNUNET_HELLO_address_free (address); | ||
1555 | mas.session = NULL; | 1563 | mas.session = NULL; |
1556 | (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer, | 1564 | (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer, |
1557 | &mas, | 1565 | &mas, |
@@ -1738,7 +1746,8 @@ wlan_plugin_address_pretty_printer (void *cls, const char *type, | |||
1738 | void * | 1746 | void * |
1739 | libgnunet_plugin_transport_wlan_done (void *cls) | 1747 | libgnunet_plugin_transport_wlan_done (void *cls) |
1740 | { | 1748 | { |
1741 | struct WlanAddress wa; | 1749 | struct WlanAddress wa; |
1750 | struct GNUNET_HELLO_Address *address; | ||
1742 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1751 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1743 | struct Plugin *plugin = api->cls; | 1752 | struct Plugin *plugin = api->cls; |
1744 | struct MacEndpoint *endpoint; | 1753 | struct MacEndpoint *endpoint; |
@@ -1752,14 +1761,17 @@ libgnunet_plugin_transport_wlan_done (void *cls) | |||
1752 | 1761 | ||
1753 | if (GNUNET_YES == plugin->have_mac) | 1762 | if (GNUNET_YES == plugin->have_mac) |
1754 | { | 1763 | { |
1755 | memset (&wa, 0, sizeof (wa)); | 1764 | memset (&wa, 0, sizeof(wa)); |
1756 | wa.options = htonl (plugin->options); | 1765 | wa.options = htonl (plugin->options); |
1757 | wa.mac = plugin->mac_address; | 1766 | wa.mac = plugin->mac_address; |
1758 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, | 1767 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1759 | &wa, | 1768 | PLUGIN_NAME, &wa, sizeof (struct WlanAddress), |
1760 | sizeof (struct WlanAddress), | 1769 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1761 | "wlan"); | 1770 | |
1762 | plugin->have_mac = GNUNET_NO; | 1771 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); |
1772 | plugin->have_mac = GNUNET_NO; | ||
1773 | |||
1774 | GNUNET_HELLO_address_free (address); | ||
1763 | } | 1775 | } |
1764 | 1776 | ||
1765 | if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task) | 1777 | if (GNUNET_SCHEDULER_NO_TASK != plugin->beacon_task) |
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 6c81acb49..13920d6fe 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
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 | /** | 20 | /** |
21 | * @file transport/test_plugin_transport.c | 21 | * @file transport/test_plugin_transport.c |
22 | * @brief testcase for transport_api.c | 22 | * @brief testcase for transport_api.c |
@@ -120,21 +120,17 @@ unsigned int pretty_printers_running; | |||
120 | */ | 120 | */ |
121 | static int ok; | 121 | static int ok; |
122 | 122 | ||
123 | |||
124 | struct AddressWrapper | 123 | struct AddressWrapper |
125 | { | 124 | { |
126 | struct AddressWrapper *next; | 125 | struct AddressWrapper *next; |
127 | 126 | ||
128 | struct AddressWrapper *prev; | 127 | struct AddressWrapper *prev; |
129 | 128 | ||
130 | void *addr; | 129 | struct GNUNET_HELLO_Address *address; |
131 | |||
132 | size_t addrlen; | ||
133 | 130 | ||
134 | char *addrstring; | 131 | char *addrstring; |
135 | }; | 132 | }; |
136 | 133 | ||
137 | |||
138 | static void | 134 | static void |
139 | end () | 135 | end () |
140 | { | 136 | { |
@@ -144,33 +140,32 @@ end () | |||
144 | 140 | ||
145 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) | 141 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) |
146 | { | 142 | { |
147 | GNUNET_SCHEDULER_cancel (timeout_endbadly); | 143 | GNUNET_SCHEDULER_cancel (timeout_endbadly); |
148 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; | 144 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; |
149 | } | 145 | } |
150 | if (NULL != api) | 146 | if (NULL != api) |
151 | GNUNET_PLUGIN_unload (libname, api); | 147 | GNUNET_PLUGIN_unload (libname, api); |
152 | 148 | ||
153 | while (NULL != head) | 149 | while (NULL != head) |
154 | { | 150 | { |
155 | w = head; | 151 | w = head; |
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 152 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", |
157 | "Plugin did not remove address `%s'\n", w->addrstring); | 153 | w->addrstring); |
158 | GNUNET_CONTAINER_DLL_remove (head, tail, w); | 154 | GNUNET_CONTAINER_DLL_remove(head, tail, w); |
159 | c ++; | 155 | c++; |
160 | GNUNET_free (w->addr); | 156 | GNUNET_HELLO_address_free(w->address); |
161 | GNUNET_free (w->addrstring); | 157 | GNUNET_free(w->addrstring); |
162 | GNUNET_free (w); | 158 | GNUNET_free(w); |
163 | } | 159 | } |
164 | if (c > 0) | 160 | if (c > 0) |
165 | { | 161 | { |
166 | GNUNET_break (0); | 162 | GNUNET_break(0); |
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 163 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", |
168 | "Plugin did not remove %u addresses \n", c); | 164 | c); |
169 | ok = 1; | 165 | ok = 1; |
170 | } | 166 | } |
171 | 167 | ||
172 | 168 | GNUNET_free(libname); | |
173 | GNUNET_free (libname); | ||
174 | libname = NULL; | 169 | libname = NULL; |
175 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 170 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
176 | stats = NULL; | 171 | stats = NULL; |
@@ -182,7 +177,6 @@ end () | |||
182 | } | 177 | } |
183 | } | 178 | } |
184 | 179 | ||
185 | |||
186 | static void | 180 | static void |
187 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 181 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
188 | { | 182 | { |
@@ -192,48 +186,49 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
192 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; | 186 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; |
193 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | 187 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) |
194 | { | 188 | { |
195 | GNUNET_SCHEDULER_cancel (timeout_wait); | 189 | GNUNET_SCHEDULER_cancel (timeout_wait); |
196 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | 190 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; |
197 | } | 191 | } |
198 | 192 | ||
199 | if (pretty_printers_running > 0) | 193 | if (pretty_printers_running > 0) |
200 | { | 194 | { |
201 | timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &end_badly, &ok); | 195 | timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 196 | &end_badly, &ok); |
203 | "Have pending calls to pretty_printer ... deferring shutdown\n"); | 197 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
204 | return; | 198 | "Have pending calls to pretty_printer ... deferring shutdown\n"); |
199 | return; | ||
205 | } | 200 | } |
206 | 201 | ||
207 | if (NULL != cls) | 202 | if (NULL != cls) |
208 | { | 203 | { |
209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
210 | "Test took too long to execute, timeout .... \n"); | 205 | "Test took too long to execute, timeout .... \n"); |
211 | } | 206 | } |
212 | 207 | ||
213 | if (NULL != libname) | 208 | if (NULL != libname) |
214 | { | 209 | { |
215 | if (NULL != api) | 210 | if (NULL != api) |
216 | GNUNET_PLUGIN_unload (libname, api); | 211 | GNUNET_PLUGIN_unload (libname, api); |
217 | GNUNET_free (libname); | 212 | GNUNET_free(libname); |
218 | libname = NULL; | 213 | libname = NULL; |
219 | } | 214 | } |
220 | 215 | ||
221 | while (NULL != head) | 216 | while (NULL != head) |
222 | { | 217 | { |
223 | w = head; | 218 | w = head; |
224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 219 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", |
225 | "Plugin did not remove address `%s'\n", w->addrstring); | 220 | w->addrstring); |
226 | GNUNET_CONTAINER_DLL_remove (head, tail, w); | 221 | GNUNET_CONTAINER_DLL_remove(head, tail, w); |
227 | c ++; | 222 | c++; |
228 | GNUNET_free (w->addr); | 223 | GNUNET_HELLO_address_free(w->address); |
229 | GNUNET_free (w->addrstring); | 224 | GNUNET_free(w->addrstring); |
230 | GNUNET_free (w); | 225 | GNUNET_free(w); |
231 | } | 226 | } |
232 | if (c > 0) | 227 | if (c > 0) |
233 | { | 228 | { |
234 | GNUNET_break (0); | 229 | GNUNET_break(0); |
235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 230 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", |
236 | "Plugin did not remove %u addresses\n", c); | 231 | c); |
237 | } | 232 | } |
238 | 233 | ||
239 | if (NULL != stats) | 234 | if (NULL != stats) |
@@ -251,51 +246,44 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
251 | ok = 1; | 246 | ok = 1; |
252 | } | 247 | } |
253 | 248 | ||
254 | |||
255 | static void | 249 | static void |
256 | wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 250 | wait_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
257 | { | 251 | { |
258 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | 252 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; |
259 | if (0 == addresses_reported) | 253 | if (0 == addresses_reported) |
260 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 254 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
261 | "Plugin did not report any addresses, could not check address conversion functions\n"); | 255 | "Plugin did not report any addresses, could not check address conversion functions\n"); |
262 | end (); | 256 | end (); |
263 | } | 257 | } |
264 | 258 | ||
265 | |||
266 | static void | 259 | static void |
267 | end_badly_now () | 260 | end_badly_now () |
268 | { | 261 | { |
269 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | 262 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) |
270 | { | 263 | { |
271 | GNUNET_SCHEDULER_cancel (timeout_wait); | 264 | GNUNET_SCHEDULER_cancel (timeout_wait); |
272 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | 265 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; |
273 | } | 266 | } |
274 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) | 267 | if (GNUNET_SCHEDULER_NO_TASK != timeout_endbadly) |
275 | { | 268 | { |
276 | GNUNET_SCHEDULER_cancel (timeout_endbadly); | 269 | GNUNET_SCHEDULER_cancel (timeout_endbadly); |
277 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; | 270 | timeout_endbadly = GNUNET_SCHEDULER_NO_TASK; |
278 | } | 271 | } |
279 | timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 272 | timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); |
280 | } | 273 | } |
281 | 274 | ||
282 | |||
283 | static struct GNUNET_TIME_Relative | 275 | static struct GNUNET_TIME_Relative |
284 | env_receive (void *cls, | 276 | env_receive (void *cls, |
285 | const struct GNUNET_PeerIdentity *peer, | 277 | const struct GNUNET_HELLO_Address *address, |
286 | const struct GNUNET_MessageHeader *message, | 278 | struct Session *session, |
287 | struct Session * session, | 279 | const struct GNUNET_MessageHeader *message) |
288 | const char *sender_address, | ||
289 | uint16_t sender_address_len) | ||
290 | { | 280 | { |
291 | /* do nothing */ | 281 | /* do nothing */ |
292 | return GNUNET_TIME_relative_get_zero_(); | 282 | return GNUNET_TIME_relative_get_zero_ (); |
293 | } | 283 | } |
294 | 284 | ||
295 | |||
296 | static int got_reply; | 285 | static int got_reply; |
297 | 286 | ||
298 | |||
299 | /** | 287 | /** |
300 | * Take the given address and append it to the set of results sent back to | 288 | * Take the given address and append it to the set of results sent back to |
301 | * the client. | 289 | * the client. |
@@ -309,28 +297,23 @@ address_pretty_printer_cb (void *cls, const char *buf) | |||
309 | if (NULL != buf) | 297 | if (NULL != buf) |
310 | { | 298 | { |
311 | got_reply = GNUNET_YES; | 299 | got_reply = GNUNET_YES; |
312 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 300 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", buf); |
313 | "Pretty address : `%s'\n", buf); | 301 | pretty_printers_running--; |
314 | pretty_printers_running --; | ||
315 | } | 302 | } |
316 | else | 303 | else |
317 | { | 304 | { |
318 | if (GNUNET_NO == got_reply) | 305 | if (GNUNET_NO == got_reply) |
319 | { | 306 | { |
320 | pretty_printers_running --; | 307 | pretty_printers_running--; |
321 | GNUNET_break (0); | 308 | GNUNET_break(0); |
322 | end_badly_now (); | 309 | end_badly_now (); |
323 | } | 310 | } |
324 | } | 311 | } |
325 | } | 312 | } |
326 | 313 | ||
327 | |||
328 | static void | 314 | static void |
329 | env_notify_address (void *cls, | 315 | env_notify_address (void *cls, int add_remove, |
330 | int add_remove, | 316 | const struct GNUNET_HELLO_Address *address) |
331 | const void *addr, | ||
332 | size_t addrlen, | ||
333 | const char *plugin) | ||
334 | { | 317 | { |
335 | struct AddressWrapper *w; | 318 | struct AddressWrapper *w; |
336 | struct AddressWrapper *wtmp; | 319 | struct AddressWrapper *wtmp; |
@@ -339,150 +322,145 @@ env_notify_address (void *cls, | |||
339 | 322 | ||
340 | if (GNUNET_YES == add_remove) | 323 | if (GNUNET_YES == add_remove) |
341 | { | 324 | { |
342 | addresses_reported ++; | 325 | addresses_reported++; |
343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 326 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding address of length %u\n", |
344 | "Adding address of length %u\n", addrlen); | 327 | address->address_length); |
345 | 328 | ||
346 | for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) | 329 | for (wtmp = head; NULL != wtmp; wtmp = wtmp->next) |
330 | { | ||
331 | if ((address->address_length == wtmp->address->address_length) && | ||
332 | (0 == memcmp (address->address, wtmp->address->address, address->address_length))) | ||
347 | { | 333 | { |
348 | if ((addrlen == wtmp->addrlen) && (0 == memcmp (addr, wtmp->addr, addrlen))) | 334 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
349 | { | 335 | "Duplicate address notification .... \n"); |
350 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 336 | return; |
351 | "Duplicate address notification .... \n"); | ||
352 | return; | ||
353 | } | ||
354 | } | ||
355 | |||
356 | w = GNUNET_new (struct AddressWrapper); | ||
357 | w->addr = GNUNET_malloc (addrlen); | ||
358 | w->addrlen = addrlen; | ||
359 | memcpy (w->addr, addr, addrlen); | ||
360 | GNUNET_CONTAINER_DLL_insert(head, tail, w); | ||
361 | got_reply = GNUNET_NO; | ||
362 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
363 | "Testing: address_to_string \n"); | ||
364 | w->addrstring = strdup (api->address_to_string (api, w->addr, w->addrlen)); | ||
365 | if (NULL == w->addrstring) | ||
366 | { | ||
367 | GNUNET_break (0); | ||
368 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
369 | "Plugin cannot convert address to string!\n"); | ||
370 | end_badly_now(); | ||
371 | return; | ||
372 | } | ||
373 | else | ||
374 | { | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
376 | "Plugin added address `%s'\n", w->addrstring); | ||
377 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
378 | "Testing address_to_string: OK\n"); | ||
379 | } | ||
380 | |||
381 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
382 | "Testing: string_to_address \n"); | ||
383 | s2a = NULL; | ||
384 | s2a_len = 0; | ||
385 | if ((GNUNET_OK != api->string_to_address (api, w->addrstring, strlen (w->addrstring)+1, &s2a, &s2a_len)) || (NULL == s2a)) | ||
386 | { | ||
387 | GNUNET_break (0); | ||
388 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
389 | "Plugin cannot convert string to address!\n"); | ||
390 | end_badly_now(); | ||
391 | return; | ||
392 | } | ||
393 | |||
394 | /* | ||
395 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
396 | "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); | ||
397 | |||
398 | int c1; | ||
399 | for (c1 = 0; c1 < s2a_len; c1++ ) | ||
400 | fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); | ||
401 | */ | ||
402 | if (s2a_len != w->addrlen) | ||
403 | { | ||
404 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
405 | "Plugin creates different address length when converting address->string->address: %u != %u\n", w->addrlen, s2a_len); | ||
406 | } | ||
407 | else if (0 != memcmp (s2a, w->addr, s2a_len)) | ||
408 | { | ||
409 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
410 | "Plugin creates different address length when converting back and forth %i!\n", memcmp (s2a, w->addr, s2a_len)); | ||
411 | } | ||
412 | else | ||
413 | { | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
415 | "Testing string_to_address: OK\n"); | ||
416 | } | ||
417 | GNUNET_free (s2a); | ||
418 | |||
419 | pretty_printers_running ++; | ||
420 | api->address_pretty_printer (api->cls, plugin, addr, addrlen, | ||
421 | GNUNET_YES, GNUNET_TIME_UNIT_MINUTES, | ||
422 | &address_pretty_printer_cb, | ||
423 | w); | ||
424 | |||
425 | if (GNUNET_OK != api->check_address (api->cls, w->addr, w->addrlen)) | ||
426 | { | ||
427 | GNUNET_break (0); | ||
428 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
429 | "Plugin refuses added address!\n"); | ||
430 | end_badly_now(); | ||
431 | return; | ||
432 | } | ||
433 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | ||
434 | { | ||
435 | GNUNET_SCHEDULER_cancel (timeout_wait); | ||
436 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | ||
437 | } | 337 | } |
338 | } | ||
339 | |||
340 | w = GNUNET_new (struct AddressWrapper); | ||
341 | w->address = GNUNET_HELLO_address_copy (address); | ||
342 | GNUNET_CONTAINER_DLL_insert(head, tail, w); | ||
343 | got_reply = GNUNET_NO; | ||
344 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: address_to_string \n"); | ||
345 | w->addrstring = strdup ( | ||
346 | api->address_to_string (api, w->address->address, | ||
347 | w->address->address_length)); | ||
348 | if (NULL == w->addrstring) | ||
349 | { | ||
350 | GNUNET_break(0); | ||
351 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
352 | "Plugin cannot convert address to string!\n"); | ||
353 | end_badly_now (); | ||
354 | return; | ||
355 | } | ||
356 | else | ||
357 | { | ||
358 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Plugin added address `%s'\n", | ||
359 | w->addrstring); | ||
360 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing address_to_string: OK\n"); | ||
361 | } | ||
362 | |||
363 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing: string_to_address \n"); | ||
364 | s2a = NULL; | ||
365 | s2a_len = 0; | ||
366 | if ((GNUNET_OK | ||
367 | != api->string_to_address (api, w->addrstring, | ||
368 | strlen (w->addrstring) + 1, &s2a, &s2a_len)) || (NULL == s2a)) | ||
369 | { | ||
370 | GNUNET_break(0); | ||
371 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
372 | "Plugin cannot convert string to address!\n"); | ||
373 | end_badly_now (); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | /* | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
379 | "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); | ||
380 | |||
381 | int c1; | ||
382 | for (c1 = 0; c1 < s2a_len; c1++ ) | ||
383 | fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); | ||
384 | */ | ||
385 | if (s2a_len != w->address->address_length) | ||
386 | { | ||
387 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
388 | "Plugin creates different address length when converting address->string->address: %u != %u\n", | ||
389 | w->address->address_length, s2a_len); | ||
390 | } | ||
391 | else if (0 != memcmp (s2a, w->address->address, s2a_len)) | ||
392 | { | ||
393 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
394 | "Plugin creates different address length when converting back and forth %i!\n", | ||
395 | memcmp (s2a, w->address->address, s2a_len)); | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Testing string_to_address: OK\n"); | ||
400 | } | ||
401 | GNUNET_free(s2a); | ||
402 | |||
403 | pretty_printers_running++; | ||
404 | api->address_pretty_printer (api->cls, address->transport_name, address->address, address->address_length, GNUNET_YES, | ||
405 | GNUNET_TIME_UNIT_MINUTES, &address_pretty_printer_cb, w); | ||
406 | |||
407 | if (GNUNET_OK != api->check_address (api->cls, w->address->address, w->address->address_length)) | ||
408 | { | ||
409 | GNUNET_break(0); | ||
410 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin refuses added address!\n"); | ||
411 | end_badly_now (); | ||
412 | return; | ||
413 | } | ||
414 | if (GNUNET_SCHEDULER_NO_TASK != timeout_wait) | ||
415 | { | ||
416 | GNUNET_SCHEDULER_cancel (timeout_wait); | ||
417 | timeout_wait = GNUNET_SCHEDULER_NO_TASK; | ||
418 | } | ||
438 | 419 | ||
439 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); | 420 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); |
440 | 421 | ||
441 | } | 422 | } |
442 | else if (GNUNET_NO == add_remove) | 423 | else if (GNUNET_NO == add_remove) |
443 | { | 424 | { |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 425 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing address of length %u\n", |
445 | "Removing address of length %u\n", addrlen); | 426 | address->address_length); |
446 | 427 | ||
447 | w = head; | 428 | w = head; |
448 | while (NULL != w) | 429 | while (NULL != w) |
430 | { | ||
431 | if ((address->address_length == w->address->address_length) && | ||
432 | (0 == memcmp (w->address->address, address->address, address->address_length))) | ||
449 | { | 433 | { |
450 | if ((addrlen == w->addrlen) && (0 == memcmp (w->addr, addr, addrlen))) | 434 | break; |
451 | { | ||
452 | break; | ||
453 | } | ||
454 | w = w->next; | ||
455 | } | ||
456 | |||
457 | if (w == NULL) | ||
458 | { | ||
459 | GNUNET_break (0); | ||
460 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
461 | "Plugin removes address never added!\n"); | ||
462 | end_badly_now(); | ||
463 | return; | ||
464 | } | 435 | } |
436 | w = w->next; | ||
437 | } | ||
438 | |||
439 | if (w == NULL ) | ||
440 | { | ||
441 | GNUNET_break(0); | ||
442 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
443 | "Plugin removes address never added!\n"); | ||
444 | end_badly_now (); | ||
445 | return; | ||
446 | } | ||
465 | 447 | ||
466 | GNUNET_CONTAINER_DLL_remove (head, tail, w); | 448 | GNUNET_CONTAINER_DLL_remove(head, tail, w); |
467 | GNUNET_free (w->addr); | 449 | GNUNET_HELLO_address_free (w->address); |
468 | GNUNET_free (w->addrstring); | 450 | GNUNET_free(w->addrstring); |
469 | GNUNET_free (w); | 451 | GNUNET_free(w); |
470 | } | 452 | } |
471 | else | 453 | else |
472 | { | 454 | { |
473 | GNUNET_break (0); | 455 | GNUNET_break(0); |
474 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 456 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Invalid operation: %u\n", add_remove); |
475 | "Invalid operation: %u\n", add_remove); | 457 | end_badly_now (); |
476 | end_badly_now (); | 458 | return; |
477 | return; | ||
478 | } | 459 | } |
479 | } | 460 | } |
480 | 461 | ||
481 | |||
482 | static struct GNUNET_ATS_Information | 462 | static struct GNUNET_ATS_Information |
483 | env_get_address_type (void *cls, | 463 | env_get_address_type (void *cls, const struct sockaddr *addr, size_t addrlen) |
484 | const struct sockaddr *addr, | ||
485 | size_t addrlen) | ||
486 | { | 464 | { |
487 | struct GNUNET_ATS_Information ats; | 465 | struct GNUNET_ATS_Information ats; |
488 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 466 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
@@ -490,34 +468,27 @@ env_get_address_type (void *cls, | |||
490 | return ats; | 468 | return ats; |
491 | } | 469 | } |
492 | 470 | ||
493 | |||
494 | static const struct GNUNET_MessageHeader * | 471 | static const struct GNUNET_MessageHeader * |
495 | env_get_our_hello () | 472 | env_get_our_hello () |
496 | { | 473 | { |
497 | return (const struct GNUNET_MessageHeader *) hello; | 474 | return (const struct GNUNET_MessageHeader *) hello; |
498 | } | 475 | } |
499 | 476 | ||
500 | |||
501 | static void | 477 | static void |
502 | env_session_end (void *cls, | 478 | env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, |
503 | const struct GNUNET_PeerIdentity *peer, | 479 | struct Session * session) |
504 | struct Session * session) | ||
505 | { | 480 | { |
506 | } | 481 | } |
507 | 482 | ||
508 | |||
509 | static void | 483 | static void |
510 | env_update_metrics (void *cls, | 484 | env_update_metrics (void *cls, |
511 | const struct GNUNET_PeerIdentity *peer, | 485 | const struct GNUNET_HELLO_Address *address, |
512 | const void *address, | 486 | struct Session *session, |
513 | uint16_t address_len, | 487 | const struct GNUNET_ATS_Information *ats, |
514 | struct Session *session, | 488 | uint32_t ats_count) |
515 | const struct GNUNET_ATS_Information *ats, | ||
516 | uint32_t ats_count) | ||
517 | { | 489 | { |
518 | } | 490 | } |
519 | 491 | ||
520 | |||
521 | static void | 492 | static void |
522 | setup_plugin_environment () | 493 | setup_plugin_environment () |
523 | { | 494 | { |
@@ -534,15 +505,13 @@ setup_plugin_environment () | |||
534 | env.session_end = &env_session_end; | 505 | env.session_end = &env_session_end; |
535 | } | 506 | } |
536 | 507 | ||
537 | |||
538 | static int | 508 | static int |
539 | handle_helper_message (void *cls, void *client, | 509 | handle_helper_message (void *cls, void *client, |
540 | const struct GNUNET_MessageHeader *hdr) | 510 | const struct GNUNET_MessageHeader *hdr) |
541 | { | 511 | { |
542 | return GNUNET_OK; | 512 | return GNUNET_OK; |
543 | } | 513 | } |
544 | 514 | ||
545 | |||
546 | /** | 515 | /** |
547 | * Runs the test. | 516 | * Runs the test. |
548 | * | 517 | * |
@@ -550,10 +519,10 @@ handle_helper_message (void *cls, void *client, | |||
550 | * @param c configuration to use | 519 | * @param c configuration to use |
551 | */ | 520 | */ |
552 | static void | 521 | static void |
553 | run (void *cls, char *const *args, const char *cfgfile, | 522 | run (void *cls, char * const *args, const char *cfgfile, |
554 | const struct GNUNET_CONFIGURATION_Handle *c) | 523 | const struct GNUNET_CONFIGURATION_Handle *c) |
555 | { | 524 | { |
556 | char *const *argv = cls; | 525 | char * const *argv = cls; |
557 | unsigned long long tneigh; | 526 | unsigned long long tneigh; |
558 | char *keyfile; | 527 | char *keyfile; |
559 | char *plugin; | 528 | char *plugin; |
@@ -563,66 +532,62 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
563 | 532 | ||
564 | cfg = c; | 533 | cfg = c; |
565 | /* parse configuration */ | 534 | /* parse configuration */ |
566 | if ( (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (c, | 535 | if ((GNUNET_OK |
567 | "TRANSPORT", | 536 | != GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", |
568 | "NEIGHBOUR_LIMIT", | 537 | "NEIGHBOUR_LIMIT", &tneigh)) |
569 | &tneigh)) || | 538 | || (GNUNET_OK |
570 | (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, | 539 | != GNUNET_CONFIGURATION_get_value_filename (c, "PEER", "PRIVATE_KEY", |
571 | "PEER", "PRIVATE_KEY", | 540 | &keyfile))) |
572 | &keyfile))) | 541 | { |
573 | { | 542 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
574 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 543 | "Transport service is lacking key configuration settings. Exiting.\n"); |
575 | "Transport service is lacking key configuration settings. Exiting.\n"); | ||
576 | return; | 544 | return; |
577 | } | 545 | } |
578 | 546 | ||
579 | if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg))) | 547 | if (NULL == (stats = GNUNET_STATISTICS_create ("transport", cfg))) |
580 | { | 548 | { |
581 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 549 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
582 | "Could not create statistics. Exiting.\n"); | 550 | "Could not create statistics. Exiting.\n"); |
583 | GNUNET_free (keyfile); | 551 | GNUNET_free(keyfile); |
584 | end_badly_now (); | 552 | end_badly_now (); |
585 | return; | 553 | return; |
586 | } | 554 | } |
587 | 555 | ||
588 | if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) | 556 | if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) |
589 | { | 557 | { |
590 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 558 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Hostkey `%s' missing. Exiting.\n", |
591 | "Hostkey `%s' missing. Exiting.\n", | 559 | HOSTKEY_FILE); |
592 | HOSTKEY_FILE); | 560 | GNUNET_free(keyfile); |
593 | GNUNET_free (keyfile); | 561 | end_badly_now (); |
594 | end_badly_now (); | 562 | return; |
595 | return; | ||
596 | } | 563 | } |
597 | 564 | ||
598 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile)) | 565 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (keyfile)) |
599 | { | 566 | { |
600 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 567 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
601 | "Could not create a directory for hostkey `%s'. Exiting.\n", | 568 | "Could not create a directory for hostkey `%s'. Exiting.\n", keyfile); |
602 | keyfile); | 569 | GNUNET_free(keyfile); |
603 | GNUNET_free (keyfile); | 570 | end_badly_now (); |
604 | end_badly_now (); | 571 | return; |
605 | return; | ||
606 | } | 572 | } |
607 | 573 | ||
608 | if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) | 574 | if (GNUNET_OK != GNUNET_DISK_file_copy (HOSTKEY_FILE, keyfile)) |
609 | { | 575 | { |
610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 576 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
611 | "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", | 577 | "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", |
612 | HOSTKEY_FILE, keyfile); | 578 | HOSTKEY_FILE, keyfile); |
613 | GNUNET_free (keyfile); | 579 | GNUNET_free(keyfile); |
614 | end_badly_now (); | 580 | end_badly_now (); |
615 | return; | 581 | return; |
616 | } | 582 | } |
617 | 583 | ||
618 | |||
619 | max_connect_per_transport = (uint32_t) tneigh; | 584 | max_connect_per_transport = (uint32_t) tneigh; |
620 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); | 585 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); |
621 | GNUNET_free (keyfile); | 586 | GNUNET_free(keyfile); |
622 | if (NULL == my_private_key) | 587 | if (NULL == my_private_key) |
623 | { | 588 | { |
624 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 589 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
625 | "Could not access hostkey. Exiting.\n"); | 590 | "Could not access hostkey. Exiting.\n"); |
626 | end_badly_now (); | 591 | end_badly_now (); |
627 | return; | 592 | return; |
628 | } | 593 | } |
@@ -633,18 +598,18 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
633 | /* load plugins... */ | 598 | /* load plugins... */ |
634 | setup_plugin_environment (); | 599 | setup_plugin_environment (); |
635 | 600 | ||
636 | GNUNET_assert (strlen (argv[0]) > strlen ("test_plugin_")); | 601 | GNUNET_assert(strlen (argv[0]) > strlen ("test_plugin_")); |
637 | plugin = strstr(argv[0],"test_plugin_"); | 602 | plugin = strstr (argv[0], "test_plugin_"); |
638 | sep = strrchr(argv[0],'.'); | 603 | sep = strrchr (argv[0], '.'); |
639 | if (NULL == plugin) | 604 | if (NULL == plugin) |
640 | { | 605 | { |
641 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); | 606 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); |
642 | end_badly_now (); | 607 | end_badly_now (); |
643 | return; | 608 | return; |
644 | } | 609 | } |
645 | plugin += strlen ("test_plugin_"); | 610 | plugin += strlen ("test_plugin_"); |
646 | if (NULL != sep) | 611 | if (NULL != sep) |
647 | sep[0] = '\0'; | 612 | sep[0] = '\0'; |
648 | 613 | ||
649 | /* Hack for WLAN: start a second helper */ | 614 | /* Hack for WLAN: start a second helper */ |
650 | if (0 == strcmp (plugin, "wlan")) | 615 | if (0 == strcmp (plugin, "wlan")) |
@@ -654,77 +619,73 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
654 | helper_argv[1] = (char *) "2"; | 619 | helper_argv[1] = (char *) "2"; |
655 | helper_argv[2] = NULL; | 620 | helper_argv[2] = NULL; |
656 | suid_helper = GNUNET_HELPER_start (GNUNET_NO, | 621 | suid_helper = GNUNET_HELPER_start (GNUNET_NO, |
657 | "gnunet-helper-transport-wlan-dummy", | 622 | "gnunet-helper-transport-wlan-dummy", helper_argv, |
658 | helper_argv, | 623 | &handle_helper_message, NULL, NULL ); |
659 | &handle_helper_message, | ||
660 | NULL, | ||
661 | NULL); | ||
662 | } | 624 | } |
663 | 625 | ||
664 | /* Loading plugin */ | 626 | /* Loading plugin */ |
665 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); | 627 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); |
666 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); | 628 | GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); |
667 | api = GNUNET_PLUGIN_load (libname, &env); | 629 | api = GNUNET_PLUGIN_load (libname, &env); |
668 | if (api == NULL) | 630 | if (api == NULL ) |
669 | { | 631 | { |
670 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 632 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
671 | "Failed to load transport plugin for %s\n", plugin); | 633 | "Failed to load transport plugin for %s\n", plugin); |
672 | end_badly_now (); | 634 | end_badly_now (); |
673 | return; | 635 | return; |
674 | } | 636 | } |
675 | 637 | ||
676 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); | 638 | timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); |
677 | 639 | ||
678 | /* Check if all functions are implemented */ | 640 | /* Check if all functions are implemented */ |
679 | if (NULL == api->address_pretty_printer) | 641 | if (NULL == api->address_pretty_printer) |
680 | { | 642 | { |
681 | GNUNET_break (0); | 643 | GNUNET_break(0); |
682 | end_badly_now (); | 644 | end_badly_now (); |
683 | return; | 645 | return; |
684 | } | 646 | } |
685 | if (NULL == api->address_to_string) | 647 | if (NULL == api->address_to_string) |
686 | { | 648 | { |
687 | GNUNET_break (0); | 649 | GNUNET_break(0); |
688 | end_badly_now (); | 650 | end_badly_now (); |
689 | return; | 651 | return; |
690 | } | 652 | } |
691 | GNUNET_assert (NULL != api->check_address); | 653 | GNUNET_assert(NULL != api->check_address); |
692 | if (NULL == api->check_address) | 654 | if (NULL == api->check_address) |
693 | { | 655 | { |
694 | GNUNET_break (0); | 656 | GNUNET_break(0); |
695 | end_badly_now (); | 657 | end_badly_now (); |
696 | return; | 658 | return; |
697 | } | 659 | } |
698 | GNUNET_assert (NULL != api->disconnect_peer); | 660 | GNUNET_assert(NULL != api->disconnect_peer); |
699 | if (NULL == api->disconnect_peer) | 661 | if (NULL == api->disconnect_peer) |
700 | { | 662 | { |
701 | GNUNET_break (0); | 663 | GNUNET_break(0); |
702 | end_badly_now (); | 664 | end_badly_now (); |
703 | return; | 665 | return; |
704 | } | 666 | } |
705 | GNUNET_assert (NULL != api->get_session); | 667 | GNUNET_assert(NULL != api->get_session); |
706 | if (NULL == api->get_session) | 668 | if (NULL == api->get_session) |
707 | { | 669 | { |
708 | GNUNET_break (0); | 670 | GNUNET_break(0); |
709 | end_badly_now (); | 671 | end_badly_now (); |
710 | return; | 672 | return; |
711 | } | 673 | } |
712 | if (NULL == api->address_pretty_printer) | 674 | if (NULL == api->address_pretty_printer) |
713 | { | 675 | { |
714 | GNUNET_break (0); | 676 | GNUNET_break(0); |
715 | end_badly_now (); | 677 | end_badly_now (); |
716 | return; | 678 | return; |
717 | } | 679 | } |
718 | if (NULL == api->string_to_address) | 680 | if (NULL == api->string_to_address) |
719 | { | 681 | { |
720 | GNUNET_break (0); | 682 | GNUNET_break(0); |
721 | end_badly_now (); | 683 | end_badly_now (); |
722 | return; | 684 | return; |
723 | } | 685 | } |
724 | 686 | ||
725 | } | 687 | } |
726 | 688 | ||
727 | |||
728 | /** | 689 | /** |
729 | * The main function for the test | 690 | * The main function for the test |
730 | * | 691 | * |
@@ -733,32 +694,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
733 | * @return 0 ok, 1 on error | 694 | * @return 0 ok, 1 on error |
734 | */ | 695 | */ |
735 | int | 696 | int |
736 | main (int argc, char *const *argv) | 697 | main (int argc, char * const *argv) |
737 | { | 698 | { |
738 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 699 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
739 | GNUNET_GETOPT_OPTION_END | 700 | GNUNET_GETOPT_OPTION_END }; |
740 | }; | ||
741 | int ret; | 701 | int ret; |
742 | 702 | ||
743 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); | 703 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); |
744 | 704 | ||
745 | char *const argv_prog[] = { | 705 | char * const argv_prog[] = { "test_plugin_transport", "-c", |
746 | "test_plugin_transport", | 706 | "test_plugin_transport_data.conf", NULL }; |
747 | "-c", | 707 | GNUNET_log_setup ("test-plugin-transport", "WARNING", NULL ); |
748 | "test_plugin_transport_data.conf", | 708 | ok = 1; /* set to fail */ |
749 | NULL | 709 | ret = |
750 | }; | 710 | (GNUNET_OK |
751 | GNUNET_log_setup ("test-plugin-transport", | 711 | == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport", |
752 | "WARNING", | 712 | "testcase", options, &run, (void *) argv)) ? ok : 1; |
753 | NULL); | ||
754 | ok = 1; /* set to fail */ | ||
755 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (3, | ||
756 | argv_prog, | ||
757 | "test-plugin-transport", | ||
758 | "testcase", | ||
759 | options, | ||
760 | &run, | ||
761 | (void *) argv)) ? ok : 1; | ||
762 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); | 713 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport"); |
763 | return ret; | 714 | return ret; |
764 | } | 715 | } |
diff --git a/src/transport/transport.h b/src/transport/transport.h index beea4031e..5a2f04056 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -461,6 +461,11 @@ struct PeerIterateResponseMessage | |||
461 | struct GNUNET_TIME_AbsoluteNBO state_timeout; | 461 | struct GNUNET_TIME_AbsoluteNBO state_timeout; |
462 | 462 | ||
463 | /** | 463 | /** |
464 | * Local info about the address | ||
465 | */ | ||
466 | uint32_t local_address_info GNUNET_PACKED; | ||
467 | |||
468 | /** | ||
464 | * State this peer is in as #GNUNET_TRANSPORT_PeerState enumeration element | 469 | * State this peer is in as #GNUNET_TRANSPORT_PeerState enumeration element |
465 | */ | 470 | */ |
466 | uint32_t state GNUNET_PACKED; | 471 | uint32_t state GNUNET_PACKED; |
diff --git a/src/transport/transport_api_monitoring.c b/src/transport/transport_api_monitoring.c index ef7a01040..50517cc6c 100644 --- a/src/transport/transport_api_monitoring.c +++ b/src/transport/transport_api_monitoring.c | |||
@@ -311,8 +311,7 @@ reconnect (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) | |||
311 | * message with the human-readable address | 311 | * message with the human-readable address |
312 | */ | 312 | */ |
313 | static void | 313 | static void |
314 | peer_response_processor (void *cls, | 314 | peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) |
315 | const struct GNUNET_MessageHeader *msg) | ||
316 | { | 315 | { |
317 | struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; | 316 | struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; |
318 | struct PeerIterateResponseMessage *pir_msg; | 317 | struct PeerIterateResponseMessage *pir_msg; |
@@ -432,7 +431,7 @@ peer_response_processor (void *cls, | |||
432 | 431 | ||
433 | /* notify client */ | 432 | /* notify client */ |
434 | address = GNUNET_HELLO_address_allocate (&pir_msg->peer, | 433 | address = GNUNET_HELLO_address_allocate (&pir_msg->peer, |
435 | transport_name, addr, alen); | 434 | transport_name, addr, alen, ntohl(pir_msg->local_address_info)); |
436 | pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, address, | 435 | pal_ctx->cb (pal_ctx->cb_cls, &pir_msg->peer, address, |
437 | ntohl(pir_msg->state), | 436 | ntohl(pir_msg->state), |
438 | GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); | 437 | GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); |