/** * Main state machine that goes over all options and * runs the next requested function. * * @param cls unused * @param tc scheduler context */ static void state_machine (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { tt = GNUNET_SCHEDULER_NO_TASK; if (NULL != put_uri) { GPI_plugins_load (cfg); if (GNUNET_SYSERR == parse_hello_uri (put_uri)) fprintf (stderr, _("Invalid URI `%s'\n"), put_uri); GNUNET_free (put_uri); put_uri = NULL; return; } if (GNUNET_YES == get_info) { get_info = GNUNET_NO; GPI_plugins_load (cfg); pic = GNUNET_PEERINFO_iterate (peerinfo, NULL, TIMEOUT, &print_peer_info, NULL); return; } if (GNUNET_YES == get_self) { struct GNUNET_CRYPTO_HashAsciiEncoded enc; get_self = GNUNET_NO; GNUNET_CRYPTO_hash_to_enc (&my_peer_identity.hashPubKey, &enc); if (be_quiet) printf ("%s\n", (char *) &enc); else printf (_("I am peer `%s'.\n"), (const char *) &enc); } if (GNUNET_YES == get_uri) { struct GetUriContext *guc; char *pkey; guc = GNUNET_malloc (sizeof (struct GetUriContext)); pkey = GNUNET_CRYPTO_rsa_public_key_to_string (&my_public_key); GNUNET_asprintf (&guc->uri, "%s%s", HELLO_URI_PREFIX, pkey); GNUNET_free (pkey); GPI_plugins_load (cfg); pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity, TIMEOUT, &print_my_uri, guc); get_uri = GNUNET_NO; return; } GNUNET_SCHEDULER_shutdown (); }
/** * 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_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peerinfo is notifying us to rebuild our hostlist\n"); if (NULL != err_msg) GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Error in communication with PEERINFO service: %s\n"), err_msg); if (NULL != builder) { /* restart re-build already in progress ... */ if (NULL != builder->pitr) { GNUNET_PEERINFO_iterate_cancel (builder->pitr); builder->pitr = NULL; } GNUNET_free_non_null (builder->data); builder->size = 0; builder->data = NULL; } else { builder = GNUNET_new (struct HostSet); } GNUNET_assert (NULL != peerinfo); builder->pitr = GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, GNUNET_TIME_UNIT_MINUTES, &host_processor, NULL); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { h = GNUNET_PEERINFO_connect (cfg); GNUNET_assert (NULL != h); add_peer (); ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid, &process, cls); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { h = GNUNET_PEERINFO_connect (cfg); GNUNET_assert (NULL != h); ic = GNUNET_PEERINFO_iterate (h, GNUNET_YES, NULL, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); }
static void process (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg) { unsigned int agc; if (err_msg != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Error in communication with PEERINFO service\n")); } if (peer == NULL) { ic = NULL; if ((3 == global_ret) && (retries < 50)) { /* try again */ retries++; add_peer (); ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, &process, cls); return; } GNUNET_assert (peer == NULL); GNUNET_assert (2 == global_ret); GNUNET_PEERINFO_disconnect (h); h = NULL; global_ret = 0; return; } if (hello != NULL) { GNUNET_assert (3 == global_ret); agc = 3; GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); GNUNET_assert (agc == 0); global_ret = 2; } }
void NetworkManager::notifyConnect(const struct GNUNET_PeerIdentity *peerIdent) { const char* key = GNUNET_i2s_full (peerIdent); QString peerIdStr(key); if(!theApp->models()->networkModel()) { qWarning() << tr("Tried to add a peer while the network model was not created"); return; } //Do not show my own. if(theApp->gnunet()->myPublicKeyStr() == peerIdStr) { //Call peerinfo iterate to get my own hello, to create my share-link. GNUNET_PEERINFO_iterate (m_peerInfo, false, peerIdent, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &peerinfoProcessorCallback, this); return; } Peer* peer = theApp->models()->networkModel()->getPeer(peerIdStr); //If peer do not exist, create it. if(peer == NULL) peer = theApp->models()->networkModel()->addNewPeer(peerIdent,peerIdStr); //Just set as connected if the previous status was disconnected if(!peer->isConnected()) setConnectedPeers(++m_connectedPeers); peer->setConnected(true); }