static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (send_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (send_task); send_task = GNUNET_SCHEDULER_NO_TASK; } if (shutdown_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (shutdown_task); shutdown_task = GNUNET_SCHEDULER_NO_TASK; } if (cc != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; } if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; if (blacklist_p1 != NULL) GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1); if (blacklist_p2 != NULL) GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2); if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); if (p2 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); ok = GNUNET_SYSERR; }
/** * Stop tasks that modify clock behavior. */ void GNUNET_SPEEDUP_stop_ () { if (NULL != speedup_task) { GNUNET_SCHEDULER_cancel (speedup_task); speedup_task = NULL; } if ( (0 != interval.rel_value_us) && (0 != delta.rel_value_us) ) LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopped execution speed up\n"); }
static void end () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); if (timer_task != NULL) { GNUNET_SCHEDULER_cancel (timer_task); timer_task = NULL; } if (die_task != NULL) { GNUNET_SCHEDULER_cancel (die_task); die_task = NULL; } if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); if (disconnects == 0) ok = 0; else { ok = disconnects; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Had %u disconnects while waiting %s\n", disconnects, GNUNET_STRINGS_relative_time_to_string (WAIT, GNUNET_YES)); } GNUNET_TRANSPORT_TESTING_done (tth); }
static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { die_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); if (restarted == GNUNET_YES) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was restarted\n"); if (restarted == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer was NOT restarted\n"); if (reconnect_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (reconnect_task); reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (send_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (send_task); send_task = GNUNET_SCHEDULER_NO_TASK; if (cc != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; } if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); if (p2 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); ok = GNUNET_SYSERR; }
/** * Something went wrong and timed out. Kill everything and set error flag */ static void do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { 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, tc); }
/** * Cancel notification upon flush. Should only be used when the flush * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already * called. * * @param h the logger handle */ void GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h) { if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task) { GNUNET_SCHEDULER_cancel (h->flush_completion_task); h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK; } if (GNUNET_SCHEDULER_NO_TASK != h->timeout_flush_task) cancel_timeout_flush (h); h->cb = NULL; h->cb_cls = NULL; }
static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { die_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); if (send_task != NULL) GNUNET_SCHEDULER_cancel (send_task); if (cc != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); cc = NULL; } if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); if (s_started == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were not started \n")); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were started \n")); if (s_connected == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not connected\n")); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were connected\n")); if (s_sending == GNUNET_NO) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were ready to send data\n")); th = NULL; if (p1 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); if (p2 != NULL) GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); ok = GNUNET_SYSERR; }
/** * Ask the connection to call us once the specified number of bytes * are free in the transmission buffer. May call the notify * method immediately if enough space is available. * * @param connection connection * @param size number of bytes to send * @param timeout after how long should we give up (and call * notify with buf NULL and size 0)? * @param notify function to call * @param notify_cls closure for notify * @return non-NULL if the notify callback was queued, * NULL if we are already going to notify someone else (busy) */ struct GNUNET_CONNECTION_TransmitHandle * 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) { if (NULL != connection->nth.notify_ready) { GNUNET_assert (0); return NULL; } GNUNET_assert (NULL != notify); GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); GNUNET_assert (connection->write_buffer_off <= connection->write_buffer_size); GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_off); connection->nth.notify_ready = notify; connection->nth.notify_ready_cls = notify_cls; connection->nth.connection = connection; connection->nth.notify_size = size; connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->nth.timeout_task); if ((NULL == connection->sock) && (NULL == connection->ap_head) && (NULL == connection->dns_active)) { if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) GNUNET_SCHEDULER_cancel (connection->write_task); connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, connection); return &connection->nth; } if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) return &connection->nth; /* previous transmission still in progress */ if (NULL != connection->sock) { /* connected, try to transmit now */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmission (%p).\n", connection); connection->write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout), connection->sock, &transmit_ready, connection); return &connection->nth; } /* not yet connected, wait for connection */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", connection); connection->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); return &connection->nth; }
/** * Function called on result for a GNS lookup * * @param cls closure, unused * @param rd_count number of records * @param rd the records in reply */ static void on_lookup_result(void *cls, uint32_t rd_count, const struct GNUNET_NAMESTORE_RecordData *rd) { struct in_addr a; uint32_t i; char* addr; lr = NULL; if (GNUNET_SCHEDULER_NO_TASK != die_task) { GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_NAMESTORE_disconnect (namestore_handle); namestore_handle = NULL; if (rd_count == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup failed, rp_filtering?\n"); ok = 2; } else { ok = 1; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); for (i=0; i<rd_count; i++) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); if (rd[i].record_type == GNUNET_GNS_RECORD_A) { memcpy (&a, rd[i].data, sizeof(a)); addr = inet_ntoa(a); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); if (0 == strcmp (addr, TEST_IP)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); ok = 0; } } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n"); } } } GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); }
/** * Check if the get_handle is being used, if so stop the request. Either * way, schedule the end_badly_cont function which actually shuts down the * test. */ static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { die_task = GNUNET_SCHEDULER_NO_TASK; int c; if (GNUNET_SCHEDULER_NO_TASK != wait_task) { GNUNET_SCHEDULER_cancel (wait_task); wait_task = GNUNET_SCHEDULER_NO_TASK; } for (c = 0; c < 3; c++) { if (NULL != nh[c]) { GNUNET_NAMESTORE_disconnect(nh[c]); nh[c] = NULL; } if (NULL != get_cfg_ops[c]) { GNUNET_TESTBED_operation_done(get_cfg_ops[c]); get_cfg_ops[c] = NULL; } if (NULL != cfg_handles[c]) { GNUNET_CONFIGURATION_destroy (cfg_handles[c]); cfg_handles[c] = NULL; } } if (NULL != topology_op) { GNUNET_TESTBED_operation_done (topology_op); topology_op = NULL; } if (NULL != lookup_handle) { GNUNET_GNS_cancel_lookup_request (lookup_handle); lookup_handle = NULL; } if (NULL != gh) { GNUNET_GNS_disconnect(gh); gh = NULL; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test failed \n"); GNUNET_SCHEDULER_shutdown (); ok = 1; }
/** * Remove a mapping created with (mini)upnpc. Calling * this function will give 'upnpc' 1s to remove tha mapping, * so while this function is non-blocking, a task will be * left with the scheduler for up to 1s past this call. * * @param mini the handle */ void GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini) { char pstr[6]; if (NULL != mini->refresh_task) { GNUNET_SCHEDULER_cancel (mini->refresh_task); mini->refresh_task = NULL; } if (NULL != mini->refresh_cmd) { GNUNET_OS_command_stop (mini->refresh_cmd); mini->refresh_cmd = NULL; } if (NULL != mini->map_cmd) { GNUNET_OS_command_stop (mini->map_cmd); mini->map_cmd = NULL; } if (GNUNET_NO == mini->did_map) { GNUNET_free (mini); return; } mini->ac (mini->ac_cls, GNUNET_NO, (const struct sockaddr *) &mini->current_addr, sizeof (mini->current_addr), GNUNET_NAT_ERROR_SUCCESS); /* Note: oddly enough, deletion uses the external port whereas * addition uses the internal port; this rarely matters since they * often are the same, but it might... */ GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) ntohs (mini->current_addr.sin_port)); LOG (GNUNET_ERROR_TYPE_DEBUG, "Unmapping port %u with UPnP\n", ntohs (mini->current_addr.sin_port)); mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT, "upnpc", "upnpc", "-d", pstr, mini->is_tcp ? "tcp" : "udp", NULL); }
static void put_cont (void *cls, int32_t success, const char *emsg) { static int c = 0; if (success == GNUNET_OK) { c++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record %u \n", c); } else { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to created records\n"); GNUNET_break (0); GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); } if (c == 3) { res = 1; returned_records = 0; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All records created, starting iteration over all zones \n"); zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, NULL, GNUNET_NAMESTORE_RF_NONE, GNUNET_NAMESTORE_RF_NONE, zone_proc, &zone); if (zi == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create zone iterator\n"); GNUNET_break (0); GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); } } }
static void end () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); if (timeout_task != NULL) GNUNET_SCHEDULER_cancel (timeout_task); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); GNUNET_TRANSPORT_TESTING_done (tth); }
/** * Handle ANNOUNCE message. * * @param cls closure * @param client identification of the client * @param message the actual message */ static void handle_announce (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct AnnounceMessage *am; const char *regex; struct ClientEntry *ce; uint16_t size; size = ntohs (message->size); am = (const struct AnnounceMessage *) message; regex = (const char *) &am[1]; if ( (size <= sizeof (struct AnnounceMessage)) || ('\0' != regex[size - sizeof (struct AnnounceMessage) - 1]) ) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } ce = GNUNET_new (struct ClientEntry); ce->client = client; ce->frequency = GNUNET_TIME_relative_ntoh (am->refresh_delay); ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency, &reannounce, ce); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to announce regex `%s' every %s\n", regex, GNUNET_STRINGS_relative_time_to_string (ce->frequency, GNUNET_NO)); ce->ah = REGEX_INTERNAL_announce (dht, my_private_key, regex, ntohs (am->compression), stats); if (NULL == ce->ah) { GNUNET_break (0); GNUNET_SCHEDULER_cancel (ce->refresh_task); GNUNET_free (ce); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ce); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
static void abort_publish_task (void *cls) { if (NULL != publish) { GNUNET_FS_publish_stop (publish); publish = NULL; } if (NULL != timeout_task) { GNUNET_SCHEDULER_cancel (timeout_task); timeout_task = NULL; } }
static int receive (void *cls, const struct GNUNET_PeerIdentity *other, const struct GNUNET_MessageHeader *message) { if (die_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (die_task); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer %s\n", GNUNET_i2s (other)); GNUNET_assert (GNUNET_MESSAGE_TYPE_DUMMY == ntohs (message->type)); GNUNET_assert (0 == memcmp (other, &myself, sizeof (myself))); GNUNET_SCHEDULER_add_now (&cleanup, NULL); ret = 0; return GNUNET_OK; }
/** * Increment session timeout due to activity */ static void reschedule_session_timeout (struct Session *s) { GNUNET_assert (NULL != s); GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); GNUNET_SCHEDULER_cancel (s->timeout_task); s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, s); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p set to %llu\n", s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); }
/** * Function called to notify transport users that another * peer connected to us. * * @param cls closure * @param peer the peer that connected * @param latency current latency of the connection * @param distance in overlay hops, as given by transport plugin */ static void notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) { if (peer == NULL) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); ok = 0; if (timeout_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (timeout_task); timeout_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_SCHEDULER_add_now (&clean_up, NULL); }
/** * Get an IP address as a string. * * @param sa host address * @param salen length of host address * @param do_resolve use GNUNET_NO to return numeric hostname * @param timeout how long to try resolving * @param callback function to call with hostnames * last callback is NULL when finished * @param cls closure for callback * @return handle that can be used to cancel the request */ struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, int do_resolve, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_HostnameCallback callback, void *cls) { struct GNUNET_RESOLVER_RequestHandle *rh; size_t ip_len; const void *ip; check_config (); switch (sa->sa_family) { case AF_INET: ip_len = sizeof (struct in_addr); ip = &((const struct sockaddr_in*)sa)->sin_addr; break; case AF_INET6: ip_len = sizeof (struct in6_addr); ip = &((const struct sockaddr_in6*)sa)->sin6_addr; break; default: GNUNET_break (0); return NULL; } rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen); rh->name_callback = callback; rh->cls = cls; rh->af = sa->sa_family; rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); memcpy (&rh[1], ip, ip_len); rh->data_len = ip_len; rh->direction = GNUNET_YES; rh->received_response = GNUNET_NO; if (GNUNET_NO == do_resolve) { rh->task = GNUNET_SCHEDULER_add_now (&numeric_reverse, rh); return rh; } GNUNET_CONTAINER_DLL_insert_tail (req_head, req_tail, rh); rh->was_queued = GNUNET_YES; if (s_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (s_task); s_task = GNUNET_SCHEDULER_NO_TASK; } process_requests (); return rh; }
static void end () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); if (send_task != NULL) { GNUNET_SCHEDULER_cancel (send_task); send_task = NULL; } if (die_task != NULL) GNUNET_SCHEDULER_cancel (die_task); if (NULL != th) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; } GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); }
static void abort_sks_search_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (sks_search == NULL) return; GNUNET_FS_search_stop (sks_search); sks_search = NULL; if (ksk_search == NULL) { GNUNET_FS_stop (fs); if (NULL != kill_task) GNUNET_SCHEDULER_cancel (kill_task); } }
/** * Stop logging * * @param l the logging handle */ void GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l) { if (GNUNET_YES!= l->running) return; if (NULL != l->log_task) GNUNET_SCHEDULER_cancel (l->log_task); l->log_task = NULL; l->running = GNUNET_NO; GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Stop logging\n")); }
/** * Function run on CTRL-C or shutdown (i.e. success/timeout/etc.). * Cleans up. */ static void shutdown_task (void *cls) { if (NULL != peer0) { GNUNET_TESTBED_operation_done (peer0); peer0 = NULL; } if (NULL != timeout_tid) { GNUNET_SCHEDULER_cancel (timeout_tid); timeout_tid = NULL; } }
/** * Shut down the DHT subsystem. */ void GCD_shutdown (void) { if (NULL != dht_handle) { GNUNET_DHT_disconnect (dht_handle); dht_handle = NULL; } if (NULL != announce_id_task) { GNUNET_SCHEDULER_cancel (announce_id_task); announce_id_task = NULL; } }
static size_t transmit_ready (void *cls, size_t size, void *buf) { char *cbuf = buf; struct TestMessage hdr; unsigned int ret; p1.nth = NULL; GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); if (buf == NULL) { if ((p1.ch != NULL) && (p1.connect_status == 1)) GNUNET_break (NULL != (p1.nth = GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO, GNUNET_CORE_PRIO_BEST_EFFORT, FAST_TIMEOUT, &p2.id, MESSAGESIZE, &transmit_ready, &p1))); return 0; } GNUNET_assert (tr_n < TOTAL_MSGS); ret = 0; GNUNET_assert (size >= MESSAGESIZE); GNUNET_assert (buf != NULL); cbuf = buf; do { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u of size %u at offset %u\n", tr_n, MESSAGESIZE, ret); hdr.header.size = htons (MESSAGESIZE); hdr.header.type = htons (MTYPE); hdr.num = htonl (tr_n); memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); ret += sizeof (struct TestMessage); memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage)); ret += MESSAGESIZE - sizeof (struct TestMessage); tr_n++; if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) break; /* sometimes pack buffer full, sometimes not */ } while (size - ret >= MESSAGESIZE); GNUNET_SCHEDULER_cancel (err_task); err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); total_bytes_sent += ret; return ret; }
/** * Callback which will be called to after a host registration succeeded or failed * * @param cls the closure * @param emsg the error message; NULL if host registration is successful */ static void host_registration_completion (void *cls, const char *emsg) { reg_handle = NULL; if (NULL != emsg) { LOG (GNUNET_ERROR_TYPE_WARNING, _("Host registration failed for a host. Error: %s\n"), emsg); GNUNET_SCHEDULER_cancel (abort_task); abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); return; } register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL); }
static void abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (NULL != publish) { GNUNET_FS_publish_stop (publish); publish = NULL; } if (NULL != timeout_task) { GNUNET_SCHEDULER_cancel (timeout_task); timeout_task = NULL; } }
/** * We are done with everything. Stop remaining * tasks, signal handler and the server. */ static void do_shutdown () { if (NULL != server) { GNUNET_SERVER_destroy (server); server = NULL; } if (GNUNET_SCHEDULER_NO_TASK != child_death_task) { GNUNET_SCHEDULER_cancel (child_death_task); child_death_task = GNUNET_SCHEDULER_NO_TASK; } }
static void finish_testing () { GNUNET_assert (pg != NULL); if (die_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (die_task); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called finish testing, stopping daemons.\n"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling daemons_stop\n"); GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "daemons_stop finished\n"); ok = 0; }
/** * Task run on shutdown to terminate. Triggers printing out * all statistics. * * @param cls NULL */ static void terminate_task (void *cls) { if (NULL != terminate_taskid) { GNUNET_SCHEDULER_cancel (terminate_taskid); terminate_taskid = NULL; } GNUNET_TESTBED_get_statistics (0, NULL, NULL, NULL, &process_stats, &shutdown_task, NULL); }