PortMapper.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2026-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifdef ZT_USE_MINIUPNPC
  14. #ifndef ZT_PORTMAPPER_HPP
  15. #define ZT_PORTMAPPER_HPP
  16. #include <vector>
  17. #include "../node/Constants.hpp"
  18. #include "../node/InetAddress.hpp"
  19. #include "../node/Mutex.hpp"
  20. #include "Thread.hpp"
  21. /**
  22. * How frequently should we refresh our UPNP/NAT-PnP/whatever state?
  23. */
  24. #define ZT_PORTMAPPER_REFRESH_DELAY 300000
  25. namespace ZeroTier {
  26. class PortMapperImpl;
  27. /**
  28. * UPnP/NAT-PnP port mapping "daemon"
  29. */
  30. class PortMapper
  31. {
  32. friend class PortMapperImpl;
  33. public:
  34. /**
  35. * Create and start port mapper service
  36. *
  37. * @param localUdpPortToMap Port we want visible to the outside world
  38. * @param name Unique name of this endpoint (based on ZeroTier address)
  39. */
  40. PortMapper(int localUdpPortToMap,const char *uniqueName);
  41. ~PortMapper();
  42. /**
  43. * @return All current external mappings for our port
  44. */
  45. std::vector<InetAddress> get() const;
  46. private:
  47. PortMapperImpl *_impl;
  48. };
  49. } // namespace ZeroTier
  50. #endif
  51. #endif // ZT_USE_MINIUPNPC