diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-14 19:35:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-14 19:35:28 +0000 |
commit | e29dc6a80c57c9dfdfc0bc2415497ca88b990b30 (patch) | |
tree | f92b989c4cf3cae42091c6d53b209c125bedcaac /src | |
parent | b4b8ee35e09ef1828a342355cd0e6ca58fc6441e (diff) | |
download | gnunet-e29dc6a80c57c9dfdfc0bc2415497ca88b990b30.tar.gz gnunet-e29dc6a80c57c9dfdfc0bc2415497ca88b990b30.zip |
implement fast reconnect, handle disconnect better
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index c310afc22..211595b51 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -514,26 +514,6 @@ GST_neighbours_stop () | |||
514 | 514 | ||
515 | 515 | ||
516 | /** | 516 | /** |
517 | * A session was terminated. Take note. | ||
518 | * | ||
519 | * @param peer identity of the peer where the session died | ||
520 | * @param session session that is gone | ||
521 | */ | ||
522 | void | ||
523 | GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | ||
524 | struct Session *session) | ||
525 | { | ||
526 | struct NeighbourMapEntry *n; | ||
527 | |||
528 | n = lookup_neighbour (peer); | ||
529 | if (NULL == n) | ||
530 | return; | ||
531 | if (session == n->session) | ||
532 | n->session = NULL; | ||
533 | } | ||
534 | |||
535 | |||
536 | /** | ||
537 | * For an existing neighbour record, set the active connection to | 517 | * For an existing neighbour record, set the active connection to |
538 | * the given address. | 518 | * the given address. |
539 | * | 519 | * |
@@ -693,6 +673,43 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) | |||
693 | 673 | ||
694 | 674 | ||
695 | /** | 675 | /** |
676 | * A session was terminated. Take note. | ||
677 | * | ||
678 | * @param peer identity of the peer where the session died | ||
679 | * @param session session that is gone | ||
680 | */ | ||
681 | void | ||
682 | GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | ||
683 | struct Session *session) | ||
684 | { | ||
685 | struct NeighbourMapEntry *n; | ||
686 | |||
687 | n = lookup_neighbour (peer); | ||
688 | if (NULL == n) | ||
689 | return; | ||
690 | if (session != n->session) | ||
691 | return; /* doesn't affect us */ | ||
692 | n->session = NULL; | ||
693 | if (GNUNET_YES != n->is_connected) | ||
694 | return; /* not connected anymore anyway, shouldn't matter */ | ||
695 | /* try QUICKLY to re-establish a connection, reduce timeout! */ | ||
696 | if (NULL != n->ats) | ||
697 | { | ||
698 | /* how can this be!? */ | ||
699 | GNUNET_break (0); | ||
700 | return; | ||
701 | } | ||
702 | GNUNET_SCHEDULER_cancel (n->timeout_task); | ||
703 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
704 | &neighbour_timeout_task, n); | ||
705 | n->asc = GNUNET_ATS_suggest_address (GST_ats, | ||
706 | peer, | ||
707 | &try_connect_using_address, | ||
708 | n); | ||
709 | } | ||
710 | |||
711 | |||
712 | /** | ||
696 | * Transmit a message to the given target using the active connection. | 713 | * Transmit a message to the given target using the active connection. |
697 | * | 714 | * |
698 | * @param target destination | 715 | * @param target destination |
@@ -947,21 +964,27 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) | |||
947 | struct GNUNET_MessageHeader disconnect_msg; | 964 | struct GNUNET_MessageHeader disconnect_msg; |
948 | 965 | ||
949 | n = lookup_neighbour (target); | 966 | n = lookup_neighbour (target); |
950 | disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 967 | if (NULL == n) |
951 | disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); | 968 | return; /* not active */ |
952 | papi = GST_plugins_find (n->plugin_name); | 969 | if (GNUNET_YES == n->is_connected) |
953 | if (papi != NULL) | 970 | { |
954 | papi->send (papi->cls, | 971 | /* we're actually connected, send DISCONNECT message */ |
955 | target, | 972 | disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
956 | (const void*) &disconnect_msg, | 973 | disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); |
957 | sizeof (struct GNUNET_MessageHeader), | 974 | papi = GST_plugins_find (n->plugin_name); |
958 | UINT32_MAX /* priority */, | 975 | if (papi != NULL) |
959 | GNUNET_TIME_UNIT_FOREVER_REL, | 976 | papi->send (papi->cls, |
960 | n->session, | 977 | target, |
961 | n->addr, | 978 | (const void*) &disconnect_msg, |
962 | n->addrlen, | 979 | sizeof (struct GNUNET_MessageHeader), |
963 | GNUNET_YES, | 980 | UINT32_MAX /* priority */, |
964 | NULL, NULL); | 981 | GNUNET_TIME_UNIT_FOREVER_REL, |
982 | n->session, | ||
983 | n->addr, | ||
984 | n->addrlen, | ||
985 | GNUNET_YES, | ||
986 | NULL, NULL); | ||
987 | } | ||
965 | disconnect_neighbour (n); | 988 | disconnect_neighbour (n); |
966 | } | 989 | } |
967 | 990 | ||