mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 20:13:44 +02:00
Makefile changes, and make Topology::getBestSupernode() return the "next" supernode if I am a supernode. Also some comment cleanup.
This commit is contained in:
parent
95d123cfc2
commit
282114e96c
4 changed files with 108 additions and 91 deletions
|
@ -35,7 +35,6 @@ endif
|
||||||
#LDFLAGS=
|
#LDFLAGS=
|
||||||
#STRIP=echo
|
#STRIP=echo
|
||||||
|
|
||||||
# Our code doesn't use rtti, so don't bloat the binary with it.
|
|
||||||
CXXFLAGS=$(CFLAGS) -fno-rtti
|
CXXFLAGS=$(CFLAGS) -fno-rtti
|
||||||
|
|
||||||
include objects.mk
|
include objects.mk
|
||||||
|
|
48
make-mac.mk
48
make-mac.mk
|
@ -15,7 +15,6 @@ ifeq ($(ZT_OFFICIAL_RELEASE),1)
|
||||||
CODESIGN=codesign
|
CODESIGN=codesign
|
||||||
CODESIGN_CERT="Developer ID Application: ZeroTier Networks LLC (8ZD9JUCZ4V)"
|
CODESIGN_CERT="Developer ID Application: ZeroTier Networks LLC (8ZD9JUCZ4V)"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(ZT_AUTO_UPDATE),1)
|
ifeq ($(ZT_AUTO_UPDATE),1)
|
||||||
DEFS+=-DZT_AUTO_UPDATE
|
DEFS+=-DZT_AUTO_UPDATE
|
||||||
endif
|
endif
|
||||||
|
@ -23,34 +22,34 @@ endif
|
||||||
# Enable SSE-optimized Salsa20
|
# Enable SSE-optimized Salsa20
|
||||||
DEFS+=-DZT_SALSA20_SSE
|
DEFS+=-DZT_SALSA20_SSE
|
||||||
|
|
||||||
# Uncomment to dump trace and log info to stdout (useful for debug/test)
|
# "make debug" is a shortcut for this
|
||||||
#DEFS+=-DZT_TRACE -DZT_LOG_STDOUT
|
ifeq ($(ZT_DEBUG),1)
|
||||||
|
CFLAGS=-Wall -g -pthread -DZT_TRACE -DZT_LOG_STDOUT $(INCLUDES) $(DEFS)
|
||||||
# Uncomment for a release optimized universal binary build
|
STRIP=echo
|
||||||
CFLAGS=-arch i386 -arch x86_64 -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
|
DEFS+=-DZT_TRACE -DZT_LOG_STDOUT
|
||||||
STRIP=strip
|
else
|
||||||
|
CFLAGS=-arch i386 -arch x86_64 -Wall -O3 -flto -fPIE -fvectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS)
|
||||||
# Uncomment for a debug build
|
STRIP=strip
|
||||||
#CFLAGS=-Wall -g -pthread -DZT_TRACE -DZT_LOG_STDOUT $(INCLUDES) $(DEFS)
|
endif
|
||||||
#STRIP=echo
|
|
||||||
|
|
||||||
CXXFLAGS=$(CFLAGS) -fno-rtti
|
CXXFLAGS=$(CFLAGS) -fno-rtti
|
||||||
|
|
||||||
include objects.mk
|
include objects.mk
|
||||||
OBJS+=osnet/BSDRoutingTable.o osnet/OSXEthernetTap.o osnet/OSXEthernetTapFactory.o
|
OBJS+=main.o osnet/BSDRoutingTable.o osnet/OSXEthernetTap.o osnet/OSXEthernetTapFactory.o
|
||||||
|
|
||||||
all: one
|
all: one
|
||||||
|
|
||||||
one: $(OBJS)
|
one: $(OBJS)
|
||||||
$(CXX) $(CXXFLAGS) -o zerotier-one main.cpp $(OBJS) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o zerotier-one $(OBJS) $(LIBS)
|
||||||
$(STRIP) zerotier-one
|
$(STRIP) zerotier-one
|
||||||
ln -sf zerotier-one zerotier-cli
|
ln -sf zerotier-one zerotier-cli
|
||||||
ln -sf zerotier-one zerotier-idtool
|
ln -sf zerotier-one zerotier-idtool
|
||||||
|
|
||||||
selftest: $(OBJS)
|
selftest: $(OBJS) selftest.o
|
||||||
$(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.cpp $(OBJS) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.o $(OBJS) $(LIBS)
|
||||||
$(STRIP) zerotier-selftest
|
$(STRIP) zerotier-selftest
|
||||||
|
|
||||||
|
# Requires that ../Qt be symlinked to the Qt root to use for UI build
|
||||||
mac-ui: FORCE
|
mac-ui: FORCE
|
||||||
mkdir -p build-ZeroTierUI-release
|
mkdir -p build-ZeroTierUI-release
|
||||||
cd build-ZeroTierUI-release ; ../../Qt/bin/qmake ../ZeroTierUI/ZeroTierUI.pro ; make -j 4
|
cd build-ZeroTierUI-release ; ../../Qt/bin/qmake ../ZeroTierUI/ZeroTierUI.pro ; make -j 4
|
||||||
|
@ -59,15 +58,13 @@ mac-ui: FORCE
|
||||||
$(CODESIGN) -f -s $(CODESIGN_CERT) "build-ZeroTierUI-release/ZeroTier One.app"
|
$(CODESIGN) -f -s $(CODESIGN_CERT) "build-ZeroTierUI-release/ZeroTier One.app"
|
||||||
$(CODESIGN) -vvv "build-ZeroTierUI-release/ZeroTier One.app"
|
$(CODESIGN) -vvv "build-ZeroTierUI-release/ZeroTier One.app"
|
||||||
|
|
||||||
install-mac-tap: FORCE
|
|
||||||
mkdir -p /Library/Application\ Support/ZeroTier/One
|
|
||||||
rm -rf /Library/Application\ Support/ZeroTier/One/tap.kext
|
|
||||||
cp -R ext/bin/tap-mac/tap.kext /Library/Application\ Support/ZeroTier/One
|
|
||||||
chown -R root:wheel /Library/Application\ Support/ZeroTier/One/tap.kext
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf *.dSYM build-* $(OBJS) zerotier-* ZeroTierOneInstaller-* "ZeroTier One.zip" "ZeroTier One.dmg"
|
rm -rf *.dSYM main.o selftest.o build-* $(OBJS) zerotier-* ZeroTierOneInstaller-* "ZeroTier One.zip" "ZeroTier One.dmg"
|
||||||
|
|
||||||
|
debug: FORCE
|
||||||
|
make -j 4 ZT_DEBUG=1
|
||||||
|
|
||||||
|
# For our use -- builds official signed binary, packages in installer and download DMG
|
||||||
official: FORCE
|
official: FORCE
|
||||||
make -j 4 ZT_OFFICIAL_RELEASE=1
|
make -j 4 ZT_OFFICIAL_RELEASE=1
|
||||||
make mac-ui ZT_OFFICIAL_RELEASE=1
|
make mac-ui ZT_OFFICIAL_RELEASE=1
|
||||||
|
@ -80,4 +77,11 @@ official: FORCE
|
||||||
hdiutil convert /tmp/tmp.dmg -format UDZO -o "ZeroTier One.dmg"
|
hdiutil convert /tmp/tmp.dmg -format UDZO -o "ZeroTier One.dmg"
|
||||||
rm -f /tmp/tmp.dmg
|
rm -f /tmp/tmp.dmg
|
||||||
|
|
||||||
|
# For those building from source -- installs signed binary tap driver in system ZT home
|
||||||
|
install-mac-tap: FORCE
|
||||||
|
mkdir -p /Library/Application\ Support/ZeroTier/One
|
||||||
|
rm -rf /Library/Application\ Support/ZeroTier/One/tap.kext
|
||||||
|
cp -R ext/bin/tap-mac/tap.kext /Library/Application\ Support/ZeroTier/One
|
||||||
|
chown -R root:wheel /Library/Application\ Support/ZeroTier/One/tap.kext
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
|
@ -639,12 +639,12 @@ void Switch::cancelWhoisRequest(const Address &addr)
|
||||||
|
|
||||||
void Switch::doAnythingWaitingForPeer(const SharedPtr<Peer> &peer)
|
void Switch::doAnythingWaitingForPeer(const SharedPtr<Peer> &peer)
|
||||||
{
|
{
|
||||||
{
|
{ // cancel pending WHOIS since we now know this peer
|
||||||
Mutex::Lock _l(_outstandingWhoisRequests_m);
|
Mutex::Lock _l(_outstandingWhoisRequests_m);
|
||||||
_outstandingWhoisRequests.erase(peer->address());
|
_outstandingWhoisRequests.erase(peer->address());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ // finish processing any packets waiting on peer's public key / identity
|
||||||
Mutex::Lock _l(_rxQueue_m);
|
Mutex::Lock _l(_rxQueue_m);
|
||||||
for(std::list< SharedPtr<PacketDecoder> >::iterator rxi(_rxQueue.begin());rxi!=_rxQueue.end();) {
|
for(std::list< SharedPtr<PacketDecoder> >::iterator rxi(_rxQueue.begin());rxi!=_rxQueue.end();) {
|
||||||
if ((*rxi)->tryDecode(_r))
|
if ((*rxi)->tryDecode(_r))
|
||||||
|
@ -653,7 +653,7 @@ void Switch::doAnythingWaitingForPeer(const SharedPtr<Peer> &peer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{ // finish sending any packets waiting on peer's public key / identity
|
||||||
Mutex::Lock _l(_txQueue_m);
|
Mutex::Lock _l(_txQueue_m);
|
||||||
std::pair< std::multimap< Address,TXQueueEntry >::iterator,std::multimap< Address,TXQueueEntry >::iterator > waitingTxQueueItems(_txQueue.equal_range(peer->address()));
|
std::pair< std::multimap< Address,TXQueueEntry >::iterator,std::multimap< Address,TXQueueEntry >::iterator > waitingTxQueueItems(_txQueue.equal_range(peer->address()));
|
||||||
for(std::multimap< Address,TXQueueEntry >::iterator txi(waitingTxQueueItems.first);txi!=waitingTxQueueItems.second;) {
|
for(std::multimap< Address,TXQueueEntry >::iterator txi(waitingTxQueueItems.first);txi!=waitingTxQueueItems.second;) {
|
||||||
|
@ -690,8 +690,11 @@ void Switch::_handleRemotePacketFragment(const SharedPtr<Socket> &fromSock,const
|
||||||
if (fragment.hops() < ZT_RELAY_MAX_HOPS) {
|
if (fragment.hops() < ZT_RELAY_MAX_HOPS) {
|
||||||
fragment.incrementHops();
|
fragment.incrementHops();
|
||||||
|
|
||||||
|
// Note: we don't bother initiating NAT-t for fragments, since heads will set that off.
|
||||||
|
// It wouldn't hurt anything, just redundant and unnecessary.
|
||||||
SharedPtr<Peer> relayTo = _r->topology->getPeer(destination);
|
SharedPtr<Peer> relayTo = _r->topology->getPeer(destination);
|
||||||
if ((!relayTo)||(relayTo->send(_r,fragment.data(),fragment.size(),Utils::now()) == Path::PATH_TYPE_NULL)) {
|
if ((!relayTo)||(relayTo->send(_r,fragment.data(),fragment.size(),Utils::now()) == Path::PATH_TYPE_NULL)) {
|
||||||
|
// Don't know peer or no direct path -- so relay via supernode
|
||||||
relayTo = _r->topology->getBestSupernode();
|
relayTo = _r->topology->getBestSupernode();
|
||||||
if (relayTo)
|
if (relayTo)
|
||||||
relayTo->send(_r,fragment.data(),fragment.size(),Utils::now());
|
relayTo->send(_r,fragment.data(),fragment.size(),Utils::now());
|
||||||
|
@ -772,11 +775,7 @@ void Switch::_handleRemotePacketHead(const SharedPtr<Socket> &fromSock,const Ine
|
||||||
if ((fromSock->udp())&&(relayedVia == Path::PATH_TYPE_UDP))
|
if ((fromSock->udp())&&(relayedVia == Path::PATH_TYPE_UDP))
|
||||||
unite(source,destination,false);
|
unite(source,destination,false);
|
||||||
} else {
|
} else {
|
||||||
// If we've received a packet not for us and we don't have
|
// Don't know peer or no direct path -- so relay via supernode
|
||||||
// a direct path to its recipient, pass it to (another)
|
|
||||||
// supernode. This can happen due to Internet weather -- the
|
|
||||||
// most direct supernode may not be reachable, yet another
|
|
||||||
// further away may be.
|
|
||||||
relayTo = _r->topology->getBestSupernode(&source,1,true);
|
relayTo = _r->topology->getBestSupernode(&source,1,true);
|
||||||
if (relayTo)
|
if (relayTo)
|
||||||
relayTo->send(_r,packet->data(),packet->size(),Utils::now());
|
relayTo->send(_r,packet->data(),packet->size(),Utils::now());
|
||||||
|
@ -903,21 +902,9 @@ bool Switch::_trySend(const Packet &packet,bool encrypt)
|
||||||
remaining -= chunkSize;
|
remaining -= chunkSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* #ifdef ZT_TRACE
|
|
||||||
if (via != peer) {
|
|
||||||
TRACE(">> %s to %s via %s (%d)",Packet::verbString(packet.verb()),peer->address().toString().c_str(),via->address().toString().c_str(),(int)packet.size());
|
|
||||||
} else {
|
|
||||||
TRACE(">> %s to %s (%d)",Packet::verbString(packet.verb()),peer->address().toString().c_str(),(int)packet.size());
|
|
||||||
}
|
|
||||||
#endif */
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
} else requestWhois(packet.destination());
|
||||||
}
|
|
||||||
|
|
||||||
requestWhois(packet.destination());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,65 +161,92 @@ void Topology::saveIdentity(const Identity &id)
|
||||||
SharedPtr<Peer> Topology::getBestSupernode(const Address *avoid,unsigned int avoidCount,bool strictAvoid) const
|
SharedPtr<Peer> Topology::getBestSupernode(const Address *avoid,unsigned int avoidCount,bool strictAvoid) const
|
||||||
{
|
{
|
||||||
SharedPtr<Peer> bestSupernode;
|
SharedPtr<Peer> bestSupernode;
|
||||||
unsigned int l,bestSupernodeLatency = 65536;
|
|
||||||
uint64_t now = Utils::now();
|
uint64_t now = Utils::now();
|
||||||
uint64_t lds,ldr;
|
|
||||||
|
|
||||||
Mutex::Lock _l(_supernodes_m);
|
Mutex::Lock _l(_supernodes_m);
|
||||||
|
|
||||||
// First look for a best supernode by comparing latencies, but exclude
|
if (_amSupernode) {
|
||||||
// supernodes that have not responded to direct messages in order to
|
/* If I am a supernode, the "best" supernode is the one whose address
|
||||||
// try to exclude any that are dead or unreachable.
|
* is numerically greater than mine (with wrap at top of list). This
|
||||||
for(std::vector< SharedPtr<Peer> >::const_iterator sn(_supernodePeers.begin());sn!=_supernodePeers.end();) {
|
* causes packets searching for a route to pretty much literally
|
||||||
// Skip explicitly avoided relays
|
* circumnavigate the globe rather than bouncing between just two. */
|
||||||
for(unsigned int i=0;i<avoidCount;++i) {
|
|
||||||
if (avoid[i] == (*sn)->address())
|
|
||||||
goto keep_searching_for_supernodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip possibly comatose or unreachable relays
|
if (_supernodeAddresses.size() > 1) { // gotta be one other than me for this to work
|
||||||
lds = (*sn)->lastDirectSend();
|
std::set<Address>::const_iterator sna(_supernodeAddresses.find(_r->identity.address()));
|
||||||
ldr = (*sn)->lastDirectReceive();
|
if (sna != _supernodeAddresses.end()) { // sanity check -- _amSupernode should've been false in this case
|
||||||
if ((lds)&&(lds > ldr)&&((lds - ldr) > ZT_PEER_RELAY_CONVERSATION_LATENCY_THRESHOLD))
|
for(;;) {
|
||||||
goto keep_searching_for_supernodes;
|
if (++sna == _supernodeAddresses.end())
|
||||||
|
sna = _supernodeAddresses.begin(); // wrap around at end
|
||||||
if ((*sn)->hasActiveDirectPath(now)) {
|
if (*sna != _r->identity.address()) { // pick one other than us -- starting from me+1 in sorted set order
|
||||||
l = (*sn)->latency();
|
SharedPtr<Peer> p(getPeer(*sna));
|
||||||
if (bestSupernode) {
|
if ((p)&&(p->hasActiveDirectPath(now))) {
|
||||||
if ((l)&&(l < bestSupernodeLatency)) {
|
bestSupernode = p;
|
||||||
bestSupernodeLatency = l;
|
break;
|
||||||
bestSupernode = *sn;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (l)
|
|
||||||
bestSupernodeLatency = l;
|
|
||||||
bestSupernode = *sn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* If I am not a supernode, the best supernode is the active one with
|
||||||
|
* the lowest latency. */
|
||||||
|
|
||||||
keep_searching_for_supernodes:
|
unsigned int l,bestSupernodeLatency = 65536;
|
||||||
++sn;
|
uint64_t lds,ldr;
|
||||||
}
|
|
||||||
|
|
||||||
if (bestSupernode) {
|
// First look for a best supernode by comparing latencies, but exclude
|
||||||
bestSupernode->use(now);
|
// supernodes that have not responded to direct messages in order to
|
||||||
return bestSupernode;
|
// try to exclude any that are dead or unreachable.
|
||||||
} else if (strictAvoid)
|
for(std::vector< SharedPtr<Peer> >::const_iterator sn(_supernodePeers.begin());sn!=_supernodePeers.end();) {
|
||||||
return SharedPtr<Peer>();
|
// Skip explicitly avoided relays
|
||||||
|
for(unsigned int i=0;i<avoidCount;++i) {
|
||||||
|
if (avoid[i] == (*sn)->address())
|
||||||
|
goto keep_searching_for_supernodes;
|
||||||
|
}
|
||||||
|
|
||||||
// If we have nothing from above, just pick one without avoidance criteria.
|
// Skip possibly comatose or unreachable relays
|
||||||
for(std::vector< SharedPtr<Peer> >::const_iterator sn=_supernodePeers.begin();sn!=_supernodePeers.end();++sn) {
|
lds = (*sn)->lastDirectSend();
|
||||||
if ((*sn)->hasActiveDirectPath(now)) {
|
ldr = (*sn)->lastDirectReceive();
|
||||||
unsigned int l = (*sn)->latency();
|
if ((lds)&&(lds > ldr)&&((lds - ldr) > ZT_PEER_RELAY_CONVERSATION_LATENCY_THRESHOLD))
|
||||||
if (bestSupernode) {
|
goto keep_searching_for_supernodes;
|
||||||
if ((l)&&(l < bestSupernodeLatency)) {
|
|
||||||
bestSupernodeLatency = l;
|
if ((*sn)->hasActiveDirectPath(now)) {
|
||||||
|
l = (*sn)->latency();
|
||||||
|
if (bestSupernode) {
|
||||||
|
if ((l)&&(l < bestSupernodeLatency)) {
|
||||||
|
bestSupernodeLatency = l;
|
||||||
|
bestSupernode = *sn;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (l)
|
||||||
|
bestSupernodeLatency = l;
|
||||||
|
bestSupernode = *sn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keep_searching_for_supernodes:
|
||||||
|
++sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestSupernode) {
|
||||||
|
bestSupernode->use(now);
|
||||||
|
return bestSupernode;
|
||||||
|
} else if (strictAvoid)
|
||||||
|
return SharedPtr<Peer>();
|
||||||
|
|
||||||
|
// If we have nothing from above, just pick one without avoidance criteria.
|
||||||
|
for(std::vector< SharedPtr<Peer> >::const_iterator sn=_supernodePeers.begin();sn!=_supernodePeers.end();++sn) {
|
||||||
|
if ((*sn)->hasActiveDirectPath(now)) {
|
||||||
|
unsigned int l = (*sn)->latency();
|
||||||
|
if (bestSupernode) {
|
||||||
|
if ((l)&&(l < bestSupernodeLatency)) {
|
||||||
|
bestSupernodeLatency = l;
|
||||||
|
bestSupernode = *sn;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (l)
|
||||||
|
bestSupernodeLatency = l;
|
||||||
bestSupernode = *sn;
|
bestSupernode = *sn;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (l)
|
|
||||||
bestSupernodeLatency = l;
|
|
||||||
bestSupernode = *sn;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue