From 68ac884d4752a3768c287f1f38485602ec6a4c5e Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 2 Oct 2019 14:30:46 -0700 Subject: [PATCH] . --- controller/EmbeddedNetworkController.cpp | 6 -- controller/EmbeddedNetworkController.hpp | 6 -- go/pkg/zerotier/api.go | 70 ++++++++++++------------ node/Identity.hpp | 2 + node/Locator.hpp | 4 +- root/root.cpp | 1 - 6 files changed, 38 insertions(+), 51 deletions(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index 8bd1d62e8..0b6c44055 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -548,8 +548,6 @@ void EmbeddedNetworkController::request( unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET( const std::vector &path, - const std::map &urlArgs, - const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType) @@ -645,8 +643,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET( unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST( const std::vector &path, - const std::map &urlArgs, - const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType) @@ -1055,8 +1051,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST( unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE( const std::vector &path, - const std::map &urlArgs, - const std::map &headers, const std::string &body, std::string &responseBody, std::string &responseContentType) diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp index e5ee5ada5..82946940e 100644 --- a/controller/EmbeddedNetworkController.hpp +++ b/controller/EmbeddedNetworkController.hpp @@ -68,22 +68,16 @@ public: 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); diff --git a/go/pkg/zerotier/api.go b/go/pkg/zerotier/api.go index 79b484b76..acc22827c 100644 --- a/go/pkg/zerotier/api.go +++ b/go/pkg/zerotier/api.go @@ -313,7 +313,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, *http.Server, e _ = apiSendObj(out, req, http.StatusOK, node.LocalConfig()) } else { out.Header().Set("Allow", "GET, HEAD, PUT, POST") - _ = apiSendObj(out, req, http.StatusMethodNotAllowed, nil) + _ = apiSendObj(out, req, http.StatusMethodNotAllowed, &APIErr{"unsupported method: " + req.Method}) } }) @@ -388,38 +388,38 @@ func createAPIServer(basePath string, node *Node) (*http.Server, *http.Server, e if req.Method == http.MethodDelete { if queriedID == 0 { - _ = apiSendObj(out, req, http.StatusBadRequest, nil) - } else { - networks := node.Networks() - for _, nw := range networks { - if nw.id == queriedID { - _ = node.Leave(queriedID) - _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw)) - return - } - } - _ = apiSendObj(out, req, http.StatusNotFound, &APIErr{"network not found"}) + _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only specific networks can be deleted"}) + return } + networks := node.Networks() + for _, nw := range networks { + if nw.id == queriedID { + _ = node.Leave(queriedID) + _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw)) + return + } + } + _ = apiSendObj(out, req, http.StatusNotFound, &APIErr{"network not found"}) } else if req.Method == http.MethodPost || req.Method == http.MethodPut { if queriedID == 0 { _ = apiSendObj(out, req, http.StatusBadRequest, nil) - } else { - var nw APINetwork - if apiReadObj(out, req, &nw) == nil { - n := node.GetNetwork(nw.ID) - if n == nil { - n, err := node.Join(nw.ID, nw.Settings, nil) - if err != nil { - _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual networks can be added or modified with POST/PUT"}) - } else { - _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n)) - } + return + } + var nw APINetwork + if apiReadObj(out, req, &nw) == nil { + n := node.GetNetwork(nw.ID) + if n == nil { + n, err := node.Join(nw.ID, nw.Settings, nil) + if err != nil { + _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual networks can be added or modified with POST/PUT"}) } else { - if nw.Settings != nil { - n.SetLocalSettings(nw.Settings) - } _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n)) } + } else { + if nw.Settings != nil { + n.SetLocalSettings(nw.Settings) + } + _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n)) } } } else if req.Method == http.MethodGet || req.Method == http.MethodHead { @@ -430,15 +430,15 @@ func createAPIServer(basePath string, node *Node) (*http.Server, *http.Server, e nws = append(nws, apiNetworkFromNetwork(nw)) } _ = apiSendObj(out, req, http.StatusOK, nws) - } else { - for _, nw := range networks { - if nw.ID() == queriedID { - _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw)) - return - } - } - _ = apiSendObj(out, req, http.StatusNotFound, &APIErr{"network not found"}) + return } + for _, nw := range networks { + if nw.ID() == queriedID { + _ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(nw)) + return + } + } + _ = apiSendObj(out, req, http.StatusNotFound, &APIErr{"network not found"}) } else { out.Header().Set("Allow", "GET, HEAD, PUT, POST, DELETE") _ = apiSendObj(out, req, http.StatusMethodNotAllowed, &APIErr{"unsupported method " + req.Method}) @@ -476,7 +476,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, *http.Server, e } } } - _ = apiSendObj(out, req, http.StatusNotFound, nil) + _ = apiSendObj(out, req, http.StatusNotFound, &APIErr{"root not found"}) } else if req.Method == http.MethodPost || req.Method == http.MethodPut { if len(queriedName) == 0 { _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual roots can be added or modified with POST/PUT"}) diff --git a/node/Identity.hpp b/node/Identity.hpp index d5d7b5144..9b5f7eb72 100644 --- a/node/Identity.hpp +++ b/node/Identity.hpp @@ -308,6 +308,7 @@ public: } else { b.append((uint8_t)0); } + b.append((uint16_t)0); // size of additional fields break; } @@ -371,6 +372,7 @@ public: } else { _hasPrivate = false; } + p += b.template at(p) + 2; break; default: diff --git a/node/Locator.hpp b/node/Locator.hpp index 2743b5330..63d9e9b07 100644 --- a/node/Locator.hpp +++ b/node/Locator.hpp @@ -329,9 +329,7 @@ public: throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW; memcpy(_signature,b.field(p,_signatureLength),_signatureLength); p += _signatureLength; - p += b.template at(p); p += 2; - if (p > b.size()) - throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW; + p += b.template at(p) + 2; return (p - startAt); } diff --git a/root/root.cpp b/root/root.cpp index e46903e0f..8db77c5de 100644 --- a/root/root.cpp +++ b/root/root.cpp @@ -1237,7 +1237,6 @@ int main(int argc,char **argv) ip6[1] = 0; } OSUtils::ztsnprintf(ver,sizeof(ver),"%d.%d.%d",(*p)->vMajor,(*p)->vMinor,(*p)->vRev); - double forwardingSpeed = 0.0; fprintf(pf,"%.10llx %21s %45s %10.4f %6s" ZT_EOL_S, (unsigned long long)(*p)->id.address().toInt(), ip4,