aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-transport.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-transport.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-transport.c')
-rw-r--r--src/transport/gnunet-transport.c87
1 files changed, 85 insertions, 2 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 684b5a92c..119584810 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -124,6 +124,11 @@ static int monitor_validation;
124static int try_connect; 124static int try_connect;
125 125
126/** 126/**
127 * Option -D.
128 */
129static int try_disconnect;
130
131/**
127 * Option -n. 132 * Option -n.
128 */ 133 */
129static int numeric; 134static int numeric;
@@ -836,6 +841,25 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
836 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity))) 841 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
837 return; 842 return;
838 843
844 if (try_disconnect)
845 {
846 /* all done, terminate instantly */
847 FPRINTF (stdout, _("Successfully disconnected from `%s'\n"),
848 GNUNET_i2s_full (peer));
849 ret = 0;
850
851 if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
852 {
853 GNUNET_SCHEDULER_cancel (op_timeout);
854 op_timeout = GNUNET_SCHEDULER_NO_TASK;
855 }
856
857 if (GNUNET_SCHEDULER_NO_TASK != end)
858 GNUNET_SCHEDULER_cancel (end);
859 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
860 return;
861 }
862
839 if (NULL != th) 863 if (NULL != th)
840 { 864 {
841 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 865 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
@@ -1159,6 +1183,31 @@ try_connect_cb (void *cls, const int result)
1159 } 1183 }
1160} 1184}
1161 1185
1186static void
1187try_disconnect_cb (void *cls, const int result)
1188{
1189 static int retries = 0;
1190 if (GNUNET_OK == result)
1191 {
1192 tc_handle = NULL;
1193 return;
1194 }
1195 retries++;
1196 if (retries < 10)
1197 tc_handle = GNUNET_TRANSPORT_try_disconnect (handle, &pid, try_disconnect_cb,
1198 NULL );
1199 else
1200 {
1201 FPRINTF (stderr, "%s",
1202 _("Failed to send connect request to transport service\n") );
1203 if (GNUNET_SCHEDULER_NO_TASK != end)
1204 GNUNET_SCHEDULER_cancel (end);
1205 ret = 1;
1206 end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1207 return;
1208 }
1209}
1210
1162/** 1211/**
1163 * Function called with the result of the check if the 'transport' 1212 * Function called with the result of the check if the 'transport'
1164 * service is running. 1213 * service is running.
@@ -1188,7 +1237,7 @@ testservice_task (void *cls, int result)
1188 } 1237 }
1189 1238
1190 counter = benchmark_send + benchmark_receive + iterate_connections 1239 counter = benchmark_send + benchmark_receive + iterate_connections
1191 + monitor_connections + monitor_connects + try_connect 1240 + monitor_connections + monitor_connects + try_connect + try_disconnect +
1192 + iterate_validation + monitor_validation; 1241 + iterate_validation + monitor_validation;
1193 1242
1194 if (1 < counter) 1243 if (1 < counter)
@@ -1238,6 +1287,36 @@ testservice_task (void *cls, int result)
1238 NULL ); 1287 NULL );
1239 1288
1240 } 1289 }
1290 else if (try_disconnect) /* -D: Disconnect from peer */
1291 {
1292 if (NULL == cpid)
1293 {
1294 FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
1295 "-D", "-p");
1296 ret = 1;
1297 return;
1298 }
1299 handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
1300 &notify_connect, &notify_disconnect);
1301 if (NULL == handle)
1302 {
1303 FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
1304 ret = 1;
1305 return;
1306 }
1307 tc_handle = GNUNET_TRANSPORT_try_disconnect (handle, &pid, try_disconnect_cb,
1308 NULL );
1309 if (NULL == tc_handle)
1310 {
1311 FPRINTF (stderr, "%s",
1312 _("Failed to send request to transport service\n") );
1313 ret = 1;
1314 return;
1315 }
1316 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1317 NULL );
1318
1319 }
1241 else if (benchmark_send) /* -s: Benchmark sending */ 1320 else if (benchmark_send) /* -s: Benchmark sending */
1242 { 1321 {
1243 if (NULL == cpid) 1322 if (NULL == cpid)
@@ -1367,9 +1446,13 @@ main (int argc, char * const *argv)
1367 0, &GNUNET_GETOPT_set_one, &iterate_all }, 1446 0, &GNUNET_GETOPT_set_one, &iterate_all },
1368 { 'b', "benchmark", NULL, 1447 { 'b', "benchmark", NULL,
1369 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"), 1448 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1370 0, &GNUNET_GETOPT_set_one, &benchmark_receive }, { 'C', "connect", 1449 0, &GNUNET_GETOPT_set_one, &benchmark_receive },
1450 { 'C', "connect",
1371 NULL, gettext_noop ("connect to a peer"), 0, 1451 NULL, gettext_noop ("connect to a peer"), 0,
1372 &GNUNET_GETOPT_set_one, &try_connect }, 1452 &GNUNET_GETOPT_set_one, &try_connect },
1453 { 'D', "disconnect",
1454 NULL, gettext_noop ("disconnect to a peer"), 0,
1455 &GNUNET_GETOPT_set_one, &try_disconnect },
1373 { 'd', "validation", NULL, 1456 { 'd', "validation", NULL,
1374 gettext_noop ("print information for all pending validations "), 1457 gettext_noop ("print information for all pending validations "),
1375 0, &GNUNET_GETOPT_set_one, &iterate_validation }, 1458 0, &GNUNET_GETOPT_set_one, &iterate_validation },