diff --git a/src/core/core.cpp b/src/core/core.cpp index 071a69ce0..cd916decb 100644 --- a/src/core/core.cpp +++ b/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 shuffleBootstrapNodes(QList bootstrapNodes) { std::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count()); @@ -1296,6 +1312,25 @@ QPair Core::getKeypair() const 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(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 */ diff --git a/src/core/core.h b/src/core/core.h index be8fb93ef..e8a7444cd 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -111,6 +111,9 @@ public: ToxPk getSelfPublicKey() const override; QPair getKeypair() const; + QByteArray getSelfDhtId() const; + int getSelfUdpPort() const; + public slots: void start();