NetworkController.hpp 3.1 KB

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