aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c88
1 files changed, 35 insertions, 53 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 386894d48..251b4c356 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -246,8 +246,8 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
246 * @param cls the 'struct NeighbourMapEntry' 246 * @param cls the 'struct NeighbourMapEntry'
247 * @param tc scheduler context 247 * @param tc scheduler context
248 */ 248 */
249static void 249static void transmission_task (void *cls,
250transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 250 const struct GNUNET_SCHEDULER_TaskContext *tc);
251 251
252 252
253/** 253/**
@@ -318,15 +318,11 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
318 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); 318 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
319 n->is_active = mq; 319 n->is_active = mq;
320 mq->n = n; 320 mq->n = n;
321 ret = papi->send (papi->cls, 321 ret =
322 &n->id, 322 papi->send (papi->cls, &n->id, mq->message_buf, mq->message_buf_size,
323 mq->message_buf, 323 0 /* priority -- remove from plugin API? */ ,
324 mq->message_buf_size, 324 timeout, n->session, n->addr, n->addrlen, GNUNET_YES,
325 0 /* priority -- remove from plugin API? */ , 325 &transmit_send_continuation, mq);
326 timeout,
327 n->session,
328 n->addr,
329 n->addrlen, GNUNET_YES, &transmit_send_continuation, mq);
330 if (ret == -1) 326 if (ret == -1)
331 { 327 {
332 /* failure, but 'send' would not call continuation in this case, 328 /* failure, but 'send' would not call continuation in this case,
@@ -361,8 +357,7 @@ transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
361 * @param disconnect_cb function to call if we disconnect from a peer 357 * @param disconnect_cb function to call if we disconnect from a peer
362 */ 358 */
363void 359void
364GST_neighbours_start (void *cls, 360GST_neighbours_start (void *cls, GNUNET_TRANSPORT_NotifyConnect connect_cb,
365 GNUNET_TRANSPORT_NotifyConnect connect_cb,
366 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb) 361 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
367{ 362{
368 callback_cls = cls; 363 callback_cls = cls;
@@ -466,8 +461,7 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
466 struct NeighbourMapEntry *n = value; 461 struct NeighbourMapEntry *n = value;
467 462
468#if DEBUG_TRANSPORT 463#if DEBUG_TRANSPORT
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n",
470 "Disconnecting peer `%4s', %s\n",
471 GNUNET_i2s (&n->id), "SHUTDOWN_TASK"); 465 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
472#endif 466#endif
473 disconnect_neighbour (n); 467 disconnect_neighbour (n);
@@ -481,8 +475,8 @@ disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
481void 475void
482GST_neighbours_stop () 476GST_neighbours_stop ()
483{ 477{
484 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 478 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &disconnect_all_neighbours,
485 &disconnect_all_neighbours, NULL); 479 NULL);
486 GNUNET_CONTAINER_multihashmap_destroy (neighbours); 480 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
487 neighbours = NULL; 481 neighbours = NULL;
488 callback_cls = NULL; 482 callback_cls = NULL;
@@ -506,10 +500,8 @@ GST_neighbours_stop ()
506 */ 500 */
507void 501void
508GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, 502GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
509 const char *plugin_name, 503 const char *plugin_name, const void *address,
510 const void *address, 504 size_t address_len, struct Session *session,
511 size_t address_len,
512 struct Session *session,
513 const struct GNUNET_TRANSPORT_ATS_Information 505 const struct GNUNET_TRANSPORT_ATS_Information
514 *ats, uint32_t ats_count) 506 *ats, uint32_t ats_count)
515{ 507{
@@ -528,8 +520,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
528 n->addrlen = address_len; 520 n->addrlen = address_len;
529 n->session = session; 521 n->session = session;
530 GNUNET_array_grow (n->ats, n->ats_count, ats_count); 522 GNUNET_array_grow (n->ats, n->ats_count, ats_count);
531 memcpy (n->ats, 523 memcpy (n->ats, ats,
532 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 524 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
533 GNUNET_free_non_null (n->plugin_name); 525 GNUNET_free_non_null (n->plugin_name);
534 n->plugin_name = GNUNET_strdup (plugin_name); 526 n->plugin_name = GNUNET_strdup (plugin_name);
535 GNUNET_SCHEDULER_cancel (n->timeout_task); 527 GNUNET_SCHEDULER_cancel (n->timeout_task);
@@ -538,9 +530,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
538 &neighbour_timeout_task, n); 530 &neighbour_timeout_task, n);
539 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 531 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
540 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 532 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
541 GST_neighbours_send (peer, 533 GST_neighbours_send (peer, &connect_msg, sizeof (connect_msg),
542 &connect_msg,
543 sizeof (connect_msg),
544 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL); 534 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
545} 535}
546 536
@@ -558,10 +548,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
558 * @param ats_count number of performance records in 'ats' 548 * @param ats_count number of performance records in 'ats'
559 */ 549 */
560static void 550static void
561try_connect_using_address (void *cls, 551try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target,
562 const struct GNUNET_PeerIdentity *target, 552 const char *plugin_name, const void *plugin_address,
563 const char *plugin_name,
564 const void *plugin_address,
565 size_t plugin_address_len, 553 size_t plugin_address_len,
566 struct GNUNET_BANDWIDTH_Value32NBO bandwidth, 554 struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
567 const struct GNUNET_TRANSPORT_ATS_Information *ats, 555 const struct GNUNET_TRANSPORT_ATS_Information *ats,
@@ -570,9 +558,7 @@ try_connect_using_address (void *cls,
570 struct NeighbourMapEntry *n = cls; 558 struct NeighbourMapEntry *n = cls;
571 559
572 n->asc = NULL; 560 n->asc = NULL;
573 GST_neighbours_switch_to_address (target, 561 GST_neighbours_switch_to_address (target, plugin_name, plugin_address,
574 plugin_name,
575 plugin_address,
576 plugin_address_len, NULL, ats, ats_count); 562 plugin_address_len, NULL, ats, ats_count);
577 if (GNUNET_YES == n->is_connected) 563 if (GNUNET_YES == n->is_connected)
578 return; 564 return;
@@ -591,9 +577,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
591{ 577{
592 struct NeighbourMapEntry *n; 578 struct NeighbourMapEntry *n;
593 579
594 GNUNET_assert (0 != memcmp (target, 580 GNUNET_assert (0 !=
595 &GST_my_identity, 581 memcmp (target, &GST_my_identity,
596 sizeof (struct GNUNET_PeerIdentity))); 582 sizeof (struct GNUNET_PeerIdentity)));
597 n = lookup_neighbour (target); 583 n = lookup_neighbour (target);
598 if ((NULL != n) && (GNUNET_YES == n->is_connected)) 584 if ((NULL != n) && (GNUNET_YES == n->is_connected))
599 return; /* already connected */ 585 return; /* already connected */
@@ -614,8 +600,9 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
614 } 600 }
615 if (n->asc != NULL) 601 if (n->asc != NULL)
616 return; /* already trying */ 602 return; /* already trying */
617 n->asc = GNUNET_ATS_suggest_address (GST_ats, 603 n->asc =
618 target, &try_connect_using_address, n); 604 GNUNET_ATS_suggest_address (GST_ats, target, &try_connect_using_address,
605 n);
619} 606}
620 607
621 608
@@ -684,10 +671,8 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
684 * @param cont_cls closure for 'cont' 671 * @param cont_cls closure for 'cont'
685 */ 672 */
686void 673void
687GST_neighbours_send (const struct GNUNET_PeerIdentity *target, 674GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
688 const void *msg, 675 size_t msg_size, struct GNUNET_TIME_Relative timeout,
689 size_t msg_size,
690 struct GNUNET_TIME_Relative timeout,
691 GST_NeighbourSendContinuation cont, void *cont_cls) 676 GST_NeighbourSendContinuation cont, void *cont_cls)
692{ 677{
693 struct NeighbourMapEntry *n; 678 struct NeighbourMapEntry *n;
@@ -785,8 +770,8 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
785#if DEBUG_TRANSPORT 770#if DEBUG_TRANSPORT
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
787 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n", 772 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n",
788 (unsigned long long) n-> 773 (unsigned long long) n->in_tracker.
789 in_tracker.consumption_since_last_update__, 774 consumption_since_last_update__,
790 (unsigned int) n->in_tracker.available_bytes_per_s__, 775 (unsigned int) n->in_tracker.available_bytes_per_s__,
791 (unsigned long long) ret.rel_value); 776 (unsigned long long) ret.rel_value);
792#endif 777#endif
@@ -850,13 +835,12 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
850 if (0 != ntohl (quota.value__)) 835 if (0 != ntohl (quota.value__))
851 return; 836 return;
852#if DEBUG_TRANSPORT 837#if DEBUG_TRANSPORT
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s' due to `%s'\n",
854 "Disconnecting peer `%4s' due to `%s'\n",
855 GNUNET_i2s (&n->id), "SET_QUOTA"); 839 GNUNET_i2s (&n->id), "SET_QUOTA");
856#endif 840#endif
857 GNUNET_STATISTICS_update (GST_stats, 841 GNUNET_STATISTICS_update (GST_stats,
858 gettext_noop ("# disconnects due to quota of 0"), 842 gettext_noop ("# disconnects due to quota of 0"), 1,
859 1, GNUNET_NO); 843 GNUNET_NO);
860 disconnect_neighbour (n); 844 disconnect_neighbour (n);
861} 845}
862 846
@@ -939,13 +923,11 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
939 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 923 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
940 papi = GST_plugins_find (n->plugin_name); 924 papi = GST_plugins_find (n->plugin_name);
941 if (papi != NULL) 925 if (papi != NULL)
942 papi->send (papi->cls, 926 papi->send (papi->cls, target, (const void *) &disconnect_msg,
943 target,
944 (const void *) &disconnect_msg,
945 sizeof (struct GNUNET_MessageHeader), 927 sizeof (struct GNUNET_MessageHeader),
946 UINT32_MAX /* priority */ , 928 UINT32_MAX /* priority */ ,
947 GNUNET_TIME_UNIT_FOREVER_REL, 929 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->addr, n->addrlen,
948 n->session, n->addr, n->addrlen, GNUNET_YES, NULL, NULL); 930 GNUNET_YES, NULL, NULL);
949 } 931 }
950 disconnect_neighbour (n); 932 disconnect_neighbour (n);
951} 933}