Locator.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2019 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. #ifndef ZT_LOCATOR_HPP
  27. #define ZT_LOCATOR_HPP
  28. #include "Constants.hpp"
  29. #include "Identity.hpp"
  30. #include "InetAddress.hpp"
  31. #include "Utils.hpp"
  32. #include <algorithm>
  33. #include <vector>
  34. namespace ZeroTier {
  35. /**
  36. * Signed information about a node's location on the network
  37. *
  38. * A locator can be stored in DNS as a series of TXT records with a DNS name
  39. * that includes a public key that can be used to validate the locator's
  40. * signature. That way DNS records can't be spoofed even if no DNSSEC or
  41. * anything else is present to secure DNS.
  42. */
  43. class Locator
  44. {
  45. public:
  46. Locator() :
  47. _signatureLength(0) {}
  48. inline const std::vector<InetAddress> &phy() const { return _physical; }
  49. inline const std::vector<Identity> &virt() const { return _virtual; }
  50. inline bool sign(const Identity &signingId)
  51. {
  52. std::sort(_physical.begin(),_physical.end());
  53. std::sort(_virtual.begin(),_virtual.end());
  54. _id = signingId;
  55. }
  56. private:
  57. int64_t _ts;
  58. Identity _id;
  59. std::vector<InetAddress> _physical;
  60. std::vector<Identity> _virtual;
  61. unsigned int _signatureLength;
  62. uint8_t _signature[ZT_SIGNATURE_BUFFER_SIZE];
  63. };
  64. } // namespace ZeroTier
  65. #endif