/* * ZeroTier One - Network Virtualization Everywhere * Copyright (C) 2011-2015 ZeroTier, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * -- * * ZeroTier may be used and distributed under the terms of the GPLv3, which * are available at: http://www.gnu.org/licenses/gpl-3.0.html * * If you would like to embed ZeroTier into a commercial application or * redistribute it in a modified binary form, please contact ZeroTier Networks * LLC. Start here: http://www.zerotier.com/ */ #ifndef ZT_SQLITENETWORKCONTROLLER_HPP #define ZT_SQLITENETWORKCONTROLLER_HPP #include #include #include #include #include "../node/Constants.hpp" #include "../node/NetworkController.hpp" #include "../node/Mutex.hpp" #include "../osdep/Thread.hpp" #include "../ext/offbase/offbase.hpp" namespace ZeroTier { class Node; class SqliteNetworkController : public NetworkController { public: SqliteNetworkController(Node *node,const char *dbPath); virtual ~SqliteNetworkController(); virtual NetworkController::ResultCode doNetworkConfigRequest( const InetAddress &fromAddr, const Identity &signingId, const Identity &identity, uint64_t nwid, const Dictionary &metaData, NetworkConfig &nc); unsigned int handleControlPlaneHttpGET( const std::vector &path, const std::map &urlArgs, const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType); unsigned int handleControlPlaneHttpPOST( const std::vector &path, const std::map &urlArgs, const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType); unsigned int handleControlPlaneHttpDELETE( const std::vector &path, const std::map &urlArgs, const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType); // threadMain() for backup thread -- do not call directly void threadMain() throw(); private: unsigned int _doCPGet( const std::vector &path, const std::map &urlArgs, const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType); static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report); Node *const _node; std::string _instanceId; offbase _db; Thread _dbCommitThread; volatile bool _dbCommitThreadRun; // Circuit tests outstanding struct _CircuitTestEntry { ZT_CircuitTest *test; std::string jsonResults; }; std::map< uint64_t,_CircuitTestEntry > _circuitTests; // Last request time by address, for rate limitation std::map< std::pair,uint64_t > _lastRequestTime; Mutex _lock; }; } // namespace ZeroTier #endif