SqliteNetworkController.hpp 4.1 KB

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