diff options
Diffstat (limited to 'src/dv')
-rw-r--r-- | src/dv/plugin_transport_dv.c | 126 | ||||
-rw-r--r-- | src/dv/test_transport_dv_data.conf | 4 |
2 files changed, 73 insertions, 57 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index df6576f5f..b4de760d2 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c | |||
@@ -130,7 +130,7 @@ struct Session | |||
130 | 130 | ||
131 | /** | 131 | /** |
132 | * Does the transport service know about this session (and we thus | 132 | * Does the transport service know about this session (and we thus |
133 | * need to call 'session_end' when it is released?) | 133 | * need to call `session_end` when it is released?) |
134 | */ | 134 | */ |
135 | int active; | 135 | int active; |
136 | 136 | ||
@@ -182,6 +182,8 @@ notify_distance_change (struct Session *session) | |||
182 | struct Plugin *plugin = session->plugin; | 182 | struct Plugin *plugin = session->plugin; |
183 | struct GNUNET_ATS_Information ats; | 183 | struct GNUNET_ATS_Information ats; |
184 | 184 | ||
185 | if (GNUNET_YES != session->active) | ||
186 | return; | ||
185 | ats.type = htonl ((uint32_t) GNUNET_ATS_QUALITY_NET_DISTANCE); | 187 | ats.type = htonl ((uint32_t) GNUNET_ATS_QUALITY_NET_DISTANCE); |
186 | ats.value = htonl (session->distance); | 188 | ats.value = htonl (session->distance); |
187 | plugin->env->update_address_metrics (plugin->env->cls, | 189 | plugin->env->update_address_metrics (plugin->env->cls, |
@@ -195,10 +197,10 @@ notify_distance_change (struct Session *session) | |||
195 | /** | 197 | /** |
196 | * Function called by MST on each message from the box. | 198 | * Function called by MST on each message from the box. |
197 | * | 199 | * |
198 | * @param cls closure with the 'struct Plugin' | 200 | * @param cls closure with the `struct Plugin *` |
199 | * @param client identification of the client (with the 'struct Session') | 201 | * @param client identification of the client (with the 'struct Session') |
200 | * @param message the actual message | 202 | * @param message the actual message |
201 | * @return GNUNET_OK on success | 203 | * @return #GNUNET_OK on success |
202 | */ | 204 | */ |
203 | static int | 205 | static int |
204 | unbox_cb (void *cls, | 206 | unbox_cb (void *cls, |
@@ -217,7 +219,9 @@ unbox_cb (void *cls, | |||
217 | message, | 219 | message, |
218 | session, "", 0); | 220 | session, "", 0); |
219 | plugin->env->update_address_metrics (plugin->env->cls, | 221 | plugin->env->update_address_metrics (plugin->env->cls, |
220 | &session->sender, NULL, 0, session, &ats, 1); | 222 | &session->sender, NULL, |
223 | 0, session, | ||
224 | &ats, 1); | ||
221 | return GNUNET_OK; | 225 | return GNUNET_OK; |
222 | } | 226 | } |
223 | 227 | ||
@@ -240,11 +244,10 @@ handle_dv_message_received (void *cls, | |||
240 | struct GNUNET_ATS_Information ats; | 244 | struct GNUNET_ATS_Information ats; |
241 | struct Session *session; | 245 | struct Session *session; |
242 | 246 | ||
243 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for peer `%s': new distance %u\n", | 247 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
244 | "DV_MESSAGE_RECEIVED", | 248 | "Received `%s' message for peer `%s': new distance %u\n", |
245 | GNUNET_i2s (sender), distance); | 249 | "DV_MESSAGE_RECEIVED", |
246 | 250 | GNUNET_i2s (sender), distance); | |
247 | |||
248 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, | 251 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, |
249 | sender); | 252 | sender); |
250 | if (NULL == session) | 253 | if (NULL == session) |
@@ -270,14 +273,16 @@ handle_dv_message_received (void *cls, | |||
270 | msg, | 273 | msg, |
271 | session, "", 0); | 274 | session, "", 0); |
272 | plugin->env->update_address_metrics (plugin->env->cls, | 275 | plugin->env->update_address_metrics (plugin->env->cls, |
273 | sender, "", 0, session, &ats, 1); | 276 | sender, "", |
277 | 0, session, | ||
278 | &ats, 1); | ||
274 | } | 279 | } |
275 | 280 | ||
276 | 281 | ||
277 | /** | 282 | /** |
278 | * Function called if DV starts to be able to talk to a peer. | 283 | * Function called if DV starts to be able to talk to a peer. |
279 | * | 284 | * |
280 | * @param cls closure with 'struct Plugin' | 285 | * @param cls closure with `struct Plugin *` |
281 | * @param peer newly connected peer | 286 | * @param peer newly connected peer |
282 | * @param distance distance to the peer | 287 | * @param distance distance to the peer |
283 | * @param network the network the next hop is located in | 288 | * @param network the network the next hop is located in |
@@ -296,10 +301,10 @@ handle_dv_connect (void *cls, | |||
296 | * If you remove it, also remove libgnunetats linkage from Makefile.am | 301 | * If you remove it, also remove libgnunetats linkage from Makefile.am |
297 | */ | 302 | */ |
298 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 303 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
299 | "Received `%s' message for peer `%s' with next hop in network %s \n", | 304 | "Received `%s' message for peer `%s' with next hop in network %s \n", |
300 | "DV_CONNECT", | 305 | "DV_CONNECT", |
301 | GNUNET_i2s (peer), | 306 | GNUNET_i2s (peer), |
302 | GNUNET_ATS_print_network_type (network)); | 307 | GNUNET_ATS_print_network_type (network)); |
303 | 308 | ||
304 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, | 309 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, |
305 | peer); | 310 | peer); |
@@ -307,8 +312,7 @@ handle_dv_connect (void *cls, | |||
307 | { | 312 | { |
308 | GNUNET_break (0); | 313 | GNUNET_break (0); |
309 | session->distance = distance; | 314 | session->distance = distance; |
310 | if (GNUNET_YES == session->active) | 315 | notify_distance_change (session); |
311 | notify_distance_change (session); | ||
312 | return; /* nothing to do */ | 316 | return; /* nothing to do */ |
313 | } | 317 | } |
314 | 318 | ||
@@ -317,30 +321,33 @@ handle_dv_connect (void *cls, | |||
317 | session->plugin = plugin; | 321 | session->plugin = plugin; |
318 | session->distance = distance; | 322 | session->distance = distance; |
319 | session->network = network; | 323 | session->network = network; |
320 | GNUNET_assert( | 324 | GNUNET_assert(GNUNET_YES == |
321 | GNUNET_YES == GNUNET_CONTAINER_multipeermap_put (plugin->sessions, | 325 | GNUNET_CONTAINER_multipeermap_put (plugin->sessions, |
322 | &session->sender, session, | 326 | &session->sender, session, |
323 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 327 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
324 | 328 | ||
325 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 329 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
326 | "Creating new session %p for peer `%s'\n", | 330 | "Creating new session %p for peer `%s'\n", |
327 | session, | 331 | session, |
328 | GNUNET_i2s (peer)); | 332 | GNUNET_i2s (peer)); |
329 | 333 | ||
330 | /* Notify transport and ats about new connection */ | 334 | /* Notify transport and ats about new connection */ |
331 | ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | 335 | ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); |
332 | ats[0].value = htonl (distance); | 336 | ats[0].value = htonl (distance); |
333 | ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE); | 337 | ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE); |
334 | ats[1].value = htonl (network); | 338 | ats[1].value = htonl (network); |
335 | plugin->env->session_start (plugin->env->cls, peer, PLUGIN_NAME, NULL, 0, | 339 | session->active = GNUNET_YES; |
336 | session, ats, 2); | 340 | plugin->env->session_start (plugin->env->cls, peer, |
341 | PLUGIN_NAME, | ||
342 | NULL, 0, | ||
343 | session, ats, 2); | ||
337 | } | 344 | } |
338 | 345 | ||
339 | 346 | ||
340 | /** | 347 | /** |
341 | * Function called if DV distance to a peer is changed. | 348 | * Function called if DV distance to a peer is changed. |
342 | * | 349 | * |
343 | * @param cls closure with 'struct Plugin' | 350 | * @param cls closure with `struct Plugin *` |
344 | * @param peer connected peer | 351 | * @param peer connected peer |
345 | * @param distance new distance to the peer | 352 | * @param distance new distance to the peer |
346 | */ | 353 | */ |
@@ -366,8 +373,7 @@ handle_dv_distance_changed (void *cls, | |||
366 | return; | 373 | return; |
367 | } | 374 | } |
368 | session->distance = distance; | 375 | session->distance = distance; |
369 | if (GNUNET_YES == session->active) | 376 | notify_distance_change (session); |
370 | notify_distance_change (session); | ||
371 | } | 377 | } |
372 | 378 | ||
373 | 379 | ||
@@ -388,14 +394,16 @@ free_session (struct Session *session) | |||
388 | session)); | 394 | session)); |
389 | 395 | ||
390 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 396 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
391 | "Freeing session %p for peer `%s'\n", | 397 | "Freeing session %p for peer `%s'\n", |
392 | session, | 398 | session, |
393 | GNUNET_i2s (&session->sender)); | 399 | GNUNET_i2s (&session->sender)); |
394 | |||
395 | if (GNUNET_YES == session->active) | 400 | if (GNUNET_YES == session->active) |
401 | { | ||
396 | plugin->env->session_end (plugin->env->cls, | 402 | plugin->env->session_end (plugin->env->cls, |
397 | &session->sender, | 403 | &session->sender, |
398 | session); | 404 | session); |
405 | session->active = GNUNET_NO; | ||
406 | } | ||
399 | while (NULL != (pr = session->pr_head)) | 407 | while (NULL != (pr = session->pr_head)) |
400 | { | 408 | { |
401 | GNUNET_CONTAINER_DLL_remove (session->pr_head, | 409 | GNUNET_CONTAINER_DLL_remove (session->pr_head, |
@@ -416,7 +424,7 @@ free_session (struct Session *session) | |||
416 | /** | 424 | /** |
417 | * Function called if DV is no longer able to talk to a peer. | 425 | * Function called if DV is no longer able to talk to a peer. |
418 | * | 426 | * |
419 | * @param cls closure with 'struct Plugin' | 427 | * @param cls closure with `struct Plugin *` |
420 | * @param peer peer that disconnected | 428 | * @param peer peer that disconnected |
421 | */ | 429 | */ |
422 | static void | 430 | static void |
@@ -426,15 +434,14 @@ handle_dv_disconnect (void *cls, | |||
426 | struct Plugin *plugin = cls; | 434 | struct Plugin *plugin = cls; |
427 | struct Session *session; | 435 | struct Session *session; |
428 | 436 | ||
429 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for peer `%s'\n", | 437 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
430 | "DV_DISCONNECT", | 438 | "Received `%s' message for peer `%s'\n", |
431 | GNUNET_i2s (peer)); | 439 | "DV_DISCONNECT", |
432 | 440 | GNUNET_i2s (peer)); | |
433 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, | 441 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, |
434 | peer); | 442 | peer); |
435 | if (NULL == session) | 443 | if (NULL == session) |
436 | return; /* nothing to do */ | 444 | return; /* nothing to do */ |
437 | |||
438 | free_session (session); | 445 | free_session (session); |
439 | } | 446 | } |
440 | 447 | ||
@@ -444,7 +451,7 @@ handle_dv_disconnect (void *cls, | |||
444 | * Clean up the pending request, and call continuations. | 451 | * Clean up the pending request, and call continuations. |
445 | * | 452 | * |
446 | * @param cls closure | 453 | * @param cls closure |
447 | * @param ok GNUNET_OK on success, GNUNET_SYSERR on error | 454 | * @param ok #GNUNET_OK on success, #GNUNET_SYSERR on error |
448 | */ | 455 | */ |
449 | static void | 456 | static void |
450 | send_finished (void *cls, | 457 | send_finished (void *cls, |
@@ -479,7 +486,7 @@ send_finished (void *cls, | |||
479 | * been transmitted (or if the transport is ready | 486 | * been transmitted (or if the transport is ready |
480 | * for the next transmission call; or if the | 487 | * for the next transmission call; or if the |
481 | * peer disconnected...) | 488 | * peer disconnected...) |
482 | * @param cont_cls closure for cont | 489 | * @param cont_cls closure for @a cont |
483 | * @return number of bytes used (on the physical network, with overheads); | 490 | * @return number of bytes used (on the physical network, with overheads); |
484 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 491 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
485 | * and does NOT mean that the message was not transmitted (DV) | 492 | * and does NOT mean that the message was not transmitted (DV) |
@@ -487,7 +494,9 @@ send_finished (void *cls, | |||
487 | static ssize_t | 494 | static ssize_t |
488 | dv_plugin_send (void *cls, | 495 | dv_plugin_send (void *cls, |
489 | struct Session *session, | 496 | struct Session *session, |
490 | const char *msgbuf, size_t msgbuf_size, unsigned int priority, | 497 | const char *msgbuf, |
498 | size_t msgbuf_size, | ||
499 | unsigned int priority, | ||
491 | struct GNUNET_TIME_Relative timeout, | 500 | struct GNUNET_TIME_Relative timeout, |
492 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 501 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
493 | { | 502 | { |
@@ -530,11 +539,12 @@ dv_plugin_send (void *cls, | |||
530 | * from the given peer and cancel all previous transmissions | 539 | * from the given peer and cancel all previous transmissions |
531 | * (and their continuations). | 540 | * (and their continuations). |
532 | * | 541 | * |
533 | * @param cls closure | 542 | * @param cls closure with the `struct Plugin *` |
534 | * @param target peer from which to disconnect | 543 | * @param target peer from which to disconnect |
535 | */ | 544 | */ |
536 | static void | 545 | static void |
537 | dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 546 | dv_plugin_disconnect (void *cls, |
547 | const struct GNUNET_PeerIdentity *target) | ||
538 | { | 548 | { |
539 | struct Plugin *plugin = cls; | 549 | struct Plugin *plugin = cls; |
540 | struct Session *session; | 550 | struct Session *session; |
@@ -573,10 +583,11 @@ dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
573 | * @param numeric should (IP) addresses be displayed in numeric form? | 583 | * @param numeric should (IP) addresses be displayed in numeric form? |
574 | * @param timeout after how long should we give up? | 584 | * @param timeout after how long should we give up? |
575 | * @param asc function to call on each string | 585 | * @param asc function to call on each string |
576 | * @param asc_cls closure for asc | 586 | * @param asc_cls closure for @a asc |
577 | */ | 587 | */ |
578 | static void | 588 | static void |
579 | dv_plugin_address_pretty_printer (void *cls, const char *type, const void *addr, | 589 | dv_plugin_address_pretty_printer (void *cls, const char *type, |
590 | const void *addr, | ||
580 | size_t addrlen, int numeric, | 591 | size_t addrlen, int numeric, |
581 | struct GNUNET_TIME_Relative timeout, | 592 | struct GNUNET_TIME_Relative timeout, |
582 | GNUNET_TRANSPORT_AddressStringCallback asc, | 593 | GNUNET_TRANSPORT_AddressStringCallback asc, |
@@ -594,12 +605,13 @@ dv_plugin_address_pretty_printer (void *cls, const char *type, const void *addr, | |||
594 | * | 605 | * |
595 | * @param cls closure | 606 | * @param cls closure |
596 | * @param addr the (hopefully) DV address | 607 | * @param addr the (hopefully) DV address |
597 | * @param addrlen the length of the address | 608 | * @param addrlen the length of the @a addr |
598 | * | ||
599 | * @return string representing the DV address | 609 | * @return string representing the DV address |
600 | */ | 610 | */ |
601 | static const char * | 611 | static const char * |
602 | dv_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 612 | dv_plugin_address_to_string (void *cls, |
613 | const void *addr, | ||
614 | size_t addrlen) | ||
603 | { | 615 | { |
604 | if (0 != addrlen) | 616 | if (0 != addrlen) |
605 | { | 617 | { |
@@ -622,12 +634,14 @@ dv_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
622 | * @param cls closure | 634 | * @param cls closure |
623 | * @param addr pointer to the address | 635 | * @param addr pointer to the address |
624 | * @param addrlen length of addr | 636 | * @param addrlen length of addr |
625 | * @return GNUNET_OK if this is a plausible address for this peer | 637 | * @return #GNUNET_OK if this is a plausible address for this peer |
626 | * and transport, GNUNET_SYSERR if not | 638 | * and transport, #GNUNET_SYSERR if not |
627 | * | 639 | * |
628 | */ | 640 | */ |
629 | static int | 641 | static int |
630 | dv_plugin_check_address (void *cls, const void *addr, size_t addrlen) | 642 | dv_plugin_check_address (void *cls, |
643 | const void *addr, | ||
644 | size_t addrlen) | ||
631 | { | 645 | { |
632 | if (0 != addrlen) | 646 | if (0 != addrlen) |
633 | return GNUNET_SYSERR; | 647 | return GNUNET_SYSERR; |
@@ -668,11 +682,11 @@ dv_get_session (void *cls, | |||
668 | * | 682 | * |
669 | * @param cls closure ('struct Plugin*') | 683 | * @param cls closure ('struct Plugin*') |
670 | * @param addr string address | 684 | * @param addr string address |
671 | * @param addrlen length of the address including \0 termination | 685 | * @param addrlen length of the @a addr including \0 termination |
672 | * @param buf location to store the buffer | 686 | * @param buf location to store the buffer |
673 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 687 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
674 | * @param added length of created address | 688 | * @param added length of created address |
675 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 689 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
676 | */ | 690 | */ |
677 | static int | 691 | static int |
678 | dv_plugin_string_to_address (void *cls, | 692 | dv_plugin_string_to_address (void *cls, |
@@ -698,7 +712,7 @@ dv_plugin_string_to_address (void *cls, | |||
698 | * used by the next hop here. Or find some other way | 712 | * used by the next hop here. Or find some other way |
699 | * to properly allow ATS-DV resource allocation. | 713 | * to properly allow ATS-DV resource allocation. |
700 | * | 714 | * |
701 | * @param cls closure ('struct Plugin*') | 715 | * @param cls closure (`struct Plugin *`) |
702 | * @param session the session | 716 | * @param session the session |
703 | * @return the network type | 717 | * @return the network type |
704 | */ | 718 | */ |
diff --git a/src/dv/test_transport_dv_data.conf b/src/dv/test_transport_dv_data.conf index 346677a25..6c813223b 100644 --- a/src/dv/test_transport_dv_data.conf +++ b/src/dv/test_transport_dv_data.conf | |||
@@ -3,10 +3,12 @@ | |||
3 | [transport] | 3 | [transport] |
4 | PORT = 2565 | 4 | PORT = 2565 |
5 | PLUGINS = tcp dv | 5 | PLUGINS = tcp dv |
6 | PREFIX = valgrind | ||
6 | 7 | ||
7 | [dv] | 8 | [dv] |
8 | AUTOSTART = YES | 9 | AUTOSTART = YES |
9 | #PREFIX = valgrind | 10 | PREFIX = valgrind |
10 | 11 | ||
11 | [set] | 12 | [set] |
12 | AUTOSTART = YES | 13 | AUTOSTART = YES |
14 | PREFIX = valgrind \ No newline at end of file | ||