NetworkController.hpp 3.5 KB

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