Renamed supernode to rootserver

This commit is contained in:
Kees Bos 2015-05-06 12:05:20 +02:00
commit a425bbc673
30 changed files with 166 additions and 156 deletions

View file

@ -254,7 +254,7 @@
/**
* Delay between scans of the topology active peer DB for peers that need ping
*
* This is also how often pings will be retried to upstream peers (supernodes)
* This is also how often pings will be retried to upstream peers (rootservers)
* constantly until something is heard.
*/
#define ZT_PING_CHECK_INVERVAL 6250
@ -279,9 +279,9 @@
*
* When we send something (including frames), we generally expect a response.
* Switching relays if no response in a short period of time causes more
* rapid failover if a supernode goes down or becomes unreachable. In the
* rapid failover if a rootserver goes down or becomes unreachable. In the
* mistaken case, little harm is done as it'll pick the next-fastest
* supernode and will switch back eventually.
* rootserver and will switch back eventually.
*/
#define ZT_PEER_RELAY_CONVERSATION_LATENCY_THRESHOLD 10000

View file

@ -32,9 +32,8 @@
namespace ZeroTier {
void Dictionary::fromString(const char *s,unsigned int maxlen)
void Dictionary::updateFromString(const char *s,unsigned int maxlen)
{
clear();
bool escapeState = false;
std::string keyBuf;
std::string *element = &keyBuf;
@ -75,6 +74,12 @@ void Dictionary::fromString(const char *s,unsigned int maxlen)
(*this)[keyBuf];
}
void Dictionary::fromString(const char *s,unsigned int maxlen)
{
clear();
updateFromString(s,maxlen);
}
bool Dictionary::sign(const Identity &id,uint64_t now)
{
try {

View file

@ -259,6 +259,9 @@ public:
*/
void fromString(const char *s,unsigned int maxlen);
inline void fromString(const std::string &s) { fromString(s.c_str(),(unsigned int)s.length()); }
void updateFromString(const char *s,unsigned int maxlen);
inline void update(const char *s,unsigned int maxlen) { updateFromString(s, maxlen); }
inline void update(const std::string &s) { updateFromString(s.c_str(),(unsigned int)s.length()); }
/**
* @return True if this dictionary is cryptographically signed

View file

@ -110,7 +110,7 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,const SharedPtr<Peer>
case Packet::ERROR_OBJ_NOT_FOUND:
if (inReVerb == Packet::VERB_WHOIS) {
if (RR->topology->isSupernode(peer->address()))
if (RR->topology->isRootserver(peer->address()))
RR->sw->cancelWhoisRequest(Address(field(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH));
} else if (inReVerb == Packet::VERB_NETWORK_CONFIG_REQUEST) {
SharedPtr<Network> network(RR->node->network(at<uint64_t>(ZT_PROTO_VERB_ERROR_IDX_PAYLOAD)));
@ -128,7 +128,7 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,const SharedPtr<Peer>
break;
case Packet::ERROR_IDENTITY_COLLISION:
if (RR->topology->isSupernode(peer->address()))
if (RR->topology->isRootserver(peer->address()))
RR->node->postEvent(ZT1_EVENT_FATAL_ERROR_IDENTITY_COLLISION);
break;
@ -268,7 +268,7 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR)
peer->setRemoteVersion(protoVersion,vMajor,vMinor,vRevision);
bool trusted = false;
if (RR->topology->isSupernode(id.address())) {
if (RR->topology->isRootserver(id.address())) {
RR->node->postNewerVersionIfNewer(vMajor,vMinor,vRevision);
trusted = true;
}
@ -353,7 +353,7 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
peer->setRemoteVersion(vProto,vMajor,vMinor,vRevision);
bool trusted = false;
if (RR->topology->isSupernode(peer->address())) {
if (RR->topology->isRootserver(peer->address())) {
RR->node->postNewerVersionIfNewer(vMajor,vMinor,vRevision);
trusted = true;
}
@ -362,10 +362,10 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p
} break;
case Packet::VERB_WHOIS: {
// Right now only supernodes are allowed to send OK(WHOIS) to prevent
// Right now only rootservers are allowed to send OK(WHOIS) to prevent
// poisoning attacks. Further decentralization will require some other
// kind of trust mechanism.
if (RR->topology->isSupernode(peer->address())) {
if (RR->topology->isRootserver(peer->address())) {
const Identity id(*this,ZT_PROTO_VERB_WHOIS__OK__IDX_IDENTITY);
if (id.locallyValidate())
RR->sw->doAnythingWaitingForPeer(RR->topology->addPeer(SharedPtr<Peer>(new Peer(RR->identity,id))));

View file

@ -216,7 +216,7 @@ void Multicaster::send(
if ((now - gs.lastExplicitGather) >= ZT_MULTICAST_EXPLICIT_GATHER_DELAY) {
gs.lastExplicitGather = now;
SharedPtr<Peer> sn(RR->topology->getBestSupernode());
SharedPtr<Peer> sn(RR->topology->getBestRootserver());
if (sn) {
TRACE(">>MC upstream GATHER up to %u for group %.16llx/%s",gatherLimit,nwid,mg.toString().c_str());
@ -271,12 +271,12 @@ void Multicaster::send(
delete [] indexes;
#ifdef ZT_SUPPORT_LEGACY_MULTICAST
// This sends a P5 multicast up to our supernode, who then
// This sends a P5 multicast up to our rootserver, who then
// redistributes it manually down to all <1.0.0 peers for
// legacy support. These peers don't support the new multicast
// frame type, so even if they receive it they will ignore it.
{
SharedPtr<Peer> sn(RR->topology->getBestSupernode());
SharedPtr<Peer> sn(RR->topology->getBestRootserver());
if (sn) {
uint32_t rn = RR->prng->next32();
Packet outp(sn->address(),RR->identity.address(),Packet::VERB_P5_MULTICAST_FRAME);

View file

@ -518,13 +518,13 @@ public:
RR(renv),
_now(renv->node->now()),
_network(nw),
_supernodeAddresses(renv->topology->supernodeAddresses()),
_rootserverAddresses(renv->topology->rootserverAddresses()),
_allMulticastGroups(nw->_allMulticastGroups())
{}
inline void operator()(Topology &t,const SharedPtr<Peer> &p)
{
if ( ( (p->hasActiveDirectPath(_now)) && (_network->_isAllowed(p->address())) ) || (std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),p->address()) != _supernodeAddresses.end()) ) {
if ( ( (p->hasActiveDirectPath(_now)) && (_network->_isAllowed(p->address())) ) || (std::find(_rootserverAddresses.begin(),_rootserverAddresses.end(),p->address()) != _rootserverAddresses.end()) ) {
Packet outp(p->address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
for(std::vector<MulticastGroup>::iterator mg(_allMulticastGroups.begin());mg!=_allMulticastGroups.end();++mg) {
@ -551,7 +551,7 @@ private:
const RuntimeEnvironment *RR;
uint64_t _now;
Network *_network;
std::vector<Address> _supernodeAddresses;
std::vector<Address> _rootserverAddresses;
std::vector<MulticastGroup> _allMulticastGroups;
};

View file

@ -133,7 +133,9 @@ Node::Node(
if (!rt.size())
rt.fromString(ZT_DEFAULTS.defaultRootTopology);
}
RR->topology->setSupernodes(Dictionary(rt.get("supernodes","")));
Dictionary rootservers(rt.get("rootservers",""));
rootservers.update(rt.get("supernodes",""));
RR->topology->setRootservers(rootservers);
postEvent(ZT1_EVENT_UP);
}
@ -189,7 +191,7 @@ public:
RR(renv),
_now(now),
_relays(relays),
_supernodes(RR->topology->supernodeAddresses())
_rootservers(RR->topology->rootserverAddresses())
{
}
@ -205,7 +207,7 @@ public:
}
}
if ((isRelay)||(std::find(_supernodes.begin(),_supernodes.end(),p->address()) != _supernodes.end())) {
if ((isRelay)||(std::find(_rootservers.begin(),_rootservers.end(),p->address()) != _rootservers.end())) {
p->doPingAndKeepalive(RR,_now);
if (p->lastReceive() > lastReceiveFromUpstream)
lastReceiveFromUpstream = p->lastReceive();
@ -219,7 +221,7 @@ private:
const RuntimeEnvironment *RR;
uint64_t _now;
const std::vector< std::pair<Address,InetAddress> > &_relays;
std::vector<Address> _supernodes;
std::vector<Address> _rootservers;
};
ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *nextBackgroundTaskDeadline)
@ -260,7 +262,7 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
}
}
// Ping living or supernode/relay peers
// Ping living or rootserver/relay peers
_PingPeersThatNeedPing pfunc(RR,now,networkRelays);
RR->topology->eachPeer<_PingPeersThatNeedPing &>(pfunc);
@ -384,7 +386,7 @@ ZT1_PeerList *Node::peers() const
p->versionRev = -1;
}
p->latency = pi->second->latency();
p->role = RR->topology->isSupernode(pi->second->address()) ? ZT1_PEER_ROLE_SUPERNODE : ZT1_PEER_ROLE_LEAF;
p->role = RR->topology->isRootserver(pi->second->address()) ? ZT1_PEER_ROLE_ROOTSERVER : ZT1_PEER_ROLE_LEAF;
std::vector<Path> paths(pi->second->paths());
Path *bestPath = pi->second->getBestPath(_now);

View file

@ -626,7 +626,7 @@ public:
* [... additional tuples of network/address/adi ...]
*
* LIKEs are sent to peers with whom you have a direct peer to peer
* connection, and always including supernodes.
* connection, and always including rootservers.
*
* OK/ERROR are not generated.
*/

View file

@ -122,16 +122,16 @@ void Peer::received(
/* Announce multicast groups of interest to direct peers if they are
* considered authorized members of a given network. Also announce to
* supernodes and network controllers. */
* rootservers and network controllers. */
if ((pathIsConfirmed)&&((now - _lastAnnouncedTo) >= ((ZT_MULTICAST_LIKE_EXPIRE / 2) - 1000))) {
_lastAnnouncedTo = now;
const bool isSupernode = RR->topology->isSupernode(_id.address());
const bool isRootserver = RR->topology->isRootserver(_id.address());
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_MULTICAST_LIKE);
const std::vector< SharedPtr<Network> > networks(RR->node->allNetworks());
for(std::vector< SharedPtr<Network> >::const_iterator n(networks.begin());n!=networks.end();++n) {
if ( (isSupernode) || ((*n)->isAllowed(_id.address())) ) {
if ( (isRootserver) || ((*n)->isAllowed(_id.address())) ) {
const std::vector<MulticastGroup> mgs((*n)->allMulticastGroups());
for(std::vector<MulticastGroup>::const_iterator mg(mgs.begin());mg!=mgs.end();++mg) {
if ((outp.size() + 18) > ZT_UDP_DEFAULT_PAYLOAD_MTU) {

View file

@ -118,7 +118,7 @@ void SelfAwareness::iam(const Address &reporter,const InetAddress &reporterPhysi
// For all peers for whom we forgot an address, send a packet indirectly if
// they are still considered alive so that we will re-establish direct links.
SharedPtr<Peer> sn(RR->topology->getBestSupernode());
SharedPtr<Peer> sn(RR->topology->getBestRootserver());
if (sn) {
Path *snp = sn->getBestPath(now);
if (snp) {

View file

@ -320,8 +320,8 @@ bool Switch::unite(const Address &p1,const Address &p2,bool force)
* P2 in randomized order in terms of which gets sent first. This is done
* since in a few cases NAT-t can be sensitive to slight timing differences
* in terms of when the two peers initiate. Normally this is accounted for
* by the nearly-simultaneous RENDEZVOUS kickoff from the supernode, but
* given that supernodes are hosted on cloud providers this can in some
* by the nearly-simultaneous RENDEZVOUS kickoff from the rootserver, but
* given that rootservers are hosted on cloud providers this can in some
* cases have a few ms of latency between packet departures. By randomizing
* the order we make each attempted NAT-t favor one or the other going
* first, meaning if it doesn't succeed the first time it might the second
@ -565,8 +565,8 @@ void Switch::_handleRemotePacketFragment(const InetAddress &fromAddr,const void
// It wouldn't hurt anything, just redundant and unnecessary.
SharedPtr<Peer> relayTo = RR->topology->getPeer(destination);
if ((!relayTo)||(!relayTo->send(RR,fragment.data(),fragment.size(),RR->node->now()))) {
// Don't know peer or no direct path -- so relay via supernode
relayTo = RR->topology->getBestSupernode();
// Don't know peer or no direct path -- so relay via rootserver
relayTo = RR->topology->getBestRootserver();
if (relayTo)
relayTo->send(RR,fragment.data(),fragment.size(),RR->node->now());
}
@ -641,8 +641,8 @@ void Switch::_handleRemotePacketHead(const InetAddress &fromAddr,const void *dat
if ((relayTo)&&((relayTo->send(RR,packet->data(),packet->size(),RR->node->now())))) {
unite(source,destination,false);
} else {
// Don't know peer or no direct path -- so relay via supernode
relayTo = RR->topology->getBestSupernode(&source,1,true);
// Don't know peer or no direct path -- so relay via rootserver
relayTo = RR->topology->getBestRootserver(&source,1,true);
if (relayTo)
relayTo->send(RR,packet->data(),packet->size(),RR->node->now());
}
@ -712,13 +712,13 @@ void Switch::_handleBeacon(const InetAddress &fromAddr,const Buffer<ZT_PROTO_BEA
Address Switch::_sendWhoisRequest(const Address &addr,const Address *peersAlreadyConsulted,unsigned int numPeersAlreadyConsulted)
{
SharedPtr<Peer> supernode(RR->topology->getBestSupernode(peersAlreadyConsulted,numPeersAlreadyConsulted,false));
if (supernode) {
Packet outp(supernode->address(),RR->identity.address(),Packet::VERB_WHOIS);
SharedPtr<Peer> rootserver(RR->topology->getBestRootserver(peersAlreadyConsulted,numPeersAlreadyConsulted,false));
if (rootserver) {
Packet outp(rootserver->address(),RR->identity.address(),Packet::VERB_WHOIS);
addr.appendTo(outp);
outp.armor(supernode->key(),true);
if (supernode->send(RR,outp.data(),outp.size(),RR->node->now()))
return supernode->address();
outp.armor(rootserver->key(),true);
if (rootserver->send(RR,outp.data(),outp.size(),RR->node->now()))
return rootserver->address();
}
return Address();
}
@ -752,7 +752,7 @@ bool Switch::_trySend(const Packet &packet,bool encrypt,uint64_t nwid)
}
if (!relay)
relay = RR->topology->getBestSupernode();
relay = RR->topology->getBestRootserver();
if (!(relay)||(!(viaPath = relay->getBestPath(now))))
return false;

View file

@ -36,7 +36,7 @@ namespace ZeroTier {
Topology::Topology(const RuntimeEnvironment *renv) :
RR(renv),
_amSupernode(false)
_amRootserver(false)
{
}
@ -44,16 +44,16 @@ Topology::~Topology()
{
}
void Topology::setSupernodes(const std::map< Identity,std::vector<InetAddress> > &sn)
void Topology::setRootservers(const std::map< Identity,std::vector<InetAddress> > &sn)
{
Mutex::Lock _l(_lock);
if (_supernodes == sn)
if (_rootservers == sn)
return; // no change
_supernodes = sn;
_supernodeAddresses.clear();
_supernodePeers.clear();
_rootservers = sn;
_rootserverAddresses.clear();
_rootserverPeers.clear();
const uint64_t now = RR->node->now();
for(std::map< Identity,std::vector<InetAddress> >::const_iterator i(sn.begin());i!=sn.end();++i) {
@ -64,17 +64,17 @@ void Topology::setSupernodes(const std::map< Identity,std::vector<InetAddress> >
for(std::vector<InetAddress>::const_iterator j(i->second.begin());j!=i->second.end();++j)
p->addPath(Path(*j,true));
p->use(now);
_supernodePeers.push_back(p);
_rootserverPeers.push_back(p);
}
_supernodeAddresses.push_back(i->first.address());
_rootserverAddresses.push_back(i->first.address());
}
std::sort(_supernodeAddresses.begin(),_supernodeAddresses.end());
std::sort(_rootserverAddresses.begin(),_rootserverAddresses.end());
_amSupernode = (_supernodes.find(RR->identity) != _supernodes.end());
_amRootserver = (_rootservers.find(RR->identity) != _rootservers.end());
}
void Topology::setSupernodes(const Dictionary &sn)
void Topology::setRootservers(const Dictionary &sn)
{
std::map< Identity,std::vector<InetAddress> > m;
for(Dictionary::const_iterator d(sn.begin());d!=sn.end();++d) {
@ -86,11 +86,11 @@ void Topology::setSupernodes(const Dictionary &sn)
if (udp.length() > 0)
a.push_back(InetAddress(udp));
} catch ( ... ) {
TRACE("supernode list contained invalid entry for: %s",d->first.c_str());
TRACE("rootserver list contained invalid entry for: %s",d->first.c_str());
}
}
}
this->setSupernodes(m);
this->setRootservers(m);
}
SharedPtr<Peer> Topology::addPeer(const SharedPtr<Peer> &peer)
@ -141,28 +141,28 @@ SharedPtr<Peer> Topology::getPeer(const Address &zta)
return SharedPtr<Peer>();
}
SharedPtr<Peer> Topology::getBestSupernode(const Address *avoid,unsigned int avoidCount,bool strictAvoid)
SharedPtr<Peer> Topology::getBestRootserver(const Address *avoid,unsigned int avoidCount,bool strictAvoid)
{
SharedPtr<Peer> bestSupernode;
SharedPtr<Peer> bestRootserver;
const uint64_t now = RR->node->now();
Mutex::Lock _l(_lock);
if (_amSupernode) {
/* If I am a supernode, the "best" supernode is the one whose address
if (_amRootserver) {
/* If I am a rootserver, the "best" rootserver is the one whose address
* is numerically greater than mine (with wrap at top of list). This
* causes packets searching for a route to pretty much literally
* circumnavigate the globe rather than bouncing between just two. */
if (_supernodeAddresses.size() > 1) { // gotta be one other than me for this to work
std::vector<Address>::const_iterator sna(std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),RR->identity.address()));
if (sna != _supernodeAddresses.end()) { // sanity check -- _amSupernode should've been false in this case
if (_rootserverAddresses.size() > 1) { // gotta be one other than me for this to work
std::vector<Address>::const_iterator sna(std::find(_rootserverAddresses.begin(),_rootserverAddresses.end(),RR->identity.address()));
if (sna != _rootserverAddresses.end()) { // sanity check -- _amRootserver should've been false in this case
for(;;) {
if (++sna == _supernodeAddresses.end())
sna = _supernodeAddresses.begin(); // wrap around at end
if (++sna == _rootserverAddresses.end())
sna = _rootserverAddresses.begin(); // wrap around at end
if (*sna != RR->identity.address()) { // pick one other than us -- starting from me+1 in sorted set order
std::map< Address,SharedPtr<Peer> >::const_iterator p(_activePeers.find(*sna));
if ((p != _activePeers.end())&&(p->second->hasActiveDirectPath(now))) {
bestSupernode = p->second;
bestRootserver = p->second;
break;
}
}
@ -170,80 +170,80 @@ SharedPtr<Peer> Topology::getBestSupernode(const Address *avoid,unsigned int avo
}
}
} else {
/* If I am not a supernode, the best supernode is the active one with
/* If I am not a rootserver, the best rootserver is the active one with
* the lowest latency. */
unsigned int l,bestSupernodeLatency = 65536;
unsigned int l,bestRootserverLatency = 65536;
uint64_t lds,ldr;
// First look for a best supernode by comparing latencies, but exclude
// supernodes that have not responded to direct messages in order to
// First look for a best rootserver by comparing latencies, but exclude
// rootservers that have not responded to direct messages in order to
// try to exclude any that are dead or unreachable.
for(std::vector< SharedPtr<Peer> >::const_iterator sn(_supernodePeers.begin());sn!=_supernodePeers.end();) {
for(std::vector< SharedPtr<Peer> >::const_iterator sn(_rootserverPeers.begin());sn!=_rootserverPeers.end();) {
// Skip explicitly avoided relays
for(unsigned int i=0;i<avoidCount;++i) {
if (avoid[i] == (*sn)->address())
goto keep_searching_for_supernodes;
goto keep_searching_for_rootservers;
}
// Skip possibly comatose or unreachable relays
lds = (*sn)->lastDirectSend();
ldr = (*sn)->lastDirectReceive();
if ((lds)&&(lds > ldr)&&((lds - ldr) > ZT_PEER_RELAY_CONVERSATION_LATENCY_THRESHOLD))
goto keep_searching_for_supernodes;
goto keep_searching_for_rootservers;
if ((*sn)->hasActiveDirectPath(now)) {
l = (*sn)->latency();
if (bestSupernode) {
if ((l)&&(l < bestSupernodeLatency)) {
bestSupernodeLatency = l;
bestSupernode = *sn;
if (bestRootserver) {
if ((l)&&(l < bestRootserverLatency)) {
bestRootserverLatency = l;
bestRootserver = *sn;
}
} else {
if (l)
bestSupernodeLatency = l;
bestSupernode = *sn;
bestRootserverLatency = l;
bestRootserver = *sn;
}
}
keep_searching_for_supernodes:
keep_searching_for_rootservers:
++sn;
}
if (bestSupernode) {
bestSupernode->use(now);
return bestSupernode;
if (bestRootserver) {
bestRootserver->use(now);
return bestRootserver;
} 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) {
for(std::vector< SharedPtr<Peer> >::const_iterator sn=_rootserverPeers.begin();sn!=_rootserverPeers.end();++sn) {
if ((*sn)->hasActiveDirectPath(now)) {
unsigned int l = (*sn)->latency();
if (bestSupernode) {
if ((l)&&(l < bestSupernodeLatency)) {
bestSupernodeLatency = l;
bestSupernode = *sn;
if (bestRootserver) {
if ((l)&&(l < bestRootserverLatency)) {
bestRootserverLatency = l;
bestRootserver = *sn;
}
} else {
if (l)
bestSupernodeLatency = l;
bestSupernode = *sn;
bestRootserverLatency = l;
bestRootserver = *sn;
}
}
}
}
if (bestSupernode)
bestSupernode->use(now);
return bestSupernode;
if (bestRootserver)
bestRootserver->use(now);
return bestRootserver;
}
void Topology::clean(uint64_t now)
{
Mutex::Lock _l(_lock);
for(std::map< Address,SharedPtr<Peer> >::iterator p(_activePeers.begin());p!=_activePeers.end();) {
if (((now - p->second->lastUsed()) >= ZT_PEER_IN_MEMORY_EXPIRATION)&&(std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),p->first) == _supernodeAddresses.end())) {
if (((now - p->second->lastUsed()) >= ZT_PEER_IN_MEMORY_EXPIRATION)&&(std::find(_rootserverAddresses.begin(),_rootserverAddresses.end(),p->first) == _rootserverAddresses.end())) {
_activePeers.erase(p++);
} else ++p;
}

View file

@ -59,21 +59,21 @@ public:
~Topology();
/**
* Set up supernodes for this network
* Set up rootservers for this network
*
* @param sn Supernodes for this network
* @param sn Rootservers for this network
*/
void setSupernodes(const std::map< Identity,std::vector<InetAddress> > &sn);
void setRootservers(const std::map< Identity,std::vector<InetAddress> > &sn);
/**
* Set up supernodes for this network
* Set up rootservers for this network
*
* This performs no signature verification of any kind. The caller must
* check the signature of the root topology dictionary first.
*
* @param sn Supernodes dictionary from root-topology
* @param sn Rootservers dictionary from root-topology
*/
void setSupernodes(const Dictionary &sn);
void setRootservers(const Dictionary &sn);
/**
* Add a peer to database
@ -95,65 +95,65 @@ public:
SharedPtr<Peer> getPeer(const Address &zta);
/**
* @return Vector of peers that are supernodes
* @return Vector of peers that are rootservers
*/
inline std::vector< SharedPtr<Peer> > supernodePeers() const
inline std::vector< SharedPtr<Peer> > rootserverPeers() const
{
Mutex::Lock _l(_lock);
return _supernodePeers;
return _rootserverPeers;
}
/**
* @return Number of supernodes
* @return Number of rootservers
*/
inline unsigned int numSupernodes() const
inline unsigned int numRootservers() const
{
Mutex::Lock _l(_lock);
return (unsigned int)_supernodePeers.size();
return (unsigned int)_rootserverPeers.size();
}
/**
* Get the current favorite supernode
* Get the current favorite rootserver
*
* @return Supernode with lowest latency or NULL if none
* @return Rootserver with lowest latency or NULL if none
*/
inline SharedPtr<Peer> getBestSupernode()
inline SharedPtr<Peer> getBestRootserver()
{
return getBestSupernode((const Address *)0,0,false);
return getBestRootserver((const Address *)0,0,false);
}
/**
* Get the best supernode, avoiding supernodes listed in an array
* Get the best rootserver, avoiding rootservers listed in an array
*
* This will get the best supernode (lowest latency, etc.) but will
* try to avoid the listed supernodes, only using them if no others
* This will get the best rootserver (lowest latency, etc.) but will
* try to avoid the listed rootservers, only using them if no others
* are available.
*
* @param avoid Nodes to avoid
* @param avoidCount Number of nodes to avoid
* @param strictAvoid If false, consider avoided supernodes anyway if no non-avoid supernodes are available
* @return Supernode or NULL if none
* @param strictAvoid If false, consider avoided rootservers anyway if no non-avoid rootservers are available
* @return Rootserver or NULL if none
*/
SharedPtr<Peer> getBestSupernode(const Address *avoid,unsigned int avoidCount,bool strictAvoid);
SharedPtr<Peer> getBestRootserver(const Address *avoid,unsigned int avoidCount,bool strictAvoid);
/**
* @param zta ZeroTier address
* @return True if this is a designated supernode
* @return True if this is a designated rootserver
*/
inline bool isSupernode(const Address &zta) const
inline bool isRootserver(const Address &zta) const
throw()
{
Mutex::Lock _l(_lock);
return (std::find(_supernodeAddresses.begin(),_supernodeAddresses.end(),zta) != _supernodeAddresses.end());
return (std::find(_rootserverAddresses.begin(),_rootserverAddresses.end(),zta) != _rootserverAddresses.end());
}
/**
* @return Vector of supernode addresses
* @return Vector of rootserver addresses
*/
inline std::vector<Address> supernodeAddresses() const
inline std::vector<Address> rootserverAddresses() const
{
Mutex::Lock _l(_lock);
return _supernodeAddresses;
return _rootserverAddresses;
}
/**
@ -206,13 +206,13 @@ private:
const RuntimeEnvironment *RR;
std::map< Address,SharedPtr<Peer> > _activePeers;
std::map< Identity,std::vector<InetAddress> > _supernodes;
std::vector< Address > _supernodeAddresses;
std::vector< SharedPtr<Peer> > _supernodePeers;
std::map< Identity,std::vector<InetAddress> > _rootservers;
std::vector< Address > _rootserverAddresses;
std::vector< SharedPtr<Peer> > _rootserverPeers;
Mutex _lock;
bool _amSupernode;
bool _amRootserver;
};
} // namespace ZeroTier