From 3fb3b449c98d18224144181a0f21d84b6958cbb6 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sun, 10 Mar 2024 20:34:30 +0100 Subject: [PATCH] get port from tox --- plugins/plugin_tox_upnp.cpp | 3 ++- src/CMakeLists.txt | 1 + src/solanaceae/tox_upnp.cpp | 7 ++++++- src/solanaceae/tox_upnp.hpp | 6 +++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/plugin_tox_upnp.cpp b/plugins/plugin_tox_upnp.cpp index 6659bbb..ebde423 100644 --- a/plugins/plugin_tox_upnp.cpp +++ b/plugins/plugin_tox_upnp.cpp @@ -29,10 +29,11 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) try { // TODO: toxI + auto* tox_i = PLUG_RESOLVE_INSTANCE(ToxI); // static store, could be anywhere tho // construct with fetched dependencies - g_tox_upnp = std::make_unique(); + g_tox_upnp = std::make_unique(*tox_i); // register types PLUG_PROVIDE_INSTANCE(ToxUPnP, plugin_name, g_tox_upnp.get()); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f381e27..f4535b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,5 +13,6 @@ target_include_directories(solanaceae_tox_upnp PUBLIC .) target_compile_features(solanaceae_tox_upnp PUBLIC cxx_std_17) target_link_libraries(solanaceae_tox_upnp PUBLIC miniupnpc::miniupnpc + solanaceae_toxcore_interface ) diff --git a/src/solanaceae/tox_upnp.cpp b/src/solanaceae/tox_upnp.cpp index bd21fad..04360f4 100644 --- a/src/solanaceae/tox_upnp.cpp +++ b/src/solanaceae/tox_upnp.cpp @@ -8,8 +8,13 @@ #include -ToxUPnP::ToxUPnP(void) { +ToxUPnP::ToxUPnP(ToxI& tox) { // get tox port + auto [port_opt, _] = tox.toxSelfGetUDPPort(); + if (!port_opt.has_value()) { + return; // oof + } + _local_port = port_opt.value(); // start upnp thread _thread = std::thread([this](void) { diff --git a/src/solanaceae/tox_upnp.hpp b/src/solanaceae/tox_upnp.hpp index 71ef98c..16581b8 100644 --- a/src/solanaceae/tox_upnp.hpp +++ b/src/solanaceae/tox_upnp.hpp @@ -4,16 +4,16 @@ #include #include -class ToxUPnP { - // TODO: ToxI& _t; +#include +class ToxUPnP { uint16_t _local_port {33445}; std::atomic_bool _quit {false}; std::thread _thread; public: - ToxUPnP(void); + ToxUPnP(ToxI& tox); ~ToxUPnP(void); };