diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-05-16 16:09:28 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-05-16 16:09:28 -0700 |
commit | a187d290f15ed2191e994852a6778bf4aa0f083b (patch) | |
tree | c33f5c43b6b5dec857a5b8670ed570ea56d96b74 /service | |
parent | 27c5f04d68003774b9a85eb7047c683cbb64f0df (diff) | |
download | infinitytier-a187d290f15ed2191e994852a6778bf4aa0f083b.tar.gz infinitytier-a187d290f15ed2191e994852a6778bf4aa0f083b.zip |
Fixes to control plane, API, eliminate problematic inheritance pattern, and start on a NodeJS class for talking to the network controller.
Diffstat (limited to 'service')
-rw-r--r-- | service/ControlPlane.cpp | 9 | ||||
-rw-r--r-- | service/ControlPlane.hpp | 6 | ||||
-rw-r--r-- | service/ControlPlaneSubsystem.hpp | 76 | ||||
-rw-r--r-- | service/OneService.cpp | 2 | ||||
-rw-r--r-- | service/README.md | 2 |
5 files changed, 10 insertions, 85 deletions
diff --git a/service/ControlPlane.cpp b/service/ControlPlane.cpp index 69c5d48d..1d9f9b4a 100644 --- a/service/ControlPlane.cpp +++ b/service/ControlPlane.cpp @@ -26,7 +26,6 @@ */ #include "ControlPlane.hpp" -#include "ControlPlaneSubsystem.hpp" #include "OneService.hpp" #include "../version.h" @@ -34,6 +33,8 @@ #include "../ext/http-parser/http_parser.h" +#include "../controller/SqliteNetworkController.hpp" + #include "../node/InetAddress.hpp" #include "../node/Node.hpp" #include "../node/Utils.hpp" @@ -444,7 +445,7 @@ unsigned int ControlPlane::handleRequest( responseContentType = "text/plain"; scode = 200; } else { - std::map<std::string,ControlPlaneSubsystem *>::const_iterator ss(_subsystems.find(ps[0])); + std::map<std::string,SqliteNetworkController *>::const_iterator ss(_subsystems.find(ps[0])); if (ss != _subsystems.end()) scode = ss->second->handleControlPlaneHttpGET(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); else scode = 404; @@ -477,7 +478,7 @@ unsigned int ControlPlane::handleRequest( } else scode = 500; } } else { - std::map<std::string,ControlPlaneSubsystem *>::const_iterator ss(_subsystems.find(ps[0])); + std::map<std::string,SqliteNetworkController *>::const_iterator ss(_subsystems.find(ps[0])); if (ss != _subsystems.end()) scode = ss->second->handleControlPlaneHttpPOST(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); else scode = 404; @@ -509,7 +510,7 @@ unsigned int ControlPlane::handleRequest( _node->freeQueryResult((void *)nws); } else scode = 500; } else { - std::map<std::string,ControlPlaneSubsystem *>::const_iterator ss(_subsystems.find(ps[0])); + std::map<std::string,SqliteNetworkController *>::const_iterator ss(_subsystems.find(ps[0])); if (ss != _subsystems.end()) scode = ss->second->handleControlPlaneHttpDELETE(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType); else scode = 404; diff --git a/service/ControlPlane.hpp b/service/ControlPlane.hpp index b7b0a857..fc8a0182 100644 --- a/service/ControlPlane.hpp +++ b/service/ControlPlane.hpp @@ -40,7 +40,7 @@ namespace ZeroTier { class OneService; class Node; -class ControlPlaneSubsystem; +class SqliteNetworkController; struct InetAddress; /** @@ -72,7 +72,7 @@ public: * @param prefix First element in URI path * @param subsys Object to call for results of GET and POST/PUT operations */ - inline void mount(const char *prefix,ControlPlaneSubsystem *subsys) + inline void mount(const char *prefix,SqliteNetworkController *subsys) { Mutex::Lock _l(_lock); _subsystems[std::string(prefix)] = subsys; @@ -104,7 +104,7 @@ private: Node *const _node; std::string _uiStaticPath; std::set<std::string> _authTokens; - std::map<std::string,ControlPlaneSubsystem *> _subsystems; + std::map<std::string,SqliteNetworkController *> _subsystems; Mutex _lock; }; diff --git a/service/ControlPlaneSubsystem.hpp b/service/ControlPlaneSubsystem.hpp deleted file mode 100644 index 9de875ca..00000000 --- a/service/ControlPlaneSubsystem.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 <http://www.gnu.org/licenses/>. - * - * -- - * - * 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_CONTROLPLANESUBSYSTEM_HPP -#define ZT_CONTROLPLANESUBSYSTEM_HPP - -#include <map> -#include <vector> -#include <string> - -namespace ZeroTier { - -/** - * Base class for subsystems that can be mounted under the HTTP control plane - * - * Handlers should fill in responseBody and responseContentType and return - * a HTTP status code or 0 on other errors. - */ -class ControlPlaneSubsystem -{ -public: - ControlPlaneSubsystem() {} - virtual ~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) = 0; - - 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) = 0; - - 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) = 0; -}; - -} // namespace ZeroTier - -#endif diff --git a/service/OneService.cpp b/service/OneService.cpp index 99aaf77d..13108aa1 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -233,7 +233,7 @@ public: _controlPlane = new ControlPlane(this,_node,(_homePath + ZT_PATH_SEPARATOR_S + "ui").c_str()); _controlPlane->addAuthToken(authToken.c_str()); if (_master) - _controlPlane->mount("controller",reinterpret_cast<ControlPlaneSubsystem *>(_master)); + _controlPlane->mount("controller",reinterpret_cast<SqliteNetworkController *>(_master)); { // Remember networks from previous session std::vector<std::string> networksDotD(OSUtils::listDirectory((_homePath + ZT_PATH_SEPARATOR_S + "networks.d").c_str())); diff --git a/service/README.md b/service/README.md index c347931f..ecab6e75 100644 --- a/service/README.md +++ b/service/README.md @@ -11,7 +11,7 @@ The JSON API supports GET, POST/PUT, and DELETE. PUT is treated as a synonym for Values POSTed to the JSON API are *extremely* type sensitive. Things *must* be of the indicated type, otherwise they will be ignored or will generate an error. Anything quoted is a string so booleans and integers must lack quotes. Booleans must be *true* or *false* and nothing else. Integers cannot contain decimal points or they are floats (and vice versa). If something seems to be getting ignored or set to a strange value, or if you receive errors, check the type of all JSON fields you are submitting against the types listed below. Unrecognized fields in JSON objects are also ignored. -API requests must be authenticated via an authentication token. ZeroTier One saves this token in the *authtoken.secret* file in its working directory. This token may be supplied via the *authToken* URL parameter (e.g. '?authToken=...') or via the *X-ZT1-Auth* HTTP request header. Static UI pages are the only thing the server will allow without authentication. +API requests must be authenticated via an authentication token. ZeroTier One saves this token in the *authtoken.secret* file in its working directory. This token may be supplied via the *auth* URL parameter (e.g. '?auth=...') or via the *X-ZT1-Auth* HTTP request header. Static UI pages are the only thing the server will allow without authentication. A *jsonp* URL argument may be supplied to request JSONP encapsulation. A JSONP response is sent as a script with its JSON response payload wrapped in a call to the function name supplied as the argument to *jsonp*. |