(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID));
}
@@ -625,7 +625,7 @@ bool IncomingPacket::_doEXT_FRAME(const RuntimeEnvironment *RR,const SharedPtrnode->putFrame(network->id(),from,to,etherType,0,field(comLen + ZT_PROTO_VERB_EXT_FRAME_IDX_PAYLOAD,payloadLen),payloadLen);
}
- peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,hops(),packetId(),Packet::VERB_EXT_FRAME,0,Packet::VERB_NOP);
} else {
TRACE("dropped EXT_FRAME from %s(%s): we are not connected to network %.16llx",source().toString().c_str(),_remoteAddress.toString().c_str(),at(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID));
}
@@ -646,7 +646,7 @@ bool IncomingPacket::_doMULTICAST_LIKE(const RuntimeEnvironment *RR,const Shared
for(unsigned int ptr=ZT_PACKET_IDX_PAYLOAD;ptrmc->add(now,at(ptr),MulticastGroup(MAC(field(ptr + 8,6),6),at(ptr + 14)),peer->address());
- peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP);
} catch (std::exception &ex) {
TRACE("dropped MULTICAST_LIKE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
} catch ( ... ) {
@@ -670,7 +670,7 @@ bool IncomingPacket::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment
}
}
- peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE,0,Packet::VERB_NOP);
} catch (std::exception &ex) {
TRACE("dropped NETWORK_MEMBERSHIP_CERTIFICATE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
} catch ( ... ) {
@@ -689,7 +689,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
const unsigned int h = hops();
const uint64_t pid = packetId();
- peer->received(RR,_remoteAddress,_linkDesperation,h,pid,Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,h,pid,Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP);
if (RR->localNetworkController) {
Dictionary netconf;
@@ -709,7 +709,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
if (outp.size() > ZT_PROTO_MAX_PACKET_LENGTH) {
TRACE("NETWORK_CONFIG_REQUEST failed: internal error: netconf size %u is too large",(unsigned int)netconfStr.length());
} else {
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
}
}
} break;
@@ -722,7 +722,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
outp.append((unsigned char)Packet::ERROR_OBJ_NOT_FOUND);
outp.append(nwid);
outp.armor(peer->key(),true);
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
} break;
case NetworkController::NETCONF_QUERY_ACCESS_DENIED: {
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_ERROR);
@@ -731,7 +731,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
outp.append((unsigned char)Packet::ERROR_NETWORK_ACCESS_DENIED_);
outp.append(nwid);
outp.armor(peer->key(),true);
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
} break;
case NetworkController::NETCONF_QUERY_INTERNAL_SERVER_ERROR:
TRACE("NETWORK_CONFIG_REQUEST failed: internal error: %s",netconf.get("error","(unknown)").c_str());
@@ -747,7 +747,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
outp.append((unsigned char)Packet::ERROR_UNSUPPORTED_OPERATION);
outp.append(nwid);
outp.armor(peer->key(),true);
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
}
} catch (std::exception &exc) {
TRACE("dropped NETWORK_CONFIG_REQUEST from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
@@ -768,7 +768,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REFRESH(const RuntimeEnvironment *RR,cons
nw->requestConfiguration();
ptr += 8;
}
- peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REFRESH,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REFRESH,0,Packet::VERB_NOP);
} catch (std::exception &exc) {
TRACE("dropped NETWORK_CONFIG_REFRESH from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
} catch ( ... ) {
@@ -795,11 +795,11 @@ bool IncomingPacket::_doMULTICAST_GATHER(const RuntimeEnvironment *RR,const Shar
outp.append((uint32_t)mg.adi());
if (RR->mc->gather(peer->address(),nwid,mg,outp,gatherLimit)) {
outp.armor(peer->key(),true);
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
}
}
- peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_MULTICAST_GATHER,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_GATHER,0,Packet::VERB_NOP);
} catch (std::exception &exc) {
TRACE("dropped MULTICAST_GATHER from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
} catch ( ... ) {
@@ -886,12 +886,12 @@ bool IncomingPacket::_doMULTICAST_FRAME(const RuntimeEnvironment *RR,const Share
outp.append((unsigned char)0x02); // flag 0x02 = contains gather results
if (RR->mc->gather(peer->address(),nwid,to,outp,gatherLimit)) {
outp.armor(peer->key(),true);
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
}
}
} // else ignore -- not a member of this network
- peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_MULTICAST_FRAME,0,Packet::VERB_NOP);
+ peer->received(RR,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_FRAME,0,Packet::VERB_NOP);
} catch (std::exception &exc) {
TRACE("dropped MULTICAST_FRAME from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
} catch ( ... ) {
@@ -908,7 +908,7 @@ void IncomingPacket::_sendErrorNeedCertificate(const RuntimeEnvironment *RR,cons
outp.append((unsigned char)Packet::ERROR_NEED_MEMBERSHIP_CERTIFICATE);
outp.append(nwid);
outp.armor(peer->key(),true);
- RR->node->putPacket(_remoteAddress,outp.data(),outp.size(),_linkDesperation);
+ RR->node->putPacket(_remoteAddress,outp.data(),outp.size());
}
} // namespace ZeroTier
diff --git a/node/IncomingPacket.hpp b/node/IncomingPacket.hpp
index 5940a78ec..174fa38dc 100644
--- a/node/IncomingPacket.hpp
+++ b/node/IncomingPacket.hpp
@@ -73,15 +73,13 @@ public:
* @param data Packet data
* @param len Packet length
* @param remoteAddress Address from which packet came
- * @param linkDesperation Link desperation for link over which packet was received
* @param now Current time
* @throws std::out_of_range Range error processing packet
*/
- IncomingPacket(const void *data,unsigned int len,const InetAddress &remoteAddress,unsigned int linkDesperation,uint64_t now) :
+ IncomingPacket(const void *data,unsigned int len,const InetAddress &remoteAddress,uint64_t now) :
Packet(data,len),
_receiveTime(now),
_remoteAddress(remoteAddress),
- _linkDesperation(linkDesperation),
__refCount()
{
}
@@ -129,7 +127,6 @@ private:
uint64_t _receiveTime;
InetAddress _remoteAddress;
- unsigned int _linkDesperation;
AtomicCounter __refCount;
};
diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp
index 54fc763fe..940a58b26 100644
--- a/node/InetAddress.cpp
+++ b/node/InetAddress.cpp
@@ -137,8 +137,7 @@ void InetAddress::set(const void *ipBytes,unsigned int ipLen,unsigned int port)
reinterpret_cast(this)->sin_port = Utils::hton((uint16_t)port);
} else if (ipLen == 16) {
ss_family = AF_INET6;
- (reinterpret_cast(reinterpret_cast(this)->sin6_addr.s6_addr))[0] = ((const uint64_t *)ipBytes)[0];
- (reinterpret_cast(reinterpret_cast(this)->sin6_addr.s6_addr))[1] = ((const uint64_t *)ipBytes)[1];
+ memcpy(reinterpret_cast(this)->sin6_addr.s6_addr,ipBytes,16);
reinterpret_cast(this)->sin6_port = Utils::hton((uint16_t)port);
}
}
diff --git a/node/Node.cpp b/node/Node.cpp
index 654465e8d..6b3f1f2c9 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -80,8 +80,7 @@ Node::Node(
_startTimeAfterInactivity(0),
_lastPingCheck(0),
_lastHousekeepingRun(0),
- _lastBeacon(0),
- _coreDesperation(0)
+ _lastBeacon(0)
{
_newestVersionSeen[0] = ZEROTIER_ONE_VERSION_MAJOR;
_newestVersionSeen[1] = ZEROTIER_ONE_VERSION_MINOR;
@@ -155,13 +154,12 @@ Node::~Node()
ZT1_ResultCode Node::processWirePacket(
uint64_t now,
const struct sockaddr_storage *remoteAddress,
- unsigned int linkDesperation,
const void *packetData,
unsigned int packetLength,
volatile uint64_t *nextBackgroundTaskDeadline)
{
_now = now;
- RR->sw->onRemotePacket(*(reinterpret_cast(remoteAddress)),linkDesperation,packetData,packetLength);
+ RR->sw->onRemotePacket(*(reinterpret_cast(remoteAddress)),packetData,packetLength);
return ZT1_RESULT_OK;
}
@@ -219,8 +217,7 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
if ((now - _lastPingCheck) >= ZT_PING_CHECK_INVERVAL) {
_lastPingCheck = now;
- // This is used as a floor for the desperation and online status
- // calculations if we just started up or have been asleep.
+ // This is used to compute whether we appear to be "online" or not
if ((now - _startTimeAfterInactivity) > (ZT_PING_CHECK_INVERVAL * 3))
_startTimeAfterInactivity = now;
@@ -229,7 +226,6 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
RR->topology->eachPeer<_PingPeersThatNeedPing &>(pfunc);
const uint64_t lastActivityAgo = now - std::max(_startTimeAfterInactivity,pfunc.lastReceiveFromUpstream);
- _coreDesperation = (unsigned int)(lastActivityAgo / (ZT_PING_CHECK_INVERVAL * ZT_CORE_DESPERATION_INCREMENT));
bool oldOnline = _online;
_online = (lastActivityAgo < ZT_PEER_ACTIVITY_TIMEOUT);
if (oldOnline != _online)
@@ -251,11 +247,13 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
if ((now - _lastBeacon) >= ZT_BEACON_INTERVAL) {
_lastBeacon = now;
char beacon[13];
- *(reinterpret_cast(beacon)) = RR->prng->next32();
- *(reinterpret_cast(beacon + 4)) = RR->prng->next32();
+ void *p = beacon;
+ *(reinterpret_cast(p)) = RR->prng->next32();
+ p = beacon + 4;
+ *(reinterpret_cast(p)) = RR->prng->next32();
RR->identity.address().copyTo(beacon + 8,5);
RR->antiRec->logOutgoingZT(beacon,13);
- putPacket(ZT_DEFAULTS.v4Broadcast,beacon,13,0);
+ putPacket(ZT_DEFAULTS.v4Broadcast,beacon,13);
}
}
@@ -441,7 +439,7 @@ std::string Node::dataStoreGet(const char *name)
void Node::postNewerVersionIfNewer(unsigned int major,unsigned int minor,unsigned int rev)
{
- if (Peer::compareVersion(major,minor,rev,_newestVersionSeen[0],_newestVersionSeen[1],_newestVersionSeen[2]) > 0) {
+ if (Utils::compareVersion(major,minor,rev,_newestVersionSeen[0],_newestVersionSeen[1],_newestVersionSeen[2]) > 0) {
_newestVersionSeen[0] = major;
_newestVersionSeen[1] = minor;
_newestVersionSeen[2] = rev;
@@ -526,13 +524,12 @@ enum ZT1_ResultCode ZT1_Node_processWirePacket(
ZT1_Node *node,
uint64_t now,
const struct sockaddr_storage *remoteAddress,
- unsigned int linkDesperation,
const void *packetData,
unsigned int packetLength,
volatile uint64_t *nextBackgroundTaskDeadline)
{
try {
- return reinterpret_cast(node)->processWirePacket(now,remoteAddress,linkDesperation,packetData,packetLength,nextBackgroundTaskDeadline);
+ return reinterpret_cast(node)->processWirePacket(now,remoteAddress,packetData,packetLength,nextBackgroundTaskDeadline);
} catch (std::bad_alloc &exc) {
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
} catch ( ... ) {
diff --git a/node/Node.hpp b/node/Node.hpp
index 70531bf85..f8678115d 100644
--- a/node/Node.hpp
+++ b/node/Node.hpp
@@ -79,7 +79,6 @@ public:
ZT1_ResultCode processWirePacket(
uint64_t now,
const struct sockaddr_storage *remoteAddress,
- unsigned int linkDesperation,
const void *packetData,
unsigned int packetLength,
volatile uint64_t *nextBackgroundTaskDeadline);
@@ -119,16 +118,14 @@ public:
* @param addr Destination address
* @param data Packet data
* @param len Packet length
- * @param desperation Link desperation for reaching this address
* @return True if packet appears to have been sent
*/
- inline bool putPacket(const InetAddress &addr,const void *data,unsigned int len,unsigned int desperation)
+ inline bool putPacket(const InetAddress &addr,const void *data,unsigned int len)
{
return (_wirePacketSendFunction(
reinterpret_cast(this),
_uPtr,
reinterpret_cast(&addr),
- desperation,
data,
len) == 0);
}
@@ -174,23 +171,6 @@ public:
return nw;
}
- /**
- * Get an overall current level of desperation
- *
- * The current level of desperation is based on how recently an upstream
- * (a.k.a. supernode) peer has spoken to us. As such, it will change and
- * return to 0 once something like tunneling (higher desperation link) is
- * active. As a result, actual link desperation for outgoing messages
- * should be the max of either this or the most recent link desperation
- * for an incoming message from a given address. See Path.hpp and Peer.hpp.
- *
- * In other words think of this as 'the desperation we should try to
- * escalate to right now.'
- *
- * @return Overall system level of desperation
- */
- inline unsigned int coreDesperation() const throw() { return _coreDesperation; }
-
inline bool dataStorePut(const char *name,const void *data,unsigned int len,bool secure) { return (_dataStorePutFunction(reinterpret_cast(this),_uPtr,name,data,len,(int)secure) == 0); }
inline bool dataStorePut(const char *name,const std::string &data,bool secure) { return dataStorePut(name,(const void *)data.data(),(unsigned int)data.length(),secure); }
inline void dataStoreDelete(const char *name) { _dataStorePutFunction(reinterpret_cast(this),_uPtr,name,(const void *)0,0,0); }
@@ -253,7 +233,6 @@ private:
uint64_t _lastPingCheck;
uint64_t _lastHousekeepingRun;
uint64_t _lastBeacon;
- unsigned int _coreDesperation;
unsigned int _newestVersionSeen[3]; // major, minor, revision
bool _online;
};
diff --git a/node/Path.hpp b/node/Path.hpp
index 4a8e837d0..393b72251 100644
--- a/node/Path.hpp
+++ b/node/Path.hpp
@@ -57,7 +57,6 @@ public:
_addr(),
_lastSend(0),
_lastReceived(0),
- _lastReceiveDesperation(0),
_fixed(false) {}
Path(const Path &p) throw() { memcpy(this,&p,sizeof(Path)); }
@@ -66,7 +65,6 @@ public:
_addr(addr),
_lastSend(0),
_lastReceived(0),
- _lastReceiveDesperation(0),
_fixed(fixed) {}
inline void init(const InetAddress &addr,bool fixed)
@@ -74,7 +72,6 @@ public:
_addr = addr;
_lastSend = 0;
_lastReceived = 0;
- _lastReceiveDesperation = 0;
_fixed = fixed;
}
@@ -107,13 +104,11 @@ public:
* Called when a packet is received from this path
*
* @param t Time of receive
- * @param d Link desperation of receive
*/
- inline void received(uint64_t t,unsigned int d)
+ inline void received(uint64_t t)
throw()
{
_lastReceived = t;
- _lastReceiveDesperation = d;
}
/**
@@ -126,11 +121,6 @@ public:
*/
inline void setFixed(bool f) throw() { _fixed = f; }
- /**
- * @return Last desperation reported via incoming link
- */
- inline unsigned int lastReceiveDesperation() const throw() { return _lastReceiveDesperation; }
-
/**
* @param now Current time
* @return True if this path is fixed or has received data in last ACTIVITY_TIMEOUT ms
@@ -152,7 +142,7 @@ public:
*/
inline bool send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now)
{
- if (RR->node->putPacket(_addr,data,len,std::max(RR->node->coreDesperation(),_lastReceiveDesperation))) {
+ if (RR->node->putPacket(_addr,data,len)) {
sent(now);
RR->antiRec->logOutgoingZT(data,len);
return true;
@@ -187,7 +177,6 @@ private:
InetAddress _addr;
uint64_t _lastSend;
uint64_t _lastReceived;
- unsigned int _lastReceiveDesperation;
bool _fixed;
};
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 7c0868eb7..d788d0063 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -60,7 +60,6 @@ Peer::Peer(const Identity &myIdentity,const Identity &peerIdentity)
void Peer::received(
const RuntimeEnvironment *RR,
const InetAddress &remoteAddr,
- int linkDesperation,
unsigned int hops,
uint64_t packetId,
Packet::Verb verb,
@@ -78,7 +77,7 @@ void Peer::received(
unsigned int np = _numPaths;
for(unsigned int p=0;pinit(remoteAddr,false);
- slot->received(now,linkDesperation);
+ slot->received(now);
_numPaths = np;
pathIsConfirmed = true;
}
@@ -115,7 +114,7 @@ void Peer::received(
if ((now - _lastPathConfirmationSent) >= ZT_MIN_PATH_CONFIRMATION_INTERVAL) {
_lastPathConfirmationSent = now;
TRACE("got %s via unknown path %s(%s), confirming...",Packet::verbString(verb),_id.address().toString().c_str(),remoteAddr.toString().c_str());
- attemptToContactAt(RR,remoteAddr,linkDesperation,now);
+ attemptToContactAt(RR,remoteAddr,now);
}
}
}
@@ -137,7 +136,7 @@ void Peer::received(
for(std::vector::const_iterator mg(mgs.begin());mg!=mgs.end();++mg) {
if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) {
outp.armor(_key,true);
- RR->node->putPacket(remoteAddr,outp.data(),outp.size(),linkDesperation);
+ RR->node->putPacket(remoteAddr,outp.data(),outp.size());
outp.reset(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
}
@@ -150,7 +149,7 @@ void Peer::received(
}
if (outp.size() > ZT_PROTO_MIN_PACKET_LENGTH) {
outp.armor(_key,true);
- RR->node->putPacket(remoteAddr,outp.data(),outp.size(),linkDesperation);
+ RR->node->putPacket(remoteAddr,outp.data(),outp.size());
}
}
}
@@ -161,7 +160,7 @@ void Peer::received(
_lastMulticastFrame = now;
}
-void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &atAddress,unsigned int linkDesperation,uint64_t now)
+void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &atAddress,uint64_t now)
{
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_HELLO);
outp.append((unsigned char)ZT_PROTO_VERSION);
@@ -189,26 +188,21 @@ void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &at
}
outp.armor(_key,false); // HELLO is sent in the clear
- RR->node->putPacket(atAddress,outp.data(),outp.size(),linkDesperation);
+ RR->node->putPacket(atAddress,outp.data(),outp.size());
}
void Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now)
{
Path *const bestPath = getBestPath(now);
if ((bestPath)&&(bestPath->active(now))) {
- const unsigned int desp = std::max(RR->node->coreDesperation(),bestPath->lastReceiveDesperation());
if ((now - bestPath->lastReceived()) >= ZT_PEER_DIRECT_PING_DELAY) {
- TRACE("PING %s(%s) desperation == %u",_id.address().toString().c_str(),bestPath->address().toString().c_str(),desp);
- attemptToContactAt(RR,bestPath->address(),desp,now);
+ TRACE("PING %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
+ attemptToContactAt(RR,bestPath->address(),now);
bestPath->sent(now);
} else if ((now - bestPath->lastSend()) >= ZT_NAT_KEEPALIVE_DELAY) {
- // We only do keepalive if desperation is zero right now, since higher
- // desperation paths involve things like tunneling that do not need it.
- if (desp == 0) {
- TRACE("NAT keepalive %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
- RR->node->putPacket(bestPath->address(),"",0,0);
- bestPath->sent(now);
- }
+ TRACE("NAT keepalive %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
+ RR->node->putPacket(bestPath->address(),"",0);
+ bestPath->sent(now);
}
}
}
@@ -269,7 +263,7 @@ bool Peer::resetWithinScope(const RuntimeEnvironment *RR,InetAddress::IpScope sc
while (x < np) {
if (_paths[x].address().ipScope() == scope) {
if (_paths[x].fixed()) {
- attemptToContactAt(RR,_paths[x].address(),_paths[x].lastReceiveDesperation(),now);
+ attemptToContactAt(RR,_paths[x].address(),now);
_paths[y++] = _paths[x]; // keep fixed paths
}
} else {
@@ -281,11 +275,11 @@ bool Peer::resetWithinScope(const RuntimeEnvironment *RR,InetAddress::IpScope sc
return (y < np);
}
-void Peer::getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6,unsigned int maxDesperation) const
+void Peer::getBestActiveAddresses(uint64_t now,InetAddress &v4,InetAddress &v6) const
{
uint64_t bestV4 = 0,bestV6 = 0;
for(unsigned int p=0,np=_numPaths;p findCommonGround(const Peer &a,const Peer &b,uint64_t now,unsigned int maxDesperation)
+ static inline std::pair findCommonGround(const Peer &a,const Peer &b,uint64_t now)
{
std::pair v4,v6;
- b.getBestActiveAddresses(now,v4.first,v6.first,maxDesperation);
- a.getBestActiveAddresses(now,v4.second,v6.second,maxDesperation);
+ b.getBestActiveAddresses(now,v4.first,v6.first);
+ a.getBestActiveAddresses(now,v4.second,v6.second);
if ((v6.first)&&(v6.second)) // prefer IPv6 if both have it since NAT-t is (almost) unnecessary
return v6;
else if ((v4.first)&&(v4.second))
@@ -407,31 +402,6 @@ public:
else return std::pair();
}
- /**
- * Compare Peer version tuples
- */
- static inline int compareVersion(unsigned int maj1,unsigned int min1,unsigned int rev1,unsigned int maj2,unsigned int min2,unsigned int rev2)
- throw()
- {
- if (maj1 > maj2)
- return 1;
- else if (maj1 < maj2)
- return -1;
- else {
- if (min1 > min2)
- return 1;
- else if (min1 < min2)
- return -1;
- else {
- if (rev1 > rev2)
- return 1;
- else if (rev1 < rev2)
- return -1;
- else return 0;
- }
- }
- }
-
private:
void _announceMulticastGroups(const RuntimeEnvironment *RR,uint64_t now);
diff --git a/node/Switch.cpp b/node/Switch.cpp
index e2bc74c5f..19a77db74 100644
--- a/node/Switch.cpp
+++ b/node/Switch.cpp
@@ -58,16 +58,16 @@ Switch::~Switch()
{
}
-void Switch::onRemotePacket(const InetAddress &fromAddr,int linkDesperation,const void *data,unsigned int len)
+void Switch::onRemotePacket(const InetAddress &fromAddr,const void *data,unsigned int len)
{
try {
if (len == ZT_PROTO_BEACON_LENGTH) {
- _handleBeacon(fromAddr,linkDesperation,Buffer(data,len));
+ _handleBeacon(fromAddr,Buffer(data,len));
} else if (len > ZT_PROTO_MIN_FRAGMENT_LENGTH) {
if (((const unsigned char *)data)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] == ZT_PACKET_FRAGMENT_INDICATOR) {
- _handleRemotePacketFragment(fromAddr,linkDesperation,data,len);
+ _handleRemotePacketFragment(fromAddr,data,len);
} else if (len >= ZT_PROTO_MIN_PACKET_LENGTH) {
- _handleRemotePacketHead(fromAddr,linkDesperation,data,len);
+ _handleRemotePacketHead(fromAddr,data,len);
}
}
} catch (std::exception &ex) {
@@ -291,8 +291,7 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force)
const uint64_t now = RR->node->now();
- // Right now we only unite desperation == 0 links, which will be direct
- std::pair cg(Peer::findCommonGround(*p1p,*p2p,now,0));
+ std::pair cg(Peer::findCommonGround(*p1p,*p2p,now));
if (!(cg.first))
return false;
@@ -369,18 +368,18 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force)
return true;
}
-void Switch::contact(const SharedPtr &peer,const InetAddress &atAddr,unsigned int maxDesperation)
+void Switch::contact(const SharedPtr &peer,const InetAddress &atAddr)
{
TRACE("sending NAT-t message to %s(%s)",peer->address().toString().c_str(),atAddr.toString().c_str());
const uint64_t now = RR->node->now();
- // Attempt to contact at zero desperation first
- peer->attemptToContactAt(RR,atAddr,0,now);
+ // Attempt to contact directly
+ peer->attemptToContactAt(RR,atAddr,now);
// If we have not punched through after this timeout, open refreshing can of whupass
{
Mutex::Lock _l(_contactQueue_m);
- _contactQueue.push_back(ContactQueueEntry(peer,now + ZT_NAT_T_TACTICAL_ESCALATION_DELAY,atAddr,maxDesperation));
+ _contactQueue.push_back(ContactQueueEntry(peer,now + ZT_NAT_T_TACTICAL_ESCALATION_DELAY,atAddr));
}
}
@@ -450,7 +449,7 @@ unsigned long Switch::doTimerTasks(uint64_t now)
case 0: {
// First strategy: rifle method: direct packet to known port
- qi->peer->attemptToContactAt(RR,qi->inaddr,qi->currentDesperation,now);
+ qi->peer->attemptToContactAt(RR,qi->inaddr,now);
} break;
case 1: {
@@ -460,7 +459,7 @@ unsigned long Switch::doTimerTasks(uint64_t now)
for(int i=0;i<9;++i) {
if (++p > 0xffff) break;
tmpaddr.setPort((unsigned int)p);
- qi->peer->attemptToContactAt(RR,tmpaddr,qi->currentDesperation,now);
+ qi->peer->attemptToContactAt(RR,tmpaddr,now);
}
} break;
@@ -471,19 +470,12 @@ unsigned long Switch::doTimerTasks(uint64_t now)
for(int i=0;i<3;++i) {
if (--p < 1024) break;
tmpaddr.setPort((unsigned int)p);
- qi->peer->attemptToContactAt(RR,tmpaddr,qi->currentDesperation,now);
+ qi->peer->attemptToContactAt(RR,tmpaddr,now);
}
- // Escalate link desperation after all strategies attempted
- ++qi->currentDesperation;
- if (qi->currentDesperation > qi->maxDesperation) {
- // We've tried all strategies at all levels of desperation, give up.
- _contactQueue.erase(qi++);
- continue;
- } else {
- // Otherwise restart at new link desperation level (e.g. try a tougher transport)
- qi->strategyIteration = 0;
- }
+ // We've tried all strategies
+ _contactQueue.erase(qi++);
+ continue;
} break;
}
@@ -572,7 +564,7 @@ const char *Switch::etherTypeName(const unsigned int etherType)
return "UNKNOWN";
}
-void Switch::_handleRemotePacketFragment(const InetAddress &fromAddr,int linkDesperation,const void *data,unsigned int len)
+void Switch::_handleRemotePacketFragment(const InetAddress &fromAddr,const void *data,unsigned int len)
{
Packet::Fragment fragment(data,len);
Address destination(fragment.destination());
@@ -644,9 +636,9 @@ void Switch::_handleRemotePacketFragment(const InetAddress &fromAddr,int linkDes
}
}
-void Switch::_handleRemotePacketHead(const InetAddress &fromAddr,int linkDesperation,const void *data,unsigned int len)
+void Switch::_handleRemotePacketHead(const InetAddress &fromAddr,const void *data,unsigned int len)
{
- SharedPtr packet(new IncomingPacket(data,len,fromAddr,linkDesperation,RR->node->now()));
+ SharedPtr packet(new IncomingPacket(data,len,fromAddr,RR->node->now()));
Address source(packet->source());
Address destination(packet->destination());
@@ -714,7 +706,7 @@ void Switch::_handleRemotePacketHead(const InetAddress &fromAddr,int linkDespera
}
}
-void Switch::_handleBeacon(const InetAddress &fromAddr,int linkDesperation,const Buffer &data)
+void Switch::_handleBeacon(const InetAddress &fromAddr,const Buffer &data)
{
Address beaconAddr(data.field(ZT_PROTO_BEACON_IDX_ADDRESS,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
if (beaconAddr == RR->identity.address())
@@ -726,7 +718,7 @@ void Switch::_handleBeacon(const InetAddress &fromAddr,int linkDesperation,const
_lastBeacon = now;
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NOP);
outp.armor(peer->key(),false);
- RR->node->putPacket(fromAddr,outp.data(),outp.size(),linkDesperation);
+ RR->node->putPacket(fromAddr,outp.data(),outp.size());
}
}
}
diff --git a/node/Switch.hpp b/node/Switch.hpp
index aec7f0460..0b748247e 100644
--- a/node/Switch.hpp
+++ b/node/Switch.hpp
@@ -79,11 +79,10 @@ public:
* Called when a packet is received from the real network
*
* @param fromAddr Internet IP address of origin
- * @param linkDesperation Link desperation of path over which packet was received
* @param data Packet data
* @param len Packet length
*/
- void onRemotePacket(const InetAddress &fromAddr,int linkDesperation,const void *data,unsigned int len);
+ void onRemotePacket(const InetAddress &fromAddr,const void *data,unsigned int len);
/**
* Called when a packet comes from a local Ethernet tap
@@ -136,9 +135,8 @@ public:
*
* @param peer Peer to contact
* @param atAddr Address of peer
- * @param linkDesperation Attempt up to given max desperation
*/
- void contact(const SharedPtr &peer,const InetAddress &atAddr,unsigned int maxDesperation);
+ void contact(const SharedPtr &peer,const InetAddress &atAddr);
/**
* Request WHOIS on a given address
@@ -182,9 +180,9 @@ public:
throw();
private:
- void _handleRemotePacketFragment(const InetAddress &fromAddr,int linkDesperation,const void *data,unsigned int len);
- void _handleRemotePacketHead(const InetAddress &fromAddr,int linkDesperation,const void *data,unsigned int len);
- void _handleBeacon(const InetAddress &fromAddr,int linkDesperation,const Buffer &data);
+ void _handleRemotePacketFragment(const InetAddress &fromAddr,const void *data,unsigned int len);
+ void _handleRemotePacketHead(const InetAddress &fromAddr,const void *data,unsigned int len);
+ void _handleBeacon(const InetAddress &fromAddr,const Buffer &data);
Address _sendWhoisRequest(
const Address &addr,
@@ -248,19 +246,15 @@ private:
struct ContactQueueEntry
{
ContactQueueEntry() {}
- ContactQueueEntry(const SharedPtr &p,uint64_t ft,const InetAddress &a,unsigned int md) :
+ ContactQueueEntry(const SharedPtr &p,uint64_t ft,const InetAddress &a) :
peer(p),
fireAtTime(ft),
inaddr(a),
- maxDesperation(md),
- currentDesperation(0),
- strategyIteration(1) {} // start with 2nd strategy, zero desperation, since we've already tried 0/0
+ strategyIteration(1) {} // start with 2nd strategy, since first was tried at inception
SharedPtr peer;
uint64_t fireAtTime;
InetAddress inaddr;
- unsigned int maxDesperation;
- unsigned int currentDesperation;
unsigned int strategyIteration;
};
std::list _contactQueue;
diff --git a/node/Utils.hpp b/node/Utils.hpp
index bdd673a98..bd567cf5c 100644
--- a/node/Utils.hpp
+++ b/node/Utils.hpp
@@ -381,6 +381,33 @@ public:
}
static inline int64_t ntoh(int64_t n) throw() { return (int64_t)ntoh((uint64_t)n); }
+ /**
+ * Compare Peer version tuples
+ *
+ * @return -1, 0, or 1 based on whether first tuple is less than, equal to, or greater than second
+ */
+ static inline int compareVersion(unsigned int maj1,unsigned int min1,unsigned int rev1,unsigned int maj2,unsigned int min2,unsigned int rev2)
+ throw()
+ {
+ if (maj1 > maj2)
+ return 1;
+ else if (maj1 < maj2)
+ return -1;
+ else {
+ if (min1 > min2)
+ return 1;
+ else if (min1 < min2)
+ return -1;
+ else {
+ if (rev1 > rev2)
+ return 1;
+ else if (rev1 < rev2)
+ return -1;
+ else return 0;
+ }
+ }
+ }
+
/**
* Hexadecimal characters 0-f
*/
diff --git a/nodejs-zt1-client/package.json b/nodejs-zt1-client/package.json
index c840d8aed..953f6d37d 100644
--- a/nodejs-zt1-client/package.json
+++ b/nodejs-zt1-client/package.json
@@ -9,6 +9,7 @@
"author": "ZeroTier, Inc.",
"license": "BSD",
"dependencies": {
+ "async": "^0.9.0",
"request": "^2.55.0"
}
}
diff --git a/objects.mk b/objects.mk
index da7086f40..0986ef0dc 100644
--- a/objects.mk
+++ b/objects.mk
@@ -23,6 +23,7 @@ OBJS=\
node/Switch.o \
node/Topology.o \
node/Utils.o \
+ osdep/BackgroundResolver.o \
osdep/Http.o \
osdep/OSUtils.o \
service/ControlPlane.o \
diff --git a/one.cpp b/one.cpp
index d6da3a26d..f2d7970b1 100644
--- a/one.cpp
+++ b/one.cpp
@@ -72,12 +72,7 @@
#include "service/OneService.hpp"
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
-#include "controller/SqliteNetworkController.hpp"
-#endif
-
#define ZT1_PID_PATH "zerotier-one.pid"
-#define ZT1_CONTROLLER_DB_PATH "controller.db"
using namespace ZeroTier;
@@ -151,7 +146,7 @@ static int cli(int argc,char **argv)
json = true;
break;
- case 'p': // port for HTTP
+ case 'p':
port = Utils::strToUInt(argv[i] + 2);
if ((port > 0xffff)||(port == 0)) {
cliPrintHelp(argv[0],stdout);
@@ -159,7 +154,7 @@ static int cli(int argc,char **argv)
}
break;
- case 'D': // Home path
+ case 'D':
if (argv[i][2]) {
homeDir = argv[i] + 2;
} else {
@@ -168,7 +163,7 @@ static int cli(int argc,char **argv)
}
break;
- case 'H': // HTTP IP
+ case 'H':
if (argv[i][2]) {
ip = argv[i] + 2;
} else {
@@ -177,7 +172,7 @@ static int cli(int argc,char **argv)
}
break;
- case 'T': // Override root topology
+ case 'T':
if (argv[i][2]) {
authToken = argv[i] + 2;
} else {
@@ -186,7 +181,7 @@ static int cli(int argc,char **argv)
}
break;
- case 'v': // Display version
+ case 'v':
if (argv[i][2]) {
cliPrintHelp(argv[0],stdout);
return 1;
@@ -227,6 +222,20 @@ static int cli(int argc,char **argv)
if (!authToken.length()) {
OSUtils::readFile((homeDir + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),authToken);
+#ifdef __UNIX_LIKE__
+ if (!authToken.length()) {
+ const char *hd = getenv("HOME");
+ if (hd) {
+ char p[4096];
+#ifdef __APPLE__
+ Utils::snprintf(p,sizeof(p),"%s/Library/Application Support/ZeroTier/One/authtoken.secret",hd);
+#else
+ Utils::snprintf(p,sizeof(p),"%s/.zeroTierOneAuthToken",hd);
+#endif
+ OSUtils::readFile(p,authToken);
+ }
+ }
+#endif
if (!authToken.length()) {
fprintf(stderr,"%s: missing authentication token and authtoken.secret not found (or readable) in %s"ZT_EOL_S,argv[0],homeDir.c_str());
return 2;
@@ -741,6 +750,7 @@ static BOOL WINAPI _winConsoleCtrlHandler(DWORD dwCtrlType)
}
// Pokes a hole in the Windows firewall (advfirewall) for the running program
+/* -- now done by Advanced Installer
static void _winPokeAHole()
{
char myPath[MAX_PATH];
@@ -777,6 +787,7 @@ static void _winPokeAHole()
}
}
}
+*/
// Returns true if this is running as the local administrator
static BOOL IsCurrentUserLocalAdministrator(void)
@@ -877,6 +888,9 @@ static void printHelp(const char *cn,FILE *out)
{
fprintf(out,"ZeroTier One version %d.%d.%d"ZT_EOL_S"(c)2011-2015 ZeroTier, Inc."ZT_EOL_S,ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
fprintf(out,"Licensed under the GNU General Public License v3"ZT_EOL_S""ZT_EOL_S);
+ std::string updateUrl(OneService::autoUpdateUrl());
+ if (updateUrl.length())
+ fprintf(out,"Automatic update enabled:"ZT_EOL_S" %s"ZT_EOL_S""ZT_EOL_S,updateUrl.c_str());
fprintf(out,"Usage: %s [-switches] [home directory]"ZT_EOL_S""ZT_EOL_S,cn);
fprintf(out,"Available switches:"ZT_EOL_S);
fprintf(out," -h - Display this help"ZT_EOL_S);
@@ -1112,13 +1126,13 @@ int main(int argc,char **argv)
return 1;
}
} else {
- _winPokeAHole();
+ //_winPokeAHole();
}
SetConsoleCtrlHandler(&_winConsoleCtrlHandler,TRUE);
// continues on to ordinary command line execution code below...
} else {
// Running from service manager
- _winPokeAHole();
+ //_winPokeAHole();
ZeroTierOneService zt1Service;
if (CServiceBase::Run(zt1Service) == TRUE) {
return 0;
@@ -1129,19 +1143,6 @@ int main(int argc,char **argv)
}
#endif // __WINDOWS__
- NetworkController *controller = (NetworkController *)0;
-#ifdef ZT_ENABLE_NETWORK_CONTROLLER
- try {
- controller = new SqliteNetworkController((homeDir + ZT_PATH_SEPARATOR_S + ZT1_CONTROLLER_DB_PATH).c_str());
- } catch (std::exception &exc) {
- fprintf(stderr,"%s: failure initializing SqliteNetworkController: %s"ZT_EOL_S,argv[0],exc.what());
- return 1;
- } catch ( ... ) {
- fprintf(stderr,"%s: failure initializing SqliteNetworkController: unknown exception"ZT_EOL_S,argv[0]);
- return 1;
- }
-#endif // ZT_ENABLE_NETWORK_CONTROLLER
-
#ifdef __UNIX_LIKE__
std::string pidPath(homeDir + ZT_PATH_SEPARATOR_S + ZT1_PID_PATH);
{
@@ -1158,7 +1159,7 @@ int main(int argc,char **argv)
try {
for(;;) {
- zt1Service = OneService::newInstance(homeDir.c_str(),port,controller,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0);
+ zt1Service = OneService::newInstance(homeDir.c_str(),port,(overrideRootTopology.length() > 0) ? overrideRootTopology.c_str() : (const char *)0);
switch(zt1Service->run()) {
case OneService::ONE_STILL_RUNNING: // shouldn't happen, run() won't return until done
case OneService::ONE_NORMAL_TERMINATION:
@@ -1191,7 +1192,6 @@ int main(int argc,char **argv)
delete zt1Service;
zt1Service = (OneService *)0;
- delete controller;
#ifdef __UNIX_LIKE__
OSUtils::rm(pidPath.c_str());
diff --git a/osdep/BSDEthernetTap.cpp b/osdep/BSDEthernetTap.cpp
index e9899bc45..2a504a6f8 100644
--- a/osdep/BSDEthernetTap.cpp
+++ b/osdep/BSDEthernetTap.cpp
@@ -59,10 +59,12 @@
#include