mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-07 02:58:31 +00:00
pushDirectPaths() implementation
This commit is contained in:
parent
93bb934d4e
commit
255320e2a6
@ -319,6 +319,11 @@
|
|||||||
*/
|
*/
|
||||||
#define ZT_MIN_PATH_CONFIRMATION_INTERVAL 5000
|
#define ZT_MIN_PATH_CONFIRMATION_INTERVAL 5000
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interval between direct path pushes in milliseconds
|
||||||
|
*/
|
||||||
|
#define ZT_DIRECT_PATH_PUSH_INTERVAL 300000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanity limit on maximum bridge routes
|
* Sanity limit on maximum bridge routes
|
||||||
*
|
*
|
||||||
|
@ -892,7 +892,6 @@ public:
|
|||||||
VERB_SET_EPHEMERAL_KEY = 15,
|
VERB_SET_EPHEMERAL_KEY = 15,
|
||||||
|
|
||||||
/* Push of potential endpoints for direct communication:
|
/* Push of potential endpoints for direct communication:
|
||||||
* <[1] flags (unused, must be zero)>
|
|
||||||
* <[2] 16-bit number of paths>
|
* <[2] 16-bit number of paths>
|
||||||
* <[...] paths>
|
* <[...] paths>
|
||||||
*
|
*
|
||||||
|
@ -208,9 +208,66 @@ void Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void Peer::pushDirectPaths(const std::vector<Path> &dps,uint64_t now,bool force)
|
void Peer::pushDirectPaths(const RuntimeEnvironment *RR,const std::vector<Path> &dps,uint64_t now,bool force)
|
||||||
//{
|
{
|
||||||
//}
|
if (((now - _lastDirectPathPush) >= ZT_DIRECT_PATH_PUSH_INTERVAL)||(force)) {
|
||||||
|
_lastDirectPathPush = now;
|
||||||
|
|
||||||
|
std::vector<Path>::const_iterator p(dps.begin());
|
||||||
|
while (p != dps.end()) {
|
||||||
|
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS);
|
||||||
|
outp.addSize(2); // leave room for count
|
||||||
|
|
||||||
|
unsigned int count = 0;
|
||||||
|
while ((p != dps.end())&&((outp.size() + 24) < ZT_PROTO_MAX_PACKET_LENGTH)) {
|
||||||
|
uint8_t addressType = 4;
|
||||||
|
switch(p->address().ss_family) {
|
||||||
|
case AF_INET:
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
addressType = 6;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
++p;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t flags = 0;
|
||||||
|
if (p->metric() < 0)
|
||||||
|
flags |= (0x01 | 0x02); // forget and blacklist
|
||||||
|
else {
|
||||||
|
if (p->reliable())
|
||||||
|
flags |= 0x04; // no NAT keepalives and such
|
||||||
|
switch(p->trust()) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
case Path::TRUST_PRIVACY:
|
||||||
|
flags |= 0x08; // no encryption
|
||||||
|
break;
|
||||||
|
case Path::TRUST_ULTIMATE:
|
||||||
|
flags |= (0x08 | 0x10); // no encryption, no authentication (redundant but go ahead and set both)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outp.append(flags);
|
||||||
|
outp.append((uint8_t)((p->metric() >= 0) ? ((p->metric() <= 255) ? p->metric() : 255) : 0));
|
||||||
|
outp.append((uint16_t)0);
|
||||||
|
outp.append(addressType);
|
||||||
|
outp.append(p->address().rawIpData(),((addressType == 4) ? 4 : 16));
|
||||||
|
outp.append((uint16_t)p->address().port());
|
||||||
|
|
||||||
|
++count;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count) {
|
||||||
|
outp.setAt(ZT_PACKET_IDX_PAYLOAD,(uint16_t)count);
|
||||||
|
RR->sw->send(outp,true,0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Peer::addPath(const RemotePath &newp)
|
void Peer::addPath(const RemotePath &newp)
|
||||||
{
|
{
|
||||||
|
@ -181,11 +181,12 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Push direct paths (if within rate limit)
|
* Push direct paths (if within rate limit)
|
||||||
*
|
*
|
||||||
|
* @param RR Runtime environment
|
||||||
* @param dps Direct paths to me to push to this peer
|
* @param dps Direct paths to me to push to this peer
|
||||||
* @param now Current time
|
* @param now Current time
|
||||||
* @param force If true, force regardless of when we pushed direct paths last
|
* @param force If true, force regardless of when we pushed direct paths last
|
||||||
*/
|
*/
|
||||||
void pushDirectPaths(const std::vector<InetAddress> &dps,uint64_t now,bool force);
|
void pushDirectPaths(const RuntimeEnvironment *RR,const std::vector<Path> &dps,uint64_t now,bool force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return All known direct paths to this peer
|
* @return All known direct paths to this peer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user