/** * Assuming all peers have been destroyed cleanup run handle * * @param rc the run context */ static void cleanup (struct GNUNET_TESTBED_RunHandle *rc) { unsigned int hid; GNUNET_assert (NULL == rc->register_hosts_task); GNUNET_assert (NULL == rc->reg_handle); GNUNET_assert (NULL == rc->peers); GNUNET_assert (NULL == rc->hclist); GNUNET_assert (RC_PEERS_SHUTDOWN == rc->state); GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap32_size (rc->rcop_map)); GNUNET_CONTAINER_multihashmap32_destroy (rc->rcop_map); if (NULL != rc->c) GNUNET_TESTBED_controller_disconnect (rc->c); if (NULL != rc->cproc) GNUNET_TESTBED_controller_stop (rc->cproc); if (NULL != rc->h) GNUNET_TESTBED_host_destroy (rc->h); for (hid = 0; hid < rc->num_hosts; hid++) GNUNET_TESTBED_host_destroy (rc->hosts[hid]); GNUNET_free_non_null (rc->hosts); if (NULL != rc->cfg) GNUNET_CONFIGURATION_destroy (rc->cfg); GNUNET_free_non_null (rc->topo_file); GNUNET_free_non_null (rc->trusted_ip); GNUNET_free (rc); }
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); }
void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { unsigned int ca; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n"); if (NULL != mlp) { GAS_mlp_done (mlp); mlp = NULL; } if (NULL != a) { for (ca=0; ca < (peers * addresses); ca++) { GNUNET_free (a[ca].plugin); GNUNET_free (a[ca].ats); } } if (NULL != amap) GNUNET_CONTAINER_multihashmap_destroy(amap); GNUNET_free_non_null (a); GNUNET_free_non_null (p); }
static void end () { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); if (die_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_NO_TASK; } if (NULL != atsh) GNUNET_ATS_scheduling_done (atsh); if (phal != NULL) GNUNET_ATS_performance_list_addresses_cancel (phal); phal = NULL; if (ph != NULL) GNUNET_ATS_performance_done (ph); ph = NULL; GNUNET_free_non_null (p0_addresses[0].addr); GNUNET_free_non_null (p0_addresses[1].addr); GNUNET_free_non_null (p1_addresses[0].addr); GNUNET_free_non_null (p1_addresses[1].addr); ret = 0; }
/** * Free the given DNS record. * * @param r record to free */ void GNUNET_DNSPARSER_free_record (struct GNUNET_DNSPARSER_Record *r) { GNUNET_free_non_null (r->name); switch (r->type) { case GNUNET_DNSPARSER_TYPE_MX: GNUNET_DNSPARSER_free_mx (r->data.mx); break; case GNUNET_DNSPARSER_TYPE_SOA: GNUNET_DNSPARSER_free_soa (r->data.soa); break; case GNUNET_DNSPARSER_TYPE_SRV: GNUNET_DNSPARSER_free_srv (r->data.srv); break; case GNUNET_DNSPARSER_TYPE_CERT: GNUNET_DNSPARSER_free_cert (r->data.cert); break; case GNUNET_DNSPARSER_TYPE_NS: case GNUNET_DNSPARSER_TYPE_CNAME: case GNUNET_DNSPARSER_TYPE_PTR: GNUNET_free_non_null (r->data.hostname); break; default: GNUNET_free_non_null (r->data.raw.data); break; } }
/** * Try connecting to the server using UNIX domain sockets. * * @param service_name name of service to connect to * @param cfg configuration to use * @return GNUNET_OK if the configuration is valid, GNUNET_SYSERR if not */ static int test_service_configuration (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg) { int ret = GNUNET_SYSERR; char *hostname = NULL; unsigned long long port; #if AF_UNIX char *unixpath = NULL; if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "UNIXPATH", &unixpath)) && (0 < strlen (unixpath))) ret = GNUNET_OK; GNUNET_free_non_null (unixpath); #endif if ( (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port)) && (port <= 65535) && (0 != port) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME", &hostname)) && (0 != strlen (hostname)) ) ret = GNUNET_OK; GNUNET_free_non_null (hostname); return ret; }
/** * Function called when get_statistics operation is cancelled or marked as done * * @param cls the GetStatsContext */ static void oprelease_get_stats (void *cls) { struct GetStatsContext *sc = cls; unsigned int peer; LOG_DEBUG ("Cleaning up get_statistics operation\n"); if (NULL != sc->call_completion_task_id) GNUNET_SCHEDULER_cancel (sc->call_completion_task_id); if (NULL != sc->ops) { for (peer = 0; peer < sc->num_peers; peer++) { if (NULL != sc->ops[peer]) { GNUNET_TESTBED_operation_done (sc->ops[peer]); sc->ops[peer] = NULL; } } GNUNET_free (sc->ops); } GNUNET_free_non_null (sc->subsystem); GNUNET_free_non_null (sc->name); GNUNET_free (sc); if (GNUNET_YES == GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue)) no_wait_queue = NULL; }
/** * Add a host to the list and notify clients about this event * * @param identity the identity of the host * @return the HostEntry */ static struct HostEntry * add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) { struct HostEntry *entry; struct ReadHostFileContext r; char *fn; entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity); if (NULL == entry) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding new peer `%s'\n", GNUNET_i2s (identity)); GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, GNUNET_NO); entry = GNUNET_new (struct HostEntry); entry->identity = *identity; GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put (hostmap, &entry->identity, entry, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); notify_all (entry); fn = get_host_filename (identity); if (NULL != fn) { read_host_file (fn, GNUNET_YES, &r); if (NULL != r.hello) update_hello (identity, r.hello); if (NULL != r.friend_only_hello) update_hello (identity, r.friend_only_hello); GNUNET_free_non_null (r.hello); GNUNET_free_non_null (r.friend_only_hello); GNUNET_free (fn); } }
/** * Send shorten response back to client * * @param cls the closure containing a client shorten handle * @param name the shortened name result or NULL if cannot be shortened */ static void send_shorten_response(void* cls, const char* name) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n", "SHORTEN_RESULT", name); struct GNUNET_GNS_ClientShortenResultMessage *rmsg; struct ClientShortenHandle *csh = (struct ClientShortenHandle *)cls; if (name == NULL) { name = ""; } rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + strlen(name) + 1); rmsg->id = csh->unique_id; rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT); rmsg->header.size = htons(sizeof(struct GNUNET_GNS_ClientShortenResultMessage) + strlen(name) + 1); strcpy((char*)&rmsg[1], name); GNUNET_SERVER_notification_context_unicast (nc, csh->client, (const struct GNUNET_MessageHeader *) rmsg, GNUNET_NO); GNUNET_SERVER_receive_done (csh->client, GNUNET_OK); GNUNET_free(rmsg); GNUNET_free_non_null(csh->name); GNUNET_free_non_null(csh->zone_key); GNUNET_free(csh); }
static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct SysmonProperty *sp; struct SysmonProperty *next; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sysdaemon stopping ... \n"); end_task = GNUNET_SCHEDULER_NO_TASK; if (NULL != stats) { GNUNET_STATISTICS_destroy (stats, GNUNET_YES); stats = NULL; } next = sp_head; while (NULL != (sp = next)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping `%s' \n", sp->desc); GNUNET_CONTAINER_DLL_remove (sp_head, sp_tail, sp); next = sp->next; if (GNUNET_SCHEDULER_NO_TASK != sp->task_id) { GNUNET_SCHEDULER_cancel (sp->task_id); sp->task_id = GNUNET_SCHEDULER_NO_TASK; } GNUNET_free_non_null (sp->cmd); GNUNET_free_non_null (sp->cmd_args); GNUNET_free (sp->desc); GNUNET_free (sp); } }
/** * The main function. * * @param argc number of arguments from the command line * @param argv command line arguments * @return 0 ok, 1 on error */ int main (int argc, char *const *argv) { int res; resolve_addresses_numeric = GNUNET_NO; op_monitor = GNUNET_NO; op_list_all = GNUNET_NO; op_list_used = GNUNET_NO; op_set_pref = GNUNET_NO; pending = 0; receive_done = GNUNET_NO; static const struct GNUNET_GETOPT_CommandLineOption options[] = { {'u', "used", NULL, gettext_noop ("get list of active addresses currently used"), 0, &GNUNET_GETOPT_set_one, &op_list_used}, {'a', "all", NULL, gettext_noop ("get list of all active addresses"), 0, &GNUNET_GETOPT_set_one, &op_list_all}, {'n', "numeric", NULL, gettext_noop ("do not resolve IP addresses to hostnames"), 0, &GNUNET_GETOPT_set_one, &resolve_addresses_numeric}, {'m', "monitor", NULL, gettext_noop ("monitor mode"), 0, &GNUNET_GETOPT_set_one, &op_monitor}, {'p', "preference", NULL, gettext_noop ("set preference for the given peer"), 0, &GNUNET_GETOPT_set_one, &op_set_pref}, {'i', "id", "TYPE", gettext_noop ("peer id"), 1, &GNUNET_GETOPT_set_string, &pid_str}, {'t', "type", "TYPE", gettext_noop ("preference type to set: latency | bandwidth"), 1, &GNUNET_GETOPT_set_string, &type_str}, {'k', "value", "VALUE", gettext_noop ("preference value"), 1, &GNUNET_GETOPT_set_uint, &value}, {'V', "verbose", NULL, gettext_noop ("verbose output (include ATS address properties)"), 0, &GNUNET_GETOPT_set_one, &verbose}, GNUNET_GETOPT_OPTION_END }; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", gettext_noop ("Print information about ATS state"), options, &run, NULL); GNUNET_free_non_null (pid_str); GNUNET_free_non_null (type_str); GNUNET_free ((void *) argv); if (GNUNET_OK == res) return ret; else return 1; }
/** * Destroy publish-structure. Clients should never destroy publish * structures that were passed to #GNUNET_FS_publish_start already. * * @param fi structure to destroy * @param cleaner function to call on each entry in the structure * (useful to clean up client_info); can be NULL; return * values are ignored * @param cleaner_cls closure for @a cleaner */ void GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, GNUNET_FS_FileInformationProcessor cleaner, void *cleaner_cls) { struct GNUNET_FS_FileInformation *pos; int no; no = GNUNET_NO; if (GNUNET_YES == fi->is_directory) { /* clean up directory */ while (NULL != (pos = fi->data.dir.entries)) { fi->data.dir.entries = pos->next; GNUNET_FS_file_information_destroy (pos, cleaner, cleaner_cls); } /* clean up client-info */ if (NULL != cleaner) cleaner (cleaner_cls, fi, fi->data.dir.dir_size, fi->meta, &fi->keywords, &fi->bo, &no, &fi->client_info); GNUNET_free_non_null (fi->data.dir.dir_data); } else { /* call clean-up function of the reader */ if (NULL != fi->data.file.reader) { (void) fi->data.file.reader (fi->data.file.reader_cls, 0, 0, NULL, NULL); fi->data.file.reader = NULL; } /* clean up client-info */ if (NULL != cleaner) cleaner (cleaner_cls, fi, fi->data.file.file_size, fi->meta, &fi->keywords, &fi->bo, &fi->data.file.do_index, &fi->client_info); } GNUNET_free_non_null (fi->filename); GNUNET_free_non_null (fi->emsg); if (NULL != fi->sks_uri) GNUNET_FS_uri_destroy (fi->sks_uri); if (NULL != fi->chk_uri) GNUNET_FS_uri_destroy (fi->chk_uri); /* clean up serialization */ if ((NULL != fi->serialization) && (0 != UNLINK (fi->serialization))) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fi->serialization); if (NULL != fi->keywords) GNUNET_FS_uri_destroy (fi->keywords); if (NULL != fi->meta) GNUNET_CONTAINER_meta_data_destroy (fi->meta); GNUNET_free_non_null (fi->serialization); if (NULL != fi->te) { GNUNET_FS_tree_encoder_finish (fi->te, NULL); fi->te = NULL; } GNUNET_free (fi); }
/** * Free meta data item. * * @param item item to free */ static void meta_item_free (struct MetaItem *item) { GNUNET_free_non_null (item->plugin_name); GNUNET_free_non_null (item->mime_type); GNUNET_free_non_null (item->data); GNUNET_free (item); }
/** * Create SUSPEND event for the given unindex operation * and then clean up our state (without stop signal). * * @param cls the `struct GNUNET_FS_UnindexContext` to signal for */ void GNUNET_FS_unindex_signal_suspend_ (void *cls) { struct GNUNET_FS_UnindexContext *uc = cls; struct GNUNET_FS_ProgressInfo pi; /* FIXME: lots of duplication with unindex_stop here! */ if (uc->dscan != NULL) { GNUNET_FS_directory_scan_abort (uc->dscan); uc->dscan = NULL; } if (NULL != uc->dqe) { GNUNET_DATASTORE_cancel (uc->dqe); uc->dqe = NULL; } if (uc->fhc != NULL) { GNUNET_CRYPTO_hash_file_cancel (uc->fhc); uc->fhc = NULL; } if (NULL != uc->ksk_uri) { GNUNET_FS_uri_destroy (uc->ksk_uri); uc->ksk_uri = NULL; } if (uc->client != NULL) { GNUNET_CLIENT_disconnect (uc->client); uc->client = NULL; } if (NULL != uc->dsh) { GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); uc->dsh = NULL; } if (NULL != uc->tc) { GNUNET_FS_tree_encoder_finish (uc->tc, NULL); uc->tc = NULL; } if (uc->fh != NULL) { GNUNET_DISK_file_close (uc->fh); uc->fh = NULL; } GNUNET_FS_end_top (uc->h, uc->top); pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; GNUNET_FS_unindex_make_status_ (&pi, uc, (uc->state == UNINDEX_STATE_COMPLETE) ? uc->file_size : 0); GNUNET_break (NULL == uc->client_info); GNUNET_free (uc->filename); GNUNET_free_non_null (uc->serialization); GNUNET_free_non_null (uc->emsg); GNUNET_free (uc); }
/** * Close the connection and free associated resources. There must * not be any pending requests for reading or writing to the * connection at this time. * * @param connection connection to destroy */ void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) { struct AddressProbe *pos; LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); GNUNET_assert (NULL == connection->nth.notify_ready); GNUNET_assert (NULL == connection->receiver); if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) { GNUNET_SCHEDULER_cancel (connection->write_task); connection->write_task = GNUNET_SCHEDULER_NO_TASK; connection->write_buffer_off = 0; } if (GNUNET_SCHEDULER_NO_TASK != connection->read_task) { GNUNET_SCHEDULER_cancel (connection->read_task); connection->read_task = GNUNET_SCHEDULER_NO_TASK; } if (GNUNET_SCHEDULER_NO_TASK != connection->nth.timeout_task) { GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; } connection->nth.notify_ready = NULL; if (NULL != connection->dns_active) { GNUNET_RESOLVER_request_cancel (connection->dns_active); connection->dns_active = NULL; } while (NULL != (pos = connection->ap_head)) { 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_free (pos); } if ( (NULL != connection->sock) && (GNUNET_YES != connection->persist) ) { if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && (ENOTCONN != errno) && (ECONNRESET != errno) ) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); } if (NULL != connection->sock) { if (GNUNET_YES != connection->persist) GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); else GNUNET_free (connection->sock); /* at least no memory leak (we deliberately * leak the socket in this special case) ... */ } GNUNET_free_non_null (connection->addr); GNUNET_free_non_null (connection->hostname); GNUNET_free (connection->write_buffer); GNUNET_free (connection); }
/** * Free SOA information record. * * @param soa record to free */ void GNUNET_DNSPARSER_free_soa (struct GNUNET_DNSPARSER_SoaRecord *soa) { if (NULL == soa) return; GNUNET_free_non_null (soa->mname); GNUNET_free_non_null (soa->rname); GNUNET_free (soa); }
/** * read the pseudonym infomation from a file * @param cfg configuration to use * @param nsid hash code of a pseudonym * @param meta meta data to be read from a file * @param ranking ranking of a pseudonym * @param ns_name name of a pseudonym */ static int read_info (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **meta, int32_t * ranking, char **ns_name) { char *fn; char *emsg; struct GNUNET_BIO_ReadHandle *fileR; fn = get_data_filename (cfg, PS_METADATA_DIR, nsid); GNUNET_assert (fn != NULL); if (GNUNET_YES != GNUNET_DISK_file_test (fn)) { GNUNET_free (fn); return GNUNET_SYSERR; } fileR = GNUNET_BIO_read_open (fn); if (fileR == NULL) { GNUNET_free (fn); return GNUNET_SYSERR; } emsg = NULL; *ns_name = NULL; if ((GNUNET_OK != GNUNET_BIO_read_int32 (fileR, ranking)) || (GNUNET_OK != GNUNET_BIO_read_string (fileR, "Read string error!", ns_name, 200)) || (GNUNET_OK != GNUNET_BIO_read_meta_data (fileR, "Read meta data error!", meta))) { (void) GNUNET_BIO_read_close (fileR, &emsg); GNUNET_free_non_null (emsg); GNUNET_free_non_null (*ns_name); *ns_name = NULL; GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); GNUNET_free (fn); return GNUNET_SYSERR; } if (GNUNET_OK != GNUNET_BIO_read_close (fileR, &emsg)) { LOG (GNUNET_ERROR_TYPE_WARNING, _("Failed to parse metadata about pseudonym from file `%s': %s\n"), fn, emsg); GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn)); GNUNET_CONTAINER_meta_data_destroy (*meta); *meta = NULL; GNUNET_free_non_null (*ns_name); *ns_name = NULL; GNUNET_free_non_null (emsg); GNUNET_free (fn); return GNUNET_SYSERR; } GNUNET_free (fn); return GNUNET_OK; }
/** * Task to clean up and shutdown nicely * * @param cls NULL * @param tc the TaskContext from scheduler */ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { 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_free_lcfq (); GST_free_mctxq (); GST_free_occq (); GST_free_roccq (); GST_free_nccq (); GST_neighbour_list_clean(); GST_free_prcq (); /* Clear peer list */ GST_destroy_peers (); /* Clear route list */ GST_route_list_clear (); /* Clear GST_slave_list */ GST_slave_list_clear (); /* Clear host list */ for (id = 0; id < GST_host_list_size; id++) if (NULL != GST_host_list[id]) GNUNET_TESTBED_host_destroy (GST_host_list[id]); GNUNET_free_non_null (GST_host_list); if (NULL != GST_context) { GNUNET_free_non_null (GST_context->master_ip); if (NULL != GST_context->system) GNUNET_TESTING_system_destroy (GST_context->system, GNUNET_YES); GNUNET_SERVER_client_drop (GST_context->client); GNUNET_free (GST_context); GST_context = NULL; } if (NULL != transmit_handle) GNUNET_SERVER_notify_transmit_ready_cancel (transmit_handle); 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_free (mq_entry); } GNUNET_free_non_null (hostname); /* Free hello cache */ GST_cache_clear (); GST_connection_pool_destroy (); GNUNET_TESTBED_operation_queue_destroy_ (GST_opq_openfds); GST_opq_openfds = NULL; GST_stats_destroy (); GST_barriers_destroy (); GNUNET_CONFIGURATION_destroy (GST_config); }
static void clean (struct SplittedHTTPAddress *addr) { if (NULL == addr) return; GNUNET_free_non_null (addr->host); GNUNET_free_non_null (addr->path); GNUNET_free_non_null (addr->protocol); GNUNET_free (addr); }
void clean (struct SplittedHTTPAddress *addr) { if (NULL != addr) { GNUNET_free_non_null (addr->host); GNUNET_free_non_null (addr->path); GNUNET_free_non_null (addr->protocol); GNUNET_free_non_null (addr); } }
/** * Remove and free an entry in the service list. Listen sockets * must have already been cleaned up. Only to be called during shutdown. * * @param sl entry to free */ static void free_service (struct ServiceList *sl) { GNUNET_assert (GNUNET_YES == in_shutdown); GNUNET_CONTAINER_DLL_remove (running_head, running_tail, sl); GNUNET_assert (NULL == sl->listen_head); GNUNET_free_non_null (sl->config); GNUNET_free_non_null (sl->binary); GNUNET_free (sl->name); GNUNET_free (sl); }
/** * Core handler for p2p hostlist advertisements */ static int ad_arrive_handler (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) { char *hostname; char *expected_uri; unsigned long long port; const struct GNUNET_MessageHeader *incoming; const char *end; if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, "HOSTLIST", "HTTPPORT", &port)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not read advertising server's configuration\n"); return GNUNET_SYSERR; } if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, "HOSTLIST", "EXTERNAL_DNS_NAME", &hostname)) hostname = GNUNET_RESOLVER_local_fqdn_get (); GNUNET_asprintf (&expected_uri, "http://%s:%u/", hostname != NULL ? hostname : "localhost", (unsigned int) port); incoming = (const struct GNUNET_MessageHeader *) message; end = (const char *) &incoming[1]; if ('\0' != end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) { GNUNET_break (0); GNUNET_free (expected_uri); GNUNET_free_non_null (hostname); return GNUNET_SYSERR; } current_adv_uri = GNUNET_strdup (end); if (0 == strcmp (expected_uri, current_adv_uri)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received hostlist advertisement with URI `%s' as expected\n", current_adv_uri); adv_arrived = GNUNET_YES; adv_sent = GNUNET_YES; } else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected URI `%s' and received URI `%s' differ\n", expected_uri, current_adv_uri); GNUNET_free (expected_uri); GNUNET_free_non_null (hostname); return GNUNET_OK; }
/** * Write PID file. * * @param sctx service context * @param pid PID to write (should be equal to 'getpid()' * @return #GNUNET_OK on success (including no work to be done) */ static int write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid) { FILE *pidfd; char *pif; char *user; char *rdir; int len; if (NULL == (pif = get_pid_file_name (sctx))) return GNUNET_OK; /* no file desired */ user = get_user_name (sctx); rdir = GNUNET_strdup (pif); len = strlen (rdir); while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) len--; rdir[len] = '\0'; if (0 != ACCESS (rdir, F_OK)) { /* we get to create a directory -- and claim it * as ours! */ (void) GNUNET_DISK_directory_create (rdir); if ((NULL != user) && (0 < strlen (user))) GNUNET_DISK_file_change_owner (rdir, user); } if (0 != ACCESS (rdir, W_OK | X_OK)) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); GNUNET_free (rdir); GNUNET_free_non_null (user); GNUNET_free (pif); return GNUNET_SYSERR; } GNUNET_free (rdir); pidfd = FOPEN (pif, "w"); if (NULL == pidfd) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); GNUNET_free (pif); GNUNET_free_non_null (user); return GNUNET_SYSERR; } if (0 > FPRINTF (pidfd, "%u", pid)) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); GNUNET_break (0 == FCLOSE (pidfd)); if ((NULL != user) && (0 < strlen (user))) GNUNET_DISK_file_change_owner (pif, user); GNUNET_free_non_null (user); GNUNET_free (pif); return GNUNET_OK; }
void delete_session (struct Session *s) { stop_session_timeout(s); if (s->msg_tk != NULL) { GNUNET_SERVER_mst_destroy (s->msg_tk); s->msg_tk = NULL; } GNUNET_free (s->addr); GNUNET_free_non_null (s->server_recv); GNUNET_free_non_null (s->server_send); GNUNET_free (s); }
/** * Main state machine that goes over all options and * runs the next requested function. * * @param cls unused * @param tc scheduler context */ static void shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct PrintContext *pc; struct AddressRecord *ar; unsigned int i; if (NULL != ac) { GNUNET_PEERINFO_add_peer_cancel (ac); ac = NULL; } if (GNUNET_SCHEDULER_NO_TASK != tt) { GNUNET_SCHEDULER_cancel (tt); tt = GNUNET_SCHEDULER_NO_TASK; } if (NULL != pic) { GNUNET_PEERINFO_iterate_cancel (pic); pic = NULL; } while (NULL != (pc = pc_head)) { GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc); for (i=0;i<pc->address_list_size;i++) { ar = &pc->address_list[i]; GNUNET_free_non_null (ar->result); if (NULL != ar->atsc) { GNUNET_TRANSPORT_address_to_string_cancel (ar->atsc); ar->atsc = NULL; } } GNUNET_free_non_null (pc->address_list); GNUNET_free (pc); } GPI_plugins_unload (); if (NULL != peerinfo) { GNUNET_PEERINFO_disconnect (peerinfo); peerinfo = NULL; } }
/** * Stop monitoring. * * @param handle The handle to the monitor request returned by monitor_start. * * On return get_handle will no longer be valid, caller must not use again!!! */ void GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle) { struct GNUNET_DHT_MonitorStartStopMessage *m; struct PendingMessage *pending; GNUNET_CONTAINER_DLL_remove (handle->dht_handle->monitor_head, handle->dht_handle->monitor_tail, handle); pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartStopMessage) + sizeof (struct PendingMessage)); m = (struct GNUNET_DHT_MonitorStartStopMessage *) &pending[1]; pending->msg = &m->header; pending->handle = handle->dht_handle; pending->free_on_send = GNUNET_YES; m->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP); m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartStopMessage)); m->type = htonl(handle->type); m->get = htons(NULL != handle->get_cb); m->get_resp = htons(NULL != handle->get_resp_cb); m->put = htons(NULL != handle->put_cb); if (NULL != handle->key) { m->filter_key = htons(1); memcpy (&m->key, handle->key, sizeof(GNUNET_HashCode)); } GNUNET_CONTAINER_DLL_insert (handle->dht_handle->pending_head, handle->dht_handle->pending_tail, pending); pending->in_pending_queue = GNUNET_YES; process_pending_messages (handle->dht_handle); GNUNET_free_non_null (handle->key); GNUNET_free (handle); }
static void do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *c) { if (mhd_task_id != NULL) { GNUNET_SCHEDULER_cancel (mhd_task_id); mhd_task_id = NULL; } if (curl_task_id != NULL) { GNUNET_SCHEDULER_cancel (curl_task_id); curl_task_id = NULL; } if (NULL != mhd) { MHD_stop_daemon (mhd); mhd = NULL; } if (NULL != identity) { GNUNET_IDENTITY_disconnect (identity); identity = NULL; } if (NULL != qe) { GNUNET_NAMESTORE_cancel (qe); qe = NULL; } GNUNET_free_non_null (url); url = NULL; }
/** * Add a pseudonym to the set of known pseudonyms. * For all pseudonym advertisements that we discover * FS should automatically call this function. * * @param cfg overall configuration * @param id the pseudonym identifier * @param meta metadata for the pseudonym */ void GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode * id, const struct GNUNET_CONTAINER_MetaData *meta) { char *name; int32_t ranking; struct GNUNET_CONTAINER_MetaData *old; char *fn; struct stat sbuf; ranking = 0; fn = get_data_filename (cfg, PS_METADATA_DIR, id); GNUNET_assert (fn != NULL); if ((0 == STAT (fn, &sbuf)) && (GNUNET_OK == read_info (cfg, id, &old, &ranking, &name))) { GNUNET_CONTAINER_meta_data_merge (old, meta); write_pseudonym_info (cfg, id, old, ranking, name); GNUNET_CONTAINER_meta_data_destroy (old); GNUNET_free_non_null (name); } else { write_pseudonym_info (cfg, id, meta, ranking, NULL); } GNUNET_free (fn); internal_notify (id, meta, ranking); }
/** * Program to manipulate ECC key files. * * @param argc number of arguments from the command line * @param argv command line arguments * @return 0 ok, 1 on error */ int main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { { 'b', "bits", "BITS", gettext_noop ("number of bits to require for the proof of work"), 1, &GNUNET_GETOPT_set_ulong, &nse_work_required }, { 'k', "keyfile", "FILE", gettext_noop ("file with private key, otherwise default is used"), 1, &GNUNET_GETOPT_set_filename, &pkfn }, { 'o', "outfile", "FILE", gettext_noop ("file with proof of work, otherwise default is used"), 1, &GNUNET_GETOPT_set_filename, &pwfn }, { 't', "timeout", "TIME", gettext_noop ("time to wait between calculations"), 1, &GNUNET_GETOPT_set_relative_time, &proof_find_delay }, GNUNET_GETOPT_OPTION_END }; int ret; if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) return 2; ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-scrypt [OPTIONS] prooffile", gettext_noop ("Manipulate GNUnet proof of work files"), options, &run, NULL)) ? 0 : 1; GNUNET_free ((void*) argv); GNUNET_free_non_null (pwfn); return ret; }
static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_NO_TASK; } int c; for (c = 0; c < RECORDS; c++) GNUNET_free_non_null((void *) s_rd[c].data); GNUNET_free (s_rd); if (privkey != NULL) GNUNET_CRYPTO_rsa_key_free (privkey); privkey = NULL; if (nsh != NULL) GNUNET_NAMESTORE_disconnect (nsh, GNUNET_YES); nsh = NULL; if (NULL != arm) stop_arm(); }