PortMapper.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  4. *
  5. * (c) ZeroTier, Inc.
  6. * https://www.zerotier.com/
  7. */
  8. #ifdef ZT_USE_MINIUPNPC
  9. #ifndef ZT_PORTMAPPER_HPP
  10. #define ZT_PORTMAPPER_HPP
  11. #include "../node/Constants.hpp"
  12. #include "../node/InetAddress.hpp"
  13. #include "../node/Mutex.hpp"
  14. #include "Thread.hpp"
  15. #include <vector>
  16. /**
  17. * How frequently should we refresh our UPNP/NAT-PnP/whatever state?
  18. */
  19. #define ZT_PORTMAPPER_REFRESH_DELAY 300000
  20. namespace ZeroTier {
  21. class PortMapperImpl;
  22. /**
  23. * UPnP/NAT-PnP port mapping "daemon"
  24. */
  25. class PortMapper {
  26. friend class PortMapperImpl;
  27. public:
  28. /**
  29. * Create and start port mapper service
  30. *
  31. * @param localUdpPortToMap Port we want visible to the outside world
  32. * @param name Unique name of this endpoint (based on ZeroTier address)
  33. */
  34. PortMapper(int localUdpPortToMap, const char* uniqueName);
  35. ~PortMapper();
  36. /**
  37. * @return All current external mappings for our port
  38. */
  39. std::vector<InetAddress> get() const;
  40. private:
  41. PortMapperImpl* _impl;
  42. };
  43. } // namespace ZeroTier
  44. #endif
  45. #endif // ZT_USE_MINIUPNPC