NetworkController.hpp 3.4 KB

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