From 90d324ae964fddf3355505d5d9651e75872f76b7 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Fri, 17 May 2019 10:15:40 -0700 Subject: Fixed ZT_SDK build issue. Moved ZT_SDK preprocessor directives to more permanent homes --- node/Constants.hpp | 4 ++++ node/NetworkConfig.hpp | 9 ++++++++- node/Node.cpp | 2 +- node/Switch.cpp | 6 +++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/node/Constants.hpp b/node/Constants.hpp index e8a3e020..4f45f616 100644 --- a/node/Constants.hpp +++ b/node/Constants.hpp @@ -482,7 +482,11 @@ /** * Timeout for overall peer activity (measured from last receive) */ +#ifndef ZT_SDK #define ZT_PEER_ACTIVITY_TIMEOUT 500000 +#else +#define ZT_PEER_ACTIVITY_TIMEOUT 30000 +#endif /** * General rate limit timeout for multiple packet types (HELLO, etc.) diff --git a/node/NetworkConfig.hpp b/node/NetworkConfig.hpp index 6367b8ec..be8c03dd 100644 --- a/node/NetworkConfig.hpp +++ b/node/NetworkConfig.hpp @@ -274,7 +274,14 @@ public: /** * @return True if frames should not be compressed */ - inline bool disableCompression() const { return ((this->flags & ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION) != 0); } + inline bool disableCompression() const + { +#ifndef ZT_SDK + return ((this->flags & ZT_NETWORKCONFIG_FLAG_DISABLE_COMPRESSION) != 0); +#else + return false; // Compression is disabled for SDK builds since it doesn't play nice with lwIP +#endif + } /** * @return Network type is public (no access control) diff --git a/node/Node.cpp b/node/Node.cpp index ffa4a700..c9f38ad3 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -340,7 +340,7 @@ ZT_ResultCode Node::processBackgroundTasks(void *tptr,int64_t now,volatile int64 // Update online status, post status change as event const bool oldOnline = _online; - _online = (((now - lastReceivedFromUpstream) < (ZT_PEER_ACTIVITY_TIMEOUT / (ZT_SDK ? 16 : 1)))||(RR->topology->amUpstream())); + _online = (((now - lastReceivedFromUpstream) < ZT_PEER_ACTIVITY_TIMEOUT)||(RR->topology->amUpstream())); if (oldOnline != _online) postEvent(tptr,_online ? ZT_EVENT_ONLINE : ZT_EVENT_OFFLINE); } catch ( ... ) { diff --git a/node/Switch.cpp b/node/Switch.cpp index eeab051e..55275dc3 100644 --- a/node/Switch.cpp +++ b/node/Switch.cpp @@ -425,7 +425,7 @@ void Switch::onLocalEthernet(void *tPtr,const SharedPtr &network,const from.appendTo(outp); outp.append((uint16_t)etherType); outp.append(data,len); - if (!network->config().disableCompression() && !ZT_SDK) + if (!network->config().disableCompression()) outp.compress(); aqm_enqueue(tPtr,network,outp,true,qosBucket); } else { @@ -433,7 +433,7 @@ void Switch::onLocalEthernet(void *tPtr,const SharedPtr &network,const outp.append(network->id()); outp.append((uint16_t)etherType); outp.append(data,len); - if (!network->config().disableCompression() && !ZT_SDK) + if (!network->config().disableCompression()) outp.compress(); aqm_enqueue(tPtr,network,outp,true,qosBucket); } @@ -490,7 +490,7 @@ void Switch::onLocalEthernet(void *tPtr,const SharedPtr &network,const from.appendTo(outp); outp.append((uint16_t)etherType); outp.append(data,len); - if (!network->config().disableCompression() && !ZT_SDK) + if (!network->config().disableCompression()) outp.compress(); aqm_enqueue(tPtr,network,outp,true,qosBucket); } else { -- cgit v1.2.3 From 541e5c510ef0c2178777b041a5f81294f9fd5c0d Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Fri, 31 May 2019 11:41:24 -0700 Subject: CLI improvements (peers, and get/set ip, ip4, ip6, etc) --- one.cpp | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 136 insertions(+), 7 deletions(-) diff --git a/one.cpp b/one.cpp index 1830f8c6..89acaace 100644 --- a/one.cpp +++ b/one.cpp @@ -69,6 +69,7 @@ #include #include #include +#include #include "version.h" #include "include/ZeroTierOne.h" @@ -129,6 +130,7 @@ static void cliPrintHelp(const char *pn,FILE *out) fprintf(out,ZT_EOL_S"Available commands:" ZT_EOL_S); fprintf(out," info - Display status info" ZT_EOL_S); fprintf(out," listpeers - List all peers" ZT_EOL_S); + fprintf(out," peers - List all peers (prettier)" ZT_EOL_S); fprintf(out," listnetworks - List all networks" ZT_EOL_S); fprintf(out," join - Join a network" ZT_EOL_S); fprintf(out," leave - Leave a network" ZT_EOL_S); @@ -137,6 +139,12 @@ static void cliPrintHelp(const char *pn,FILE *out) fprintf(out," listmoons - List moons (federated root sets)" ZT_EOL_S); fprintf(out," orbit - Join a moon via any member root" ZT_EOL_S); fprintf(out," deorbit - Leave a moon" ZT_EOL_S); + fprintf(out,ZT_EOL_S"Available settings:" ZT_EOL_S); + fprintf(out," Settings to use with [get/set] may include property names from " ZT_EOL_S); + fprintf(out," the JSON output of \"zerotier-cli -j listnetworks\". Additionally, " ZT_EOL_S); + fprintf(out," (ip, ip4, ip6, ip6plane, and ip6prefix can be used). For instance:" ZT_EOL_S); + fprintf(out," zerotier-cli get ip6plane will return the 6PLANE address" ZT_EOL_S); + fprintf(out," assigned to this node." ZT_EOL_S); } static std::string cliFixJsonCRs(const std::string &s) @@ -409,6 +417,73 @@ static int cli(int argc,char **argv) printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); return 1; } + } else if (command == "peers") { + const unsigned int scode = Http::GET(1024 * 1024 * 16,60000,(const struct sockaddr *)&addr,"/peer",requestHeaders,responseHeaders,responseBody); + + if (scode == 0) { + printf("Error connecting to the ZeroTier service: %s\n\nPlease check that the service is running and that TCP port 9993 can be contacted via 127.0.0.1." ZT_EOL_S, responseBody.c_str()); + return 1; + } + + nlohmann::json j; + try { + j = OSUtils::jsonParse(responseBody); + } catch (std::exception &exc) { + printf("%u %s invalid JSON response (%s)" ZT_EOL_S,scode,command.c_str(),exc.what()); + return 1; + } catch ( ... ) { + printf("%u %s invalid JSON response (unknown exception)" ZT_EOL_S,scode,command.c_str()); + return 1; + } + + if (scode == 200) { + if (json) { + printf("%s" ZT_EOL_S,OSUtils::jsonDump(j).c_str()); + } else { + printf("200 peers\n " ZT_EOL_S); + if (j.is_array()) { + for(unsigned long k=0;k= 0) { + OSUtils::ztsnprintf(ver,sizeof(ver),"%lld.%lld.%lld",vmaj,vmin,vrev); + } else { + ver[0] = '-'; + ver[1] = (char)0; + } + printf("%s %-6s %-6s %5d %s" ZT_EOL_S, + OSUtils::jsonString(p["address"],"-").c_str(), + ver, + OSUtils::jsonString(p["role"],"-").c_str(), + (int)OSUtils::jsonInt(p["latency"],0), + bestPath.c_str()); + } + } + } + return 0; + } else { + printf("%u %s %s" ZT_EOL_S,scode,command.c_str(),responseBody.c_str()); + return 1; + } } else if (command == "listnetworks") { const unsigned int scode = Http::GET(1024 * 1024 * 16,60000,(const struct sockaddr *)&addr,"/network",requestHeaders,responseHeaders,responseBody); @@ -468,7 +543,7 @@ static int cli(int argc,char **argv) } } else if (command == "join") { if (arg1.length() != 16) { - printf("invalid network id" ZT_EOL_S); + printf("invalid network id" ZT_EOL_S); return 2; } requestHeaders["Content-Type"] = "application/json"; @@ -496,7 +571,7 @@ static int cli(int argc,char **argv) } } else if (command == "leave") { if (arg1.length() != 16) { - printf("invalid network id" ZT_EOL_S); + printf("invalid network id" ZT_EOL_S); return 2; } unsigned int scode = Http::DEL( @@ -594,7 +669,11 @@ static int cli(int argc,char **argv) } } else if (command == "set") { if (arg1.length() != 16) { - printf("invalid network id" ZT_EOL_S); + fprintf(stderr,"invalid format: must be a 16-digit (network) ID\n"); + return 2; + } + if (!arg2.length()) { + fprintf(stderr,"invalid format: include a property name to set\n"); return 2; } std::size_t eqidx = arg2.find('='); @@ -632,16 +711,18 @@ static int cli(int argc,char **argv) } } else if (command == "get") { if (arg1.length() != 16) { - fprintf(stderr,"invalid network ID format, must be a 16-digit hexidecimal number\n"); + fprintf(stderr,"invalid format: must be a 16-digit (network) ID\n"); + return 2; + } + if (!arg2.length()) { + fprintf(stderr,"invalid format: include a property name to get\n"); return 2; } const unsigned int scode = Http::GET(1024 * 1024 * 16,60000,(const struct sockaddr *)&addr,"/network",requestHeaders,responseHeaders,responseBody); - if (scode == 0) { printf("Error connecting to the ZeroTier service: %s\n\nPlease check that the service is running and that TCP port 9993 can be contacted via 127.0.0.1." ZT_EOL_S, responseBody.c_str()); return 1; } - nlohmann::json j; try { j = OSUtils::jsonParse(responseBody); @@ -658,8 +739,56 @@ static int cli(int argc,char **argv) nlohmann::json &n = j[i]; if (n.is_object()) { if (n["id"] == arg1) { - printf("%s\n", OSUtils::jsonString(n[arg2],"-").c_str()); bNetworkFound = true; + std::string aa; + if (arg2 != "ip" && arg2 != "ip4" && arg2 != "ip6" && arg2 != "ip6plane" && arg2 != "ip6prefix") { + aa.append(OSUtils::jsonString(n[arg2],"-")); // Standard network property field + if (aa == "-") { + printf("error, unknown property name\n"); + break; + } + printf("%s\n",aa.c_str()); + break; + } + nlohmann::json &assignedAddresses = n["assignedAddresses"]; + if (assignedAddresses.is_array()) { + int matchingIdxs[ZT_MAX_ZT_ASSIGNED_ADDRESSES]; + int addressCountOfType = 0; + for (int k = 0; k().find(".") != std::string::npos) + || ((arg2.find("ip6") == 0) && addr.get().find(":") != std::string::npos) + || (arg2 == "ip") + ) { + matchingIdxs[addressCountOfType++] = k; + } + } + for (int k=0; k().find("fc") == 0) { + aa.append(addr.get().substr(0,addr.get().find("/"))); + if (k < addressCountOfType-1) aa.append("\n"); + } + } + if (arg2 == "ip6prefix") { + if (addr.get().find("fc") == 0) { + aa.append(addr.get().substr(0,addr.get().find("/")).substr(0,24)); + if (k < addressCountOfType-1) aa.append("\n"); + } + } + } + else { + aa.append(addr.get().substr(0,addr.get().find("/"))); + if (k < addressCountOfType-1) aa.append("\n"); + } + } + } + printf("%s\n",aa.c_str()); } } } -- cgit v1.2.3 From 37d321afc80aaced7e0473e33893787d9a42ef78 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 31 May 2019 15:10:45 -0700 Subject: dont spin as much in the onlineNotificationThread --- controller/PostgreSQL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index 9aa4fbaa..de6b4f46 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -1512,7 +1512,7 @@ void PostgreSQL::onlineNotificationThread() // PQclear(res); // } - std::this_thread::sleep_for(std::chrono::milliseconds(0)); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } fprintf(stderr, "%s: Fell out of run loop in onlineNotificationThread\n", _myAddressStr.c_str()); PQfinish(conn); -- cgit v1.2.3 From d4199ddb3ef59b8f754129bfc91f91c18f84759c Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 3 Jun 2019 11:00:04 -0700 Subject: Commented out RingBuffer::dump() as an alternative solution to PR #952 --- node/RingBuffer.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/RingBuffer.hpp b/node/RingBuffer.hpp index e9f17e1c..8b11e9b1 100644 --- a/node/RingBuffer.hpp +++ b/node/RingBuffer.hpp @@ -312,6 +312,7 @@ public: /** * Print the contents of the buffer */ + /* inline void dump() { size_t iterator = begin; @@ -325,6 +326,7 @@ public: } } } + */ }; } // namespace ZeroTier -- cgit v1.2.3