mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
clang-format root
This commit is contained in:
parent
0a6c22a9b8
commit
2316a45a45
2 changed files with 1304 additions and 1141 deletions
75
.clang-format
Normal file
75
.clang-format
Normal file
|
@ -0,0 +1,75 @@
|
|||
---
|
||||
BasedOnStyle: LLVM
|
||||
BreakBeforeBraces: Stroustrup
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveMacros: 'true'
|
||||
AlignConsecutiveAssignments: 'false'
|
||||
AlignConsecutiveDeclarations: 'false'
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: 'true'
|
||||
AlignTrailingComments: 'true'
|
||||
AllowAllArgumentsOnNextLine: 'false'
|
||||
AllowAllConstructorInitializersOnNextLine: 'false'
|
||||
AllowAllParametersOfDeclarationOnNextLine: 'false'
|
||||
AllowShortBlocksOnASingleLine: 'true'
|
||||
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AlwaysBreakAfterReturnType: None
|
||||
BinPackArguments: 'false'
|
||||
BinPackParameters: 'false'
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeTernaryOperators: 'true'
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
CompactNamespaces: 'false'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
ConstructorInitializerIndentWidth: '4'
|
||||
ContinuationIndentWidth: '4'
|
||||
Cpp11BracedListStyle: 'false'
|
||||
FixNamespaceComments: 'true'
|
||||
IncludeBlocks: Regroup
|
||||
IndentCaseLabels: 'true'
|
||||
IndentPPDirectives: None
|
||||
IndentWrappedFunctionNames: 'false'
|
||||
KeepEmptyLinesAtTheStartOfBlocks: 'false'
|
||||
MaxEmptyLinesToKeep: '1'
|
||||
NamespaceIndentation: None
|
||||
PointerAlignment: Left
|
||||
ReflowComments: 'true'
|
||||
SortIncludes: 'true'
|
||||
SortUsingDeclarations: 'true'
|
||||
SpaceAfterCStyleCast: 'false'
|
||||
SpaceAfterLogicalNot: 'true'
|
||||
SpaceAfterTemplateKeyword: 'true'
|
||||
SpaceBeforeAssignmentOperators: 'true'
|
||||
SpaceBeforeCpp11BracedList: 'true'
|
||||
SpaceBeforeCtorInitializerColon: 'true'
|
||||
SpaceBeforeInheritanceColon: 'true'
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: 'true'
|
||||
SpaceInEmptyParentheses: 'false'
|
||||
SpacesBeforeTrailingComments: '3'
|
||||
SpacesInAngles: 'false'
|
||||
SpacesInCStyleCastParentheses: 'false'
|
||||
SpacesInContainerLiterals: 'true'
|
||||
SpacesInParentheses: 'false'
|
||||
SpacesInSquareBrackets: 'false'
|
||||
UseTab: 'Never'
|
||||
|
||||
---
|
||||
Language: Cpp
|
||||
Standard: Cpp03
|
||||
ColumnLimit: '240'
|
||||
---
|
||||
Language: ObjC
|
||||
ColumnLimit: '240'
|
||||
---
|
||||
Language: Java
|
||||
ColumnLimit: '240'
|
||||
---
|
||||
Language: CSharp
|
||||
ColumnLimit: '240'
|
||||
...
|
374
root/root.cpp
374
root/root.cpp
|
@ -48,63 +48,56 @@
|
|||
* they appear with the first alive sibling being used.
|
||||
*/
|
||||
|
||||
|
||||
#include "../ext/cpp-httplib/httplib.h"
|
||||
#include "../ext/json/json.hpp"
|
||||
#include "../node/Address.hpp"
|
||||
#include "../node/CertificateOfMembership.hpp"
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/Identity.hpp"
|
||||
#include "../node/InetAddress.hpp"
|
||||
#include "../node/Meter.hpp"
|
||||
#include "../node/MulticastGroup.hpp"
|
||||
#include "../node/Mutex.hpp"
|
||||
#include "../node/Packet.hpp"
|
||||
#include "../node/SharedPtr.hpp"
|
||||
#include "../node/Utils.hpp"
|
||||
#include "../osdep/BlockingQueue.hpp"
|
||||
#include "../osdep/OSUtils.hpp"
|
||||
#include "geoip-html.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <atomic>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
|
||||
#include "../ext/json/json.hpp"
|
||||
#include "../ext/cpp-httplib/httplib.h"
|
||||
|
||||
#include "../node/Packet.hpp"
|
||||
#include "../node/Utils.hpp"
|
||||
#include "../node/Address.hpp"
|
||||
#include "../node/Identity.hpp"
|
||||
#include "../node/InetAddress.hpp"
|
||||
#include "../node/Mutex.hpp"
|
||||
#include "../node/SharedPtr.hpp"
|
||||
#include "../node/MulticastGroup.hpp"
|
||||
#include "../node/CertificateOfMembership.hpp"
|
||||
#include "../node/Meter.hpp"
|
||||
|
||||
#include "../osdep/OSUtils.hpp"
|
||||
#include "../osdep/BlockingQueue.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "geoip-html.h"
|
||||
|
||||
using namespace ZeroTier;
|
||||
using json = nlohmann::json;
|
||||
|
@ -127,10 +120,14 @@ using json = nlohmann::json;
|
|||
* AtomicCounter all satisfy this. Take care when adding fields that
|
||||
* this remains true.
|
||||
*/
|
||||
struct RootPeer
|
||||
struct RootPeer {
|
||||
ZT_ALWAYS_INLINE RootPeer() : v4s(-1), v6s(-1), lastSend(0), lastReceive(0), lastReceiveV4(0), lastReceiveV6(0), lastEcho(0), lastHello(0), vProto(-1), vMajor(-1), vMinor(-1), vRev(-1), identityValidated(false)
|
||||
{
|
||||
ZT_ALWAYS_INLINE RootPeer() : v4s(-1),v6s(-1),lastSend(0),lastReceive(0),lastReceiveV4(0),lastReceiveV6(0),lastEcho(0),lastHello(0),vProto(-1),vMajor(-1),vMinor(-1),vRev(-1),identityValidated(false) {}
|
||||
ZT_ALWAYS_INLINE ~RootPeer() { Utils::burn(key,sizeof(key)); }
|
||||
}
|
||||
ZT_ALWAYS_INLINE ~RootPeer()
|
||||
{
|
||||
Utils::burn(key, sizeof(key));
|
||||
}
|
||||
|
||||
Identity id; // Identity
|
||||
uint8_t key[32]; // Shared secret key
|
||||
|
@ -150,33 +147,65 @@ struct RootPeer
|
|||
};
|
||||
|
||||
// Hashers for std::unordered_map
|
||||
struct IdentityHasher { ZT_ALWAYS_INLINE std::size_t operator()(const Identity &id) const { return (std::size_t)id.hashCode(); } };
|
||||
struct AddressHasher { ZT_ALWAYS_INLINE std::size_t operator()(const Address &a) const { return (std::size_t)a.toInt(); } };
|
||||
struct InetAddressHasher { ZT_ALWAYS_INLINE std::size_t operator()(const InetAddress &ip) const { return (std::size_t)ip.hashCode(); } };
|
||||
struct MulticastGroupHasher { ZT_ALWAYS_INLINE std::size_t operator()(const MulticastGroup &mg) const { return (std::size_t)mg.hashCode(); } };
|
||||
struct IdentityHasher {
|
||||
ZT_ALWAYS_INLINE std::size_t operator()(const Identity& id) const
|
||||
{
|
||||
return (std::size_t)id.hashCode();
|
||||
}
|
||||
};
|
||||
struct AddressHasher {
|
||||
ZT_ALWAYS_INLINE std::size_t operator()(const Address& a) const
|
||||
{
|
||||
return (std::size_t)a.toInt();
|
||||
}
|
||||
};
|
||||
struct InetAddressHasher {
|
||||
ZT_ALWAYS_INLINE std::size_t operator()(const InetAddress& ip) const
|
||||
{
|
||||
return (std::size_t)ip.hashCode();
|
||||
}
|
||||
};
|
||||
struct MulticastGroupHasher {
|
||||
ZT_ALWAYS_INLINE std::size_t operator()(const MulticastGroup& mg) const
|
||||
{
|
||||
return (std::size_t)mg.hashCode();
|
||||
}
|
||||
};
|
||||
|
||||
// An ordered tuple key representing an introduction of one peer to another
|
||||
struct RendezvousKey
|
||||
{
|
||||
struct RendezvousKey {
|
||||
RendezvousKey(const Address& aa, const Address& bb)
|
||||
{
|
||||
if (aa > bb) {
|
||||
a = aa;
|
||||
b = bb;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
a = bb;
|
||||
b = aa;
|
||||
}
|
||||
}
|
||||
Address a, b;
|
||||
ZT_ALWAYS_INLINE bool operator==(const RendezvousKey &k) const { return ((a == k.a)&&(b == k.b)); }
|
||||
ZT_ALWAYS_INLINE bool operator!=(const RendezvousKey &k) const { return ((a != k.a)||(b != k.b)); }
|
||||
struct Hasher { ZT_ALWAYS_INLINE std::size_t operator()(const RendezvousKey &k) const { return (std::size_t)(k.a.toInt() ^ k.b.toInt()); } };
|
||||
ZT_ALWAYS_INLINE bool operator==(const RendezvousKey& k) const
|
||||
{
|
||||
return ((a == k.a) && (b == k.b));
|
||||
}
|
||||
ZT_ALWAYS_INLINE bool operator!=(const RendezvousKey& k) const
|
||||
{
|
||||
return ((a != k.a) || (b != k.b));
|
||||
}
|
||||
struct Hasher {
|
||||
ZT_ALWAYS_INLINE std::size_t operator()(const RendezvousKey& k) const
|
||||
{
|
||||
return (std::size_t)(k.a.toInt() ^ k.b.toInt());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct RendezvousStats
|
||||
struct RendezvousStats {
|
||||
RendezvousStats() : count(0), ts(0)
|
||||
{
|
||||
RendezvousStats() : count(0),ts(0) {}
|
||||
}
|
||||
int64_t count;
|
||||
int64_t ts;
|
||||
};
|
||||
|
@ -274,7 +303,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
const uint64_t origId = pkt.packetId();
|
||||
pkt.reset(source, s_self.address(), Packet::VERB_ERROR);
|
||||
pkt.append((uint8_t)Packet::VERB_HELLO);
|
||||
pkt.append(origId);;
|
||||
pkt.append(origId);
|
||||
;
|
||||
pkt.append((uint8_t)Packet::ERROR_IDENTITY_COLLISION);
|
||||
pkt.armor(key, true);
|
||||
sendto(sock, pkt.data(), pkt.size(), SENDTO_FLAGS, (const struct sockaddr*)ip, (socklen_t)((ip->ss_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6)));
|
||||
|
@ -282,7 +312,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
peer.set(new RootPeer);
|
||||
peer->identityValidated = false;
|
||||
|
||||
|
@ -335,7 +366,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
printf("%s packet rejected: decompression failed" ZT_EOL_S, ip->toString(ipstr));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -348,7 +380,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
peer->lastReceiveV4 = now;
|
||||
if ((now - peer->lastReceiveV6) > ZT_PEER_ACTIVITY_TIMEOUT)
|
||||
peer->v6s = -1;
|
||||
} else if (ip->isV6()) {
|
||||
}
|
||||
else if (ip->isV6()) {
|
||||
peer->ip6 = ip;
|
||||
peer->v6s = sock;
|
||||
peer->lastReceiveV6 = now;
|
||||
|
@ -392,7 +425,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
s_outputRate.log(now, pkt.size());
|
||||
peer->lastSend = now;
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
printf("* unexpected exception handling HELLO from %s" ZT_EOL_S, ip->toString(ipstr));
|
||||
}
|
||||
break;
|
||||
|
@ -413,7 +447,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
s_outputRate.log(now, outp.size());
|
||||
peer->lastSend = now;
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
printf("* unexpected exception handling ECHO from %s" ZT_EOL_S, ip->toString(ipstr));
|
||||
}
|
||||
|
||||
|
@ -444,7 +479,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
s_outputRate.log(now, pkt.size());
|
||||
peer->lastSend = now;
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
printf("* unexpected exception handling ECHO from %s" ZT_EOL_S, ip->toString(ipstr));
|
||||
}
|
||||
|
||||
|
@ -456,7 +492,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
const MulticastGroup mg(MAC(pkt.field(ptr + 8, 6), 6), pkt.template at<uint32_t>(ptr + 14));
|
||||
s_multicastSubscriptions[nwid][mg][source] = now;
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
printf("* unexpected exception handling MULTICAST_LIKE from %s" ZT_EOL_S, ip->toString(ipstr));
|
||||
}
|
||||
break;
|
||||
|
@ -507,7 +544,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
printf("* unexpected exception handling MULTICAST_GATHER from %s" ZT_EOL_S, ip->toString(ipstr));
|
||||
}
|
||||
break;
|
||||
|
@ -530,7 +568,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
s_discardedForwardRate.log(now, pkt.size());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if ((hops = (int)pkt.incrementHops()) > s_relayMaxHops) {
|
||||
// printf("%s refused to forward to %s: max hop count exceeded" ZT_EOL_S,ip->toString(ipstr),dest.toString(astr));
|
||||
s_discardedForwardRate.log(now, pkt.size());
|
||||
|
@ -633,7 +672,8 @@ static void handlePacket(const int sock,const InetAddress *const ip,Packet &pkt)
|
|||
s_forwardRate.log(now, pkt.size());
|
||||
forwardTo->lastSend = now;
|
||||
}
|
||||
} else if (forwardTo->v4s >= 0) {
|
||||
}
|
||||
else if (forwardTo->v4s >= 0) {
|
||||
if (sendto(forwardTo->v4s, pkt.data(), pkt.size(), SENDTO_FLAGS, (const struct sockaddr*)&(forwardTo->ip4), (socklen_t)sizeof(struct sockaddr_in)) > 0) {
|
||||
s_outputRate.log(now, pkt.size());
|
||||
s_forwardRate.log(now, pkt.size());
|
||||
|
@ -667,19 +707,24 @@ static int bindSocket(struct sockaddr *const bindAddr)
|
|||
}
|
||||
|
||||
if (bindAddr->sa_family == AF_INET6) {
|
||||
f = 1; setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(void *)&f,sizeof(f));
|
||||
f = 1;
|
||||
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&f, sizeof(f));
|
||||
#ifdef IPV6_MTU_DISCOVER
|
||||
f = 0; setsockopt(s,IPPROTO_IPV6,IPV6_MTU_DISCOVER,&f,sizeof(f));
|
||||
f = 0;
|
||||
setsockopt(s, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &f, sizeof(f));
|
||||
#endif
|
||||
#ifdef IPV6_DONTFRAG
|
||||
f = 0; setsockopt(s,IPPROTO_IPV6,IPV6_DONTFRAG,&f,sizeof(f));
|
||||
f = 0;
|
||||
setsockopt(s, IPPROTO_IPV6, IPV6_DONTFRAG, &f, sizeof(f));
|
||||
#endif
|
||||
}
|
||||
#ifdef IP_DONTFRAG
|
||||
f = 0; setsockopt(s,IPPROTO_IP,IP_DONTFRAG,&f,sizeof(f));
|
||||
f = 0;
|
||||
setsockopt(s, IPPROTO_IP, IP_DONTFRAG, &f, sizeof(f));
|
||||
#endif
|
||||
#ifdef IP_MTU_DISCOVER
|
||||
f = IP_PMTUDISC_DONT; setsockopt(s,IPPROTO_IP,IP_MTU_DISCOVER,&f,sizeof(f));
|
||||
f = IP_PMTUDISC_DONT;
|
||||
setsockopt(s, IPPROTO_IP, IP_MTU_DISCOVER, &f, sizeof(f));
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -691,10 +736,12 @@ static int bindSocket(struct sockaddr *const bindAddr)
|
|||
*/
|
||||
|
||||
#ifdef SO_REUSEPORT
|
||||
f = 1; setsockopt(s,SOL_SOCKET,SO_REUSEPORT,(void *)&f,sizeof(f));
|
||||
f = 1;
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (void*)&f, sizeof(f));
|
||||
#endif
|
||||
#ifndef __LINUX__ // linux wants just SO_REUSEPORT
|
||||
f = 1; setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(void *)&f,sizeof(f));
|
||||
f = 1;
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&f, sizeof(f));
|
||||
#endif
|
||||
|
||||
#ifdef __LINUX__
|
||||
|
@ -763,10 +810,12 @@ int main(int argc,char **argv)
|
|||
}
|
||||
try {
|
||||
s_config = json::parse(configStr);
|
||||
} catch (std::exception &exc) {
|
||||
}
|
||||
catch (std::exception& exc) {
|
||||
printf("FATAL: config file at %s invalid: %s" ZT_EOL_S, argv[2], exc.what());
|
||||
return 1;
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
printf("FATAL: config file at %s invalid: unknown exception" ZT_EOL_S, argv[2]);
|
||||
return 1;
|
||||
}
|
||||
|
@ -787,7 +836,8 @@ int main(int argc,char **argv)
|
|||
}
|
||||
s_ports.push_back(port);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int port = jport;
|
||||
if ((port <= 0) || (port > 65535)) {
|
||||
printf("FATAL: invalid port in config file %d" ZT_EOL_S, port);
|
||||
|
@ -795,7 +845,9 @@ int main(int argc,char **argv)
|
|||
}
|
||||
s_ports.push_back(port);
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
if (s_ports.empty())
|
||||
s_ports.push_back(ZT_DEFAULT_PORT);
|
||||
std::sort(s_ports.begin(), s_ports.end());
|
||||
|
@ -807,14 +859,16 @@ int main(int argc,char **argv)
|
|||
printf("FATAL: invalid HTTP port in config file %d" ZT_EOL_S, httpPort);
|
||||
return 1;
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
httpPort = ZT_DEFAULT_PORT;
|
||||
}
|
||||
|
||||
std::string planetFilePath;
|
||||
try {
|
||||
planetFilePath = s_config["planetFile"];
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
planetFilePath = "";
|
||||
}
|
||||
|
||||
|
@ -824,7 +878,8 @@ int main(int argc,char **argv)
|
|||
s_statsRoot = s_statsRoot.substr(0, s_statsRoot.length() - 1);
|
||||
if (s_statsRoot.length() > 0)
|
||||
OSUtils::mkdir(s_statsRoot);
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
s_statsRoot = "";
|
||||
}
|
||||
|
||||
|
@ -835,7 +890,8 @@ int main(int argc,char **argv)
|
|||
s_relayMaxHops = ZT_PROTO_MAX_HOPS;
|
||||
else if (s_relayMaxHops < 0)
|
||||
s_relayMaxHops = 0;
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
s_relayMaxHops = ZT_RELAY_MAX_HOPS;
|
||||
}
|
||||
|
||||
|
@ -872,21 +928,27 @@ int main(int argc,char **argv)
|
|||
if ((start) && (end) && (start.ss_family == end.ss_family) && (lat >= -90.0F) && (lat <= 90.0F) && (lon >= -180.0F) && (lon <= 180.0F)) {
|
||||
if (start.ss_family == AF_INET) {
|
||||
s_geoIp4[std::pair<uint32_t, uint32_t>(ip4ToH32(start), ip4ToH32(end))] = std::pair<float, float>(lat, lon);
|
||||
} else if (start.ss_family == AF_INET6) {
|
||||
}
|
||||
else if (start.ss_family == AF_INET6) {
|
||||
s_geoIp6[std::pair<std::array<uint64_t, 2>, std::array<uint64_t, 2> >(ip6ToH128(start), ip6ToH128(end))] = std::pair<float, float>(lat, lon);
|
||||
}
|
||||
}
|
||||
}
|
||||
s_geoInit = true;
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
fclose(gf);
|
||||
}));
|
||||
}
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
|
||||
unsigned int ncores = std::thread::hardware_concurrency();
|
||||
if (ncores == 0) ncores = 1;
|
||||
if (ncores == 0)
|
||||
ncores = 1;
|
||||
|
||||
s_run = true;
|
||||
|
||||
|
@ -901,7 +963,8 @@ int main(int argc,char **argv)
|
|||
if (likely(! (*p)->identityValidated)) {
|
||||
if (likely((*p)->id.locallyValidate())) {
|
||||
(*p)->identityValidated = true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
{
|
||||
std::lock_guard<std::mutex> p_l(s_peersByVirtAddr_l);
|
||||
auto pp = s_peersByVirtAddr.find((*p)->id.address());
|
||||
|
@ -950,8 +1013,10 @@ int main(int argc,char **argv)
|
|||
|
||||
sockets.push_back(s6);
|
||||
sockets.push_back(s4);
|
||||
if (v4Sock < 0) v4Sock = s4;
|
||||
if (v6Sock < 0) v6Sock = s6;
|
||||
if (v4Sock < 0)
|
||||
v4Sock = s4;
|
||||
if (v6Sock < 0)
|
||||
v6Sock = s6;
|
||||
|
||||
threads.push_back(std::thread([s6, s4]() {
|
||||
struct sockaddr_in6 in6;
|
||||
|
@ -965,18 +1030,22 @@ int main(int argc,char **argv)
|
|||
try {
|
||||
pkt->setSize((unsigned int)pl);
|
||||
handlePacket(s6, reinterpret_cast<const InetAddress*>(&in6), *pkt);
|
||||
} catch (std::exception &exc) {
|
||||
}
|
||||
catch (std::exception& exc) {
|
||||
char ipstr[128];
|
||||
printf("WARNING: unexpected exception handling packet from %s: %s" ZT_EOL_S, reinterpret_cast<const InetAddress*>(&in6)->toString(ipstr), exc.what());
|
||||
} catch (int exc) {
|
||||
}
|
||||
catch (int exc) {
|
||||
char ipstr[128];
|
||||
printf("WARNING: unexpected exception handling packet from %s: ZT exception code %d" ZT_EOL_S, reinterpret_cast<const InetAddress*>(&in6)->toString(ipstr), exc);
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
char ipstr[128];
|
||||
printf("WARNING: unexpected exception handling packet from %s: unknown exception" ZT_EOL_S, reinterpret_cast<const InetAddress*>(&in6)->toString(ipstr));
|
||||
}
|
||||
}
|
||||
} else if (!s_run) {
|
||||
}
|
||||
else if (! s_run) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -995,18 +1064,22 @@ int main(int argc,char **argv)
|
|||
try {
|
||||
pkt->setSize((unsigned int)pl);
|
||||
handlePacket(s4, reinterpret_cast<const InetAddress*>(&in4), *pkt);
|
||||
} catch (std::exception &exc) {
|
||||
}
|
||||
catch (std::exception& exc) {
|
||||
char ipstr[128];
|
||||
printf("WARNING: unexpected exception handling packet from %s: %s" ZT_EOL_S, reinterpret_cast<const InetAddress*>(&in4)->toString(ipstr), exc.what());
|
||||
} catch (int exc) {
|
||||
}
|
||||
catch (int exc) {
|
||||
char ipstr[128];
|
||||
printf("WARNING: unexpected exception handling packet from %s: ZT exception code %d" ZT_EOL_S, reinterpret_cast<const InetAddress*>(&in4)->toString(ipstr), exc);
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
char ipstr[128];
|
||||
printf("WARNING: unexpected exception handling packet from %s: unknown exception" ZT_EOL_S, reinterpret_cast<const InetAddress*>(&in4)->toString(ipstr));
|
||||
}
|
||||
}
|
||||
} else if (!s_run) {
|
||||
}
|
||||
else if (! s_run) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1067,41 +1140,45 @@ int main(int argc,char **argv)
|
|||
for (auto p = s_peers.begin(); p != s_peers.end(); ++p) {
|
||||
if (first)
|
||||
first = false;
|
||||
else o << ',';
|
||||
o <<
|
||||
"{\"address\":\"" << (*p)->id.address().toString(tmp) << "\""
|
||||
else
|
||||
o << ',';
|
||||
o << "{\"address\":\"" << (*p)->id.address().toString(tmp)
|
||||
<< "\""
|
||||
",\"latency\":-1"
|
||||
",\"paths\":[";
|
||||
if ((*p)->v4s >= 0) {
|
||||
o <<
|
||||
"{\"active\":true"
|
||||
",\"address\":\"" << (*p)->ip4.toIpString(tmp) << "\\/" << (*p)->ip4.port() << "\""
|
||||
o << "{\"active\":true"
|
||||
",\"address\":\""
|
||||
<< (*p)->ip4.toIpString(tmp) << "\\/" << (*p)->ip4.port()
|
||||
<< "\""
|
||||
",\"expired\":false"
|
||||
",\"lastReceive\":" << (*p)->lastReceive <<
|
||||
",\"lastSend\":" << (*p)->lastSend <<
|
||||
",\"preferred\":true"
|
||||
",\"lastReceive\":"
|
||||
<< (*p)->lastReceive << ",\"lastSend\":" << (*p)->lastSend
|
||||
<< ",\"preferred\":true"
|
||||
",\"trustedPathId\":0}";
|
||||
}
|
||||
if ((*p)->v6s >= 0) {
|
||||
if ((*p)->v4s >= 0)
|
||||
o << ',';
|
||||
o <<
|
||||
"{\"active\":true"
|
||||
",\"address\":\"" << (*p)->ip6.toIpString(tmp) << "\\/" << (*p)->ip6.port() << "\""
|
||||
o << "{\"active\":true"
|
||||
",\"address\":\""
|
||||
<< (*p)->ip6.toIpString(tmp) << "\\/" << (*p)->ip6.port()
|
||||
<< "\""
|
||||
",\"expired\":false"
|
||||
",\"lastReceive\":" << (*p)->lastReceive <<
|
||||
",\"lastSend\":" << (*p)->lastSend <<
|
||||
",\"preferred\":" << (((*p)->ip4) ? "false" : "true") <<
|
||||
",\"trustedPathId\":0}";
|
||||
",\"lastReceive\":"
|
||||
<< (*p)->lastReceive << ",\"lastSend\":" << (*p)->lastSend << ",\"preferred\":" << (((*p)->ip4) ? "false" : "true") << ",\"trustedPathId\":0}";
|
||||
}
|
||||
o << "]"
|
||||
",\"role\":\"LEAF\""
|
||||
",\"version\":\"" << (*p)->vMajor << '.' << (*p)->vMinor << '.' << (*p)->vRev << "\""
|
||||
",\"versionMajor\":" << (*p)->vMajor <<
|
||||
",\"versionMinor\":" << (*p)->vMinor <<
|
||||
",\"versionRev\":" << (*p)->vRev << "}";
|
||||
",\"version\":\""
|
||||
<< (*p)->vMajor << '.' << (*p)->vMinor << '.' << (*p)->vRev
|
||||
<< "\""
|
||||
",\"versionMajor\":"
|
||||
<< (*p)->vMajor << ",\"versionMinor\":" << (*p)->vMinor << ",\"versionRev\":" << (*p)->vRev << "}";
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
o << ']';
|
||||
res.set_content(o.str(), "application/json");
|
||||
});
|
||||
|
@ -1119,7 +1196,8 @@ int main(int argc,char **argv)
|
|||
bool firstCoord = true;
|
||||
std::pair<uint32_t, uint32_t> k4(0, 0xffffffff);
|
||||
std::pair<std::array<uint64_t, 2>, std::array<uint64_t, 2> > k6;
|
||||
k6.second[0] = 0xffffffffffffffffULL; k6.second[1] = 0xffffffffffffffffULL;
|
||||
k6.second[0] = 0xffffffffffffffffULL;
|
||||
k6.second[1] = 0xffffffffffffffffULL;
|
||||
|
||||
std::unordered_map<InetAddress, std::set<Address>, InetAddressHasher> ips;
|
||||
{
|
||||
|
@ -1145,7 +1223,8 @@ int main(int argc,char **argv)
|
|||
bestRangeSize = range;
|
||||
bestRangeLatLon = geo->second;
|
||||
}
|
||||
} else if ((geo->first.first < k4.first)&&(geo->first.second < k4.first)) {
|
||||
}
|
||||
else if ((geo->first.first < k4.first) && (geo->first.second < k4.first)) {
|
||||
break;
|
||||
}
|
||||
++geo;
|
||||
|
@ -1164,7 +1243,8 @@ int main(int argc,char **argv)
|
|||
}
|
||||
o << "\"}";
|
||||
}
|
||||
} else if (p->first.isV6()) {
|
||||
}
|
||||
else if (p->first.isV6()) {
|
||||
k6.first = ip6ToH128(p->first);
|
||||
auto geo = std::map<std::pair<std::array<uint64_t, 2>, std::array<uint64_t, 2> >, std::pair<float, float> >::reverse_iterator(s_geoIp6.upper_bound(k6));
|
||||
while (geo != s_geoIp6.rend()) {
|
||||
|
@ -1182,14 +1262,16 @@ int main(int argc,char **argv)
|
|||
}
|
||||
o << "\"}";
|
||||
break;
|
||||
} else if ((geo->first.first < k6.first)&&(geo->first.second < k6.first)) {
|
||||
}
|
||||
else if ((geo->first.first < k6.first) && (geo->first.second < k6.first)) {
|
||||
break;
|
||||
}
|
||||
++geo;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
res.set_content("Internal error: unexpected exception resolving GeoIP locations", "text/plain");
|
||||
return;
|
||||
}
|
||||
|
@ -1220,15 +1302,18 @@ int main(int argc,char **argv)
|
|||
for (auto c = b->second.begin(); c != b->second.end();) {
|
||||
if ((now - c->second) > ZT_MULTICAST_LIKE_EXPIRE)
|
||||
b->second.erase(c++);
|
||||
else ++c;
|
||||
else
|
||||
++c;
|
||||
}
|
||||
if (b->second.empty())
|
||||
a->second.erase(b++);
|
||||
else ++b;
|
||||
else
|
||||
++b;
|
||||
}
|
||||
if (a->second.empty())
|
||||
s_multicastSubscriptions.erase(a++);
|
||||
else ++a;
|
||||
else
|
||||
++a;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1243,7 +1328,8 @@ int main(int argc,char **argv)
|
|||
if ((now - (*p)->lastReceive) > ZT_PEER_ACTIVITY_TIMEOUT) {
|
||||
toRemove.emplace_back();
|
||||
p->swap(toRemove.back());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
newPeers.emplace_back();
|
||||
p->swap(newPeers.back());
|
||||
}
|
||||
|
@ -1259,7 +1345,9 @@ int main(int argc,char **argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
|
||||
// Remove old rendezvous entries
|
||||
{
|
||||
|
@ -1267,7 +1355,8 @@ int main(int argc,char **argv)
|
|||
for (auto lr = s_rendezvousTracking.begin(); lr != s_rendezvousTracking.end();) {
|
||||
if ((now - lr->second.ts) > ZT_PEER_ACTIVITY_TIMEOUT)
|
||||
s_rendezvousTracking.erase(lr++);
|
||||
else ++lr;
|
||||
else
|
||||
++lr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1284,7 +1373,8 @@ int main(int argc,char **argv)
|
|||
s_planet = planetData;
|
||||
}
|
||||
}
|
||||
} catch ( ... ) {
|
||||
}
|
||||
catch (...) {
|
||||
std::lock_guard<std::mutex> pl(s_planet_l);
|
||||
s_planet.clear();
|
||||
}
|
||||
|
@ -1309,23 +1399,20 @@ int main(int argc,char **argv)
|
|||
for (auto p = sp.begin(); p != sp.end(); ++p) {
|
||||
if ((*p)->v4s >= 0) {
|
||||
(*p)->ip4.toString(ip4);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ip4[0] = '-';
|
||||
ip4[1] = 0;
|
||||
}
|
||||
if ((*p)->v6s >= 0) {
|
||||
(*p)->ip6.toString(ip6);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ip6[0] = '-';
|
||||
ip6[1] = 0;
|
||||
}
|
||||
OSUtils::ztsnprintf(ver, sizeof(ver), "%d.%d.%d", (*p)->vMajor, (*p)->vMinor, (*p)->vRev);
|
||||
fprintf(pf,"%.10llx %21s %45s %10.4f %6s" ZT_EOL_S,
|
||||
(unsigned long long)(*p)->id.address().toInt(),
|
||||
ip4,
|
||||
ip6,
|
||||
fabs((double)(now - (*p)->lastReceive) / 1000.0),
|
||||
ver);
|
||||
fprintf(pf, "%.10llx %21s %45s %10.4f %6s" ZT_EOL_S, (unsigned long long)(*p)->id.address().toInt(), ip4, ip6, fabs((double)(now - (*p)->lastReceive) / 1000.0), ver);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1353,7 +1440,8 @@ int main(int argc,char **argv)
|
|||
fprintf(sf, "Recent P2P Graph Edges : %llu" ZT_EOL_S, (unsigned long long)s_rendezvousTracking.size());
|
||||
if (s_rendezvousTracking.empty()) {
|
||||
fprintf(sf, "Recent P2P Success Rate : 100.0000%%" ZT_EOL_S);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
fprintf(sf, "Recent P2P Success Rate : %.4f%%" ZT_EOL_S, (1.0 - ((double)unsuccessfulp2p / (double)s_rendezvousTracking.size())) * 100.0);
|
||||
}
|
||||
s_rendezvousTracking_l.unlock();
|
||||
|
|
Loading…
Add table
Reference in a new issue