mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-22 15:06:54 +02:00
properly adjust various lines
breakup multiple statements onto multiple lines
This commit is contained in:
parent
6306db65a1
commit
8e0ecc88f7
26 changed files with 551 additions and 308 deletions
|
@ -112,13 +112,11 @@ SharedPtr<Bond> Bond::createBond(const RuntimeEnvironment* renv, const SharedPtr
|
|||
bond = new Bond(renv, _bondPolicyTemplates[_defaultPolicyStr].ptr(), peer);
|
||||
bond->debug("new default custom bond (based on %s)", bond->getPolicyStrByCode(bond->policy()).c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (! _bondPolicyTemplates[_policyTemplateAssignments[identity]]) {
|
||||
bond = new Bond(renv, _defaultPolicy, peer);
|
||||
bond->debug("peer-specific bond, was specified as %s but the bond definition was not found, using default %s", _policyTemplateAssignments[identity].c_str(), getPolicyStrByCode(_defaultPolicy).c_str());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bond = new Bond(renv, _bondPolicyTemplates[_policyTemplateAssignments[identity]].ptr(), peer);
|
||||
bond->debug("new default bond");
|
||||
}
|
||||
|
@ -187,12 +185,10 @@ SharedPtr<Link> Bond::getLinkBySocket(const std::string& policyAlias, uint64_t l
|
|||
SharedPtr<Link> s = new Link(ifnameStr, 0, 0, 0, true, ZT_BOND_SLAVE_MODE_PRIMARY, "");
|
||||
_interfaceToLinkMap[policyAlias].insert(std::pair<std::string, SharedPtr<Link> >(ifnameStr, s));
|
||||
return s;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return SharedPtr<Link>();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return search->second;
|
||||
}
|
||||
}
|
||||
|
@ -359,8 +355,7 @@ SharedPtr<Path> Bond::getAppropriatePath(int64_t now, int32_t flowId)
|
|||
_rrPacketsSentOnCurrLink = 0;
|
||||
if (_numBondedPaths == 1 || _rrIdx >= (ZT_MAX_PEER_NETWORK_PATHS - 1)) {
|
||||
_rrIdx = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int _tempIdx = _rrIdx;
|
||||
for (int searchCount = 0; searchCount < (_numBondedPaths - 1); searchCount++) {
|
||||
_tempIdx = (_tempIdx == (_numBondedPaths - 1)) ? 0 : _tempIdx + 1;
|
||||
|
@ -390,8 +385,7 @@ SharedPtr<Path> Bond::getAppropriatePath(int64_t now, int32_t flowId)
|
|||
if (likely(it != _flows.end())) {
|
||||
it->second->lastActivity = now;
|
||||
return _paths[it->second->assignedPath].p;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
unsigned char entropy;
|
||||
Utils::getSecureRandom(&entropy, 1);
|
||||
SharedPtr<Flow> flow = createFlow(ZT_MAX_PEER_NETWORK_PATHS, flowId, entropy, now);
|
||||
|
@ -469,8 +463,7 @@ void Bond::recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId,
|
|||
_paths[pathIdx].qosStatsIn[packetId] = now;
|
||||
++(_paths[pathIdx].packetsReceivedSinceLastQoS);
|
||||
//_paths[pathIdx].packetValiditySamples.push(true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// debug("QoS buffer full, will not record information");
|
||||
}
|
||||
/*
|
||||
|
@ -497,8 +490,7 @@ void Bond::recordIncomingPacket(const SharedPtr<Path>& path, uint64_t packetId,
|
|||
SharedPtr<Flow> flow;
|
||||
if (! _flows.count(flowId)) {
|
||||
flow = createFlow(pathIdx, flowId, 0, now);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
flow = _flows[flowId];
|
||||
}
|
||||
if (flow) {
|
||||
|
@ -584,8 +576,7 @@ bool Bond::assignFlowToBondedPath(SharedPtr<Flow>& flow, int64_t now, bool reass
|
|||
|
||||
if (reassign) {
|
||||
log("attempting to re-assign out-flow %04x previously on idx %d (%u / %zu flows)", flow->id, flow->assignedPath, _paths[_realIdxMap[flow->assignedPath]].assignedFlowCount, _flows.size());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
debug("attempting to assign flow for the first time");
|
||||
}
|
||||
|
||||
|
@ -599,8 +590,7 @@ bool Bond::assignFlowToBondedPath(SharedPtr<Flow>& flow, int64_t now, bool reass
|
|||
|
||||
if (reassign) {
|
||||
bondedIdx = (flow->assignedPath + offset) % (_numBondedPaths);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bondedIdx = abs((int)((entropy + offset) % (_numBondedPaths)));
|
||||
}
|
||||
// debug("idx=%d, offset=%d, randomCap=%f, actualCap=%f", bondedIdx, offset, randomLinkCapacity, _paths[_realIdxMap[bondedIdx]].relativeLinkCapacity);
|
||||
|
@ -623,8 +613,7 @@ bool Bond::assignFlowToBondedPath(SharedPtr<Flow>& flow, int64_t now, bool reass
|
|||
flow->assignPath(_realIdxMap[bondedIdx], now);
|
||||
++(_paths[_realIdxMap[bondedIdx]].assignedFlowCount);
|
||||
// debug(" ABLE to find optimal link %f idx %d", _paths[_realIdxMap[bondedIdx]].relativeQuality, bondedIdx);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// We were (unable) to find a path that didn't violate at least one quality requirement, will choose next best option
|
||||
flow->assignPath(_realIdxMap[nextBestQualIdx], now);
|
||||
++(_paths[_realIdxMap[nextBestQualIdx]].assignedFlowCount);
|
||||
|
@ -684,13 +673,11 @@ void Bond::forgetFlowsWhenNecessary(uint64_t age, bool oldest, int64_t now)
|
|||
debug("forget flow %04x (age %" PRId64 ") (%u / %zu)", it->first, it->second->age(now), _paths[it->second->assignedPath].assignedFlowCount, (_flows.size() - 1));
|
||||
_paths[it->second->assignedPath].assignedFlowCount--;
|
||||
it = _flows.erase(it);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (oldest) { // Remove single oldest by natural expiration
|
||||
} else if (oldest) { // Remove single oldest by natural expiration
|
||||
uint64_t maxAge = 0;
|
||||
while (it != _flows.end()) {
|
||||
if (it->second->age(now) > maxAge) {
|
||||
|
@ -737,8 +724,7 @@ void Bond::processIncomingPathNegotiationRequest(uint64_t now, SharedPtr<Path>&
|
|||
if (_peer->_id.address().toInt() > RR->node->identity().address().toInt()) {
|
||||
debug("agree with peer to use alternate link %s/%s\n", link->ifname().c_str(), pathStr);
|
||||
_negotiatedPathIdx = pathIdx;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
debug("ignore petition from peer to use alternate link %s/%s\n", link->ifname().c_str(), pathStr);
|
||||
}
|
||||
}
|
||||
|
@ -852,8 +838,7 @@ void Bond::sendQOS_MEASUREMENT(void* tPtr, int pathIdx, int64_t localSocket, con
|
|||
if (atAddress) {
|
||||
outp.armor(_peer->key(), false, _peer->aesKeysIfSupported());
|
||||
RR->node->putPacket(tPtr, localSocket, atAddress, outp.data(), outp.size());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
RR->sw->send(tPtr, outp, false);
|
||||
}
|
||||
_paths[pathIdx].packetsReceivedSinceLastQoS = 0;
|
||||
|
@ -1192,8 +1177,7 @@ void Bond::estimatePathQuality(int64_t now)
|
|||
if ((now - it->second) >= qosRecordTimeout) {
|
||||
it = _paths[i].qosStatsOut.erase(it);
|
||||
++numDroppedQosOutRecords;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
@ -1221,8 +1205,7 @@ void Bond::estimatePathQuality(int64_t now)
|
|||
if ((now - it->second) >= qosRecordTimeout) {
|
||||
it = _paths[i].qosStatsIn.erase(it);
|
||||
++numDroppedQosInRecords;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
@ -1341,8 +1324,7 @@ void Bond::estimatePathQuality(int64_t now)
|
|||
shouldAvoid = true;
|
||||
}
|
||||
_paths[i].shouldAvoid = shouldAvoid;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (! shouldAvoid) {
|
||||
log("no longer avoiding link %s", pathToStr(_paths[i].p).c_str());
|
||||
_paths[i].shouldAvoid = false;
|
||||
|
@ -1454,8 +1436,7 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
|
|||
_lastBondStatusLog = now;
|
||||
if (_abPathIdx == ZT_MAX_PEER_NETWORK_PATHS) {
|
||||
log("no active link");
|
||||
}
|
||||
else if (_paths[_abPathIdx].p) {
|
||||
} else if (_paths[_abPathIdx].p) {
|
||||
log("active link is %s, failover queue size is %zu", pathToStr(_paths[_abPathIdx].p).c_str(), _abFailoverQueue.size());
|
||||
}
|
||||
if (_abFailoverQueue.empty()) {
|
||||
|
@ -1563,8 +1544,7 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
|
|||
log("link %s is ineligible, removing from failover queue (%zu links remain in queue)", pathToStr(_paths[_abPathIdx].p).c_str(), _abFailoverQueue.size());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
@ -1713,8 +1693,7 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
|
|||
if (! _abFailoverQueue.empty()) {
|
||||
dequeueNextActiveBackupPath(now);
|
||||
log("active link switched to %s", pathToStr(_paths[_abPathIdx].p).c_str());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log("failover queue is empty, no links to choose from");
|
||||
}
|
||||
}
|
||||
|
@ -1760,8 +1739,7 @@ void Bond::processActiveBackupTasks(void* tPtr, int64_t now)
|
|||
dequeueNextActiveBackupPath(now);
|
||||
_lastPathNegotiationCheck = now;
|
||||
log("switch negotiated link %s (select mode: optimize)", pathToStr(_paths[_abPathIdx].p).c_str());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Try to find a better path and automatically switch to it -- not too often, though.
|
||||
if ((now - _lastActiveBackupPathChange) > ZT_BOND_OPTIMIZE_INTERVAL) {
|
||||
if (! _abFailoverQueue.empty()) {
|
||||
|
|
|
@ -889,8 +889,7 @@ class Bond {
|
|||
_lastAckRateCheck = now;
|
||||
if (_ackCutoffCount > numToDrain) {
|
||||
_ackCutoffCount -= numToDrain;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_ackCutoffCount = 0;
|
||||
}
|
||||
return (_ackCutoffCount < ZT_ACK_CUTOFF_LIMIT);
|
||||
|
@ -909,8 +908,7 @@ class Bond {
|
|||
uint64_t diff = now - _lastQoSRateCheck;
|
||||
if ((diff) <= (_qosSendInterval / ZT_MAX_PEER_NETWORK_PATHS)) {
|
||||
++_qosCutoffCount;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_qosCutoffCount = 0;
|
||||
}
|
||||
_lastQoSRateCheck = now;
|
||||
|
@ -930,8 +928,7 @@ class Bond {
|
|||
int diff = now - _lastPathNegotiationReceived;
|
||||
if ((diff) <= (ZT_PATH_NEGOTIATION_CUTOFF_TIME / ZT_MAX_PEER_NETWORK_PATHS)) {
|
||||
++_pathNegotiationCutoffCount;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_pathNegotiationCutoffCount = 0;
|
||||
}
|
||||
_lastPathNegotiationReceived = now;
|
||||
|
@ -1228,20 +1225,17 @@ class Bond {
|
|||
unsigned int suggestedRefractoryPeriod = refractoryPeriod ? punishment + (refractoryPeriod * 2) : punishment;
|
||||
refractoryPeriod = std::min(suggestedRefractoryPeriod, (unsigned int)ZT_BOND_MAX_REFRACTORY_PERIOD);
|
||||
lastRefractoryUpdate = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uint32_t drainRefractory = 0;
|
||||
if (lastRefractoryUpdate) {
|
||||
drainRefractory = (now - lastRefractoryUpdate);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
drainRefractory = (now - lastAliveToggle);
|
||||
}
|
||||
lastRefractoryUpdate = now;
|
||||
if (refractoryPeriod > drainRefractory) {
|
||||
refractoryPeriod -= drainRefractory;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
refractoryPeriod = 0;
|
||||
lastRefractoryUpdate = 0;
|
||||
}
|
||||
|
|
|
@ -837,14 +837,12 @@ static inline void reduce_add_sub(fe25519 *r)
|
|||
crypto_uint32 t;
|
||||
int i,rep;
|
||||
|
||||
for(rep=0;rep<4;rep++)
|
||||
{
|
||||
for(rep=0;rep<4;rep++) {
|
||||
t = r->v[31] >> 7;
|
||||
r->v[31] &= 127;
|
||||
t = times19(t);
|
||||
r->v[0] += t;
|
||||
for(i=0;i<31;i++)
|
||||
{
|
||||
for(i=0;i<31;i++) {
|
||||
t = r->v[i] >> 8;
|
||||
r->v[i+1] += t;
|
||||
r->v[i] &= 255;
|
||||
|
@ -857,14 +855,12 @@ static inline void reduce_mul(fe25519 *r)
|
|||
crypto_uint32 t;
|
||||
int i,rep;
|
||||
|
||||
for(rep=0;rep<2;rep++)
|
||||
{
|
||||
for(rep=0;rep<2;rep++) {
|
||||
t = r->v[31] >> 7;
|
||||
r->v[31] &= 127;
|
||||
t = times19(t);
|
||||
r->v[0] += t;
|
||||
for(i=0;i<31;i++)
|
||||
{
|
||||
for(i=0;i<31;i++) {
|
||||
t = r->v[i] >> 8;
|
||||
r->v[i+1] += t;
|
||||
r->v[i] &= 255;
|
||||
|
@ -1136,8 +1132,7 @@ static inline void reduce_add_sub(sc25519 *r)
|
|||
int i;
|
||||
unsigned char t[32];
|
||||
|
||||
for(i=0;i<32;i++)
|
||||
{
|
||||
for(i=0;i<32;i++) {
|
||||
pb += m[i];
|
||||
b = lt(r->v[i],pb);
|
||||
t[i] = r->v[i]-pb+(b<<8);
|
||||
|
@ -1177,15 +1172,13 @@ static inline void barrett_reduce(sc25519 *r, const crypto_uint32 x[64])
|
|||
for(j=0;j<33;j++)
|
||||
if(i+j < 33) r2[i+j] += m[i]*q3[j];
|
||||
|
||||
for(i=0;i<32;i++)
|
||||
{
|
||||
for(i=0;i<32;i++) {
|
||||
carry = r2[i] >> 8;
|
||||
r2[i+1] += carry;
|
||||
r2[i] &= 0xff;
|
||||
}
|
||||
|
||||
for(i=0;i<32;i++)
|
||||
{
|
||||
for(i=0;i<32;i++) {
|
||||
pb += r2[i];
|
||||
b = lt(r1[i],pb);
|
||||
r->v[i] = r1[i]-pb+(b<<8);
|
||||
|
@ -1227,8 +1220,7 @@ static inline void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y)
|
|||
{
|
||||
int i, carry;
|
||||
for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i];
|
||||
for(i=0;i<31;i++)
|
||||
{
|
||||
for(i=0;i<31;i++) {
|
||||
carry = r->v[i] >> 8;
|
||||
r->v[i+1] += carry;
|
||||
r->v[i] &= 0xff;
|
||||
|
@ -1246,8 +1238,7 @@ static inline void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y)
|
|||
for(j=0;j<32;j++)
|
||||
t[i+j] += x->v[i] * y->v[j];
|
||||
|
||||
for(i=0;i<63;i++)
|
||||
{
|
||||
for(i=0;i<63;i++) {
|
||||
carry = t[i] >> 8;
|
||||
t[i+1] += carry;
|
||||
t[i] &= 0xff;
|
||||
|
@ -1260,8 +1251,7 @@ static inline void sc25519_window3(signed char r[85], const sc25519 *s)
|
|||
{
|
||||
char carry;
|
||||
int i;
|
||||
for(i=0;i<10;i++)
|
||||
{
|
||||
for(i=0;i<10;i++) {
|
||||
r[8*i+0] = s->v[3*i+0] & 7;
|
||||
r[8*i+1] = (s->v[3*i+0] >> 3) & 7;
|
||||
r[8*i+2] = (s->v[3*i+0] >> 6) & 7;
|
||||
|
@ -1282,8 +1272,7 @@ static inline void sc25519_window3(signed char r[85], const sc25519 *s)
|
|||
|
||||
/* Making it signed */
|
||||
carry = 0;
|
||||
for(i=0;i<84;i++)
|
||||
{
|
||||
for(i=0;i<84;i++) {
|
||||
r[i] += carry;
|
||||
r[i+1] += r[i] >> 3;
|
||||
r[i] &= 7;
|
||||
|
@ -1296,8 +1285,7 @@ static inline void sc25519_window3(signed char r[85], const sc25519 *s)
|
|||
static inline void sc25519_2interleave2(unsigned char r[127], const sc25519 *s1, const sc25519 *s2)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<31;i++)
|
||||
{
|
||||
for(i=0;i<31;i++) {
|
||||
r[4*i] = ( s1->v[i] & 3) ^ (( s2->v[i] & 3) << 2);
|
||||
r[4*i+1] = ((s1->v[i] >> 2) & 3) ^ (((s2->v[i] >> 2) & 3) << 2);
|
||||
r[4*i+2] = ((s1->v[i] >> 4) & 3) ^ (((s2->v[i] >> 4) & 3) << 2);
|
||||
|
@ -2399,13 +2387,11 @@ static inline void ge25519_double_scalarmult_vartime(ge25519_p3 *r, const ge2551
|
|||
|
||||
/* scalar multiplication */
|
||||
*r = pre[b[126]];
|
||||
for(i=125;i>=0;i--)
|
||||
{
|
||||
for(i=125;i>=0;i--) {
|
||||
dbl_p1p1(&tp1p1, (ge25519_p2 *)r);
|
||||
p1p1_to_p2((ge25519_p2 *) r, &tp1p1);
|
||||
dbl_p1p1(&tp1p1, (ge25519_p2 *)r);
|
||||
if(b[i]!=0)
|
||||
{
|
||||
if(b[i]!=0) {
|
||||
p1p1_to_p3(r, &tp1p1);
|
||||
add_p1p1(&tp1p1, r, &pre[b[i]]);
|
||||
}
|
||||
|
@ -2424,8 +2410,7 @@ static inline void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s)
|
|||
choose_t((ge25519_aff *)r, 0, b[0]);
|
||||
fe25519_setone(&r->z);
|
||||
fe25519_mul(&r->t, &r->x, &r->y);
|
||||
for(i=1;i<85;i++)
|
||||
{
|
||||
for(i=1;i<85;i++) {
|
||||
choose_t(&t, (unsigned long long) i, b[i]);
|
||||
ge25519_mixadd2(r, &t);
|
||||
}
|
||||
|
|
|
@ -419,11 +419,15 @@ public:
|
|||
|
||||
unsigned int p = startAt;
|
||||
|
||||
_nwid = b.template at<uint64_t>(p); p += 8;
|
||||
_ts = b.template at<uint64_t>(p); p += 8;
|
||||
_id = b.template at<uint32_t>(p); p += 4;
|
||||
_nwid = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_ts = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_id = b.template at<uint32_t>(p);
|
||||
p += 4;
|
||||
|
||||
const unsigned int rc = b.template at<uint16_t>(p); p += 2;
|
||||
const unsigned int rc = b.template at<uint16_t>(p);
|
||||
p += 2;
|
||||
if (rc > ZT_MAX_CAPABILITY_RULES)
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
|
||||
deserializeRules(b,p,_rules,_ruleCount,rc);
|
||||
|
@ -433,18 +437,21 @@ public:
|
|||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
|
||||
|
||||
for(unsigned int i=0;;++i) {
|
||||
const Address to(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
const Address to(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
if (!to)
|
||||
break;
|
||||
if ((i >= _maxCustodyChainLength)||(i >= ZT_MAX_CAPABILITY_CUSTODY_CHAIN_LENGTH))
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
|
||||
_custody[i].to = to;
|
||||
_custody[i].from.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_custody[i].from.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
if (b[p++] == 1) {
|
||||
if (b.template at<uint16_t>(p) != ZT_C25519_SIGNATURE_LEN)
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN;
|
||||
p += 2;
|
||||
memcpy(_custody[i].signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN); p += ZT_C25519_SIGNATURE_LEN;
|
||||
memcpy(_custody[i].signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN);
|
||||
p += ZT_C25519_SIGNATURE_LEN;
|
||||
} else {
|
||||
p += 2 + b.template at<uint16_t>(p);
|
||||
}
|
||||
|
|
|
@ -241,7 +241,8 @@ public:
|
|||
if (b[p++] != 1)
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE;
|
||||
|
||||
unsigned int numq = b.template at<uint16_t>(p); p += sizeof(uint16_t);
|
||||
unsigned int numq = b.template at<uint16_t>(p);
|
||||
p += sizeof(uint16_t);
|
||||
uint64_t lastId = 0;
|
||||
for(unsigned int i=0;i<numq;++i) {
|
||||
const uint64_t qid = b.template at<uint64_t>(p);
|
||||
|
|
|
@ -174,11 +174,16 @@ public:
|
|||
|
||||
*this = CertificateOfOwnership();
|
||||
|
||||
_networkId = b.template at<uint64_t>(p); p += 8;
|
||||
_ts = b.template at<uint64_t>(p); p += 8;
|
||||
_flags = b.template at<uint64_t>(p); p += 8;
|
||||
_id = b.template at<uint32_t>(p); p += 4;
|
||||
_thingCount = b.template at<uint16_t>(p); p += 2;
|
||||
_networkId = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_ts = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_flags = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_id = b.template at<uint32_t>(p);
|
||||
p += 4;
|
||||
_thingCount = b.template at<uint16_t>(p);
|
||||
p += 2;
|
||||
for(unsigned int i=0,j=_thingCount;i<j;++i) {
|
||||
if (i < ZT_CERTIFICATEOFOWNERSHIP_MAX_THINGS) {
|
||||
_thingTypes[i] = (uint8_t)b[p++];
|
||||
|
@ -187,13 +192,16 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
_issuedTo.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_issuedTo.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
if (b[p++] == 1) {
|
||||
if (b.template at<uint16_t>(p) != ZT_C25519_SIGNATURE_LEN)
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN;
|
||||
p += 2;
|
||||
memcpy(_signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN); p += ZT_C25519_SIGNATURE_LEN;
|
||||
memcpy(_signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN);
|
||||
p += ZT_C25519_SIGNATURE_LEN;
|
||||
} else {
|
||||
p += 2 + b.template at<uint16_t>(p);
|
||||
}
|
||||
|
|
|
@ -164,11 +164,21 @@ public:
|
|||
if (esc) {
|
||||
esc = false;
|
||||
switch(*p) {
|
||||
case 'r': dest[j++] = 13; break;
|
||||
case 'n': dest[j++] = 10; break;
|
||||
case '0': dest[j++] = (char)0; break;
|
||||
case 'e': dest[j++] = '='; break;
|
||||
default: dest[j++] = *p; break;
|
||||
case 'r':
|
||||
dest[j++] = 13;
|
||||
break;
|
||||
case 'n':
|
||||
dest[j++] = 10;
|
||||
break;
|
||||
case '0':
|
||||
dest[j++] = (char)0;
|
||||
break;
|
||||
case 'e':
|
||||
dest[j++] = '=';
|
||||
break;
|
||||
default:
|
||||
dest[j++] = *p;
|
||||
break;
|
||||
}
|
||||
if (j == (int)destlen) {
|
||||
dest[j-1] = (char)0;
|
||||
|
@ -335,11 +345,21 @@ public:
|
|||
return false;
|
||||
}
|
||||
switch(*p) {
|
||||
case 0: _d[j++] = '0'; break;
|
||||
case 13: _d[j++] = 'r'; break;
|
||||
case 10: _d[j++] = 'n'; break;
|
||||
case '\\': _d[j++] = '\\'; break;
|
||||
case '=': _d[j++] = 'e'; break;
|
||||
case 0:
|
||||
_d[j++] = '0';
|
||||
break;
|
||||
case 13:
|
||||
_d[j++] = 'r';
|
||||
break;
|
||||
case 10:
|
||||
_d[j++] = 'n';
|
||||
break;
|
||||
case '\\':
|
||||
_d[j++] = '\\';
|
||||
break;
|
||||
case '=':
|
||||
_d[j++] = 'e';
|
||||
break;
|
||||
}
|
||||
if (j == C) {
|
||||
_d[i] = (char)0;
|
||||
|
|
|
@ -89,26 +89,66 @@ bool IncomingPacket::tryDecode(const RuntimeEnvironment *RR,void *tPtr,int32_t f
|
|||
Metrics::pkt_nop_in++;
|
||||
peer->received(tPtr,_path,hops(),packetId(),payloadLength(),v,0,Packet::VERB_NOP,false,0,ZT_QOS_NO_FLOW);
|
||||
break;
|
||||
case Packet::VERB_HELLO: r = _doHELLO(RR,tPtr,true); break;
|
||||
case Packet::VERB_ACK : r = _doACK(RR,tPtr,peer); break;
|
||||
case Packet::VERB_QOS_MEASUREMENT: r = _doQOS_MEASUREMENT(RR,tPtr,peer); break;
|
||||
case Packet::VERB_ERROR: r = _doERROR(RR,tPtr,peer); break;
|
||||
case Packet::VERB_OK: r = _doOK(RR,tPtr,peer); break;
|
||||
case Packet::VERB_WHOIS: r = _doWHOIS(RR,tPtr,peer); break;
|
||||
case Packet::VERB_RENDEZVOUS: r = _doRENDEZVOUS(RR,tPtr,peer); break;
|
||||
case Packet::VERB_FRAME: r = _doFRAME(RR,tPtr,peer,flowId); break;
|
||||
case Packet::VERB_EXT_FRAME: r = _doEXT_FRAME(RR,tPtr,peer,flowId); break;
|
||||
case Packet::VERB_ECHO: r = _doECHO(RR,tPtr,peer); break;
|
||||
case Packet::VERB_MULTICAST_LIKE: r = _doMULTICAST_LIKE(RR,tPtr,peer); break;
|
||||
case Packet::VERB_NETWORK_CREDENTIALS: r = _doNETWORK_CREDENTIALS(RR,tPtr,peer); break;
|
||||
case Packet::VERB_NETWORK_CONFIG_REQUEST: r = _doNETWORK_CONFIG_REQUEST(RR,tPtr,peer); break;
|
||||
case Packet::VERB_NETWORK_CONFIG: r = _doNETWORK_CONFIG(RR,tPtr,peer); break;
|
||||
case Packet::VERB_MULTICAST_GATHER: r = _doMULTICAST_GATHER(RR,tPtr,peer); break;
|
||||
case Packet::VERB_MULTICAST_FRAME: r = _doMULTICAST_FRAME(RR,tPtr,peer); break;
|
||||
case Packet::VERB_PUSH_DIRECT_PATHS: r = _doPUSH_DIRECT_PATHS(RR,tPtr,peer); break;
|
||||
case Packet::VERB_USER_MESSAGE: r = _doUSER_MESSAGE(RR,tPtr,peer); break;
|
||||
case Packet::VERB_REMOTE_TRACE: r = _doREMOTE_TRACE(RR,tPtr,peer); break;
|
||||
case Packet::VERB_PATH_NEGOTIATION_REQUEST: r = _doPATH_NEGOTIATION_REQUEST(RR,tPtr,peer); break;
|
||||
case Packet::VERB_HELLO:
|
||||
r = _doHELLO(RR, tPtr, true);
|
||||
break;
|
||||
case Packet::VERB_ACK:
|
||||
r = _doACK(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_QOS_MEASUREMENT:
|
||||
r = _doQOS_MEASUREMENT(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_ERROR:
|
||||
r = _doERROR(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_OK:
|
||||
r = _doOK(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_WHOIS:
|
||||
r = _doWHOIS(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_RENDEZVOUS:
|
||||
r = _doRENDEZVOUS(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_FRAME:
|
||||
r = _doFRAME(RR, tPtr, peer, flowId);
|
||||
break;
|
||||
case Packet::VERB_EXT_FRAME:
|
||||
r = _doEXT_FRAME(RR, tPtr, peer, flowId);
|
||||
break;
|
||||
case Packet::VERB_ECHO:
|
||||
r = _doECHO(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_MULTICAST_LIKE:
|
||||
r = _doMULTICAST_LIKE(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_NETWORK_CREDENTIALS:
|
||||
r = _doNETWORK_CREDENTIALS(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_NETWORK_CONFIG_REQUEST:
|
||||
r = _doNETWORK_CONFIG_REQUEST(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_NETWORK_CONFIG:
|
||||
r = _doNETWORK_CONFIG(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_MULTICAST_GATHER:
|
||||
r = _doMULTICAST_GATHER(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_MULTICAST_FRAME:
|
||||
r = _doMULTICAST_FRAME(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_PUSH_DIRECT_PATHS:
|
||||
r = _doPUSH_DIRECT_PATHS(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_USER_MESSAGE:
|
||||
r = _doUSER_MESSAGE(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_REMOTE_TRACE:
|
||||
r = _doREMOTE_TRACE(RR, tPtr, peer);
|
||||
break;
|
||||
case Packet::VERB_PATH_NEGOTIATION_REQUEST:
|
||||
r = _doPATH_NEGOTIATION_REQUEST(RR, tPtr, peer);
|
||||
break;
|
||||
}
|
||||
if (r) {
|
||||
RR->node->statsLogVerb((unsigned int)v,(unsigned int)size());
|
||||
|
@ -263,7 +303,8 @@ bool IncomingPacket::_doERROR(const RuntimeEnvironment *RR,void *tPtr,const Shar
|
|||
Metrics::pkt_error_authentication_required_in++;
|
||||
} break;
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
peer->received(tPtr,_path,hops(),packetId(),payloadLength(),Packet::VERB_ERROR,inRePacketId,inReVerb,false,networkId,ZT_QOS_NO_FLOW);
|
||||
|
@ -433,8 +474,10 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR,void *tPtr,const bool
|
|||
uint64_t planetWorldId = 0;
|
||||
uint64_t planetWorldTimestamp = 0;
|
||||
if ((ptr + 16) <= size()) {
|
||||
planetWorldId = at<uint64_t>(ptr); ptr += 8;
|
||||
planetWorldTimestamp = at<uint64_t>(ptr); ptr += 8;
|
||||
planetWorldId = at<uint64_t>(ptr);
|
||||
ptr += 8;
|
||||
planetWorldTimestamp = at<uint64_t>(ptr);
|
||||
ptr += 8;
|
||||
}
|
||||
|
||||
std::vector< std::pair<uint64_t,uint64_t> > moonIdsAndTimestamps;
|
||||
|
@ -444,7 +487,8 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR,void *tPtr,const bool
|
|||
|
||||
// Get moon IDs and timestamps if present
|
||||
if ((ptr + 2) <= size()) {
|
||||
const unsigned int numMoons = at<uint16_t>(ptr); ptr += 2;
|
||||
const unsigned int numMoons = at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
for(unsigned int i=0;i<numMoons;++i) {
|
||||
if ((World::Type)(*this)[ptr++] == World::TYPE_MOON)
|
||||
moonIdsAndTimestamps.push_back(std::pair<uint64_t,uint64_t>(at<uint64_t>(ptr),at<uint64_t>(ptr + 8)));
|
||||
|
@ -555,7 +599,8 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,void *tPtr,const SharedP
|
|||
|
||||
// Handle planet or moon updates if present
|
||||
if ((ptr + 2) <= size()) {
|
||||
const unsigned int worldsLen = at<uint16_t>(ptr); ptr += 2;
|
||||
const unsigned int worldsLen = at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
if (RR->topology->shouldAcceptWorldUpdateFrom(peer->address())) {
|
||||
const unsigned int endOfWorlds = ptr + worldsLen;
|
||||
while (ptr < endOfWorlds) {
|
||||
|
@ -624,14 +669,17 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,void *tPtr,const SharedP
|
|||
if ((flags & 0x02) != 0) {
|
||||
// OK(MULTICAST_FRAME) includes implicit gather results
|
||||
offset += ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_COM_AND_GATHER_RESULTS;
|
||||
unsigned int totalKnown = at<uint32_t>(offset); offset += 4;
|
||||
unsigned int count = at<uint16_t>(offset); offset += 2;
|
||||
unsigned int totalKnown = at<uint32_t>(offset);
|
||||
offset += 4;
|
||||
unsigned int count = at<uint16_t>(offset);
|
||||
offset += 2;
|
||||
RR->mc->addMultiple(tPtr,RR->node->now(),networkId,mg,field(offset,count * 5),count,totalKnown);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
peer->received(tPtr,_path,hops(),packetId(),payloadLength(),Packet::VERB_OK,inRePacketId,inReVerb,false,networkId,ZT_QOS_NO_FLOW);
|
||||
|
@ -993,7 +1041,8 @@ bool IncomingPacket::_doNETWORK_CREDENTIALS(const RuntimeEnvironment *RR,void *t
|
|||
++p; // skip trailing 0 after COMs if present
|
||||
|
||||
if (p < size()) { // older ZeroTier versions do not send capabilities, tags, or revocations
|
||||
const unsigned int numCapabilities = at<uint16_t>(p); p += 2;
|
||||
const unsigned int numCapabilities = at<uint16_t>(p);
|
||||
p += 2;
|
||||
for(unsigned int i=0;i<numCapabilities;++i) {
|
||||
p += cap.deserialize(*this,p);
|
||||
if ((!network)||(network->id() != cap.networkId()))
|
||||
|
@ -1014,7 +1063,8 @@ bool IncomingPacket::_doNETWORK_CREDENTIALS(const RuntimeEnvironment *RR,void *t
|
|||
|
||||
if (p >= size()) return true;
|
||||
|
||||
const unsigned int numTags = at<uint16_t>(p); p += 2;
|
||||
const unsigned int numTags = at<uint16_t>(p);
|
||||
p += 2;
|
||||
for(unsigned int i=0;i<numTags;++i) {
|
||||
p += tag.deserialize(*this,p);
|
||||
if ((!network)||(network->id() != tag.networkId()))
|
||||
|
@ -1035,7 +1085,8 @@ bool IncomingPacket::_doNETWORK_CREDENTIALS(const RuntimeEnvironment *RR,void *t
|
|||
|
||||
if (p >= size()) return true;
|
||||
|
||||
const unsigned int numRevocations = at<uint16_t>(p); p += 2;
|
||||
const unsigned int numRevocations = at<uint16_t>(p);
|
||||
p += 2;
|
||||
for(unsigned int i=0;i<numRevocations;++i) {
|
||||
p += revocation.deserialize(*this,p);
|
||||
if ((!network)||(network->id() != revocation.networkId()))
|
||||
|
@ -1056,7 +1107,8 @@ bool IncomingPacket::_doNETWORK_CREDENTIALS(const RuntimeEnvironment *RR,void *t
|
|||
|
||||
if (p >= size()) return true;
|
||||
|
||||
const unsigned int numCoos = at<uint16_t>(p); p += 2;
|
||||
const unsigned int numCoos = at<uint16_t>(p);
|
||||
p += 2;
|
||||
for(unsigned int i=0;i<numCoos;++i) {
|
||||
p += coo.deserialize(*this,p);
|
||||
if ((!network)||(network->id() != coo.networkId()))
|
||||
|
@ -1293,7 +1345,8 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,void *tPt
|
|||
|
||||
while (count--) { // if ptr overflows Buffer will throw
|
||||
unsigned int flags = (*this)[ptr++];
|
||||
unsigned int extLen = at<uint16_t>(ptr); ptr += 2;
|
||||
unsigned int extLen = at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
ptr += extLen; // unused right now
|
||||
unsigned int addrType = (*this)[ptr++];
|
||||
unsigned int addrLen = (*this)[ptr++];
|
||||
|
|
|
@ -33,24 +33,39 @@ InetAddress::IpScope InetAddress::ipScope() const
|
|||
case AF_INET: {
|
||||
const uint32_t ip = Utils::ntoh((uint32_t)reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
|
||||
switch(ip >> 24) {
|
||||
case 0x00: return IP_SCOPE_NONE; // 0.0.0.0/8 (reserved, never used)
|
||||
case 0x06: return IP_SCOPE_PSEUDOPRIVATE; // 6.0.0.0/8 (US Army)
|
||||
case 0x0a: return IP_SCOPE_PRIVATE; // 10.0.0.0/8
|
||||
case 0x0b: return IP_SCOPE_PSEUDOPRIVATE; // 11.0.0.0/8 (US DoD)
|
||||
case 0x15: return IP_SCOPE_PSEUDOPRIVATE; // 21.0.0.0/8 (US DDN-RVN)
|
||||
case 0x16: return IP_SCOPE_PSEUDOPRIVATE; // 22.0.0.0/8 (US DISA)
|
||||
case 0x19: return IP_SCOPE_PSEUDOPRIVATE; // 25.0.0.0/8 (UK Ministry of Defense)
|
||||
case 0x1a: return IP_SCOPE_PSEUDOPRIVATE; // 26.0.0.0/8 (US DISA)
|
||||
case 0x1c: return IP_SCOPE_PSEUDOPRIVATE; // 28.0.0.0/8 (US DSI-North)
|
||||
case 0x1d: return IP_SCOPE_PSEUDOPRIVATE; // 29.0.0.0/8 (US DISA)
|
||||
case 0x1e: return IP_SCOPE_PSEUDOPRIVATE; // 30.0.0.0/8 (US DISA)
|
||||
case 0x33: return IP_SCOPE_PSEUDOPRIVATE; // 51.0.0.0/8 (UK Department of Social Security)
|
||||
case 0x37: return IP_SCOPE_PSEUDOPRIVATE; // 55.0.0.0/8 (US DoD)
|
||||
case 0x38: return IP_SCOPE_PSEUDOPRIVATE; // 56.0.0.0/8 (US Postal Service)
|
||||
case 0x00:
|
||||
return IP_SCOPE_NONE; // 0.0.0.0/8 (reserved, never used)
|
||||
case 0x06:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 6.0.0.0/8 (US Army)
|
||||
case 0x0a:
|
||||
return IP_SCOPE_PRIVATE; // 10.0.0.0/8
|
||||
case 0x0b:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 11.0.0.0/8 (US DoD)
|
||||
case 0x15:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 21.0.0.0/8 (US DDN-RVN)
|
||||
case 0x16:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 22.0.0.0/8 (US DISA)
|
||||
case 0x19:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 25.0.0.0/8 (UK Ministry of Defense)
|
||||
case 0x1a:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 26.0.0.0/8 (US DISA)
|
||||
case 0x1c:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 28.0.0.0/8 (US DSI-North)
|
||||
case 0x1d:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 29.0.0.0/8 (US DISA)
|
||||
case 0x1e:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 30.0.0.0/8 (US DISA)
|
||||
case 0x33:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 51.0.0.0/8 (UK Department of Social Security)
|
||||
case 0x37:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 55.0.0.0/8 (US DoD)
|
||||
case 0x38:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 56.0.0.0/8 (US Postal Service)
|
||||
case 0x64:
|
||||
if ((ip & 0xffc00000) == 0x64400000) return IP_SCOPE_PRIVATE; // 100.64.0.0/10
|
||||
break;
|
||||
case 0x7f: return IP_SCOPE_LOOPBACK; // 127.0.0.0/8
|
||||
case 0x7f:
|
||||
return IP_SCOPE_LOOPBACK; // 127.0.0.0/8
|
||||
case 0xa9:
|
||||
if ((ip & 0xffff0000) == 0xa9fe0000) return IP_SCOPE_LINK_LOCAL; // 169.254.0.0/16
|
||||
break;
|
||||
|
@ -68,11 +83,14 @@ InetAddress::IpScope InetAddress::ipScope() const
|
|||
case 0xcb:
|
||||
if ((ip & 0xffffff00) == 0xcb007100) return IP_SCOPE_PRIVATE; // 203.0.113.0/24
|
||||
break;
|
||||
case 0xff: return IP_SCOPE_NONE; // 255.0.0.0/8 (broadcast, or unused/unusable)
|
||||
case 0xff:
|
||||
return IP_SCOPE_NONE; // 255.0.0.0/8 (broadcast, or unused/unusable)
|
||||
}
|
||||
switch(ip >> 28) {
|
||||
case 0xe: return IP_SCOPE_MULTICAST; // 224.0.0.0/4
|
||||
case 0xf: return IP_SCOPE_PSEUDOPRIVATE; // 240.0.0.0/4 ("reserved," usually unusable)
|
||||
case 0xe:
|
||||
return IP_SCOPE_MULTICAST; // 224.0.0.0/4
|
||||
case 0xf:
|
||||
return IP_SCOPE_PSEUDOPRIVATE; // 240.0.0.0/4 ("reserved," usually unusable)
|
||||
}
|
||||
return IP_SCOPE_GLOBAL;
|
||||
} break;
|
||||
|
|
|
@ -260,9 +260,12 @@ struct InetAddress : public sockaddr_storage
|
|||
inline unsigned int port() const
|
||||
{
|
||||
switch(ss_family) {
|
||||
case AF_INET: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in *>(this)->sin_port));
|
||||
case AF_INET6: return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port));
|
||||
default: return 0;
|
||||
case AF_INET:
|
||||
return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in *>(this)->sin_port));
|
||||
case AF_INET6:
|
||||
return Utils::ntoh((uint16_t)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_port));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,8 +287,10 @@ struct InetAddress : public sockaddr_storage
|
|||
{
|
||||
const unsigned int n = port();
|
||||
switch(ss_family) {
|
||||
case AF_INET: return (n <= 32);
|
||||
case AF_INET6: return (n <= 128);
|
||||
case AF_INET:
|
||||
return (n <= 32);
|
||||
case AF_INET6:
|
||||
return (n <= 128);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -356,9 +361,12 @@ struct InetAddress : public sockaddr_storage
|
|||
inline const void *rawIpData() const
|
||||
{
|
||||
switch(ss_family) {
|
||||
case AF_INET: return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
|
||||
case AF_INET6: return (const void *)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
default: return 0;
|
||||
case AF_INET:
|
||||
return (const void *)&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr);
|
||||
case AF_INET6:
|
||||
return (const void *)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -512,11 +520,16 @@ struct InetAddress : public sockaddr_storage
|
|||
break;
|
||||
case AF_INET6: {
|
||||
const uint8_t *ip = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr);
|
||||
h = ((unsigned long)ip[0]); h <<= 1;
|
||||
h += ((unsigned long)ip[1]); h <<= 1;
|
||||
h += ((unsigned long)ip[2]); h <<= 1;
|
||||
h += ((unsigned long)ip[3]); h <<= 1;
|
||||
h += ((unsigned long)ip[4]); h <<= 1;
|
||||
h = ((unsigned long)ip[0]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[1]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[2]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[3]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[4]);
|
||||
h <<= 1;
|
||||
h += ((unsigned long)ip[5]);
|
||||
} break;
|
||||
}
|
||||
|
@ -570,13 +583,17 @@ struct InetAddress : public sockaddr_storage
|
|||
return (unsigned int)(b.template at<uint16_t>(p) + 3); // other addresses begin with 16-bit non-inclusive length
|
||||
case 0x04:
|
||||
ss_family = AF_INET;
|
||||
memcpy(&(reinterpret_cast<struct sockaddr_in *>(this)->sin_addr.s_addr),b.field(p,4),4); p += 4;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p)); p += 2;
|
||||
memcpy(&(reinterpret_cast<struct sockaddr_in *>(this)->sin_addr.s_addr),b.field(p,4),4);
|
||||
p += 4;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p));
|
||||
p += 2;
|
||||
break;
|
||||
case 0x06:
|
||||
ss_family = AF_INET6;
|
||||
memcpy(reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,b.field(p,16),16); p += 16;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p)); p += 2;
|
||||
memcpy(reinterpret_cast<struct sockaddr_in6 *>(this)->sin6_addr.s6_addr,b.field(p,16),16);
|
||||
p += 16;
|
||||
reinterpret_cast<struct sockaddr_in *>(this)->sin_port = Utils::hton(b.template at<uint16_t>(p));
|
||||
p += 2;
|
||||
break;
|
||||
default:
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_BAD_ENCODING;
|
||||
|
|
15
node/MAC.hpp
15
node/MAC.hpp
|
@ -71,11 +71,16 @@ public:
|
|||
return;
|
||||
}
|
||||
const unsigned char *b = (const unsigned char *)bits;
|
||||
_m = ((((uint64_t)*b) & 0xff) << 40); ++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 32); ++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 24); ++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 16); ++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 8); ++b;
|
||||
_m = ((((uint64_t)*b) & 0xff) << 40);
|
||||
++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 32);
|
||||
++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 24);
|
||||
++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 16);
|
||||
++b;
|
||||
_m |= ((((uint64_t)*b) & 0xff) << 8);
|
||||
++b;
|
||||
_m |= (((uint64_t)*b) & 0xff);
|
||||
}
|
||||
|
||||
|
|
|
@ -560,7 +560,8 @@ Network::Network(const RuntimeEnvironment *renv,void *tPtr,uint64_t nwid,void *u
|
|||
_lastConfigUpdate = 0; // still want to re-request since it's likely outdated
|
||||
} else {
|
||||
uint64_t tmp[2];
|
||||
tmp[0] = nwid; tmp[1] = 0;
|
||||
tmp[0] = nwid;
|
||||
tmp[1] = 0;
|
||||
|
||||
bool got = false;
|
||||
Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> *dict = new Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY>();
|
||||
|
@ -871,8 +872,10 @@ uint64_t Network::handleConfigChunk(void *tPtr,const uint64_t packetId,const Add
|
|||
const unsigned int start = ptr;
|
||||
|
||||
ptr += 8; // skip network ID, which is already obviously known
|
||||
const unsigned int chunkLen = chunk.at<uint16_t>(ptr); ptr += 2;
|
||||
const void *chunkData = chunk.field(ptr,chunkLen); ptr += chunkLen;
|
||||
const unsigned int chunkLen = chunk.at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
const void *chunkData = chunk.field(ptr,chunkLen);
|
||||
ptr += chunkLen;
|
||||
|
||||
NetworkConfig *nc = (NetworkConfig *)0;
|
||||
uint64_t configUpdateId;
|
||||
|
@ -884,9 +887,12 @@ uint64_t Network::handleConfigChunk(void *tPtr,const uint64_t packetId,const Add
|
|||
unsigned long totalLength,chunkIndex;
|
||||
if (ptr < chunk.size()) {
|
||||
const bool fastPropagate = ((chunk[ptr++] & 0x01) != 0);
|
||||
configUpdateId = chunk.at<uint64_t>(ptr); ptr += 8;
|
||||
totalLength = chunk.at<uint32_t>(ptr); ptr += 4;
|
||||
chunkIndex = chunk.at<uint32_t>(ptr); ptr += 4;
|
||||
configUpdateId = chunk.at<uint64_t>(ptr);
|
||||
ptr += 8;
|
||||
totalLength = chunk.at<uint32_t>(ptr);
|
||||
ptr += 4;
|
||||
chunkIndex = chunk.at<uint32_t>(ptr);
|
||||
ptr += 4;
|
||||
|
||||
if (((chunkIndex + chunkLen) > totalLength)||(totalLength >= ZT_NETWORKCONFIG_DICT_CAPACITY)) // >= since we need room for a null at the end
|
||||
return 0;
|
||||
|
@ -1029,7 +1035,8 @@ int Network::setConfiguration(void *tPtr,const NetworkConfig &nconf,bool saveToD
|
|||
try {
|
||||
if (nconf.toDictionary(*d,false)) {
|
||||
uint64_t tmp[2];
|
||||
tmp[0] = _id; tmp[1] = 0;
|
||||
tmp[0] = _id;
|
||||
tmp[1] = 0;
|
||||
RR->node->stateObjectPut(tPtr,ZT_STATE_OBJECT_NETWORK_CONFIG,tmp,d->data(),d->sizeBytes());
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
|
|
|
@ -364,8 +364,10 @@ bool NetworkConfig::fromDictionary(const Dictionary<ZT_NETWORKCONFIG_DICT_CAPACI
|
|||
while ((p < tmp->size())&&(routeCount < ZT_MAX_NETWORK_ROUTES)) {
|
||||
p += reinterpret_cast<InetAddress *>(&(this->routes[this->routeCount].target))->deserialize(*tmp,p);
|
||||
p += reinterpret_cast<InetAddress *>(&(this->routes[this->routeCount].via))->deserialize(*tmp,p);
|
||||
this->routes[this->routeCount].flags = tmp->at<uint16_t>(p); p += 2;
|
||||
this->routes[this->routeCount].metric = tmp->at<uint16_t>(p); p += 2;
|
||||
this->routes[this->routeCount].flags = tmp->at<uint16_t>(p);
|
||||
p += 2;
|
||||
this->routes[this->routeCount].metric = tmp->at<uint16_t>(p);
|
||||
p += 2;
|
||||
++this->routeCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,8 @@ Node::Node(void *uptr,void *tptr,const struct ZT_Node_Callbacks *callbacks,int64
|
|||
memset((void *)(&_stats),0,sizeof(_stats));
|
||||
|
||||
uint64_t idtmp[2];
|
||||
idtmp[0] = 0; idtmp[1] = 0;
|
||||
idtmp[0] = 0;
|
||||
idtmp[1] = 0;
|
||||
char tmp[2048];
|
||||
int n = stateObjectGet(tptr,ZT_STATE_OBJECT_IDENTITY_SECRET,idtmp,tmp,sizeof(tmp) - 1);
|
||||
if (n > 0) {
|
||||
|
@ -86,11 +87,13 @@ Node::Node(void *uptr,void *tptr,const struct ZT_Node_Callbacks *callbacks,int64
|
|||
RR->identity.generate();
|
||||
RR->identity.toString(false,RR->publicIdentityStr);
|
||||
RR->identity.toString(true,RR->secretIdentityStr);
|
||||
idtmp[0] = RR->identity.address().toInt(); idtmp[1] = 0;
|
||||
idtmp[0] = RR->identity.address().toInt();
|
||||
idtmp[1] = 0;
|
||||
stateObjectPut(tptr,ZT_STATE_OBJECT_IDENTITY_SECRET,idtmp,RR->secretIdentityStr,(unsigned int)strlen(RR->secretIdentityStr));
|
||||
stateObjectPut(tptr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,RR->publicIdentityStr,(unsigned int)strlen(RR->publicIdentityStr));
|
||||
} else {
|
||||
idtmp[0] = RR->identity.address().toInt(); idtmp[1] = 0;
|
||||
idtmp[0] = RR->identity.address().toInt();
|
||||
idtmp[1] = 0;
|
||||
n = stateObjectGet(tptr,ZT_STATE_OBJECT_IDENTITY_PUBLIC,idtmp,tmp,sizeof(tmp) - 1);
|
||||
if ((n > 0)&&(n < (int)sizeof(RR->publicIdentityStr))&&(n < (int)sizeof(tmp))) {
|
||||
if (memcmp(tmp,RR->publicIdentityStr,n))
|
||||
|
@ -427,7 +430,8 @@ ZT_ResultCode Node::leave(uint64_t nwid,void **uptr,void *tptr)
|
|||
}
|
||||
|
||||
uint64_t tmp[2];
|
||||
tmp[0] = nwid; tmp[1] = 0;
|
||||
tmp[0] = nwid;
|
||||
tmp[1] = 0;
|
||||
RR->node->stateObjectDelete(tptr,ZT_STATE_OBJECT_NETWORK_CONFIG,tmp);
|
||||
|
||||
return ZT_RESULT_OK;
|
||||
|
@ -773,7 +777,8 @@ void Node::ncSendError(uint64_t nwid,uint64_t requestPacketId,const Address &des
|
|||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (requestPacketId) {
|
||||
Packet outp(destination,RR->identity.address(),Packet::VERB_ERROR);
|
||||
|
|
121
node/Packet.cpp
121
node/Packet.cpp
|
@ -295,7 +295,11 @@ static inline void LZ4_wildCopy(void* dstPtr, const void* srcPtr, void* dstEnd)
|
|||
BYTE* d = (BYTE*)dstPtr;
|
||||
const BYTE* s = (const BYTE*)srcPtr;
|
||||
BYTE* const e = (BYTE*)dstEnd;
|
||||
do { LZ4_copy8(d,s); d+=8; s+=8; } while (d<e);
|
||||
do {
|
||||
LZ4_copy8(d,s);
|
||||
d+=8;
|
||||
s+=8;
|
||||
} while (d<e);
|
||||
}
|
||||
|
||||
#define MINMATCH 4
|
||||
|
@ -355,8 +359,18 @@ static inline unsigned LZ4_NbCommonBytes (reg_t val)
|
|||
return (__builtin_clzll((U64)val) >> 3);
|
||||
# else
|
||||
unsigned r;
|
||||
if (!(val>>32)) { r=4; } else { r=0; val>>=32; }
|
||||
if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }
|
||||
if (!(val>>32)) {
|
||||
r=4;
|
||||
} else {
|
||||
r=0;
|
||||
val>>=32;
|
||||
}
|
||||
if (!(val>>16)) {
|
||||
r+=2;
|
||||
val>>=8;
|
||||
} else {
|
||||
val>>=24;
|
||||
}
|
||||
r += (!val);
|
||||
return r;
|
||||
# endif
|
||||
|
@ -369,7 +383,13 @@ static inline unsigned LZ4_NbCommonBytes (reg_t val)
|
|||
return (__builtin_clz((U32)val) >> 3);
|
||||
# else
|
||||
unsigned r;
|
||||
if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
|
||||
if (!(val>>16)) {
|
||||
r=2;
|
||||
val>>=8;
|
||||
} else {
|
||||
r=0;
|
||||
val>>=24;
|
||||
}
|
||||
r += (!val);
|
||||
return r;
|
||||
# endif
|
||||
|
@ -384,13 +404,20 @@ static inline unsigned LZ4_count(const BYTE* pIn, const BYTE* pMatch, const BYTE
|
|||
|
||||
while (likely(pIn<pInLimit-(STEPSIZE-1))) {
|
||||
reg_t const diff = LZ4_read_ARCH(pMatch) ^ LZ4_read_ARCH(pIn);
|
||||
if (!diff) { pIn+=STEPSIZE; pMatch+=STEPSIZE; continue; }
|
||||
if (!diff) {
|
||||
pIn+=STEPSIZE;
|
||||
pMatch+=STEPSIZE; continue;
|
||||
}
|
||||
pIn += LZ4_NbCommonBytes(diff);
|
||||
return (unsigned)(pIn - pStart);
|
||||
}
|
||||
|
||||
if ((STEPSIZE==8) && (pIn<(pInLimit-3)) && (LZ4_read32(pMatch) == LZ4_read32(pIn))) { pIn+=4; pMatch+=4; }
|
||||
if ((pIn<(pInLimit-1)) && (LZ4_read16(pMatch) == LZ4_read16(pIn))) { pIn+=2; pMatch+=2; }
|
||||
if ((STEPSIZE==8) && (pIn<(pInLimit-3)) && (LZ4_read32(pMatch) == LZ4_read32(pIn))) {
|
||||
pIn+=4; pMatch+=4;
|
||||
}
|
||||
if ((pIn<(pInLimit-1)) && (LZ4_read16(pMatch) == LZ4_read16(pIn))) {
|
||||
pIn+=2; pMatch+=2;
|
||||
}
|
||||
if ((pIn<pInLimit) && (*pMatch == *pIn)) pIn++;
|
||||
return (unsigned)(pIn - pStart);
|
||||
}
|
||||
|
@ -436,11 +463,19 @@ FORCE_INLINE U32 LZ4_hashPosition(const void* const p, tableType_t const tableTy
|
|||
|
||||
static inline void LZ4_putPositionOnHash(const BYTE* p, U32 h, void* tableBase, tableType_t const tableType, const BYTE* srcBase)
|
||||
{
|
||||
switch (tableType)
|
||||
{
|
||||
case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; }
|
||||
case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; }
|
||||
case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; }
|
||||
switch (tableType) {
|
||||
case byPtr: {
|
||||
const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p;
|
||||
return;
|
||||
}
|
||||
case byU32: {
|
||||
U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase);
|
||||
return;
|
||||
}
|
||||
case byU16: {
|
||||
U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -452,9 +487,18 @@ FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t ta
|
|||
|
||||
static inline const BYTE* LZ4_getPositionOnHash(U32 h, void* tableBase, tableType_t tableType, const BYTE* srcBase)
|
||||
{
|
||||
if (tableType == byPtr) { const BYTE** hashTable = (const BYTE**) tableBase; return hashTable[h]; }
|
||||
if (tableType == byU32) { const U32* const hashTable = (U32*) tableBase; return hashTable[h] + srcBase; }
|
||||
{ const U16* const hashTable = (U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */
|
||||
if (tableType == byPtr) {
|
||||
const BYTE** hashTable = (const BYTE**) tableBase;
|
||||
return hashTable[h];
|
||||
}
|
||||
if (tableType == byU32) {
|
||||
const U32* const hashTable = (U32*) tableBase;
|
||||
return hashTable[h] + srcBase;
|
||||
}
|
||||
{ /* default, to ensure a return */
|
||||
const U16* const hashTable = (U16*) tableBase;
|
||||
return hashTable[h] + srcBase;
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE const BYTE* LZ4_getPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
|
||||
|
@ -494,8 +538,7 @@ FORCE_INLINE int LZ4_compress_generic(
|
|||
|
||||
/* Init conditions */
|
||||
if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) return 0; /* Unsupported inputSize, too large (or negative) */
|
||||
switch(dict)
|
||||
{
|
||||
switch(dict) {
|
||||
case noDict:
|
||||
default:
|
||||
base = (const BYTE*)source;
|
||||
|
@ -515,7 +558,8 @@ FORCE_INLINE int LZ4_compress_generic(
|
|||
|
||||
/* First Byte */
|
||||
LZ4_putPosition(ip, cctx->hashTable, tableType, base);
|
||||
ip++; forwardH = LZ4_hashPosition(ip, tableType);
|
||||
ip++;
|
||||
forwardH = LZ4_hashPosition(ip, tableType);
|
||||
|
||||
/* Main Loop */
|
||||
for ( ; ; ) {
|
||||
|
@ -524,7 +568,8 @@ FORCE_INLINE int LZ4_compress_generic(
|
|||
BYTE* token;
|
||||
|
||||
/* Find a match */
|
||||
{ const BYTE* forwardIp = ip;
|
||||
{
|
||||
const BYTE* forwardIp = ip;
|
||||
unsigned step = 1;
|
||||
unsigned searchMatchNb = acceleration << LZ4_skipTrigger;
|
||||
do {
|
||||
|
@ -554,10 +599,14 @@ FORCE_INLINE int LZ4_compress_generic(
|
|||
}
|
||||
|
||||
/* Catch up */
|
||||
while (((ip>anchor) & (match+refDelta > lowLimit)) && (unlikely(ip[-1]==match[refDelta-1]))) { ip--; match--; }
|
||||
while (((ip>anchor) & (match+refDelta > lowLimit)) && (unlikely(ip[-1]==match[refDelta-1]))) {
|
||||
ip--;
|
||||
match--;
|
||||
}
|
||||
|
||||
/* Encode Literals */
|
||||
{ unsigned const litLength = (unsigned)(ip - anchor);
|
||||
{
|
||||
unsigned const litLength = (unsigned)(ip - anchor);
|
||||
token = op++;
|
||||
if ((outputLimited) && /* Check output buffer overflow */
|
||||
(unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit)))
|
||||
|
@ -577,10 +626,12 @@ FORCE_INLINE int LZ4_compress_generic(
|
|||
|
||||
_next_match:
|
||||
/* Encode Offset */
|
||||
LZ4_writeLE16(op, (U16)(ip-match)); op+=2;
|
||||
LZ4_writeLE16(op, (U16)(ip-match));
|
||||
op+=2;
|
||||
|
||||
/* Encode MatchLength */
|
||||
{ unsigned matchCode;
|
||||
{
|
||||
unsigned matchCode;
|
||||
|
||||
if ((dict==usingExtDict) && (lowLimit==dictionary)) {
|
||||
const BYTE* limit;
|
||||
|
@ -639,8 +690,11 @@ _next_match:
|
|||
LZ4_putPosition(ip, cctx->hashTable, tableType, base);
|
||||
if ( ((dictIssue==dictSmall) ? (match>=lowRefLimit) : 1)
|
||||
&& (match+MAX_DISTANCE>=ip)
|
||||
&& (LZ4_read32(match+refDelta)==LZ4_read32(ip)) )
|
||||
{ token=op++; *token=0; goto _next_match; }
|
||||
&& (LZ4_read32(match+refDelta)==LZ4_read32(ip)) ) {
|
||||
token=op++;
|
||||
*token=0;
|
||||
goto _next_match;
|
||||
}
|
||||
|
||||
/* Prepare next loop */
|
||||
forwardH = LZ4_hashPosition(++ip, tableType);
|
||||
|
@ -648,7 +702,8 @@ _next_match:
|
|||
|
||||
_last_literals:
|
||||
/* Encode Last Literals */
|
||||
{ size_t const lastRun = (size_t)(iend - anchor);
|
||||
{
|
||||
size_t const lastRun = (size_t)(iend - anchor);
|
||||
if ( (outputLimited) && /* Check output buffer overflow */
|
||||
((op - (BYTE*)dest) + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > (U32)maxOutputSize) )
|
||||
return 0;
|
||||
|
@ -768,8 +823,7 @@ FORCE_INLINE int LZ4_decompress_generic(
|
|||
/* copy literals */
|
||||
cpy = op+length;
|
||||
if ( ((endOnInput) && ((cpy>(partialDecoding?oexit:oend-MFLIMIT)) || (ip+length>iend-(2+1+LASTLITERALS))) )
|
||||
|| ((!endOnInput) && (cpy>oend-WILDCOPYLENGTH)) )
|
||||
{
|
||||
|| ((!endOnInput) && (cpy>oend-WILDCOPYLENGTH)) ) {
|
||||
if (partialDecoding) {
|
||||
if (cpy > oend) goto _output_error; /* Error : write attempt beyond end of output buffer */
|
||||
if ((endOnInput) && (ip+length > iend)) goto _output_error; /* Error : read attempt beyond end of input buffer */
|
||||
|
@ -783,10 +837,12 @@ FORCE_INLINE int LZ4_decompress_generic(
|
|||
break; /* Necessarily EOF, due to parsing restrictions */
|
||||
}
|
||||
LZ4_wildCopy(op, ip, cpy);
|
||||
ip += length; op = cpy;
|
||||
ip += length;
|
||||
op = cpy;
|
||||
|
||||
/* get offset */
|
||||
offset = LZ4_readLE16(ip); ip+=2;
|
||||
offset = LZ4_readLE16(ip);
|
||||
ip += 2;
|
||||
match = op - offset;
|
||||
if ((checkOffset) && (unlikely(match < lowLimit))) goto _output_error; /* Error : offset outside buffers */
|
||||
LZ4_write32(op, (U32)offset); /* costs ~1%; silence an msan warning when offset==0 */
|
||||
|
@ -841,7 +897,10 @@ FORCE_INLINE int LZ4_decompress_generic(
|
|||
match += dec32table[offset];
|
||||
memcpy(op+4, match, 4);
|
||||
match -= dec64;
|
||||
} else { LZ4_copy8(op, match); match+=8; }
|
||||
} else {
|
||||
LZ4_copy8(op, match);
|
||||
match+=8;
|
||||
}
|
||||
op += 8;
|
||||
|
||||
if (unlikely(cpy>oend-12)) {
|
||||
|
|
|
@ -165,8 +165,7 @@ public:
|
|||
unsigned int pl = _latency;
|
||||
if (pl < 0xffff) {
|
||||
_latency = (pl + l) / 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_latency = l;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,8 +146,7 @@ void Peer::received(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
replacePath = i;
|
||||
break;
|
||||
}
|
||||
|
@ -518,8 +517,7 @@ unsigned int Peer::doPingAndKeepalive(void *tPtr,int64_t now)
|
|||
for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
|
||||
if (_paths[i].p) {
|
||||
maxPriority = std::max(_paths[i].priority,maxPriority);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -534,8 +532,7 @@ unsigned int Peer::doPingAndKeepalive(void *tPtr,int64_t now)
|
|||
_paths[i].p->sent(now);
|
||||
sent |= (_paths[i].p->address().ss_family == AF_INET) ? 0x1 : 0x2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_paths[i] = _PeerPath();
|
||||
deletionOccurred = true;
|
||||
}
|
||||
|
|
|
@ -469,15 +469,20 @@ public:
|
|||
|
||||
SharedPtr<Peer> p(new Peer(renv,renv->identity,id));
|
||||
|
||||
p->_vProto = b.template at<uint16_t>(ptr); ptr += 2;
|
||||
p->_vMajor = b.template at<uint16_t>(ptr); ptr += 2;
|
||||
p->_vMinor = b.template at<uint16_t>(ptr); ptr += 2;
|
||||
p->_vRevision = b.template at<uint16_t>(ptr); ptr += 2;
|
||||
p->_vProto = b.template at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
p->_vMajor = b.template at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
p->_vMinor = b.template at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
p->_vRevision = b.template at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
|
||||
// When we deserialize from the cache we don't actually restore paths. We
|
||||
// just try them and then re-learn them if they happen to still be up.
|
||||
// Paths are fairly ephemeral in the real world in most cases.
|
||||
const unsigned int tryPathCount = b.template at<uint16_t>(ptr); ptr += 2;
|
||||
const unsigned int tryPathCount = b.template at<uint16_t>(ptr);
|
||||
ptr += 2;
|
||||
for(unsigned int i=0;i<tryPathCount;++i) {
|
||||
InetAddress inaddr;
|
||||
try {
|
||||
|
|
|
@ -151,14 +151,21 @@ public:
|
|||
unsigned int p = startAt;
|
||||
|
||||
p += 4; // 4 bytes, currently unused
|
||||
_id = b.template at<uint32_t>(p); p += 4;
|
||||
_networkId = b.template at<uint64_t>(p); p += 8;
|
||||
_id = b.template at<uint32_t>(p);
|
||||
p += 4;
|
||||
_networkId = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
p += 4; // 4 bytes, currently unused
|
||||
_credentialId = b.template at<uint32_t>(p); p += 4;
|
||||
_threshold = (int64_t)b.template at<uint64_t>(p); p += 8;
|
||||
_flags = b.template at<uint64_t>(p); p += 8;
|
||||
_target.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_credentialId = b.template at<uint32_t>(p);
|
||||
p += 4;
|
||||
_threshold = (int64_t)b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_flags = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_target.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
_type = (Credential::Type)b[p++];
|
||||
|
||||
if (b[p++] == 1) {
|
||||
|
|
|
@ -193,11 +193,9 @@ public:
|
|||
{
|
||||
if (end == begin) {
|
||||
return wrap ? S : 0;
|
||||
}
|
||||
else if (end > begin) {
|
||||
} else if (end > begin) {
|
||||
return end - begin;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return S + end - begin;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,23 +432,45 @@ void Switch::onLocalEthernet(void *tPtr,const SharedPtr<Network> &network,const
|
|||
const MAC peerMac(v6EmbeddedAddress,network->id());
|
||||
|
||||
uint8_t adv[72];
|
||||
adv[0] = 0x60; adv[1] = 0x00; adv[2] = 0x00; adv[3] = 0x00;
|
||||
adv[4] = 0x00; adv[5] = 0x20;
|
||||
adv[6] = 0x3a; adv[7] = 0xff;
|
||||
adv[0] = 0x60;
|
||||
adv[1] = 0x00;
|
||||
adv[2] = 0x00;
|
||||
adv[3] = 0x00;
|
||||
adv[4] = 0x00;
|
||||
adv[5] = 0x20;
|
||||
adv[6] = 0x3a;
|
||||
adv[7] = 0xff;
|
||||
for(int i=0;i<16;++i) adv[8 + i] = pkt6[i];
|
||||
for(int i=0;i<16;++i) adv[24 + i] = my6[i];
|
||||
adv[40] = 0x88; adv[41] = 0x00;
|
||||
adv[42] = 0x00; adv[43] = 0x00; // future home of checksum
|
||||
adv[44] = 0x60; adv[45] = 0x00; adv[46] = 0x00; adv[47] = 0x00;
|
||||
adv[40] = 0x88;
|
||||
adv[41] = 0x00;
|
||||
adv[42] = 0x00;
|
||||
adv[43] = 0x00; // future home of checksum
|
||||
adv[44] = 0x60;
|
||||
adv[45] = 0x00;
|
||||
adv[46] = 0x00;
|
||||
adv[47] = 0x00;
|
||||
for(int i=0;i<16;++i) adv[48 + i] = pkt6[i];
|
||||
adv[64] = 0x02; adv[65] = 0x01;
|
||||
adv[66] = peerMac[0]; adv[67] = peerMac[1]; adv[68] = peerMac[2]; adv[69] = peerMac[3]; adv[70] = peerMac[4]; adv[71] = peerMac[5];
|
||||
adv[64] = 0x02;
|
||||
adv[65] = 0x01;
|
||||
adv[66] = peerMac[0];
|
||||
adv[67] = peerMac[1];
|
||||
adv[68] = peerMac[2];
|
||||
adv[69] = peerMac[3];
|
||||
adv[70] = peerMac[4];
|
||||
adv[71] = peerMac[5];
|
||||
|
||||
uint16_t pseudo_[36];
|
||||
uint8_t *const pseudo = reinterpret_cast<uint8_t *>(pseudo_);
|
||||
for(int i=0;i<32;++i) pseudo[i] = adv[8 + i];
|
||||
pseudo[32] = 0x00; pseudo[33] = 0x00; pseudo[34] = 0x00; pseudo[35] = 0x20;
|
||||
pseudo[36] = 0x00; pseudo[37] = 0x00; pseudo[38] = 0x00; pseudo[39] = 0x3a;
|
||||
pseudo[32] = 0x00;
|
||||
pseudo[33] = 0x00;
|
||||
pseudo[34] = 0x00;
|
||||
pseudo[35] = 0x20;
|
||||
pseudo[36] = 0x00;
|
||||
pseudo[37] = 0x00;
|
||||
pseudo[38] = 0x00;
|
||||
pseudo[39] = 0x3a;
|
||||
for(int i=0;i<32;++i) pseudo[40 + i] = adv[40 + i];
|
||||
uint32_t checksum = 0;
|
||||
for(int i=0;i<36;++i) checksum += Utils::hton(pseudo_[i]);
|
||||
|
@ -627,11 +649,13 @@ void Switch::aqm_enqueue(void *tPtr, const SharedPtr<Network> &network, Packet &
|
|||
if (nqcb->oldQueues[i]->id == qosBucket) {
|
||||
selectedQueue = nqcb->oldQueues[i];
|
||||
}
|
||||
} if (i < nqcb->newQueues.size()) { // search new queues (this would imply not often-used queues)
|
||||
}
|
||||
if (i < nqcb->newQueues.size()) { // search new queues (this would imply not often-used queues)
|
||||
if (nqcb->newQueues[i]->id == qosBucket) {
|
||||
selectedQueue = nqcb->newQueues[i];
|
||||
}
|
||||
} if (i < nqcb->inactiveQueues.size()) { // search inactive queues
|
||||
}
|
||||
if (i < nqcb->inactiveQueues.size()) { // search inactive queues
|
||||
if (nqcb->inactiveQueues[i]->id == qosBucket) {
|
||||
selectedQueue = nqcb->inactiveQueues[i];
|
||||
// move queue to end of NEW queue list
|
||||
|
@ -655,8 +679,7 @@ void Switch::aqm_enqueue(void *tPtr, const SharedPtr<Network> &network, Packet &
|
|||
|
||||
// Drop a packet if necessary
|
||||
ManagedQueue *selectedQueueToDropFrom = nullptr;
|
||||
if (nqcb->_currEnqueuedPackets > ZT_AQM_MAX_ENQUEUED_PACKETS)
|
||||
{
|
||||
if (nqcb->_currEnqueuedPackets > ZT_AQM_MAX_ENQUEUED_PACKETS) {
|
||||
// DEBUG_INFO("too many enqueued packets (%d), finding packet to drop", nqcb->_currEnqueuedPackets);
|
||||
int maxQueueLength = 0;
|
||||
for (size_t i=0; i<ZT_AQM_NUM_BUCKETS; i++) {
|
||||
|
@ -665,12 +688,14 @@ void Switch::aqm_enqueue(void *tPtr, const SharedPtr<Network> &network, Packet &
|
|||
maxQueueLength = nqcb->oldQueues[i]->byteLength;
|
||||
selectedQueueToDropFrom = nqcb->oldQueues[i];
|
||||
}
|
||||
} if (i < nqcb->newQueues.size()) {
|
||||
}
|
||||
if (i < nqcb->newQueues.size()) {
|
||||
if (nqcb->newQueues[i]->byteLength > maxQueueLength) {
|
||||
maxQueueLength = nqcb->newQueues[i]->byteLength;
|
||||
selectedQueueToDropFrom = nqcb->newQueues[i];
|
||||
}
|
||||
} if (i < nqcb->inactiveQueues.size()) {
|
||||
}
|
||||
if (i < nqcb->inactiveQueues.size()) {
|
||||
if (nqcb->inactiveQueues[i]->byteLength > maxQueueLength) {
|
||||
maxQueueLength = nqcb->inactiveQueues[i]->byteLength;
|
||||
selectedQueueToDropFrom = nqcb->inactiveQueues[i];
|
||||
|
@ -785,8 +810,7 @@ void Switch::aqm_dequeue(void *tPtr)
|
|||
// DEBUG_INFO("moving q=%p from NEW to OLD list", queueAtFrontOfList);
|
||||
oldQueues->push_back(queueAtFrontOfList);
|
||||
currQueues->erase(currQueues->begin());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int len = entryToEmit->packet.payloadLength();
|
||||
queueAtFrontOfList->byteLength -= len;
|
||||
queueAtFrontOfList->byteCredit -= len;
|
||||
|
@ -818,8 +842,7 @@ void Switch::aqm_dequeue(void *tPtr)
|
|||
// Move to inactive list of queues
|
||||
inactiveQueues->push_back(queueAtFrontOfList);
|
||||
currQueues->erase(currQueues->begin());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
int len = entryToEmit->packet.payloadLength();
|
||||
queueAtFrontOfList->byteLength -= len;
|
||||
queueAtFrontOfList->byteCredit -= len;
|
||||
|
@ -1018,8 +1041,7 @@ bool Switch::_trySend(void *tPtr,Packet &packet,bool encrypt,int32_t flowId)
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
viaPath = peer->getAppropriatePath(now,false,flowId);
|
||||
if (!viaPath) {
|
||||
peer->tryMemorizedPath(tPtr,now); // periodically attempt memorized or statically defined paths, if any are known
|
||||
|
|
21
node/Tag.hpp
21
node/Tag.hpp
|
@ -143,19 +143,26 @@ public:
|
|||
|
||||
*this = Tag();
|
||||
|
||||
_networkId = b.template at<uint64_t>(p); p += 8;
|
||||
_ts = b.template at<uint64_t>(p); p += 8;
|
||||
_id = b.template at<uint32_t>(p); p += 4;
|
||||
_networkId = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_ts = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_id = b.template at<uint32_t>(p);
|
||||
p += 4;
|
||||
|
||||
_value = b.template at<uint32_t>(p); p += 4;
|
||||
_value = b.template at<uint32_t>(p);
|
||||
p += 4;
|
||||
|
||||
_issuedTo.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); p += ZT_ADDRESS_LENGTH;
|
||||
_issuedTo.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
_signedBy.setTo(b.field(p,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH);
|
||||
p += ZT_ADDRESS_LENGTH;
|
||||
if (b[p++] == 1) {
|
||||
if (b.template at<uint16_t>(p) != ZT_C25519_SIGNATURE_LEN)
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_CRYPTOGRAPHIC_TOKEN;
|
||||
p += 2;
|
||||
memcpy(_signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN); p += ZT_C25519_SIGNATURE_LEN;
|
||||
memcpy(_signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN);
|
||||
p += ZT_C25519_SIGNATURE_LEN;
|
||||
} else {
|
||||
p += 2 + b.template at<uint16_t>(p);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ Topology::Topology(const RuntimeEnvironment *renv,void *tPtr) :
|
|||
{
|
||||
uint8_t tmp[ZT_WORLD_MAX_SERIALIZED_LENGTH];
|
||||
uint64_t idtmp[2];
|
||||
idtmp[0] = 0; idtmp[1] = 0;
|
||||
idtmp[0] = 0;
|
||||
idtmp[1] = 0;
|
||||
int n = RR->node->stateObjectGet(tPtr,ZT_STATE_OBJECT_PLANET,idtmp,tmp,sizeof(tmp));
|
||||
if (n > 0) {
|
||||
try {
|
||||
|
@ -86,7 +87,9 @@ SharedPtr<Peer> Topology::getPeer(void *tPtr,const Address &zta)
|
|||
|
||||
try {
|
||||
Buffer<ZT_PEER_MAX_SERIALIZED_STATE_SIZE> buf;
|
||||
uint64_t idbuf[2]; idbuf[0] = zta.toInt(); idbuf[1] = 0;
|
||||
uint64_t idbuf[2];
|
||||
idbuf[0] = zta.toInt();
|
||||
idbuf[1] = 0;
|
||||
int len = RR->node->stateObjectGet(tPtr,ZT_STATE_OBJECT_PEER,idbuf,buf.unsafeData(),ZT_PEER_MAX_SERIALIZED_STATE_SIZE);
|
||||
if (len > 0) {
|
||||
buf.setSize(len);
|
||||
|
@ -268,7 +271,8 @@ bool Topology::addWorld(void *tPtr,const World &newWorld,bool alwaysAcceptNew)
|
|||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> sbuf;
|
||||
existing->serialize(sbuf,false);
|
||||
uint64_t idtmp[2];
|
||||
idtmp[0] = existing->id(); idtmp[1] = 0;
|
||||
idtmp[0] = existing->id();
|
||||
idtmp[1] = 0;
|
||||
RR->node->stateObjectPut(tPtr,(existing->type() == World::TYPE_PLANET) ? ZT_STATE_OBJECT_PLANET : ZT_STATE_OBJECT_MOON,idtmp,sbuf.data(),sbuf.size());
|
||||
} catch ( ... ) {}
|
||||
|
||||
|
@ -281,7 +285,8 @@ void Topology::addMoon(void *tPtr,const uint64_t id,const Address &seed)
|
|||
{
|
||||
char tmp[ZT_WORLD_MAX_SERIALIZED_LENGTH];
|
||||
uint64_t idtmp[2];
|
||||
idtmp[0] = id; idtmp[1] = 0;
|
||||
idtmp[0] = id;
|
||||
idtmp[1] = 0;
|
||||
int n = RR->node->stateObjectGet(tPtr,ZT_STATE_OBJECT_MOON,idtmp,tmp,sizeof(tmp));
|
||||
if (n > 0) {
|
||||
try {
|
||||
|
@ -312,7 +317,8 @@ void Topology::removeMoon(void *tPtr,const uint64_t id)
|
|||
nm.push_back(*m);
|
||||
} else {
|
||||
uint64_t idtmp[2];
|
||||
idtmp[0] = id; idtmp[1] = 0;
|
||||
idtmp[0] = id;
|
||||
idtmp[1] = 0;
|
||||
RR->node->stateObjectDelete(tPtr,ZT_STATE_OBJECT_MOON,idtmp);
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +402,9 @@ void Topology::_savePeer(void *tPtr,const SharedPtr<Peer> &peer)
|
|||
try {
|
||||
Buffer<ZT_PEER_MAX_SERIALIZED_STATE_SIZE> buf;
|
||||
peer->serializeForCache(buf);
|
||||
uint64_t tmpid[2]; tmpid[0] = peer->address().toInt(); tmpid[1] = 0;
|
||||
uint64_t tmpid[2];
|
||||
tmpid[0] = peer->address().toInt();
|
||||
tmpid[1] = 0;
|
||||
RR->node->stateObjectPut(tPtr,ZT_STATE_OBJECT_PEER,tmpid,buf.data(),buf.size());
|
||||
} catch ( ... ) {} // sanity check, discard invalid entries
|
||||
}
|
||||
|
|
|
@ -72,7 +72,10 @@ void Trace::peerConfirmingUnknownPath(void *const tPtr,const uint64_t networkId,
|
|||
ZT_LOCAL_TRACE(tPtr,RR,"trying unknown path %s to %.10llx (packet %.16llx verb %d local socket %lld network %.16llx)",path->address().toString(tmp),peer.address().toInt(),packetId,verb,path->localSocket(),networkId);
|
||||
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (networkId) { Mutex::Lock l(_byNet_m); _byNet.get(networkId,byn); }
|
||||
if (networkId) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(networkId,byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -107,7 +110,10 @@ void Trace::peerLearnedNewPath(void *const tPtr,const uint64_t networkId,Peer &p
|
|||
ZT_LOCAL_TRACE(tPtr,RR,"learned new path %s to %.10llx (packet %.16llx local socket %lld network %.16llx)",newPath->address().toString(tmp),peer.address().toInt(),packetId,newPath->localSocket(),networkId);
|
||||
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (networkId) { Mutex::Lock l(_byNet_m); _byNet.get(networkId,byn); }
|
||||
if (networkId) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(networkId,byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -134,7 +140,10 @@ void Trace::peerRedirected(void *const tPtr,const uint64_t networkId,Peer &peer,
|
|||
ZT_LOCAL_TRACE(tPtr,RR,"explicit redirect from %.10llx to path %s",peer.address().toInt(),newPath->address().toString(tmp));
|
||||
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (networkId) { Mutex::Lock l(_byNet_m); _byNet.get(networkId,byn); }
|
||||
if (networkId) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(networkId,byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -379,7 +388,10 @@ void Trace::networkFilter(
|
|||
void Trace::credentialRejected(void *const tPtr,const CertificateOfMembership &c,const char *reason)
|
||||
{
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (c.networkId()) { Mutex::Lock l(_byNet_m); _byNet.get(c.networkId(),byn); }
|
||||
if (c.networkId()) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(c.networkId(),byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -402,7 +414,10 @@ void Trace::credentialRejected(void *const tPtr,const CertificateOfMembership &c
|
|||
void Trace::credentialRejected(void *const tPtr,const CertificateOfOwnership &c,const char *reason)
|
||||
{
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (c.networkId()) { Mutex::Lock l(_byNet_m); _byNet.get(c.networkId(),byn); }
|
||||
if (c.networkId()) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(c.networkId(),byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -425,7 +440,10 @@ void Trace::credentialRejected(void *const tPtr,const CertificateOfOwnership &c,
|
|||
void Trace::credentialRejected(void *const tPtr,const Capability &c,const char *reason)
|
||||
{
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (c.networkId()) { Mutex::Lock l(_byNet_m); _byNet.get(c.networkId(),byn); }
|
||||
if (c.networkId()) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(c.networkId(),byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -448,7 +466,10 @@ void Trace::credentialRejected(void *const tPtr,const Capability &c,const char *
|
|||
void Trace::credentialRejected(void *const tPtr,const Tag &c,const char *reason)
|
||||
{
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (c.networkId()) { Mutex::Lock l(_byNet_m); _byNet.get(c.networkId(),byn); }
|
||||
if (c.networkId()) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(c.networkId(),byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
@ -472,7 +493,10 @@ void Trace::credentialRejected(void *const tPtr,const Tag &c,const char *reason)
|
|||
void Trace::credentialRejected(void *const tPtr,const Revocation &c,const char *reason)
|
||||
{
|
||||
std::pair<Address,Trace::Level> byn;
|
||||
if (c.networkId()) { Mutex::Lock l(_byNet_m); _byNet.get(c.networkId(),byn); }
|
||||
if (c.networkId()) {
|
||||
Mutex::Lock l(_byNet_m);
|
||||
_byNet.get(c.networkId(),byn);
|
||||
}
|
||||
|
||||
if ((_globalTarget)||(byn.first)) {
|
||||
Dictionary<ZT_MAX_REMOTE_TRACE_SIZE> d;
|
||||
|
|
|
@ -102,10 +102,17 @@ public:
|
|||
*/
|
||||
static inline unsigned int log2(uint32_t v)
|
||||
{
|
||||
uint32_t r = (v > 0xffff) << 4; v >>= r;
|
||||
uint32_t shift = (v > 0xff) << 3; v >>= shift; r |= shift;
|
||||
shift = (v > 0xf) << 2; v >>= shift; r |= shift;
|
||||
shift = (v > 0x3) << 1; v >>= shift; r |= shift;
|
||||
uint32_t r = (v > 0xffff) << 4;
|
||||
v >>= r;
|
||||
uint32_t shift = (v > 0xff) << 3;
|
||||
v >>= shift;
|
||||
r |= shift;
|
||||
shift = (v > 0xf) << 2;
|
||||
v >>= shift;
|
||||
r |= shift;
|
||||
shift = (v > 0x3) << 1;
|
||||
v >>= shift;
|
||||
r |= shift;
|
||||
r |= (v >> 1);
|
||||
return (unsigned int)r;
|
||||
}
|
||||
|
|
|
@ -195,17 +195,27 @@ public:
|
|||
_roots.clear();
|
||||
|
||||
switch((Type)b[p++]) {
|
||||
case TYPE_NULL: _type = TYPE_NULL; break; // shouldn't ever really happen in serialized data but it's not invalid
|
||||
case TYPE_PLANET: _type = TYPE_PLANET; break;
|
||||
case TYPE_MOON: _type = TYPE_MOON; break;
|
||||
case TYPE_NULL: // shouldn't ever really happen in serialized data but it's not invalid
|
||||
_type = TYPE_NULL;
|
||||
break;
|
||||
case TYPE_PLANET:
|
||||
_type = TYPE_PLANET;
|
||||
break;
|
||||
case TYPE_MOON:
|
||||
_type = TYPE_MOON;
|
||||
break;
|
||||
default:
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_INVALID_TYPE;
|
||||
}
|
||||
|
||||
_id = b.template at<uint64_t>(p); p += 8;
|
||||
_ts = b.template at<uint64_t>(p); p += 8;
|
||||
memcpy(_updatesMustBeSignedBy.data,b.field(p,ZT_C25519_PUBLIC_KEY_LEN),ZT_C25519_PUBLIC_KEY_LEN); p += ZT_C25519_PUBLIC_KEY_LEN;
|
||||
memcpy(_signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN); p += ZT_C25519_SIGNATURE_LEN;
|
||||
_id = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
_ts = b.template at<uint64_t>(p);
|
||||
p += 8;
|
||||
memcpy(_updatesMustBeSignedBy.data,b.field(p,ZT_C25519_PUBLIC_KEY_LEN),ZT_C25519_PUBLIC_KEY_LEN);
|
||||
p += ZT_C25519_PUBLIC_KEY_LEN;
|
||||
memcpy(_signature.data,b.field(p,ZT_C25519_SIGNATURE_LEN),ZT_C25519_SIGNATURE_LEN);
|
||||
p += ZT_C25519_SIGNATURE_LEN;
|
||||
const unsigned int numRoots = (unsigned int)b[p++];
|
||||
if (numRoots > ZT_WORLD_MAX_ROOTS)
|
||||
throw ZT_EXCEPTION_INVALID_SERIALIZED_DATA_OVERFLOW;
|
||||
|
|
Loading…
Add table
Reference in a new issue