NetworkController.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ZT_NETWORKCONFIGMASTER_HPP
  19. #define ZT_NETWORKCONFIGMASTER_HPP
  20. #include <stdint.h>
  21. #include "Constants.hpp"
  22. #include "Dictionary.hpp"
  23. #include "NetworkConfig.hpp"
  24. #include "Revocation.hpp"
  25. #include "Address.hpp"
  26. namespace ZeroTier {
  27. class Identity;
  28. struct InetAddress;
  29. /**
  30. * Interface for network controller implementations
  31. */
  32. class NetworkController
  33. {
  34. public:
  35. enum ErrorCode
  36. {
  37. NC_ERROR_NONE = 0,
  38. NC_ERROR_OBJECT_NOT_FOUND = 1,
  39. NC_ERROR_ACCESS_DENIED = 2,
  40. NC_ERROR_INTERNAL_SERVER_ERROR = 3
  41. };
  42. /**
  43. * Interface for sender used to send pushes and replies
  44. */
  45. class Sender
  46. {
  47. public:
  48. /**
  49. * Send a configuration to a remote peer
  50. *
  51. * @param nwid Network ID
  52. * @param requestPacketId Request packet ID to send OK(NETWORK_CONFIG_REQUEST) or 0 to send NETWORK_CONFIG (push)
  53. * @param destination Destination peer Address
  54. * @param nc Network configuration to send
  55. * @param sendLegacyFormatConfig If true, send an old-format network config
  56. */
  57. virtual void ncSendConfig(uint64_t nwid,uint64_t requestPacketId,const Address &destination,const NetworkConfig &nc,bool sendLegacyFormatConfig) = 0;
  58. /**
  59. * Send revocation to a node
  60. *
  61. * @param destination Destination node address
  62. * @param rev Revocation to send
  63. */
  64. virtual void ncSendRevocation(const Address &destination,const Revocation &rev) = 0;
  65. /**
  66. * Send a network configuration request error
  67. *
  68. * @param nwid Network ID
  69. * @param requestPacketId Request packet ID or 0 if none
  70. * @param destination Destination peer Address
  71. * @param errorCode Error code
  72. */
  73. virtual void ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &destination,NetworkController::ErrorCode errorCode) = 0;
  74. };
  75. NetworkController() {}
  76. virtual ~NetworkController() {}
  77. /**
  78. * Called when this is added to a Node to initialize and supply info
  79. *
  80. * @param signingId Identity for signing of network configurations, certs, etc.
  81. * @param sender Sender implementation for sending replies or config pushes
  82. */
  83. virtual void init(const Identity &signingId,Sender *sender) = 0;
  84. /**
  85. * Handle a network configuration request
  86. *
  87. * @param nwid 64-bit network ID
  88. * @param fromAddr Originating wire address or null address if packet is not direct (or from self)
  89. * @param requestPacketId Packet ID of request packet or 0 if not initiated by remote request
  90. * @param identity ZeroTier identity of originating peer
  91. * @param metaData Meta-data bundled with request (if any)
  92. * @return Returns NETCONF_QUERY_OK if result 'nc' is valid, or an error code on error
  93. */
  94. virtual void request(
  95. uint64_t nwid,
  96. const InetAddress &fromAddr,
  97. uint64_t requestPacketId,
  98. const Identity &identity,
  99. const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData) = 0;
  100. };
  101. } // namespace ZeroTier
  102. #endif