NetworkController.hpp 3.3 KB

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