/** * PEERINFO calls this function to let us know about a possible peer * that we might want to connect to. * * @param cls closure (not used) * @param peer potential peer to connect to * @param hello HELLO for this peer (or NULL) * @param err_msg NULL if successful, otherwise contains error message */ static void process_peer (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg) { struct Peer *pos; if (err_msg != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Error in communication with PEERINFO service: %s\n"), err_msg); GNUNET_PEERINFO_notify_cancel (peerinfo_notify); peerinfo_notify = GNUNET_PEERINFO_notify (cfg, &process_peer, NULL); return; } GNUNET_assert (peer != NULL); if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; /* that's me! */ if (hello == NULL) { /* free existing HELLO, if any */ pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); if (NULL != pos) { GNUNET_free_non_null (pos->hello); pos->hello = NULL; if (pos->filter != NULL) { GNUNET_CONTAINER_bloomfilter_free (pos->filter); pos->filter = NULL; } if ((GNUNET_NO == pos->is_connected) && (GNUNET_NO == pos->is_friend) && (0 == GNUNET_TIME_absolute_get_remaining (pos-> greylisted_until).rel_value)) free_peer (NULL, &pos->pid.hashPubKey, pos); } return; } consider_for_advertising (hello); pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); if (pos == NULL) pos = make_peer (peer, hello, GNUNET_NO); GNUNET_assert (NULL != pos); if (GNUNET_YES == pos->is_connected) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already connected to peer `%s'\n", GNUNET_i2s (peer)); return; } if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already tried peer `%s' recently\n", GNUNET_i2s (peer)); return; /* peer still greylisted */ } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Considering connecting to peer `%s'\n", GNUNET_i2s (peer)); schedule_attempt_connect (pos); }
/** * Last task run during shutdown. Disconnects us from * the transport and core. * * @param cls unused, NULL * @param tc scheduler context */ static void cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (NULL != peerinfo_notify) { GNUNET_PEERINFO_notify_cancel (peerinfo_notify); peerinfo_notify = NULL; } GNUNET_TRANSPORT_disconnect (transport); transport = NULL; if (handle != NULL) { GNUNET_CORE_disconnect (handle); handle = NULL; } whitelist_peers (); if (GNUNET_SCHEDULER_NO_TASK != add_task) { GNUNET_SCHEDULER_cancel (add_task); add_task = GNUNET_SCHEDULER_NO_TASK; } GNUNET_CONTAINER_multihashmap_iterate (peers, &free_peer, NULL); GNUNET_CONTAINER_multihashmap_destroy (peers); peers = NULL; if (stats != NULL) { GNUNET_STATISTICS_destroy (stats, GNUNET_NO); stats = NULL; } }
/** * PEERINFO calls this function to let us know about a possible peer * that we might want to connect to. * * @param cls closure (not used) * @param peer potential peer to connect to * @param hello HELLO for this peer (or NULL) * @param err_msg NULL if successful, otherwise contains error message */ static void process_peer (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg) { struct Peer *pos; if (NULL != err_msg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Error in communication with PEERINFO service: %s\n"), err_msg); GNUNET_PEERINFO_notify_cancel (peerinfo_notify); peerinfo_notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL); return; } GNUNET_assert (NULL != peer); if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; /* that's me! */ if (NULL == hello) { /* free existing HELLO, if any */ pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); if (NULL != pos) { GNUNET_free_non_null (pos->hello); pos->hello = NULL; if (NULL != pos->filter) { GNUNET_CONTAINER_bloomfilter_free (pos->filter); pos->filter = NULL; } if ( (NULL == pos->mq) && (GNUNET_NO == pos->is_friend) ) free_peer (NULL, &pos->pid, pos); } return; } consider_for_advertising (hello); pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); if (NULL == pos) pos = make_peer (peer, hello, GNUNET_NO); attempt_connect (pos); }
static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { timeout_task = NULL; GNUNET_break(0); if (NULL != pnc_wo_fo) { GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); pnc_wo_fo = NULL; } if (NULL != pnc_w_fo) { GNUNET_PEERINFO_notify_cancel (pnc_w_fo); pnc_w_fo = NULL; } if (NULL != h) { GNUNET_PEERINFO_disconnect (h); h = NULL; } global_ret = 255; }
static void done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (NULL != pnc_w_fo) GNUNET_PEERINFO_notify_cancel (pnc_w_fo); pnc_w_fo = NULL; if (NULL != pnc_wo_fo) GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); pnc_wo_fo = NULL; GNUNET_PEERINFO_disconnect (h); h = NULL; if (NULL != timeout_task) { GNUNET_SCHEDULER_cancel (timeout_task); timeout_task = NULL; } if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) global_ret = 0; else GNUNET_break(0); }
/** * Stop the validation subsystem. */ void GST_validation_stop () { struct CheckHelloValidatedContext *chvc; GNUNET_CONTAINER_multihashmap_iterate (validation_map, &cleanup_validation_entry, NULL); GNUNET_CONTAINER_multihashmap_destroy (validation_map); validation_map = NULL; while (NULL != (chvc = chvc_head)) { GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc); GNUNET_free (chvc); } GNUNET_PEERINFO_notify_cancel (pnc); }
/** * Last task run during shutdown. Disconnects us from * the transport and core. * * @param cls unused, NULL */ static void cleaning_task (void *cls) { if (NULL != peerinfo_notify) { GNUNET_PEERINFO_notify_cancel (peerinfo_notify); peerinfo_notify = NULL; } if (NULL != handle) { GNUNET_CORE_disconnect (handle); handle = NULL; } whitelist_peers (); if (NULL != add_task) { GNUNET_SCHEDULER_cancel (add_task); add_task = NULL; } if (NULL != oh) { GNUNET_TRANSPORT_offer_hello_cancel (oh); oh = NULL; } GNUNET_CONTAINER_multipeermap_iterate (peers, &free_peer, NULL); GNUNET_CONTAINER_multipeermap_destroy (peers); peers = NULL; if (NULL != ats) { GNUNET_ATS_connectivity_done (ats); ats = NULL; } if (NULL != stats) { GNUNET_STATISTICS_destroy (stats, GNUNET_NO); stats = NULL; } }
/** * Stop server offering our hostlist. */ void GNUNET_HOSTLIST_server_stop () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); if (NULL != hostlist_task_v6) { GNUNET_SCHEDULER_cancel (hostlist_task_v6); hostlist_task_v6 = NULL; } if (NULL != hostlist_task_v4) { GNUNET_SCHEDULER_cancel (hostlist_task_v4); hostlist_task_v4 = NULL; } if (NULL != daemon_handle_v4) { MHD_stop_daemon (daemon_handle_v4); daemon_handle_v4 = NULL; } if (NULL != daemon_handle_v6) { MHD_stop_daemon (daemon_handle_v6); daemon_handle_v6 = NULL; } if (NULL != response) { MHD_destroy_response (response); response = NULL; } if (NULL != notify) { GNUNET_PEERINFO_notify_cancel (notify); notify = NULL; } if (NULL != builder) { if (NULL != builder->pitr) { GNUNET_PEERINFO_iterate_cancel (builder->pitr); builder->pitr = NULL; } GNUNET_free_non_null (builder->data); GNUNET_free (builder); builder = NULL; } if (NULL != peerinfo) { GNUNET_PEERINFO_disconnect (peerinfo); peerinfo = NULL; } if (NULL != advertisements) { GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (advertisements)); GNUNET_CONTAINER_multipeermap_destroy (advertisements); advertisements = NULL; } cfg = NULL; stats = NULL; core = NULL; }