aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-03-27 16:51:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-03-27 16:51:32 +0000
commit25fea659b134e2716aa95edc8f6267603e08ce61 (patch)
treefe0eb5a7fdaca512c833f930486942d688e6cfd7 /src/transport/gnunet-service-transport_neighbours.c
parent075f1356987b48d3afd3f5c01ddebe23fa0ae240 (diff)
downloadgnunet-25fea659b134e2716aa95edc8f6267603e08ce61.tar.gz
gnunet-25fea659b134e2716aa95edc8f6267603e08ce61.zip
added functionality to use the CLI to disconnect peers
fixed DISCONNECT functionality
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 025cf5f76..7d2ceb524 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -46,7 +46,7 @@
46 * Time we give plugin to transmit DISCONNECT message before the 46 * Time we give plugin to transmit DISCONNECT message before the
47 * neighbour entry self-destructs. 47 * neighbour entry self-destructs.
48 */ 48 */
49#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100) 49#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
50 50
51/** 51/**
52 * How often must a peer violate bandwidth quotas before we start 52 * How often must a peer violate bandwidth quotas before we start
@@ -1054,7 +1054,7 @@ send_disconnect (struct NeighbourMapEntry *n)
1054{ 1054{
1055 struct SessionDisconnectMessage disconnect_msg; 1055 struct SessionDisconnectMessage disconnect_msg;
1056 1056
1057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1057 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1058 "Sending DISCONNECT message to peer `%4s'\n", 1058 "Sending DISCONNECT message to peer `%4s'\n",
1059 GNUNET_i2s (&n->id)); 1059 GNUNET_i2s (&n->id));
1060 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage)); 1060 disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
@@ -1075,10 +1075,9 @@ send_disconnect (struct NeighbourMapEntry *n)
1075 &disconnect_msg.purpose, 1075 &disconnect_msg.purpose,
1076 &disconnect_msg.signature)); 1076 &disconnect_msg.signature));
1077 1077
1078 (void) send_with_session (n, 1078 (void) send_with_session (n, (const char *) &disconnect_msg,
1079 (const char *) &disconnect_msg, sizeof (disconnect_msg), 1079 sizeof (disconnect_msg), UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
1080 UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, 1080 GNUNET_NO, &send_disconnect_cont, NULL );
1081 GNUNET_NO, &send_disconnect_cont, NULL);
1082 GNUNET_STATISTICS_update (GST_stats, 1081 GNUNET_STATISTICS_update (GST_stats,
1083 gettext_noop 1082 gettext_noop
1084 ("# DISCONNECT messages sent"), 1, 1083 ("# DISCONNECT messages sent"), 1,
@@ -1113,7 +1112,6 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1113 break; 1112 break;
1114 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS: 1113 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
1115 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ 1114 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1116 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED);
1117 free_neighbour (n, GNUNET_NO); 1115 free_neighbour (n, GNUNET_NO);
1118 return; 1116 return;
1119 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK: 1117 case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
@@ -1121,6 +1119,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1121 send_disconnect (n); 1119 send_disconnect (n);
1122 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); 1120 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
1123 break; 1121 break;
1122 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
1124 case GNUNET_TRANSPORT_PS_CONNECTED: 1123 case GNUNET_TRANSPORT_PS_CONNECTED:
1125 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1124 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1126 /* we are currently connected, need to send disconnect and do 1125 /* we are currently connected, need to send disconnect and do
@@ -1134,13 +1133,9 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1134 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT); 1133 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
1135 break; 1134 break;
1136 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 1135 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
1137 /* ATS address request timeout, disconnect without sending disconnect message */ 1136 /* Disconnecting while waiting for an ATS address to reconnect,
1138 GNUNET_STATISTICS_set (GST_stats, 1137 * cannot send DISCONNECT */
1139 gettext_noop ("# peers connected"), 1138 free_neighbour (n, GNUNET_NO);
1140 --neighbours_connected,
1141 GNUNET_NO);
1142 disconnect_notify_cb (callback_cls, &n->id);
1143 set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
1144 break; 1139 break;
1145 case GNUNET_TRANSPORT_PS_DISCONNECT: 1140 case GNUNET_TRANSPORT_PS_DISCONNECT:
1146 /* already disconnected, ignore */ 1141 /* already disconnected, ignore */
@@ -1680,7 +1675,7 @@ send_session_connect_cont (void *cls,
1680 n->primary_address.session); 1675 n->primary_address.session);
1681 GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL ); 1676 GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL );
1682 unset_primary_address (n); 1677 unset_primary_address (n);
1683 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1678 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
1684 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 1679 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1685 break; 1680 break;
1686 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1681 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
@@ -1689,7 +1684,7 @@ send_session_connect_cont (void *cls,
1689 n->primary_address.session); 1684 n->primary_address.session);
1690 GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL ); 1685 GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL );
1691 unset_primary_address (n); 1686 unset_primary_address (n);
1692 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, 1687 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1693 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1688 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1694 break; 1689 break;
1695 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT: 1690 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
@@ -1769,7 +1764,7 @@ send_session_connect (struct NeighbourAddress *na)
1769 case GNUNET_TRANSPORT_PS_CONNECT_SENT: 1764 case GNUNET_TRANSPORT_PS_CONNECT_SENT:
1770 /* Remove address and request and additional one */ 1765 /* Remove address and request and additional one */
1771 unset_primary_address (n); 1766 unset_primary_address (n);
1772 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1767 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
1773 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 1768 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1774 /* Hard failure to send the CONNECT message with this address: 1769 /* Hard failure to send the CONNECT message with this address:
1775 Destroy address and session */ 1770 Destroy address and session */
@@ -1777,7 +1772,7 @@ send_session_connect (struct NeighbourAddress *na)
1777 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1772 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1778 /* Remove address and request and additional one */ 1773 /* Remove address and request and additional one */
1779 unset_primary_address (n); 1774 unset_primary_address (n);
1780 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, 1775 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1781 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1776 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1782 break; 1777 break;
1783 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT: 1778 case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
@@ -3284,6 +3279,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3284 free_neighbour (n, GNUNET_NO); 3279 free_neighbour (n, GNUNET_NO);
3285 return GNUNET_YES; 3280 return GNUNET_YES;
3286 case GNUNET_TRANSPORT_PS_CONNECTED: 3281 case GNUNET_TRANSPORT_PS_CONNECTED:
3282 /* Our primary connection died, try a fast reconnect */
3287 unset_primary_address (n); 3283 unset_primary_address (n);
3288 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3284 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3289 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3285 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
@@ -3315,7 +3311,9 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3315 free_address (&n->primary_address); 3311 free_address (&n->primary_address);
3316 n->primary_address = n->alternative_address; 3312 n->primary_address = n->alternative_address;
3317 memset (&n->alternative_address, 0, sizeof (struct NeighbourAddress)); 3313 memset (&n->alternative_address, 0, sizeof (struct NeighbourAddress));
3318 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 3314 /* FIXME: Why GNUNET_TRANSPORT_PS_RECONNECT_ATS ?*/
3315 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3316 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
3319 break; 3317 break;
3320 case GNUNET_TRANSPORT_PS_DISCONNECT: 3318 case GNUNET_TRANSPORT_PS_DISCONNECT:
3321 free_address (&n->primary_address); 3319 free_address (&n->primary_address);
@@ -3473,6 +3471,21 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
3473 disconnect_neighbour (n); 3471 disconnect_neighbour (n);
3474} 3472}
3475 3473
3474void delayed_disconnect (void *cls,
3475 const struct GNUNET_SCHEDULER_TaskContext* tc)
3476{
3477 struct NeighbourMapEntry *n = cls;
3478 if (GNUNET_YES == test_connected (n))
3479 GNUNET_STATISTICS_update (GST_stats,
3480 gettext_noop
3481 ("# other peer asked to disconnect from us"), 1,
3482 GNUNET_NO);
3483 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3484 "Disconnecting by request from peer %s\n",
3485 GNUNET_i2s (&n->id));
3486 free_neighbour (n, GNUNET_NO);
3487}
3488
3476 3489
3477/** 3490/**
3478 * We received a disconnect message from the given peer, 3491 * We received a disconnect message from the given peer,
@@ -3493,10 +3506,10 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
3493 GNUNET_i2s (peer)); 3506 GNUNET_i2s (peer));
3494 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage)) 3507 if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
3495 { 3508 {
3496 // GNUNET_break_op (0); 3509 GNUNET_break_op (0);
3497 GNUNET_STATISTICS_update (GST_stats, 3510 GNUNET_STATISTICS_update (GST_stats,
3498 gettext_noop 3511 gettext_noop
3499 ("# disconnect messages ignored (old format)"), 1, 3512 ("# disconnect messages ignored (malformed)"), 1,
3500 GNUNET_NO); 3513 GNUNET_NO);
3501 return; 3514 return;
3502 } 3515 }
@@ -3544,15 +3557,7 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer
3544 GNUNET_break_op (0); 3557 GNUNET_break_op (0);
3545 return; 3558 return;
3546 } 3559 }
3547 if (GNUNET_YES == test_connected (n)) 3560 GNUNET_SCHEDULER_add_now (&delayed_disconnect, n);
3548 GNUNET_STATISTICS_update (GST_stats,
3549 gettext_noop
3550 ("# other peer asked to disconnect from us"), 1,
3551 GNUNET_NO);
3552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3553 "Disconnecting by request from peer %s\n",
3554 GNUNET_i2s (peer));
3555 disconnect_neighbour (n);
3556} 3561}
3557 3562
3558 3563
@@ -3782,9 +3787,8 @@ GST_neighbours_stop ()
3782 util_transmission_tk = GNUNET_SCHEDULER_NO_TASK; 3787 util_transmission_tk = GNUNET_SCHEDULER_NO_TASK;
3783 } 3788 }
3784 3789
3785 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 3790 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &disconnect_all_neighbours,
3786 &disconnect_all_neighbours, 3791 NULL );
3787 NULL);
3788 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 3792 GNUNET_CONTAINER_multipeermap_destroy (neighbours);
3789 3793
3790 next = pending_bc_head; 3794 next = pending_bc_head;