SqliteNetworkController.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_SQLITENETWORKCONTROLLER_HPP
  28. #define ZT_SQLITENETWORKCONTROLLER_HPP
  29. #include <stdint.h>
  30. #include <sqlite3.h>
  31. #include <string>
  32. #include <map>
  33. #include <vector>
  34. #include "../node/Constants.hpp"
  35. #include "../node/NetworkController.hpp"
  36. #include "../node/Mutex.hpp"
  37. #include "../service/ControlPlaneSubsystem.hpp"
  38. namespace ZeroTier {
  39. class SqliteNetworkController : public NetworkController,public ControlPlaneSubsystem
  40. {
  41. public:
  42. SqliteNetworkController(const char *dbPath);
  43. virtual ~SqliteNetworkController();
  44. // NetworkController
  45. virtual NetworkController::ResultCode doNetworkConfigRequest(
  46. const InetAddress &fromAddr,
  47. const Identity &signingId,
  48. const Identity &identity,
  49. uint64_t nwid,
  50. const Dictionary &metaData,
  51. uint64_t haveRevision,
  52. Dictionary &netconf);
  53. // ControlPlaneSubsystem
  54. virtual unsigned int handleControlPlaneHttpGET(
  55. const std::vector<std::string> &path,
  56. const std::map<std::string,std::string> &urlArgs,
  57. const std::map<std::string,std::string> &headers,
  58. const std::string &body,
  59. std::string &responseBody,
  60. std::string &responseContentType);
  61. virtual unsigned int handleControlPlaneHttpPOST(
  62. const std::vector<std::string> &path,
  63. const std::map<std::string,std::string> &urlArgs,
  64. const std::map<std::string,std::string> &headers,
  65. const std::string &body,
  66. std::string &responseBody,
  67. std::string &responseContentType);
  68. virtual unsigned int handleControlPlaneHttpDELETE(
  69. const std::vector<std::string> &path,
  70. const std::map<std::string,std::string> &urlArgs,
  71. const std::map<std::string,std::string> &headers,
  72. const std::string &body,
  73. std::string &responseBody,
  74. std::string &responseContentType);
  75. private:
  76. std::string _dbPath;
  77. sqlite3 *_db;
  78. sqlite3_stmt *_sGetNetworkById;
  79. sqlite3_stmt *_sGetMember;
  80. sqlite3_stmt *_sCreateMember;
  81. sqlite3_stmt *_sGetNodeIdentity;
  82. sqlite3_stmt *_sCreateNode;
  83. sqlite3_stmt *_sUpdateNode;
  84. sqlite3_stmt *_sUpdateNode2;
  85. sqlite3_stmt *_sGetEtherTypesFromRuleTable;
  86. sqlite3_stmt *_sGetMulticastRates;
  87. sqlite3_stmt *_sGetActiveBridges;
  88. sqlite3_stmt *_sGetIpAssignmentsForNode;
  89. sqlite3_stmt *_sGetIpAssignmentPools;
  90. sqlite3_stmt *_sCheckIfIpIsAllocated;
  91. sqlite3_stmt *_sAllocateIp;
  92. sqlite3_stmt *_sDeleteIpAllocations;
  93. sqlite3_stmt *_sGetRelays;
  94. sqlite3_stmt *_sListNetworks;
  95. sqlite3_stmt *_sListNetworkMembers;
  96. sqlite3_stmt *_sGetMember2;
  97. sqlite3_stmt *_sGetIpAssignmentPools2;
  98. sqlite3_stmt *_sListRules;
  99. sqlite3_stmt *_sCreateRule;
  100. sqlite3_stmt *_sCreateNetwork;
  101. sqlite3_stmt *_sGetNetworkRevision;
  102. sqlite3_stmt *_sSetNetworkRevision;
  103. sqlite3_stmt *_sGetIpAssignmentsForNode2;
  104. sqlite3_stmt *_sDeleteRelaysForNetwork;
  105. sqlite3_stmt *_sCreateRelay;
  106. sqlite3_stmt *_sDeleteIpAssignmentPoolsForNetwork;
  107. sqlite3_stmt *_sDeleteRulesForNetwork;
  108. sqlite3_stmt *_sCreateIpAssignmentPool;
  109. sqlite3_stmt *_sDeleteMember;
  110. sqlite3_stmt *_sDeleteNetworkAndRelated;
  111. Mutex _lock;
  112. };
  113. } // namespace ZeroTier
  114. #endif