NetworkController.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2026-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #ifndef ZT_NETWORKCONFIGMASTER_HPP
  14. #define ZT_NETWORKCONFIGMASTER_HPP
  15. #include <stdint.h>
  16. #include "Constants.hpp"
  17. #include "Dictionary.hpp"
  18. #include "NetworkConfig.hpp"
  19. #include "Revocation.hpp"
  20. #include "Address.hpp"
  21. namespace ZeroTier {
  22. class Identity;
  23. struct InetAddress;
  24. /**
  25. * Interface for network controller implementations
  26. */
  27. class NetworkController
  28. {
  29. public:
  30. enum ErrorCode
  31. {
  32. NC_ERROR_NONE = 0,
  33. NC_ERROR_OBJECT_NOT_FOUND = 1,
  34. NC_ERROR_ACCESS_DENIED = 2,
  35. NC_ERROR_INTERNAL_SERVER_ERROR = 3,
  36. NC_ERROR_AUTHENTICATION_REQUIRED = 4
  37. };
  38. /**
  39. * Interface for sender used to send pushes and replies
  40. */
  41. class Sender
  42. {
  43. public:
  44. /**
  45. * Send a configuration to a remote peer
  46. *
  47. * @param nwid Network ID
  48. * @param requestPacketId Request packet ID to send OK(NETWORK_CONFIG_REQUEST) or 0 to send NETWORK_CONFIG (push)
  49. * @param destination Destination peer Address
  50. * @param nc Network configuration to send
  51. * @param sendLegacyFormatConfig If true, send an old-format network config
  52. */
  53. virtual void ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &destination,const NetworkConfig &nc,bool sendLegacyFormatConfig) = 0;
  54. /**
  55. * Send revocation to a node
  56. *
  57. * @param destination Destination node address
  58. * @param rev Revocation to send
  59. */
  60. virtual void ncSendRevocation(const Address &destination,const Revocation &rev) = 0;
  61. /**
  62. * Send a network configuration request error
  63. *
  64. * If errorData/errorDataSize are provided they must point to a valid serialized
  65. * Dictionary containing error data. They can be null/zero if not specified.
  66. *
  67. * @param nwid Network ID
  68. * @param requestPacketId Request packet ID or 0 if none
  69. * @param destination Destination peer Address
  70. * @param errorCode Error code
  71. * @param errorData Data associated with error or NULL if none
  72. * @param errorDataSize Size of errorData in bytes
  73. */
  74. virtual void ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &destination,NetworkController::ErrorCode errorCode, const void *errorData, unsigned int errorDataSize) = 0;
  75. };
  76. NetworkController() {}
  77. virtual ~NetworkController() {}
  78. /**
  79. * Called when this is added to a Node to initialize and supply info
  80. *
  81. * @param signingId Identity for signing of network configurations, certs, etc.
  82. * @param sender Sender implementation for sending replies or config pushes
  83. */
  84. virtual void init(const Identity &signingId,Sender *sender) = 0;
  85. /**
  86. * Handle a network configuration request
  87. *
  88. * @param nwid 64-bit network ID
  89. * @param fromAddr Originating wire address or null address if packet is not direct (or from self)
  90. * @param requestPacketId Packet ID of request packet or 0 if not initiated by remote request
  91. * @param identity ZeroTier identity of originating peer
  92. * @param metaData Meta-data bundled with request (if any)
  93. * @return Returns NETCONF_QUERY_OK if result 'nc' is valid, or an error code on error
  94. */
  95. virtual void request(
  96. uint64_t nwid,
  97. const InetAddress &fromAddr,
  98. uint64_t requestPacketId,
  99. const Identity &identity,
  100. const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData) = 0;
  101. };
  102. } // namespace ZeroTier
  103. #endif