Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(core): avoid logging which bootstrap node is being connected to
Browse files Browse the repository at this point in the history
Errors are parsed and printed, but which specific node is being connected to
isn't very relevant to any errors that would occur, and the nodes list is
already updated to prune offline nodes based on nodes.tox.chat periodically.
This provides some extra privacy about which connections are being made,
even though the bootstrap nodes are already public.
  • Loading branch information
anthonybilinski committed Oct 10, 2019
1 parent fe9d83d commit 731a498
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ bool LogConferenceTitleError(TOX_ERR_CONFERENCE_TITLE error)
return error;
}

bool parseToxErrBootstrap(Tox_Err_Bootstrap error)
{
switch(error) {
case TOX_ERR_BOOTSTRAP_OK:
return true;

case TOX_ERR_BOOTSTRAP_NULL:
qCritical() << "null argument when not expected";
return false;

case TOX_ERR_BOOTSTRAP_BAD_HOST:
qCritical() << "Could not resolve hostname, or invalid IP address";
return false;

case TOX_ERR_BOOTSTRAP_BAD_PORT:
qCritical() << "out of range port";
return false;

default:
qCritical() << "Unknown Tox_Err_bootstrap error code:" << error;
return false;
}
}

bool parseFriendSendMessageError(Tox_Err_Friend_Send_Message error)
{
switch (error) {
Expand Down Expand Up @@ -448,21 +472,19 @@ void Core::bootstrapDht()
QString dhtServerAddress = dhtServer.address.toLatin1();
QString port = QString::number(dhtServer.port);
QString name = dhtServer.name;
qDebug() << QString("Connecting to %1:%2 (%3)").arg(dhtServerAddress, port, name);
qDebug() << QString("Connecting to a bootstrap node...");
QByteArray address = dhtServer.address.toLatin1();
// TODO: constucting the pk via ToxId is a workaround
ToxPk pk = ToxId{dhtServer.userId}.getPublicKey();


const uint8_t* pkPtr = pk.getData();

if (!tox_bootstrap(tox.get(), address.constData(), dhtServer.port, pkPtr, nullptr)) {
qDebug() << "Error bootstrapping from " + dhtServer.name;
}
Tox_Err_Bootstrap error;
tox_bootstrap(tox.get(), address.constData(), dhtServer.port, pkPtr, &error);
parseToxErrBootstrap(error);

if (!tox_add_tcp_relay(tox.get(), address.constData(), dhtServer.port, pkPtr, nullptr)) {
qDebug() << "Error adding TCP relay from " + dhtServer.name;
}
tox_add_tcp_relay(tox.get(), address.constData(), dhtServer.port, pkPtr, &error);
parseToxErrBootstrap(error);

++j;
++i;
Expand Down

0 comments on commit 731a498

Please sign in to comment.