NetworkController.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  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. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef ZT_NETWORKCONFIGMASTER_HPP
  28. #define ZT_NETWORKCONFIGMASTER_HPP
  29. #include <stdint.h>
  30. #include "Constants.hpp"
  31. #include "InetAddress.hpp"
  32. #include "Dictionary.hpp"
  33. #include "Address.hpp"
  34. #include "Identity.hpp"
  35. namespace ZeroTier {
  36. class RuntimeEnvironment;
  37. /**
  38. * Interface for network controller implementations
  39. */
  40. class NetworkController
  41. {
  42. public:
  43. /**
  44. * Return value of doNetworkConfigRequest
  45. */
  46. enum ResultCode
  47. {
  48. NETCONF_QUERY_OK = 0,
  49. NETCONF_QUERY_OBJECT_NOT_FOUND = 1,
  50. NETCONF_QUERY_ACCESS_DENIED = 2,
  51. NETCONF_QUERY_INTERNAL_SERVER_ERROR = 3,
  52. NETCONF_QUERY_IGNORE = 4
  53. };
  54. NetworkController() {}
  55. virtual ~NetworkController() {}
  56. /**
  57. * Handle a network config request, sending replies if necessary
  58. *
  59. * This call is permitted to block, and may be called concurrently from more
  60. * than one thread. Implementations must use locks if needed.
  61. *
  62. * On internal server errors, the 'error' field in result can be filled in
  63. * to indicate the error.
  64. *
  65. * @param fromAddr Originating wire address or null address if packet is not direct (or from self)
  66. * @param signingId Identity that should be used to sign results -- must include private key
  67. * @param identity Originating peer ZeroTier identity
  68. * @param nwid 64-bit network ID
  69. * @param metaData Meta-data bundled with request (empty if none)
  70. * @param result Dictionary to receive resulting signed netconf on success
  71. * @return Returns NETCONF_QUERY_OK if result dictionary is valid, or an error code on error
  72. */
  73. virtual NetworkController::ResultCode doNetworkConfigRequest(
  74. const InetAddress &fromAddr,
  75. const Identity &signingId,
  76. const Identity &identity,
  77. uint64_t nwid,
  78. const Dictionary &metaData,
  79. Dictionary &result) = 0;
  80. };
  81. } // namespace ZeroTier
  82. #endif