/** * Convenience method for running a "simple" test on the local system * with a single call from 'main'. Underlay and overlay topology are * configured using the "UNDERLAY" and "OVERLAY" options in the * "[testbed]" section of the configuration (with possible options * given in "UNDERLAY_XXX" and/or "OVERLAY_XXX"). * * The test is to be terminated using a call to * "GNUNET_SCHEDULER_shutdown". If starting the test fails, * the program is stopped without 'master' ever being run. * * NOTE: this function should be called from 'main', NOT from * within a GNUNET_SCHEDULER-loop. This function will initialze * the scheduler loop, the testbed and then pass control to * 'master'. * * @param testname name of the testcase (to configure logging, etc.) * @param cfg_filename configuration filename to use * (for testbed, controller and peers) * @param num_peers number of peers to start * @param event_mask bit mask with set of events to call 'cc' for; * or-ed values of "1LL" shifted by the * respective 'enum GNUNET_TESTBED_EventType' * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") * @param cc controller callback to invoke on events; This callback is called * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't * set in the event_mask as this is the only way get access to the * handle of each peer * @param cc_cls closure for cc * @param test_master task to run once the test is ready * @param test_master_cls closure for 'task'. * @return GNUNET_SYSERR on error, GNUNET_OK on success */ int GNUNET_TESTBED_test_run (const char *testname, const char *cfg_filename, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls) { char *argv2[] = { NULL, "-c", NULL, NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; struct TestRunContext *rc; int ret; argv2[0] = GNUNET_strdup (testname); argv2[2] = GNUNET_strdup (cfg_filename); GNUNET_assert (NULL != test_master); GNUNET_assert (num_peers > 0); rc = GNUNET_malloc (sizeof (struct TestRunContext) + (num_peers * sizeof (struct GNUNET_TESTBED_Peer *))); rc->test_master = test_master; rc->test_master_cls = test_master_cls; rc->num_peers = num_peers; rc->event_mask = event_mask; rc->cc = cc; rc->cc_cls = cc_cls; ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, testname, "nohelp", options, &run, rc); GNUNET_free (rc); GNUNET_free (argv2[0]); GNUNET_free (argv2[2]); return ret; }
static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { cc = NULL; char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); s_connected = GNUNET_YES; send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); }
static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (ps); GNUNET_SCHEDULER_add_now (&end, NULL); }
/** * Look for an existing PKEY delegation record for a given public key. * Returns at most one result to the processor. * * @param h handle to the namestore * @param zone hash of public key of the zone to look up in, never NULL * @param value_zone hash of the public key of the target zone (value), never NULL * @param proc function to call on the matching records, or with * NULL (rd_count == 0) if there are no matching records * @param proc_cls closure for proc * @return a handle that can be used to * cancel */ struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_ShortHashCode *zone, const struct GNUNET_CRYPTO_ShortHashCode *value_zone, GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) { struct GNUNET_NAMESTORE_QueueEntry *qe; struct PendingMessage *pe; size_t msg_size = 0; uint32_t rid = 0; GNUNET_assert (NULL != h); GNUNET_assert (NULL != zone); GNUNET_assert (NULL != value_zone); rid = get_op_id(h); qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); qe->nsh = h; qe->proc = proc; qe->proc_cls = proc_cls; qe->op_id = rid; GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); /* set msg_size*/ msg_size = sizeof (struct ZoneToNameMessage); pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); /* create msg here */ struct ZoneToNameMessage * msg; pe->size = msg_size; pe->is_init = GNUNET_NO; msg = (struct ZoneToNameMessage *) &pe[1]; msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); msg->gns_header.header.size = htons (msg_size); msg->gns_header.r_id = htonl (rid); msg->zone = *zone; msg->value_zone = *value_zone; char * z_tmp = GNUNET_strdup (GNUNET_short_h2s (zone)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s' in zone `%s'\n", "NAMESTORE_ZONE_TO_NAME", z_tmp, GNUNET_short_h2s (value_zone)); GNUNET_free (z_tmp); /* transmit message */ GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); do_transmit(h); return qe; }
void key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct GNUNET_REGEX_Edge *edges) { unsigned int i; struct IteratorContext *ctx = cls; char *out_str; char *state_id = GNUNET_strdup (GNUNET_h2s (key)); if (GNUNET_YES == ctx->should_save_graph) { if (GNUNET_YES == accepting) GNUNET_asprintf (&out_str, "\"%s\" [shape=doublecircle]\n", state_id); else GNUNET_asprintf (&out_str, "\"%s\" [shape=circle]\n", state_id); fwrite (out_str, strlen (out_str), 1, ctx->graph_filep); GNUNET_free (out_str); for (i = 0; i < num_edges; i++) { transition_counter++; GNUNET_asprintf (&out_str, "\"%s\" -> \"%s\" [label = \"%s (%s)\"]\n", state_id, GNUNET_h2s (&edges[i].destination), edges[i].label, proof); fwrite (out_str, strlen (out_str), 1, ctx->graph_filep); GNUNET_free (out_str); } } else { for (i = 0; i < num_edges; i++) transition_counter++; } for (i = 0; i < ctx->string_count; i++) { if (0 == strcmp (proof, ctx->strings[i])) ctx->match_count++; } if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key)) { ctx->error++; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed: proof: %s key: %s\n", proof, state_id); } GNUNET_free (state_id); }
/** * 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; }
static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, GNUNET_i2s (peer)); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; }
static int testCanonicalize () { char *fn = GNUNET_strdup ("ab?><|cd*ef:/g\""); GNUNET_DISK_filename_canonicalize (fn); if (0 != strcmp (fn, "ab____cd_ef__g_")) { GNUNET_free (fn); return 1; } GNUNET_free (fn); return 0; }
/** * Function called by the tree encoder to obtain * a block of plaintext data (for the lowest level * of the tree). * * @param cls our publishing context * @param offset identifies which block to get * @param max (maximum) number of bytes to get; returning * fewer will also cause errors * @param buf where to copy the plaintext buffer * @param emsg location to store an error message (on error) * @return number of bytes copied to buf, 0 on error */ static size_t unindex_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) { struct GNUNET_FS_UnindexContext *uc = cls; size_t pt_size; pt_size = GNUNET_MIN (max, uc->file_size - offset); if (offset != GNUNET_DISK_file_seek (uc->fh, offset, GNUNET_DISK_SEEK_SET)) { *emsg = GNUNET_strdup (_("Failed to find given position in file")); return 0; } if (pt_size != GNUNET_DISK_file_read (uc->fh, buf, pt_size)) { *emsg = GNUNET_strdup (_("Failed to read file")); return 0; } return pt_size; }
static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { cc = NULL; char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", p1_c, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! send_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); }
/** * Log a disconnect event. * * @param cls NULL * @param me peer that had the event * @param other peer that disconnected. */ void GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, struct GNUNET_TRANSPORT_TESTING_PeerContext *me, const struct GNUNET_PeerIdentity *other) { char *ps; ps = GNUNET_strdup (GNUNET_i2s (&me->id)); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer `%s' disconnected from %u (%s)!\n", GNUNET_i2s (other), me->no, ps); }
/** * Store a new entry in the PEERSTORE. * Note that stored entries can be lost in some cases * such as power failure. * * @param h Handle to the PEERSTORE service * @param sub_system name of the sub system * @param peer Peer Identity * @param key entry key * @param value entry value BLOB * @param size size of @e value * @param expiry absolute time after which the entry is (possibly) deleted * @param options options specific to the storage operation * @param cont Continuation function after the store request is sent * @param cont_cls Closure for @a cont */ struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store (struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls) { struct GNUNET_MQ_Envelope *ev; struct GNUNET_PEERSTORE_StoreContext *sc; LOG (GNUNET_ERROR_TYPE_DEBUG, "Storing value (size: %lu) for subsytem `%s', peer `%s', key `%s'\n", size, sub_system, GNUNET_i2s (peer), key); ev = PEERSTORE_create_record_mq_envelope (sub_system, peer, key, value, size, &expiry, options, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE); sc = GNUNET_new (struct GNUNET_PEERSTORE_StoreContext); sc->sub_system = GNUNET_strdup (sub_system); sc->peer = *peer; sc->key = GNUNET_strdup (key); sc->value = GNUNET_memdup (value, size); sc->size = size; sc->expiry = expiry; sc->options = options; sc->cont = cont; sc->cont_cls = cont_cls; sc->h = h; GNUNET_CONTAINER_DLL_insert_tail (h->store_head, h->store_tail, sc); GNUNET_MQ_notify_sent (ev, &store_request_sent, sc); GNUNET_MQ_send (h->mq, ev); return sc; }
/** * Convert a string of the form "4 X 5 Y" into a numeric value * by interpreting "X" and "Y" as units and then multiplying * the numbers with the values associated with the respective * unit from the conversion table. * * @param input input string to parse * @param table table with the conversion of unit names to numbers * @param output where to store the result * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ static int convert_with_table (const char *input, const struct ConversionTable *table, unsigned long long *output) { unsigned long long ret; char *in; const char *tok; unsigned long long last; unsigned int i; ret = 0; last = 0; in = GNUNET_strdup (input); for (tok = strtok (in, " "); tok != NULL; tok = strtok (NULL, " ")) { do { i = 0; while ((table[i].name != NULL) && (0 != strcasecmp (table[i].name, tok))) i++; if (table[i].name != NULL) { last *= table[i].value; break; /* next tok */ } else { char *endptr; ret += last; errno = 0; last = strtoull (tok, &endptr, 10); if ((0 != errno) || (endptr == tok)) { GNUNET_free (in); return GNUNET_SYSERR; /* expected number */ } if ('\0' == endptr[0]) break; /* next tok */ else tok = endptr; /* and re-check (handles times like "10s") */ } } while (GNUNET_YES); } ret += last; *output = ret; GNUNET_free (in); return GNUNET_OK; }
static void notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { struct PeerContext *p = cls; struct PeerContext *t = NULL; if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) t = p1; if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) t = p2; GNUNET_assert (t != NULL); char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); GNUNET_free (ps); if ((MTYPE == ntohs (message->type)) && (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) { if (restarted == GNUNET_NO) { restarted = GNUNET_YES; restart (p1, cfg_file_p1); restart (p2, cfg_file_p2); return; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Restarted peers connected, stopping test...\n"); ok = 0; end (); } } else { GNUNET_break (0); ok = 1; if (die_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); } }
/** * Connect to the datastore and remove the blocks. * * @param uc context for the unindex operation. */ void GNUNET_FS_unindex_do_remove_ (struct GNUNET_FS_UnindexContext *uc) { if (NULL == uc->dsh) uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); if (NULL == uc->dsh) { uc->state = UNINDEX_STATE_ERROR; uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); GNUNET_FS_unindex_sync_ (uc); signal_unindex_error (uc); return; } uc->fh = GNUNET_DISK_file_open (uc->filename, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); if (NULL == uc->fh) { GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); uc->dsh = NULL; uc->state = UNINDEX_STATE_ERROR; uc->emsg = GNUNET_strdup (_("Failed to open file for unindexing.")); GNUNET_FS_unindex_sync_ (uc); signal_unindex_error (uc); return; } uc->tc = GNUNET_FS_tree_encoder_create (uc->h, uc->file_size, uc, &unindex_reader, &unindex_process, &unindex_progress, &unindex_extract_keywords); GNUNET_FS_tree_encoder_next (uc->tc); }
/** * Load and initialize all plugins. The respective functions will be * invoked by the plugins when the respective events happen. The * closure will be set to a 'const char*' containing the name of the * plugin that caused the call. * * @param cfg configuration to use */ void GPI_plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct TransportPlugin *plug; struct TransportPlugin *next; char *libname; char *plugs; char *pos; if (NULL != plugins_head) return; /* already loaded */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS", &plugs)) return; GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting transport plugins `%s'\n"), plugs); for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' transport plugin\n"), pos); GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos); plug = GNUNET_malloc (sizeof (struct TransportPlugin)); plug->short_name = GNUNET_strdup (pos); plug->lib_name = libname; plug->env.cfg = cfg; plug->env.cls = plug->short_name; GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug); } GNUNET_free (plugs); next = plugins_head; while (next != NULL) { plug = next; next = plug->next; plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env); if (plug->api == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to load transport plugin for `%s'\n"), plug->lib_name); GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); GNUNET_free (plug->short_name); GNUNET_free (plug->lib_name); GNUNET_free (plug); } } }
/** * Resolves the hostname of the host to an ip address * * @param host the host whose hostname is to be resolved */ void GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host) { char *hostname; hostname = (char *) host->hostname; host->hostname = simple_resolve (hostname); if (NULL == host->hostname) { GNUNET_break (0); host->hostname = hostname; return; } GNUNET_free (hostname); host->hostname = GNUNET_strdup (host->hostname); }
char * path_2s (struct CadetPeerPath *p) { char *s; char *old; unsigned int i; old = GNUNET_strdup (""); for (i = 0; i < p->length; i++) { GNUNET_asprintf (&s, "%s %s", old, GNUNET_i2s (GNUNET_PEER_resolve2 (p->peers[i]))); GNUNET_free_non_null (old); old = s; } return old; }
static void testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) { char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); GNUNET_free (p1_c); cc = NULL; test_connected = GNUNET_YES; measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); GNUNET_SCHEDULER_add_now (&sendtask, NULL); }
/** * Function to call with a human-readable format of an address * * @param cls closure * @param address NULL on error, otherwise 0-terminated printable UTF-8 string */ static void process_resolved_address (void *cls, const char *address) { struct AddressRecord * ar = cls; struct PrintContext *pc = ar->pc; if (NULL != address) { if (NULL == ar->result) ar->result = GNUNET_strdup (address); return; } ar->atsc = NULL; pc->num_addresses++; if (pc->num_addresses == pc->address_list_size) dump_pc (pc); }
/** * Obtain the plugin API based on a the stripped plugin name after the underscore. * * Example: GST_plugins_printer_find (http_client) will return all plugins * starting with the prefix "http": * http_client or server if loaded * * @param name name of the plugin * @return the plugin's API, NULL if the plugin is not loaded */ struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_printer_find (const char *name) { struct TransportPlugin *pos; char *stripped = GNUNET_strdup (name); char *sep = strchr (stripped, '_'); if (NULL != sep) sep[0] = '\0'; for (pos = plugins_head; NULL != pos; pos = pos->next) if (pos->short_name == strstr (pos->short_name, stripped)) break; GNUNET_free (stripped); if (NULL == pos) return NULL; return pos->api; }
/** * Create a ATS_address with the given information * @param peer peer * @param plugin_name plugin * @param plugin_addr address * @param plugin_addr_len address length * @param session_id session * @return the ATS_Address */ static struct ATS_Address * create_address (const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, uint32_t session_id) { struct ATS_Address *aa = NULL; aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); aa->peer = *peer; aa->addr_len = plugin_addr_len; aa->addr = &aa[1]; memcpy (&aa[1], plugin_addr, plugin_addr_len); aa->plugin = GNUNET_strdup (plugin_name); aa->session_id = session_id; return aa; }
/** * If necessary, connect to the datastore and remove the KBlocks. * * @param uc context for the unindex operation. */ void GNUNET_FS_unindex_do_remove_kblocks_ (struct GNUNET_FS_UnindexContext *uc) { const char *keyword; const struct GNUNET_CRYPTO_EcdsaPrivateKey *anon; struct GNUNET_CRYPTO_EcdsaPublicKey anon_pub; struct GNUNET_CRYPTO_EcdsaPublicKey dpub; if (NULL == uc->dsh) uc->dsh = GNUNET_DATASTORE_connect (uc->h->cfg); if (NULL == uc->dsh) { uc->state = UNINDEX_STATE_ERROR; uc->emsg = GNUNET_strdup (_("Failed to connect to `datastore' service.")); GNUNET_FS_unindex_sync_ (uc); signal_unindex_error (uc); return; } if ( (NULL == uc->ksk_uri) || (uc->ksk_offset >= uc->ksk_uri->data.ksk.keywordCount) ) { unindex_finish (uc); return; } anon = GNUNET_CRYPTO_ecdsa_key_get_anonymous (); GNUNET_CRYPTO_ecdsa_key_get_public (anon, &anon_pub); keyword = &uc->ksk_uri->data.ksk.keywords[uc->ksk_offset][1]; GNUNET_CRYPTO_ecdsa_public_key_derive (&anon_pub, keyword, "fs-ublock", &dpub); GNUNET_CRYPTO_hash (&dpub, sizeof (dpub), &uc->uquery); uc->dqe = GNUNET_DATASTORE_get_key (uc->dsh, uc->roff++, &uc->uquery, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0 /* priority */, 1 /* queue size */, GNUNET_TIME_UNIT_FOREVER_REL, &process_kblock_for_unindex, uc); }
/** * Load configuration (starts with defaults, then loads * system-specific configuration). * * @param cfg configuration to update * @param filename name of the configuration file, NULL to load defaults * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename) { char *baseconfig; const char *base_config_varname; base_config_varname = GNUNET_OS_project_data_get ()->base_config_varname; if (NULL != (baseconfig = getenv (base_config_varname))) { baseconfig = GNUNET_strdup (baseconfig); } else { char *ipath; ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); if (NULL == ipath) return GNUNET_SYSERR; GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d"); GNUNET_free (ipath); } if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load_from (cfg, baseconfig)) { GNUNET_free (baseconfig); return GNUNET_SYSERR; /* no configuration at all found */ } GNUNET_free (baseconfig); if ((NULL != filename) && (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) { /* specified configuration not found */ return GNUNET_SYSERR; } if (((GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && (filename != NULL)) GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", filename); return GNUNET_OK; }
/** * Initialize plugins subsystem. * * @param cfg configuration to use * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (failed to load * solver plugin) */ int GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg) { char *mode_str; /* Figure out configured solution method */ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "No resource assignment method configured, using proportional approach\n"); mode_str = GNUNET_strdup ("proportional"); } env.cls = NULL; env.info_cb = &solver_info_cb; env.bandwidth_changed_cb = &bandwidth_changed_cb; env.get_preferences = &GAS_preference_get_by_peer; env.get_connectivity = &GAS_connectivity_has_peer; env.cfg = cfg; env.stats = GSA_stats; env.addresses = GSA_addresses; env.network_count = GNUNET_ATS_NetworkTypeCount; load_quotas (cfg, env.out_quota, env.in_quota, GNUNET_ATS_NetworkTypeCount); GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", mode_str); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initializing solver `%s'\n", mode_str); GNUNET_free (mode_str); if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin); return GNUNET_SYSERR; } return GNUNET_OK; }
/** * Continuation called to notify client about result of the * datastore removal operation. * * @param cls closure * @param success #GNUNET_SYSERR on failure * @param min_expiration minimum expiration time required for content to be stored * @param msg NULL on success, otherwise an error message */ static void process_cont (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg) { struct GNUNET_FS_UnindexContext *uc = cls; if (success == GNUNET_SYSERR) { uc->emsg = GNUNET_strdup (msg); signal_unindex_error (uc); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Datastore REMOVE operation succeeded\n"); GNUNET_FS_tree_encoder_next (uc->tc); }
static void sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { send_task = NULL; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; char *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); GNUNET_free (receiver_s); th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, TIMEOUT_TRANSMIT, ¬ify_ready, p1); }
/** * Handler for CREATE message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_create_message (void *cls, const struct CreateRequestMessage *crm) { struct GNUNET_SERVICE_Client *client = cls; struct Ego *ego; const char *str; char *fn; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); str = (const char *) &crm[1]; for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, str)) { send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); GNUNET_SERVICE_client_continue (client); return; } } ego = GNUNET_new (struct Ego); ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); *ego->pk = crm->private_key; ego->identifier = GNUNET_strdup (str); GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); send_result_code (client, 0, NULL); fn = get_ego_filename (ego); (void) GNUNET_DISK_directory_create_for_file (fn); if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != GNUNET_DISK_fn_write (fn, &crm->private_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); GNUNET_free (fn); notify_listeners (ego); GNUNET_SERVICE_client_continue (client); }
/** * Resolve the given request using gethostbyaddr * * @param cache the request to resolve (and where to store the result) */ static void gethostbyaddr_resolve (struct IPCache *cache) { struct hostent *ent; ent = gethostbyaddr (cache->ip, cache->ip_len, cache->af); if (NULL != ent) { cache->addr = GNUNET_strdup (ent->h_name); } else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "gethostbyaddr failed: %s\n", hstrerror (h_errno)); } }
/** * Get the first MD entry of the given type. Caller * is responsible for freeing the return value. * Also, only meta data items that are strings (0-terminated) * are returned by this function. * * @param md metadata to inspect * @param type type to look for * @return NULL if no entry was found */ char * GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type) { struct MetaItem *pos; if (md == NULL) return NULL; pos = md->items; while (NULL != pos) { if ((type == pos->type) && ((pos->format == EXTRACTOR_METAFORMAT_UTF8) || (pos->format == EXTRACTOR_METAFORMAT_C_STRING))) return GNUNET_strdup (pos->data); pos = pos->next; } return NULL; }