mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
Run UPnP discovery in the background
This commit is contained in:
parent
a7db46d69b
commit
bb4c7f0298
5 changed files with 66 additions and 12 deletions
11
.github/workflows/c-cpp.yml
vendored
11
.github/workflows/c-cpp.yml
vendored
|
@ -251,10 +251,9 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
config:
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\", rx: "ON"}
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\", rx: "OFF"}
|
||||
#- {vs: Visual Studio 17 2022, os: 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\", rx: "ON"}
|
||||
#- {vs: Visual Studio 17 2022, os: 2022, msbuild: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\", rx: "OFF"}
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\", rx: "ON", upnp: "ON"}
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\", rx: "OFF", upnp: "ON"}
|
||||
- {vs: Visual Studio 16 2019, os: 2019, msbuild: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\amd64\\", rx: "OFF", upnp: "OFF"}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
|
@ -269,7 +268,7 @@ jobs:
|
|||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -G "${{ matrix.config.vs }}" -DWITH_RANDOMX=${{ matrix.config.rx }}
|
||||
cmake .. -G "${{ matrix.config.vs }}" -DWITH_RANDOMX=${{ matrix.config.rx }} -DWITH_UPNP=${{ matrix.config.upnp }}
|
||||
& "${{ matrix.config.msbuild }}msbuild" /m /p:Configuration=Release p2pool.vcxproj
|
||||
|
||||
- name: Build tests
|
||||
|
@ -288,7 +287,7 @@ jobs:
|
|||
- name: Archive binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: p2pool-msbuild-${{ matrix.config.os }}-randomx-${{ matrix.config.rx }}.exe
|
||||
name: p2pool-msbuild-${{ matrix.config.os }}-randomx-${{ matrix.config.rx }}-upnp-${{ matrix.config.upnp }}.exe
|
||||
path: build/Release/p2pool.exe
|
||||
|
||||
build-macos:
|
||||
|
|
6
.github/workflows/test-sync.yml
vendored
6
.github/workflows/test-sync.yml
vendored
|
@ -24,7 +24,7 @@ jobs:
|
|||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DWITH_UPNP=OFF -DDEV_TEST_SYNC=ON -DCMAKE_C_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12
|
||||
cmake .. -DDEV_TEST_SYNC=ON -DCMAKE_C_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12
|
||||
make -j$(nproc)
|
||||
|
||||
- name: Run p2pool
|
||||
|
@ -60,7 +60,7 @@ jobs:
|
|||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DWITH_UPNP=OFF -DDEV_TEST_SYNC=ON
|
||||
cmake .. -DDEV_TEST_SYNC=ON
|
||||
make -j3
|
||||
|
||||
- name: Run p2pool
|
||||
|
@ -96,7 +96,7 @@ jobs:
|
|||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -G "Visual Studio 17 2022" -DWITH_UPNP=OFF -DDEV_TEST_SYNC=ON
|
||||
cmake .. -G "Visual Studio 17 2022" -DDEV_TEST_SYNC=ON
|
||||
& "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Msbuild\\Current\\Bin\\amd64\\msbuild" /m /p:Configuration=Debug p2pool.vcxproj
|
||||
|
||||
- name: Run p2pool
|
||||
|
|
|
@ -60,6 +60,12 @@ p2pool::p2pool(int argc, char* argv[])
|
|||
{
|
||||
LOGINFO(1, log::LightCyan() << VERSION);
|
||||
|
||||
#ifdef WITH_UPNP
|
||||
if (m_params->m_upnp) {
|
||||
init_upnp();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_params->m_wallet.valid()) {
|
||||
LOGERR(1, "Invalid wallet address. Try \"p2pool --help\".");
|
||||
throw std::exception();
|
||||
|
@ -189,6 +195,12 @@ p2pool::p2pool(int argc, char* argv[])
|
|||
|
||||
p2pool::~p2pool()
|
||||
{
|
||||
#ifdef WITH_UPNP
|
||||
if (m_params->m_upnp) {
|
||||
destroy_upnp();
|
||||
}
|
||||
#endif
|
||||
|
||||
uv_rwlock_destroy(&m_mainchainLock);
|
||||
uv_rwlock_destroy(&m_minerDataLock);
|
||||
uv_mutex_destroy(&m_foundBlocksLock);
|
||||
|
|
47
src/util.cpp
47
src/util.cpp
|
@ -568,17 +568,58 @@ UV_LoopUserData* GetLoopUserData(uv_loop_t* loop, bool create)
|
|||
#ifdef WITH_UPNP
|
||||
static struct UPnP_Discover
|
||||
{
|
||||
UPnP_Discover() { devlist = upnpDiscover(1000, nullptr, nullptr, UPNP_LOCAL_PORT_ANY, 0, 2, &error); }
|
||||
~UPnP_Discover() { freeUPNPDevlist(devlist); }
|
||||
|
||||
uv_mutex_t lock;
|
||||
int error;
|
||||
UPNPDev* devlist;
|
||||
} upnp_discover;
|
||||
|
||||
void init_upnp()
|
||||
{
|
||||
uv_mutex_init_checked(&upnp_discover.lock);
|
||||
|
||||
uv_work_t* req = new uv_work_t{};
|
||||
|
||||
const int err = uv_queue_work(uv_default_loop_checked(), req,
|
||||
[](uv_work_t* /*req*/)
|
||||
{
|
||||
BACKGROUND_JOB_START(init_upnp);
|
||||
LOGINFO(1, "UPnP: Started scanning for UPnP IGD devices");
|
||||
{
|
||||
MutexLock lock(upnp_discover.lock);
|
||||
upnp_discover.devlist = upnpDiscover(1000, nullptr, nullptr, UPNP_LOCAL_PORT_ANY, 0, 2, &upnp_discover.error);
|
||||
}
|
||||
LOGINFO(1, "UPnP: Finished scanning for UPnP IGD devices");
|
||||
},
|
||||
[](uv_work_t* req, int /*status*/)
|
||||
{
|
||||
delete req;
|
||||
BACKGROUND_JOB_STOP(init_upnp);
|
||||
}
|
||||
);
|
||||
|
||||
if (err) {
|
||||
LOGERR(0, "init_upnp: uv_queue_work failed, error " << uv_err_name(err));
|
||||
delete req;
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_upnp()
|
||||
{
|
||||
{
|
||||
MutexLock lock(upnp_discover.lock);
|
||||
|
||||
freeUPNPDevlist(upnp_discover.devlist);
|
||||
upnp_discover.devlist = nullptr;
|
||||
}
|
||||
uv_mutex_destroy(&upnp_discover.lock);
|
||||
}
|
||||
|
||||
void add_portmapping(int external_port, int internal_port)
|
||||
{
|
||||
LOGINFO(1, "UPnP: trying to map WAN:" << external_port << " to LAN:" << internal_port);
|
||||
|
||||
MutexLock lock(upnp_discover.lock);
|
||||
|
||||
if (!upnp_discover.devlist) {
|
||||
LOGWARN(1, "upnpDiscover: no UPnP IGD devices found, error " << upnp_discover.error);
|
||||
return;
|
||||
|
|
|
@ -247,6 +247,8 @@ bool str_to_ip(bool is_v6, const char* ip, raw_ip& result);
|
|||
bool is_localhost(const std::string& host);
|
||||
|
||||
#ifdef WITH_UPNP
|
||||
void init_upnp();
|
||||
void destroy_upnp();
|
||||
void add_portmapping(int external_port, int internal_port);
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue