Path.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  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. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef ZT_PATH_HPP
  28. #define ZT_PATH_HPP
  29. #include "Constants.hpp"
  30. #include "InetAddress.hpp"
  31. #include "Utils.hpp"
  32. namespace ZeroTier {
  33. class Path
  34. {
  35. public:
  36. // Must be the same values as ZT1_LocalInterfaceAddressTrust in ZeroTierOne.h
  37. enum Trust
  38. {
  39. TRUST_NORMAL = 0,
  40. TRUST_PRIVACY = 1,
  41. TRUST_ULTIMATE = 2
  42. };
  43. Path() :
  44. _addr(),
  45. _metric(0),
  46. _trust(TRUST_NORMAL),
  47. _reliable(false)
  48. {
  49. }
  50. Path(const InetAddress &addr,int metric,Trust trust,bool reliable) :
  51. _addr(addr),
  52. _metric(metric),
  53. _trust(trust),
  54. _reliable(reliable)
  55. {
  56. }
  57. /**
  58. * @return Physical address
  59. */
  60. inline const InetAddress &address() const throw() { return _addr; }
  61. /**
  62. * @return Metric (higher == worse) or negative if path is blacklisted
  63. */
  64. inline int metric() const throw() { return _metric; }
  65. /**
  66. * @return Path trust level
  67. */
  68. inline Trust trust() const throw() { return _trust; }
  69. /**
  70. * @return True if path is considered reliable (no NAT keepalives etc. are needed)
  71. */
  72. inline bool reliable() const throw() { return _reliable; }
  73. /**
  74. * @return True if address is non-NULL
  75. */
  76. inline operator bool() const throw() { return (_addr); }
  77. // Comparisons are by address only
  78. inline bool operator==(const Path &p) const throw() { return (_addr == p._addr); }
  79. inline bool operator!=(const Path &p) const throw() { return (_addr != p._addr); }
  80. inline bool operator<(const Path &p) const throw() { return (_addr < p._addr); }
  81. inline bool operator>(const Path &p) const throw() { return (_addr > p._addr); }
  82. inline bool operator<=(const Path &p) const throw() { return (_addr <= p._addr); }
  83. inline bool operator>=(const Path &p) const throw() { return (_addr >= p._addr); }
  84. protected:
  85. InetAddress _addr;
  86. int _metric; // negative == blacklisted
  87. Trust _trust;
  88. bool _reliable;
  89. };
  90. } // namespace ZeroTier
  91. #endif