mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
[upnp] fix code
This commit is contained in:
parent
06066a4df5
commit
2f516d03a5
2 changed files with 56 additions and 54 deletions
|
@ -79,9 +79,10 @@ namespace transport
|
||||||
|
|
||||||
void UPnP::Discover ()
|
void UPnP::Discover ()
|
||||||
{
|
{
|
||||||
|
bool isError;
|
||||||
|
|
||||||
#if (MINIUPNPC_API_VERSION >= 8)
|
#if (MINIUPNPC_API_VERSION >= 8)
|
||||||
int err = UPNPDISCOVER_SUCCESS;
|
int err = UPNPDISCOVER_SUCCESS;
|
||||||
bool isError;
|
|
||||||
|
|
||||||
#if (MINIUPNPC_API_VERSION >= 14)
|
#if (MINIUPNPC_API_VERSION >= 14)
|
||||||
m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0, 0, 2, &err);
|
m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0, 0, 2, &err);
|
||||||
|
@ -92,7 +93,7 @@ namespace transport
|
||||||
isError = err != UPNPDISCOVER_SUCCESS;
|
isError = err != UPNPDISCOVER_SUCCESS;
|
||||||
#else
|
#else
|
||||||
m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0);
|
m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0);
|
||||||
isError = err == NULL;
|
isError = m_Devlist == NULL;
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// notify starting thread
|
// notify starting thread
|
||||||
|
|
105
daemon/UPnP.h
105
daemon/UPnP.h
|
@ -17,72 +17,73 @@
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace transport
|
namespace transport
|
||||||
|
{
|
||||||
|
const int UPNP_RESPONSE_TIMEOUT = 2000; // in milliseconds
|
||||||
|
|
||||||
|
enum
|
||||||
{
|
{
|
||||||
const int UPNP_RESPONSE_TIMEOUT = 2000; // in milliseconds
|
UPNP_IGD_NONE = 0,
|
||||||
|
UPNP_IGD_VALID_CONNECTED = 1,
|
||||||
|
UPNP_IGD_VALID_NOT_CONNECTED = 2,
|
||||||
|
UPNP_IGD_INVALID = 3
|
||||||
|
};
|
||||||
|
|
||||||
enum
|
class UPnP
|
||||||
{
|
{
|
||||||
UPNP_IGD_NONE = 0,
|
public:
|
||||||
UPNP_IGD_VALID_CONNECTED = 1,
|
|
||||||
UPNP_IGD_VALID_NOT_CONNECTED = 2,
|
|
||||||
UPNP_IGD_INVALID = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
class UPnP
|
UPnP ();
|
||||||
{
|
~UPnP ();
|
||||||
public:
|
void Close ();
|
||||||
|
|
||||||
UPnP ();
|
void Start ();
|
||||||
~UPnP ();
|
void Stop ();
|
||||||
void Close ();
|
|
||||||
|
|
||||||
void Start ();
|
private:
|
||||||
void Stop ();
|
|
||||||
|
|
||||||
private:
|
void Discover ();
|
||||||
|
int CheckMapping (const char* port, const char* type);
|
||||||
|
void PortMapping ();
|
||||||
|
void TryPortMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
|
||||||
|
void CloseMapping ();
|
||||||
|
void CloseMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
|
||||||
|
|
||||||
void Discover ();
|
void Run ();
|
||||||
int CheckMapping (const char* port, const char* type);
|
std::string GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address);
|
||||||
void PortMapping ();
|
|
||||||
void TryPortMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
|
|
||||||
void CloseMapping ();
|
|
||||||
void CloseMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
|
|
||||||
|
|
||||||
void Run ();
|
private:
|
||||||
std::string GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address);
|
|
||||||
|
|
||||||
private:
|
bool m_IsRunning;
|
||||||
|
std::unique_ptr<std::thread> m_Thread;
|
||||||
|
std::condition_variable m_Started;
|
||||||
|
std::mutex m_StartedMutex;
|
||||||
|
boost::asio::io_service m_Service;
|
||||||
|
boost::asio::deadline_timer m_Timer;
|
||||||
|
struct UPNPUrls m_upnpUrls;
|
||||||
|
struct IGDdatas m_upnpData;
|
||||||
|
|
||||||
bool m_IsRunning;
|
// For miniupnpc
|
||||||
std::unique_ptr<std::thread> m_Thread;
|
struct UPNPDev * m_Devlist = 0;
|
||||||
std::condition_variable m_Started;
|
char m_NetworkAddr[64];
|
||||||
std::mutex m_StartedMutex;
|
char m_externalIPAddress[40];
|
||||||
boost::asio::io_service m_Service;
|
};
|
||||||
boost::asio::deadline_timer m_Timer;
|
}
|
||||||
struct UPNPUrls m_upnpUrls;
|
|
||||||
struct IGDdatas m_upnpData;
|
|
||||||
|
|
||||||
// For miniupnpc
|
|
||||||
struct UPNPDev * m_Devlist = 0;
|
|
||||||
char m_NetworkAddr[64];
|
|
||||||
char m_externalIPAddress[40];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // USE_UPNP
|
#else // USE_UPNP
|
||||||
namespace i2p {
|
namespace i2p {
|
||||||
namespace transport {
|
namespace transport {
|
||||||
/* class stub */
|
/* class stub */
|
||||||
class UPnP {
|
class UPnP {
|
||||||
public:
|
public:
|
||||||
UPnP () {};
|
|
||||||
~UPnP () {};
|
UPnP () {};
|
||||||
void Start () { LogPrint(eLogWarning, "UPnP: this module was disabled at compile-time"); }
|
~UPnP () {};
|
||||||
void Stop () {};
|
void Start () { LogPrint(eLogWarning, "UPnP: this module was disabled at compile-time"); }
|
||||||
};
|
void Stop () {};
|
||||||
}
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_UPNP
|
#endif // USE_UPNP
|
||||||
#endif // __UPNP_H__
|
#endif // __UPNP_H__
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue