/**
* Request echo service
*/
-int echo;
+static int echo;
/**
* Request a debug dump
*/
-int dump;
+static int dump;
/**
* Time of last echo request.
*/
-struct GNUNET_TIME_Absolute echo_time;
+static struct GNUNET_TIME_Absolute echo_time;
/**
* Task for next echo request.
*/
-struct GNUNET_SCHEDULER_Task * echo_task;
+static struct GNUNET_SCHEDULER_Task *echo_task;
/**
* Peer to connect to.
/**
* Data pending in netcat mode.
*/
-size_t data_size;
-
+static size_t data_size;
/**
* Cadet handle.
/**
* Shutdown task handle.
*/
-struct GNUNET_SCHEDULER_Task * sd;
+static struct GNUNET_SCHEDULER_Task *sd;
+/**
+ * Task for reading from stdin.
+ */
+static struct GNUNET_SCHEDULER_Task *rd_task;
+
+/**
+ * Task for main job.
+ */
+static struct GNUNET_SCHEDULER_Task *job;
static void
static void
shutdown_task (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown\n");
if (NULL != th)
{
GNUNET_CADET_notify_transmit_ready_cancel (th);
if (NULL != mh)
{
GNUNET_CADET_disconnect (mh);
- mh = NULL;
+ mh = NULL;
+ }
+ if (NULL != rd_task)
+ {
+ GNUNET_SCHEDULER_cancel (rd_task);
+ rd_task = NULL;
+ }
+ if (NULL != echo_task)
+ {
+ GNUNET_SCHEDULER_cancel (echo_task);
+ echo_task = NULL;
+ }
+ if (NULL != job)
+ {
+ GNUNET_SCHEDULER_cancel (job);
+ job = NULL;
}
}
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-size_t
+static size_t
data_ready (void *cls, size_t size, void *buf)
{
struct GNUNET_MessageHeader *msg;
}
total_size = data_size + sizeof (struct GNUNET_MessageHeader);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sending %u bytes\n", data_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "sending %u bytes\n",
+ (unsigned int) data_size);
GNUNET_assert (size >= total_size);
msg = buf;
read_stdio (void *cls)
{
static char buf[60000];
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- return;
- }
data_size = read (0, buf, 60000);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "stdio read %u bytes\n", data_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "stdio read %u bytes\n",
+ (unsigned int) data_size);
if (data_size < 1)
{
GNUNET_SCHEDULER_shutdown();
rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set_native (rs, 0);
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
- GNUNET_TIME_UNIT_FOREVER_REL,
- rs, NULL,
- &read_stdio, NULL);
+ rd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ rs, NULL,
+ &read_stdio, NULL);
GNUNET_NETWORK_fdset_destroy (rs);
}
static void
send_echo (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) || NULL == ch)
+ if (NULL == ch)
return;
-
GNUNET_assert (NULL == th);
th = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
{
GNUNET_CADET_request_dump (mh);
GNUNET_SCHEDULER_cancel (sd);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &shutdown_task, NULL);
}
if (GNUNET_NO == echo)
listen_stdio ();
else
- GNUNET_SCHEDULER_add_now (send_echo, NULL);
+ echo_task = GNUNET_SCHEDULER_add_now (&send_echo, NULL);
}
* (0 = unknown, 1 = ourselves, 2 = neighbor)
*/
static void
-peers_callback (void *cls, const struct GNUNET_PeerIdentity *peer,
- int tunnel, unsigned int n_paths, unsigned int best_path)
+peers_callback (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ int tunnel,
+ unsigned int n_paths,
+ unsigned int best_path)
{
if (NULL == peer)
{
* Each path starts with the local peer.
* Each path ends with the destination peer (given in @c peer).
*/
-void
+static void
peer_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
int tunnel,
* @param estate Encryption state.
* @param cstate Connectivity state.
*/
-void
+static void
tunnels_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
unsigned int channels,
* @param estate Encryption status.
* @param cstate Connectivity status.
*/
-void
+static void
tunnel_callback (void *cls,
const struct GNUNET_PeerIdentity *peer,
unsigned int n_channels,
}
if (GNUNET_YES != monitor_mode)
{
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
}
return;
}
static void
get_peers (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
- return;
- }
+ job = NULL;
GNUNET_CADET_get_peers (mh, &peers_callback, NULL);
}
{
struct GNUNET_PeerIdentity pid;
+ job = NULL;
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
strlen (peer_id),
GNUNET_CADET_get_peer (mh, &pid, peer_callback, NULL);
}
+
/**
* Call CADET's meta API, get all tunnels known to a peer.
*
static void
get_tunnels (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
- return;
- }
+ job = NULL;
GNUNET_CADET_get_tunnels (mh, &tunnels_callback, NULL);
}
fprintf (stderr,
_("Invalid tunnel owner `%s'\n"),
tunnel_id);
- GNUNET_SCHEDULER_shutdown();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_CADET_get_tunnel (mh, &pid, tunnel_callback, NULL);
static void
show_channel (void *cls)
{
-
+ job = NULL;
+ GNUNET_break (0);
}
static void
show_connection (void *cls)
{
-
+ job = NULL;
+ GNUNET_break (0);
}
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
GNUNET_CADET_InboundChannelNotificationHandler *newch = NULL;
else if (NULL != peer_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show peer\n");
- GNUNET_SCHEDULER_add_now (&show_peer, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_peer, NULL);
}
else if (NULL != tunnel_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show tunnel\n");
- GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_tunnel, NULL);
}
else if (NULL != channel_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show channel\n");
- GNUNET_SCHEDULER_add_now (&show_channel, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_channel, NULL);
}
else if (NULL != conn_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show connection\n");
- GNUNET_SCHEDULER_add_now (&show_connection, NULL);
+ job = GNUNET_SCHEDULER_add_now (&show_connection, NULL);
}
else if (GNUNET_YES == request_peers)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all peers\n");
- GNUNET_SCHEDULER_add_now (&get_peers, NULL);
+ job = GNUNET_SCHEDULER_add_now (&get_peers, NULL);
}
else if (GNUNET_YES == request_tunnels)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Show all tunnels\n");
- GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
+ job = GNUNET_SCHEDULER_add_now (&get_tunnels, NULL);
}
else
{
ports);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done\n");
if (NULL == mh)
- GNUNET_SCHEDULER_add_now (shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
else
- sd = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- shutdown_task, NULL);
-
+ sd = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}