Builds with new Path code.

This commit is contained in:
Adam Ierymenko 2014-03-21 13:46:55 -07:00
parent ba3f04deed
commit 33ad3deaee
9 changed files with 91 additions and 65 deletions

View file

@ -581,7 +581,7 @@ Node::ReasonForTermination Node::run()
std::vector< SharedPtr<Peer> > sns(_r->topology->supernodePeers()); std::vector< SharedPtr<Peer> > sns(_r->topology->supernodePeers());
TRACE("pinging %d supernodes",(int)sns.size()); TRACE("pinging %d supernodes",(int)sns.size());
for(std::vector< SharedPtr<Peer> >::const_iterator p(sns.begin());p!=sns.end();++p) for(std::vector< SharedPtr<Peer> >::const_iterator p(sns.begin());p!=sns.end();++p)
(*p)->sendPing(_r,now); (*p)->sendPing(_r,now,resynchronize);
} }
if (resynchronize) { if (resynchronize) {
@ -618,7 +618,7 @@ Node::ReasonForTermination Node::run()
if ((now - lastPingCheck) >= ZT_PING_CHECK_DELAY) { if ((now - lastPingCheck) >= ZT_PING_CHECK_DELAY) {
lastPingCheck = now; lastPingCheck = now;
try { try {
_r->topology->eachPeer(Topology::PingPeersThatNeedPing(_r,now)); _r->topology->eachPeer(Topology::PingPeersThatNeedPing(_r,now,resynchronize));
_r->topology->eachPeer(Topology::OpenPeersThatNeedFirewallOpener(_r,now)); _r->topology->eachPeer(Topology::OpenPeersThatNeedFirewallOpener(_r,now));
} catch (std::exception &exc) { } catch (std::exception &exc) {
LOG("unexpected exception running ping check cycle: %s",exc.what()); LOG("unexpected exception running ping check cycle: %s",exc.what());

View file

@ -156,20 +156,18 @@ public:
} }
inline void operator()(Topology &t,const SharedPtr<Peer> &p) inline void operator()(Topology &t,const SharedPtr<Peer> &p)
{ {
InetAddress v4(p->ipv4ActivePath(now)); std::vector<Path> pp(p->paths());
InetAddress v6(p->ipv6ActivePath(now)); std::string pathsStr;
if ((v4)||(v6)) { for(std::vector<Path>::const_iterator ppp(pp.begin());ppp!=pp.end();++ppp) {
ipcc->printf("200 listpeers %s %s %s %u %s"ZT_EOL_S, if (pathsStr.length())
pathsStr.push_back(',');
pathsStr.append(ppp->toString());
}
ipcc->printf("200 listpeers %s %s %u %s"ZT_EOL_S,
p->address().toString().c_str(), p->address().toString().c_str(),
((v4) ? v4.toString().c_str() : "-"), ((pathsStr.length() > 0) ? pathsStr.c_str() : "-"),
((v6) ? v6.toString().c_str() : "-"),
p->latency(), p->latency(),
p->remoteVersion().c_str()); p->remoteVersion().c_str());
} else {
ipcc->printf("200 listpeers %s - - - %s"ZT_EOL_S,
p->address().toString().c_str(),
p->remoteVersion().c_str());
}
} }
IpcConnection *ipcc; IpcConnection *ipcc;
uint64_t now; uint64_t now;
@ -216,7 +214,7 @@ void NodeConfig::_doCommand(IpcConnection *ipcc,const char *commandLine)
std::vector< SharedPtr<Peer> > snp(_r->topology->supernodePeers()); std::vector< SharedPtr<Peer> > snp(_r->topology->supernodePeers());
for(std::vector< SharedPtr<Peer> >::const_iterator sn(snp.begin());sn!=snp.end();++sn) { for(std::vector< SharedPtr<Peer> >::const_iterator sn(snp.begin());sn!=snp.end();++sn) {
uint64_t lastRec = (*sn)->lastDirectReceive(); uint64_t lastRec = (*sn)->lastDirectReceive();
if ((lastRec)&&(lastRec > since)&&((now - lastRec) < ZT_PEER_LINK_ACTIVITY_TIMEOUT)) { if ((lastRec)&&(lastRec > since)&&((now - lastRec) < ZT_PEER_PATH_ACTIVITY_TIMEOUT)) {
isOnline = true; isOnline = true;
break; break;
} }
@ -224,7 +222,7 @@ void NodeConfig::_doCommand(IpcConnection *ipcc,const char *commandLine)
ipcc->printf("200 info %s %s %s"ZT_EOL_S,_r->identity.address().toString().c_str(),(isOnline ? "ONLINE" : "OFFLINE"),Node::versionString()); ipcc->printf("200 info %s %s %s"ZT_EOL_S,_r->identity.address().toString().c_str(),(isOnline ? "ONLINE" : "OFFLINE"),Node::versionString());
} else if (cmd[0] == "listpeers") { } else if (cmd[0] == "listpeers") {
ipcc->printf("200 listpeers <ztaddr> <ipv4> <ipv6> <latency> <version>"ZT_EOL_S); ipcc->printf("200 listpeers <ztaddr> <paths> <latency> <version>"ZT_EOL_S);
_r->topology->eachPeer(_DumpPeerStatistics(ipcc)); _r->topology->eachPeer(_DumpPeerStatistics(ipcc));
} else if (cmd[0] == "listnetworks") { } else if (cmd[0] == "listnetworks") {
Mutex::Lock _l(_networks_m); Mutex::Lock _l(_networks_m);

View file

@ -82,7 +82,7 @@ bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r)
switch(verb()) { switch(verb()) {
case Packet::VERB_NOP: case Packet::VERB_NOP:
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_NOP,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_NOP,0,Packet::VERB_NOP,Utils::now());
return true; return true;
case Packet::VERB_HELLO: case Packet::VERB_HELLO:
return _doHELLO(_r); // legal, but why? :) return _doHELLO(_r); // legal, but why? :)
@ -156,7 +156,7 @@ bool PacketDecoder::_doERROR(const RuntimeEnvironment *_r,const SharedPtr<Peer>
break; break;
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_ERROR,inRePacketId,inReVerb,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_ERROR,inRePacketId,inReVerb,Utils::now());
} catch (std::exception &ex) { } catch (std::exception &ex) {
TRACE("dropped ERROR from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what()); TRACE("dropped ERROR from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
} catch ( ... ) { } catch ( ... ) {
@ -246,7 +246,7 @@ bool PacketDecoder::_doHELLO(const RuntimeEnvironment *_r)
peer = _r->topology->addPeer(newPeer); peer = _r->topology->addPeer(newPeer);
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_HELLO,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_HELLO,0,Packet::VERB_NOP,Utils::now());
peer->setRemoteVersion(vMajor,vMinor,vRevision); peer->setRemoteVersion(vMajor,vMinor,vRevision);
// If a supernode has a version higher than ours, this causes a software // If a supernode has a version higher than ours, this causes a software
@ -324,7 +324,7 @@ bool PacketDecoder::_doOK(const RuntimeEnvironment *_r,const SharedPtr<Peer> &pe
break; break;
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_OK,inRePacketId,inReVerb,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_OK,inRePacketId,inReVerb,Utils::now());
} catch (std::exception &ex) { } catch (std::exception &ex) {
TRACE("dropped OK from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what()); TRACE("dropped OK from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
} catch ( ... ) { } catch ( ... ) {
@ -358,7 +358,7 @@ bool PacketDecoder::_doWHOIS(const RuntimeEnvironment *_r,const SharedPtr<Peer>
} else { } else {
TRACE("dropped WHOIS from %s(%s): missing or invalid address",source().toString().c_str(),_remoteAddress.toString().c_str()); TRACE("dropped WHOIS from %s(%s): missing or invalid address",source().toString().c_str(),_remoteAddress.toString().c_str());
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_WHOIS,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_WHOIS,0,Packet::VERB_NOP,Utils::now());
return true; return true;
} }
@ -387,7 +387,7 @@ bool PacketDecoder::_doRENDEZVOUS(const RuntimeEnvironment *_r,const SharedPtr<P
if ((port > 0)&&((addrlen == 4)||(addrlen == 16))) { if ((port > 0)&&((addrlen == 4)||(addrlen == 16))) {
InetAddress atAddr(field(ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRESS,addrlen),addrlen,port); InetAddress atAddr(field(ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRESS,addrlen),addrlen,port);
TRACE("RENDEZVOUS from %s says %s might be at %s, starting NAT-t",source().toString().c_str(),with.toString().c_str(),atAddr.toString().c_str()); TRACE("RENDEZVOUS from %s says %s might be at %s, starting NAT-t",source().toString().c_str(),with.toString().c_str(),atAddr.toString().c_str());
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_RENDEZVOUS,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_RENDEZVOUS,0,Packet::VERB_NOP,Utils::now());
_r->sw->contact(withPeer,atAddr); _r->sw->contact(withPeer,atAddr);
} else { } else {
TRACE("dropped corrupt RENDEZVOUS from %s(%s) (bad address or port)",source().toString().c_str(),_remoteAddress.toString().c_str()); TRACE("dropped corrupt RENDEZVOUS from %s(%s) (bad address or port)",source().toString().c_str(),_remoteAddress.toString().c_str());
@ -426,7 +426,7 @@ bool PacketDecoder::_doFRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer>
// we receive unicast frames from it. This is called "implicit social // we receive unicast frames from it. This is called "implicit social
// ordering" in other docs. // ordering" in other docs.
_r->mc->bringCloser(network->id(),source()); _r->mc->bringCloser(network->id(),source());
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_FRAME,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_FRAME,0,Packet::VERB_NOP,Utils::now());
} else { } else {
TRACE("dropped FRAME from %s(%s): sender not a member of closed network %.16llx",source().toString().c_str(),_remoteAddress.toString().c_str(),network->id()); TRACE("dropped FRAME from %s(%s): sender not a member of closed network %.16llx",source().toString().c_str(),_remoteAddress.toString().c_str(),network->id());
@ -583,7 +583,7 @@ bool PacketDecoder::_doMULTICAST_FRAME(const RuntimeEnvironment *_r,const Shared
#endif #endif
// At this point the frame is basically valid, so we can call it a receive // At this point the frame is basically valid, so we can call it a receive
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_FRAME,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_FRAME,0,Packet::VERB_NOP,Utils::now());
// This gets updated later in most cases but start with the global limit. // This gets updated later in most cases but start with the global limit.
unsigned int maxDepth = ZT_MULTICAST_GLOBAL_MAX_DEPTH; unsigned int maxDepth = ZT_MULTICAST_GLOBAL_MAX_DEPTH;
@ -834,7 +834,7 @@ bool PacketDecoder::_doMULTICAST_LIKE(const RuntimeEnvironment *_r,const SharedP
} }
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP,now); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_MULTICAST_LIKE,0,Packet::VERB_NOP,now);
} catch (std::exception &ex) { } catch (std::exception &ex) {
TRACE("dropped MULTICAST_LIKE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what()); TRACE("dropped MULTICAST_LIKE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
} catch ( ... ) { } catch ( ... ) {
@ -870,7 +870,7 @@ bool PacketDecoder::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *
} }
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE,0,Packet::VERB_NOP,Utils::now());
} catch (std::exception &ex) { } 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()); TRACE("dropped NETWORK_MEMBERSHIP_CERTIFICATE from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),ex.what());
} catch ( ... ) { } catch ( ... ) {
@ -913,7 +913,7 @@ bool PacketDecoder::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *_r,const
#ifndef __WINDOWS__ #ifndef __WINDOWS__
} }
#endif // !__WINDOWS__ #endif // !__WINDOWS__
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP,Utils::now());
} catch (std::exception &exc) { } 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()); TRACE("dropped NETWORK_CONFIG_REQUEST from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
} catch ( ... ) { } catch ( ... ) {
@ -934,7 +934,7 @@ bool PacketDecoder::_doNETWORK_CONFIG_REFRESH(const RuntimeEnvironment *_r,const
nw->requestConfiguration(); nw->requestConfiguration();
} }
} }
peer->onReceive(_r,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REFRESH,0,Packet::VERB_NOP,Utils::now()); peer->onReceive(_r,_fromSock,_remoteAddress,hops(),packetId(),Packet::VERB_NETWORK_CONFIG_REFRESH,0,Packet::VERB_NOP,Utils::now());
} catch (std::exception &exc) { } 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()); TRACE("dropped NETWORK_CONFIG_REFRESH from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
} catch ( ... ) { } catch ( ... ) {

View file

@ -111,12 +111,12 @@ public:
Utils::snprintf(lrago,sizeof(lrago),"%lld",(long long)((_lastReceived != 0) ? (now - _lastReceived) : -1)); Utils::snprintf(lrago,sizeof(lrago),"%lld",(long long)((_lastReceived != 0) ? (now - _lastReceived) : -1));
Utils::snprintf(lfoago,sizeof(lfoago),"%lld",(long long)((_lastFirewallOpener != 0) ? (now - _lastFirewallOpener) : -1)); Utils::snprintf(lfoago,sizeof(lfoago),"%lld",(long long)((_lastFirewallOpener != 0) ? (now - _lastFirewallOpener) : -1));
Utils::snprintf(lpago,sizeof(lfoago),"%lld",(long long)((_lastPing != 0) ? (now - _lastPing) : -1)); Utils::snprintf(lpago,sizeof(lfoago),"%lld",(long long)((_lastPing != 0) ? (now - _lastPing) : -1));
return (std::string(_tcp ? "tcp:" : "udp:") + _addr.toString() + "[" + lsago + "," lrago + "," + lpago + "," + lfoago + "," + (active(now) ? "active" : "inactive") + "," + (_fixed ? "fixed" : "learned") + "]"); return (_addr.toString() + "[" + (_tcp ? "tcp" : "udp") + ";" + lsago + ";" + lrago + ";" + lpago + ";" + lfoago + ";" + (active(now) ? "active" : "inactive") + ";" + (_fixed ? "fixed" : "learned") + "]");
} }
inline operator==(const Path &p) const throw() { return ((_addr == p._addr)&&(_tcp == p._tcp)); } inline bool operator==(const Path &p) const throw() { return ((_addr == p._addr)&&(_tcp == p._tcp)); }
inline operator!=(const Path &p) const throw() { return ((_addr != p._addr)||(_tcp != p._tcp)); } inline bool operator!=(const Path &p) const throw() { return ((_addr != p._addr)||(_tcp != p._tcp)); }
inline operator<(const Path &p) const inline bool operator<(const Path &p) const
throw() throw()
{ {
if (_addr == p._addr) { if (_addr == p._addr) {

View file

@ -112,7 +112,7 @@ bool Peer::send(const RuntimeEnvironment *_r,const void *data,unsigned int len,u
uint64_t bestPathLastReceived = 0; uint64_t bestPathLastReceived = 0;
std::vector<Path>::iterator bestPath; std::vector<Path>::iterator bestPath;
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) { for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
uint64_t lr = p->lastRecevied(); uint64_t lr = p->lastReceived();
if (lr >= bestPathLastReceived) { if (lr >= bestPathLastReceived) {
bestPathLastReceived = lr; bestPathLastReceived = lr;
bestPath = p; bestPath = p;

View file

@ -199,7 +199,7 @@ public:
uint64_t x = 0; uint64_t x = 0;
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) { for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) {
uint64_t l = p->lastReceive(); uint64_t l = p->lastReceived();
if (l > x) if (l > x)
x = l; x = l;
} }
@ -316,7 +316,7 @@ public:
inline void addPath(const Path &newp) inline void addPath(const Path &newp)
{ {
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) { for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
if (*p == newp) { if (*p == newp) {
p->setFixed(newp.fixed()); p->setFixed(newp.fixed());
return; return;
@ -380,25 +380,48 @@ public:
*/ */
inline operator bool() const throw() { return (_id); } inline operator bool() const throw() { return (_id); }
/**
* @param now Current time
* @param v4 Result parameter to receive active IPv4 address, if any
* @param v6 Result parameter to receive active IPv6 address, if any
*/
inline void getActiveUdpPathAddresses(uint64_t now,InetAddress &v4,InetAddress &v6) const
{
bool gotV4 = false,gotV6 = false;
Mutex::Lock _l(_lock);
for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) {
if (!gotV4) {
if ((!p->tcp())&&(p->address().isV4())&&(p->active(now))) {
gotV4 = true;
v4 = p->address();
}
} else if (!gotV6) {
if ((!p->tcp())&&(p->address().isV6())&&(p->active(now))) {
gotV6 = true;
v6 = p->address();
}
} else break;
}
}
/** /**
* Find a common set of addresses by which two peers can link, if any * Find a common set of addresses by which two peers can link, if any
* *
* @param a Peer A * @param a Peer A
* @param b Peer B * @param b Peer B
* @param now Current time * @param now Current time
* @return Pair: B's address to send to A, A's address to send to B * @return Pair: B's address (to send to A), A's address (to send to B)
*/ */
static inline std::pair<InetAddress,InetAddress> findCommonGround(const Peer &a,const Peer &b,uint64_t now) static inline std::pair<InetAddress,InetAddress> findCommonGround(const Peer &a,const Peer &b,uint64_t now)
throw() throw()
{ {
if ((a._ipv6p.isActive(now))&&(b._ipv6p.isActive(now))) std::pair<InetAddress,InetAddress> v4,v6;
return std::pair<InetAddress,InetAddress>(b._ipv6p.addr,a._ipv6p.addr); b.getActiveUdpPathAddresses(now,v4.first,v6.first);
else if ((a._ipv4p.isActive(now))&&(b._ipv4p.isActive(now))) a.getActiveUdpPathAddresses(now,v4.second,v6.second);
return std::pair<InetAddress,InetAddress>(b._ipv4p.addr,a._ipv4p.addr); if ((v6.first)&&(v6.second))
else if ((a._ipv6p.addr)&&(b._ipv6p.addr)) return v6;
return std::pair<InetAddress,InetAddress>(b._ipv6p.addr,a._ipv6p.addr); if ((v4.first)&&(v4.second))
else if ((a._ipv4p.addr)&&(b._ipv4p.addr)) return v4;
return std::pair<InetAddress,InetAddress>(b._ipv4p.addr,a._ipv4p.addr);
return std::pair<InetAddress,InetAddress>(); return std::pair<InetAddress,InetAddress>();
} }

View file

@ -577,14 +577,14 @@ void SocketManager::whack()
_whackSendPipe_m.unlock(); _whackSendPipe_m.unlock();
} }
void closeTcpSockets() void SocketManager::closeTcpSockets()
{ {
{ {
Mutex::Lock _l2(_tcpSockets_m); Mutex::Lock _l2(_tcpSockets_m);
_fdSetLock.lock(); _fdSetLock.lock();
for(std::map< InetAddress,SharedPtr<Socket> >::iterator s(_tcpSockets.begin());s!=_tcpSockets.end();++s`) { for(std::map< InetAddress,SharedPtr<Socket> >::iterator s(_tcpSockets.begin());s!=_tcpSockets.end();++s) {
FD_CLR((*s)->_sock,&_readfds); FD_CLR(s->second->_sock,&_readfds);
FD_CLR((*s)->_sock,&_writefds); FD_CLR(s->second->_sock,&_writefds);
} }
_fdSetLock.unlock(); _fdSetLock.unlock();
_tcpSockets.clear(); _tcpSockets.clear();

View file

@ -64,8 +64,9 @@ void Topology::setSupernodes(const std::map< Identity,std::vector<InetAddress> >
SharedPtr<Peer> p(getPeer(i->first.address())); SharedPtr<Peer> p(getPeer(i->first.address()));
if (!p) if (!p)
p = addPeer(SharedPtr<Peer>(new Peer(_r->identity,i->first))); p = addPeer(SharedPtr<Peer>(new Peer(_r->identity,i->first)));
for(std::vector<InetAddress>::const_iterator j(i->second.begin());j!=i->second.end();++j) for(std::vector<InetAddress>::const_iterator j(i->second.begin());j!=i->second.end();++j) {
p->setPathAddress(*j,true); p->addPath(Path(*j,false,true));
}
p->setLastUsed(now); p->setLastUsed(now);
_supernodePeers.push_back(p); _supernodePeers.push_back(p);
} }

View file

@ -216,31 +216,35 @@ public:
class PingPeersThatNeedPing class PingPeersThatNeedPing
{ {
public: public:
PingPeersThatNeedPing(const RuntimeEnvironment *renv,uint64_t now) throw() : PingPeersThatNeedPing(const RuntimeEnvironment *renv,uint64_t now,bool firstSinceReset) throw() :
_now(now), _now(now),
_supernodeAddresses(renv->topology->supernodeAddresses()), _supernodeAddresses(renv->topology->supernodeAddresses()),
_r(renv) {} _r(renv),
_firstSinceReset(firstSinceReset) {}
inline void operator()(Topology &t,const SharedPtr<Peer> &p) inline void operator()(Topology &t,const SharedPtr<Peer> &p)
{ {
if ( if (
/* 1: we have not heard anything directly in ZT_PEER_DIRECT_PING_DELAY ms */
((_now - p->lastDirectReceive()) >= ZT_PEER_DIRECT_PING_DELAY) && ((_now - p->lastDirectReceive()) >= ZT_PEER_DIRECT_PING_DELAY) &&
/* 2: */
( (
/* 2a: peer has direct path, and has sent us something recently */
( (
(p->hasDirectPath())&& (p->hasDirectPath())&&
((_now - p->lastFrame()) < ZT_PEER_LINK_ACTIVITY_TIMEOUT) ((_now - p->lastFrame()) < ZT_PEER_PATH_ACTIVITY_TIMEOUT)
) && ) &&
/* 2b: peer is not a supernode */
(!_supernodeAddresses.count(p->address())) (!_supernodeAddresses.count(p->address()))
) )
) { ) { p->sendPing(_r,_now,_firstSinceReset); }
p->sendPing(_r,_now);
}
} }
private: private:
uint64_t _now; uint64_t _now;
std::set<Address> _supernodeAddresses; std::set<Address> _supernodeAddresses;
const RuntimeEnvironment *_r; const RuntimeEnvironment *_r;
bool _firstSinceReset;
}; };
/** /**
@ -261,7 +265,7 @@ public:
{ {
if (!_supernodeAddresses.count(p->address())) { if (!_supernodeAddresses.count(p->address())) {
p->clearPaths(false); // false means don't forget 'fixed' paths e.g. supernodes p->clearPaths(false); // false means don't forget 'fixed' paths e.g. supernodes
if (((_now - p->lastFrame()) < ZT_PEER_LINK_ACTIVITY_TIMEOUT)&&(_supernode)) { if (((_now - p->lastFrame()) < ZT_PEER_PATH_ACTIVITY_TIMEOUT)&&(_supernode)) {
TRACE("sending reset NOP to %s",p->address().toString().c_str()); TRACE("sending reset NOP to %s",p->address().toString().c_str());
Packet outp(p->address(),_r->identity.address(),Packet::VERB_NOP); Packet outp(p->address(),_r->identity.address(),Packet::VERB_NOP);
outp.armor(p->key(),false); // no need to encrypt a NOP outp.armor(p->key(),false); // no need to encrypt a NOP