h->currently_down = GNUNET_YES;
GNUNET_assert (NULL == h->reconnect_task);
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
+ GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
+ &reconnect_arm_task,
+ h);
/* Don't clear pending messages on disconnection, deliver them later
clear_pending_messages (h, GNUNET_ARM_REQUEST_DISCONNECTED);
GNUNET_assert (NULL == h->control_pending_head);
*/
struct GNUNET_ARM_Handle *
GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls)
+ GNUNET_ARM_ConnectionStatusCallback conn_status,
+ void *cls)
{
struct GNUNET_ARM_Handle *h;
h->control_pending_tail, cm);
cm->timeout_task_id =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (cm->timeout), &control_message_timeout, cm);
+ (cm->timeout),
+ &control_message_timeout, cm);
trigger_next_request (h, GNUNET_NO);
}
h->control_pending_tail, cm);
cm->timeout_task_id =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (cm->timeout), &control_message_timeout, cm);
+ (cm->timeout),
+ &control_message_timeout, cm);
trigger_next_request (h, GNUNET_NO);
}
*/
static unsigned int no_stderr;
+/**
+ * Handle for the task running the #action_loop().
+ */
+static struct GNUNET_SCHEDULER_Task *al_task;
+
/**
* Attempts to delete configuration file and GNUNET_HOME
static void
shutdown_task (void *cls)
{
+ if (NULL != al_task)
+ {
+ GNUNET_SCHEDULER_cancel (al_task);
+ al_task = NULL;
+ }
if (NULL != h)
{
GNUNET_ARM_disconnect_and_free (h);
*/
static void
start_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "ARM service [re]start successful\n");
start = 0;
- GNUNET_SCHEDULER_add_now (action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
*/
static void
stop_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
(GNUNET_ARM_RESULT_STOPPED != result) &&
(GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
{
- GNUNET_asprintf (&msg, "%s", _("Failed to stop the ARM service: %s\n"));
+ GNUNET_asprintf (&msg, "%s",
+ _("Failed to stop the ARM service: %s\n"));
FPRINTF (stdout, msg, ret_string (result));
GNUNET_free (msg);
GNUNET_SCHEDULER_shutdown ();
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Initiating an ARM restart\n");
}
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
*/
static void
init_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
init);
GNUNET_free (init);
init = NULL;
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
*/
static void
term_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, const char *service,
+ enum GNUNET_ARM_RequestStatus rs,
+ const char *service,
enum GNUNET_ARM_Result result)
{
char *msg;
term);
GNUNET_free (term);
term = NULL;
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
*/
static void
list_callback (void *cls,
- enum GNUNET_ARM_RequestStatus rs, unsigned int count,
+ enum GNUNET_ARM_RequestStatus rs,
+ unsigned int count,
const char *const*list)
{
unsigned int i;
{
char *msg;
- GNUNET_asprintf (&msg, "%s", _("Failed to request a list of services: %s\n"));
+ GNUNET_asprintf (&msg, "%s",
+ _("Failed to request a list of services: %s\n"));
FPRINTF (stdout, msg, req_string (rs));
GNUNET_free (msg);
ret = 3;
}
if (NULL == list)
{
- FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not running?\n"));
+ FPRINTF (stderr, "%s",
+ _("Error communicating with ARM. ARM not running?\n"));
GNUNET_SCHEDULER_shutdown ();
ret = 3;
return;
FPRINTF (stdout, "%s", _("Running services:\n"));
for (i = 0; i < count; i++)
FPRINTF (stdout, "%s\n", list[i]);
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
}
static void
action_loop (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
+ al_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Running requested actions\n");
while (1)
{
switch (phase++)
case 0:
if (NULL != term)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Termination action\n");
GNUNET_ARM_request_service_stop (h, term,
(0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
&term_callback, NULL);
case 1:
if (end || restart)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "End action\n");
GNUNET_ARM_request_service_stop (h, "arm",
(0 == timeout.rel_value_us) ? STOP_TIMEOUT_ARM : timeout,
&stop_callback, NULL);
case 2:
if (start)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Start action\n");
GNUNET_ARM_request_service_start (h, "arm",
(no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
(no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
case 3:
if (NULL != init)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
- GNUNET_ARM_request_service_start (h, init, GNUNET_OS_INHERIT_STD_NONE,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Initialization action\n");
+ GNUNET_ARM_request_service_start (h, init,
+ GNUNET_OS_INHERIT_STD_NONE,
(0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
&init_callback, NULL);
return;
*/
static void
srv_status (void *cls,
- const char *service, enum GNUNET_ARM_ServiceStatus status)
+ const char *service,
+ enum GNUNET_ARM_ServiceStatus status)
{
const char *msg;
return;
if (monitor)
m = GNUNET_ARM_monitor (cfg, &srv_status, NULL);
- GNUNET_SCHEDULER_add_now (&action_loop, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ al_task = GNUNET_SCHEDULER_add_now (&action_loop, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
{
struct ServiceListeningInfo *sli = cls;
struct ServiceList *sl = sli->sl;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
sli->accept_task = NULL;
GNUNET_assert (GNUNET_NO == in_shutdown);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
start_process (sl, NULL, 0);
}
sli->accept_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, sock,
&accept_connection, sli);
- GNUNET_CONTAINER_DLL_insert (sl->listen_head, sl->listen_tail, sli);
+ GNUNET_CONTAINER_DLL_insert (sl->listen_head,
+ sl->listen_tail,
+ sli);
}
servicename);
if (0 == strcasecmp (servicename, "arm"))
{
- broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
- signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_STOPPING);
+ broadcast_status (servicename,
+ GNUNET_ARM_SERVICE_STOPPING, NULL);
+ signal_result (client,
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_STOPPING);
GNUNET_SERVER_client_persist_ (client);
- GNUNET_SCHEDULER_add_now (trigger_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&trigger_shutdown, NULL);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
sl = find_service (servicename);
if (sl == NULL)
{
- signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IS_NOT_KNOWN);
+ signal_result (client,
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_IS_NOT_KNOWN);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
if (GNUNET_YES == in_shutdown)
{
/* shutdown in progress */
- signal_result (client, servicename, request_id, GNUNET_ARM_RESULT_IN_SHUTDOWN);
+ signal_result (client,
+ servicename,
+ request_id,
+ GNUNET_ARM_RESULT_IN_SHUTDOWN);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
if (NULL != sl->killing_client)
{
/* killing already in progress */
- signal_result (client, servicename, request_id,
+ signal_result (client,
+ servicename,
+ request_id,
GNUNET_ARM_RESULT_IS_STOPPING_ALREADY);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
if (NULL == sl->proc)
{
/* process is down */
- signal_result (client, servicename, request_id,
+ signal_result (client,
+ servicename,
+ request_id,
GNUNET_ARM_RESULT_IS_STOPPED_ALREADY);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending kill signal to service `%s', waiting for process to die.\n",
servicename);
- broadcast_status (servicename, GNUNET_ARM_SERVICE_STOPPING, NULL);
+ broadcast_status (servicename,
+ GNUNET_ARM_SERVICE_STOPPING,
+ NULL);
/* no signal_start - only when it's STOPPED */
sl->killed_at = GNUNET_TIME_absolute_get ();
if (0 != GNUNET_OS_process_kill (sl->proc, GNUNET_TERM_SIG))
while (NULL != (sli = pos->listen_head))
{
GNUNET_CONTAINER_DLL_remove (pos->listen_head,
- pos->listen_tail, sli);
+ pos->listen_tail,
+ sli);
if (NULL != sli->accept_task)
{
GNUNET_SCHEDULER_cancel (sli->accept_task);
while (NULL != (pos = nxt))
{
nxt = pos->next;
- if (pos->proc != NULL)
+ if (NULL != pos->proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Stopping service `%s'\n",
}
}
/* finally, should all service processes be already gone, terminate for real */
- if (running_head == NULL)
+ if (NULL == running_head)
do_shutdown ();
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
delayed_restart_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct ServiceList *sl;
struct GNUNET_TIME_Relative lowestRestartDelay;
struct ServiceListeningInfo *sli;
child_restart_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (GNUNET_NO == in_shutdown);
lowestRestartDelay = GNUNET_TIME_UNIT_FOREVER_REL;
/* accept was actually paused, so start it again */
sli->accept_task =
GNUNET_SCHEDULER_add_read_net
- (GNUNET_TIME_UNIT_FOREVER_REL, sli->listen_socket,
+ (GNUNET_TIME_UNIT_FOREVER_REL,
+ sli->listen_socket,
&accept_connection, sli);
}
}
static void
maint_child_death (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct ServiceList *pos;
struct ServiceList *next;
struct ServiceListeningInfo *sli;
unsigned long statusCode;
const struct GNUNET_DISK_FileHandle *pr;
- pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+ pr = GNUNET_DISK_pipe_handle (sigpipe,
+ GNUNET_DISK_PIPE_END_READ);
child_death_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- {
- /* shutdown scheduled us, ignore! */
- child_death_task =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr,
- &maint_child_death,
- NULL);
- return;
- }
/* consume the signal */
GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
}
else
{
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
- pos->name,
- statstr,
- statcode,
- GNUNET_STRINGS_relative_time_to_string (pos->backoff,
- GNUNET_YES));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Service `%s' terminated with status %s/%d, will restart in %s\n"),
+ pos->name,
+ statstr,
+ statcode,
+ GNUNET_STRINGS_relative_time_to_string (pos->backoff,
+ GNUNET_YES));
/* schedule restart */
pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
cfg = c;
server = serv;
GNUNET_assert (NULL != serv);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
child_death_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_DISK_pipe_handle (sigpipe,
ok = 3;
else if (ok == 1)
ok = 0;
- GNUNET_SCHEDULER_add_now (trigger_disconnect, arm);
+ GNUNET_SCHEDULER_add_now (&trigger_disconnect, arm);
}
}
/**
* Task set up to cancel the shutdown request on timeout.
*/
- struct GNUNET_SCHEDULER_Task * cancel_task;
+ struct GNUNET_SCHEDULER_Task *cancel_task;
/**
* Task to call once shutdown complete
{
/* Re-try shutdown */
LOG ("do-nothing didn't die, trying again\n");
- GNUNET_SCHEDULER_add_now (kill_task, NULL);
+ GNUNET_SCHEDULER_add_now (&kill_task, NULL);
return;
}
startedWaitingAt = GNUNET_TIME_absolute_get ();
static void
-arm_stop_cb (void *cls, enum GNUNET_ARM_RequestStatus status, const char *servicename, enum GNUNET_ARM_Result result)
+arm_stop_cb (void *cls,
+ enum GNUNET_ARM_RequestStatus status,
+ const char *servicename,
+ enum GNUNET_ARM_Result result)
{
GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
LOG ("ARM service stopped\n");
- GNUNET_SCHEDULER_add_now (trigger_disconnect, NULL);
+ GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL);
}
LOG ("do-nothing is starting\n");
phase++;
ok = 1;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &kill_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &kill_task, NULL);
}
else if ((phase == 2) && (strcasecmp (SERVICE, service) == 0))
{
if (status == GNUNET_ARM_SERVICE_STARTING)
{
LOG ("do-nothing is starting\n");
- GNUNET_SCHEDULER_add_now (kill_task, &ok);
+ GNUNET_SCHEDULER_add_now (&kill_task, &ok);
}
else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
{
collect_log_task (void *cls)
{
struct LoggingHandle *l = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
l->log_task = NULL;
GNUNET_ATS_TEST_logging_now (l);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- return;
l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
&collect_log_task,
l);
return;
if (NULL != l->log_task)
+ {
GNUNET_SCHEDULER_cancel (l->log_task);
- l->log_task = NULL;
+ l->log_task = NULL;
+ }
l->running = GNUNET_NO;
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
static void
collect_log_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
log_task = NULL;
-
- collect_log_now();
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
- return;
-
+ collect_log_now ();
log_task = GNUNET_SCHEDULER_add_delayed (frequency,
&collect_log_task, NULL);
}
int c_m;
struct PeerLoggingTimestep *cur;
- if (GNUNET_YES!= running)
+ if (GNUNET_YES != running)
return;
if (NULL != log_task)
+ {
GNUNET_SCHEDULER_cancel (log_task);
- log_task = NULL;
+ log_task = NULL;
+ }
collect_log_task (NULL);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
/* All messages received and no resolutions pending*/
if (shutdown_task != NULL)
GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (end, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
}
return;
}
/* All messages received and no resolutions pending*/
if (shutdown_task != NULL)
GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (end, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
}
return;
}
shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &end,
- NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
return;
}
if (opt_list_used)
shutdown_task = GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &end,
- NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
return;
}
if (opt_monitor)
ph = GNUNET_ATS_performance_init (cfg,
&ats_perf_mon_cb,
NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&end,
+ NULL);
if (NULL == ph)
+ {
FPRINTF (stderr,
"%s",
_("Cannot connect to ATS service, exiting...\n"));
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &end,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
+ }
return;
}
if (opt_set_pref)
GAS_performance_done ();
GAS_preference_done ();
GAS_reservations_done ();
- GNUNET_SERVER_disconnect_notify_cancel (GSA_server,
- &client_disconnect_handler,
- NULL);
if (NULL != GSA_stats)
{
GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
&client_disconnect_handler,
NULL);
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
/*
This file is part of GNUnet.
Copyright (C) 2011 GNUnet e.V.
+
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
+
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
-
/**
* @file cadet/cadet_api.c
* @brief cadet api: client implementation of new cadet service
reconnect_cbk (void *cls)
{
struct GNUNET_CADET_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->reconnect_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
do_reconnect (h);
}
*
* @param h handle to the cadet
*
- * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
+ * @return #GNUNET_YES in case of sucess, #GNUNET_NO otherwise (service down...)
*/
static void
reconnect (struct GNUNET_CADET_Handle *h)
/**
* @brief Destroy a path after some time has past.
- *
- * If the path is returned from DHT again after a while, try again.
- *
- * Removes the path from the peer (except for direct paths).
+ * Removes the path from the peer (must not be used for direct paths).
*
* @param cls Closure (path to destroy).
*/
{
struct CadetPeerPath *path = cls;
struct CadetPeer *peer;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- LOG (GNUNET_ERROR_TYPE_INFO, "Destroy delayed %p (%u)\n", path, path->length);
path->path_delete = NULL;
-
- /* During shutdown, the peers peermap might not exist anymore. */
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) == 0)
- {
- if (2 >= path->length)
- {
- /* This is not the place to destroy direct paths, only core_disconnect
- * should do it and never delay it.
- */
- GNUNET_break (0);
- }
- peer = GCP_get_short (path->peers[path->length - 1], GNUNET_NO);
- if (NULL != peer)
- GCP_remove_path (peer, path);
- }
- else
- path_destroy (path);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Destroy delayed %p (%u)\n",
+ path,
+ path->length);
+ GNUNET_assert (2 < path->length);
+ peer = GCP_get_short (path->peers[path->length - 1],
+ GNUNET_NO);
+ GNUNET_assert (NULL != peer);
+ GCP_remove_path (peer, path);
}
* Create a new path
*
* @param length How many hops will the path have.
- *
* @return A newly allocated path with a peer array of the specified length.
*/
struct CadetPeerPath *
unsigned int i;
aux = path_new (path->length);
- memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
+ memcpy (aux->peers,
+ path->peers,
+ path->length * sizeof (GNUNET_PEER_Id));
for (i = 0; i < aux->length; i++)
GNUNET_PEER_change_rc (aux->peers[i], 1);
return aux;
if (NULL != p->path_delete)
return;
- LOG (GNUNET_ERROR_TYPE_INFO, "Invalidating path %p (%u)\n", p, p->length);
- p->path_delete = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &path_destroy_delayed, p);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Invalidating path %p (%u)\n",
+ p,
+ p->length);
+ p->path_delete
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &path_destroy_delayed, p);
}
* @param p1 First path
* @param p2 Second path
*
- * @return GNUNET_YES if both paths are equivalent
- * GNUNET_NO otherwise
+ * @return #GNUNET_YES if both paths are equivalent
+ * #GNUNET_NO otherwise
*/
int
path_equivalent (const struct CadetPeerPath *p1,
*
* @param p the path to destroy
*
- * @return GNUNET_OK on success
+ * @return #GNUNET_OK on success
*/
int
path_destroy (struct CadetPeerPath *p)
if (NULL == p)
return GNUNET_OK;
- LOG (GNUNET_ERROR_TYPE_INFO, "destroying path %p (%u)\n", p, p->length);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "destroying path %p (%u)\n",
+ p,
+ p->length);
GNUNET_PEER_decrement_rcs (p->peers, p->length);
GNUNET_free_non_null (p->peers);
if (NULL != p->path_delete)
* 0 if they are identical.
*/
int
-path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2)
+path_cmp (const struct CadetPeerPath *p1,
+ const struct CadetPeerPath *p2)
{
if (p1->length > p2->length)
return 1;
if (p1->length < p2->length)
return -1;
- return memcmp (p1->peers, p2->peers, sizeof (GNUNET_PEER_Id) * p1->length);
+ return memcmp (p1->peers,
+ p2->peers,
+ sizeof (GNUNET_PEER_Id) * p1->length);
}
/**
* Task to do the next ping.
*/
- struct GNUNET_SCHEDULER_Task * ping_task;
+ struct GNUNET_SCHEDULER_Task *ping_task;
+
+ /**
+ * NTR operation for the next ping.
+ */
+ struct GNUNET_CADET_TransmitHandle *ping_ntr;
float mean[number_rounds];
float var[number_rounds];
/**
* Operation to get peer ids.
*/
-struct CadetPeer *peers;
+static struct CadetPeer *peers;
/**
* Peer ids counter.
*/
static struct GNUNET_CADET_TEST_Context *test_ctx;
-/**
- * Task called to shutdown test.
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
-
/**
* Task called to disconnect peers, before shutdown.
*/
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
/**
* Task to perform tests
*/
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
/**
* Round number.
*/
static int test_finished;
+/**
+ * Task running each round of the benchmark.
+ */
+static struct GNUNET_SCHEDULER_Task *round_task;
+
/**
* START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
}
-/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- */
-static void
-shutdown_task (void *cls)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
- shutdown_handle = NULL;
-}
-
-
/**
* Disconnect from cadet services af all peers, call shutdown.
*
unsigned int i;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting cadet service, called from line %ld\n", line);
+ "disconnecting cadet service, called from line %ld\n",
+ line);
disconnect_task = NULL;
for (i = 0; i < peers_total; i++)
{
if (NULL != peers[i].ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: channel %p\n", i, peers[i].ch);
GNUNET_CADET_channel_destroy (peers[i].ch);
}
if (NULL != peers[i].warmup_ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: warmup channel %p\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: warmup channel %p\n",
i, peers[i].warmup_ch);
GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
}
if (NULL != peers[i].incoming_ch)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u: incoming channel %p\n",
i, peers[i].incoming_ch);
GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
}
}
GNUNET_CADET_TEST_cleanup (test_ctx);
- if (NULL != shutdown_handle)
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ */
+static void
+shutdown_task (void *cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Ending test.\n");
+ if (NULL != disconnect_task)
{
- GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
+ }
+ if (NULL != round_task)
+ {
+ GNUNET_SCHEDULER_cancel (round_task);
+ round_task = NULL;
+ }
+ if (NULL != test_task)
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = NULL;
}
- shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
* @param subsystem name of subsystem that created the statistic
* @param name the name of the datum
* @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
static int
-stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
- const char *subsystem, const char *name,
- uint64_t value, int is_persistent)
+stats_iterator (void *cls,
+ const struct GNUNET_TESTBED_Peer *peer,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
{
uint32_t i;
static void
collect_stats (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
- stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Start collecting statistics...\n");
+ stats_op = GNUNET_TESTBED_get_statistics (peers_total,
+ testbed_handles,
NULL, NULL,
- stats_iterator, stats_cont, NULL);
+ &stats_iterator,
+ &stats_cont, NULL);
}
static void
finish_profiler (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
test_finished = GNUNET_YES;
- show_end_data();
+ show_end_data ();
GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
}
+
/**
* Set the total number of running peers.
*
run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
if (NULL != peers[r].ping_task)
+ {
GNUNET_SCHEDULER_cancel (peers[r].ping_task);
- peers[r].ping_task = NULL;
-
+ peers[r].ping_task = NULL;
+ }
+ if (NULL != peers[r].ping_ntr)
+ {
+ GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
+ peers[r].ping_ntr = NULL;
+ }
peers[r].up = run;
if (NULL != peers[r].ch)
static void
next_rnd (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
if (0.0 == rounds[current_round])
{
adjust_running_peers (rounds[current_round] * peers_total);
current_round++;
- GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
ping (void *cls)
{
struct CadetPeer *peer = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
peer->ping_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)
- || GNUNET_YES == test_finished)
+ if (GNUNET_YES == test_finished)
return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n",
- get_index (peer), get_index (peer->dest), peer->data_sent);
-
- GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
- GNUNET_TIME_UNIT_FOREVER_REL,
- sizeof (struct CadetPingMessage),
- &tmt_rdy_ping, peer);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%u -> %u (%u)\n",
+ get_index (peer),
+ get_index (peer->dest),
+ peer->data_sent);
+ peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ sizeof (struct CadetPingMessage),
+ &tmt_rdy_ping, peer);
}
/**
* @param tc Task context.
*/
static void
-pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping)
+pong (struct GNUNET_CADET_Channel *channel,
+ const struct CadetPingMessage *ping)
{
struct CadetPingMessage *copy;
copy = GNUNET_new (struct CadetPingMessage);
- memcpy (copy, ping, sizeof (*ping));
+ *copy = *ping;
GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
sizeof (struct CadetPingMessage),
struct CadetPeer *peer = (struct CadetPeer *) cls;
struct CadetPingMessage *msg = buf;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
+ peer->ping_ntr = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "tmt_rdy called, filling buffer\n");
if (size < sizeof (struct CadetPingMessage) || NULL == buf)
{
GNUNET_break (GNUNET_YES == test_finished);
* with the channel is stored
*/
static void
-channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
+channel_cleaner (void *cls,
+ const struct GNUNET_CADET_Channel *channel,
void *channel_ctx)
{
long n = (long) cls;
{
enum GNUNET_CADET_ChannelOption flags;
unsigned long i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
test_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
flags = GNUNET_CADET_OPTION_DEFAULT;
number_rounds + 1),
&disconnect_cadet_peers,
(void *) __LINE__);
- GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+ round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+ &next_rnd,
+ NULL);
}
}
}
+
/**
* Callback to be called when the requested peer information is available
*
*/
static void
peer_id_cb (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- const struct GNUNET_TESTBED_PeerInformation *pinfo,
- const char *emsg)
+ struct GNUNET_TESTBED_Operation *op,
+ const struct GNUNET_TESTBED_PeerInformation *pinfo,
+ const char *emsg)
{
long n = (long) cls;
&start_test, NULL);
}
+
/**
* test main: start test when all peers are connected
*
{
unsigned long i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "test main\n");
test_ctx = ctx;
GNUNET_assert (peers_total == num_peers);
peers_running = num_peers;
disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
&disconnect_cadet_peers,
(void *) __LINE__);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
for (i = 0; i < peers_total; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "requesting id %ld\n",
+ i);
peers[i].up = GNUNET_YES;
peers[i].cadet = cadetes[i];
peers[i].op =
if (4 > argc)
{
- fprintf (stderr, "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", argv[0]);
- fprintf (stderr, "example: %s 30s 16 1 Y\n", argv[0]);
+ fprintf (stderr,
+ "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
+ argv[0]);
+ fprintf (stderr,
+ "example: %s 30s 16 1 Y\n",
+ argv[0]);
return 1;
}
- if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[1], &round_time))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (argv[1],
+ &round_time))
{
- fprintf (stderr, "%s is not a valid time\n", argv[1]);
+ fprintf (stderr,
+ "%s is not a valid time\n",
+ argv[1]);
return 1;
}
peers_total = atoll (argv[2]);
if (2 > peers_total)
{
- fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]);
+ fprintf (stderr,
+ "%s peers is not valid (> 2)\n",
+ argv[1]);
return 1;
}
- peers = GNUNET_malloc (sizeof (struct CadetPeer) * peers_total);
-
+ peers = GNUNET_new_array (peers_total,
+ struct CadetPeer);
peers_pinging = atoll (argv[3]);
if (peers_total < 2 * peers_pinging)
do_warmup = (5 > argc || argv[4][0] != 'N');
- ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES);
+ ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
+ GNUNET_YES);
GNUNET_assert (NULL != ids);
p_ids = 0;
test_finished = GNUNET_NO;
/**
* 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;
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);
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);
}
stats = GNUNET_STATISTICS_create ("cadet", c);
/* Scheduled the task to clean up when shutdown is called */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
GNUNET_assert (NULL != my_private_key);
struct CadetChannel *ch;
struct GNUNET_CADET_Data *payload;
int fwd;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
rel->retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
ch = rel->ch;
copy = rel->head_sent;
if (NULL == copy)
channel_recreate (void *cls)
{
struct CadetChannelReliability *rel = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
rel->retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
LOG (GNUNET_ERROR_TYPE_DEBUG, "RE-CREATE\n");
- GNUNET_STATISTICS_update (stats, "# data retransmitted", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ "# data retransmitted", 1, GNUNET_NO);
if (rel == rel->ch->root_rel)
{
{
GNUNET_break (0);
}
-
}
*
* @param c Connection to keep alive.
* @param fwd Direction.
- * @param shutdown Are we shutting down? (Don't send traffic)
- * Non-zero value for true, not necessarily GNUNET_YES.
*/
static void
-connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
+connection_keepalive (struct CadetConnection *c,
+ int fwd)
{
GCC_check_connections ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
c->fwd_maintenance_task = NULL;
else
c->bck_maintenance_task = NULL;
-
- if (GNUNET_NO != shutdown)
- return;
-
connection_maintain (c, fwd);
GCC_check_connections ();
/* Next execution will be scheduled by message_sent or _maintain*/
static void
connection_fwd_keepalive (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
+ struct CadetConnection *c = cls;
GCC_check_connections ();
- tc = GNUNET_SCHEDULER_get_task_context ();
- connection_keepalive ((struct CadetConnection *) cls,
- GNUNET_YES,
- tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+ connection_keepalive (c,
+ GNUNET_YES);
GCC_check_connections ();
}
static void
connection_bck_keepalive (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
+ struct CadetConnection *c = cls;
GCC_check_connections ();
- tc = GNUNET_SCHEDULER_get_task_context ();
- connection_keepalive ((struct CadetConnection *) cls,
- GNUNET_NO,
- tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+ connection_keepalive (c,
+ GNUNET_NO);
GCC_check_connections ();
}
struct GNUNET_CADET_Poll msg;
struct CadetConnection *c;
int fwd;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
fc->poll_task = NULL;
GCC_check_connections ();
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- return;
- }
-
c = fc->c;
fwd = fc == &c->fwd_fc;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n",
connection_fwd_timeout (void *cls)
{
struct CadetConnection *c = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
c->fwd_maintenance_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GCC_check_connections ();
connection_timeout (c, GNUNET_YES);
GCC_check_connections ();
connection_bck_timeout (void *cls)
{
struct CadetConnection *c = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
c->bck_maintenance_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GCC_check_connections ();
connection_timeout (c, GNUNET_NO);
GCC_check_connections ();
check_duplicates (void *cls)
{
struct CadetConnection *c = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
c->check_duplicates_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (GNUNET_YES == does_connection_exist (c))
{
GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
}
-
/**
* Wait for enough time to let any dead connections time out and check for
* any remaining duplicates.
if (NULL != c->check_duplicates_task)
return;
-
delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
&check_duplicates,
}
-
/**
* Add the connection to the list of both neighbors.
*
* @param disconnected Peer that disconnected.
*/
static void
-invalidate_paths (struct CadetConnection *c, struct CadetPeer *disconnected)
+invalidate_paths (struct CadetConnection *c,
+ struct CadetPeer *disconnected)
{
struct CadetPeer *peer;
unsigned int i;
size_t size;
struct GNUNET_TIME_Absolute expiration;
struct GNUNET_TIME_Relative retry_time;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- announce_id_task = NULL;
- return;
- }
+ announce_id_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Announce ID\n");
/* TODO
* - Set data expiration in function of X
* Remove the direct path to the peer.
*
* @param peer Peer to remove the direct path from.
- *
*/
static struct CadetPeerPath *
pop_direct_path (struct CadetPeer *peer)
{
if (2 >= iter->length)
{
- GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+ GNUNET_CONTAINER_DLL_remove (peer->path_head,
+ peer->path_tail,
+ iter);
return iter;
}
}
"destroying peer %s\n",
GNUNET_i2s (&id));
- if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
+ if (GNUNET_YES !=
+ GNUNET_CONTAINER_multipeermap_remove (peers, &id, peer))
{
GNUNET_break (0);
LOG (GNUNET_ERROR_TYPE_WARNING, " peer not in peermap!!\n");
delayed_search (void *cls)
{
struct CadetPeer *peer = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
peer->search_delayed = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
GCC_check_connections ();
GCP_start_search (peer);
GCC_check_connections ();
/**
- * Retrieve the CadetPeer stucture associated with the peer. Optionally create
- * one and insert it in the appropriate structures if the peer is not known yet.
+ * Retrieve the CadetPeer stucture associated with the
+ * peer. Optionally create one and insert it in the appropriate
+ * structures if the peer is not known yet.
*
* @param peer Short identity of the peer.
* @param create #GNUNET_YES if a new peer should be created if unknown.
}
}
}
- GNUNET_CONTAINER_DLL_insert_tail (peer->path_head, peer->path_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (peer->path_head,
+ peer->path_tail,
path);
LOG (GNUNET_ERROR_TYPE_DEBUG, " added last\n");
* @param path Path to remove. Is always destroyed .
*/
void
-GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
+GCP_remove_path (struct CadetPeer *peer,
+ struct CadetPeerPath *path)
{
struct CadetPeerPath *iter;
struct CadetPeerPath *next;
GNUNET_assert (myid == path->peers[0]);
GNUNET_assert (peer->id == path->peers[path->length - 1]);
- LOG (GNUNET_ERROR_TYPE_INFO, "Removing path %p (%u) from %s\n",
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Removing path %p (%u) from %s\n",
path, path->length, GCP_2s (peer));
for (iter = peer->path_head; NULL != iter; iter = next)
next = iter->next;
if (0 == path_cmp (path, iter))
{
- GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, iter);
+ GNUNET_CONTAINER_DLL_remove (peer->path_head,
+ peer->path_tail,
+ iter);
if (iter != path)
path_destroy (iter);
}
* @param hello Hello message.
*/
void
-GCP_set_hello (struct CadetPeer *peer, const struct GNUNET_HELLO_Message *hello)
+GCP_set_hello (struct CadetPeer *peer,
+ const struct GNUNET_HELLO_Message *hello)
{
struct GNUNET_HELLO_Message *old;
size_t size;
finish_kx (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
LOG (GNUNET_ERROR_TYPE_INFO, "finish KX for %s\n", GCT_2s (t));
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- LOG (GNUNET_ERROR_TYPE_INFO, " shutdown\n");
- return;
- }
-
GNUNET_free (t->kx_ctx);
t->kx_ctx = NULL;
}
if (is_key_null (&t->kx_ctx->e_key_old))
{
- t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (finish_kx, t);
+ t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_now (&finish_kx, t);
return;
}
delay = GNUNET_TIME_relative_divide (rekey_period, 4);
delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_MINUTES);
- t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay, finish_kx, t);
+ t->kx_ctx->finish_task = GNUNET_SCHEDULER_add_delayed (delay,
+ &finish_kx, t);
}
ax_kx_resend (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
t->rekey_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (CADET_TUNNEL_KEY_OK == t->estate)
{
/* Should have been canceled on estate change */
rekey_tunnel (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
t->rekey_task = NULL;
LOG (GNUNET_ERROR_TYPE_INFO, "Re-key Tunnel %s\n", GCT_2s (t));
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
-
GNUNET_assert (NULL != t->kx_ctx);
struct GNUNET_TIME_Relative duration;
{
struct GNUNET_TIME_Absolute time;
long n;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
rekey_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
-
GNUNET_free_non_null (otr_ephemeral_key);
otr_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
{
struct CadetTunnel *t = value;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "GCT_shutdown destroying tunnel at %p\n", t);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "GCT_shutdown destroying tunnel at %p\n", t);
GCT_destroy (t);
return GNUNET_YES;
}
trim_connections (void *cls)
{
struct CadetTunnel *t = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
t->trim_connections_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (GCT_count_connections (t) > 2 * CONNECTIONS_PER_TUNNEL)
{
struct CadetTConnection *iter;
aux = GNUNET_new (struct CadetTChannel);
aux->ch = ch;
- LOG (GNUNET_ERROR_TYPE_DEBUG, " adding %p to %p\n", aux, t->channel_head);
- GNUNET_CONTAINER_DLL_insert_tail (t->channel_head, t->channel_tail, aux);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " adding %p to %p\n", aux, t->channel_head);
+ GNUNET_CONTAINER_DLL_insert_tail (t->channel_head,
+ t->channel_tail,
+ aux);
if (NULL != t->destroy_task)
{
if (aux->ch == ch)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " found! %s\n", GCCH_2s (ch));
- GNUNET_CONTAINER_DLL_remove (t->channel_head, t->channel_tail, aux);
+ GNUNET_CONTAINER_DLL_remove (t->channel_head,
+ t->channel_tail,
+ aux);
GNUNET_free (aux);
return;
}
{
struct CadetTunnel *t = cls;
struct CadetTConnection *iter;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "delayed destroying tunnel %p\n", t);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Not destroying tunnel, due to shutdown. "
- "Tunnel at %p should have been freed by GCT_shutdown\n", t);
- return;
- }
t->destroy_task = NULL;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "delayed destroying tunnel %p\n",
+ t);
t->cstate = CADET_TUNNEL_SHUTDOWN;
-
for (iter = t->connection_head; NULL != iter; iter = iter->next)
{
GCC_send_destroy (iter->c);
if (NULL == t)
return;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n", GCP_2s (t->peer));
-
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "destroying tunnel %s\n",
+ GCP_2s (t->peer));
GNUNET_break (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_remove (tunnels,
GCP_get_id (t->peer), t));
if (NULL != t->destroy_task)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "cancelling dest: %p\n", t->destroy_task);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "cancelling dest: %p\n",
+ t->destroy_task);
GNUNET_SCHEDULER_cancel (t->destroy_task);
t->destroy_task = NULL;
}
/**
* Task called to disconnect peers.
*/
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
/**
* Task To perform tests
*/
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
/**
- * Task called to shutdown test.
+ * Task runnining #data_task().
*/
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
+static struct GNUNET_SCHEDULER_Task *data_job;
/**
* Cadet handle for the root peer
return peers_requested - 1;
}
+
/**
* Show the results of the test (banwidth acheived) and log them to GAUGER
*/
}
-/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- * @param tc Task Context.
- */
-static void
-shutdown_task (void *cls)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
- shutdown_handle = NULL;
-}
-
-
/**
* Disconnect from cadet services af all peers, call shutdown.
*
{
long line = (long) cls;
unsigned int i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "disconnecting cadet peers due to SHUTDOWN! called from %ld\n",
- line);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "disconnecting cadet service of peers, called from line %ld\n",
- line);
disconnect_task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "disconnecting cadet service of peers, called from line %ld\n",
+ line);
for (i = 0; i < 2; i++)
{
GNUNET_TESTBED_operation_done (t_op[i]);
incoming_ch = NULL;
}
GNUNET_CADET_TEST_cleanup (test_ctx);
- if (NULL != shutdown_handle)
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ * @param tc Task Context.
+ */
+static void
+shutdown_task (void *cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending test.\n");
+ if (NULL != data_job)
{
- GNUNET_SCHEDULER_cancel (shutdown_handle);
+ GNUNET_SCHEDULER_cancel (data_job);
+ data_job = NULL;
+ }
+ if (NULL != test_task)
+ {
+ GNUNET_SCHEDULER_cancel (test_task);
+ test_task = NULL;
+ }
+ if (NULL != disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ (void *) __LINE__);
}
- shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
-
/**
* Stats callback. Finish the stats testbed operation and when all stats have
* been iterated, shutdown the test.
if (NULL != disconnect_task)
GNUNET_SCHEDULER_cancel (disconnect_task);
- disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers, cls);
-
+ disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+ cls);
}
gather_stats_and_exit (void *cls)
{
long l = (long) cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
disconnect_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gathering statistics from line %d\n", l);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- {
- disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
- (void *) __LINE__);
- return;
- }
-
-
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "gathering statistics from line %d\n",
+ l);
if (NULL != ch)
{
if (NULL != th)
{
struct GNUNET_CADET_Channel *channel;
static struct GNUNET_CADET_TransmitHandle **pth;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
long src;
+ data_job = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data task\n");
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
if (GNUNET_YES == test_backwards)
{
channel = incoming_ch;
if (0 == i)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " in 1 ms\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &data_task, (void *) 1L);
+ data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ &data_task, (void *) 1L);
}
else
{
i++;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "in %u ms\n", i);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_MILLISECONDS,
- i),
- &data_task, (void *) i);
+ data_job = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ i),
+ &data_task, (void *) i);
}
}
}
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Scheduling message %d\n",
counter + 1);
- GNUNET_SCHEDULER_add_now (&data_task, NULL);
+ data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
}
}
if (SPEED == test)
{
GNUNET_assert (peers_requested - 1 == client);
- GNUNET_SCHEDULER_add_now (&data_task, NULL);
+ data_job = GNUNET_SCHEDULER_add_now (&data_task, NULL);
return GNUNET_OK;
}
}
do_test (void *cls)
{
enum GNUNET_CADET_ChannelOption flags;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
+ test_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "do_test\n");
if (NULL != disconnect_task)
{
GNUNET_SCHEDULER_cancel (disconnect_task);
+ disconnect_task = NULL;
}
flags = GNUNET_CADET_OPTION_DEFAULT;
&tmt_rdy, (void *) 0L);
}
+
/**
* Callback to be called when the requested peer information is available
*
disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
&disconnect_cadet_peers,
(void *) __LINE__);
- shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0],
GNUNET_TESTBED_PIT_IDENTITY,
&pi_cb, (void *) 0L);
static int got_data = GNUNET_NO;
-static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *connect_task;
static struct GNUNET_CADET_TransmitHandle *mth;
if (NULL != abort_task)
{
GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = NULL;
+ }
+ if (NULL != connect_task)
+ {
+ GNUNET_SCHEDULER_cancel (connect_task);
+ connect_task = NULL;
}
if (NULL != ch)
{
GNUNET_CADET_channel_destroy (ch);
+ ch = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
if (NULL != cadet_peer_1)
{
GNUNET_CADET_disconnect (cadet_peer_1);
+ cadet_peer_1 = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
if (NULL != cadet_peer_2)
{
GNUNET_CADET_disconnect (cadet_peer_2);
+ cadet_peer_2 = NULL;
}
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
result = GNUNET_SYSERR;
abort_task = NULL;
- if (NULL != shutdown_task)
- {
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = NULL;
- }
- do_shutdown (cls);
+ GNUNET_SCHEDULER_shutdown ();
}
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Data callback! Shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Data callback! Shutting down.\n");
got_data = GNUNET_YES;
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_CADET_receive_done (channel);
return GNUNET_OK;
}
do_connect (void *cls)
{
struct GNUNET_PeerIdentity id;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
+ connect_task = NULL;
GNUNET_TESTING_peer_get_identity (me, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1,
static uint32_t ports[] = {1, 0};
me = peer;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
+ (GNUNET_TIME_UNIT_SECONDS, 15),
+ &do_abort,
NULL);
cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */
(void *) 1L, /* cls */
ports); /* ports offered */
if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to cadet :(\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Couldn't connect to cadet :(\n");
result = GNUNET_SYSERR;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
- }
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
GNUNET_TIME_UNIT_SECONDS,
2),
static int result;
-static struct GNUNET_SCHEDULER_Task * abort_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *connect_task;
static unsigned int repetition;
if (NULL != abort_task)
{
GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = NULL;
+ }
+ if (NULL != connect_task)
+ {
+ GNUNET_SCHEDULER_cancel (connect_task);
+ connect_task = NULL;
}
if (NULL != ch1)
{
GNUNET_CADET_channel_destroy (ch1);
+ ch1 = NULL;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 1\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect client 2\n");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ABORT\n");
result = GNUNET_SYSERR;
abort_task = NULL;
- if (NULL != shutdown_task)
- {
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = NULL;
- }
- do_shutdown (cls);
-}
-
-
-static void
-finish (void)
-{
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
ch2 = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "everything fine! finishing!\n");
result = GNUNET_OK;
- finish ();
+ GNUNET_SCHEDULER_shutdown ();
}
}
{
struct GNUNET_PeerIdentity id;
size_t size = sizeof (struct GNUNET_MessageHeader) + DATA_SIZE;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
+ connect_task = NULL;
GNUNET_TESTING_peer_get_identity (me, &id);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1,
static uint32_t ports[] = {1, 0};
me = peer;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 15), &do_abort,
result = GNUNET_SYSERR;
return;
}
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO CADET :D\n");
- }
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_connect, NULL);
+ connect_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &do_connect,
+ NULL);
}
}
statistics = GNUNET_STATISTICS_create ("consensus", cfg);
GNUNET_SERVER_add_handlers (server, server_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
GNUNET_SERVER_disconnect_notify (server, handle_client_disconnect, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "consensus running\n");
}
GNUNET_log_setup ("test_consensus_api",
"INFO",
NULL);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing consensus api\n");
-
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &on_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL);
GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id,
int
main (int argc, char **argv)
{
- int ret;
-
- ret = GNUNET_TESTING_peer_run ("test_consensus_api",
- "test_consensus.conf",
- &run, NULL);
- return ret;
+ return GNUNET_TESTING_peer_run ("test_consensus_api",
+ "test_consensus.conf",
+ &run, NULL);
}
switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&switch_to_speaker,
NULL);
- st = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
fprintf (stderr,
_("We will now be recording you for %s. After that time, the recording will be played back to you..."),
GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES));
handle_cmd_task =
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
&handle_command, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+ NULL);
}
}
nc = GNUNET_SERVER_notification_context_create (server, 16);
GNUNET_SERVER_add_handlers (server, server_handlers);
- GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SERVER_disconnect_notify (server,
+ &handle_client_disconnect,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
_("Failed to connect to CORE service!\n"));
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
return;
}
GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GNUNET_SERVER_suspend (server);
GSC_TYPEMAP_init ();
pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile);
{
/* peer with "higher" identity starts a delayed KX, if the "lower" peer
* does not start a KX since he sees no reasons to do so */
- kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &set_key_retry_task,
- kx);
+ kx->retry_set_key_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &set_key_retry_task,
+ kx);
}
return kx;
}
/**
* Has the test been successful?
*/
-int result;
+static int result;
-unsigned int num_received;
+static unsigned int num_received;
-struct GNUNET_CORE_Handle *core;
+static struct GNUNET_CORE_Handle *core;
-struct GNUNET_MQ_Handle *mq;
+static struct GNUNET_MQ_Handle *mq;
-struct GNUNET_PeerIdentity myself;
+static struct GNUNET_PeerIdentity myself;
static void
static void
-connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
+connect_cb (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connected to peer %s.\n",
GNUNET_i2s (peer));
if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity)))
{
unsigned int i;
struct GNUNET_MQ_Envelope *ev;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing messages.\n");
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Queueing messages.\n");
for (i = 0; i < NUM_MSG; i++)
{
ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_TEST);
const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got test message %d\n", num_received);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got test message %d\n",
+ num_received);
num_received++;
if (NUM_MSG == num_received)
{
static void
shutdown_task (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutting down\n");
GNUNET_MQ_destroy (mq);
GNUNET_CORE_disconnect (core);
}
GNUNET_assert (0);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
+
int
main (int argc, char *argv1[])
{
static void
terminate_task_error (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
err_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Testcase failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Testcase failed!\n");
terminate_peer (&p1);
terminate_peer (&p2);
//GNUNET_break (0);
*/
GNUNET_SCHEDULER_cancel (err_task);
err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
-
}
}
-
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Asking core (1) for transmission to peer `%4s'\n",
GNUNET_i2s (&p2.id));
- if (err_task != NULL)
- GNUNET_SCHEDULER_cancel (err_task);
+ GNUNET_SCHEDULER_cancel (err_task);
err_task =
GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
start_time = GNUNET_TIME_absolute_get ();
libgnunetcurl_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
-ljansson \
+ -lcurl \
$(XLIB)
#check_PROGRAMS = \
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
do_get ();
}
delete_expired (void *cls)
{
expired_kill_task = NULL;
- plugin->api->get_expiration (plugin->api->cls, &expired_processor, NULL);
+ plugin->api->get_expiration (plugin->api->cls,
+ &expired_processor,
+ NULL);
}
GNUNET_SERVER_disconnect_notify (server,
&cleanup_reservations,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleaning_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+ NULL);
}
static struct GNUNET_HashCode key;
static char data[65536];
char gstr[128];
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- crc->phase = RP_ERROR;
ok = (int) crc->phase;
switch (crc->phase)
{
GNUNET_SCHEDULER_add_now (&test, crc);
}
+
static void
do_put (struct CpsRunContext *crc)
{
static int
-iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
- const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority,
- uint32_t anonymity, struct GNUNET_TIME_Absolute expiration,
+iterate_zeros (void *cls,
+ const struct GNUNET_HashCode *key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration,
uint64_t uid)
{
struct CpsRunContext *crc = cls;
static int
-expiration_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
- const void *data, enum GNUNET_BLOCK_Type type,
- uint32_t priority, uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+expiration_get (void *cls,
+ const struct GNUNET_HashCode *key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration,
+ uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
static int
-replication_get (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
- const void *data, enum GNUNET_BLOCK_Type type,
- uint32_t priority, uint32_t anonymity,
- struct GNUNET_TIME_Absolute expiration, uint64_t uid)
+replication_get (void *cls,
+ const struct GNUNET_HashCode *key,
+ uint32_t size,
+ const void *data,
+ enum GNUNET_BLOCK_Type type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute expiration,
+ uint64_t uid)
{
struct CpsRunContext *crc = cls;
int i;
test (void *cls)
{
struct CpsRunContext *crc = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_break (0);
- crc->phase = RP_ERROR;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In phase %d, iteration %u\n", crc->phase, crc->cnt);
switch (crc->phase)
{
struct CpsRunContext *crc = cls;
struct GNUNET_HashCode key;
- 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_WARNING, "Test aborted.\n");
- crc->phase = RP_ERROR;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"In phase %d, iteration %u\n", crc->phase, crc->cnt);
switch (crc->phase)
*/
static int ret;
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
- * Task run to clean up on timeout.
+ * Task run to clean up on shutdown.
*
* @param cls unused
*/
GNUNET_DHT_disconnect (dht_handle);
dht_handle = NULL;
}
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
if (verbose)
FPRINTF (stderr, "%s `%s' \n", _("Issueing DHT GET with key"), GNUNET_h2s_full (&key));
- GNUNET_SCHEDULER_add_delayed (timeout_request,
- &cleanup_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
+ &timeout_task, NULL);
get_handle =
GNUNET_DHT_get_start (dht_handle, query_type, &key, replication,
(demultixplex_everywhere) ? GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE : GNUNET_DHT_RO_NONE,
*/
static int ret;
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
* Stop monitoring request and start shutdown
GNUNET_DHT_disconnect (dht_handle);
dht_handle = NULL;
}
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * We hit a timeout. Stop monitoring request and start shutdown
+ *
+ * @param cls closure (unused)
+ */
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
+
/**
* Callback called on each GET request going through the DHT.
*
* @param desired_replication_level Desired replication level.
* @param key Key of the requested data.
*/
-void
+static void
get_callback (void *cls,
enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
* @param data Pointer to the result data.
* @param size Number of bytes in data.
*/
-void
+static void
get_resp_callback (void *cls,
enum GNUNET_BLOCK_Type type,
const struct GNUNET_PeerIdentity *get_path,
* @param data Pointer to the data carried.
* @param size Number of bytes in data.
*/
-void
+static void
put_callback (void *cls,
enum GNUNET_DHT_RouteOption options,
enum GNUNET_BLOCK_Type type,
FPRINTF (stderr,
"Monitoring for %s\n",
GNUNET_STRINGS_relative_time_to_string (timeout_request, GNUNET_NO));
- GNUNET_SCHEDULER_add_delayed (timeout_request, &cleanup_task, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout_request,
+ &timeout_task,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
monitor_handle = GNUNET_DHT_monitor_start (dht_handle,
block_type,
key,
}
}
+
/**
* Signature of the main function of a task.
*
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
+
/**
* Main function that will be run by the scheduler.
*
* @param c 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 *c)
{
struct GNUNET_TIME_Relative timeout;
struct GNUNET_TIME_Absolute expiration;
cfg = c;
-
if ((NULL == query_key) || (NULL == data))
{
FPRINTF (stderr, "%s", _("Must provide KEY and DATA for DHT put!\n"));
shutdown_task (NULL);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GDS_transport_handle =
GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
if (GDS_transport_handle == NULL)
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
struct GNUNET_TIME_Relative next_send_time;
struct BloomConstructorContext bcc;
struct GNUNET_CONTAINER_BloomFilter *peer_bf;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
find_peer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
if (newly_found_peers > bucket_size)
{
/* If we are finding many peers already, no need to send out our request right now! */
}
}
+
/**
* Get the ID of the local node.
*
shutdown_task (NULL);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
-
/**
* @file dht/gnunet-service-xdht.c
* @brief GNUnet DHT service
* @author Christian Grothoff
* @author Nathan Evans
*/
-
#include "platform.h"
#include "gnunet_block_lib.h"
#include "gnunet_util_lib.h"
shutdown_task (NULL);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
{
struct ClientQueryRecord *cqr;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
retry_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
{
cqr->hnode = NULL;
a_ctx = NULL;
}
//FIXME: Should we collect stats only for put/get not for other messages.
- if(NULL != bandwidth_stats_op)
+ if (NULL != bandwidth_stats_op)
+ {
GNUNET_TESTBED_operation_done (bandwidth_stats_op);
- bandwidth_stats_op = NULL;
+ bandwidth_stats_op = NULL;
+ }
+ if (NULL != successor_stats_op)
+ {
+ GNUNET_TESTBED_operation_done (successor_stats_op);
+ successor_stats_op = NULL;
+ }
+ if (NULL != successor_stats_task)
+ {
+ GNUNET_SCHEDULER_cancel (successor_stats_task);
+ successor_stats_task = NULL;
+ }
GNUNET_free_non_null (a_ac);
}
{
struct Context *ctx = cls;
struct GNUNET_TESTBED_Operation *op;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
GNUNET_assert (NULL != ctx);
GNUNET_assert (NULL != (op = ctx->op));
ctx->op = NULL;
successor_stats_op = NULL;
if (0 == max_searches)
{
- start_func();
+ start_func ();
return;
}
GNUNET_NO);
if ((start_val == val) && (count == num_peers))
{
- DEBUG("CIRCLE COMPLETED after %u tries", tries);
+ DEBUG ("CIRCLE COMPLETED after %u tries", tries);
if(NULL == successor_stats_task)
{
start_func();
}
return;
}
- else
+ if (max_searches == ++tries)
{
- if (max_searches == ++tries)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
- " circle formation. Exiting\n",
- max_searches,tries);
- if (NULL != successor_stats_task)
- {
- successor_stats_task = NULL;
- }
- if(NULL == successor_stats_task)
- {
- start_func();
- }
-
- return;
- }
- else
- {
- flag = 0;
- successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
- &collect_stats, cls);
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
+ " circle formation. Exiting\n",
+ max_searches,tries);
+ start_func();
+ return;
}
+ flag = 0;
+ successor_stats_task
+ = GNUNET_SCHEDULER_add_delayed (delay_stats,
+ &collect_stats,
+ cls);
}
static void
collect_stats (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
- return;
-
+ successor_stats_task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Start collecting statistics...\n");
GNUNET_assert(NULL != testbed_handles);
if (0 != max_searches)
- successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
- GNUNET_NO);
- successor_stats_op =
- GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
- "dht", NULL,
- successor_stats_iterator,
- successor_stats_cont, cls);
-
- GNUNET_assert(NULL != successor_stats_op);
+ successor_peer_hashmap
+ = GNUNET_CONTAINER_multihashmap_create (num_peers,
+ GNUNET_NO);
+ successor_stats_op
+ = GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
+ "dht", NULL,
+ successor_stats_iterator,
+ successor_stats_cont, cls);
+ GNUNET_assert (NULL != successor_stats_op);
}
collect_stat_cls->service_connect_ctx = cls;
collect_stat_cls->op = op;
- successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
- &collect_stats,
- collect_stat_cls);
+ successor_stats_task
+ = GNUNET_SCHEDULER_add_delayed (delay_stats,
+ &collect_stats,
+ collect_stat_cls);
}
}
if (0 == num_peers)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"),
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Exiting as the number of peers is %u\n"),
num_peers);
return;
}
event_mask = 0;
GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, NULL,
NULL, &test_run, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
tc = GNUNET_SCHEDULER_get_task_context ();
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
{
- /* timeout or shutdown */
+ /* timeout */
cleanup_rs (rs);
return;
}
flags,
&display_request,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
}
GNUNET_DNS_FLAG_POST_RESOLUTION,
&modify_request,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
}
cfg = cfg_;
stats = GNUNET_STATISTICS_create ("dns", cfg);
nc = GNUNET_SERVER_notification_context_create (server, 1);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ cls);
dns_exit = NULL;
if ( ( (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
&change_cb,
&disconnect_cb,
&message_cb);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
MAX_QUEUE_SIZE_PLUGIN);
stats = GNUNET_STATISTICS_create ("dv", cfg);
GNUNET_SERVER_add_handlers (server, plugin_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
unsigned int links_succeeded,
unsigned int links_failed)
{
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
if (4 != num_peers)
{
ok = 1;
* Function scheduled as very last function, cleans up after us
*
* @param cls NULL
- * @param tc scheduler context
*/
static void
cleanup (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("`%s' must be installed SUID, EXIT will not work\n"),
"gnunet-helper-exit");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &dummy_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&dummy_task,
+ NULL);
global_ret = 1;
return;
}
app_idx++;
}
GNUNET_free_non_null (dns_exit);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup,
+ NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_CONNECTIONS",
*/
static int do_disable_creation_time;
-/**
- * Handle for the 'shutdown' task.
- */
-static struct GNUNET_SCHEDULER_Task *kill_task;
-
/**
* Handle for the main task that does scanning and working.
*/
static void
do_stop_task (void *cls)
{
- kill_task = NULL;
do_shutdown = GNUNET_YES;
if (NULL != publish_proc)
{
run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
&scan,
NULL);
- kill_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+ NULL);
}
{
struct Pattern *p = cls;
struct GNUNET_FS_FileInformation *fi;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
p->task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
fi = make_file (p->x, p->y, p);
p->start_time = GNUNET_TIME_absolute_get ();
p->ctx = GNUNET_FS_publish_start (fs_handle,
{
struct Pattern *p = cls;
struct GNUNET_FS_Uri *keywords;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
p->task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
keywords = make_keywords (p->x);
p->start_time = GNUNET_TIME_absolute_get ();
p->sctx = GNUNET_FS_search_start (fs_handle, keywords,
cfg = cfg_;
/* Scheduled the task to clean up when shutdown is called */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
ctx = NULL;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
/**
- * Task run on timeout to terminate. Triggers printing out
+ * Task run on shutdown to terminate. Triggers printing out
* all statistics.
*
* @param cls NULL
static void
terminate_task (void *cls)
{
- terminate_taskid = NULL;
+ if (NULL != terminate_taskid)
+ {
+ GNUNET_SCHEDULER_cancel (terminate_taskid);
+ terminate_taskid = NULL;
+ }
GNUNET_TESTBED_get_statistics (0, NULL,
NULL, NULL,
&process_stats,
}
+/**
+ * Task run on timeout to terminate. Triggers printing out
+ * all statistics.
+ *
+ * @param cls NULL
+ */
+static void
+timeout_task (void *cls)
+{
+ terminate_taskid = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Signature of a main function for a testcase.
*
if (0 != timeout.rel_value_us)
terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout,
- &terminate_task, NULL);
- else
- terminate_taskid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &terminate_task,
+ &timeout_task,
NULL);
+ GNUNET_SCHEDULER_add_shutdown (&terminate_task,
+ NULL);
}
ret = 1;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_stop_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_stop_task,
+ NULL);
if (NULL != pseudonym)
identity = GNUNET_IDENTITY_connect (cfg,
&identity_cb,
static int local_only;
+static struct GNUNET_SCHEDULER_Task *tt;
+
+
/**
* Type of a function that libextractor calls for each
* meta data item found.
}
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Main function that will be run by the scheduler.
*
return;
}
if (0 != timeout.rel_value_us)
- GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_task, NULL);
- else
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout,
+ &timeout_task,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
GSF_cover_content_count = (GSF_cover_content_count * 15) / 16;
GSF_cover_query_count = (GSF_cover_query_count * 15) / 16;
cover_age_task =
- GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+ GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
+ &age_cover_counters,
NULL);
}
NULL);
GNUNET_SERVER_add_handlers (server, handlers);
cover_age_task =
- GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY, &age_cover_counters,
+ GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
+ &age_cover_counters,
NULL);
datastore_get_load = GNUNET_LOAD_value_init (DATASTORE_LOAD_AUTODECLINE);
GSF_cadet_start_server ();
GSF_cadet_start_client ();
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
return GNUNET_OK;
}
*/
static struct GNUNET_PEERSTORE_Handle *peerstore;
+/**
+ * Task used to flush respect values to disk.
+ */
+static struct GNUNET_SCHEDULER_Task *fr_task;
+
/**
* Update the latency information kept for the given peer.
{
struct GSF_DelayedHandle *dh = cls;
struct GSF_ConnectedPeer *cp = dh->cp;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_CONTAINER_DLL_remove (cp->delayed_head,
cp->delayed_tail,
dh);
cp->delay_queue_size--;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (dh->pm);
- GNUNET_free (dh);
- return;
- }
(void) GSF_peer_transmit_ (cp,
GNUNET_NO,
UINT32_MAX,
static void
cron_flush_respect (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- if (NULL == cp_map)
- return;
+ fr_task = NULL;
GNUNET_CONTAINER_multipeermap_iterate (cp_map,
- &flush_respect, NULL);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
- GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_respect, NULL);
+ &flush_respect,
+ NULL);
+ fr_task = GNUNET_SCHEDULER_add_delayed_with_priority (RESPECT_FLUSH_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_respect, NULL);
}
{
cp_map = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
peerstore = GNUNET_PEERSTORE_connect (GSF_cfg);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
- &cron_flush_respect, NULL);
+ fr_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ &cron_flush_respect, NULL);
}
&flush_respect,
NULL);
GNUNET_CONTAINER_multipeermap_iterate (cp_map,
- &clean_peer, NULL);
+ &clean_peer,
+ NULL);
+ GNUNET_SCHEDULER_cancel (fr_task);
+ fr_task = NULL;
GNUNET_CONTAINER_multipeermap_destroy (cp_map);
cp_map = NULL;
- GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+ GNUNET_PEERSTORE_disconnect (peerstore,
+ GNUNET_YES);
+
}
gather_dht_put_blocks (void *cls)
{
struct PutOperator *po = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
po->dht_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
po->dht_qe =
GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, po->current_offset++, 0,
UINT_MAX,
GNUNET_FS_stop (ctx);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
stop_source_peer (void *cls)
{
struct DownloadContext *dc = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- /* Do not interact with testbed when shutting down */
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ /* FIXME: We should not interact with testbed when shutting down */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stopping source peer\n");
- op = GNUNET_TESTBED_peer_stop (NULL, daemons[1], &do_download, dc);
+ op = GNUNET_TESTBED_peer_stop (NULL,
+ daemons[1],
+ &do_download, dc);
GNUNET_assert (NULL != op);
}
dc->uri = GNUNET_FS_uri_dup (uri);
if (NULL != fn)
dc->fn = GNUNET_strdup (fn);
- (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY, &stop_source_peer, dc);
+ (void) GNUNET_SCHEDULER_add_delayed (MIGRATION_DELAY,
+ &stop_source_peer,
+ dc);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Publishing %llu bytes\n",
(unsigned long long) FILESIZE);
- GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO, FILESIZE, SEED,
+ GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 1, GNUNET_NO,
+ FILESIZE, SEED,
VERBOSE, &do_wait, NULL);
}
p);
}
handle->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
- handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
- &reconnect_task,
- handle);
+ handle->reconnect_task
+ = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
+ &reconnect_task,
+ handle);
}
* Main request handler.
*/
static int
-access_handler_callback (void *cls, struct MHD_Connection *connection,
- const char *url, const char *method,
- const char *version, const char *upload_data,
- size_t * upload_data_size, void **con_cls)
+access_handler_callback (void *cls,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data,
+ size_t * upload_data_size,
+ void **con_cls)
{
static int dummy;
static const struct Entry map[] = {
run_daemon (void *cls)
{
struct MHD_Daemon *daemon_handle = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
http_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
http_task = prepare_daemon (daemon_handle);
}
if (GNUNET_OK !=
server_start ())
return;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &server_stop,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&server_stop,
+ NULL);
}
do_shutdown (void *cls)
{
if (NULL != t4)
+ {
GNUNET_SCHEDULER_cancel (t4);
+ t4 = NULL;
+ }
if (NULL != t6)
+ {
GNUNET_SCHEDULER_cancel (t6);
+ t6 = NULL;
+ }
if (NULL != listen_socket4)
{
GNUNET_NETWORK_socket_close (listen_socket4);
SOCK_DGRAM,
IPPROTO_UDP);
if (NULL != listen_socket4)
- {
- struct sockaddr_in v4;
-
- memset (&v4, 0, sizeof (v4));
- v4.sin_family = AF_INET;
+ {
+ struct sockaddr_in v4;
+
+ memset (&v4, 0, sizeof (v4));
+ v4.sin_family = AF_INET;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v4.sin_len = sizeof (v4);
+ v4.sin_len = sizeof (v4);
#endif
- v4.sin_port = htons (listen_port);
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (listen_socket4,
- (struct sockaddr *) &v4,
- sizeof (v4)))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- GNUNET_NETWORK_socket_close (listen_socket4);
- listen_socket4 = NULL;
- }
+ v4.sin_port = htons (listen_port);
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (listen_socket4,
+ (struct sockaddr *) &v4,
+ sizeof (v4)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+ GNUNET_NETWORK_socket_close (listen_socket4);
+ listen_socket4 = NULL;
}
+ }
listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6,
SOCK_DGRAM,
IPPROTO_UDP);
if (NULL != listen_socket6)
- {
- struct sockaddr_in6 v6;
-
- memset (&v6, 0, sizeof (v6));
- v6.sin6_family = AF_INET6;
+ {
+ struct sockaddr_in6 v6;
+
+ memset (&v6, 0, sizeof (v6));
+ v6.sin6_family = AF_INET6;
#if HAVE_SOCKADDR_IN_SIN_LEN
- v6.sin6_len = sizeof (v6);
+ v6.sin6_len = sizeof (v6);
#endif
- v6.sin6_port = htons (listen_port);
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (listen_socket6,
- (struct sockaddr *) &v6,
- sizeof (v6)))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
- GNUNET_NETWORK_socket_close (listen_socket6);
- listen_socket6 = NULL;
- }
+ v6.sin6_port = htons (listen_port);
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind (listen_socket6,
+ (struct sockaddr *) &v6,
+ sizeof (v6)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
+ GNUNET_NETWORK_socket_close (listen_socket6);
+ listen_socket6 = NULL;
}
+ }
if ( (NULL == listen_socket4) &&
(NULL == listen_socket6) )
- {
- GNUNET_GNS_disconnect (gns);
- gns = NULL;
- GNUNET_DNSSTUB_stop (dns_stub);
- dns_stub = NULL;
- return;
- }
+ {
+ GNUNET_GNS_disconnect (gns);
+ gns = NULL;
+ GNUNET_DNSSTUB_stop (dns_stub);
+ dns_stub = NULL;
+ return;
+ }
if (NULL != listen_socket4)
t4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
listen_socket4,
listen_socket6,
&read_dns6,
listen_socket6);
-
}
* @param c 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 *c)
{
cfg = c;
_("No DNS server specified!\n"));
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (NULL == gns_zone_str)
{
identity = GNUNET_IDENTITY_connect (cfg,
if ( (NULL == gns_zone_str) ||
(GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_public_key_from_string (gns_zone_str,
- strlen (gns_zone_str),
- &my_zone)) )
+ strlen (gns_zone_str),
+ &my_zone)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("No valid GNS zone specified!\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
if (NULL == identity)
ns = GNUNET_NAMESTORE_connect (cfg);
sh = GNUNET_IDENTITY_connect (cfg, &get_ego, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
struct GNUNET_NETWORK_Handle *lsock = cls;
struct GNUNET_NETWORK_Handle *s;
struct Socks5Request *s5r;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
if (lsock == lsock4)
ltask4 = NULL;
else
ltask6 = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (lsock == lsock4)
ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
lsock,
"gns-proxy",
&identity_master_cb,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
*/
static struct GNUNET_IDENTITY_Operation *id_op;
+/**
+ * Task scheduled to handle timeout.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
/**
* Task run on shutdown. Cleans up everything.
GNUNET_GNS_disconnect (gns);
gns = NULL;
}
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
+}
+
+
+/**
+ * Task run on timeout. Triggers shutdown.
+ *
+ * @param cls unused
+ */
+static void
+do_timeout (void *cls)
+{
+ tt = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
* @param c 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 *c)
{
struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
_("Failed to connect to GNS\n"));
return;
}
- GNUNET_SCHEDULER_add_delayed (timeout,
- &do_shutdown, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout,
+ &do_timeout, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (NULL != public_key)
{
if (GNUNET_OK !=
&monitor_sync_event,
NULL);
GNUNET_break (NULL != zmon);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
MHD_add_response_header (resp,
"Access-Control-Allow-Methods",
MHD_HTTP_METHOD_GET);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ handle->proc (handle->proc_cls,
+ resp,
+ MHD_HTTP_OK);
cleanup_handle (handle);
- return;
}
}
-
/**
* Entry point for the plugin.
*
NULL);
}
+
static void
start_curl (void *cls)
{
* specified target peer; NULL on error
*/
static void
-commence_testing (void *cls, int32_t success, const char *emsg)
+commence_testing (void *cls,
+ int32_t success,
+ const char *emsg)
{
GNUNET_SCHEDULER_add_now (&disco_ns, NULL);
- if ((emsg != NULL) && (GNUNET_YES != success))
+ if ( (emsg != NULL) && (GNUNET_YES != success) )
{
fprintf (stderr,
- "NS failed to create record %s\n", emsg);
+ "NS failed to create record %s\n",
+ emsg);
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), start_curl, NULL);
-
+ curl_task_id =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &start_curl, NULL);
}
-
-
/**
* Function to keep the HTTP server running.
*/
GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh,
advertising);
#endif
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleaning_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+ NULL);
if (NULL == core)
{
/**
* ID of the task, checking if hostlist download should take plate
*/
-static struct GNUNET_SCHEDULER_Task * ti_check_download;
+static struct GNUNET_SCHEDULER_Task *ti_check_download;
/**
* ID of the task downloading the hostlist
*/
-static struct GNUNET_SCHEDULER_Task * ti_download;
+static struct GNUNET_SCHEDULER_Task *ti_download;
/**
* ID of the task saving the hostlsit in a regular intervall
*/
-static struct GNUNET_SCHEDULER_Task * ti_saving_task;
+static struct GNUNET_SCHEDULER_Task *ti_saving_task;
/**
* ID of the task called to initiate a download
*/
-static struct GNUNET_SCHEDULER_Task * ti_download_dispatcher_task;
+static struct GNUNET_SCHEDULER_Task *ti_download_dispatcher_task;
/**
* ID of the task controlling the locking between two hostlist tests
*/
-static struct GNUNET_SCHEDULER_Task * ti_testing_intervall_task;
+static struct GNUNET_SCHEDULER_Task *ti_testing_intervall_task;
/**
* At what time MUST the current hostlist request be done?
{
CURLMcode mret;
- if ((stat_testing_hostlist == GNUNET_YES) &&
- (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test))
+ if ( (stat_testing_hostlist == GNUNET_YES) &&
+ (GNUNET_NO == stat_download_successful) &&
+ (NULL != hostlist_to_test) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_
hostlist_to_test = NULL;
}
- if (multi != NULL)
+ if (NULL != multi)
{
mret = curl_multi_remove_handle (multi, curl);
if (mret != CURLM_OK)
curl_multi_strerror (mret));
multi = NULL;
}
- if (curl != NULL)
+ if (NULL != curl)
{
curl_easy_cleanup (curl);
curl = NULL;
int running;
struct CURLMsg *msg;
CURLMcode mret;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
ti_download = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutdown requested while trying to download hostlist from `%s'\n",
- current_url);
- update_hostlist ();
- clean_up ();
- return;
- }
if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
static void
task_download_dispatcher (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
ti_download_dispatcher_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n");
if (GNUNET_NO == stat_download_in_progress)
{
{
static int once;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
ti_check_download = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (stats == NULL)
{
curl_global_cleanup ();
_("Have %u/%u connections. Will consider downloading hostlist in %s\n"),
stat_connection_count, MIN_CONNECTIONS,
GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
- ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL);
+ ti_check_download = GNUNET_SCHEDULER_add_delayed (delay,
+ &task_check, NULL);
}
static void
task_testing_intervall_reset (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
ti_testing_intervall_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
stat_testing_allowed = GNUNET_OK;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Testing new hostlist advertisements is allowed again\n");
static void
task_hostlist_saving (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
ti_saving_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
save_hostlist_file (GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Hostlists will be saved to file again in %s\n",
GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES));
ti_saving_task =
- GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving,
+ GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL,
+ &task_hostlist_saving,
NULL);
}
void
GNUNET_HOSTLIST_client_stop ()
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hostlist client shutdown\n");
if (NULL != sget)
{
GNUNET_STATISTICS_get_cancel (sget);
stats = NULL;
if (GNUNET_YES == stat_learning)
save_hostlist_file (GNUNET_YES);
- if (ti_saving_task != NULL)
+ if (NULL != ti_saving_task)
{
GNUNET_SCHEDULER_cancel (ti_saving_task);
ti_saving_task = NULL;
}
-
- if (ti_download_dispatcher_task != NULL)
+ if (NULL != ti_download_dispatcher_task)
{
GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task);
ti_download_dispatcher_task = NULL;
}
- if (ti_testing_intervall_task != NULL)
+ if (NULL != ti_testing_intervall_task)
{
GNUNET_SCHEDULER_cancel (ti_testing_intervall_task);
ti_testing_intervall_task = NULL;
}
- if (ti_download != NULL)
+ if (NULL != ti_download)
{
GNUNET_SCHEDULER_cancel (ti_download);
ti_download = NULL;
+ update_hostlist ();
+ clean_up ();
}
- if (ti_check_download != NULL)
+ if (NULL != ti_check_download)
{
GNUNET_SCHEDULER_cancel (ti_check_download);
ti_check_download = NULL;
/**
* Our primary task for IPv4.
*/
-static struct GNUNET_SCHEDULER_Task * hostlist_task_v4;
+static struct GNUNET_SCHEDULER_Task *hostlist_task_v4;
/**
* Our primary task for IPv6.
*/
-static struct GNUNET_SCHEDULER_Task * hostlist_task_v6;
+static struct GNUNET_SCHEDULER_Task *hostlist_task_v6;
/**
* Our canonical response.
run_daemon (void *cls)
{
struct MHD_Daemon *daemon_handle = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
if (daemon_handle == daemon_handle_v4)
hostlist_task_v4 = NULL;
else
hostlist_task_v6 = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
if (daemon_handle == daemon_handle_v4)
hostlist_task_v4 = prepare_daemon (daemon_handle);
wrs = GNUNET_NETWORK_fdset_create ();
wws = GNUNET_NETWORK_fdset_create ();
max = -1;
- GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
+ GNUNET_assert (MHD_YES ==
+ MHD_get_fdset (daemon_handle,
+ &rs, &ws, &es, &max));
haveto = MHD_get_timeout (daemon_handle, &timeout);
if (haveto == MHD_YES)
tv.rel_value_us = (uint64_t) timeout * 1000LL;
tv = GNUNET_TIME_UNIT_FOREVER_REL;
GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1);
GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
- ret =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
- tv, wrs, wws,
- &run_daemon, daemon_handle);
+ ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
+ tv, wrs, wws,
+ &run_daemon, daemon_handle);
GNUNET_NETWORK_fdset_destroy (wrs);
GNUNET_NETWORK_fdset_destroy (wws);
return ret;
static int ok;
-static struct GNUNET_SCHEDULER_Task * timeout_task;
+static struct GNUNET_SCHEDULER_Task *timeout_task;
struct PeerContext
{
* @param distance in overlay hops, as given by transport plugin
*/
static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
if (peer == NULL)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peers connected, shutting down.\n");
ok = 0;
if (timeout_task != NULL)
{
static void
-process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
static void
stop_arm (struct PeerContext *p)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking ARM to stop core service\n");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &waitpid_task, p);
}
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_assert (ok == 1);
ok++;
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &timeout_error,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
}
static int
-process_adv_sent (void *cls, const char *subsystem, const char *name,
+process_adv_sent (void *cls,
+ const char *subsystem,
+ const char *name,
uint64_t value, int is_persistent)
{
if ((value >= 1) && (adv_sent == GNUNET_NO))
check_statistics (void *cls)
{
char *stat;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
check_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
+ GNUNET_asprintf (&stat,
+ gettext_noop ("# advertised URI `%s' downloaded"),
current_adv_uri);
if (NULL != learn_peer.stats)
{
* Core handler for p2p hostlist advertisements
*/
static int
-ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
+ad_arrive_handler (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
{
char *hostname;
* @param distance in overlay hops, as given by transport plugin
*/
static void
-notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
if (peer == NULL)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peers connected, shutting down.\n");
ok = 0;
if (timeout_task != NULL)
{
static void
-process_hello (void *cls, const struct GNUNET_MessageHeader *message)
+process_hello (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct PeerContext *p = cls;
stop_arm (struct PeerContext *p)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &waitpid_task, p);
}
{
GNUNET_assert (ok == 1);
ok++;
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &timeout_error, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &shutdown_task,
NULL);
setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf");
setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf");
/**
* Timeout task
*/
-static struct GNUNET_SCHEDULER_Task * timeout_task;
-
+static struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Update task
*/
-static struct GNUNET_SCHEDULER_Task * update_task;
+static struct GNUNET_SCHEDULER_Task *update_task;
/**
* Timeout for next update pass
scopes = NULL;
}
+
static void
update_identities(void *cls);
+
/**
*
* Cleanup attr_map
* @param cls NULL
* @param key the key
* @param value the json_t attribute value
- * @return GNUNET_YES
+ * @return #GNUNET_YES
*/
static int
clear_ego_attrs (void *cls,
return GNUNET_YES;
}
+
/**
*
* Update all ID_TOKEN records for an identity and store them
* @param lbl the name of the record
* @param rd_count number of records
* @param rd record data
- *
*/
static void
token_collect (void *cls,
{
token_metadata_record = &rd[0];
token_record = &rd[1];
- } else {
+ }
+ else
+ {
token_record = &rd[0];
token_metadata_record = &rd[1];
}
label = GNUNET_strdup (lbl);
rd_exp = token_record->expiration_time;
- GNUNET_SCHEDULER_add_now (&handle_token_update, ego_entry);
+ GNUNET_SCHEDULER_add_now (&handle_token_update,
+ ego_entry);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
">>> Updating Attributes finished\n");
ego_entry->attributes_dirty = GNUNET_NO;
- update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_entry);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_entry);
return;
}
}
-
/**
* Function called initially to start update task
*/
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, ">>> Starting Service\n");
//Initially iterate all itenties and refresh all tokens
- update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_head);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_head);
}
+
/**
* Initial ego collection function.
*
struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
char *ticket_str;
char *token_str;
+
handle->ns_qe = NULL;
if (GNUNET_SYSERR == success)
{
GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
- irm = create_issue_result_message (handle->label, ticket_str, token_str);
+ irm = create_issue_result_message (handle->label,
+ ticket_str,
+ token_str);
GNUNET_SERVER_notification_context_unicast (nc,
handle->client,
&irm->header,
token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
/**
- *
* The main function
*
* @param argc number of arguments from the cli
* @param argv command line arguments
* @return 0 ok, 1 on error
- *
*/
int
main (int argc, char *const *argv)
&run, NULL)) ? 0 : 1;
}
-/* end of gnunet-rest-server.c */
+/* end of gnunet-service-identity-provider.c */
/**
* ID of a task associated with the resolution process.
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* The plugin result processor
/**
- * Task run on shutdown. Cleans up everything.
+ * Task run on error, sends error message. Cleans up everything.
*
- * @param cls unused
+ * @param cls the `struct RequestHandle`
*/
static void
do_error (void *cls)
GNUNET_free (json_error);
}
+/**
+ * Task run on timeout, sends error message. Cleans up everything.
+ *
+ * @param cls the `struct RequestHandle`
+ */
+static void
+do_timeout (void *cls)
+{
+ struct RequestHandle *handle = cls;
+
+ handle->timeout_task = NULL;
+ do_error (handle);
+}
+
+
/**
* Task run on shutdown. Cleans up everything.
*
do_cleanup_handle_delayed (void *cls)
{
struct RequestHandle *handle = cls;
- cleanup_handle(handle);
+
+ cleanup_handle (handle);
}
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result_str);
GNUNET_SCHEDULER_add_now (&do_cleanup_handle_delayed, handle);
-
-
}
+
/**
* Continueationf for token issue request
*
GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
&key) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Issuer not found\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Issuer not found\n");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
if (NULL == ego_val)
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Ego invalid: %s\n", ego_val);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Ego invalid: %s\n",
+ ego_val);
return;
}
for (ego_entry = handle->ego_head;
egoname = ego_entry->identifier;
break;
}
- if (NULL == egoname || NULL == ego_entry)
+ if ( (NULL == egoname) ||
+ (NULL == ego_entry) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Ego not found: %s\n", ego_val);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Ego not found: %s\n",
+ ego_val);
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego to issue token for: %s\n", egoname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Ego to issue token for: %s\n",
+ egoname);
//Meta info
GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
&key) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Audience missing!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Audience missing!\n");
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
audience = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
&key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience to issue token for: %s\n", audience);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Audience to issue token for: %s\n",
+ audience);
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego,
}
nonce_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
&key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request nonce: %s\n", nonce_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request nonce: %s\n",
+ nonce_str);
sscanf (nonce_str, "%"SCNu64, &nonce);
//Get expiration for token from URL parameter
handle);
handle->timeout_task =
GNUNET_SCHEDULER_add_delayed (handle->timeout,
- &do_error,
+ &do_timeout,
handle);
-
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connected\n");
}
create_ego,
&create_finished,
&create_op);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
test_finished ();
}
GNUNET_DISK_directory_scan (ego_directory,
&process_ego_file,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
/**
- * Task run on shutdown. Cleans up everything.
+ * Task run on errors. Reports an error and cleans up everything.
*
- * @param cls unused
+ * @param cls the `struct RequestHandle`
*/
static void
do_error (void *cls)
&handle->emsg);
resp = GNUNET_REST_create_json_response (json_error);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST);
+ handle->proc (handle->proc_cls,
+ resp,
+ MHD_HTTP_BAD_REQUEST);
cleanup_handle (handle);
GNUNET_free (json_error);
}
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = NULL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &end_normally, NULL);
+ GNUNET_SCHEDULER_add_now (&end_normally, NULL);
}
/**
* Version of the API (for entire gnunetutil.so library).
*/
-#define GNUNET_UTIL_VERSION 0x000A0100
+#define GNUNET_UTIL_VERSION 0x000A0101
/**
GNUNET_SCHEDULER_REASON_STARTUP = 1,
/**
- * We are shutting down and are running all shutdown-related tasks
- * (regardless of timeout, etc.).
+ * We are shutting down and are running all shutdown-related tasks.
*/
GNUNET_SCHEDULER_REASON_SHUTDOWN = 2,
* tasks have completed. On systems with signals, receiving a SIGTERM
* (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown
* to be run after the active task is complete. As a result, SIGTERM
- * causes all active tasks to be scheduled with reason
+ * causes all shutdown tasks to be scheduled with reason
* #GNUNET_SCHEDULER_REASON_SHUTDOWN. (However, tasks added
* afterwards will execute normally!). Note that any particular
* signal will only shut down one scheduler; applications should
/**
- * Request the shutdown of the scheduler. Marks all currently
- * pending tasks as ready because of shutdown. This will
- * cause all tasks to run (as soon as possible, respecting
- * priorities and prerequisite tasks). Note that tasks
- * scheduled AFTER this call may still be delayed arbitrarily.
+ * Request the shutdown of a scheduler. Marks all tasks
+ * awaiting shutdown as ready. Note that tasks
+ * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
+ * will be delayed until the next shutdown signal.
*/
void
GNUNET_SCHEDULER_shutdown (void);
void *task_cls);
+/**
+ * Schedule a new task to be run on shutdown, that is when a CTRL-C
+ * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being
+ * invoked.
+ *
+ * @param task main function of the task
+ * @param task_cls closure of @a task
+ * @return unique task identifier for the job
+ * only valid until @a task is started!
+ */
+struct GNUNET_SCHEDULER_Task *
+GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls);
+
+
/**
* Schedule a new task to be run as soon as possible with the
* (transitive) ignore-shutdown flag either explicitly set or
* will be scheduled for execution once the delay has expired. It
* will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param task main function of the task
* @param task_cls closure of @a task
* @return unique task identifier for the job
* Schedule a new task to be run with a specified delay. The task
* will be scheduled for execution once the delay has expired.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* either the delay has expired or the socket operation is ready. It
* will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param rfd read file-descriptor
* @param task main function of the task
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
* (prerequisite-run)
* && (delay-ready
* || any-rs-ready
- * || any-ws-ready
- * || shutdown-active)
+ * || any-ws-ready)
* </code>
*
* @param prio how important is this task?
- * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever",
- * which means that the task will only be run after we receive SIGTERM
+ * @param delay how long should we wait?
* @param rs set of file descriptors we want to read (can be NULL)
* @param ws set of file descriptors we want to write (can be NULL)
* @param task main function of the task
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, server_handlers);
- GNUNET_SERVER_disconnect_notify (server, &client_notify_disconnect, NULL);
-
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SERVER_disconnect_notify (server,
+ &client_notify_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
* @param cfg configuration to use
*/
static void
-run (void *cls, struct GNUNET_SERVER_Handle *srv,
+run (void *cls,
+ struct GNUNET_SERVER_Handle *srv,
const struct GNUNET_CONFIGURATION_Handle *c)
{
cfg = c;
break;
case TEST_MEMBER_PART:
- GNUNET_SCHEDULER_add_now (schedule_origin_stop, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_origin_stop, NULL);
break;
default:
test = TEST_MEMBER_PART;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Test #%u: member_part()\n", test);
- GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
}
{
case TEST_MEMBER_JOIN_REFUSE:
GNUNET_assert (0 == relay_count);
- GNUNET_SCHEDULER_add_now (schedule_member_part, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_member_part, NULL);
break;
case TEST_MEMBER_JOIN_ADMIT:
*/
static void
#if DEBUG_TEST_MULTICAST
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
#else
run (void *cls,
#endif
{
cfg = c;
- end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
-
- core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
- NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
+ end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, NULL);
+ core = GNUNET_CORE_connect (cfg, NULL,
+ &core_connected, NULL, NULL,
+ NULL, GNUNET_NO,
+ NULL, GNUNET_NO,
+ NULL);
}
return;
}
-
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
ns = GNUNET_NAMECACHE_connect (cfg);
GNUNET_GNSRECORD_query_from_public_key (&pubkey,
name,
GNUNET_SERVER_disconnect_notify (server,
&client_disconnect_notification,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Block was decrypted successfully \n");
-
- GNUNET_SCHEDULER_add_now (&end, NULL);
+
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
+
static void
name_lookup_proc (void *cls,
const struct GNUNET_GNSRECORD_Block *block)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Namecache returned no block\n"));
- if (endbadly_task != NULL)
+ if (NULL != endbadly_task)
GNUNET_SCHEDULER_cancel (endbadly_task);
endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL);
return;
}
id_op = GNUNET_IDENTITY_get (identity, "fcfsd",
&identity_cb, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
ret = -1;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, (void *) cfg);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg);
if (NULL == ego_name)
{
GNUNET_SERVER_disconnect_notify (server,
&client_disconnect_notification,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
/**
* Cleanup lookup handle
+ *
* @param handle Handle to clean up
*/
static void
struct RecordEntry *record_entry;
struct RecordEntry *record_tmp;
int i;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Cleaning up\n");
if (NULL != handle->resp_object)
GNUNET_free (handle);
}
+
/**
* Create json representation of a GNSRECORD
*
/**
- * Task run on shutdown. Cleans up everything.
+ * Task run on error. Generates error response and cleans up.
*
- * @param cls unused
+ * @param cls the request to generate an error response for
*/
static void
do_error (void *cls)
}
+/**
+ * Task run on timeout.
+ *
+ * @param cls the request to time out
+ */
+static void
+do_timeout (void *cls)
+{
+ struct RequestHandle *handle = cls;
+
+ handle->timeout_task = NULL;
+ do_error (handle);
+}
+
+
static void
cleanup_handle_delayed (void *cls)
{
&testservice_id_task,
handle);
handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
- &do_error,
+ &do_timeout,
handle);
-
-
}
/**
GNUNET_SERVER_create (NULL, NULL, (struct sockaddr * const *) sa, slen,
GNUNET_TIME_UNIT_SECONDS, GNUNET_YES);
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
*/
static void
add_ip_to_address_list (struct GNUNET_NAT_Handle *h,
- enum LocalAddressSource src, const void *addr,
+ enum LocalAddressSource src,
+ const void *addr,
socklen_t addrlen)
{
struct sockaddr_in s4;
GNUNET_break (0);
return GNUNET_OK;
}
- if ((h->internal_address == NULL) && (h->server_proc == NULL) &&
- (h->server_read_task == NULL) &&
- (GNUNET_YES == isDefault) && ((addr->sa_family == AF_INET) ||
- (addr->sa_family == AF_INET6)))
+ if ( (h->internal_address == NULL) &&
+ (h->server_proc == NULL) &&
+ (h->server_read_task == NULL) &&
+ (GNUNET_YES == isDefault) &&
+ ( (addr->sa_family == AF_INET) ||
+ (addr->sa_family == AF_INET6) ) )
{
/* no internal address configured, but we found a "default"
* interface, try using that as our 'internal' address */
restart_nat_server (void *cls)
{
struct GNUNET_NAT_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->server_read_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
start_gnunet_nat_server (h);
}
int port;
const char *port_start;
struct sockaddr_in sin_addr;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->server_read_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
memset (mybuf, 0, sizeof (mybuf));
bytes =
GNUNET_DISK_file_read (h->server_stdout_handle, mybuf, sizeof (mybuf));
sizeof (sin_addr));
h->server_read_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->server_stdout_handle, &nat_server_read,
+ h->server_stdout_handle,
+ &nat_server_read,
h);
}
(GNUNET_NETWORK_fdset_isset (tc->read_ready,
lsock4)))
{
- rlen = GNUNET_NETWORK_socket_recv (lsock4, reply_buf, sizeof (reply_buf));
+ rlen = GNUNET_NETWORK_socket_recv (lsock4,
+ reply_buf,
+ sizeof (reply_buf));
//Lets handle the packet
memset(&answer, 0, sizeof(struct sockaddr_in));
}
else
{
- if (GNUNET_OK == GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
+ if (GNUNET_OK ==
+ GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
{
//Process the answer
process_stun_reply (&answer, ah);
next_phase (ah);
}
-
-
-
}
}
-
-
-static void request_callback (void *cls,
- enum GNUNET_NAT_StatusCode result)
+static void
+request_callback (void *cls,
+ enum GNUNET_NAT_StatusCode result)
{
// struct GNUNET_NAT_AutoHandle *ah = cls;
stop_stun ();
// next_phase (ah); FIXME this always will be NULL, as called in test_stun()
-};
-
-
-
+}
/**
{
//Lets call our function now when it accepts
ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
- lsock4, &do_udp_read, ah);
-
+ lsock4,
+ &do_udp_read,
+ ah);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"STUN service listens on port %u\n",
port);
- if (GNUNET_NO == GNUNET_NAT_stun_make_request (stun_server, stun_port,
- lsock4, &request_callback,
- NULL))
+ if (GNUNET_NO ==
+ GNUNET_NAT_stun_make_request (stun_server, stun_port,
+ lsock4,
+ &request_callback,
+ NULL))
{
/*An error happened*/
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n");
}
-
/**
* Process list of local IP addresses. Find and set the
* one of the default interface.
* @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned)
* @param netmask the network mask (can be NULL for unknown or unassigned))
* @param addrlen length of the @a addr and @a broadcast_addr
- * @return GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
+ * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
*/
static int
process_if (void *cls,
- const char *name,
- int isDefault,
- const struct sockaddr *addr,
- const struct sockaddr *broadcast_addr,
- const struct sockaddr *netmask,
- socklen_t addrlen)
+ const char *name,
+ int isDefault,
+ const struct sockaddr *addr,
+ const struct sockaddr *broadcast_addr,
+ const struct sockaddr *netmask,
+ socklen_t addrlen)
{
struct GNUNET_NAT_AutoHandle *ah = cls;
const struct sockaddr_in *in;
static void
test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
{
-
struct GNUNET_CLIENT_Connection *client;
struct GNUNET_NAT_TestMessage msg;
-
if (ah->stun_ip)
{
LOG (GNUNET_ERROR_TYPE_INFO,
{
GNUNET_SCHEDULER_cancel (ltask4);
ltask4 = GNUNET_SCHEDULER_add_read_net (NAT_SERVER_TIMEOUT,
- lsock4, &do_udp_read, ah);
+ lsock4,
+ &do_udp_read,
+ ah);
}
-
}
else
{
"We don't have a STUN IP");
next_phase(ah);
}
-
-
}
-
-
/**
* Test if UPnPC works.
*
ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah);
else
next_phase (ah);
-
}
static void
test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
{
-
-
char *tmp;
char *helper;
if (GNUNET_YES !=
GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("test_icmp_server not possible, as we are not behind NAT\n"));
}
else
goto err;
if (GNUNET_YES ==
GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){
// none of these parameters are actually used in privilege testing mode
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("No working gnunet-helper-nat-server found\n"));
}
err:
GNUNET_free_non_null (tmp);
GNUNET_free (helper);
next_phase (ah);
-
}
GNUNET_CONFIGURATION_destroy (diff);
GNUNET_NAT_autoconfig_cancel (ah);
return;
-
}
-
-
-
}
eh->task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
+ if (GNUNET_YES ==
+ GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
+ {
ret =
GNUNET_DISK_file_read (eh->r, &eh->buf[eh->off],
sizeof (eh->buf) - eh->off);
- else {
+ }
+ else
+ {
eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
ret = -1; /* error reading, timeout, etc. */
}
GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
if (NULL == mini->refresh_task)
mini->refresh_task =
- GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
+ &do_refresh,
+ mini);
return;
}
/*
ret->is_tcp = is_tcp;
ret->port = port;
ret->refresh_task =
- GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, ret);
+ GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
+ &do_refresh,
+ ret);
run_upnpc_r (ret);
return ret;
}
tc = GNUNET_SCHEDULER_get_task_context ();
na->rtask = NULL;
tst = na->h;
- GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head,
+ tst->na_tail,
+ na);
if ((NULL != tc->write_ready) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) &&
(sizeof (data) ==
struct GNUNET_NAT_Test *tst = cls;
struct GNUNET_NETWORK_Handle *s;
struct NatActivity *wl;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tst->ltask = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
tst->ltask =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, tst->lsock,
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ tst->lsock,
&do_accept, tst);
s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL);
if (NULL == s)
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
wl->sock,
&do_read, wl);
- GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl);
+ GNUNET_CONTAINER_DLL_insert (tst->na_head,
+ tst->na_tail,
+ wl);
}
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5));
nh->ltask =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- nh->lsock, &do_accept, nh);
+ nh->lsock,
+ &do_accept, nh);
}
else
{
nh->ltask =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- nh->lsock, &do_udp_read, nh);
+ nh->lsock,
+ &do_udp_read, nh);
}
LOG (GNUNET_ERROR_TYPE_INFO,
"NAT test listens on port %u (%s)\n",
return nh;
}
}
- nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, nh);
+ nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout,
+ &do_timeout,
+ nh);
return nh;
}
"Stopping NAT test\n");
while (NULL != (cpos = tst->ca_head))
{
- GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos);
+ GNUNET_CONTAINER_DLL_remove (tst->ca_head,
+ tst->ca_tail,
+ cpos);
GNUNET_CLIENT_disconnect (cpos->client);
GNUNET_free (cpos);
}
while (NULL != (pos = tst->na_head))
{
- GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos);
+ GNUNET_CONTAINER_DLL_remove (tst->na_head,
+ tst->na_tail,
+ pos);
GNUNET_SCHEDULER_cancel (pos->rtask);
GNUNET_NETWORK_socket_close (pos->sock);
GNUNET_free (pos);
{
struct GNUNET_NAT_Handle *nat = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping NAT and quitting...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Stopping NAT and quitting...\n");
GNUNET_NAT_unregister (nat);
}
*/
static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
-/**
- * The shutdown task
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
/**
* Maximum number of connections to NSE services.
*/
static struct OpListEntry *oplist_tail;
/**
- * Are we shutting down
+ * Task running each round of the experiment.
*/
-static int shutting_down;
+static struct GNUNET_SCHEDULER_Task *round_task;
/**
static void
shutdown_task (void *cls)
{
- shutdown_task_id = NULL;
- if (GNUNET_YES == shutting_down)
- return;
- shutting_down = GNUNET_YES;
LOG_DEBUG ("Ending test.\n");
close_monitor_connections ();
+ if (NULL != round_task)
+ {
+ GNUNET_SCHEDULER_cancel (round_task);
+ round_task = NULL;
+ }
if (NULL != data_file)
{
GNUNET_DISK_file_close (data_file);
output_file = NULL;
}
if (NULL != testing_cfg)
+ {
GNUNET_CONFIGURATION_destroy (testing_cfg);
- testing_cfg = NULL;
-}
-
-
-/**
- * Schedules shutdown task to be run now
- */
-static void
-shutdown_now ()
-{
- if (NULL != shutdown_task_id)
- GNUNET_SCHEDULER_cancel (shutdown_task_id);
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ testing_cfg = NULL;
+ }
}
static void
finish_round (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
- LOG (GNUNET_ERROR_TYPE_INFO, "Have %u connections\n", total_connections);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ "Have %u connections\n",
+ total_connections);
close_monitor_connections ();
- GNUNET_SCHEDULER_add_now (&next_round, NULL);
+ round_task = GNUNET_SCHEDULER_add_now (&next_round, NULL);
}
static void
run_round ()
{
- LOG_DEBUG ("Running round %u\n", current_round);
+ LOG_DEBUG ("Running round %u\n",
+ current_round);
connect_nse_service ();
GNUNET_SCHEDULER_add_delayed (wait_time,
&finish_round,
struct OpListEntry *entry;
entry = GNUNET_new (struct OpListEntry);
- GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry);
+ GNUNET_CONTAINER_DLL_insert_tail (oplist_head,
+ oplist_tail,
+ entry);
return entry;
}
* @param emsg NULL on success; otherwise an error description
*/
static void
-manage_service_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
+manage_service_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
struct OpListEntry *entry = cls;
}
GNUNET_assert (0 != entry->delta);
peers_running += entry->delta;
- GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
+ GNUNET_CONTAINER_DLL_remove (oplist_head,
+ oplist_tail,
+ entry);
GNUNET_free (entry);
if (num_peers_in_round[current_round] == peers_running)
run_round ();
static void
next_round (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
+ round_task = NULL;
LOG_DEBUG ("Disconnecting nse service of peers\n");
current_round++;
if (current_round == num_rounds)
- {
- /* this was the last round, terminate */
- ok = 0;
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ {
+ /* this was the last round, terminate */
+ ok = 0;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (num_peers_in_round[current_round] == peers_running)
- {
- /* no need to churn, just run next round */
- run_round ();
- return;
- }
+ {
+ /* no need to churn, just run next round */
+ run_round ();
+ return;
+ }
adjust_running_peers ();
}
{
if (NULL == peers)
{
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
daemons = peers;
NULL, /* master_controller_cb cls */
&test_master,
NULL); /* test_master cls */
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
GNUNET_TIME_UNIT_SECONDS,
nse_test_result,
NULL);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
}
delay =
get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0);
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &transmit_task_cb,
+ peer_entry);
return GNUNET_OK;
}
{
struct GNUNET_TIME_Relative offset;
unsigned int i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
flood_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
offset = GNUNET_TIME_absolute_get_remaining (next_timestamp);
if (0 != offset.rel_value_us)
{
/* somehow run early, delay more */
flood_task =
- GNUNET_SCHEDULER_add_delayed (offset, &update_flood_message, NULL);
+ GNUNET_SCHEDULER_add_delayed (offset,
+ &update_flood_message, NULL);
return;
}
estimate_index = (estimate_index + 1) % HISTORY_SIZE;
NULL);
flood_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (next_timestamp), &update_flood_message,
+ (next_timestamp),
+ &update_flood_message,
NULL);
}
}
delay = get_transmit_delay (0);
peer_entry->transmit_task =
- GNUNET_SCHEDULER_add_delayed (delay, &transmit_task_cb, peer_entry);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &transmit_task_cb, peer_entry);
return GNUNET_OK;
}
}
flood_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
- (next_timestamp), &update_flood_message,
+ (next_timestamp),
+ &update_flood_message,
NULL);
}
}
#endif
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
GNUNET_assert (NULL != pk);
my_private_key = pk;
* @param msg message received, NULL on timeout or fatal error
*/
static void
-message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+message_handler (void *cls,
+ const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_NSE_Handle *h = cls;
const struct GNUNET_NSE_ClientMessage *client_msg;
GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
GNUNET_YES));
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+ &reconnect, h);
h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
&nse_connect_adapter,
&nse_disconnect_adapter,
&nse_peers[i]);
- GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &shutdown_task, NULL);
}
{
tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
*/
static struct NotificationContext *nc_tail;
+/**
+ * Handle for task to run #cron_clean_data_hosts()
+ */
+static struct GNUNET_SCHEDULER_Task *cron_clean;
+
+/**
+ * Handle for task to run #cron_scan_directory_hosts()
+ */
+static struct GNUNET_SCHEDULER_Task *cron_scan;
+
/**
* Notify all clients in the notify list about the
{
static unsigned int retries;
struct DirScanContext dsc;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
- if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
+ cron_scan = NULL;
+ if (GNUNET_SYSERR ==
+ GNUNET_DISK_directory_create (networkIdDirectory))
{
- GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts, NULL);
+ cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts, NULL);
return;
}
dsc.matched = 0;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
_("Still no peers found in `%s'!\n"),
networkIdDirectory);
- GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts,
- NULL);
+ cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
}
cron_clean_data_hosts (void *cls)
{
struct GNUNET_TIME_Absolute now;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ cron_clean = NULL;
now = GNUNET_TIME_absolute_get ();
GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
_("Cleaning up directory `%s'\n"),
GNUNET_DISK_directory_scan (networkIdDirectory,
&discard_hosts_helper,
&now);
- GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
- &cron_clean_data_hosts,
- NULL);
+ cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
+ &cron_clean_data_hosts,
+ NULL);
}
GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
stats = NULL;
}
+ if (NULL != cron_clean)
+ {
+ GNUNET_SCHEDULER_cancel (cron_clean);
+ cron_clean = NULL;
+ }
+ if (NULL != cron_scan)
+ {
+ GNUNET_SCHEDULER_cancel (cron_scan);
+ cron_scan = NULL;
+ }
}
"USE_INCLUDED_HELLOS");
if (GNUNET_SYSERR == use_included)
use_included = GNUNET_NO;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (GNUNET_YES != noio)
{
GNUNET_assert (GNUNET_OK ==
return;
}
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_scan_directory_data_hosts, NULL);
+ cron_scan = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_scan_directory_data_hosts,
+ NULL);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &cron_clean_data_hosts, NULL);
+ cron_clean = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &cron_clean_data_hosts,
+ NULL);
if (GNUNET_YES == use_included)
{
ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic);
ac->cont = &iterator_start_receive;
ac->cont_cls = ic;
- GNUNET_CONTAINER_DLL_insert_tail (h->ac_head, h->ac_tail, ac);
+ GNUNET_CONTAINER_DLL_insert_tail (h->ac_head,
+ h->ac_tail,
+ ac);
GNUNET_CONTAINER_DLL_insert_tail (h->ic_head,
h->ic_tail,
ic);
/**
* Tasked used for delayed re-connection attempt.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Include friend only HELLOs in callbacks
{
/* ugh */
nc->task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, nc);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &reconnect, nc);
return;
}
request_notifications (nc);
return ret;
}
+
static void
-process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Message *hello, const char *err_msg)
+process_w_fo (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_HELLO_Message *hello,
+ const char *err_msg)
{
- if (err_msg != NULL )
+ if (err_msg != NULL)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
_("Error in communication with PEERINFO service\n"));
- GNUNET_SCHEDULER_add_now (&done, NULL );
+ GNUNET_SCHEDULER_add_now (&done, NULL);
return;
}
if (0 == memcmp (&pid, peer, sizeof(pid)))
{
res_cb_w_fo = GNUNET_YES;
- GNUNET_SCHEDULER_add_now (&done, NULL );
+ GNUNET_SCHEDULER_add_now (&done, NULL);
}
return;
}
process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Message *hello, const char *err_msg)
{
- if (err_msg != NULL )
+ if (err_msg != NULL)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
_("Error in communication with PEERINFO service\n"));
- GNUNET_SCHEDULER_add_now (&done, NULL );
+ GNUNET_SCHEDULER_add_now (&done, NULL);
return;
}
}
}
+
static void
add_peer_done (void *cls, const char *emsg)
{
{
GNUNET_break(0);
GNUNET_SCHEDULER_cancel (timeout_task);
- timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL );
+ timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
}
}
+
static void
add_peer ()
{
memset (&pid, 32, sizeof(pid));
h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc,
GNUNET_YES);
- GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL );
+ GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL);
GNUNET_free(h2);
}
+
static void
-run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Peer *peer)
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
{
- timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL );
+ timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
mycfg = cfg;
- pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL );
- pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL );
+ pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
+ pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
h = GNUNET_PEERINFO_connect (cfg);
GNUNET_assert(NULL != h);
add_peer ();
}
+
int
main (int argc, char *argv[])
{
res_cb_w_fo = GNUNET_NO;
res_cb_wo_fo = GNUNET_NO;
global_ret = 3;
- if (0
- != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
- "peerinfo", "test_peerinfo_api_data.conf", &run, NULL ))
+ if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
+ "peerinfo",
+ "test_peerinfo_api_data.conf",
+ &run, NULL))
return 1;
return global_ret;
}
* @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)
{
-
- peerstore_handle = NULL;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
GNUNET_assert (NULL != peerstore_handle);
-
ret = 0;
}
*/
static struct ClientEntry *client_tail;
+/**
+ * Task run to clean up expired records.
+ */
+static struct GNUNET_SCHEDULER_Task *expire_task;
+
/**
* Are we in the process of shutting down the service? #GNUNET_YES / #GNUNET_NO
*/
GNUNET_CONTAINER_multihashmap_destroy (watchers);
watchers = NULL;
}
+ if (NULL != expire_task)
+ {
+ GNUNET_SCHEDULER_cancel (expire_task);
+ expire_task = NULL;
+ }
GNUNET_SCHEDULER_shutdown ();
}
cleanup_expired_records (void *cls)
{
int ret;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ expire_task = NULL;
GNUNET_assert (NULL != db);
- ret =
- db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
- expire_records_continuation, NULL);
+ ret = db->expire_records (db->cls, GNUNET_TIME_absolute_get (),
+ &expire_records_continuation, NULL);
if (GNUNET_OK != ret)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records, NULL);
+ GNUNET_assert (NULL == expire_task);
+ expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records, NULL);
}
}
* @param success count of records deleted or #GNUNET_SYSERR
*/
static void
-expire_records_continuation (void *cls, int success)
+expire_records_continuation (void *cls,
+ int success)
{
if (success > 0)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", success);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS,
- EXPIRED_RECORDS_CLEANUP_INTERVAL),
- &cleanup_expired_records, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%d records expired.\n",
+ success);
+ GNUNET_assert (NULL == expire_task);
+ expire_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS,
+ EXPIRED_RECORDS_CLEANUP_INTERVAL),
+ &cleanup_expired_records, NULL);
}
if (NULL == db)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Could not load database backend `%s'\n"), db_lib_name);
+ _("Could not load database backend `%s'\n"),
+ db_lib_name);
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
nc = GNUNET_SERVER_notification_context_create (server, 16);
watchers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
- GNUNET_SCHEDULER_add_now (&cleanup_expired_records, NULL);
+ expire_task = GNUNET_SCHEDULER_add_now (&cleanup_expired_records,
+ NULL);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_connect_notify (server, &handle_client_connect, NULL);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
* Task identifier for the function called
* on iterate request timeout
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
};
* @return #GNUNET_YES (continue to iterate)
*/
static int
-rewatch_it (void *cls, const struct GNUNET_HashCode *key, void *value)
+rewatch_it (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
{
struct GNUNET_PEERSTORE_Handle *h = cls;
struct GNUNET_PEERSTORE_WatchContext *wc = value;
if (NULL != chn->tmit_head)
{
- GNUNET_SCHEDULER_add_now (schedule_transmit_message, chn);
+ GNUNET_SCHEDULER_add_now (&schedule_transmit_message, chn);
}
else if (GNUNET_YES == chn->is_disconnected
&& tmit_msg->last_ptype < GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END)
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, server_handlers);
GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
/**
* Return value from 'main'.
*/
-int res;
+static int res;
-const struct GNUNET_CONFIGURATION_Handle *cfg;
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
-struct GNUNET_CORE_Handle *core;
-struct GNUNET_PeerIdentity this_peer;
+static struct GNUNET_CORE_Handle *core;
+static struct GNUNET_PeerIdentity this_peer;
/**
* Handle for task for timeout termination.
*/
-struct GNUNET_SCHEDULER_Task * end_badly_task;
+static struct GNUNET_SCHEDULER_Task * end_badly_task;
-struct GNUNET_PSYC_Master *mst;
-struct GNUNET_PSYC_Slave *slv;
+static struct GNUNET_PSYC_Master *mst;
+static struct GNUNET_PSYC_Slave *slv;
-struct GNUNET_PSYC_Channel *mst_chn, *slv_chn;
+static struct GNUNET_PSYC_Channel *mst_chn, *slv_chn;
-struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
-struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
+static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
+static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
-struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
-struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
+static struct GNUNET_CRYPTO_EddsaPublicKey channel_pub_key;
+static struct GNUNET_CRYPTO_EcdsaPublicKey slave_pub_key;
struct TransmitClosure
{
uint8_t n;
};
-struct TransmitClosure *tmit;
+static struct TransmitClosure *tmit;
-uint8_t join_req_count, end_count;
+static uint8_t join_req_count, end_count;
enum
{
} test;
-void
+static void
master_transmit ();
-void
+static void
master_history_replay_latest ();
-void master_stopped (void *cls)
+static void
+master_stopped (void *cls)
{
if (NULL != tmit)
{
GNUNET_SCHEDULER_shutdown ();
}
-void slave_parted (void *cls)
+
+static void
+slave_parted (void *cls)
{
if (NULL != mst)
{
master_stopped (NULL);
}
+
/**
* Clean up all resources used.
*/
-void
+static void
cleanup ()
{
if (NULL != core)
/**
* Finish the test case (successfully).
*/
-void
+static void
end ()
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
}
-void
+static void
master_message_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg)
{
GNUNET_assert (NULL != msg);
}
-void
+static void
master_message_part_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg,
const struct GNUNET_MessageHeader *pmsg)
{
}
-void
+static void
slave_message_cb (void *cls, const struct GNUNET_PSYC_MessageHeader *msg)
{
GNUNET_assert (NULL != msg);
}
-void
+static void
slave_message_part_cb (void *cls,
const struct GNUNET_PSYC_MessageHeader *msg,
const struct GNUNET_MessageHeader *pmsg)
}
-void
+static void
state_get_var (void *cls, const struct GNUNET_MessageHeader *mod,
const char *name, const void *value,
uint32_t value_size, uint32_t full_value_size)
/*** Slave state_get_prefix() ***/
-void
+static void
slave_state_get_prefix_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
slave_state_get_prefix ()
{
test = TEST_SLAVE_STATE_GET_PREFIX;
/*** Master state_get_prefix() ***/
-void
+static void
master_state_get_prefix_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
master_state_get_prefix ()
{
test = TEST_MASTER_STATE_GET_PREFIX;
/*** Slave state_get() ***/
-void
+static void
slave_state_get_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
slave_state_get ()
{
test = TEST_SLAVE_STATE_GET;
/*** Master state_get() ***/
-void
+static void
master_state_get_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
master_state_get ()
{
test = TEST_MASTER_STATE_GET;
/*** Slave history_replay() ***/
-void
+static void
slave_history_replay_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
slave_history_replay ()
{
test = TEST_SLAVE_HISTORY_REPLAY;
/*** Master history_replay() ***/
-void
+static void
master_history_replay_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
master_history_replay ()
{
test = TEST_MASTER_HISTORY_REPLAY;
/*** Slave history_replay_latest() ***/
-void
+static void
slave_history_replay_latest_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
slave_history_replay_latest ()
{
test = TEST_SLAVE_HISTORY_REPLAY_LATEST;
/*** Master history_replay_latest() ***/
-void
+static void
master_history_replay_latest_result (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
master_history_replay_latest ()
{
test = TEST_MASTER_HISTORY_REPLAY_LATEST;
}
-int
+static int
tmit_notify_data (void *cls, uint16_t *data_size, void *data)
{
struct TransmitClosure *tmit = cls;
}
-int
+static int
tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper,
uint32_t *full_value_size)
{
slave_join ();
-void
+static void
slave_transmit ()
{
test = TEST_SLAVE_TRANSMIT;
}
-void
+static void
slave_remove_cb (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
slave_remove ()
{
test = TEST_SLAVE_REMOVE;
}
-void
+static void
slave_add_cb (void *cls, int64_t result,
const void *err_msg, uint16_t err_msg_size)
{
}
-void
+static void
slave_add ()
{
test = TEST_SLAVE_ADD;
}
-void first_slave_parted (void *cls)
+static void
+first_slave_parted (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First slave parted.\n");
slave_join (TEST_SLAVE_JOIN_ACCEPT);
static void
schedule_slave_part (void *cls)
{
- GNUNET_PSYC_slave_part (slv, GNUNET_NO, first_slave_parted, NULL);
+ GNUNET_PSYC_slave_part (slv, GNUNET_NO, &first_slave_parted, NULL);
}
case TEST_SLAVE_JOIN_REJECT:
GNUNET_assert (0 == is_admitted);
GNUNET_assert (1 == join_req_count);
- GNUNET_SCHEDULER_add_now (schedule_slave_part, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_slave_part, NULL);
break;
case TEST_SLAVE_JOIN_ACCEPT:
}
-void
+static void
master_transmit ()
{
test = TEST_MASTER_TRANSMIT;
}
-void
+static void
master_start_cb (void *cls, int result, uint64_t max_message_id)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
}
-void
+static void
master_start ()
{
test = TEST_MASTER_START;
}
-void
+static void
core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
{
this_peer = *my_identity;
* @param cfg configuration we use (also to connect to PSYC service)
* @param peer handle to access more of the peer (not used)
*/
-void
+static void
#if DEBUG_TEST_PSYC
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
GNUNET_CONFIGURATION_get_value_string (cfg, "psycstore", "database",
&database))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No database backend configured\n");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "psycstore",
+ "database");
}
else
{
- GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_psycstore_%s", database);
+ GNUNET_asprintf (&db_lib_name,
+ "libgnunet_plugin_psycstore_%s",
+ database);
db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
GNUNET_free (database);
}
stats = GNUNET_STATISTICS_create ("psycstore", cfg);
GNUNET_SERVER_add_handlers (server, handlers);
nc = GNUNET_SERVER_notification_context_create (server, 1);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
/**
* Task doing exponential back-off trying to reconnect.
*/
- struct GNUNET_SCHEDULER_Task * reconnect_task;
+ struct GNUNET_SCHEDULER_Task *reconnect_task;
/**
* Time for next connect retry.
/**
* Handle for task for timeout termination.
*/
-static struct GNUNET_SCHEDULER_Task * end_badly_task;
+static struct GNUNET_SCHEDULER_Task *end_badly_task;
static struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key;
static struct GNUNET_CRYPTO_EcdsaPrivateKey *slave_key;
static void
end ()
{
- if (end_badly_task != NULL)
+ if (NULL != end_badly_task)
{
GNUNET_SCHEDULER_cancel (end_badly_task);
end_badly_task = NULL;
/**
* Task used to abort this operation with timeout.
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Length of the request message that follows this struct.
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup, cls);
if (ipv4_pt || ipv6_pt)
{
dns_post_handle
static void
-run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
struct in_addr v4;
REGEX_INTERNAL_announce_cancel (announce_handle);
announce_handle = NULL;
}
-
+ if (NULL != reannounce_task)
+ {
+ GNUNET_free (GNUNET_SCHEDULER_cancel (reannounce_task));
+ reannounce_task = NULL;
+ }
if (NULL != dht_handle)
{
GNUNET_DHT_disconnect (dht_handle);
{
char *regex = cls;
struct GNUNET_TIME_Relative random_delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
reannounce_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- GNUNET_free (regex);
- return;
- }
-
if (0 == rounds--)
{
global_ret = 0;
* @param regex regular expression to announce on this peer's cadet.
*/
static void
-announce_regex (const char * regex)
+announce_regex (const char *regex)
{
char *copy;
policy_filename);
GNUNET_assert (NULL == reannounce_task);
copy = GNUNET_strdup (regex);
- reannounce_task = GNUNET_SCHEDULER_add_now (reannounce_regex, (void *) copy);
+ reannounce_task = GNUNET_SCHEDULER_add_now (&reannounce_regex,
+ (void *) copy);
}
REGEX_TEST_free_from_file (components);
/* Announcing regexes from policy_filename */
- GNUNET_asprintf (&rx_with_pfx, "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*", regex_prefix, regex);
+ GNUNET_asprintf (&rx_with_pfx,
+ "%s(%s)(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)*",
+ regex_prefix,
+ regex);
announce_regex (rx_with_pfx);
GNUNET_free (regex);
GNUNET_free (rx_with_pfx);
/* Scheduled the task to clean up when shutdown is called */
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
*/
static struct GNUNET_SCHEDULER_Task * abort_task;
-/**
- * Shutdown task identifier
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
-
/**
* Host registration task identifier
*/
char output_buffer[512];
size_t size;
- shutdown_task = NULL;
if (NULL != abort_task)
+ {
GNUNET_SCHEDULER_cancel (abort_task);
+ abort_task = NULL;
+ }
if (NULL != register_hosts_task)
+ {
GNUNET_SCHEDULER_cancel (register_hosts_task);
-
+ register_hosts_task = NULL;
+ }
for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
{
peer = &peers[peer_cnt];
}
if (NULL != data_file)
+ {
GNUNET_DISK_file_close (data_file);
-
+ data_file = NULL;
+ }
for (search_str_cnt = 0;
search_str_cnt < num_peers && NULL != search_strings;
search_str_cnt++)
GNUNET_free_non_null (search_strings[search_str_cnt]);
}
GNUNET_free_non_null (search_strings);
+ search_strings = NULL;
if (NULL != reg_handle)
+ {
GNUNET_TESTBED_cancel_registration (reg_handle);
-
+ reg_handle = NULL;
+ }
if (NULL != mc)
+ {
GNUNET_TESTBED_controller_disconnect (mc);
+ mc = NULL;
+ }
if (NULL != mc_proc)
+ {
GNUNET_TESTBED_controller_stop (mc_proc);
+ mc_proc = NULL;
+ }
if (NULL != cfg)
+ {
GNUNET_CONFIGURATION_destroy (cfg);
-
- GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
+ cfg = NULL;
+ }
}
{
unsigned long i = (unsigned long) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting from line %lu...\n", i);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Aborting from line %lu...\n", i);
abort_task = NULL;
result = GNUNET_SYSERR;
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
* @return service handle to return in 'op_result', NULL on error
*/
static void *
-stats_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
+stats_ca (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
return GNUNET_STATISTICS_create ("<driver>", cfg);
}
* @param name the name of the datum
* @param value the current value
* @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
static int
-stats_iterator (void *cls, const char *subsystem, const char *name,
+stats_iterator (void *cls,
+ const char *subsystem,
+ const char *name,
uint64_t value, int is_persistent)
{
struct RegexPeer *peer = cls;
fprintf (stderr, "s");
if (peer_cnt == num_peers)
{
- struct GNUNET_TIME_Relative delay = { 100 };
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\nCollecting stats finished. Shutting down.\n");
- shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "\nCollecting stats finished. Shutting down.\n");
+ GNUNET_SCHEDULER_shutdown ();
result = GNUNET_OK;
}
else
find_timed_out (void *cls)
{
struct RegexPeer *p = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
p->timeout = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Searching for string \"%s\" on peer %d timed out.\n",
p->search_str,
find_string (void *cls)
{
unsigned int search_peer = (unsigned int) (long) cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) ||
- search_peer >= num_peers ||
- GNUNET_YES == in_shutdown)
+ if ( (search_peer >= num_peers) ||
+ (GNUNET_YES == in_shutdown) )
return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
&dht_da,
&peers[search_peer]);
GNUNET_assert (NULL != peers[search_peer].op_handle);
- peers[search_peer].timeout = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
- &find_timed_out,
- &peers[search_peer]);
+ peers[search_peer].timeout
+ = GNUNET_SCHEDULER_add_delayed (FIND_TIMEOUT,
+ &find_timed_out,
+ &peers[search_peer]);
}
-
-
/**
* Callback called when testbed has started the daemon we asked for.
*
* @param emsg NULL on success; otherwise an error description
*/
static void
-daemon_started (void *cls, struct GNUNET_TESTBED_Operation *op,
+daemon_started (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
const char *emsg)
{
struct RegexPeer *peer = (struct RegexPeer *) cls;
{
unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Starting announce.\n");
-
+ if (GNUNET_YES == in_shutdown)
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting announce.\n");
for (i = 0; i < init_parallel_searches; i++)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
announce_next_regex (void *cls)
{
struct RegexPeer *peer;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ if (GNUNET_YES == in_shutdown)
return;
if (next_search >= num_peers)
{
parallel_searches++;
}
+
/**
* DHT connect callback. Called when we are connected to the dht service for
* the peer in 'cls'. If successfull we connect to the stats service of this
* @param emsg error message.
*/
static void
-dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
- void *ca_result, const char *emsg)
+dht_connect_cb (void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
{
struct RegexPeer *peer = (struct RegexPeer *) cls;
* @param strings set of strings loaded from file. Caller needs to free this
* if number returned is greater than zero.
* @param limit upper limit on the number of strings read from the file
- * @return number of strings found in the file. GNUNET_SYSERR on error.
+ * @return number of strings found in the file. #GNUNET_SYSERR on error.
*/
static int
-load_search_strings (const char *filename, char ***strings, unsigned int limit)
+load_search_strings (const char *filename,
+ char ***strings,
+ unsigned int limit)
{
char *data;
char *buf;
* @param config 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 *config)
{
unsigned int nsearchstrs;
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("No configuration file given. Exiting\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
cfg = GNUNET_CONFIGURATION_dup (config);
"REGEX_PREFIX",
®ex_prefix))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Configuration option \"regex_prefix\" missing. Exiting\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "regexprofiler",
+ "regex_prefix");
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if (GNUNET_OK !=
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Specified policies directory does not exist. Exiting.\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if (0 >= (int) (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("No search strings file given. Exiting.\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
nsearchstrs = load_search_strings (strings_file,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"File (%s) does not contain enough strings (%u/%u).\n",
strings_file, nsearchstrs, num_peers);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if ( (0 == num_peers) || (NULL == search_strings))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Error loading search strings. Exiting.\n"));
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
for (i = 0; i < num_peers; i++)
*/
static struct ProgressMeter *meter;
-/**
- * Abort task identifier.
- */
-static struct GNUNET_SCHEDULER_Task * abort_task;
-
-/**
- * Shutdown task identifier.
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
-
/**
* Scan task identifier;
*/
-static struct GNUNET_SCHEDULER_Task * scan_task;
+static struct GNUNET_SCHEDULER_Task *scan_task;
/**
* Global testing status.
*
* @param meter the meter to reset
*
- * @return GNUNET_YES if meter reset,
- * GNUNET_SYSERR on error
+ * @return #GNUNET_YES if meter reset,
+ * #GNUNET_SYSERR on error
*/
static int
reset_meter (struct ProgressMeter *meter)
*/
static void
do_shutdown (void *cls)
-{
- shutdown_task = NULL;
- if (NULL != abort_task)
- GNUNET_SCHEDULER_cancel (abort_task);
+{
if (NULL != mysql_ctx)
+ {
GNUNET_MYSQL_context_destroy (mysql_ctx);
+ mysql_ctx = NULL;
+ }
if (NULL != meter)
+ {
free_meter (meter);
-
- GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
+ meter = NULL;
+ }
}
/**
- * abort task to run on test timed out
+ * Abort task to run on test timed out.
+ *
+ * FIXME: this doesn't actually work, it used to cancel
+ * the already running 'scan_task', but now that should
+ * always be NULL and do nothing. We instead need to set
+ * a global variable and abort scan_task internally, not
+ * via scheduler.
*
* @param cls NULL
*/
do_abort (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
- abort_task = NULL;
- GNUNET_SCHEDULER_cancel (scan_task);
- scan_task = NULL;
+ if (NULL != scan_task)
+ {
+ GNUNET_SCHEDULER_cancel (scan_task);
+ scan_task = NULL;
+ }
result = GNUNET_SYSERR;
- GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
/**
- * Dummy function for prepared select. Always return GNUNET_OK.
+ * Dummy function for prepared select. Always returns #GNUNET_OK.
*
* @param cls closure
* @param num_values number of values.
* @param values returned values from select stmt.
*
- * @return GNUNET_OK
+ * @return #GNUNET_OK
*/
static int
-return_ok (void *cls, unsigned int num_values, MYSQL_BIND * values)
+return_ok (void *cls,
+ unsigned int num_values,
+ MYSQL_BIND * values)
{
return GNUNET_OK;
}
* @param cls closure.
* @param key hash for current state.
* @param proof proof for current state.
- * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
+ * @param accepting #GNUNET_YES if this is an accepting state, #GNUNET_NO if not.
* @param num_edges number of edges leaving current state.
* @param edges edges leaving current state.
*/
static void
-regex_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof,
- int accepting, unsigned int num_edges,
+regex_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ const char *proof,
+ int accepting,
+ unsigned int num_edges,
const struct REGEX_BLOCK_Edge *edges)
{
unsigned int i;
* each state into a MySQL database.
*
* @param regex regular expression.
- * @return GNUNET_OK on success, GNUNET_SYSERR on failure.
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure.
*/
static int
announce_regex (const char *regex)
struct REGEX_INTERNAL_Automaton *dfa;
dfa =
- REGEX_INTERNAL_construct_dfa (regex, strlen (regex), max_path_compression);
+ REGEX_INTERNAL_construct_dfa (regex,
+ strlen (regex),
+ max_path_compression);
if (NULL == dfa)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create DFA for regex %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create DFA for regex %s\n",
regex);
- abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
+ GNUNET_SCHEDULER_add_now (&do_abort, NULL);
return GNUNET_SYSERR;
}
-
- REGEX_INTERNAL_iterate_all_edges (dfa, ®ex_iterator, NULL);
-
+ REGEX_INTERNAL_iterate_all_edges (dfa,
+ ®ex_iterator, NULL);
REGEX_INTERNAL_automaton_destroy (dfa);
return GNUNET_OK;
*
* @param cls closure
* @param filename complete filename (absolute path)
- * @return GNUNET_OK to continue to iterate,
- * GNUNET_SYSERR to abort iteration with error!
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_SYSERR to abort iteration with error!
*/
static int
policy_filename_cb (void *cls, const char *filename)
GNUNET_assert (NULL != filename);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Announcing regexes from file %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Announcing regexes from file %s\n",
filename);
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not find policy file %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not find policy file %s\n",
filename);
return GNUNET_OK;
}
if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename, &filesize, GNUNET_YES, GNUNET_YES))
+ GNUNET_DISK_file_size (filename, &filesize,
+ GNUNET_YES, GNUNET_YES))
filesize = 0;
if (0 == filesize)
{
if (filesize != GNUNET_DISK_fn_read (filename, data, filesize))
{
GNUNET_free (data);
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Could not read policy file %s.\n",
filename);
return GNUNET_OK;
}
data[offset] = '\0';
GNUNET_asprintf (®ex, "%s(%s)", regex_prefix, data);
GNUNET_assert (NULL != regex);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Announcing regex: %s\n", regex);
if (GNUNET_OK != announce_regex (regex))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not announce regex %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not announce regex %s\n",
regex);
}
GNUNET_free (regex);
char *stmt;
/* Create an MySQL prepared statement for the inserts */
+ scan_task = NULL;
GNUNET_asprintf (&stmt, INSERT_EDGE_STMT, table_name);
stmt_handle = GNUNET_MYSQL_statement_prepare (mysql_ctx, stmt);
GNUNET_free (stmt);
GNUNET_assert (NULL != stmt_handle);
- meter =
- create_meter (num_policy_files, "Announcing policy files\n", GNUNET_YES);
+ meter = create_meter (num_policy_files,
+ "Announcing policy files\n",
+ GNUNET_YES);
start_time = GNUNET_TIME_absolute_get ();
- GNUNET_DISK_directory_scan (policy_dir, &policy_filename_cb, stmt_handle);
+ GNUNET_DISK_directory_scan (policy_dir,
+ &policy_filename_cb,
+ stmt_handle);
duration = GNUNET_TIME_absolute_get_duration (start_time);
reset_meter (meter);
free_meter (meter);
printf ("Announced %u files containing %u policies in %s\n"
"Duplicate transitions: %llu\nMerged states: %llu\n",
- num_policy_files, num_policies,
+ num_policy_files,
+ num_policies,
GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO),
- num_merged_transitions, num_merged_states);
-
+ num_merged_transitions,
+ num_merged_states);
result = GNUNET_OK;
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
* @param config 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 *config)
{
if (NULL == args[0])
result = GNUNET_SYSERR;
return;
}
- if (GNUNET_YES != GNUNET_DISK_directory_test (args[0], GNUNET_YES))
+ if (GNUNET_YES !=
+ GNUNET_DISK_directory_test (args[0], GNUNET_YES))
{
fprintf (stderr,
_("Specified policies directory does not exist. Exiting.\n"));
}
policy_dir = args[0];
- num_policy_files = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL);
+ num_policy_files = GNUNET_DISK_directory_scan (policy_dir,
+ NULL, NULL);
meter = NULL;
if (NULL == table_name)
mysql_ctx = GNUNET_MYSQL_context_create (config, "regex-mysql");
if (NULL == mysql_ctx)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create mysql context\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to create mysql context\n");
result = GNUNET_SYSERR;
return;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (config, "regex-mysql",
- "REGEX_PREFIX", ®ex_prefix))
+ GNUNET_CONFIGURATION_get_value_string (config,
+ "regex-mysql",
+ "REGEX_PREFIX",
+ ®ex_prefix))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("%s service is lacking key configuration settings (%s). Exiting.\n"),
- "regexprofiler", "regex_prefix");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "regex-mysql",
+ "REGEX_PREFIX");
result = GNUNET_SYSERR;
return;
}
-
result = GNUNET_OK;
-
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
scan_task = GNUNET_SCHEDULER_add_now (&do_directory_scan, NULL);
-
- /* Scheduled the task to clean up when shutdown is called */
- shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
- NULL);
}
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
nc = GNUNET_SERVER_notification_context_create (server, 1);
stats = GNUNET_STATISTICS_create ("regex", cfg);
GNUNET_SERVER_add_handlers (server, handlers);
/**
* The task ID
*/
-static struct GNUNET_SCHEDULER_Task * httpd_task;
+static struct GNUNET_SCHEDULER_Task *httpd_task;
/**
* The port the service is running on (default 7776)
GNUNET_SCHEDULER_cancel (httpd_task);
httpd_task = NULL;
}
+ if (NULL != ltask4)
+ {
+ GNUNET_SCHEDULER_cancel (ltask4);
+ ltask4 = NULL;
+ }
+ if (NULL != ltask6)
+ {
+ GNUNET_SCHEDULER_cancel (ltask6);
+ ltask6 = NULL;
+ }
}
do_accept (void *cls)
{
struct GNUNET_NETWORK_Handle *lsock = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_NETWORK_Handle *s;
int fd;
const struct sockaddr *addr;
ltask4 = NULL;
else
ltask6 = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (lsock == lsock4)
ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
lsock,
(void *) cfg,
&load_plugin,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
*/
static unsigned long long matching_bits;
+/**
+ * Task used for proof-of-work calculation.
+ */
+static struct GNUNET_SCHEDULER_Task *pow_task;
+
/**
* Function run if the user aborts with CTRL-C.
}
+/**
+ * Write the current state of the revocation data
+ * to disk.
+ *
+ * @param rd data to sync
+ */
+static void
+sync_rd (const struct RevocationData *rd)
+{
+ if ( (NULL != filename) &&
+ (sizeof (struct RevocationData) ==
+ GNUNET_DISK_fn_write (filename,
+ &rd,
+ sizeof (rd),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE)) )
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "write",
+ filename);
+}
+
+
/**
* Perform the proof-of-work calculation.
*
* @param cls the `struct RevocationData`
*/
static void
-calculate_pow (void *cls)
+calculate_pow_shutdown (void *cls)
{
struct RevocationData *rd = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- /* store temporary results */
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ( (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) ||
- (0 == (rd->pow % 128) ) )
+ if (NULL != pow_task)
{
- if ( (NULL != filename) &&
- (sizeof (struct RevocationData) ==
- GNUNET_DISK_fn_write (filename,
- &rd,
- sizeof (rd),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE)) )
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "write",
- filename);
+ GNUNET_SCHEDULER_cancel (pow_task);
+ pow_task = NULL;
}
+ sync_rd (rd);
+ GNUNET_free (rd);
+}
+
+
+/**
+ * Perform the proof-of-work calculation.
+ *
+ * @param cls the `struct RevocationData`
+ */
+static void
+calculate_pow (void *cls)
+{
+ struct RevocationData *rd = cls;
+
+ /* store temporary results */
+ if (0 == (rd->pow % 128))
+ sync_rd (rd);
/* display progress estimate */
if ( (0 == ((1 << matching_bits) / 100 / 50)) ||
(0 == (rd->pow % ((1 << matching_bits) / 100 / 50))) )
(0 == (rd->pow % ((1 << matching_bits) / 100))) ) )
FPRINTF (stderr, " - @ %3u%% (estimate)\n",
(unsigned int) (rd->pow * 100) / (1 << matching_bits));
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (rd);
- return;
- }
/* actually do POW calculation */
rd->pow++;
if (GNUNET_OK ==
GNUNET_free (rd);
return;
}
- GNUNET_SCHEDULER_add_now (&calculate_pow,
- rd);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
+ rd);
}
FPRINTF (stderr,
"%s",
_("Revocation certificate not ready, calculating proof of work\n"));
- GNUNET_SCHEDULER_add_now (&calculate_pow,
- rd);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
+ rd);
+ GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
+ rd);
}
test_ego);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
q = GNUNET_REVOCATION_query (cfg,
&pk,
&print_query_result,
revoke_ego,
&ego_callback,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
return;
}
if ( (NULL != filename) &&
filename);
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
if (GNUNET_YES !=
GNUNET_REVOCATION_check_pow (&rd.key,
rd.pow,
struct RevocationData *cp = GNUNET_new (struct RevocationData);
*cp = rd;
- GNUNET_SCHEDULER_add_now (&calculate_pow,
- cp);
+ pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow,
+ cp);
+ GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown,
+ cp);
return;
-
}
perform_revocation (&rd);
return;
}
GNUNET_free (fn);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
peers = GNUNET_CONTAINER_multipeermap_create (128,
GNUNET_YES);
GNUNET_SERVER_add_handlers (srv, handlers);
static struct GNUNET_PeerIdentity *peer_id;
-/**
- * Shutdown task
- */
-static struct GNUNET_SCHEDULER_Task *shutdown_task;
-
-
/**
* Set an option of type 'struct GNUNET_PeerIdentity *' from the command line.
* A pointer to this function should be passed as part of the
static void
do_shutdown (void *cls)
{
- shutdown_task = NULL;
if (NULL != req_handle)
GNUNET_RPS_request_cancel (req_handle);
GNUNET_RPS_disconnect (rps_handle);
}
ret = 0;
- GNUNET_SCHEDULER_cancel (shutdown_task);
- GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting %u PeerIDs\n", num_peers);
req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
else
{ /* Seed PeerID */
GNUNET_RPS_seed_ids (rps_handle, 1, peer_id);
FPRINTF (stdout, "Seeded PeerID %s\n", GNUNET_i2s_full (peer_id));
ret = 0;
- GNUNET_SCHEDULER_add_now (do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
}
/*
This file is part of GNUnet.
- Copyright (C)
+ Copyright (C) 2013-2015 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
static struct RPS_Sampler *client_sampler;
-
/**
* Name to log view to
*/
static char *file_name_view_log;
-
/**
- * The size of sampler we need to be able to satisfy the client's need of
- * random peers.
+ * The size of sampler we need to be able to satisfy the client's need
+ * of random peers.
*/
static unsigned int sampler_size_client_need;
*/
static unsigned int sampler_size_est_need;
-
/**
* Percentage of total peer number in the view
* to send random PUSHes to
*/
static float beta;
-/**
- * The percentage gamma of history updates.
- * Simply 1 - alpha - beta
- */
-
-
/**
* Identifier for the main task that runs periodically.
*/
*/
static struct GNUNET_TIME_Relative round_interval;
-
-
/**
* List to store peers received through pushes temporary.
*/
*/
static struct CustomPeerMap *pull_map;
-
/**
* Handler to NSE.
*/
/**
* Handle for cancellation of iteration over peers.
*/
-struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
-
+static struct GNUNET_PEERINFO_NotifyContext *peerinfo_notify_handle;
/**
* Request counter.
/**
* The prediction of the rate of requests
*/
-static struct GNUNET_TIME_Relative request_rate;
-
+static struct GNUNET_TIME_Relative request_rate;
/**
* Number of history update tasks.
*/
-uint32_t num_hist_update_tasks;
+static uint32_t num_hist_update_tasks;
#ifdef ENABLE_MALICIOUS
* 2 Try to partition the network
* 3 Combined attack
*/
-uint32_t mal_type = 0;
+static uint32_t mal_type;
/**
* Other malicious peers
*/
-static struct GNUNET_PeerIdentity *mal_peers = NULL;
+static struct GNUNET_PeerIdentity *mal_peers;
/**
* Hashmap of malicious peers used as set.
* Used to more efficiently check whether we know that peer.
*/
-static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set = NULL;
+static struct GNUNET_CONTAINER_MultiPeerMap *mal_peer_set;
/**
* Number of other malicious peers
/**
* If type is 2 this is the DLL of attacked peers
*/
-static struct AttackedPeer *att_peers_head = NULL;
-static struct AttackedPeer *att_peers_tail = NULL;
+static struct AttackedPeer *att_peers_head;
+static struct AttackedPeer *att_peers_tail;
/**
* This index is used to point to an attacked peer to
* implement the round-robin-ish way to select attacked peers.
*/
-static struct AttackedPeer *att_peer_index = NULL;
+static struct AttackedPeer *att_peer_index;
/**
* Hashmap of attacked peers used as set.
* Used to more efficiently check whether we know that peer.
*/
-static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set = NULL;
+static struct GNUNET_CONTAINER_MultiPeerMap *att_peer_set;
/**
* Number of attacked peers
*/
-static uint32_t num_attacked_peers = 0;
-
+static uint32_t num_attacked_peers;
/**
* If type is 1 this is the attacked peer
***********************************************************************/
-
-
-
-
/***********************************************************************
* Util functions
***********************************************************************/
/**
* Print peerlist to log.
*/
-void
-print_peer_list (struct GNUNET_PeerIdentity *list, unsigned int len)
+static void
+print_peer_list (struct GNUNET_PeerIdentity *list,
+ unsigned int len)
{
unsigned int i;
/**
* Remove peer from list.
*/
- void
+static void
rem_from_list (struct GNUNET_PeerIdentity **peer_list,
unsigned int *list_size,
const struct GNUNET_PeerIdentity *peer)
/**
* Sum all time relatives of an array.
- */
- struct GNUNET_TIME_Relative
-T_relative_sum (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
+ */
+static struct GNUNET_TIME_Relative
+T_relative_sum (const struct GNUNET_TIME_Relative *rel_array,
+ uint32_t arr_size)
{
struct GNUNET_TIME_Relative sum;
uint32_t i;
/**
* Compute the average of given time relatives.
*/
- struct GNUNET_TIME_Relative
-T_relative_avg (const struct GNUNET_TIME_Relative *rel_array, uint32_t arr_size)
+static struct GNUNET_TIME_Relative
+T_relative_avg (const struct GNUNET_TIME_Relative *rel_array,
+ uint32_t arr_size)
{
- return GNUNET_TIME_relative_divide (T_relative_sum (rel_array, arr_size), arr_size);
+ return GNUNET_TIME_relative_divide (T_relative_sum (rel_array,
+ arr_size),
+ arr_size);
}
/**
* Put random peer from sampler into the view as history update.
*/
- void
-hist_update (void *cls, struct GNUNET_PeerIdentity *ids, uint32_t num_peers)
+static void
+hist_update (void *cls,
+ struct GNUNET_PeerIdentity *ids,
+ uint32_t num_peers)
{
unsigned int i;
}
-
/**
* Wrapper around #RPS_sampler_resize()
*
*
* Called every time we receive a request from the client.
*/
- void
+static void
est_request_rate()
{
struct GNUNET_TIME_Relative max_round_duration;
*
* Called once we know a peer is live.
*/
- void
-insert_in_pull_map (void *cls, const struct GNUNET_PeerIdentity *peer)
+static void
+insert_in_pull_map (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
CustomPeerMap_put (pull_map, peer);
}
+
/**
* Insert PeerID in #view
*
* Called once we know a peer is live.
*/
- void
-insert_in_view (void *cls, const struct GNUNET_PeerIdentity *peer)
+static void
+insert_in_view (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
View_put (peer);
}
+
/**
* Update sampler with given PeerID.
*/
- void
-insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
+static void
+insert_in_sampler (void *cls,
+ const struct GNUNET_PeerIdentity *peer)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Updating samplers with peer %s from insert_in_sampler()\n",
GNUNET_free (rep_cls);
}
+
static void
destroy_cli_ctx (struct ClientContext *cli_ctx)
{
* Updates sizes of sampler list and view and adapt those lists
* accordingly.
*/
- void
-nse_callback (void *cls, struct GNUNET_TIME_Absolute timestamp,
+static void
+nse_callback (void *cls,
+ struct GNUNET_TIME_Absolute timestamp,
double logestimate, double std_dev)
{
double estimate;
*
* Sends those to the requesting client.
*/
-void
+static void
client_respond (void *cls,
struct GNUNET_PeerIdentity *peer_ids,
uint32_t num_peers)
* @param client identification of the client
* @param message the actual message
*/
- static void
+static void
handle_client_seed (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
////GNUNET_free (peers);
GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_OK);
}
*/
static int
handle_peer_push (void *cls,
- struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *msg)
+ struct GNUNET_CADET_Channel *channel,
+ void **channel_ctx,
+ const struct GNUNET_MessageHeader *msg)
{
const struct GNUNET_PeerIdentity *peer;
GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER);
// FIXME wait for cadet to change this function
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PUSH (%s)\n", GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received PUSH (%s)\n",
+ GNUNET_i2s (peer));
- #ifdef ENABLE_MALICIOUS
+#ifdef ENABLE_MALICIOUS
struct AttackedPeer *tmp_att_peer;
tmp_att_peer = GNUNET_new (struct AttackedPeer);
*/
static int
handle_peer_pull_request (void *cls,
- struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *msg)
+ struct GNUNET_CADET_Channel *channel,
+ void **channel_ctx,
+ const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_PeerIdentity *peer;
const struct GNUNET_PeerIdentity *view_array;
* @param channel_ctx The context associated with this channel
* @param msg The message header
*/
- static int
+static int
handle_peer_pull_reply (void *cls,
struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
* @param spread the inverse amount of deviation from the mean
*/
static struct GNUNET_TIME_Relative
-compute_rand_delay (struct GNUNET_TIME_Relative mean, unsigned int spread)
+compute_rand_delay (struct GNUNET_TIME_Relative mean,
+ unsigned int spread)
{
struct GNUNET_TIME_Relative half_interval;
struct GNUNET_TIME_Relative ret;
* @param client The client that sent the message
* @param msg The message header
*/
- static void
+static void
handle_client_act_malicious (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
GNUNET_break (0);
}
-
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
}
struct GNUNET_TIME_Relative time_next_round;
struct AttackedPeer *tmp_att_peer;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously type %" PRIu32 ".\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Going to execute next round maliciously type %" PRIu32 ".\n",
mal_type);
do_round_task = NULL;
GNUNET_assert (mal_type <= 3);
//do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round,
//NULL);
GNUNET_assert (NULL == do_round_task);
- do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_mal_round, NULL);
+ do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
+ &do_mal_round, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
}
#endif /* ENABLE_MALICIOUS */
static void
do_round (void *cls)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round.\n");
-
uint32_t i;
const struct GNUNET_PeerIdentity *view_array;
unsigned int *permut;
struct GNUNET_PeerIdentity peer;
struct GNUNET_PeerIdentity *update_peer;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Going to execute next round.\n");
do_round_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Printing view:\n");
time_next_round = compute_rand_delay (round_interval, 2);
/* Schedule next round */
- do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_round, NULL);
+ do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round,
+ &do_round, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
}
static void
shutdown_task (void *cls)
{
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
-
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "RPS is going down\n");
GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle);
GNUNET_PEERINFO_disconnect (peerinfo_handle);
do_round_task = GNUNET_SCHEDULER_add_now (&do_round, NULL);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduled first round\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
struct GetPeerCls *gpc = cls;
uint32_t r_index;
struct RPS_Sampler *sampler;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
gpc->get_peer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
sampler = gpc->req_handle->sampler;
/**;
struct RPS_SamplerElement *s_elem;
struct GNUNET_TIME_Relative last_request_diff;
struct RPS_Sampler *sampler;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
gpc->get_peer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
sampler = gpc->req_handle->sampler;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Single peer was requested\n");
if (EMPTY == s_elem->is_empty)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sampler_mod element empty, rescheduling.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sampler_mod element empty, rescheduling.\n");
GNUNET_assert (NULL == gpc->get_peer_task);
gpc->get_peer_task =
GNUNET_SCHEDULER_add_delayed (sampler->max_round_interval,
req_handle->gpc_tail,
gpc);
// maybe add a little delay
- gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers, gpc);
+ gpc->get_peer_task = GNUNET_SCHEDULER_add_now (sampler->get_peers,
+ gpc);
}
return req_handle;
}
/**
* How many peers do we start?
*/
-uint32_t num_peers;
+static uint32_t num_peers;
/**
* How long do we run the test?
*/
static int ok;
-
/**
* Identifier for the churn task that runs periodically
*/
static struct GNUNET_SCHEDULER_Task *churn_task;
-/**
- * Identifier for the churn task that runs periodically
- */
-static struct GNUNET_SCHEDULER_Task *shutdown_task;
-
-
/**
* Called to initialise the given RPSPeer
*/
* Append arguments to file
*/
static void
-tofile_ (const char *file_name, char *line)
+tofile_ (const char *file_name, const char *line)
{
struct GNUNET_DISK_FileHandle *f;
/* char output_buffer[512]; */
if (0 == evaluate ())
{
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
if (NULL != churn_task)
GNUNET_SCHEDULER_cancel (churn_task);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
+ GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL);
}
return;
}
GNUNET_free (elements);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
ret = 0;
}
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "test master\n");
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &handle_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
peers = started_peers;
}
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
struct GNUNET_TIME_Absolute start;
struct GNUNET_TIME_Absolute deadline;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- handle_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "testing secretsharing api\n");
* Called to clean up, after a shutdown has been requested.
*
* @param cls closure
- * @param tc context information (why was this task triggered now)
*/
static void
shutdown_task (void *cls)
* - we suggested an operation to our listener,
* but did not receive a response in time
* - we got the channel from a peer but no #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
- * - shutdown (obviously)
*
* @param cls channel context
* @param tc context information (why was this task triggered now)
incoming_timeout_cb (void *cls)
{
struct Operation *incoming = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
incoming->timeout_task = NULL;
GNUNET_assert (GNUNET_YES == incoming->is_incoming);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Remote peer's incoming request timed out\n");
incoming_destroy (incoming);
static const uint32_t cadet_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0};
configuration = cfg;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
GNUNET_SERVER_disconnect_notify (server,
&handle_client_disconnect, NULL);
GNUNET_SERVER_add_handlers (server,
statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, handle_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
info1.id = "a";
info2.id = "b";
/**
* Task for reconnecting when the listener fails.
*/
- struct GNUNET_SCHEDULER_Task * reconnect_task;
+ struct GNUNET_SCHEDULER_Task *reconnect_task;
/**
* Operation we listen for.
struct GNUNET_SET_ListenHandle *lh = cls;
struct GNUNET_MQ_Envelope *mqm;
struct GNUNET_SET_ListenMessage *msg;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Listener not reconnecting due to shutdown\n");
- return;
- }
lh->reconnect_task = NULL;
GNUNET_assert (NULL == lh->client);
lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
static int ret;
+static struct GNUNET_SCHEDULER_Task *tt;
+
static void
result_cb_set1 (void *cls,
fprintf (stderr,
"set 1: received failure status!\n");
ret = 1;
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
break;
case GNUNET_SET_STATUS_DONE:
GNUNET_SET_destroy (set1);
set1 = NULL;
if (NULL == set2)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
+ }
break;
default:
GNUNET_assert (0);
GNUNET_SET_destroy (set2);
set2 = NULL;
if (NULL == set1)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
+ }
break;
default:
GNUNET_assert (0);
static void
timeout_fail (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
struct GNUNET_SET_OperationHandle *my_oh;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- &timeout_fail, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+ &timeout_fail, NULL);
config = cfg;
GNUNET_CRYPTO_get_peer_identity (cfg, &local_id);
static const struct GNUNET_CONFIGURATION_Handle *config;
+static struct GNUNET_SCHEDULER_Task *tt;
+
static void
add_element_str (struct GNUNET_SET_Handle *set, char *str)
static void
timeout_fail (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
}
-
-void
+static void
check_count (struct GNUNET_SET_Handle *set,
char *what,
unsigned int expected_count,
}
-void test_done (void *cls)
+static void
+test_done (void *cls)
{
if (NULL != set1)
GNUNET_SET_destroy (set1);
if (NULL != set2)
GNUNET_SET_destroy (set2);
-
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
}
-void check_new_set_count (void *cls)
+static void
+check_new_set_count (void *cls)
{
check_count (set2, "new set", 4, &test_done, NULL);
}
-void copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
+static void
+copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
{
printf ("copy done\n");
set2 = new_set;
}
-void test_copy (void *cls)
+static void
+test_copy (void *cls)
{
printf ("about to copy\n");
GNUNET_SET_copy_lazy (set1, copy_done, NULL);
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- &timeout_fail,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+ &timeout_fail,
+ NULL);
config = cfg;
GNUNET_TESTING_peer_get_identity (peer,
static void
timeout_fail (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
psyc_transmit_message (struct Place *plc);
+/**
+ * Clean up place data structures after a client disconnected.
+ *
+ * @param cls the `struct Place` to clean up
+ */
static void
-cleanup_place (struct Place *plc);
+cleanup_place (void *cls);
static struct MessageTransmitQueue *
const struct GNUNET_HashCode *key,
void *value)
{
- cleanup_place (value);
+ struct Place *plc = value;
+
+ cleanup_place (plc);
return GNUNET_YES;
}
/**
* Clean up place data structures after a client disconnected.
+ *
+ * @param cls the `struct Place` to clean up
*/
static void
-cleanup_place (struct Place *plc)
+cleanup_place (void *cls)
{
+ struct Place *plc = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%p Cleaning up place %s\n",
plc, GNUNET_h2s (&plc->pub_key_hash));
}
-static void
-schedule_cleanup_place (void *cls)
-{
- cleanup_place (cls);
-}
-
-
/**
* Called whenever a client is disconnected.
* Frees our resources associated with that client.
tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
plc->is_disconnected = GNUNET_YES;
GNUNET_SERVER_client_disconnect (tmit_frag->client);
- GNUNET_SCHEDULER_add_now (&schedule_cleanup_place, plc);
+ GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
return ret;
}
else
tmit_msg = psyc_transmit_queue_next_msg (plc, tmit_msg);
plc->is_disconnected = GNUNET_YES;
GNUNET_SERVER_client_disconnect (tmit_frag->client);
- GNUNET_SCHEDULER_add_now (&schedule_cleanup_place, plc);
+ GNUNET_SCHEDULER_add_now (&cleanup_place, plc);
}
else
{
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
GNUNET_SCHEDULER_cancel (end_badly_task);
end_badly_task = NULL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
- &end_normally, NULL);
+ GNUNET_SCHEDULER_add_now (&end_normally, NULL);
}
static void
transmit_resume (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission resumed.\n");
struct TransmitClosure *tmit = cls;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission resumed.\n");
if (NULL != tmit->host_ann)
GNUNET_SOCIAL_host_announce_resume (tmit->host_ann);
else
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Nym left the place again.\n");
- GNUNET_SCHEDULER_add_now (schedule_host_leave, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL);
}
static void
host_reconnected (void *cls, int result,
- const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
- uint64_t max_message_id)
+ const struct GNUNET_CRYPTO_EddsaPublicKey *home_pub_key,
+ uint64_t max_message_id)
{
place_pub_key = *home_pub_key;
GNUNET_CRYPTO_hash (&place_pub_key, sizeof (place_pub_key), &place_pub_hash);
is_host_reconnected = GNUNET_YES;
if (GNUNET_YES == is_guest_reconnected)
{
- GNUNET_SCHEDULER_add_now (schedule_guest_leave, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
}
}
is_guest_reconnected = GNUNET_YES;
if (GNUNET_YES == is_host_reconnected)
{
- GNUNET_SCHEDULER_add_now (schedule_guest_leave, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_guest_leave, NULL);
}
}
static void
-guest_look_for_result (void *cls, int64_t result_code,
- const void *data, uint16_t data_size)
+guest_look_for_result (void *cls,
+ int64_t result_code,
+ const void *data,
+ uint16_t data_size)
{
struct ResultClosure *rcls = cls;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
break;
case TEST_GUEST_ENTER_BY_NAME:
- GNUNET_SCHEDULER_add_now (schedule_reconnect, NULL);
+ GNUNET_SCHEDULER_add_now (&schedule_reconnect, NULL);
break;
default:
#endif
{
cfg = c;
- end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &end_badly, NULL);
core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
&handle_client_disconnect,
NULL);
load (server);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
* Main task that does the actual work.
*
* @param cls closure with our configuration
- * @param tc schedueler context
*/
static void
main_task (void *cls)
if (GNUNET_NO == watch)
{
if (NULL ==
- GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT, &cleanup,
+ GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT,
+ &cleanup,
&printer, h))
cleanup (h, GNUNET_SYSERR);
}
ret = 1;
return;
}
- if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name, &printer, h))
+ if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name,
+ &printer, h))
{
fprintf (stderr, _("Failed to initialize watch routine\n"));
GNUNET_SCHEDULER_add_now (&shutdown_task, h);
return;
}
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, h);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, h);
}
ai->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
&run_get_timeout,
ai);
- GNUNET_CONTAINER_DLL_insert_tail (handle->action_head, handle->action_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (handle->action_head,
+ handle->action_tail,
ai);
schedule_action (handle);
return ai;
static int
-watch_1 (void *cls, const char *subsystem, const char *name, uint64_t value,
+watch_1 (void *cls,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
int is_persistent)
{
GNUNET_assert (value == 42);
static int
-watch_2 (void *cls, const char *subsystem, const char *name, uint64_t value,
+watch_2 (void *cls,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
int is_persistent)
{
GNUNET_assert (value == 43);
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)
{
h = GNUNET_STATISTICS_create ("dummy", cfg);
GNUNET_STATISTICS_set (h2, "test-1", 42, GNUNET_NO);
GNUNET_STATISTICS_set (h2, "test-2", 43, GNUNET_NO);
shutdown_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &force_shutdown,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ &force_shutdown,
NULL);
}
* @param cfg configuration to use
*/
static void
-run (void *cls, struct GNUNET_SERVER_Handle *server,
+run (void *cls,
+ struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
};
/* FIXME: do setup here */
GNUNET_SERVER_add_handlers (server, handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
+ NULL);
}
/**
* Handle to the ATS performance subsystem
*/
-struct GNUNET_ATS_PerformanceHandle *ats;
+static struct GNUNET_ATS_PerformanceHandle *ats;
/**
* Prepared statement for inserting values into the database table
*/
-struct sqlite3_stmt *stmt_insert;
-
-/**
- * Shutdown task identifier
- */
-struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct sqlite3_stmt *stmt_insert;
/**
static void
do_shutdown (void *cls)
{
- shutdown_task = NULL;
GNUNET_ATS_performance_done (ats);
ats = NULL;
if (NULL != stmt_insert)
dbfile = NULL;
ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL);
map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
* The blacklist handle we obtain from transport when we register ourselves for
* access control
*/
-struct GNUNET_TRANSPORT_Blacklist *bh;
-
-/**
- * Task for shutdown
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_TRANSPORT_Blacklist *bh;
/**
* Are we allowing or denying access from peers
static int mode;
-/**
- * @ingroup hashmap
- * Iterator over hash map entries.
- *
- * @param cls closure
- * @param key current key code
- * @param value value in the hash map
- * @return #GNUNET_YES if we should continue to
- * iterate,
- * #GNUNET_NO if not.
- */
-static int
-iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
-{
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key,
- value));
- return GNUNET_YES;
-}
-
-
/**
* Cleaup and destroy the map
*/
{
if (NULL != map)
{
- GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map,
- &iterator,
- NULL));
GNUNET_CONTAINER_multipeermap_destroy (map);
map = NULL;
}
* @param cfg the configuration for connecting to the peer's transport service
*/
static void
-setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
+setup_ac (const char *fname,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
uint64_t fsize;
unsigned int npeers;
unsigned int cnt;
- GNUNET_assert (GNUNET_OK != GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
- GNUNET_YES));
+ GNUNET_assert (GNUNET_OK !=
+ GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
+ GNUNET_YES));
if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break (0);
}
for (cnt = 0; cnt < npeers; cnt++)
{
- if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
- &ilist[cnt],
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
+ &ilist[cnt],
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
cleanup_map ();
GNUNET_free (ilist);
return;
}
}
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL);
}
* @param c 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 *c)
{
char *shome;
char *fname;
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
- "GNUNET_HOME",
- &shome))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
+ "GNUNET_HOME",
+ &shome))
{
GNUNET_break (0);
return;
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
return 2;
ret =
(GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-testbed-blacklist",
- _
- ("Daemon to restrict incoming transport layer connections during testbed deployments"),
+ GNUNET_PROGRAM_run (argc, argv,
+ "gnunet-daemon-testbed-blacklist",
+ _("Daemon to restrict incoming transport layer connections during testbed deployments"),
options, &run, NULL)) ? 0 : 1;
GNUNET_free ((void*) argv);
return ret;
*/
static unsigned int num_hostkeys;
-/**
- * Task for shutdown
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
-
/**
* @ingroup hashmap
GNUNET_free (wl_entry);
}
bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL);
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
close_db:
GNUNET_break (SQLITE_OK == sqlite3_close (db));
- return;
}
/**
* Task identifier for the read task
*/
-static struct GNUNET_SCHEDULER_Task * read_task_id;
+static struct GNUNET_SCHEDULER_Task *read_task_id;
/**
* Task identifier for the write task
*/
-static struct GNUNET_SCHEDULER_Task * write_task_id;
+static struct GNUNET_SCHEDULER_Task *write_task_id;
/**
* Task to kill the child
*/
static struct GNUNET_SCHEDULER_Task * child_death_task_id;
-/**
- * shutdown task id
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
/**
* Are we done reading messages from stdin?
*/
shutdown_task (void *cls)
{
LOG_DEBUG ("Shutting down\n");
- shutdown_task_id = NULL;
if (NULL != testbed)
{
LOG_DEBUG ("Killing testbed\n");
}
if (NULL != write_task_id)
{
- GNUNET_SCHEDULER_cancel (write_task_id);
+ struct WriteContext *wc;
+
+ wc = GNUNET_SCHEDULER_cancel (write_task_id);
write_task_id = NULL;
+ GNUNET_free (wc->data);
+ GNUNET_free (wc);
}
if (NULL != child_death_task_id)
{
}
-/**
- * Scheduler shutdown task to be run now.
- */
-static void
-shutdown_now (void)
-{
- if (NULL != shutdown_task_id)
- GNUNET_SCHEDULER_cancel (shutdown_task_id);
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
-}
-
-
/**
* Task to write to the standard out
*
{
struct WriteContext *wc = cls;
ssize_t bytes_wrote;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_assert (NULL != wc);
write_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- GNUNET_free (wc->data);
- GNUNET_free (wc);
- return;
- }
bytes_wrote =
GNUNET_DISK_file_write (stdout_fd, wc->data + wc->pos,
wc->length - wc->pos);
if (GNUNET_SYSERR == bytes_wrote)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n");
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Cannot reply back configuration\n");
GNUNET_free (wc->data);
GNUNET_free (wc);
return;
return;
}
write_task_id =
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd,
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdout_fd,
&write_task, wc);
}
enum GNUNET_OS_ProcessStatusType type;
unsigned long code;
int ret;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
child_death_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
- {
- child_death_task_id =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr, &child_death_task, NULL);
- return;
- }
/* consume the signal */
GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
LOG_DEBUG ("Got SIGCHLD\n");
if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
- shutdown_now (); /* Couldn't send the signal, we shutdown frowning */
+ GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
}
return;
}
reply->config_size = htons ((uint16_t) config_size);
wc->data = reply;
write_task_id =
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd,
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdout_fd,
&write_task, wc);
child_death_task_id =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
error:
status = GNUNET_SYSERR;
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
{
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
ssize_t sread;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
read_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf));
if ((GNUNET_SYSERR == sread) || (0 == sread))
{
LOG_DEBUG ("STDIN closed\n");
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_YES == done_reading)
{
/* didn't expect any more data! */
GNUNET_break_op (0);
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
LOG_DEBUG ("Read %u bytes\n", sread);
GNUNET_NO))
{
GNUNET_break (0);
- shutdown_now ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
read_task_id = /* No timeout while reading */
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fd,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdin_fd,
&read_task, NULL);
}
* @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)
{
LOG_DEBUG ("Starting testbed helper...\n");
stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
stdout_fd = GNUNET_DISK_get_handle_from_native (stdout);
read_task_id =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fd,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ stdin_fd,
&read_task, NULL);
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
/**
* Our barrier wait handle
*/
-struct GNUNET_TESTBED_BarrierWaitHandle *wh;
+static struct GNUNET_TESTBED_BarrierWaitHandle *wh;
+
+static struct GNUNET_SCHEDULER_Task *tt;
/**
do_shutdown (void *cls)
{
if (NULL != wh)
+ {
GNUNET_TESTBED_barrier_wait_cancel (wh);
- wh = NULL;
+ wh = NULL;
+ }
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
}
*
* @param cls NULL
* @param name the barrier name
- * @param status GNUNET_SYSERR in case of error while waiting for the barrier;
- * GNUNET_OK if the barrier is crossed
+ * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
+ * #GNUNET_OK if the barrier is crossed
*/
static void
barrier_wait_cb (void *cls, const char *name, int status)
static void
do_wait (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
- wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL);
+ tt = NULL;
+ wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME,
+ &barrier_wait_cb,
+ NULL);
GNUNET_break (NULL != wh);
}
* @param config the configuration file handle
*/
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 *config)
{
unsigned int rsec;
rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, rsec),
- &do_wait, NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, rsec),
+ &do_wait, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
/**
* Main
*/
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
*/
struct GNUNET_BIO_WriteHandle *bio;
-/**
- * The shutdown task handle
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
/**
* The number of connections we have
*/
*/
static int in_shutdown;
+
/**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
+ * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
*
* @param cls NULL
* @param client identification of the client
* @param msg the actual message
*/
static void
-handle_log_msg (void *cls, struct GNUNET_SERVER_Client *client,
+handle_log_msg (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
uint16_t ms;
{
struct MessageQueue *mq_entry;
- shutdown_task_id = NULL;
in_shutdown = GNUNET_YES;
if (0 != nconn)
{
/* Delay shutdown if there are active connections */
- shutdown_task_id = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
return;
}
while (NULL != (mq_entry = mq_head))
{
GNUNET_free (mq_entry->msg);
GNUNET_SERVER_client_drop (mq_entry->client);
- GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry);
+ GNUNET_CONTAINER_DLL_remove (mq_head,
+ mq_tail,
+ mq_entry);
GNUNET_free (mq_entry);
}
GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio));
/**
- * Functions with this signature are called whenever a client
+x * Functions with this signature are called whenever a client
* is disconnected on the network level.
*
* @param cls closure
* for the last call when the server is destroyed
*/
static void
-client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
+client_disconnected (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
if (NULL == client)
{
return;
}
nconn--;
- if (GNUNET_YES != in_shutdown)
- return;
- GNUNET_assert (NULL != shutdown_task_id);
- GNUNET_SCHEDULER_cancel (shutdown_task_id);
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ if (GNUNET_YES == in_shutdown)
+ GNUNET_SCHEDULER_shutdown ();
}
* @param client identification of the client
*/
static void
-client_connected (void *cls, struct GNUNET_SERVER_Client *client)
+client_connected (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
if (NULL == client)
{
* @param cfg configuration to use
*/
static void
-logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+logger_run (void *cls,
+ struct GNUNET_SERVER_Handle *server,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
{&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0},
pid_t pid;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED-LOGGER", "DIR",
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "TESTBED-LOGGER",
+ "DIR",
&dir))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, "Not logging directory definied. Exiting\n");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "TESTBED-LOGGER",
+ "DIR");
GNUNET_SCHEDULER_shutdown ();
return;
}
hname = GNUNET_malloc (hname_len);
if (0 != gethostname (hname, hname_len))
{
- LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n");
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Cannot get hostname. Exiting\n");
GNUNET_free (hname);
GNUNET_free (dir);
GNUNET_SCHEDULER_shutdown ();
return;
}
- (void) GNUNET_asprintf (&fn, "%s/%.*s_%jd.dat", dir, hname_len, hname,
- (intmax_t) pid);
+ GNUNET_asprintf (&fn,
+ "%s/%.*s_%jd.dat",
+ dir,
+ hname_len,
+ hname,
+ (intmax_t) pid);
GNUNET_free (hname);
GNUNET_free (dir);
if (NULL == (bio = GNUNET_BIO_write_open (fn)))
GNUNET_SERVER_add_handlers (server, message_handlers);
GNUNET_SERVER_connect_notify (server, &client_connected, NULL);
GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL);
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
LOG_DEBUG ("TESTBED-LOGGER startup complete\n");
}
int
main (int argc, char *const *argv)
{
- //sleep (15); /* Debugging */
return (GNUNET_OK ==
GNUNET_SERVICE_run (argc, argv, "testbed-logger",
GNUNET_SERVICE_OPTION_NONE,
&logger_run, NULL)) ? 0 : 1;
}
-/* end of gnunet-service-testbed.c */
+/* end of gnunet-service-testbed-logger.c */
static struct MessageQueue *mq_tail;
-/**
- * The shutdown task handle
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
-
/**
* Function called to notify a client about the connection begin ready to queue
* more data. "buf" will be NULL and "size" zero if the connection was closed
* @param message the actual message
*/
static void
-handle_init (void *cls, struct GNUNET_SERVER_Client *client,
+handle_init (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_TESTBED_InitMessage *msg;
/**
- * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
+ * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
*
* @param cls NULL
* @param client identification of the client
* @param message the actual message
*/
static void
-handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
+handle_add_host (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_TESTBED_Host *host;
/**
- * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
+ * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
*
* @param cls NULL
* @param client identification of the client
* @param message the actual message
*/
static void
-handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
+handle_slave_get_config (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
struct MessageQueue *mq_entry;
uint32_t id;
- shutdown_task_id = NULL;
LOG_DEBUG ("Shutting down testbed service\n");
/* cleanup any remaining forwarded operations */
GST_clear_fopcq ();
GST_config = GNUNET_CONFIGURATION_dup (cfg);
GNUNET_SERVER_add_handlers (server, message_handlers);
GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
- shutdown_task_id =
- GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
LOG_DEBUG ("Testbed startup complete\n");
GST_stats_init (GST_config);
GST_barriers_init (GST_config);
int
main (int argc, char *const *argv)
{
- //sleep (15); /* Debugging */
return (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE,
+ GNUNET_SERVICE_run (argc, argv,
+ "testbed",
+ GNUNET_SERVICE_OPTION_NONE,
&testbed_run, NULL)) ? 0 : 1;
}
int ld_disk;
unsigned int mem_usage;
unsigned int nproc;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
sample_load_task_id = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
ld_cpu = cpu_get_load ();
ld_disk = disk_get_load ();
if ( (-1 == ld_cpu) || (-1 == ld_disk) )
struct OverlayConnectContext *occ = cls;
struct LocalPeer2Context *lp2c;
char *other_peer_str;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
occ->send_hello_task = NULL;
GNUNET_assert (NULL != occ->timeout_task);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GNUNET_assert (NULL != occ->hello);
if (OCC_TYPE_LOCAL != occ->type)
{
/**
* Abort task identifier
*/
-static struct GNUNET_SCHEDULER_Task * abort_task;
-
-/**
- * Shutdown task identifier
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task;
+static struct GNUNET_SCHEDULER_Task *abort_task;
/**
* Global event mask for all testbed events
static void
do_shutdown (void *cls)
{
- shutdown_task = NULL;
if (NULL != abort_task)
{
GNUNET_SCHEDULER_cancel (abort_task);
GNUNET_CONFIGURATION_destroy (cfg);
cfg = NULL;
}
- GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
}
static void
do_abort (void *cls)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
abort_task = NULL;
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Aborting\n");
result = GNUNET_SYSERR;
- if (NULL != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
result = GNUNET_OK;
fprintf (stdout, "\n");
print_overlay_links_summary ();
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (noninteractive)
{
GNUNET_SCHEDULER_cancel (abort_task);
abort_task = NULL;
- shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
return;
}
#if (!ENABLE_SUPERMUC)
#endif
fprintf (stdout, "Shutting down. Please wait\n");
fflush (stdout);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
- return;
+ GNUNET_SCHEDULER_shutdown ();
}
*/
static enum GNUNET_OS_ProcessStatusType child_status;
-/**
- * The shutdown task
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
-
/**
* Task to kill the child
*/
static void
shutdown_task (void *cls)
{
- shutdown_task_id = NULL;
if (0 != child_exit_code)
{
LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n",
GNUNET_assert (NULL != child);
terminate_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &terminate_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
if (0 != hard_kill)
{
switch (hard_kill)
&child_exit_code));
GNUNET_OS_process_destroy (child);
child = NULL;
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
}
{
GNUNET_break (0);
ret = GNUNET_SYSERR;
- shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
ret = GNUNET_OK;
terminate_task_id =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &terminate_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
child_death_task_id =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_DISK_pipe_handle (sigpipe,
do_shutdown (cls);
}
+
static void
abort_test ()
{
* @param cls NULL
* @param host the host whose status is being reported; will be NULL if the host
* given to GNUNET_TESTBED_is_host_habitable() is NULL
- * @param status GNUNET_YES if it is habitable; GNUNET_NO if not
+ * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
*/
static void
-host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host,
+host_habitable_cb (void *cls,
+ const struct GNUNET_TESTBED_Host *_host,
int status)
{
hc_handle = NULL;
"Skipping test\n");
GNUNET_SCHEDULER_cancel (abort_task);
abort_task = NULL;
- (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
result = SKIP;
return;
}
*/
static int status;
-/**
- * Shutdown task identifier
- */
-struct GNUNET_SCHEDULER_Task * shutdown_id;
/**
* The shutdown task
}
}
status = GNUNET_YES;
- shutdown_id =
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (0), &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
static void
do_abort (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
abort_task = NULL;
- (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Test timed out -- Aborting\n");
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
return; /* abort already scheduled */
GNUNET_SCHEDULER_cancel (abort_task);
abort_task = NULL;
- (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
return;
}
GNUNET_assert (NULL != peers[0]);
* @param cfg the configuration file handle
*/
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 *config)
{
uint64_t event_mask;
event_mask = 0;
event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
- GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, &controller_event_cb,
- NULL, &test_master, NULL);
+ GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask,
+ &controller_event_cb, NULL,
+ &test_master, NULL);
abort_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort,
+ (GNUNET_TIME_UNIT_SECONDS, 300),
+ &do_abort,
NULL);
}
*
* @param cls closure
* @param filename complete filename (absolute path)
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to stop iteration with no error,
+ * #GNUNET_SYSERR to abort iteration with error!
*/
-static void
+static int
iterator_cb (void *cls,
const char *filename)
{
const char *fn;
size_t len;
uint64_t fs;
- int cancel;
- cancel = GNUNET_NO;
- if (NULL == filename)
- return;
len = strlen (filename);
if (len < 5) /* log file: `pid'.dat */
- return;
+ return GNUNET_OK;
+
fn = filename + len;
if (0 != strcasecmp (".dat", fn - 4))
- return;
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs,
- GNUNET_NO, GNUNET_YES))
- return;
+ return GNUNET_OK;
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs,
+ GNUNET_NO, GNUNET_YES))
+ return GNUNET_SYSERR;
if ((BSIZE * 2) != fs) /* The file size should be equal to what we
have written */
- return;
- cancel = GNUNET_YES;
- result = GNUNET_OK;
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
}
/**
- * Functions of this type are called to notify a successful transmission of the
- * message to the logger service
+ * Functions of this type are called to notify a successful
+ * transmission of the message to the logger service
*
* @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
* @param size the amount of data sent
/**
* Task run upon shutdown interrupts
*/
- struct GNUNET_SCHEDULER_Task * interrupt_task;
+ struct GNUNET_SCHEDULER_Task *interrupt_task;
/**
* The event mask for the controller
unsigned int size;
/* reschedule */
- rc->interrupt_task = GNUNET_SCHEDULER_add_delayed
- (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt, rc);
+ rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc);
rc_cleanup_operations (rc);
if ( (GNUNET_NO == rc->shutdown) &&
(NULL != c) &&
GNUNET_SCHEDULER_shutdown ();
return;
}
- rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, rc);
+ rc->register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts,
+ rc);
}
}
rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256);
rc->timeout_task =
- GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
+ GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
+ GNUNET_assert (NULL == rc->interrupt_task);
rc->interrupt_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt,
- rc);
+ GNUNET_SCHEDULER_add_shutdown (&interrupt,
+ rc);
return;
error_cleanup:
/**
* Task identifier of the task that waits for stdin.
*/
-static struct GNUNET_SCHEDULER_Task * tid;
+static struct GNUNET_SCHEDULER_Task *tid;
/**
* Peer started for '-r'.
stdin_cb (void *cls)
{
int c;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
tid = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
- GNUNET_assert (0 != (GNUNET_SCHEDULER_REASON_READ_READY & tc->reason));
c = getchar ();
switch (c)
{
fprintf (stderr, _("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
break;
}
- tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh,
+ tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fh,
&stdin_cb, NULL);
}
}
printf("ok\n%s\n", tmpfilename);
fflush(stdout);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
fh = GNUNET_DISK_get_handle_from_native (stdin);
- tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh,
+ tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fh,
&stdin_cb, NULL);
}
struct FindAdvHelloContext fah;
size_t next_want;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
pl->hello_delay_task = NULL;
GNUNET_assert (GNUNET_YES == pl->is_connected);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return; /* we're out of here */
if (pl->hello_req != NULL)
return; /* did not finish sending the previous one */
/* find applicable HELLOs */
GNUNET_SCHEDULER_add_delayed (fah.next_adv,
&schedule_next_hello,
pl);
- if (fah.result == NULL)
+ if (NULL == fah.result)
return;
next_want = GNUNET_HELLO_size (fah.result->hello);
delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
NULL, GNUNET_NO,
NULL, GNUNET_NO,
handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleaning_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleaning_task,
+ NULL);
if (NULL == transport)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"My identity is `%4s'\n",
GNUNET_i2s_full (&GST_my_identity));
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (NULL == GST_peerinfo)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
validation_entry_changed (ve,
GNUNET_TRANSPORT_VS_UPDATE);
memset (&prop, 0, sizeof (prop));
- GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != ve->network);
prop.scope = ve->network;
prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2);
if (GNUNET_YES != ve->known_to_ats)
*/
static struct GNUNET_PeerIdentity pid;
-/**
- * Task scheduled for cleanup / termination of the process.
- */
-static struct GNUNET_SCHEDULER_Task * end;
-
/**
* Selected level of verbosity.
*/
if (it_count == benchmark_iterations)
{
benchmark_running = GNUNET_NO;
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
else
ats_sh = GNUNET_ATS_connectivity_suggest (ats,
&pid,
1);
- end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
FPRINTF (stdout,
_("Failed to connect to `%s'\n"),
GNUNET_i2s_full (&pid));
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
}
FPRINTF (stdout,
"%s",
_("Failed to list connections, timeout occured\n"));
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
ret = 1;
return;
}
GNUNET_free (vc);
if ((0 == address_resolutions) && (iterate_validation))
{
- if (NULL != end)
- {
- GNUNET_SCHEDULER_cancel (end);
- end = NULL;
- }
if (NULL != op_timeout)
{
GNUNET_SCHEDULER_cancel (op_timeout);
op_timeout = NULL;
}
ret = 0;
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
return;
}
vic = NULL;
- if (NULL != end)
- GNUNET_SCHEDULER_cancel (end);
- end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ GNUNET_SCHEDULER_shutdown ();
return;
}
resolve_validation_address (address,
GNUNET_free (rc);
if ((0 == address_resolutions) && (iterate_connections))
{
- if (NULL != end)
- {
- GNUNET_SCHEDULER_cancel (end);
- end = NULL;
- }
if (NULL != op_timeout)
{
GNUNET_SCHEDULER_cancel (op_timeout);
op_timeout = NULL;
}
ret = 0;
- end = GNUNET_SCHEDULER_add_now (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_shutdown ();
}
}
GNUNET_break(0);
return;
}
-
- end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
+
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
/**
* Session timeout task
*/
- struct GNUNET_SCHEDULER_Task * put_disconnect_task;
+ struct GNUNET_SCHEDULER_Task *put_disconnect_task;
/**
* Session timeout task
*/
- struct GNUNET_SCHEDULER_Task * timeout_task;
+ struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Task to wake up client receive handle when receiving is allowed again
*/
- struct GNUNET_SCHEDULER_Task * recv_wakeup_task;
+ struct GNUNET_SCHEDULER_Task *recv_wakeup_task;
/**
* Absolute time when to receive data again.
client_wake_up (void *cls)
{
struct GNUNET_ATS_Session *s = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
s->recv_wakeup_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p/request %p: Waking up GET handle\n",
s, s->get.easyhandle);
CURLMsg *msg;
int put_request; /* GNUNET_YES if easy handle is put, GNUNET_NO for get */
int msgs_left;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->client_perform_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
/* While data are available or timeouts occured */
do
{
if (s->recv_wakeup_task != NULL)
{
GNUNET_SCHEDULER_cancel (s->recv_wakeup_task);
- s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
- &client_wake_up, s);
+ s->recv_wakeup_task
+ = GNUNET_SCHEDULER_add_delayed (delay,
+ &client_wake_up,
+ s);
}
}
/**
* MHD IPv4 task
*/
- struct GNUNET_SCHEDULER_Task * server_v4_task;
+ struct GNUNET_SCHEDULER_Task *server_v4_task;
/**
* MHD IPv6 task
*/
- struct GNUNET_SCHEDULER_Task * server_v6_task;
+ struct GNUNET_SCHEDULER_Task *server_v6_task;
/**
* Task calling transport service about external address
*/
- struct GNUNET_SCHEDULER_Task * notify_ext_task;
+ struct GNUNET_SCHEDULER_Task *notify_ext_task;
/**
* Notify transport only about external address
server_wake_up (void *cls)
{
struct GNUNET_ATS_Session *s = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
s->recv_wakeup_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Session %p: Waking up PUT handle\n",
s);
server_v4_run (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->server_v4_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
plugin->server_v4_immediately = GNUNET_NO;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4));
server_reschedule (plugin, plugin->server_v4, GNUNET_NO);
server_v6_run (void *cls)
{
struct HTTP_Server_Plugin *plugin = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->server_v6_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
plugin->server_v6_immediately = GNUNET_NO;
GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6));
server_reschedule (plugin, plugin->server_v6, GNUNET_NO);
GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
MHD_suspend_connection (s->server_recv->mhd_conn);
if (NULL == s->recv_wakeup_task)
- s->recv_wakeup_task = GNUNET_SCHEDULER_add_delayed (delay,
- &server_wake_up, s);
+ s->recv_wakeup_task
+ = GNUNET_SCHEDULER_add_delayed (delay,
+ &server_wake_up,
+ s);
}
return MHD_YES;
}
size_t ext_addr_len;
unsigned int urlen;
char *url;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
plugin->notify_ext_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
- GNUNET_asprintf(&url,
- "%s://%s",
- plugin->protocol,
- plugin->external_hostname);
-
+ GNUNET_asprintf (&url,
+ "%s://%s",
+ plugin->protocol,
+ plugin->external_hostname);
urlen = strlen (url) + 1;
ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen);
ext_addr->options = htonl (plugin->options);
"Enabling SSL verification for external hostname address `%s'\n",
plugin->external_hostname);
plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- "https_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
+ "https_client",
+ ext_addr,
+ ext_addr_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->ext_addr);
GNUNET_free (ext_addr);
#else
plugin->ext_addr = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
- "http_client", ext_addr, ext_addr_len, GNUNET_HELLO_ADDRESS_INFO_NONE );
- plugin->env->notify_address (plugin->env->cls, GNUNET_YES, plugin->ext_addr);
+ "http_client",
+ ext_addr,
+ ext_addr_len,
+ GNUNET_HELLO_ADDRESS_INFO_NONE);
+ plugin->env->notify_address (plugin->env->cls,
+ GNUNET_YES,
+ plugin->ext_addr);
GNUNET_free (ext_addr);
#endif
}
{
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
+
plugin->select_task_v4 = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (NULL == plugin->sockv4)
return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready,
plugin->sockv4)))
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
plugin->select_task_v6 = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
if (NULL == plugin->sockv6)
return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready,
plugin->sockv6)) )
{
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
+
plugin->read_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
unix_plugin_do_read (plugin);
plugin->read_task =
{
struct Plugin *plugin = cls;
const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
+
plugin->write_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
unix_plugin_do_write (plugin);
if (NULL == plugin->msg_head)
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
+ char *receiver_s;
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
- char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
-
+ receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static void
stop_peer (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
struct PeerContext *p = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer %u (`%s')\n", p->no,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
[transport]
PLUGINS = http_server
-
PORT = 12101
PLUGINS = https_client
UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-transport.sock
+#PREFIX = valgrind
PORT = 12111
PLUGINS = https_server
UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-transport.sock
+#PREFIX = valgrind
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, &p2->id, 256, TIMEOUT,
¬ify_ready, &p1);
}
static void
sendtask_request_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static void
sendtask_response_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
{
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
{
struct GNUNET_TIME_Relative delay;
struct GNUNET_ATS_Properties prop;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
static void
sendtask (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
send_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
{
char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
timer (void *cls)
{
static int percentage;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
timer_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
percentage += 10;
time_running =
GNUNET_TIME_relative_add (time_running,
}
}
+
static void
testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
{
static void
end_badly (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Fail! Stopping peers\n");
timeout_task = NULL;
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
-
if (p1 != NULL)
GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1);
if (NULL != tth)
ret = GNUNET_SYSERR;
}
+
static void
notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
connected++;
}
+
static void
notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
{
GNUNET_i2s (peer));
}
+
static void
notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
/**
* Offer the current HELLO of P2 to P1.
*
- * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest `
+ * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
*/
static void
offer_hello (void *cls)
struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
struct PeerContext *p1 = cc->p1;
struct PeerContext *p2 = cc->p2;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
cc->tct = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
{
char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));
reconnect (void *cls)
{
struct GNUNET_TRANSPORT_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
h->reconnect_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* shutdown, just give up */
- return;
- }
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connecting to transport service.\n");
GNUNET_assert (NULL == h->client);
struct GNUNET_BANDWIDTH_Tracker *av = cls;
av->excess_task = NULL;
-
if (NULL != av->excess_cb)
av->excess_cb (av->excess_cb_cls);
}
/**
* Continuation to call the receive callback.
*
- * @param cls our handle to the client connection
+ * @param cls our handle to the client connection
*/
static void
receive_task (void *cls)
GNUNET_assert (GNUNET_YES == client->msg_complete);
GNUNET_assert (client->received_pos >= msize);
memcpy (msg, cmsg, msize);
- memmove (client->received_buf, &client->received_buf[msize],
+ memmove (client->received_buf,
+ &client->received_buf[msize],
client->received_pos - msize);
client->received_pos -= msize;
client->msg_complete = GNUNET_NO;
(GNUNET_SYSERR == client->in_receive) )
{
GNUNET_assert (NULL == client->receive_task);
- client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task, client);
+ client->receive_task = GNUNET_SCHEDULER_add_now (&receive_task,
+ client);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
/**
* ID of task used for asynchronous operations.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Final result to report back (once known).
client_delayed_retry (void *cls)
{
struct GNUNET_CLIENT_TransmitHandle *th = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_TIME_Relative delay;
th->reconnect_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* give up, was shutdown */
- th->client->th = NULL;
- th->notify (th->notify_cls, 0, NULL);
- GNUNET_free (th);
- return;
- }
th->client->connection =
do_connect (th->client->service_name,
th->client->cfg,
GNUNET_assert (NULL == th->th);
GNUNET_assert (NULL == th->reconnect_task);
th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &client_delayed_retry,
+ th);
return;
}
th->th =
GNUNET_CONNECTION_notify_transmit_ready (th->client->connection, th->size,
GNUNET_TIME_absolute_get_remaining
- (th->timeout), &client_notify,
+ (th->timeout),
+ &client_notify,
th);
if (NULL == th->th)
{
struct GNUNET_CLIENT_Connection *client = th->client;
size_t ret;
struct GNUNET_TIME_Relative delay;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
LOG (GNUNET_ERROR_TYPE_DEBUG,
"client_notify is running\n");
th->th = NULL;
client->th = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
if (NULL == buf)
{
delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
delay.rel_value_us /= 2;
if ( (GNUNET_YES != th->auto_retry) ||
(0 == --th->attempts_left) ||
- (delay.rel_value_us < 1)||
- (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
+ (delay.rel_value_us < 1) )
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Transmission failed %u times, giving up.\n",
GNUNET_assert (NULL == th->reconnect_task);
GNUNET_assert (NULL == th->th);
th->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th);
+ GNUNET_SCHEDULER_add_delayed (delay,
+ &client_delayed_retry,
+ th);
return 0;
}
GNUNET_assert (size >= th->size);
schedule_disconnect (void *cls)
{
struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
+
GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO,
- mgr->disconnect_cb, mgr->disconnect_cls);
+ mgr->disconnect_cb,
+ mgr->disconnect_cls);
}
static size_t
send_next_message (void *cls, size_t buf_size, void *buf)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "send_next_message()\n");
struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "send_next_message()\n");
if (NULL == buf)
{
/* disconnected */
GNUNET_assert (size <= buf_size);
memcpy (buf, mqi->msg, size);
- GNUNET_CONTAINER_DLL_remove (mgr->tmit_head, mgr->tmit_tail, mqi);
+ GNUNET_CONTAINER_DLL_remove (mgr->tmit_head,
+ mgr->tmit_tail,
+ mqi);
GNUNET_free (mqi->msg);
GNUNET_free (mqi);
}
else if (GNUNET_YES == mgr->is_disconnecting)
{
- GNUNET_SCHEDULER_add_now (&schedule_disconnect, mgr);
+ (void) GNUNET_SCHEDULER_add_now (&schedule_disconnect, mgr);
return size;
}
{
if (GNUNET_YES == mgr->is_disconnecting)
GNUNET_CLIENT_MANAGER_disconnect (mgr, GNUNET_NO,
- mgr->disconnect_cb, mgr->disconnect_cls);
+ mgr->disconnect_cb,
+ mgr->disconnect_cls);
return;
}
schedule_reconnect (void *cls)
{
struct GNUNET_CLIENT_MANAGER_Connection *mgr = cls;
- mgr->reconnect_task = NULL;
+ mgr->reconnect_task = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connecting to %s service.\n", mgr->service_name);
+ "Connecting to %s service.\n",
+ mgr->service_name);
GNUNET_assert (NULL == mgr->client);
- mgr->client = GNUNET_CLIENT_connect (mgr->service_name, mgr->cfg);
+ mgr->client = GNUNET_CLIENT_connect (mgr->service_name,
+ mgr->cfg);
GNUNET_assert (NULL != mgr->client);
-
transmit_next (mgr);
}
struct GNUNET_CLIENT_MANAGER_Connection *
GNUNET_CLIENT_MANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *service_name,
- const struct
- GNUNET_CLIENT_MANAGER_MessageHandler *handlers)
+ const struct GNUNET_CLIENT_MANAGER_MessageHandler *handlers)
{
- struct GNUNET_CLIENT_MANAGER_Connection *
- mgr = GNUNET_malloc (sizeof (*mgr));
+ struct GNUNET_CLIENT_MANAGER_Connection *mgr;
+
+ mgr = GNUNET_new (struct GNUNET_CLIENT_MANAGER_Connection);
mgr->cfg = cfg;
mgr->service_name = service_name;
mgr->handlers = handlers;
mgr->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
- mgr->reconnect_task = GNUNET_SCHEDULER_add_now (&schedule_reconnect, mgr);
+ mgr->reconnect_task = GNUNET_SCHEDULER_add_now (&schedule_reconnect,
+ mgr);
return mgr;
}
GNUNET_ContinuationCallback disconnect_cb,
void *cls)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting (%d)\n", transmit_queue);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting (%d)\n",
+ transmit_queue);
mgr->disconnect_cb = disconnect_cb;
mgr->disconnect_cls = cls;
if (NULL != mgr->tmit_head)
GNUNET_CLIENT_MANAGER_drop_queue (mgr);
}
}
- if (mgr->reconnect_task != NULL)
+ if (NULL != mgr->reconnect_task)
{
GNUNET_SCHEDULER_cancel (mgr->reconnect_task);
mgr->reconnect_task = NULL;
"Scheduling task to reconnect to service in %s.\n",
GNUNET_STRINGS_relative_time_to_string (mgr->reconnect_delay, GNUNET_YES));
mgr->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (mgr->reconnect_delay, &schedule_reconnect, mgr);
+ GNUNET_SCHEDULER_add_delayed (mgr->reconnect_delay,
+ &schedule_reconnect,
+ mgr);
mgr->reconnect_delay = GNUNET_TIME_STD_BACKOFF (mgr->reconnect_delay);
}
GNUNET_CLIENT_MANAGER_transmit (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
struct GNUNET_MessageHeader *msg)
{
- struct MessageQueueItem *mqi = GNUNET_malloc (sizeof (*mqi));
+ struct MessageQueueItem *mqi;
+
+ mqi = GNUNET_new (struct MessageQueueItem);
mqi->msg = GNUNET_copy_message (msg);
- GNUNET_CONTAINER_DLL_insert_tail (mgr->tmit_head, mgr->tmit_tail, mqi);
+ GNUNET_CONTAINER_DLL_insert_tail (mgr->tmit_head,
+ mgr->tmit_tail,
+ mqi);
transmit_next (mgr);
}
GNUNET_CLIENT_MANAGER_transmit_now (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
struct GNUNET_MessageHeader *msg)
{
- struct MessageQueueItem *mqi = GNUNET_malloc (sizeof (*mqi));
+ struct MessageQueueItem *mqi;
+
+ mqi = GNUNET_new (struct MessageQueueItem);
mqi->msg = GNUNET_copy_message (msg);
- GNUNET_CONTAINER_DLL_insert (mgr->tmit_head, mgr->tmit_tail, mqi);
+ GNUNET_CONTAINER_DLL_insert (mgr->tmit_head,
+ mgr->tmit_tail,
+ mqi);
transmit_next (mgr);
}
void
GNUNET_CLIENT_MANAGER_drop_queue (struct GNUNET_CLIENT_MANAGER_Connection *mgr)
{
- struct MessageQueueItem *cur, *next = mgr->tmit_head;
+ struct MessageQueueItem *cur;
+ struct MessageQueueItem *next;
+
+ next = mgr->tmit_head;
while (NULL != next)
{
cur = next;
* @return Operation, or NULL if not found.
*/
static struct OperationListItem *
-op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr, uint64_t op_id)
+op_find (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
+ uint64_t op_id)
{
- struct OperationListItem *op = mgr->op_head;
- while (NULL != op)
- {
+ struct OperationListItem *op;
+
+ for (op = mgr->op_head; NULL != op; op = op->next)
if (op->op_id == op_id)
return op;
- op = op->next;
- }
return NULL;
}
GNUNET_ResultCallback result_cb,
void *cls)
{
+ struct OperationListItem *op;
+
if (NULL == result_cb)
return 0;
-
- struct OperationListItem *op = GNUNET_malloc (sizeof (*op));
+ op = GNUNET_new (struct OperationListItem);
op->op_id = GNUNET_CLIENT_MANAGER_op_get_next_id (mgr);
op->result_cb = result_cb;
op->cls = cls;
- GNUNET_CONTAINER_DLL_insert_tail (mgr->op_head, mgr->op_tail, op);
-
+ GNUNET_CONTAINER_DLL_insert_tail (mgr->op_head,
+ mgr->op_tail,
+ op);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "%p Added operation #%" PRIu64 "\n", mgr, op->op_id);
+ "%p Added operation #%" PRIu64 "\n",
+ mgr,
+ op->op_id);
return op->op_id;
}
*/
static int
op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
- uint64_t op_id, int64_t result_code,
- const void *data, uint16_t data_size, uint8_t cancel)
+ uint64_t op_id,
+ int64_t result_code,
+ const void *data,
+ uint16_t data_size,
+ uint8_t cancel)
{
if (0 == op_id)
return GNUNET_NO;
return GNUNET_NO;
}
- GNUNET_CONTAINER_DLL_remove (mgr->op_head, mgr->op_tail, op);
-
- if (GNUNET_YES != cancel && NULL != op->result_cb)
- op->result_cb (op->cls, result_code, data, data_size);
+ GNUNET_CONTAINER_DLL_remove (mgr->op_head,
+ mgr->op_tail,
+ op);
+ if ( (GNUNET_YES != cancel) &&
+ (NULL != op->result_cb) )
+ op->result_cb (op->cls,
+ result_code, data,
+ data_size);
GNUNET_free (op);
return GNUNET_YES;
}
*/
int
GNUNET_CLIENT_MANAGER_op_result (struct GNUNET_CLIENT_MANAGER_Connection *mgr,
- uint64_t op_id, int64_t result_code,
- const void *data, uint16_t data_size)
+ uint64_t op_id,
+ int64_t result_code,
+ const void *data,
+ uint16_t data_size)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"%p Received result for operation #%" PRIu64 ": %" PRId64 " (size: %u)\n",
uint64_t op_id)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "%p Cancelling operation #%" PRIu64 "\n", mgr, op_id);
+ "%p Cancelling operation #%" PRIu64 "\n",
+ mgr,
+ op_id);
return op_result (mgr, op_id, 0, NULL, 0, GNUNET_YES);
}
struct GNUNET_RESOLVER_RequestHandle *dns_active;
/**
- * The handle we return for GNUNET_CONNECTION_notify_transmit_ready.
+ * The handle we return for #GNUNET_CONNECTION_notify_transmit_ready().
*/
struct GNUNET_CONNECTION_TransmitHandle nth;
addrlen = sizeof (addr);
sock =
- GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
+ GNUNET_NETWORK_socket_accept (lsock,
+ (struct sockaddr *) &addr,
+ &addrlen);
if (NULL == sock)
{
if (EAGAIN != errno)
sa = (struct sockaddr *) addr;
v6 = (struct sockaddr_in6 *) addr;
- if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)))
+ if ( (AF_INET6 == sa->sa_family) &&
+ (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) )
{
/* convert to V4 address */
v4 = GNUNET_new (struct sockaddr_in);
{
#if HAVE_GETPEEREID
/* most BSDs */
- if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid))
+ if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock),
+ &gc.uid,
+ &gc.gid))
gcp = &gc;
#else
#ifdef SO_PEERCRED
/* largely traditional GNU/Linux */
olen = sizeof (uc);
- if ((0 ==
- getsockopt (GNUNET_NETWORK_get_fd (sock), SOL_SOCKET, SO_PEERCRED, &uc,
- &olen)) && (olen == sizeof (uc)))
+ if ( (0 ==
+ getsockopt (GNUNET_NETWORK_get_fd (sock),
+ SOL_SOCKET,
+ SO_PEERCRED,
+ &uc,
+ &olen)) &&
+ (olen == sizeof (uc)) )
{
gc.uid = uc.uid;
gc.gid = uc.gid;
#endif
}
- if ((NULL != access_cb) &&
- (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen))))
+ if ( (NULL != access_cb) &&
+ (GNUNET_YES != (aret = access_cb (access_cb_cls,
+ gcp,
+ uaddr,
+ addrlen))) )
{
if (GNUNET_NO == aret)
LOG (GNUNET_ERROR_TYPE_INFO,
connection->sock = sock;
LOG (GNUNET_ERROR_TYPE_INFO,
_("Accepting connection from `%s': %p\n"),
- GNUNET_a2s (uaddr, addrlen), connection);
+ GNUNET_a2s (uaddr,
+ addrlen),
+ connection);
return connection;
}
return; /* nobody to tell about it */
notify = connection->nth.notify_ready;
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
+ notify (connection->nth.notify_ready_cls,
+ 0,
+ NULL);
}
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection to `%s' succeeded! (%p)\n",
- GNUNET_a2s (connection->addr, connection->addrlen),
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
connection);
/* trigger jobs that waited for the connection */
if (NULL != connection->receiver)
GNUNET_assert (NULL == connection->read_task);
connection->read_task =
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout), connection->sock,
+ (connection->receive_timeout),
+ connection->sock,
&receive_ready, connection);
}
if (NULL != connection->nth.notify_ready)
socklen_t len;
GNUNET_assert (NULL != ap->sock);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+ connection->ap_tail,
+ ap);
len = sizeof (error);
errno = 0;
error = 0;
tc = GNUNET_SCHEDULER_get_task_context ();
- if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
- (GNUNET_OK !=
- GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error,
- &len)) || (0 != error))
+ if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
+ (GNUNET_OK !=
+ GNUNET_NETWORK_socket_getsockopt (ap->sock,
+ SOL_SOCKET,
+ SO_ERROR,
+ &error,
+ &len)) ||
+ (0 != error) )
{
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (ap->sock));
GNUNET_free (ap);
- if ((NULL == connection->ap_head) &&
- (GNUNET_NO == connection->dns_active) &&
- (NULL == connection->proxy_handshake))
+ if ( (NULL == connection->ap_head) &&
+ (GNUNET_NO == connection->dns_active) &&
+ (NULL == connection->proxy_handshake) )
connect_fail_continuation (connection);
return;
}
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+ connection->ap_tail,
+ pos);
GNUNET_free (pos);
}
connect_success_continuation (connection);
GNUNET_free (ap);
return; /* not supported by us */
}
- ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
+ ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family,
+ SOCK_STREAM, 0);
if (NULL == ap->sock)
{
GNUNET_free (ap);
GNUNET_a2s (ap->addr, ap->addrlen),
connection);
if ((GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) &&
+ GNUNET_NETWORK_socket_connect (ap->sock,
+ ap->addr,
+ ap->addrlen)) &&
(EINPROGRESS != errno))
{
/* maybe refused / unsupported address, try next */
GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap);
delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
if (NULL != connection->nth.notify_ready)
- delay =
- GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
+ delay = GNUNET_TIME_relative_min (delay,
+ GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout));
if (NULL != connection->receiver)
- delay =
- GNUNET_TIME_relative_min (delay,
- GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout));
- ap->task =
- GNUNET_SCHEDULER_add_write_net (delay, ap->sock,
- &connect_probe_continuation, ap);
+ delay = GNUNET_TIME_relative_min (delay,
+ GNUNET_TIME_absolute_get_remaining (connection->receive_timeout));
+ ap->task = GNUNET_SCHEDULER_add_write_net (delay,
+ ap->sock,
+ &connect_probe_continuation,
+ ap);
}
connection->port = port;
connection->hostname = GNUNET_strdup (hostname);
connection->dns_active =
- GNUNET_RESOLVER_ip_get (connection->hostname, AF_UNSPEC,
+ GNUNET_RESOLVER_ip_get (connection->hostname,
+ AF_UNSPEC,
GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
- &try_connect_using_address, connection);
+ &try_connect_using_address,
+ connection);
return connection;
}
{
int abstract;
- abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TESTING",
+ abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "TESTING",
"USE_ABSTRACT_SOCKETS");
if (GNUNET_YES == abstract)
un->sun_path[0] = '\0';
connection->hostname = NULL;
connection->addr = (struct sockaddr *) un;
connection->addrlen = sizeof (struct sockaddr_un);
- connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+ connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX,
+ SOCK_STREAM,
+ 0);
if (NULL == connection->sock)
{
GNUNET_free (connection->addr);
return NULL;
}
if ( (GNUNET_OK !=
- GNUNET_NETWORK_socket_connect (connection->sock, connection->addr, connection->addrlen)) &&
+ GNUNET_NETWORK_socket_connect (connection->sock,
+ connection->addr,
+ connection->addrlen)) &&
(EINPROGRESS != errno) )
{
/* Just return; we expect everything to work eventually so don't fail HARD */
- GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NETWORK_socket_close (connection->sock));
connection->sock = NULL;
return connection;
}
s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0);
if (NULL == s)
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
+ "socket");
return NULL;
}
- return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen);
+ return GNUNET_CONNECTION_connect_socket (s,
+ serv_addr,
+ addrlen);
}
{
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock));
GNUNET_SCHEDULER_cancel (pos->task);
- GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos);
+ GNUNET_CONTAINER_DLL_remove (connection->ap_head,
+ connection->ap_tail,
+ pos);
GNUNET_free (pos);
}
if ( (NULL != connection->sock) &&
connection->read_task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* ignore shutdown request, go again immediately */
- connection->read_task =
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining
- (connection->receive_timeout), connection->sock,
- &receive_ready, connection);
- return;
- }
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Receive from `%s' encounters error: timeout (%s, %p)\n",
- GNUNET_a2s (connection->addr, connection->addrlen),
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), GNUNET_YES),
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout),
+ GNUNET_YES),
connection);
signal_receive_timeout (connection);
return;
signal_receive_error (connection, ECONNREFUSED);
return;
}
- GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock));
+ GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready,
+ connection->sock));
RETRY:
ret = GNUNET_NETWORK_socket_recv (connection->sock,
buffer,
/**
- * Receive data from the given connection. Note that this function will
- * call @a receiver asynchronously using the scheduler. It will
+ * Receive data from the given connection. Note that this function
+ * will call @a receiver asynchronously using the scheduler. It will
* "immediately" return. Note that there MUST only be one active
* receive call per connection at any given point in time (so do not
* call receive again until the receiver callback has been invoked).
(NULL == connection->proxy_handshake))
{
connection->receiver = NULL;
- receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
+ receiver (receiver_cls,
+ NULL, 0,
+ NULL, 0,
+ ETIMEDOUT);
return;
}
}
notify = connection->nth.notify_ready;
GNUNET_assert (NULL != notify);
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
+ notify (connection->nth.notify_ready_cls,
+ 0,
+ NULL);
}
connection->write_task = NULL;
notify = connection->nth.notify_ready;
connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
+ notify (connection->nth.notify_ready_cls,
+ 0,
+ NULL);
}
connection->write_task = NULL;
GNUNET_assert (NULL == connection->nth.timeout_task);
tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- if (NULL != connection->sock)
- goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Transmit to `%s' fails, shutdown happened (%p).\n",
- GNUNET_a2s (connection->addr, connection->addrlen), connection);
- notify = connection->nth.notify_ready;
- if (NULL != notify)
- {
- connection->nth.notify_ready = NULL;
- notify (connection->nth.notify_ready_cls, 0, NULL);
- }
- return;
- }
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
* Hence retry. */
goto SCHEDULE_WRITE;
}
- if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock))
+ if (! GNUNET_NETWORK_fdset_isset (tc->write_ready,
+ connection->sock))
{
GNUNET_assert (NULL == connection->write_task);
/* special circumstances (in particular, shutdown): not yet ready
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection transmitted %u/%u bytes to `%s' (%p)\n",
- (unsigned int) ret, have, GNUNET_a2s (connection->addr, connection->addrlen), connection);
+ (unsigned int) ret,
+ have,
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
+ connection);
connection->write_buffer_pos += ret;
if (connection->write_buffer_pos == connection->write_buffer_off)
{
connection->write_buffer_pos = 0;
connection->write_buffer_off = 0;
}
- if ((0 == connection->write_buffer_off) && (NULL == connection->nth.notify_ready))
+ if ( (0 == connection->write_buffer_off) &&
+ (NULL == connection->nth.notify_ready) )
return; /* all data sent! */
/* not done writing, schedule more */
SCHEDULE_WRITE:
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Re-scheduling transmit_ready (more to do) (%p).\n", connection);
+ "Re-scheduling transmit_ready (more to do) (%p).\n",
+ connection);
have = connection->write_buffer_off - connection->write_buffer_pos;
- GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0));
+ GNUNET_assert ( (NULL != connection->nth.notify_ready) ||
+ (have > 0) );
if (NULL == connection->write_task)
connection->write_task =
GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready ==
NULL) ? GNUNET_TIME_UNIT_FOREVER_REL :
GNUNET_TIME_absolute_get_remaining
(connection->nth.transmit_timeout),
- connection->sock, &transmit_ready, connection);
+ connection->sock,
+ &transmit_ready, connection);
}
GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection,
size_t size,
struct GNUNET_TIME_Relative timeout,
- GNUNET_CONNECTION_TransmitReadyNotify
- notify, void *notify_cls)
+ GNUNET_CONNECTION_TransmitReadyNotify notify,
+ void *notify_cls)
{
if (NULL != connection->nth.notify_ready)
{
connection->write_task =
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining
(connection->nth.transmit_timeout),
- connection->sock, &transmit_ready, connection);
+ connection->sock,
+ &transmit_ready, connection);
return &connection->nth;
}
/* not yet connected, wait for connection */
connection);
connection->nth.timeout_task =
GNUNET_SCHEDULER_add_delayed (timeout,
- &transmit_timeout, connection);
+ &transmit_timeout,
+ connection);
return &connection->nth;
}
struct GNUNET_CONNECTION_Handle *
GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph)
{
- struct GNUNET_CONNECTION_Handle * proxied = GNUNET_CONNECTION_create_from_existing(NULL);
+ struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL);
+
proxied->proxy_handshake = cph;
return proxied;
}
GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied)
{
struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake;
+
GNUNET_assert (NULL != cph);
GNUNET_assert (NULL == proxied->sock);
GNUNET_assert (NULL != cph->sock);
- proxied->sock=cph->sock;
- cph->sock=NULL;
+ proxied->sock = cph->sock;
+ cph->sock = NULL;
GNUNET_CONNECTION_destroy (cph);
connect_success_continuation (proxied);
}
delta = fhc->bsize;
if (fhc->fsize - fhc->offset < delta)
delta = fhc->fsize - fhc->offset;
- if (delta != GNUNET_DISK_file_read (fhc->fh, fhc->buffer, delta))
+ if (delta != GNUNET_DISK_file_read (fhc->fh,
+ fhc->buffer,
+ delta))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", fhc->filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "read",
+ fhc->filename);
file_hash_finish (fhc, NULL);
return;
}
fhc->offset += delta;
if (fhc->offset == fhc->fsize)
{
- res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512);
+ res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md,
+ GCRY_MD_SHA512);
file_hash_finish (fhc, res);
return;
}
fhc->task = GNUNET_SCHEDULER_add_with_priority (fhc->priority,
- &file_hash_task, fhc);
+ &file_hash_task,
+ fhc);
}
* @param filename name of file to hash
* @param blocksize number of bytes to process in one task
* @param callback function to call upon completion
- * @param callback_cls closure for callback
+ * @param callback_cls closure for @a callback
* @return NULL on (immediate) errror
*/
struct GNUNET_CRYPTO_FileHashContext *
GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
- const char *filename, size_t blocksize,
+ const char *filename,
+ size_t blocksize,
GNUNET_CRYPTO_HashCompletedCallback callback,
void *callback_cls)
{
return NULL;
}
fhc->bsize = blocksize;
- if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fhc->fsize, GNUNET_NO, GNUNET_YES))
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename,
+ &fhc->fsize,
+ GNUNET_NO,
+ GNUNET_YES))
{
GNUNET_free (fhc->filename);
GNUNET_free (fhc);
return NULL;
}
- fhc->fh =
- GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
- if (!fhc->fh)
+ fhc->fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (! fhc->fh)
{
GNUNET_free (fhc->filename);
GNUNET_free (fhc);
return NULL;
}
fhc->priority = priority;
- fhc->task =
- GNUNET_SCHEDULER_add_with_priority (priority, &file_hash_task, fhc);
+ fhc->task = GNUNET_SCHEDULER_add_with_priority (priority,
+ &file_hash_task,
+ fhc);
return fhc;
}
{
GNUNET_SCHEDULER_cancel (fhc->task);
GNUNET_free (fhc->filename);
- GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fhc->fh));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (fhc->fh));
GNUNET_free (fhc);
}
static uint64_t proof;
-static struct GNUNET_SCHEDULER_Task * proof_task;
+static struct GNUNET_SCHEDULER_Task *proof_task;
static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Write our current proof to disk.
+ *
+ * @param cls closure
*/
static void
-write_proof ()
+shutdown_task (void *cls)
{
if (sizeof (proof) !=
- GNUNET_DISK_fn_write (pwfn, &proof, sizeof (proof),
+ GNUNET_DISK_fn_write (pwfn,
+ &proof,
+ sizeof (proof),
GNUNET_DISK_PERM_USER_READ |
GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof);
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+ "write",
+ proof);
}
unsigned int i;
struct GNUNET_TIME_Absolute timestamp;
struct GNUNET_TIME_Relative elapsed;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- {
- write_proof ();
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got Proof of Work %llu\n", proof);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Got Proof of Work %llu\n",
+ proof);
proof_task = NULL;
memcpy (&buf[sizeof (uint64_t)], &pub,
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
proof = counter;
FPRINTF (stdout, "Proof of work found: %llu!\n",
(unsigned long long) proof);
- write_proof ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
counter++;
(unsigned long long) counter);
/* remember progress every 100 rounds */
proof = counter;
- write_proof ();
+ shutdown_task (NULL);
}
else
{
proof = counter;
}
proof_task =
- GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof, NULL);
}
char *pids;
cfg = config;
-
/* load proof of work */
if (NULL == pwfn)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE",
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "NSE",
"PROOFFILE",
&pwfn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE", "PROOFFILE");
+ "NSE",
+ "PROOFFILE");
GNUNET_SCHEDULER_shutdown ();
return;
}
/* load private key */
if (NULL == pkfn)
{
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "PEER",
- "PRIVATE_KEY",
- &pkfn))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &pkfn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "PEER", "PRIVATE_KEY");
+ "PEER",
+ "PRIVATE_KEY");
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Private Key file: %s\n",
+ pkfn);
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
{
- FPRINTF (stderr, _("Loading hostkey from `%s' failed.\n"), pkfn);
+ FPRINTF (stderr,
+ _("Loading hostkey from `%s' failed.\n"),
+ pkfn);
GNUNET_free (pkfn);
return;
}
if (0 == nse_work_required)
{
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS",
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "NSE",
+ "WORKBITS",
&nse_work_required))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "NSE",
+ "WORKBITS");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8)
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS",
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "NSE",
+ "WORKBITS",
_("Value is too large.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
- } else if (0 == nse_work_required)
+ }
+ else if (0 == nse_work_required)
{
- write_proof ();
GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delay between tries: %s\n",
GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1));
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ proof_task =
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
}
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
maint_child_death (void *cls)
{
enum GNUNET_OS_ProcessStatusType type;
+
if ( (GNUNET_OK !=
GNUNET_OS_process_status (p, &type, &exit_code)) ||
(type != GNUNET_OS_PROCESS_EXITED) )
if (NULL == (uri = args[0]))
{
- fprintf (stderr, _("No URI specified on command line\n"));
+ fprintf (stderr,
+ _("No URI specified on command line\n"));
return;
}
if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://")))
{
- fprintf (stderr, _("Invalid URI: does not start with `%s'\n"),
+ fprintf (stderr,
+ _("Invalid URI: does not start with `%s'\n"),
"gnunet://");
return;
}
/**
* Task to read from the helper.
*/
- struct GNUNET_SCHEDULER_Task * read_task;
+ struct GNUNET_SCHEDULER_Task *read_task;
/**
* Task to read from the helper.
*/
- struct GNUNET_SCHEDULER_Task * write_task;
+ struct GNUNET_SCHEDULER_Task *write_task;
/**
* Restart task.
*/
- struct GNUNET_SCHEDULER_Task * restart_task;
+ struct GNUNET_SCHEDULER_Task *restart_task;
/**
* Does the helper support the use of a control pipe for signalling?
helper_read (void *cls)
{
struct GNUNET_HELPER_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
ssize_t t;
h->read_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* try again */
- h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper, &helper_read, h);
- return;
- }
t = GNUNET_DISK_file_read (h->fh_from_helper, &buf, sizeof (buf));
if (t < 0)
{
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
if (0 == t)
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task
+ = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
(unsigned int) t,
h->binary_name);
h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_from_helper, &helper_read, h);
+ h->fh_from_helper,
+ &helper_read, h);
if (GNUNET_SYSERR ==
- GNUNET_SERVER_mst_receive (h->mst, NULL, buf, t, GNUNET_NO, GNUNET_NO))
+ GNUNET_SERVER_mst_receive (h->mst,
+ NULL,
+ buf, t,
+ GNUNET_NO, GNUNET_NO))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Failed to parse inbound message from helper `%s'\n"),
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
}
/* out of file descriptors? try again later... */
stop_helper (h, GNUNET_NO);
h->restart_task =
- GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
{
/* failed to start process? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
helper_write (void *cls)
{
struct GNUNET_HELPER_Handle *h = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_HELPER_SendHandle *sh;
const char *buf;
ssize_t t;
h->write_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* try again */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Helper write triggered during shutdown, retrying\n");
- h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
- h->fh_to_helper, &helper_write, h);
- return;
- }
if (NULL == (sh = h->sh_head))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Stopping and restarting helper task!\n");
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task = GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
- h->retry_back_off), &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off),
+ &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
impl_send_continue (void *cls)
{
struct GNUNET_MQ_Handle *mq = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
struct GNUNET_MQ_Envelope *current_envelope;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
mq->continue_task = NULL;
/* call is only valid if we're actually currently sending
* a message */
GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
mq->envelope_tail,
mq->current_envelope);
- mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
+ mq->send_impl (mq,
+ mq->current_envelope->mh,
+ mq->impl_state);
}
if (NULL != current_envelope->sent_cb)
current_envelope->sent_cb (current_envelope->sent_cls);
/**
- * Call the send implementation for the next queued message,
- * if any.
- * Only useful for implementing message queues,
- * results in undefined behavior if not used carefully.
+ * Call the send implementation for the next queued message, if any.
+ * Only useful for implementing message queues, results in undefined
+ * behavior if not used carefully.
*
* @param mq message queue to send the next message with
*/
return NULL;
mqm = GNUNET_MQ_msg_ (mhp, size, type);
- memcpy ((char *) mqm->mh + base_size, nested_mh, ntohs (nested_mh->size));
+ memcpy ((char *) mqm->mh + base_size,
+ nested_mh,
+ ntohs (nested_mh->size));
return mqm;
}
* Transmit a queued message to the session's client.
*
* @param cls consensus session
- * @param size number of bytes available in buf
+ * @param size number of bytes available in @a buf
* @param buf where the callee should write the message
- * @return number of bytes written to buf
+ * @return number of bytes written to @a buf
*/
static size_t
transmit_queued (void *cls, size_t size,
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL != state);
- state->th =
- GNUNET_SERVER_notify_transmit_ready (state->client, ntohs (msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_queued, mq);
+ state->th = GNUNET_SERVER_notify_transmit_ready (state->client,
+ ntohs (msg->size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &transmit_queued, mq);
}
GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ);
return;
}
-
- GNUNET_CLIENT_receive (state->connection, handle_client_message, mq,
+ GNUNET_CLIENT_receive (state->connection,
+ &handle_client_message,
+ mq,
GNUNET_TIME_UNIT_FOREVER_REL);
-
GNUNET_MQ_inject_message (mq, msg);
}
GNUNET_assert (NULL != state);
GNUNET_assert (NULL == state->th);
state->th =
- GNUNET_CLIENT_notify_transmit_ready (state->connection, ntohs (msg->size),
+ GNUNET_CLIENT_notify_transmit_ready (state->connection,
+ ntohs (msg->size),
GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO,
&connection_client_transmit_queued, mq);
GNUNET_assert (NULL != state->th);
if (NULL == mq->assoc_map)
return NULL;
- val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map, request_id);
- GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map, request_id);
+ val = GNUNET_CONTAINER_multihashmap32_get (mq->assoc_map,
+ request_id);
+ GNUNET_CONTAINER_multihashmap32_remove_all (mq->assoc_map,
+ request_id);
return val;
}
struct GNUNET_MQ_Envelope *ev;
ev = mq->envelope_head;
ev->parent_queue = NULL;
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
+ mq->envelope_tail,
+ ev);
GNUNET_MQ_discard (ev);
}
-
if (NULL != mq->current_envelope)
{
/* we can only discard envelopes that
GNUNET_MQ_discard (mq->current_envelope);
mq->current_envelope = NULL;
}
-
if (NULL != mq->assoc_map)
{
GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map);
GNUNET_assert (NULL != mq);
GNUNET_assert (NULL != mq->cancel_impl);
- if (mq->current_envelope == ev) {
+ if (mq->current_envelope == ev)
+ {
// complex case, we already started with transmitting
// the message
- mq->cancel_impl (mq, mq->impl_state);
+ mq->cancel_impl (mq,
+ mq->impl_state);
// continue sending the next message, if any
if (NULL == mq->envelope_head)
{
GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
mq->envelope_tail,
mq->current_envelope);
- mq->send_impl (mq, mq->current_envelope->mh, mq->impl_state);
+ mq->send_impl (mq,
+ mq->current_envelope->mh,
+ mq->impl_state);
}
- } else {
+ }
+ else
+ {
// simple case, message is still waiting in the queue
- GNUNET_CONTAINER_DLL_remove (mq->envelope_head, mq->envelope_tail, ev);
+ GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
+ mq->envelope_tail,
+ ev);
}
ev->parent_queue = NULL;
.bug_email = "gnunet-developers@gnu.org",
.homepage = "http://www.gnu.org/s/gnunet/",
.config_file = "gnunet.conf",
- .user_config_file = "~/.config/gnunet.conf"
+ .user_config_file = "~/.config/gnunet.conf",
};
/**
*/
static struct GNUNET_OS_Process current_process;
+/**
+ * Handle for the #parent_control_handler() Task.
+ */
+static struct GNUNET_SCHEDULER_Task *pch;
+
+
+/**
+ * This handler is called on shutdown to remove the #pch.
+ *
+ * @param cls the `struct GNUNET_DISK_FileHandle` of the control pipe
+ */
+static void
+shutdown_pch (void *cls)
+{
+ struct GNUNET_DISK_FileHandle *control_pipe = cls;
+
+ GNUNET_SCHEDULER_cancel (pch);
+ pch = NULL;
+ GNUNET_DISK_file_close (control_pipe);
+ control_pipe = NULL;
+}
+
/**
* This handler is called when there are control data to be read on the pipe
*
- * @param cls the 'struct GNUNET_DISK_FileHandle' of the control pipe
+ * @param cls the `struct GNUNET_DISK_FileHandle` of the control pipe
*/
static void
parent_control_handler (void *cls)
{
struct GNUNET_DISK_FileHandle *control_pipe = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
char sig;
char *pipe_fd;
ssize_t ret;
- tc = GNUNET_SCHEDULER_get_task_context ();
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "`%s' invoked because of %d\n", __FUNCTION__,
- tc->reason);
- if (0 != (tc->reason &
- (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT)))
- {
- GNUNET_DISK_file_close (control_pipe);
- control_pipe = NULL;
- return;
- }
- ret = GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig));
+ pch = NULL;
+ ret = GNUNET_DISK_file_read (control_pipe,
+ &sig,
+ sizeof (sig));
if (sizeof (sig) != ret)
{
if (-1 == ret)
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read");
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Closing control pipe\n");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+ "GNUNET_DISK_file_read");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Closing control pipe\n");
GNUNET_DISK_file_close (control_pipe);
control_pipe = NULL;
return;
}
pipe_fd = getenv (GNUNET_OS_CONTROL_PIPE);
- GNUNET_assert ( (NULL == pipe_fd) || (strlen (pipe_fd) <= 0) );
+ GNUNET_assert ( (NULL == pipe_fd) ||
+ (strlen (pipe_fd) <= 0) );
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got control code %d from parent via pipe %s\n", sig, pipe_fd);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- control_pipe, &parent_control_handler,
- control_pipe);
+ "Got control code %d from parent via pipe %s\n",
+ sig,
+ pipe_fd);
+ pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ control_pipe,
+ &parent_control_handler,
+ control_pipe);
GNUNET_SIGNAL_raise ((int) sig);
}
/**
* Task that connects this process to its parent via pipe;
* essentially, the parent control handler will read signal numbers
- * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment
+ * from the #GNUNET_OS_CONTROL_PIPE (as given in an environment
* variable) and raise those signals.
*
* @param cls closure (unused)
struct GNUNET_DISK_FileHandle *control_pipe;
uint64_t pipe_fd;
+ if (NULL != pch)
+ {
+ /* already done, we've been called twice... */
+ GNUNET_break (0);
+ return;
+ }
env_buf = getenv (GNUNET_OS_CONTROL_PIPE);
if ( (NULL == env_buf) || (strlen (env_buf) <= 0) )
{
pipe_fd = strtoull (env_buf, &env_buf_end, 16);
if ((0 != errno) || (env_buf == env_buf_end))
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "strtoull", env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "strtoull",
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
#endif
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n", env_buf);
+ "GNUNET_OS_CONTROL_PIPE `%s' contains garbage?\n",
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
#endif
if (NULL == control_pipe)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "open",
+ env_buf);
putenv (GNUNET_OS_CONTROL_PIPE "=");
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding parent control handler pipe `%s' to the scheduler\n", env_buf);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe,
- &parent_control_handler, control_pipe);
+ "Adding parent control handler pipe `%s' to the scheduler\n",
+ env_buf);
+ pch = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ control_pipe,
+ &parent_control_handler,
+ control_pipe);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_pch,
+ control_pipe);
putenv (GNUNET_OS_CONTROL_PIPE "=");
}
/**
* Get process structure for current process
*
- * The pointer it returns points to static memory location and must not be
- * deallocated/closed
+ * The pointer it returns points to static memory location and must
+ * not be deallocated/closed.
*
* @return pointer to the process sturcutre for this process
*/
* @return 0 on success, -1 on error
*/
int
-GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig)
+GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc,
+ int sig)
{
int ret;
char csig;
csig = (char) sig;
if (NULL != proc->control_pipe)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via pipe\n", sig, proc->pid);
- ret = GNUNET_DISK_file_write (proc->control_pipe, &csig, sizeof (csig));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending signal %d to pid: %u via pipe\n",
+ sig,
+ proc->pid);
+ ret = GNUNET_DISK_file_write (proc->control_pipe,
+ &csig,
+ sizeof (csig));
if (sizeof (csig) == ret)
return 0;
}
if (0 != GetExitCodeProcess (proc->handle, &exitcode))
must_kill = (exitcode == STILL_ACTIVE) ? GNUNET_YES : GNUNET_NO;
if (GNUNET_YES == must_kill)
+ {
if (0 == SafeTerminateProcess (proc->handle, 0, 0))
{
DWORD error_code = GetLastError ();
- if ((error_code != WAIT_TIMEOUT) && (error_code != ERROR_PROCESS_ABORTED))
+ if ( (error_code != WAIT_TIMEOUT) &&
+ (error_code != ERROR_PROCESS_ABORTED) )
{
LOG ((error_code == ERROR_ACCESS_DENIED) ?
- GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
- "SafeTermiateProcess failed with code %lu\n", error_code);
+ GNUNET_ERROR_TYPE_INFO : GNUNET_ERROR_TYPE_WARNING,
+ "SafeTermiateProcess failed with code %lu\n",
+ error_code);
/* The problem here is that a process that is already dying
* might cause SafeTerminateProcess to fail with
* ERROR_ACCESS_DENIED, but the process WILL die eventually.
}
}
}
+ }
}
return 0;
#else
errno = EINVAL;
return -1;
#else
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending signal %d to pid: %u via system call\n", sig, proc->pid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending signal %d to pid: %u via system call\n",
+ sig,
+ proc->pid);
return PLIBC_KILL (proc->pid, sig);
#endif
}
}
+
/**
* Get the pid of the process in question
*
/**
- * Cleans up process structure contents (OS-dependent) and deallocates it
+ * Cleans up process structure contents (OS-dependent) and deallocates
+ * it.
*
* @param proc pointer to process structure
*/
GNUNET_free (proc);
}
+
#if WINDOWS
#include "gnunet_signal_lib.h"
*/
#define DWORD_WINAPI DWORD WINAPI
+
/**
* @brief Waits for a process to terminate and invokes the SIGCHLD handler
* @param proc pointer to process structure
fd = open ("/dev/null", flags);
if (-1 == fd)
{
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", "/dev/null");
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ "/dev/null");
return;
}
if (fd == target_fd)
int fd_stdin_read;
int fd_stdin_write;
- if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
+ if (GNUNET_SYSERR ==
+ GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
return NULL; /* not executable */
if (GNUNET_YES == pipe_control)
{
struct GNUNET_DISK_PipeHandle *childpipe;
int dup_childpipe_read_fd = -1;
- childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
+ childpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO,
+ GNUNET_YES, GNUNET_NO);
if (NULL == childpipe)
return NULL;
- childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_READ);
- childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe, GNUNET_DISK_PIPE_END_WRITE);
+ childpipe_read = GNUNET_DISK_pipe_detach_end (childpipe,
+ GNUNET_DISK_PIPE_END_READ);
+ childpipe_write = GNUNET_DISK_pipe_detach_end (childpipe,
+ GNUNET_DISK_PIPE_END_WRITE);
GNUNET_DISK_pipe_close (childpipe);
- if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
- (GNUNET_OK != GNUNET_DISK_internal_file_handle_ (childpipe_read,
- &childpipe_read_fd, sizeof (int))) ||
- (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
+ if ( (NULL == childpipe_read) ||
+ (NULL == childpipe_write) ||
+ (GNUNET_OK !=
+ GNUNET_DISK_internal_file_handle_ (childpipe_read,
+ &childpipe_read_fd,
+ sizeof (int))) ||
+ (-1 == (dup_childpipe_read_fd = dup (childpipe_read_fd))))
{
if (NULL != childpipe_read)
GNUNET_DISK_file_close (childpipe_read);
cmd->rtask = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (GNUNET_YES != GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, cmd->r))
+ if (GNUNET_YES !=
+ GNUNET_NETWORK_fdset_handle_isset (tc->read_ready,
+ cmd->r))
{
- /* timeout, shutdown, etc. */
+ /* timeout */
proc = cmd->proc;
cmd->proc = NULL;
proc (cmd->proc_cls, NULL);
return;
}
- ret =
- GNUNET_DISK_file_read (cmd->r, &cmd->buf[cmd->off],
- sizeof (cmd->buf) - cmd->off);
+ ret = GNUNET_DISK_file_read (cmd->r,
+ &cmd->buf[cmd->off],
+ sizeof (cmd->buf) - cmd->off);
if (ret <= 0)
{
if ((cmd->off > 0) && (cmd->off < sizeof (cmd->buf)))
cmd->off -= (end + 1 - cmd->buf);
end = memchr (cmd->buf, '\n', cmd->off);
}
- cmd->rtask =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
- (cmd->timeout), cmd->r, &cmd_read, cmd);
+ cmd->rtask
+ = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining
+ (cmd->timeout),
+ cmd->r,
+ &cmd_read, cmd);
}
struct GNUNET_DISK_PipeHandle *opipe;
va_list ap;
- opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES,
+ GNUNET_NO, GNUNET_YES);
if (NULL == opipe)
return NULL;
va_start (ap, binary);
/* redirect stdout, don't inherit stderr/stdin */
- eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap);
+ eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL,
+ opipe, NULL, binary,
+ ap);
va_end (ap);
if (NULL == eip)
{
cmd->opipe = opipe;
cmd->proc = proc;
cmd->proc_cls = proc_cls;
- cmd->r = GNUNET_DISK_pipe_handle (opipe, GNUNET_DISK_PIPE_END_READ);
- cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout, cmd->r, &cmd_read, cmd);
+ cmd->r = GNUNET_DISK_pipe_handle (opipe,
+ GNUNET_DISK_PIPE_END_READ);
+ cmd->rtask = GNUNET_SCHEDULER_add_read_file (timeout,
+ cmd->r,
+ &cmd_read,
+ cmd);
return cmd;
}
program_main (void *cls)
{
struct CommandContext *cc = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
GNUNET_SPEEDUP_start_(cc->cfg);
GNUNET_RESOLVER_connect (cc->cfg);
cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg);
GNUNET_RESOLVER_HostnameCallback name_callback;
/**
- * Closure for the respective "callback".
+ * Closure for the callbacks.
*/
void *cls;
* Task handle for making reply callbacks in numeric lookups
* asynchronous, and for timeout handling.
*/
- struct GNUNET_SCHEDULER_Task * task;
+ struct GNUNET_SCHEDULER_Task *task;
/**
* Desired address family.
rh->addr_callback (rh->cls,
(const struct sockaddr *) &v4,
sizeof (v4));
+
break;
default:
GNUNET_break (0);
/* nothing to do, release socket really soon if there is nothing
* else happening... */
s_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&shutdown_task,
NULL);
return;
static void
reconnect_task (void *cls)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
r_task = NULL;
if (NULL == req_head)
return; /* no work pending */
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Trying to connect to DNS service\n");
client = GNUNET_CLIENT_connect ("resolver",
break;
case GNUNET_SYSERR:
/* request was cancelled, remove entirely */
- GNUNET_CONTAINER_DLL_remove (req_head, req_tail, rh);
+ GNUNET_CONTAINER_DLL_remove (req_head,
+ req_tail,
+ rh);
GNUNET_free (rh);
break;
default:
/*
This file is part of GNUnet
- Copyright (C) 2009-2013 GNUnet e.V.
+ Copyright (C) 2009-2016 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
int lifeness;
+ /**
+ * Is this task run on shutdown?
+ */
+ int on_shutdown;
+
/**
* Is this task in the ready list?
*/
*/
static struct GNUNET_SCHEDULER_Task *pending_tail;
+/**
+ * Head of list of tasks waiting for shutdown.
+ */
+static struct GNUNET_SCHEDULER_Task *shutdown_head;
+
+/**
+ * Tail of list of tasks waiting for shutdown.
+ */
+static struct GNUNET_SCHEDULER_Task *shutdown_tail;
+
/**
* List of tasks waiting ONLY for a timeout event.
* Sorted by timeout (earliest first). Used so that
{
enum GNUNET_SCHEDULER_Priority p = check_priority (task->priority);
- if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- p = task->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
GNUNET_CONTAINER_DLL_insert (ready_head[p],
ready_tail[p],
task);
/**
- * Request the shutdown of a scheduler. Marks all currently
- * pending tasks as ready because of shutdown. This will
- * cause all tasks to run (as soon as possible, respecting
- * priorities and prerequisite tasks). Note that tasks
- * scheduled AFTER this call may still be delayed arbitrarily.
- *
- * Note that we don't move the tasks into the ready queue yet;
- * check_ready() will do that later, possibly adding additional
- * readiness-factors
+ * Request the shutdown of a scheduler. Marks all tasks
+ * awaiting shutdown as ready. Note that tasks
+ * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
+ * will be delayed until the next shutdown signal.
*/
void
GNUNET_SCHEDULER_shutdown ()
{
struct GNUNET_SCHEDULER_Task *pos;
- int i;
- for (pos = pending_timeout_head; NULL != pos; pos = pos->next)
- pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- for (pos = pending_head; NULL != pos; pos = pos->next)
+ while (NULL != (pos = shutdown_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (shutdown_head,
+ shutdown_tail,
+ pos);
pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
- for (i = 0; i < GNUNET_SCHEDULER_PRIORITY_COUNT; i++)
- for (pos = ready_head[i]; NULL != pos; pos = pos->next)
- pos->reason |= GNUNET_SCHEDULER_REASON_SHUTDOWN;
+ queue_ready_task (pos);
+ }
}
}
+/**
+ * Output stack trace of task @a t.
+ *
+ * @param t task to dump stack trace of
+ */
+static void
+dump_backtrace (struct GNUNET_SCHEDULER_Task *t)
+{
+#if EXECINFO
+ unsigned int i;
+
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Task %p trace %u: %s\n",
+ t,
+ i,
+ t->backtrace_strings[i]);
+#endif
+}
+
+
/**
* Run at least one task in the highest-priority queue that is not
* empty. Keep running tasks until we are either no longer running
"Running task: %p\n",
pos);
pos->callback (pos->callback_cls);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < pos->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %p trace %u: %s\n",
- pos,
- i,
- pos->backtrace_strings[i]);
-#endif
+ dump_backtrace (pos);
active_task = NULL;
destroy_task (pos);
tasks_run++;
for (t = pending_head; NULL != t; t = t->next)
if (t->lifeness == GNUNET_YES)
return GNUNET_OK;
+ for (t = shutdown_head; NULL != t; t = t->next)
+ if (t->lifeness == GNUNET_YES)
+ return GNUNET_OK;
for (t = pending_timeout_head; NULL != t; t = t->next)
if (t->lifeness == GNUNET_YES)
return GNUNET_OK;
- if ((NULL != pending_head) || (NULL != pending_timeout_head))
+ if (NULL != shutdown_head)
{
GNUNET_SCHEDULER_shutdown ();
return GNUNET_OK;
my_pid = getpid ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Registering signal handlers\n");
- shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown);
- shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown);
+ shc_int = GNUNET_SIGNAL_handler_install (SIGINT,
+ &sighandler_shutdown);
+ shc_term = GNUNET_SIGNAL_handler_install (SIGTERM,
+ &sighandler_shutdown);
#if (SIGTERM != GNUNET_TERM_SIG)
- shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG, &sighandler_shutdown);
+ shc_gterm = GNUNET_SIGNAL_handler_install (GNUNET_TERM_SIG,
+ &sighandler_shutdown);
#endif
#ifndef MINGW
- shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE, &sighandler_pipe);
- shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown);
- shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown);
+ shc_pipe = GNUNET_SIGNAL_handler_install (SIGPIPE,
+ &sighandler_pipe);
+ shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT,
+ &sighandler_shutdown);
+ shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP,
+ &sighandler_shutdown);
#endif
current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
current_lifeness = GNUNET_YES;
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
t->read_fd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ dump_backtrace (t);
}
}
if (-1 != t->write_fd)
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
t->write_fd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ dump_backtrace (t);
}
}
}
enum GNUNET_SCHEDULER_Priority p;
void *ret;
- GNUNET_assert (NULL != active_task);
+ GNUNET_assert ( (NULL != active_task) ||
+ (GNUNET_NO == task->lifeness) );
if (! task->in_ready_list)
{
if ( (-1 == task->read_fd) &&
(NULL == task->read_set) &&
(NULL == task->write_set) )
{
- GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
- pending_timeout_tail,
- task);
+ if (GNUNET_YES == task->on_shutdown)
+ GNUNET_CONTAINER_DLL_remove (shutdown_head,
+ shutdown_tail,
+ task);
+ else
+ GNUNET_CONTAINER_DLL_remove (pending_timeout_head,
+ pending_timeout_tail,
+ task);
if (task == pending_timeout_last)
pending_timeout_last = NULL;
}
}
+/**
+ * Initialize backtrace data for task @a t
+ *
+ * @param t task to initialize
+ */
+static void
+init_backtrace (struct GNUNET_SCHEDULER_Task *t)
+{
+#if EXECINFO
+ void *backtrace_array[MAX_TRACE_DEPTH];
+
+ t->num_backtrace_strings
+ = backtrace (backtrace_array, MAX_TRACE_DEPTH);
+ t->backtrace_strings =
+ backtrace_symbols (backtrace_array,
+ t->num_backtrace_strings);
+ dump_backtrace (t);
+#endif
+}
+
+
/**
* Continue the current execution with the given function. This is
* similar to the other "add" functions except that there is no delay
{
struct GNUNET_SCHEDULER_Task *t;
-#if EXECINFO
- void *backtrace_array[50];
-#endif
-
GNUNET_assert (NULL != task);
GNUNET_assert ((NULL != active_task) ||
(GNUNET_SCHEDULER_REASON_STARTUP == reason));
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, 50);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
t->read_fd = -1;
t->write_fd = -1;
t->callback = task;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding continuation task %p\n",
t);
+ init_backtrace (t);
queue_ready_task (t);
}
* Schedule a new task to be run with a specified delay. The task
* will be scheduled for execution once the delay has expired.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param task main function of the task
* @param task_cls closure of @a task
struct GNUNET_SCHEDULER_Task *pos;
struct GNUNET_SCHEDULER_Task *prev;
-#if EXECINFO
- void *backtrace_array[MAX_TRACE_DEPTH];
-#endif
-
GNUNET_assert (NULL != active_task);
GNUNET_assert (NULL != task);
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
t->callback = task;
t->callback_cls = task_cls;
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
t->read_fd = -1;
t->write_fd = -1;
#if PROFILE_DELAYS
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding task: %p\n",
t);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %p trace %d: %s\n",
- t,
- i,
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
return t;
}
* will be scheduled for execution once the delay has expired. It
* will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param task main function of the task
- * @param task_cls closure of task
+ * @param task_cls closure of @a task
* @return unique task identifier for the job
- * only valid until "task" is started!
+ * only valid until @a task is started!
*/
struct GNUNET_SCHEDULER_Task *
GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
- GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
+ GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls)
{
return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
GNUNET_SCHEDULER_PRIORITY_DEFAULT,
* @param task main function of the task
* @param task_cls closure of @a task
* @return unique task identifier for the job
- * only valid until "task" is started!
+ * only valid until @a task is started!
*/
struct GNUNET_SCHEDULER_Task *
-GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
+GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls)
{
- return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls);
+ return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO,
+ task,
+ task_cls);
+}
+
+
+/**
+ * Schedule a new task to be run on shutdown, that is when a CTRL-C
+ * signal is received, or when #GNUNET_SCHEDULER_shutdown() is being
+ * invoked.
+ *
+ * @param task main function of the task
+ * @param task_cls closure of @a task
+ * @return unique task identifier for the job
+ * only valid until @a task is started!
+ */
+struct GNUNET_SCHEDULER_Task *
+GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls)
+{
+ struct GNUNET_SCHEDULER_Task *t;
+
+ GNUNET_assert (NULL != active_task);
+ GNUNET_assert (NULL != task);
+ t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
+ t->callback = task;
+ t->callback_cls = task_cls;
+ t->read_fd = -1;
+ t->write_fd = -1;
+#if PROFILE_DELAYS
+ t->start_time = GNUNET_TIME_absolute_get ();
+#endif
+ t->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
+ t->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
+ t->on_shutdown = GNUNET_YES;
+ t->lifeness = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (shutdown_head,
+ shutdown_tail,
+ t);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding task: %p\n",
+ t);
+ init_backtrace (t);
+ return t;
}
* (prerequisite-run)
* && (delay-ready
* || any-rs-ready
- * || any-ws-ready
- * || shutdown-active )
+ * || any-ws-ready)
* </code>
*
- * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever",
- * which means that the task will only be run after we receive SIGTERM
+ * @param delay how long should we wait?
* @param priority priority to use
* @param rfd file descriptor we want to read (can be -1)
* @param wfd file descriptors we want to write (can be -1)
{
struct GNUNET_SCHEDULER_Task *t;
-#if EXECINFO
- void *backtrace_array[MAX_TRACE_DEPTH];
-#endif
-
GNUNET_assert (NULL != active_task);
GNUNET_assert (NULL != task);
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
t->callback = task;
t->callback_cls = task_cls;
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
#if DEBUG_FDS
if (-1 != rfd)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
rfd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
GNUNET_assert (0);
}
}
LOG (GNUNET_ERROR_TYPE_ERROR,
"Got invalid file descriptor %d!\n",
wfd);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Trace: %s\n",
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
GNUNET_assert (0);
}
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding task %p\n",
t);
-#if EXECINFO
- unsigned int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task %p trace %d: %s\n",
- t,
- i,
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
return t;
}
#endif
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* either the delay has expired or the socket operation is ready. It
* will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority to use for the task
* @param rfd read file-descriptor
* @param task main function of the task
* socket operation is ready. It will be run with the priority of
* the calling task.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param rfd read file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready. It will be run with the DEFAULT priority.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param wfd write file-descriptor
* @param task main function of the task
* @param task_cls closure of @a task
* scheduled for execution once either the delay has expired or the
* socket operation is ready.
*
- * @param delay when should this operation time out? Use
- * #GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param delay when should this operation time out?
* @param priority priority of the task
* @param fd file-descriptor
* @param on_read whether to poll the file-descriptor for readability
* (prerequisite-run)
* && (delay-ready
* || any-rs-ready
- * || any-ws-ready
- * || (shutdown-active && run-on-shutdown) )
+ * || any-ws-ready) )
* </code>
*
* @param prio how important is this task?
- * @param delay how long should we wait? Use #GNUNET_TIME_UNIT_FOREVER_REL for "forever",
- * which means that the task will only be run after we receive SIGTERM
+ * @param delay how long should we wait?
* @param rs set of file descriptors we want to read (can be NULL)
* @param ws set of file descriptors we want to write (can be NULL)
* @param task main function of the task
void *task_cls)
{
struct GNUNET_SCHEDULER_Task *t;
-#if EXECINFO
- void *backtrace_array[MAX_TRACE_DEPTH];
-#endif
if ( (NULL == rs) &&
(NULL == ws) )
t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
t->callback = task;
t->callback_cls = task_cls;
-#if EXECINFO
- t->num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
- t->backtrace_strings =
- backtrace_symbols (backtrace_array, t->num_backtrace_strings);
-#endif
t->read_fd = -1;
t->write_fd = -1;
if (NULL != rs)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding task %p\n",
t);
-#if EXECINFO
- int i;
-
- for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Task p trace %d: %s\n",
- t,
- i,
- t->backtrace_strings[i]);
-#endif
+ init_backtrace (t);
return t;
}
server->listen_task = NULL;
tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- /* ignore shutdown, someone else will take care of it! */
- GNUNET_SERVER_resume (server);
- return;
- }
for (i = 0; NULL != server->listen_sockets[i]; i++)
{
if (GNUNET_NETWORK_fdset_isset (tc->read_ready,
* @return NULL on error, otherwise the listen socket
*/
static struct GNUNET_NETWORK_Handle *
-open_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
+open_listen_socket (const struct sockaddr *server_addr,
+ socklen_t socklen)
{
struct GNUNET_NETWORK_Handle *sock;
uint16_t port;
if (GNUNET_NO == client->is_monitor)
return; /* not done yet */
server->in_soft_shutdown = GNUNET_SYSERR;
- GNUNET_SCHEDULER_add_now (&do_destroy, server);
+ (void) GNUNET_SCHEDULER_add_now (&do_destroy, server);
}
return; /* nothing to do, no listen sockets! */
if (NULL == server->listen_sockets[1])
{
- /* simplified method: no fd set needed; this is then much simpler and
- much more efficient */
+ /* simplified method: no fd set needed; this is then much simpler
+ and much more efficient */
server->listen_task =
GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_SCHEDULER_PRIORITY_HIGH,
warn_no_receive_done (void *cls)
{
struct GNUNET_SERVER_Client *client = cls;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
client->warn_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
&warn_no_receive_done, client);
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
- (unsigned int) client->warn_type,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start), GNUNET_YES));
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
+ (unsigned int) client->warn_type,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start),
+ GNUNET_YES));
}
sender->warn_start = GNUNET_TIME_absolute_get ();
sender->warn_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
- &warn_no_receive_done, sender);
+ &warn_no_receive_done,
+ sender);
sender->warn_type = type;
}
sender->suspended++;
/**
* Task ID of the shutdown task.
*/
- struct GNUNET_SCHEDULER_Task * shutdown_task;
+ struct GNUNET_SCHEDULER_Task *shutdown_task;
/**
* Idle timeout for server.
{
struct GNUNET_SERVICE_Context *sctx = cls;
unsigned int i;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
(void) GNUNET_SPEEDUP_start_ (sctx->cfg);
GNUNET_RESOLVER_connect (sctx->cfg);
if (NULL != sctx->lsocks)
{
/* install a task that will kill the server
* process if the scheduler ever gets a shutdown signal */
- sctx->shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- sctx);
+ sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ sctx);
}
sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers));
memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers));
* @param buf where the callee should write the message
* @return number of bytes written to @a buf
*/
-
size_t
transmit_ready (void *cls,
size_t size,
* successful operations, including DNS resolution, do not use this. */
if (NULL == buf)
{
- const struct GNUNET_SCHEDULER_TaskContext *tc;
-
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return 0;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) {
- if (0==ih->step)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING,
- "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
- register_sender (ih);
- }
- else
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
- ih->step);
- GNUNET_break (0);
- }
- return 0;
+ if (0 == ih->step)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Timeout contacting SOCKS server, retrying indefinitely, but probably hopeless.\n");
+ register_sender (ih);
+ }
+ else
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Timeout during mid SOCKS handshake (step %u), probably not a SOCKS server.\n",
+ ih->step);
+ GNUNET_break (0);
}
- /* if (reason == 48) register_sender (ih); */
- /* GNUNET_break(0); */
return 0;
}
do_speedup (void *cls)
{
static long long current_offset;
- const struct GNUNET_SCHEDULER_TaskContext *tc;
speedup_task = NULL;
- tc = GNUNET_SCHEDULER_get_task_context ();
- if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
- return;
current_offset += delta.rel_value_us;
GNUNET_TIME_set_offset (current_offset);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Speeding up execution time by %s\n",
GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_NO));
- speedup_task = GNUNET_SCHEDULER_add_delayed (interval, &do_speedup, NULL);
+ speedup_task = GNUNET_SCHEDULER_add_delayed (interval,
+ &do_speedup,
+ NULL);
}
int
GNUNET_SPEEDUP_start_ (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ GNUNET_assert (NULL == speedup_task);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
- "SPEEDUP_INTERVAL", &interval))
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "testing",
+ "SPEEDUP_INTERVAL",
+ &interval))
return GNUNET_SYSERR;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg, "testing",
- "SPEEDUP_DELTA", &delta))
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "testing",
+ "SPEEDUP_DELTA",
+ &delta))
return GNUNET_SYSERR;
- if ((0 == interval.rel_value_us) || (0 == delta.rel_value_us))
+ if ( (0 == interval.rel_value_us) ||
+ (0 == delta.rel_value_us) )
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Speed up disabled\n");
"Speed up executed every %s\n",
GNUNET_STRINGS_relative_time_to_string (interval, GNUNET_NO));
speedup_task = GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
- &do_speedup, NULL);
+ &do_speedup,
+ NULL);
return GNUNET_OK;
}
"Stopped execution speed up\n");
}
-
-
/* end of speedup.c */
FPRINTF (stderr, "got %d bytes, reading more\n", rd);
#endif
read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
+ stdout_read_handle,
+ &read_call,
(void*) stdout_read_handle);
return;
}
die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 10), &end_task,
+ (GNUNET_TIME_UNIT_SECONDS, 10),
+ &end_task,
NULL);
bytes = 0;
memset (&buf, 0, sizeof (buf));
read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
+ stdout_read_handle,
+ &read_call,
(void*) stdout_read_handle);
}
GNUNET_assert (desc != NULL);
if (GNUNET_NETWORK_socket_setsockopt
(desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+ "setsockopt");
GNUNET_assert (GNUNET_OK ==
GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa,
sizeof (sa)));
}
-
static void
-dead_receive (void *cls, const void *buf, size_t available,
- const struct sockaddr *addr, socklen_t addrlen, int errCode)
+dead_receive (void *cls,
+ const void *buf,
+ size_t available,
+ const struct sockaddr *addr,
+ socklen_t addrlen,
+ int errCode)
{
GNUNET_assert (0);
}
GNUNET_CONNECTION_destroy (lsock);
GNUNET_CONNECTION_receive (asock, 1024,
GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, cls);
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ &dead_receive, cls);
}
}
-
static void
task_receive_cancel (void *cls)
{
GNUNET_assert (lsock != NULL);
csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT);
GNUNET_assert (csock != NULL);
- GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls,
- &run_accept_cancel, cls);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &receive_cancel_task,
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ ls,
+ &run_accept_cancel,
+ cls);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &receive_cancel_task,
cls);
}
-
/**
* Main method, starts scheduler with task_timeout.
*/
ok = 1;
cfg = GNUNET_CONFIGURATION_create ();
- GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ "resolver",
+ "HOSTNAME",
"localhost");
GNUNET_SCHEDULER_run (&task_receive_cancel, &ok);
GNUNET_CONFIGURATION_destroy (cfg);
#define TESTSTRING "Hello World\0"
+
static int
testReadWrite ()
{
return 0;
}
+
static int
testOpenClose ()
{
static int ok;
+
static int
scan_callback (void *want, const char *filename)
{
return GNUNET_OK;
}
+
static int
testDirScan ()
{
if (GNUNET_OK !=
GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK !=
GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
+ {
+ GNUNET_break (0);
return 1;
+ }
GNUNET_DISK_directory_scan ("test", &scan_callback,
"test" DIR_SEPARATOR_STR "entry");
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (ok < 2)
+ {
+ GNUNET_break (0);
return 1;
+ }
return 0;
}
+static int
+iter_callback (void *cls,
+ const char *filename)
+{
+ int *i = cls;
+
+ (*i)++;
+ return GNUNET_OK;
+}
+
+
static int
testDirIter ()
{
i = 0;
if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_many"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_create ("test/entry_more"))
+ {
+ GNUNET_break (0);
return 1;
+ }
+ GNUNET_DISK_directory_scan ("test",
+ &iter_callback,
+ &i);
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (i < 3)
+ {
+ GNUNET_break (0);
return 1;
+ }
return 0;
}
testDirMani ()
{
if (GNUNET_OK != GNUNET_DISK_directory_create_for_file ("test/ing"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_NO != GNUNET_DISK_file_test ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_NO != GNUNET_DISK_file_test ("test/ing"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_create ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_YES != GNUNET_DISK_directory_test ("test", GNUNET_YES))
+ {
+ GNUNET_break (0);
return 1;
+ }
if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
+ {
+ GNUNET_break (0);
return 1;
+ }
return 0;
}
failureCount += testCanonicalize ();
failureCount += testChangeOwner ();
failureCount += testDirMani ();
- if (failureCount != 0)
+ if (0 != failureCount)
{
- FPRINTF (stderr, "\n%u TESTS FAILED!\n", failureCount);
+ FPRINTF (stderr,
+ "\n%u TESTS FAILED!\n",
+ failureCount);
return -1;
}
return 0;
const struct GNUNET_DISK_FileHandle *stdout_read_handle;
};
-struct read_context rc;
+
+static struct read_context rc;
+
static void
end_task (void *cls)
{
int bytes;
- bytes = GNUNET_DISK_file_read (rc.stdout_read_handle, &rc.buf[rc.buf_offset], \
- sizeof (rc.buf) - rc.buf_offset);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "bytes is %d\n", bytes);
+ bytes = GNUNET_DISK_file_read (rc.stdout_read_handle,
+ &rc.buf[rc.buf_offset],
+ sizeof (rc.buf) - rc.buf_offset);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "bytes is %d\n",
+ bytes);
if (bytes < 1)
{
GNUNET_break (0);
ok = 1;
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ (void) GNUNET_SCHEDULER_add_now (&end_task, NULL);
return;
}
ok = strncmp (rc.buf, test_phrase, strlen (test_phrase));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "read %s\n", &rc.buf[rc.buf_offset]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "read %s\n",
+ &rc.buf[rc.buf_offset]);
rc.buf_offset += bytes;
if (0 == ok)
{
GNUNET_SCHEDULER_cancel (die_task);
- GNUNET_SCHEDULER_add_now (&end_task, NULL);
+ (void) GNUNET_SCHEDULER_add_now (&end_task, NULL);
return;
}
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- rc.stdout_read_handle, &read_call,
+ rc.stdout_read_handle,
+ &read_call,
NULL);
-
}
die_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MINUTES, 1), &end_task,
+ (GNUNET_TIME_UNIT_MINUTES, 1),
+ &end_task,
NULL);
memset (&rc, 0, sizeof (rc));
rc.stdout_read_handle = stdout_read_handle;
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- stdout_read_handle, &read_call,
+ stdout_read_handle,
+ &read_call,
NULL);
}
fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
proc =
GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR,
- hello_pipe_stdin, hello_pipe_stdout, NULL,
+ hello_pipe_stdin,
+ hello_pipe_stdout,
+ NULL,
fn,
- "gnunet-service-resolver", "-", NULL);
+ "gnunet-service-resolver", "-",
+ NULL);
sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */
GNUNET_free (fn);
if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG))
#include "gnunet_util_lib.h"
-struct GNUNET_DISK_PipeHandle *p;
+static struct GNUNET_DISK_PipeHandle *p;
static const struct GNUNET_DISK_FileHandle *fds[2];
{
int *ok = cls;
- /* t4 should be ready (albeit with lower priority) */
GNUNET_assert (8 == *ok);
(*ok) = 0;
}
GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
(*ok) = 8;
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &taskLast,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&taskLast,
+ cls);
GNUNET_SCHEDULER_shutdown ();
}
GNUNET_assert (NULL != p);
fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[0], &taskRd,
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fds[0],
+ &taskRd,
cls);
- GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, fds[1],
- &taskWrt, cls);
+ GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fds[1],
+ &taskWrt,
+ cls);
}
GNUNET_assert (1 == *ok);
(*ok) = 2;
GNUNET_SCHEDULER_add_now (&task3, cls);
- GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI, &task2,
+ GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_UI,
+ &task2,
cls);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &task4, cls);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &task4,
+ cls);
}
GNUNET_assert (1 == *ok);
*ok = 8;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
+ GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
GNUNET_SCHEDULER_shutdown ();
}
GNUNET_assert (1 == *ok);
*ok = 8;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &taskLast, cls);
- GNUNET_break (0 == PLIBC_KILL (getpid (), GNUNET_TERM_SIG));
+ GNUNET_SCHEDULER_add_shutdown (&taskLast, cls);
+ GNUNET_break (0 == PLIBC_KILL (getpid (),
+ GNUNET_TERM_SIG));
}
GNUNET_assert (1 == *ok);
*ok = 0;
- GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now
- (&taskNeverRun, NULL));
+ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_add_now (&taskNeverRun, NULL));
}
return;
}
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MICROSECONDS, i), &test_task,
+ (GNUNET_TIME_UNIT_MICROSECONDS, i),
+ &test_task,
NULL);
i += INCR;
}
int
main (int argc, char *argv[])
{
- GNUNET_log_setup ("test-scheduler-delay", "WARNING", NULL);
+ GNUNET_log_setup ("test-scheduler-delay",
+ "WARNING",
+ NULL);
target = GNUNET_TIME_absolute_get ();
GNUNET_SCHEDULER_run (&test_task, NULL);
FPRINTF (stdout,
static void
-recv_cb (void *cls, struct GNUNET_SERVER_Client *client,
+recv_cb (void *cls,
+ struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
GNUNET_assert (ok == 2);
static void
-recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient,
+recv_cb (void *cls,
+ struct GNUNET_SERVER_Client *argclient,
const struct GNUNET_MessageHeader *message)
{
switch (ok)
{
case 2:
ok++;
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (GNUNET_TIME_UNIT_MILLISECONDS, 50),
- &send_done, argclient);
+ (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_MILLISECONDS, 50),
+ &send_done,
+ argclient);
break;
case 4:
ok++;
* @param client identification of the client
*/
static void
-notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+notify_disconnect (void *cls,
+ struct GNUNET_SERVER_Client *client)
{
if (client == NULL)
return;
GNUNET_assert (ok == 5);
ok = 0;
- GNUNET_SCHEDULER_add_now (&clean_up, NULL);
+ (void) GNUNET_SCHEDULER_add_now (&clean_up, NULL);
}
fprintf (stderr, "..%u", cycles);
if (cycles <= 5)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &run,
+ NULL);
return;
}
end = GNUNET_TIME_absolute_get();
*
*/
static void
-check (void *cls, char *const *args,
+check (void *cls,
+ char *const *args,
const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *
- cfg)
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
fprintf (stderr, "0");
- fflush(stdout);
- GNUNET_SCHEDULER_add_now(&run, NULL);
+ fflush (stdout);
+ GNUNET_SCHEDULER_add_now (&run, NULL);
}
int
main (int argc, char *argv[])
{
- static char *const argvn[] = { "test-speedup",
+ static char *const argvn[] = {
+ "test-speedup",
"-c", "test_speedup_data.conf",
NULL
};
&message_token, NULL, NULL);
nc = GNUNET_SERVER_notification_context_create (server, 1);
GNUNET_SERVER_add_handlers (server, service_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &cleanup,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&cleanup,
+ NULL);
}
* @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)
{
int dst_af;
struct GNUNET_TIME_Absolute etime;
etime = GNUNET_TIME_relative_to_absolute (duration);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_disconnect, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_disconnect, NULL);
handle = GNUNET_VPN_connect (cfg);
if (NULL == handle)
goto error;