Ejemplo n.º 1
0
void Core::bootstrapDht()
{
    const Settings& s = Settings::getInstance();
    QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();

    int listSize = dhtServerList.size();
    static int j = qrand() % listSize, n=0;

    // We couldn't connect after trying 6 different nodes, let's try something else
    if (n>3)
    {
        qDebug() << "Core: We're having trouble connecting to the DHT, slowing down";
        bootstrapTimer->setInterval(TOX_BOOTSTRAP_INTERVAL*(n-1));
    }
    else
        qDebug() << "Core: Connecting to the DHT ...";

    int i=0;
    while (i < (2 - (n>3)))
    {
        const Settings::DhtServer& dhtServer = dhtServerList[j % listSize];
        if (tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(),
            qToBigEndian(dhtServer.port), CUserId(dhtServer.userId).data()) == 1)
            qDebug() << QString("Core: Bootstraping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data()
                        +QString(", port ")+QString().setNum(dhtServer.port);
        else
            qDebug() << "Core: Error bootstraping from "+dhtServer.name;

        tox_do(tox);
        j++;
        i++;
        n++;
    }
}
Ejemplo n.º 2
0
void Core::bootstrapDht()
{
    const Settings& s = Settings::getInstance();
    QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();

    int listSize = dhtServerList.size();
    static int j = qrand() % listSize;

    qDebug() << "Core: Bootstraping to the DHT ...";

    int i=0;
    while (i < 2) // i think the more we bootstrap, the more we jitter because the more we overwrite nodes
    {
        const Settings::DhtServer& dhtServer = dhtServerList[j % listSize];
        if (tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(),
            dhtServer.port, CUserId(dhtServer.userId).data()) == 1)
            qDebug() << QString("Core: Bootstraping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data()
                        +QString(", port ")+QString().setNum(dhtServer.port);
        else
            qDebug() << "Core: Error bootstraping from "+dhtServer.name;

        j++;
        i++;
    }
}
Ejemplo n.º 3
0
void Core::acceptFriendRequest(const QString& userId)
{
    int friendId = tox_addfriend_norequest(tox, CUserId(userId).data());
    if (friendId == -1) {
        emit failedToAddFriend(userId);
    } else {
        emit friendAdded(friendId, userId);
    }
}
Ejemplo n.º 4
0
void Core::requestFriendship(const QString& userId, const QString& message)
{
    CString cMessage(message);

    int friendId = tox_addfriend(handle, CUserId(userId).data(), cMessage.data(), cMessage.size());
    if (friendId == -1) {
        emit failedToAddFriend(userId);
    } else {
        emit friendAdded(friendId, userId);
        friendIdList << friendId;
    }
}
Ejemplo n.º 5
0
void Core::acceptFriendRequest(const QString& userId)
{
    uint32_t friendId = tox_friend_add_norequest(tox, CUserId(userId).data(), nullptr);
    if (friendId == std::numeric_limits<uint32_t>::max())
    {
        emit failedToAddFriend(userId);
    }
    else
    {
        saveConfiguration();
        emit friendAdded(friendId, userId);
    }
}
Ejemplo n.º 6
0
Archivo: core.cpp Proyecto: Pik-9/qTox
/**
 * @brief Connects us to the Tox network
 */
void Core::bootstrapDht()
{
    const Settings& s = Settings::getInstance();
    QList<DhtServer> dhtServerList = s.getDhtServerList();

    int listSize = dhtServerList.size();
    if (listSize == 0)
    {
        qWarning() << "no bootstrap list?!?";
        return;
    }
    static int j = qrand() % listSize;

    int i=0;
    while (i < 2) // i think the more we bootstrap, the more we jitter because the more we overwrite nodes
    {
        const DhtServer& dhtServer = dhtServerList[j % listSize];
        qDebug() << "Connecting to "+QString(dhtServer.address.toLatin1().data())
                    +':'+QString().setNum(dhtServer.port)+" ("+dhtServer.name+')';

        if (!tox_bootstrap(tox, dhtServer.address.toLatin1().data(),
            dhtServer.port, CUserId(dhtServer.userId).data(), nullptr))
        {
            qDebug() << "Error bootstrapping from "+dhtServer.name;
        }

        if (!tox_add_tcp_relay(tox, dhtServer.address.toLatin1().data(),
            dhtServer.port, CUserId(dhtServer.userId).data(), nullptr))
        {
            qDebug() << "Error adding TCP relay from "+dhtServer.name;
        }

        j++;
        i++;
    }
}
Ejemplo n.º 7
0
void Core::bootstrapDht()
{
    const Settings& s = Settings::getInstance();
    QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();

    tox_IP_Port bootstrapIpPort;
    for (const Settings::DhtServer& dhtServer : dhtServerList) {
        bootstrapIpPort.port = htons(dhtServer.port);
        bootstrapIpPort.ip.i = resolveAddress(dhtServer.address.toLatin1().data());
        if (bootstrapIpPort.ip.i == 0) {
            continue;
        }

        tox_bootstrap(tox, bootstrapIpPort, CUserId(dhtServer.userId).data());
    }
}
Ejemplo n.º 8
0
void Core::bootstrapDht()
{
    const Settings& s = Settings::getInstance();
    QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();

    tox_IP_Port bootstrapIpPort;
    for (const Settings::DhtServer& dhtServer : dhtServerList) {
        bootstrapIpPort.port = htons(dhtServer.port);
        //FIXME this is not in the api
        // tox_resolve_addr(dhtServer.address.toLatin1().data());
        bootstrapIpPort.ip.i = 0x58DFAF42;
        if (bootstrapIpPort.ip.i == 0) {
            continue;
        }

        tox_bootstrap(handle, bootstrapIpPort, CUserId(dhtServer.userId).data());
    }
}
Ejemplo n.º 9
0
void Core::bootstrapDht()
{
    const Settings& s = Settings::getInstance();
    QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();

    for (const Settings::DhtServer& dhtServer : dhtServerList) {
       tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(), dhtServer.port, CUserId(dhtServer.userId).data());
    }
}