コード例 #1
0
/**
 * Print URI of the peer.
 *
 * @param cls the 'struct GetUriContext'
 * @param peer identity of the peer (unused)
 * @param hello addresses of the peer
 * @param err_msg error message
 */
static void
print_my_uri (void *cls, const struct GNUNET_PeerIdentity *peer,
              const struct GNUNET_HELLO_Message *hello, 
	      const char *err_msg)
{
  if (peer == NULL)
  {
    pic = NULL;
    if (err_msg != NULL)
      FPRINTF (stderr,
	       _("Error in communication with PEERINFO service: %s\n"), 
	       err_msg);
    tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
    return;
  }

  if (NULL == hello)
    return;

  char *uri = GNUNET_HELLO_compose_uri(hello, &GPI_plugins_find);
  if (NULL != uri) {
    printf ("%s\n", (const char *) uri);
    GNUNET_free (uri);
  }
}
コード例 #2
0
ファイル: NetworkManager.cpp プロジェクト: bratao/cangote
/**
 * Function called for peers that we know about.
 *
 * @param peer id of the peer, NULL for last call
 * @param hello hello message for the peer (can be NULL)
 * @param err_msg NULL if successful, otherwise contains error message
 */
void NetworkManager::peerinfoProcessor(const struct GNUNET_PeerIdentity *peer,
                                       const struct GNUNET_HELLO_Message *hello,
                                       const char *err_msg)
{

    if(peer == NULL)
    {
        qWarning() << QString("Got a NULL peer in peerinfoProcessor. %1").arg(err_msg ? err_msg : "");
        return;
    }


    const char* key = GNUNET_i2s_full (peer);
    QString peerIdStr(key);


    if(!theApp->models()->networkModel())
    {
        qWarning() << tr("Got a info about a peer while the network model was not created");
        return;
    }


    //If is myself, update my Hello string to display to the user.
    if(theApp->gnunet()->myPublicKeyStr() == peerIdStr)
    {
        if(!hello)
        {
            qWarning() << tr("Got a info about myself without a hello");
            return;
        }

        //Save my hello URL
        char *uri = GNUNET_HELLO_compose_uri(hello, &m_gnunetTransportPlugins->GPI_plugins_find);
        setMyHelloStr(QString(uri));
        return;
    }


    Peer* newPeer = NULL;

    //See if peer already exists.If not, create a new one.
    if(!theApp->models()->networkModel()->contains(peerIdStr)) {
        newPeer = theApp->models()->networkModel()->addNewPeer(peer, peerIdStr);
    } else {
        newPeer =theApp->models()->networkModel()->getPeer(peerIdStr);
    }

    Q_ASSERT(newPeer);



    if(hello){
        GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
                                    &peerAddressCallback, newPeer);
    }

}