PortMapper.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2017 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. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #ifdef ZT_USE_MINIUPNPC
  27. #ifndef ZT_PORTMAPPER_HPP
  28. #define ZT_PORTMAPPER_HPP
  29. #include <vector>
  30. #include "../node/Constants.hpp"
  31. #include "../node/InetAddress.hpp"
  32. #include "../node/Mutex.hpp"
  33. #include "Thread.hpp"
  34. /**
  35. * How frequently should we refresh our UPNP/NAT-PnP/whatever state?
  36. */
  37. #define ZT_PORTMAPPER_REFRESH_DELAY 300000
  38. namespace ZeroTier {
  39. class PortMapperImpl;
  40. /**
  41. * UPnP/NAT-PnP port mapping "daemon"
  42. */
  43. class PortMapper
  44. {
  45. friend class PortMapperImpl;
  46. public:
  47. /**
  48. * Create and start port mapper service
  49. *
  50. * @param localUdpPortToMap Port we want visible to the outside world
  51. * @param name Unique name of this endpoint (based on ZeroTier address)
  52. */
  53. PortMapper(int localUdpPortToMap,const char *uniqueName);
  54. ~PortMapper();
  55. /**
  56. * @return All current external mappings for our port
  57. */
  58. std::vector<InetAddress> get() const;
  59. private:
  60. PortMapperImpl *_impl;
  61. };
  62. } // namespace ZeroTier
  63. #endif
  64. #endif // ZT_USE_MINIUPNPC