This commit is contained in:
Adam Ierymenko 2019-10-02 14:30:46 -07:00
parent e2f3996843
commit 68ac884d47
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
6 changed files with 38 additions and 51 deletions

View file

@ -548,8 +548,6 @@ void EmbeddedNetworkController::request(
unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET( unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
const std::vector<std::string> &path, 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, const std::string &body,
std::string &responseBody, std::string &responseBody,
std::string &responseContentType) std::string &responseContentType)
@ -645,8 +643,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST( unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
const std::vector<std::string> &path, 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, const std::string &body,
std::string &responseBody, std::string &responseBody,
std::string &responseContentType) std::string &responseContentType)
@ -1055,8 +1051,6 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE( unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
const std::vector<std::string> &path, 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, const std::string &body,
std::string &responseBody, std::string &responseBody,
std::string &responseContentType) std::string &responseContentType)

View file

@ -68,22 +68,16 @@ public:
unsigned int handleControlPlaneHttpGET( unsigned int handleControlPlaneHttpGET(
const std::vector<std::string> &path, 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, const std::string &body,
std::string &responseBody, std::string &responseBody,
std::string &responseContentType); std::string &responseContentType);
unsigned int handleControlPlaneHttpPOST( unsigned int handleControlPlaneHttpPOST(
const std::vector<std::string> &path, 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, const std::string &body,
std::string &responseBody, std::string &responseBody,
std::string &responseContentType); std::string &responseContentType);
unsigned int handleControlPlaneHttpDELETE( unsigned int handleControlPlaneHttpDELETE(
const std::vector<std::string> &path, 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, const std::string &body,
std::string &responseBody, std::string &responseBody,
std::string &responseContentType); std::string &responseContentType);

View file

@ -313,7 +313,7 @@ func createAPIServer(basePath string, node *Node) (*http.Server, *http.Server, e
_ = apiSendObj(out, req, http.StatusOK, node.LocalConfig()) _ = apiSendObj(out, req, http.StatusOK, node.LocalConfig())
} else { } else {
out.Header().Set("Allow", "GET, HEAD, PUT, POST") 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 req.Method == http.MethodDelete {
if queriedID == 0 { if queriedID == 0 {
_ = apiSendObj(out, req, http.StatusBadRequest, nil) _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only specific networks can be deleted"})
} else { 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"})
} }
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 { } else if req.Method == http.MethodPost || req.Method == http.MethodPut {
if queriedID == 0 { if queriedID == 0 {
_ = apiSendObj(out, req, http.StatusBadRequest, nil) _ = apiSendObj(out, req, http.StatusBadRequest, nil)
} else { return
var nw APINetwork }
if apiReadObj(out, req, &nw) == nil { var nw APINetwork
n := node.GetNetwork(nw.ID) if apiReadObj(out, req, &nw) == nil {
if n == nil { n := node.GetNetwork(nw.ID)
n, err := node.Join(nw.ID, nw.Settings, nil) if n == nil {
if err != nil { n, err := node.Join(nw.ID, nw.Settings, nil)
_ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual networks can be added or modified with POST/PUT"}) if err != nil {
} else { _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual networks can be added or modified with POST/PUT"})
_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n))
}
} else { } else {
if nw.Settings != nil {
n.SetLocalSettings(nw.Settings)
}
_ = apiSendObj(out, req, http.StatusOK, apiNetworkFromNetwork(n)) _ = 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 { } 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)) nws = append(nws, apiNetworkFromNetwork(nw))
} }
_ = apiSendObj(out, req, http.StatusOK, nws) _ = apiSendObj(out, req, http.StatusOK, nws)
} else { 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"})
} }
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 { } else {
out.Header().Set("Allow", "GET, HEAD, PUT, POST, DELETE") out.Header().Set("Allow", "GET, HEAD, PUT, POST, DELETE")
_ = apiSendObj(out, req, http.StatusMethodNotAllowed, &APIErr{"unsupported method " + req.Method}) _ = 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 { } else if req.Method == http.MethodPost || req.Method == http.MethodPut {
if len(queriedName) == 0 { if len(queriedName) == 0 {
_ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual roots can be added or modified with POST/PUT"}) _ = apiSendObj(out, req, http.StatusBadRequest, &APIErr{"only individual roots can be added or modified with POST/PUT"})

View file

@ -308,6 +308,7 @@ public:
} else { } else {
b.append((uint8_t)0); b.append((uint8_t)0);
} }
b.append((uint16_t)0); // size of additional fields
break; break;
} }
@ -371,6 +372,7 @@ public:
} else { } else {
_hasPrivate = false; _hasPrivate = false;
} }
p += b.template at<uint16_t>(p) + 2;
break; break;
default: default:

View file

@ -329,9 +329,7 @@ public:
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW; throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
memcpy(_signature,b.field(p,_signatureLength),_signatureLength); memcpy(_signature,b.field(p,_signatureLength),_signatureLength);
p += _signatureLength; p += _signatureLength;
p += b.template at<uint16_t>(p); p += 2; p += b.template at<uint16_t>(p) + 2;
if (p > b.size())
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
return (p - startAt); return (p - startAt);
} }

View file

@ -1237,7 +1237,6 @@ int main(int argc,char **argv)
ip6[1] = 0; ip6[1] = 0;
} }
OSUtils::ztsnprintf(ver,sizeof(ver),"%d.%d.%d",(*p)->vMajor,(*p)->vMinor,(*p)->vRev); 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, fprintf(pf,"%.10llx %21s %45s %10.4f %6s" ZT_EOL_S,
(unsigned long long)(*p)->id.address().toInt(), (unsigned long long)(*p)->id.address().toInt(),
ip4, ip4,