Path.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. enum Trust
  37. {
  38. TRUST_NORMAL,
  39. TRUST_PRIVACY,
  40. TRUST_ULTIMATE
  41. };
  42. Path() :
  43. _addr(),
  44. _metric(0),
  45. _trust(TRUST_NORMAL),
  46. _reliable(false),
  47. _fixed(false)
  48. {
  49. }
  50. Path(const InetAddress &addr,int metric,Trust trust,bool reliable,bool fixed) :
  51. _addr(addr),
  52. _metric(metric),
  53. _trust(trust),
  54. _reliable(reliable),
  55. _fixed(fixed)
  56. {
  57. }
  58. /**
  59. * @return Physical address
  60. */
  61. inline const InetAddress &address() const throw() { return _addr; }
  62. /**
  63. * @return Metric (higher == worse) or negative if path is blacklisted
  64. */
  65. inline int metric() const throw() { return _metric; }
  66. /**
  67. * @return Path trust level
  68. */
  69. inline Trust trust() const throw() { return _trust; }
  70. /**
  71. * @return True if path is considered reliable (no NAT keepalives etc. are needed)
  72. */
  73. inline bool reliable() const throw() { return _reliable; }
  74. /**
  75. * @return Is this a fixed path?
  76. */
  77. inline bool fixed() const throw() { return _fixed; }
  78. /**
  79. * @return True if address is non-NULL
  80. */
  81. inline operator bool() const throw() { return (_addr); }
  82. // Comparisons are by address only
  83. inline bool operator==(const Path &p) const throw() { return (_addr == p._addr); }
  84. inline bool operator!=(const Path &p) const throw() { return (_addr != p._addr); }
  85. inline bool operator<(const Path &p) const throw() { return (_addr < p._addr); }
  86. inline bool operator>(const Path &p) const throw() { return (_addr > p._addr); }
  87. inline bool operator<=(const Path &p) const throw() { return (_addr <= p._addr); }
  88. inline bool operator>=(const Path &p) const throw() { return (_addr >= p._addr); }
  89. protected:
  90. InetAddress _addr;
  91. int _metric; // negative == blacklisted
  92. Trust _trust;
  93. bool _reliable;
  94. bool _fixed;
  95. };
  96. } // namespace ZeroTier
  97. #endif