/** * Implementation function that cancels the currently sent message. * * @param mq message queue * @param impl_state state specific to the implementation */ static void core_mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct CoreMQState *mqs = impl_state; GNUNET_assert (NULL != mqs->th); GNUNET_CORE_notify_transmit_ready_cancel (mqs->th); }
void GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg) { GNUNET_CONTAINER_DLL_remove (tg_head, tg_tail, tg); tg->dest->tg = NULL; if (GNUNET_SCHEDULER_NO_TASK != tg->send_task) { GNUNET_SCHEDULER_cancel (tg->send_task); tg->send_task = GNUNET_SCHEDULER_NO_TASK; } if (top->test_core) { if (NULL != tg->dest->cth) { GNUNET_CORE_notify_transmit_ready_cancel (tg->dest->cth); tg->dest->cth = NULL; } } else { if (NULL != tg->dest->tth) { GNUNET_TRANSPORT_notify_transmit_ready_cancel (tg->dest->tth); tg->dest->tth = NULL; } } GNUNET_free (tg); }
static void terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_CORE_Handle *ch; err_task = GNUNET_SCHEDULER_NO_TASK; GNUNET_STATISTICS_destroy (p1.stats, GNUNET_NO); GNUNET_STATISTICS_destroy (p2.stats, GNUNET_NO); GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); if (p1.nth != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (p1.nth); p1.nth = NULL; } if (connect_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (connect_task); connect_task = GNUNET_SCHEDULER_NO_TASK; } ch = p1.ch; p1.ch = NULL; GNUNET_CORE_disconnect (ch); ch = p2.ch; p2.ch = NULL; GNUNET_CORE_disconnect (ch); GNUNET_TRANSPORT_disconnect (p1.th); p1.th = NULL; GNUNET_TRANSPORT_disconnect (p2.th); p2.th = NULL; GNUNET_free_non_null (p1.hello); GNUNET_free_non_null (p2.hello); }
/** * Clean up node * * @param cls the peermap to clean up * @param key key of the current node * @param value related node object * @return always #GNUNET_OK */ static int cleanup_node (void *cls, const struct GNUNET_PeerIdentity * key, void *value) { struct Node *n; struct NodeComCtx *e_cur; struct NodeComCtx *e_next; struct GNUNET_CONTAINER_MultiPeerMap *cur = cls; n = value; if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) { GNUNET_SCHEDULER_cancel (n->timeout_task); n->timeout_task = GNUNET_SCHEDULER_NO_TASK; } if (NULL != n->cth) { GNUNET_CORE_notify_transmit_ready_cancel (n->cth); n->cth = NULL; } e_next = n->e_req_head; while (NULL != (e_cur = e_next)) { e_next = e_cur->next; GNUNET_CONTAINER_DLL_remove (n->e_req_head, n->e_req_tail, e_cur); GNUNET_free (e_cur); } GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_remove (cur, key, value)); GNUNET_free (value); return GNUNET_OK; }
/** * Signature of functions implementing the * destruction of a message queue. * Implementations must not free @a mq, but should * take care of @a impl_state. * * @param mq the message queue to destroy * @param impl_state state of the implementation */ static void core_mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct CoreMQState *mqs = impl_state; if (NULL != mqs->th) { GNUNET_CORE_notify_transmit_ready_cancel (mqs->th); mqs->th = NULL; } GNUNET_free (mqs); }
/** * Method called whenever a peer disconnects. * * @param cls closure * @param peer peer identity this notification is about */ static void disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) { struct Peer *pos; if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core told us that we disconnected from `%s'\n", GNUNET_i2s (peer)); pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); if (NULL == pos) { GNUNET_break (0); return; } if (pos->is_connected != GNUNET_YES) { GNUNET_break (0); return; } pos->is_connected = GNUNET_NO; connection_count--; if (NULL != pos->hello_req) { GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); pos->hello_req = NULL; } if (GNUNET_SCHEDULER_NO_TASK != pos->hello_delay_task) { GNUNET_SCHEDULER_cancel (pos->hello_delay_task); pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"), connection_count, GNUNET_NO); if (pos->is_friend) { friend_count--; GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"), friend_count, GNUNET_NO); } if (((connection_count < target_connection_count) || (friend_count < minimum_friend_count)) && (GNUNET_SCHEDULER_NO_TASK == add_task)) add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL); if ((friend_count < minimum_friend_count) && (blacklist == NULL)) blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); }
/** * Method called whenever a given peer disconnects. * * @param cls closure * @param peer peer identity this notification is about */ static void disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer) { struct GNUNET_CORE_TransmitHandle *th; if (! advertising) return; th = GNUNET_CONTAINER_multipeermap_get (advertisements, peer); if (NULL == th) return; GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (advertisements, peer, th)); GNUNET_CORE_notify_transmit_ready_cancel (th); }
static void terminate_peer (struct PeerContext *p) { if (p->nth != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (p->nth); p->nth = NULL; } if (NULL != p->ch) { GNUNET_CORE_disconnect (p->ch); p->ch = NULL; } if (NULL != p->th) { GNUNET_TRANSPORT_get_hello_cancel (p->ghh); GNUNET_TRANSPORT_disconnect (p->th); p->th = NULL; } if (NULL != p->ats_sh) { GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); p->ats_sh = NULL; } if (NULL != p->ats) { GNUNET_ATS_connectivity_done (p->ats); p->ats = NULL; } if (NULL != p->stats) { GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO); p->stats = NULL; } if (NULL != p->hello) { GNUNET_free (p->hello); p->hello = NULL; } }
/** * Free all resources associated with the given peer. * * @param cls closure (not used) * @param pid identity of the peer * @param value peer to free * @return GNUNET_YES (always: continue to iterate) */ static int free_peer (void *cls, const struct GNUNET_HashCode * pid, void *value) { struct Peer *pos = value; GNUNET_break (GNUNET_NO == pos->is_connected); GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (peers, pid, pos)); if (pos->hello_req != NULL) GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (pos->hello_delay_task); if (pos->attempt_connect_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (pos->attempt_connect_task); if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); GNUNET_free_non_null (pos->hello); if (pos->filter != NULL) GNUNET_CONTAINER_bloomfilter_free (pos->filter); GNUNET_free (pos); return GNUNET_YES; }
static void disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *pc = cls; if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) return; /* loopback */ pc->connect_status = 0; if (NULL != measure_task) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Measurement aborted due to disconnect!\n"); GNUNET_SCHEDULER_cancel (measure_task); measure_task = NULL; } if (pc->nth != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (pc->nth); pc->nth = NULL; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); }
static void terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { err_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase failed!\n"); //GNUNET_break (0); if (p1.nth != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (p1.nth); p1.nth = NULL; } if (measure_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (measure_task); if (connect_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (connect_task); connect_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); if (NULL != p1.ch) GNUNET_CORE_disconnect (p1.ch); p1.ch = NULL; if (NULL != p2.ch) GNUNET_CORE_disconnect (p2.ch); p2.ch = NULL; if (NULL != p1.th) GNUNET_TRANSPORT_disconnect (p1.th); p1.th = NULL; if (NULL != p2.th) GNUNET_TRANSPORT_disconnect (p2.th); p2.th = NULL; ok = 42; }
/** * Cancel existing requests for sending HELLOs to this peer * and recalculate when we should send HELLOs to it based * on our current state (something changed!). * * @param cls closure, 'struct Peer' to skip, or NULL * @param pid identity of a peer * @param value 'struct Peer*' for the peer * @return GNUNET_YES (always) */ static int reschedule_hellos (void *cls, const struct GNUNET_HashCode * pid, void *value) { struct Peer *peer = value; struct Peer *skip = cls; if (skip == peer) return GNUNET_YES; if (!peer->is_connected) return GNUNET_YES; if (peer->hello_req != NULL) { GNUNET_CORE_notify_transmit_ready_cancel (peer->hello_req); peer->hello_req = NULL; } if (peer->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (peer->hello_delay_task); peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; } peer->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); return GNUNET_YES; }