2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2007-2022 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-07-29 18:11:21 +00:00
|
|
|
|
2021-10-17 20:17:18 +00:00
|
|
|
#include <cerrno>
|
2022-02-26 01:26:31 +00:00
|
|
|
#include <future>
|
|
|
|
#include <mutex>
|
2022-03-15 14:52:16 +00:00
|
|
|
#include <string_view>
|
2022-02-26 01:26:31 +00:00
|
|
|
#include <thread>
|
2007-08-04 02:55:06 +00:00
|
|
|
|
2022-03-14 04:43:35 +00:00
|
|
|
#include <fmt/core.h>
|
|
|
|
|
2011-10-09 02:05:52 +00:00
|
|
|
#ifdef SYSTEM_MINIUPNP
|
2017-04-19 12:04:45 +00:00
|
|
|
#include <miniupnpc/miniupnpc.h>
|
|
|
|
#include <miniupnpc/upnpcommands.h>
|
2011-10-09 02:05:52 +00:00
|
|
|
#else
|
2017-04-19 12:04:45 +00:00
|
|
|
#include <miniupnp/miniupnpc.h>
|
|
|
|
#include <miniupnp/upnpcommands.h>
|
2011-10-09 02:05:52 +00:00
|
|
|
#endif
|
2007-07-14 16:29:21 +00:00
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
#include "transmission.h"
|
2013-01-25 23:34:20 +00:00
|
|
|
#include "log.h"
|
2008-04-11 17:01:13 +00:00
|
|
|
#include "port-forwarding.h"
|
|
|
|
#include "session.h"
|
2017-06-08 07:24:12 +00:00
|
|
|
#include "tr-assert.h"
|
2007-11-06 16:02:50 +00:00
|
|
|
#include "upnp.h"
|
2009-07-01 14:58:57 +00:00
|
|
|
#include "utils.h"
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
namespace
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2008-03-07 03:26:59 +00:00
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
enum class UpnpState
|
2007-12-08 19:34:15 +00:00
|
|
|
{
|
2022-02-26 01:26:31 +00:00
|
|
|
IDLE,
|
|
|
|
FAILED,
|
|
|
|
WILL_DISCOVER, // next action is upnpDiscover()
|
|
|
|
DISCOVERING, // currently making blocking upnpDiscover() call in a worker thread
|
|
|
|
WILL_MAP, // next action is UPNP_AddPortMapping()
|
|
|
|
WILL_UNMAP // next action is UPNP_DeletePortMapping()
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2007-12-08 19:34:15 +00:00
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
tr_port_forwarding portFwdState(UpnpState upnp_state, bool is_mapped)
|
|
|
|
{
|
|
|
|
switch (upnp_state)
|
|
|
|
{
|
|
|
|
case UpnpState::WILL_DISCOVER:
|
|
|
|
case UpnpState::DISCOVERING:
|
|
|
|
return TR_PORT_UNMAPPED;
|
|
|
|
|
|
|
|
case UpnpState::WILL_MAP:
|
|
|
|
return TR_PORT_MAPPING;
|
|
|
|
|
|
|
|
case UpnpState::WILL_UNMAP:
|
|
|
|
return TR_PORT_UNMAPPING;
|
|
|
|
|
|
|
|
case UpnpState::IDLE:
|
|
|
|
return is_mapped ? TR_PORT_MAPPED : TR_PORT_UNMAPPED;
|
|
|
|
|
|
|
|
default: // UpnpState::FAILED:
|
|
|
|
return TR_PORT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2007-11-06 16:02:50 +00:00
|
|
|
struct tr_upnp
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2022-01-23 17:16:36 +00:00
|
|
|
~tr_upnp()
|
|
|
|
{
|
|
|
|
TR_ASSERT(!isMapped);
|
2022-02-26 01:26:31 +00:00
|
|
|
TR_ASSERT(
|
|
|
|
state == UpnpState::IDLE || state == UpnpState::FAILED || state == UpnpState::WILL_DISCOVER ||
|
|
|
|
state == UpnpState::DISCOVERING);
|
2022-01-23 17:16:36 +00:00
|
|
|
|
|
|
|
FreeUPNPUrls(&urls);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasDiscovered = false;
|
2022-02-26 01:26:31 +00:00
|
|
|
UPNPUrls urls = {};
|
|
|
|
IGDdatas data = {};
|
2022-01-23 17:16:36 +00:00
|
|
|
int port = -1;
|
|
|
|
char lanaddr[16] = {};
|
|
|
|
bool isMapped = false;
|
2022-02-26 01:26:31 +00:00
|
|
|
UpnpState state = UpnpState::WILL_DISCOVER;
|
|
|
|
|
|
|
|
// Used to return the results of upnpDiscover() from a worker thread
|
|
|
|
// to be processed without blocking in tr_upnpPulse().
|
|
|
|
// This will be pending while the state is UpnpState::DISCOVERING.
|
|
|
|
std::optional<std::future<UPNPDev*>> discover_future;
|
2006-09-25 18:37:45 +00:00
|
|
|
};
|
|
|
|
|
2007-11-06 16:02:50 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-06-10 22:26:59 +00:00
|
|
|
|
2022-01-24 19:07:55 +00:00
|
|
|
tr_upnp* tr_upnpInit()
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2022-01-23 17:16:36 +00:00
|
|
|
return new tr_upnp();
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_upnpClose(tr_upnp* handle)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2022-01-23 17:16:36 +00:00
|
|
|
delete handle;
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
|
|
|
|
2011-10-09 02:05:52 +00:00
|
|
|
/**
|
|
|
|
*** Wrappers for miniupnpc functions
|
|
|
|
**/
|
|
|
|
|
2022-01-21 15:44:45 +00:00
|
|
|
static struct UPNPDev* tr_upnpDiscover(int msec, char const* bindaddr)
|
2011-10-09 02:05:52 +00:00
|
|
|
{
|
2021-10-19 16:09:38 +00:00
|
|
|
UPNPDev* ret = nullptr;
|
|
|
|
auto have_err = bool{};
|
2014-04-27 19:31:10 +00:00
|
|
|
|
|
|
|
#if (MINIUPNPC_API_VERSION >= 8) /* adds ipv6 and error args */
|
2017-04-19 12:04:45 +00:00
|
|
|
int err = UPNPDISCOVER_SUCCESS;
|
|
|
|
|
|
|
|
#if (MINIUPNPC_API_VERSION >= 14) /* adds ttl */
|
2022-01-21 15:44:45 +00:00
|
|
|
ret = upnpDiscover(msec, bindaddr, nullptr, 0, 0, 2, &err);
|
2017-04-19 12:04:45 +00:00
|
|
|
#else
|
2022-01-21 15:44:45 +00:00
|
|
|
ret = upnpDiscover(msec, bindaddr, nullptr, 0, 0, &err);
|
2017-04-19 12:04:45 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
have_err = err != UPNPDISCOVER_SUCCESS;
|
2014-04-27 19:31:10 +00:00
|
|
|
#else
|
2022-01-21 15:44:45 +00:00
|
|
|
ret = upnpDiscover(msec, bindaddr, nullptr, 0);
|
2021-09-15 00:18:09 +00:00
|
|
|
have_err = ret == nullptr;
|
2011-10-09 02:05:52 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (have_err)
|
|
|
|
{
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddDebug(fmt::format("upnpDiscover failed: {} ({})", tr_strerror(errno), errno));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-10-09 02:05:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ret;
|
2011-10-09 02:05:52 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static int tr_upnpGetSpecificPortMappingEntry(tr_upnp* handle, char const* proto)
|
2011-10-09 02:05:52 +00:00
|
|
|
{
|
|
|
|
char intClient[16];
|
|
|
|
char intPort[16];
|
|
|
|
char portStr[16];
|
|
|
|
|
|
|
|
*intClient = '\0';
|
|
|
|
*intPort = '\0';
|
|
|
|
|
2020-11-02 15:16:12 +00:00
|
|
|
tr_snprintf(portStr, sizeof(portStr), "%d", handle->port);
|
2014-04-27 19:31:10 +00:00
|
|
|
|
|
|
|
#if (MINIUPNPC_API_VERSION >= 10) /* adds remoteHost arg */
|
2021-10-19 16:09:38 +00:00
|
|
|
int const err = UPNP_GetSpecificPortMappingEntry(
|
2021-08-15 09:41:48 +00:00
|
|
|
handle->urls.controlURL,
|
|
|
|
handle->data.first.servicetype,
|
|
|
|
portStr,
|
|
|
|
proto,
|
2021-09-15 00:18:09 +00:00
|
|
|
nullptr /*remoteHost*/,
|
2021-08-15 09:41:48 +00:00
|
|
|
intClient,
|
|
|
|
intPort,
|
2021-09-15 00:18:09 +00:00
|
|
|
nullptr /*desc*/,
|
|
|
|
nullptr /*enabled*/,
|
|
|
|
nullptr /*duration*/);
|
2014-04-27 19:31:10 +00:00
|
|
|
#elif (MINIUPNPC_API_VERSION >= 8) /* adds desc, enabled and leaseDuration args */
|
2021-10-19 16:09:38 +00:00
|
|
|
int const err = UPNP_GetSpecificPortMappingEntry(
|
2021-08-15 09:41:48 +00:00
|
|
|
handle->urls.controlURL,
|
|
|
|
handle->data.first.servicetype,
|
|
|
|
portStr,
|
|
|
|
proto,
|
|
|
|
intClient,
|
|
|
|
intPort,
|
2021-09-15 00:18:09 +00:00
|
|
|
nullptr /*desc*/,
|
|
|
|
nullptr /*enabled*/,
|
|
|
|
nullptr /*duration*/);
|
2011-10-09 02:05:52 +00:00
|
|
|
#else
|
2021-10-19 16:09:38 +00:00
|
|
|
int const err = UPNP_GetSpecificPortMappingEntry(
|
2021-08-15 09:41:48 +00:00
|
|
|
handle->urls.controlURL,
|
|
|
|
handle->data.first.servicetype,
|
|
|
|
portStr,
|
|
|
|
proto,
|
|
|
|
intClient,
|
2017-04-19 12:04:45 +00:00
|
|
|
intPort);
|
2011-10-09 02:05:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static int tr_upnpAddPortMapping(tr_upnp const* handle, char const* proto, tr_port port, char const* desc)
|
2011-10-09 02:05:52 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const old_errno = errno;
|
2011-10-09 02:05:52 +00:00
|
|
|
char portStr[16];
|
|
|
|
errno = 0;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_snprintf(portStr, sizeof(portStr), "%d", (int)port);
|
2011-10-09 02:05:52 +00:00
|
|
|
|
2014-04-27 19:31:10 +00:00
|
|
|
#if (MINIUPNPC_API_VERSION >= 8)
|
2021-10-19 16:09:38 +00:00
|
|
|
int err = UPNP_AddPortMapping(
|
2021-08-15 09:41:48 +00:00
|
|
|
handle->urls.controlURL,
|
|
|
|
handle->data.first.servicetype,
|
|
|
|
portStr,
|
|
|
|
portStr,
|
|
|
|
handle->lanaddr,
|
|
|
|
desc,
|
|
|
|
proto,
|
2021-09-15 00:18:09 +00:00
|
|
|
nullptr,
|
|
|
|
nullptr);
|
2011-10-09 02:05:52 +00:00
|
|
|
#else
|
2021-10-19 16:09:38 +00:00
|
|
|
int err = UPNP_AddPortMapping(
|
2021-08-15 09:41:48 +00:00
|
|
|
handle->urls.controlURL,
|
|
|
|
handle->data.first.servicetype,
|
|
|
|
portStr,
|
|
|
|
portStr,
|
|
|
|
handle->lanaddr,
|
|
|
|
desc,
|
|
|
|
proto,
|
2021-09-15 00:18:09 +00:00
|
|
|
nullptr);
|
2011-10-09 02:05:52 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (err != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddDebug(fmt::format("{} Port forwarding failed with error {}: {} ({})", proto, err, tr_strerror(errno), errno));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-10-09 02:05:52 +00:00
|
|
|
|
|
|
|
errno = old_errno;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void tr_upnpDeletePortMapping(tr_upnp const* handle, char const* proto, tr_port port)
|
2011-10-09 02:05:52 +00:00
|
|
|
{
|
|
|
|
char portStr[16];
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_snprintf(portStr, sizeof(portStr), "%d", (int)port);
|
2011-10-09 02:05:52 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
UPNP_DeletePortMapping(handle->urls.controlURL, handle->data.first.servicetype, portStr, proto, nullptr);
|
2011-10-09 02:05:52 +00:00
|
|
|
}
|
|
|
|
|
2007-11-06 16:02:50 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-04-15 07:36:24 +00:00
|
|
|
|
2010-06-27 15:29:23 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
UPNP_IGD_NONE = 0,
|
|
|
|
UPNP_IGD_VALID_CONNECTED = 1,
|
|
|
|
UPNP_IGD_VALID_NOT_CONNECTED = 2,
|
|
|
|
UPNP_IGD_INVALID = 3
|
2010-06-27 15:29:23 +00:00
|
|
|
};
|
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
static auto* discoverThreadfunc(char* bindaddr)
|
|
|
|
{
|
|
|
|
auto* const ret = tr_upnpDiscover(2000, bindaddr);
|
|
|
|
tr_free(bindaddr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
static bool isFutureReady(std::future<T> const& future)
|
|
|
|
{
|
|
|
|
return future.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
|
|
|
|
}
|
|
|
|
|
2022-01-21 15:44:45 +00:00
|
|
|
tr_port_forwarding tr_upnpPulse(tr_upnp* handle, tr_port port, bool isEnabled, bool doPortCheck, char const* bindaddr)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2022-02-26 01:26:31 +00:00
|
|
|
if (isEnabled && handle->state == UpnpState::WILL_DISCOVER)
|
2007-11-09 16:10:48 +00:00
|
|
|
{
|
2022-02-26 01:26:31 +00:00
|
|
|
TR_ASSERT(!handle->discover_future);
|
|
|
|
|
|
|
|
auto task = std::packaged_task<UPNPDev*(char*)>{ discoverThreadfunc };
|
|
|
|
handle->discover_future = task.get_future();
|
|
|
|
handle->state = UpnpState::DISCOVERING;
|
|
|
|
|
|
|
|
std::thread(std::move(task), tr_strdup(bindaddr)).detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isEnabled && handle->state == UpnpState::DISCOVERING && handle->discover_future &&
|
|
|
|
isFutureReady(*handle->discover_future))
|
|
|
|
{
|
|
|
|
auto* const devlist = handle->discover_future->get();
|
|
|
|
handle->discover_future.reset();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-01-23 17:16:36 +00:00
|
|
|
FreeUPNPUrls(&handle->urls);
|
2021-08-15 09:41:48 +00:00
|
|
|
if (UPNP_GetValidIGD(devlist, &handle->urls, &handle->data, handle->lanaddr, sizeof(handle->lanaddr)) ==
|
|
|
|
UPNP_IGD_VALID_CONNECTED)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(fmt::format(_("Found Internet Gateway Device '{url}'"), fmt::arg("url", handle->urls.controlURL)));
|
|
|
|
tr_logAddInfo(fmt::format(_("Local Address is '{address}')"), fmt::arg("address", handle->lanaddr)));
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::IDLE;
|
2014-11-30 19:38:47 +00:00
|
|
|
handle->hasDiscovered = true;
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::FAILED;
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddDebug(fmt::format("UPNP_GetValidIGD failed: {} ({})", tr_strerror(errno), errno));
|
2022-03-11 21:09:22 +00:00
|
|
|
tr_logAddDebug("If your router supports UPnP, please make sure UPnP is enabled!");
|
2007-11-09 16:10:48 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
freeUPNPDevlist(devlist);
|
2007-11-09 16:10:48 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
if ((handle->state == UpnpState::IDLE) && (handle->isMapped) && (!isEnabled || handle->port != port))
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::WILL_UNMAP;
|
2007-06-10 22:26:59 +00:00
|
|
|
}
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (isEnabled && handle->isMapped && doPortCheck &&
|
2020-11-01 21:47:57 +00:00
|
|
|
((tr_upnpGetSpecificPortMappingEntry(handle, "TCP") != UPNPCOMMAND_SUCCESS) ||
|
2021-08-15 09:41:48 +00:00
|
|
|
(tr_upnpGetSpecificPortMappingEntry(handle, "UDP") != UPNPCOMMAND_SUCCESS)))
|
2009-04-22 16:00:45 +00:00
|
|
|
{
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(fmt::format(_("Port {port} is not forwarded"), fmt::arg("port", handle->port)));
|
2020-11-01 21:47:57 +00:00
|
|
|
handle->isMapped = false;
|
2009-04-22 16:00:45 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
if (handle->state == UpnpState::WILL_UNMAP)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_upnpDeletePortMapping(handle, "TCP", handle->port);
|
|
|
|
tr_upnpDeletePortMapping(handle, "UDP", handle->port);
|
2011-10-09 02:05:52 +00:00
|
|
|
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(fmt::format(
|
|
|
|
_("Stopping port forwarding through '{url}', service '{type}'"),
|
|
|
|
fmt::arg("url", handle->urls.controlURL),
|
|
|
|
fmt::arg("type", handle->data.first.servicetype)));
|
2011-10-09 02:05:52 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
handle->isMapped = false;
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::IDLE;
|
2007-12-08 19:34:15 +00:00
|
|
|
handle->port = -1;
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
if ((handle->state == UpnpState::IDLE) && isEnabled && !handle->isMapped)
|
2007-12-08 19:34:15 +00:00
|
|
|
{
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::WILL_MAP;
|
2007-12-08 19:34:15 +00:00
|
|
|
}
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
if (handle->state == UpnpState::WILL_MAP)
|
2007-12-08 19:34:15 +00:00
|
|
|
{
|
2007-12-09 17:50:05 +00:00
|
|
|
errno = 0;
|
2007-12-24 07:02:40 +00:00
|
|
|
|
2021-09-15 00:18:09 +00:00
|
|
|
if (handle->urls.controlURL == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2019-07-14 12:40:41 +00:00
|
|
|
handle->isMapped = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
else
|
|
|
|
{
|
2008-12-10 06:12:04 +00:00
|
|
|
char desc[64];
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_snprintf(desc, sizeof(desc), "%s at %d", TR_NAME, port);
|
2011-01-15 17:06:11 +00:00
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
int const err_tcp = tr_upnpAddPortMapping(handle, "TCP", port, desc);
|
|
|
|
int const err_udp = tr_upnpAddPortMapping(handle, "UDP", port, desc);
|
2011-10-09 02:05:52 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
handle->isMapped = err_tcp == 0 || err_udp == 0;
|
2007-12-24 07:02:40 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(fmt::format(
|
|
|
|
_("Port forwarding through '{url}', service '{type}'. (local address: {address}:{port})"),
|
|
|
|
fmt::arg("url", handle->urls.controlURL),
|
|
|
|
fmt::arg("type", handle->data.first.servicetype),
|
|
|
|
fmt::arg("address", handle->lanaddr),
|
|
|
|
fmt::arg("port", port)));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (handle->isMapped)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(_("Port forwarding successful!"));
|
2007-12-08 19:34:15 +00:00
|
|
|
handle->port = port;
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::IDLE;
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-14 04:43:35 +00:00
|
|
|
tr_logAddInfo(_("If your router supports UPnP, please make sure UPnP is enabled!"));
|
2007-12-08 19:34:15 +00:00
|
|
|
handle->port = -1;
|
2022-02-26 01:26:31 +00:00
|
|
|
handle->state = UpnpState::FAILED;
|
2007-12-08 19:34:15 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2022-02-26 01:26:31 +00:00
|
|
|
return portFwdState(handle->state, handle->isMapped);
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|