i2pd/daemon/UPnP.h

91 lines
1.7 KiB
C
Raw Normal View History

#ifndef __UPNP_H__
#define __UPNP_H__
#ifdef USE_UPNP
#include <string>
#include <thread>
2016-07-31 14:22:41 +00:00
#include <condition_variable>
#include <mutex>
2016-07-18 18:01:58 +00:00
#include <memory>
#include <miniupnpc/miniwget.h>
#include <miniupnpc/miniupnpc.h>
#include <miniupnpc/upnpcommands.h>
#include <miniupnpc/upnperrors.h>
2014-02-09 20:15:47 +00:00
#include <boost/asio.hpp>
namespace i2p
{
namespace transport
{
const int UPNP_RESPONSE_TIMEOUT = 2000; // in milliseconds
enum
{
UPNP_IGD_NONE = 0,
UPNP_IGD_VALID_CONNECTED = 1,
UPNP_IGD_VALID_NOT_CONNECTED = 2,
UPNP_IGD_INVALID = 3
};
2014-02-09 20:15:47 +00:00
class UPnP
{
public:
UPnP ();
~UPnP ();
void Close ();
void Start ();
void Stop ();
private:
2016-07-18 18:01:58 +00:00
void Discover ();
int CheckMapping (const char* port, const char* type);
2016-07-18 18:01:58 +00:00
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 ();
2016-07-18 18:01:58 +00:00
std::string GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address);
private:
2018-01-06 03:48:51 +00:00
2016-07-18 18:01:58 +00:00
bool m_IsRunning;
std::unique_ptr<std::thread> m_Thread;
2018-01-06 03:48:51 +00:00
std::condition_variable m_Started;
std::mutex m_StartedMutex;
2016-07-18 18:01:58 +00:00
boost::asio::io_service m_Service;
2018-01-06 03:48:51 +00:00
boost::asio::deadline_timer m_Timer;
2019-09-05 19:21:26 +00:00
bool m_upnpUrlsInitialized=false;
struct UPNPUrls m_upnpUrls;
struct IGDdatas m_upnpData;
// For miniupnpc
struct UPNPDev * m_Devlist = 0;
char m_NetworkAddr[64];
char m_externalIPAddress[40];
};
2014-02-09 20:15:47 +00:00
}
}
#else // USE_UPNP
namespace i2p {
namespace transport {
/* class stub */
class UPnP {
public:
UPnP () {};
~UPnP () {};
void Start () { LogPrint(eLogWarning, "UPnP: this module was disabled at compile-time"); }
void Stop () {};
};
}
}
2016-03-24 00:00:00 +00:00
#endif // USE_UPNP
#endif // __UPNP_H__