NetworkController.hpp 3.1 KB

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