UPnP.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef __UPNP_H__
  2. #define __UPNP_H__
  3. #ifdef USE_UPNP
  4. #include <string>
  5. #include <thread>
  6. #include <condition_variable>
  7. #include <mutex>
  8. #include <memory>
  9. #include <miniupnpc/miniwget.h>
  10. #include <miniupnpc/miniupnpc.h>
  11. #include <miniupnpc/upnpcommands.h>
  12. #include <miniupnpc/upnperrors.h>
  13. #include <boost/asio.hpp>
  14. namespace i2p
  15. {
  16. namespace transport
  17. {
  18. class UPnP
  19. {
  20. public:
  21. UPnP ();
  22. ~UPnP ();
  23. void Close ();
  24. void Start ();
  25. void Stop ();
  26. private:
  27. void Discover ();
  28. void PortMapping ();
  29. void TryPortMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
  30. void CloseMapping ();
  31. void CloseMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
  32. void Run ();
  33. std::string GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address);
  34. private:
  35. bool m_IsRunning;
  36. std::unique_ptr<std::thread> m_Thread;
  37. std::condition_variable m_Started;
  38. std::mutex m_StartedMutex;
  39. boost::asio::io_service m_Service;
  40. boost::asio::deadline_timer m_Timer;
  41. struct UPNPUrls m_upnpUrls;
  42. struct IGDdatas m_upnpData;
  43. // For miniupnpc
  44. char * m_MulticastIf = 0;
  45. char * m_Minissdpdpath = 0;
  46. struct UPNPDev * m_Devlist = 0;
  47. char m_NetworkAddr[64];
  48. char m_externalIPAddress[40];
  49. };
  50. }
  51. }
  52. #else // USE_UPNP
  53. namespace i2p {
  54. namespace transport {
  55. /* class stub */
  56. class UPnP {
  57. public:
  58. UPnP () {};
  59. ~UPnP () {};
  60. void Start () { LogPrint(eLogWarning, "UPnP: this module was disabled at compile-time"); }
  61. void Stop () {};
  62. };
  63. }
  64. }
  65. #endif // USE_UPNP
  66. #endif // __UPNP_H__