NetworkController.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_NETWORKCONFIGMASTER_HPP
  27. #define ZT_NETWORKCONFIGMASTER_HPP
  28. #include <stdint.h>
  29. #include "Constants.hpp"
  30. #include "Dictionary.hpp"
  31. #include "NetworkConfig.hpp"
  32. #include "Revocation.hpp"
  33. #include "Address.hpp"
  34. namespace ZeroTier {
  35. class Identity;
  36. struct InetAddress;
  37. /**
  38. * Interface for network controller implementations
  39. */
  40. class NetworkController
  41. {
  42. public:
  43. enum ErrorCode
  44. {
  45. NC_ERROR_NONE = 0,
  46. NC_ERROR_OBJECT_NOT_FOUND = 1,
  47. NC_ERROR_ACCESS_DENIED = 2,
  48. NC_ERROR_INTERNAL_SERVER_ERROR = 3
  49. };
  50. /**
  51. * Interface for sender used to send pushes and replies
  52. */
  53. class Sender
  54. {
  55. public:
  56. /**
  57. * Send a configuration to a remote peer
  58. *
  59. * @param nwid Network ID
  60. * @param requestPacketId Request packet ID to send OK(NETWORK_CONFIG_REQUEST) or 0 to send NETWORK_CONFIG (push)
  61. * @param destination Destination peer Address
  62. * @param nc Network configuration to send
  63. * @param sendLegacyFormatConfig If true, send an old-format network config
  64. */
  65. virtual void ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &destination,const NetworkConfig &nc,bool sendLegacyFormatConfig) = 0;
  66. /**
  67. * Send revocation to a node
  68. *
  69. * @param destination Destination node address
  70. * @param rev Revocation to send
  71. */
  72. virtual void ncSendRevocation(const Address &destination,const Revocation &rev) = 0;
  73. /**
  74. * Send a network configuration request error
  75. *
  76. * @param nwid Network ID
  77. * @param requestPacketId Request packet ID or 0 if none
  78. * @param destination Destination peer Address
  79. * @param errorCode Error code
  80. */
  81. virtual void ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &destination,NetworkController::ErrorCode errorCode) = 0;
  82. };
  83. NetworkController() {}
  84. virtual ~NetworkController() {}
  85. /**
  86. * Called when this is added to a Node to initialize and supply info
  87. *
  88. * @param signingId Identity for signing of network configurations, certs, etc.
  89. * @param sender Sender implementation for sending replies or config pushes
  90. */
  91. virtual void init(const Identity &signingId,Sender *sender) = 0;
  92. /**
  93. * Handle a network configuration request
  94. *
  95. * @param nwid 64-bit network ID
  96. * @param fromAddr Originating wire address or null address if packet is not direct (or from self)
  97. * @param requestPacketId Packet ID of request packet or 0 if not initiated by remote request
  98. * @param identity ZeroTier identity of originating peer
  99. * @param metaData Meta-data bundled with request (if any)
  100. * @return Returns NETCONF_QUERY_OK if result 'nc' is valid, or an error code on error
  101. */
  102. virtual void request(
  103. uint64_t nwid,
  104. const InetAddress &fromAddr,
  105. uint64_t requestPacketId,
  106. const Identity &identity,
  107. const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData) = 0;
  108. };
  109. } // namespace ZeroTier
  110. #endif