[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31773 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31773 - gnunet/src/mesh |
Date: |
Sun, 29 Dec 2013 23:21:19 +0100 |
Author: bartpolot
Date: 2013-12-29 23:21:19 +0100 (Sun, 29 Dec 2013)
New Revision: 31773
Modified:
gnunet/src/mesh/gnunet-mesh.c
Log:
Add echo functionality for mesh CLI
Modified: gnunet/src/mesh/gnunet-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-mesh.c 2013-12-29 21:49:53 UTC (rev 31772)
+++ gnunet/src/mesh/gnunet-mesh.c 2013-12-29 22:21:19 UTC (rev 31773)
@@ -59,6 +59,21 @@
static uint32_t listen_port;
/**
+ * Request echo service
+ */
+int echo;
+
+/**
+ * Time of last echo request.
+ */
+struct GNUNET_TIME_Absolute echo_time;
+
+/**
+ * Task for next echo request.
+ */
+GNUNET_SCHEDULER_TaskIdentifier echo_task;
+
+/**
* Peer to connect to.
*/
static char *target_id;
@@ -153,7 +168,14 @@
msg->size = htons (total_size);
msg->type = htons (GNUNET_MESSAGE_TYPE_MESH_CLI);
memcpy (&msg[1], cls, data_size);
- listen_stdio ();
+ if (GNUNET_NO == echo)
+ {
+ listen_stdio ();
+ }
+ else
+ {
+ echo_time = GNUNET_TIME_absolute_get ();
+ }
return total_size;
}
@@ -271,12 +293,32 @@
return NULL;
}
ch = channel;
- listen_stdio ();
+ if (GNUNET_NO == echo)
+ {
+ listen_stdio ();
+ return NULL;
+ }
+ data_size = 0;
return NULL;
}
+/**
+ * @brief Send an echo request to the remote peer.
+ *
+ * @param cls Closure (NULL).
+ * @param tc Task context.
+ */
+static void
+send_echo (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ GNUNET_MESH_notify_transmit_ready (ch, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof (struct GNUNET_MessageHeader),
+ &data_ready, NULL);
+}
+
/**
* Call MESH's monitor API, get info of one connection.
*
@@ -305,7 +347,10 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to `%s'\n", target_id);
opt = GNUNET_MESH_OPTION_DEFAULT | GNUNET_MESH_OPTION_RELIABLE;
ch = GNUNET_MESH_channel_create (mh, NULL, &pid, target_port, opt);
- listen_stdio ();
+ if (GNUNET_YES == echo)
+ listen_stdio ();
+ else
+ GNUNET_SCHEDULER_add_now (send_echo, NULL);
}
@@ -335,6 +380,30 @@
const char *buf;
GNUNET_break (ch == channel);
+ if (GNUNET_YES == echo)
+ {
+ if (0 != listen_port)
+ {
+ /* Just listening to echo incoming messages*/
+ GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof (struct GNUNET_MessageHeader),
+ &data_ready, NULL);
+ return GNUNET_OK;
+ }
+ else
+ {
+ struct GNUNET_TIME_Relative latency;
+
+ latency = GNUNET_TIME_absolute_get_duration (echo_time);
+ echo_time = GNUNET_TIME_UNIT_FOREVER_ABS;
+ FPRINTF (stdout, "time: %s\n",
+ GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
+ echo_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &send_echo, NULL);
+ }
+ }
+
len = ntohs (message->size) - sizeof (*message);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
buf = (const char *) &message[1];
@@ -578,6 +647,9 @@
{'b', "connection", "TUNNEL_ID:CONNECTION_ID",
gettext_noop ("provide information about a particular connection"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &conn_id},
+ {'e', "echo", NULL,
+ gettext_noop ("activate echo mode"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &echo},
{'i', "info", NULL,
gettext_noop ("provide information about all tunnels"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &get_info},
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31773 - gnunet/src/mesh,
gnunet <=