diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-12-29 22:21:19 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-12-29 22:21:19 +0000 |
commit | f4a1a3f6b35ecdac7ee395eff2eeecd230fdbd39 (patch) | |
tree | 80fab2c138d2a6d787693fcd67b8899913407169 /src | |
parent | e069ce6318baababf6792335c1277a4b0d856cf2 (diff) | |
download | gnunet-f4a1a3f6b35ecdac7ee395eff2eeecd230fdbd39.tar.gz gnunet-f4a1a3f6b35ecdac7ee395eff2eeecd230fdbd39.zip |
Add echo functionality for mesh CLI
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-mesh.c | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index 8a568cb53..9edfa2331 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c | |||
@@ -59,6 +59,21 @@ static char *channel_id; | |||
59 | static uint32_t listen_port; | 59 | static uint32_t listen_port; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Request echo service | ||
63 | */ | ||
64 | int echo; | ||
65 | |||
66 | /** | ||
67 | * Time of last echo request. | ||
68 | */ | ||
69 | struct GNUNET_TIME_Absolute echo_time; | ||
70 | |||
71 | /** | ||
72 | * Task for next echo request. | ||
73 | */ | ||
74 | GNUNET_SCHEDULER_TaskIdentifier echo_task; | ||
75 | |||
76 | /** | ||
62 | * Peer to connect to. | 77 | * Peer to connect to. |
63 | */ | 78 | */ |
64 | static char *target_id; | 79 | static char *target_id; |
@@ -153,7 +168,14 @@ data_ready (void *cls, size_t size, void *buf) | |||
153 | msg->size = htons (total_size); | 168 | msg->size = htons (total_size); |
154 | msg->type = htons (GNUNET_MESSAGE_TYPE_MESH_CLI); | 169 | msg->type = htons (GNUNET_MESSAGE_TYPE_MESH_CLI); |
155 | memcpy (&msg[1], cls, data_size); | 170 | memcpy (&msg[1], cls, data_size); |
156 | listen_stdio (); | 171 | if (GNUNET_NO == echo) |
172 | { | ||
173 | listen_stdio (); | ||
174 | } | ||
175 | else | ||
176 | { | ||
177 | echo_time = GNUNET_TIME_absolute_get (); | ||
178 | } | ||
157 | 179 | ||
158 | return total_size; | 180 | return total_size; |
159 | } | 181 | } |
@@ -271,10 +293,30 @@ channel_incoming (void *cls, | |||
271 | return NULL; | 293 | return NULL; |
272 | } | 294 | } |
273 | ch = channel; | 295 | ch = channel; |
274 | listen_stdio (); | 296 | if (GNUNET_NO == echo) |
297 | { | ||
298 | listen_stdio (); | ||
299 | return NULL; | ||
300 | } | ||
301 | data_size = 0; | ||
275 | return NULL; | 302 | return NULL; |
276 | } | 303 | } |
277 | 304 | ||
305 | /** | ||
306 | * @brief Send an echo request to the remote peer. | ||
307 | * | ||
308 | * @param cls Closure (NULL). | ||
309 | * @param tc Task context. | ||
310 | */ | ||
311 | static void | ||
312 | send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
313 | { | ||
314 | GNUNET_MESH_notify_transmit_ready (ch, GNUNET_NO, | ||
315 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
316 | sizeof (struct GNUNET_MessageHeader), | ||
317 | &data_ready, NULL); | ||
318 | } | ||
319 | |||
278 | 320 | ||
279 | 321 | ||
280 | /** | 322 | /** |
@@ -305,7 +347,10 @@ create_channel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to `%s'\n", target_id); | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to `%s'\n", target_id); |
306 | opt = GNUNET_MESH_OPTION_DEFAULT | GNUNET_MESH_OPTION_RELIABLE; | 348 | opt = GNUNET_MESH_OPTION_DEFAULT | GNUNET_MESH_OPTION_RELIABLE; |
307 | ch = GNUNET_MESH_channel_create (mh, NULL, &pid, target_port, opt); | 349 | ch = GNUNET_MESH_channel_create (mh, NULL, &pid, target_port, opt); |
308 | listen_stdio (); | 350 | if (GNUNET_YES == echo) |
351 | listen_stdio (); | ||
352 | else | ||
353 | GNUNET_SCHEDULER_add_now (send_echo, NULL); | ||
309 | } | 354 | } |
310 | 355 | ||
311 | 356 | ||
@@ -335,6 +380,30 @@ data_callback (void *cls, | |||
335 | const char *buf; | 380 | const char *buf; |
336 | GNUNET_break (ch == channel); | 381 | GNUNET_break (ch == channel); |
337 | 382 | ||
383 | if (GNUNET_YES == echo) | ||
384 | { | ||
385 | if (0 != listen_port) | ||
386 | { | ||
387 | /* Just listening to echo incoming messages*/ | ||
388 | GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO, | ||
389 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
390 | sizeof (struct GNUNET_MessageHeader), | ||
391 | &data_ready, NULL); | ||
392 | return GNUNET_OK; | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | struct GNUNET_TIME_Relative latency; | ||
397 | |||
398 | latency = GNUNET_TIME_absolute_get_duration (echo_time); | ||
399 | echo_time = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
400 | FPRINTF (stdout, "time: %s\n", | ||
401 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO)); | ||
402 | echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
403 | &send_echo, NULL); | ||
404 | } | ||
405 | } | ||
406 | |||
338 | len = ntohs (message->size) - sizeof (*message); | 407 | len = ntohs (message->size) - sizeof (*message); |
339 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); | 408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); |
340 | buf = (const char *) &message[1]; | 409 | buf = (const char *) &message[1]; |
@@ -578,6 +647,9 @@ main (int argc, char *const *argv) | |||
578 | {'b', "connection", "TUNNEL_ID:CONNECTION_ID", | 647 | {'b', "connection", "TUNNEL_ID:CONNECTION_ID", |
579 | gettext_noop ("provide information about a particular connection"), | 648 | gettext_noop ("provide information about a particular connection"), |
580 | GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id}, | 649 | GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id}, |
650 | {'e', "echo", NULL, | ||
651 | gettext_noop ("activate echo mode"), | ||
652 | GNUNET_NO, &GNUNET_GETOPT_set_one, &echo}, | ||
581 | {'i', "info", NULL, | 653 | {'i', "info", NULL, |
582 | gettext_noop ("provide information about all tunnels"), | 654 | gettext_noop ("provide information about all tunnels"), |
583 | GNUNET_NO, &GNUNET_GETOPT_set_one, &get_info}, | 655 | GNUNET_NO, &GNUNET_GETOPT_set_one, &get_info}, |