NetworkController.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "InetAddress.hpp"
  23. #include "Address.hpp"
  24. #include "Identity.hpp"
  25. #include "NetworkConfigRequestMetaData.hpp"
  26. #include "Buffer.hpp"
  27. namespace ZeroTier {
  28. class RuntimeEnvironment;
  29. /**
  30. * Interface for network controller implementations
  31. */
  32. class NetworkController
  33. {
  34. public:
  35. /**
  36. * Return value of doNetworkConfigRequest
  37. */
  38. enum ResultCode
  39. {
  40. NETCONF_QUERY_OK = 0,
  41. NETCONF_QUERY_OBJECT_NOT_FOUND = 1,
  42. NETCONF_QUERY_ACCESS_DENIED = 2,
  43. NETCONF_QUERY_INTERNAL_SERVER_ERROR = 3,
  44. NETCONF_QUERY_IGNORE = 4
  45. };
  46. NetworkController() {}
  47. virtual ~NetworkController() {}
  48. /**
  49. * Handle a network config request, sending replies if necessary
  50. *
  51. * This call is permitted to block, and may be called concurrently from more
  52. * than one thread. Implementations must use locks if needed.
  53. *
  54. * On internal server errors, the 'error' field in result can be filled in
  55. * to indicate the error.
  56. *
  57. * @param fromAddr Originating wire address or null address if packet is not direct (or from self)
  58. * @param signingId Identity that should be used to sign results -- must include private key
  59. * @param identity Originating peer ZeroTier identity
  60. * @param nwid 64-bit network ID
  61. * @param metaData Meta-data bundled with request (if any)
  62. * @param result Buffer to receive serialized network configuration data (any existing data in buffer is preserved)
  63. * @return Returns NETCONF_QUERY_OK if result dictionary is valid, or an error code on error
  64. */
  65. virtual NetworkController::ResultCode doNetworkConfigRequest(
  66. const InetAddress &fromAddr,
  67. const Identity &signingId,
  68. const Identity &identity,
  69. uint64_t nwid,
  70. const NetworkConfigRequestMetaData &metaData,
  71. Buffer<8194> &result) = 0;
  72. };
  73. } // namespace ZeroTier
  74. #endif