PortMapper.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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: 2023-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. #ifndef ZT_PORTMAPPER_HPP
  14. #define ZT_PORTMAPPER_HPP
  15. #include <vector>
  16. #include "../node/Constants.hpp"
  17. #include "../node/InetAddress.hpp"
  18. #include "../node/Mutex.hpp"
  19. #include "Thread.hpp"
  20. /**
  21. * How frequently should we refresh our UPNP/NAT-PnP/whatever state?
  22. */
  23. #define ZT_PORTMAPPER_REFRESH_DELAY 120000
  24. namespace ZeroTier {
  25. class PortMapperImpl;
  26. /**
  27. * UPnP/NAT-PnP port mapping "daemon"
  28. */
  29. class PortMapper
  30. {
  31. friend class PortMapperImpl;
  32. public:
  33. /**
  34. * Create and start port mapper service
  35. *
  36. * @param localUdpPortToMap Port we want visible to the outside world
  37. * @param name Unique name of this endpoint (based on ZeroTier address)
  38. */
  39. PortMapper(int localUdpPortToMap,const char *uniqueName);
  40. ~PortMapper();
  41. /**
  42. * @return All current external mappings for our port
  43. */
  44. std::vector<InetAddress> get() const;
  45. private:
  46. PortMapperImpl *_impl;
  47. };
  48. } // namespace ZeroTier
  49. #endif