PortMapper.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifdef ZT_USE_MINIUPNPC
  19. #ifndef ZT_PORTMAPPER_HPP
  20. #define ZT_PORTMAPPER_HPP
  21. #include <vector>
  22. #include "../node/Constants.hpp"
  23. #include "../node/InetAddress.hpp"
  24. #include "../node/Mutex.hpp"
  25. #include "Thread.hpp"
  26. /**
  27. * How frequently should we refresh our UPNP/NAT-PnP/whatever state?
  28. */
  29. #define ZT_PORTMAPPER_REFRESH_DELAY 300000
  30. namespace ZeroTier {
  31. class PortMapperImpl;
  32. /**
  33. * UPnP/NAT-PnP port mapping "daemon"
  34. */
  35. class PortMapper
  36. {
  37. friend class PortMapperImpl;
  38. public:
  39. /**
  40. * Create and start port mapper service
  41. *
  42. * @param localUdpPortToMap Port we want visible to the outside world
  43. * @param name Unique name of this endpoint (based on ZeroTier address)
  44. */
  45. PortMapper(int localUdpPortToMap,const char *uniqueName);
  46. ~PortMapper();
  47. /**
  48. * @return All current external mappings for our port
  49. */
  50. std::vector<InetAddress> get() const;
  51. private:
  52. PortMapperImpl *_impl;
  53. };
  54. } // namespace ZeroTier
  55. #endif
  56. #endif // ZT_USE_MINIUPNPC