Network controller CRUD... :P

This commit is contained in:
Adam Ierymenko 2015-04-21 16:41:35 -07:00
parent ed107c4daf
commit ddebe2d4c7
8 changed files with 508 additions and 80 deletions

View file

@ -39,19 +39,18 @@
#include "../node/Constants.hpp"
#include "../node/NetworkController.hpp"
#include "../node/Mutex.hpp"
#include "../node/NonCopyable.hpp"
#include "../service/ControlPlaneSubsystem.hpp"
namespace ZeroTier {
class SqliteNetworkController : public NetworkController
class SqliteNetworkController : public NetworkController,public ControlPlaneSubsystem
{
public:
class DBC;
friend class SqliteNetworkController::DBC;
SqliteNetworkController(const char *dbPath);
virtual ~SqliteNetworkController();
// NetworkController
virtual NetworkController::ResultCode doNetworkConfigRequest(
const InetAddress &fromAddr,
const Identity &signingId,
@ -61,12 +60,35 @@ public:
uint64_t haveRevision,
Dictionary &netconf);
// ControlPlaneSubsystem
virtual unsigned int handleControlPlaneHttpGET(
const std::vector<std::string> &path,
const std::map<std::string,std::string> &urlArgs,
const std::map<std::string,std::string> &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType);
virtual unsigned int handleControlPlaneHttpPOST(
const std::vector<std::string> &path,
const std::map<std::string,std::string> &urlArgs,
const std::map<std::string,std::string> &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType);
virtual unsigned int handleControlPlaneHttpDELETE(
const std::vector<std::string> &path,
const std::map<std::string,std::string> &urlArgs,
const std::map<std::string,std::string> &headers,
const std::string &body,
std::string &responseBody,
std::string &responseContentType);
private:
std::string _dbPath;
sqlite3 *_db;
sqlite3_stmt *_sGetNetworkById;
sqlite3_stmt *_sGetMemberByNetworkAndNodeId;
sqlite3_stmt *_sGetMember;
sqlite3_stmt *_sCreateMember;
sqlite3_stmt *_sGetNodeIdentity;
sqlite3_stmt *_sCreateNode;
@ -82,26 +104,13 @@ private:
sqlite3_stmt *_sAllocateIp;
sqlite3_stmt *_sCacheNetconf;
sqlite3_stmt *_sGetRelays;
sqlite3_stmt *_sListNetworks;
sqlite3_stmt *_sListNetworkMembers;
sqlite3_stmt *_sGetMember2;
sqlite3_stmt *_sGetIpAssignmentPools2;
sqlite3_stmt *_sListRules;
Mutex _lock;
public:
/**
* Provides a safe interface for direct access to this master's database
*
* This acts as both a contextual lock of the master's Mutex and a pointer
* to the Sqlite3 database instance. Dereferencing this with * yields the
* sqlite3* pointer. Create on parent with DBC(SqliteNetworkController &).
*/
class DBC : NonCopyable
{
public:
DBC(SqliteNetworkController &nc) : _p(&nc) { nc._lock.lock(); }
~DBC() { _p->_lock.unlock(); }
inline sqlite3 *operator*() const throw() { return _p->_db; }
private:
SqliteNetworkController *const _p;
};
};
} // namespace ZeroTier