mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-03-11 15:04:18 +00:00
Make sure received() gets called for some new messages, and docs.
This commit is contained in:
parent
69b44bf9a5
commit
0ce0bc00d2
@ -573,11 +573,13 @@ bool IncomingPacket::_doEXT_FRAME(const RuntimeEnvironment *RR,const SharedPtr<P
|
|||||||
bool IncomingPacket::_doECHO(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer)
|
bool IncomingPacket::_doECHO(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
const uint64_t pid = packetId();
|
||||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
|
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
|
||||||
outp.append((unsigned char)Packet::VERB_ECHO);
|
outp.append((unsigned char)Packet::VERB_ECHO);
|
||||||
outp.append(packetId());
|
outp.append((uint64_t)pid);
|
||||||
outp.append(field(ZT_PACKET_IDX_PAYLOAD,size() - ZT_PACKET_IDX_PAYLOAD),size() - ZT_PACKET_IDX_PAYLOAD);
|
outp.append(field(ZT_PACKET_IDX_PAYLOAD,size() - ZT_PACKET_IDX_PAYLOAD),size() - ZT_PACKET_IDX_PAYLOAD);
|
||||||
RR->sw->send(outp,true,0);
|
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||||
|
peer->received(RR,_localAddress,_remoteAddress,hops(),pid,Packet::VERB_ECHO,0,Packet::VERB_NOP);
|
||||||
} catch ( ... ) {}
|
} catch ( ... ) {}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -881,6 +883,8 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha
|
|||||||
}
|
}
|
||||||
ptr += addrLen;
|
ptr += addrLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_PUSH_DIRECT_PATHS,0,Packet::VERB_NOP);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
TRACE("dropped PUSH_DIRECT_PATHS from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
TRACE("dropped PUSH_DIRECT_PATHS from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
@ -1045,6 +1049,8 @@ bool IncomingPacket::_doCIRCUIT_TEST(const RuntimeEnvironment *RR,const SharedPt
|
|||||||
RR->sw->send(outp,true,originatorCredentialNetworkId);
|
RR->sw->send(outp,true,originatorCredentialNetworkId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peer->received(RR,_localAddress,_remoteAddress,hops(),packetId(),Packet::VERB_CIRCUIT_TEST,0,Packet::VERB_NOP);
|
||||||
} catch (std::exception &exc) {
|
} catch (std::exception &exc) {
|
||||||
TRACE("dropped CIRCUIT_TEST from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
TRACE("dropped CIRCUIT_TEST from %s(%s): unexpected exception: %s",source().toString().c_str(),_remoteAddress.toString().c_str(),exc.what());
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
@ -1063,6 +1069,7 @@ bool IncomingPacket::_doREQUEST_PROOF_OF_WORK(const RuntimeEnvironment *RR,const
|
|||||||
try {
|
try {
|
||||||
// Right now this is only allowed from root servers -- may be allowed from controllers and relays later.
|
// Right now this is only allowed from root servers -- may be allowed from controllers and relays later.
|
||||||
if (RR->topology->isRoot(peer->identity())) {
|
if (RR->topology->isRoot(peer->identity())) {
|
||||||
|
const uint64_t pid = packetId();
|
||||||
const unsigned int difficulty = (*this)[ZT_PACKET_IDX_PAYLOAD + 1];
|
const unsigned int difficulty = (*this)[ZT_PACKET_IDX_PAYLOAD + 1];
|
||||||
const unsigned int challengeLength = at<uint16_t>(ZT_PACKET_IDX_PAYLOAD + 2);
|
const unsigned int challengeLength = at<uint16_t>(ZT_PACKET_IDX_PAYLOAD + 2);
|
||||||
if (challengeLength > ZT_PROTO_MAX_PACKET_LENGTH)
|
if (challengeLength > ZT_PROTO_MAX_PACKET_LENGTH)
|
||||||
@ -1079,7 +1086,7 @@ bool IncomingPacket::_doREQUEST_PROOF_OF_WORK(const RuntimeEnvironment *RR,const
|
|||||||
TRACE("PROOF_OF_WORK computed for %s: difficulty==%u, challengeLength==%u, result: %.16llx%.16llx",peer->address().toString().c_str(),difficulty,challengeLength,Utils::ntoh(*(reinterpret_cast<const uint64_t *>(result))),Utils::ntoh(*(reinterpret_cast<const uint64_t *>(result + 8))));
|
TRACE("PROOF_OF_WORK computed for %s: difficulty==%u, challengeLength==%u, result: %.16llx%.16llx",peer->address().toString().c_str(),difficulty,challengeLength,Utils::ntoh(*(reinterpret_cast<const uint64_t *>(result))),Utils::ntoh(*(reinterpret_cast<const uint64_t *>(result + 8))));
|
||||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
|
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
|
||||||
outp.append((unsigned char)Packet::VERB_REQUEST_PROOF_OF_WORK);
|
outp.append((unsigned char)Packet::VERB_REQUEST_PROOF_OF_WORK);
|
||||||
outp.append(packetId());
|
outp.append(pid);
|
||||||
outp.append((uint16_t)sizeof(result));
|
outp.append((uint16_t)sizeof(result));
|
||||||
outp.append(result,sizeof(result));
|
outp.append(result,sizeof(result));
|
||||||
outp.armor(peer->key(),true);
|
outp.armor(peer->key(),true);
|
||||||
@ -1087,7 +1094,7 @@ bool IncomingPacket::_doREQUEST_PROOF_OF_WORK(const RuntimeEnvironment *RR,const
|
|||||||
} else {
|
} else {
|
||||||
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_ERROR);
|
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_ERROR);
|
||||||
outp.append((unsigned char)Packet::VERB_REQUEST_PROOF_OF_WORK);
|
outp.append((unsigned char)Packet::VERB_REQUEST_PROOF_OF_WORK);
|
||||||
outp.append(packetId());
|
outp.append(pid);
|
||||||
outp.append((unsigned char)Packet::ERROR_INVALID_REQUEST);
|
outp.append((unsigned char)Packet::ERROR_INVALID_REQUEST);
|
||||||
outp.armor(peer->key(),true);
|
outp.armor(peer->key(),true);
|
||||||
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());
|
||||||
@ -1098,6 +1105,8 @@ bool IncomingPacket::_doREQUEST_PROOF_OF_WORK(const RuntimeEnvironment *RR,const
|
|||||||
TRACE("dropped REQUEST_PROOF_OF_WORK from %s(%s): unrecognized proof of work type",peer->address().toString().c_str(),_remoteAddress.toString().c_str());
|
TRACE("dropped REQUEST_PROOF_OF_WORK from %s(%s): unrecognized proof of work type",peer->address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peer->received(RR,_localAddress,_remoteAddress,hops(),pid,Packet::VERB_REQUEST_PROOF_OF_WORK,0,Packet::VERB_NOP);
|
||||||
} else {
|
} else {
|
||||||
TRACE("dropped REQUEST_PROOF_OF_WORK from %s(%s): not trusted enough",peer->address().toString().c_str(),_remoteAddress.toString().c_str());
|
TRACE("dropped REQUEST_PROOF_OF_WORK from %s(%s): not trusted enough",peer->address().toString().c_str(),_remoteAddress.toString().c_str());
|
||||||
}
|
}
|
||||||
|
@ -664,6 +664,8 @@ public:
|
|||||||
*
|
*
|
||||||
* This generates OK with a copy of the transmitted payload. No ERROR
|
* This generates OK with a copy of the transmitted payload. No ERROR
|
||||||
* is generated. Response to ECHO requests is optional.
|
* is generated. Response to ECHO requests is optional.
|
||||||
|
*
|
||||||
|
* Note that fragmented ECHO packets may not work.
|
||||||
*/
|
*/
|
||||||
VERB_ECHO = 8,
|
VERB_ECHO = 8,
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user