mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-31 08:25:38 +00:00
Push more than one packet for credentials if we happen to have a whole lot. Should not happen often but might if a member has tons of tags.
This commit is contained in:
parent
297b1b4258
commit
a3c7627acf
@ -28,13 +28,16 @@
|
|||||||
|
|
||||||
namespace ZeroTier {
|
namespace ZeroTier {
|
||||||
|
|
||||||
bool Membership::sendCredentialsIfNeeded(const RuntimeEnvironment *RR,const uint64_t now,const Address &peerAddress,const NetworkConfig &nconf,const Capability *cap)
|
void Membership::sendCredentialsIfNeeded(const RuntimeEnvironment *RR,const uint64_t now,const Address &peerAddress,const NetworkConfig &nconf,const Capability *cap)
|
||||||
{
|
{
|
||||||
if ((now - _lastPushAttempt) < 1000ULL)
|
if ((now - _lastPushAttempt) < 1000ULL)
|
||||||
return false;
|
return;
|
||||||
_lastPushAttempt = now;
|
_lastPushAttempt = now;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
bool unfinished;
|
||||||
|
do {
|
||||||
|
unfinished = false;
|
||||||
Buffer<ZT_PROTO_MAX_PACKET_LENGTH> capsAndTags;
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH> capsAndTags;
|
||||||
|
|
||||||
unsigned int appendedCaps = 0;
|
unsigned int appendedCaps = 0;
|
||||||
@ -57,8 +60,10 @@ bool Membership::sendCredentialsIfNeeded(const RuntimeEnvironment *RR,const uint
|
|||||||
for(unsigned int i=0;i<nconf.tagCount;++i) {
|
for(unsigned int i=0;i<nconf.tagCount;++i) {
|
||||||
TState *const ts = _tags.get(nconf.tags[i].id());
|
TState *const ts = _tags.get(nconf.tags[i].id());
|
||||||
if ((now - ts->lastPushed) >= ZT_CREDENTIAL_PUSH_EVERY) {
|
if ((now - ts->lastPushed) >= ZT_CREDENTIAL_PUSH_EVERY) {
|
||||||
if ((capsAndTags.size() + sizeof(Tag)) > (ZT_PROTO_MAX_PACKET_LENGTH - sizeof(CertificateOfMembership)))
|
if ((capsAndTags.size() + sizeof(Tag)) >= (ZT_PROTO_MAX_PACKET_LENGTH - sizeof(CertificateOfMembership))) {
|
||||||
|
unfinished = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
nconf.tags[i].serialize(capsAndTags);
|
nconf.tags[i].serialize(capsAndTags);
|
||||||
ts->lastPushed = now;
|
ts->lastPushed = now;
|
||||||
++appendedTags;
|
++appendedTags;
|
||||||
@ -77,12 +82,11 @@ bool Membership::sendCredentialsIfNeeded(const RuntimeEnvironment *RR,const uint
|
|||||||
outp.append(capsAndTags.data(),capsAndTags.size());
|
outp.append(capsAndTags.data(),capsAndTags.size());
|
||||||
outp.compress();
|
outp.compress();
|
||||||
RR->sw->send(outp,true);
|
RR->sw->send(outp,true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
} while (unfinished); // if there are many tags, etc., we can send more than one
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
TRACE("unable to send credentials due to unexpected exception");
|
TRACE("unable to send credentials due to unexpected exception");
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Membership::addCredential(const RuntimeEnvironment *RR,const CertificateOfMembership &com)
|
int Membership::addCredential(const RuntimeEnvironment *RR,const CertificateOfMembership &com)
|
||||||
|
@ -127,9 +127,8 @@ public:
|
|||||||
* @param peerAddress Address of member peer
|
* @param peerAddress Address of member peer
|
||||||
* @param nconf My network config
|
* @param nconf My network config
|
||||||
* @param cap Capability to send or 0 if none
|
* @param cap Capability to send or 0 if none
|
||||||
* @return True if we pushed something
|
|
||||||
*/
|
*/
|
||||||
bool sendCredentialsIfNeeded(const RuntimeEnvironment *RR,const uint64_t now,const Address &peerAddress,const NetworkConfig &nconf,const Capability *cap);
|
void sendCredentialsIfNeeded(const RuntimeEnvironment *RR,const uint64_t now,const Address &peerAddress,const NetworkConfig &nconf,const Capability *cap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param nconf Our network config
|
* @param nconf Our network config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user