Browse Source

feat(Core): Add support for retrieving self DHT ID and port

To allow qTox (but just tests for now) to be bootstrapped off of.
reviewable/pr6550/r3
Anthony Bilinski 3 years ago
parent
commit
4f9ca0a411
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 35
      src/core/core.cpp
  2. 3
      src/core/core.h

35
src/core/core.cpp

@ -474,6 +474,22 @@ bool parseErr(Tox_Err_Conference_Delete error, int line)
} }
} }
bool parseErr(Tox_Err_Get_Port error, int line)
{
switch (error) {
case TOX_ERR_GET_PORT_OK:
return true;
case TOX_ERR_GET_PORT_NOT_BOUND:
qCritical() << line << "Tox instance was not bound to any port.";
return false;
default:
qCritical() << line << "Unknown Tox_Err_Get_Port error code:" << error;
return false;
}
}
QList<DhtServer> shuffleBootstrapNodes(QList<DhtServer> bootstrapNodes) QList<DhtServer> shuffleBootstrapNodes(QList<DhtServer> bootstrapNodes)
{ {
std::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count()); std::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
@ -1296,6 +1312,25 @@ QPair<QByteArray, QByteArray> Core::getKeypair() const
return keypair; return keypair;
} }
QByteArray Core::getSelfDhtId() const
{
QMutexLocker ml{&coreLoopLock};
QByteArray dhtKey(TOX_PUBLIC_KEY_SIZE, 0x00);
tox_self_get_public_key(tox.get(), reinterpret_cast<uint8_t*>(dhtKey.data()));
return dhtKey;
}
int Core::getSelfUdpPort() const
{
QMutexLocker ml{&coreLoopLock};
Tox_Err_Get_Port error;
auto port = tox_self_get_udp_port(tox.get(), &error);
if (!PARSE_ERR(error)) {
return -1;
}
return port;
}
/** /**
* @brief Returns our status message, or an empty string on failure * @brief Returns our status message, or an empty string on failure
*/ */

3
src/core/core.h

@ -111,6 +111,9 @@ public:
ToxPk getSelfPublicKey() const override; ToxPk getSelfPublicKey() const override;
QPair<QByteArray, QByteArray> getKeypair() const; QPair<QByteArray, QByteArray> getKeypair() const;
QByteArray getSelfDhtId() const;
int getSelfUdpPort() const;
public slots: public slots:
void start(); void start();

Loading…
Cancel
Save