Finally add an ECHO.

This commit is contained in:
Adam Ierymenko 2015-10-07 16:11:50 -07:00
parent 73cafbe0ec
commit 69b44bf9a5
4 changed files with 32 additions and 13 deletions

View File

@ -83,6 +83,7 @@ bool IncomingPacket::tryDecode(const RuntimeEnvironment *RR)
case Packet::VERB_RENDEZVOUS: return _doRENDEZVOUS(RR,peer); case Packet::VERB_RENDEZVOUS: return _doRENDEZVOUS(RR,peer);
case Packet::VERB_FRAME: return _doFRAME(RR,peer); case Packet::VERB_FRAME: return _doFRAME(RR,peer);
case Packet::VERB_EXT_FRAME: return _doEXT_FRAME(RR,peer); case Packet::VERB_EXT_FRAME: return _doEXT_FRAME(RR,peer);
case Packet::VERB_ECHO: return _doECHO(RR,peer);
case Packet::VERB_MULTICAST_LIKE: return _doMULTICAST_LIKE(RR,peer); case Packet::VERB_MULTICAST_LIKE: return _doMULTICAST_LIKE(RR,peer);
case Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE: return _doNETWORK_MEMBERSHIP_CERTIFICATE(RR,peer); case Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE: return _doNETWORK_MEMBERSHIP_CERTIFICATE(RR,peer);
case Packet::VERB_NETWORK_CONFIG_REQUEST: return _doNETWORK_CONFIG_REQUEST(RR,peer); case Packet::VERB_NETWORK_CONFIG_REQUEST: return _doNETWORK_CONFIG_REQUEST(RR,peer);
@ -569,6 +570,18 @@ bool IncomingPacket::_doEXT_FRAME(const RuntimeEnvironment *RR,const SharedPtr<P
return true; return true;
} }
bool IncomingPacket::_doECHO(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer)
{
try {
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_OK);
outp.append((unsigned char)Packet::VERB_ECHO);
outp.append(packetId());
outp.append(field(ZT_PACKET_IDX_PAYLOAD,size() - ZT_PACKET_IDX_PAYLOAD),size() - ZT_PACKET_IDX_PAYLOAD);
RR->sw->send(outp,true,0);
} catch ( ... ) {}
return true;
}
bool IncomingPacket::_doMULTICAST_LIKE(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer) bool IncomingPacket::_doMULTICAST_LIKE(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer)
{ {
try { try {
@ -636,7 +649,7 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,cons
outp.append(netconfStr.data(),(unsigned int)netconfStr.length()); outp.append(netconfStr.data(),(unsigned int)netconfStr.length());
outp.compress(); outp.compress();
outp.armor(peer->key(),true); outp.armor(peer->key(),true);
if (outp.size() > ZT_PROTO_MAX_PACKET_LENGTH) { if (outp.size() > ZT_PROTO_MAX_PACKET_LENGTH) { // sanity check
TRACE("NETWORK_CONFIG_REQUEST failed: internal error: netconf size %u is too large",(unsigned int)netconfStr.length()); TRACE("NETWORK_CONFIG_REQUEST failed: internal error: netconf size %u is too large",(unsigned int)netconfStr.length());
} else { } else {
RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size()); RR->node->putPacket(_localAddress,_remoteAddress,outp.data(),outp.size());

View File

@ -138,6 +138,7 @@ private:
bool _doRENDEZVOUS(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer); bool _doRENDEZVOUS(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);
bool _doFRAME(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer); bool _doFRAME(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);
bool _doEXT_FRAME(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer); bool _doEXT_FRAME(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);
bool _doECHO(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);
bool _doMULTICAST_LIKE(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer); bool _doMULTICAST_LIKE(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);
bool _doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer); bool _doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);
bool _doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer); bool _doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,const SharedPtr<Peer> &peer);

View File

@ -45,6 +45,7 @@ const char *Packet::verbString(Verb v)
case VERB_RENDEZVOUS: return "RENDEZVOUS"; case VERB_RENDEZVOUS: return "RENDEZVOUS";
case VERB_FRAME: return "FRAME"; case VERB_FRAME: return "FRAME";
case VERB_EXT_FRAME: return "EXT_FRAME"; case VERB_EXT_FRAME: return "EXT_FRAME";
case VERB_ECHO: return "ECHO";
case VERB_MULTICAST_LIKE: return "MULTICAST_LIKE"; case VERB_MULTICAST_LIKE: return "MULTICAST_LIKE";
case VERB_NETWORK_MEMBERSHIP_CERTIFICATE: return "NETWORK_MEMBERSHIP_CERTIFICATE"; case VERB_NETWORK_MEMBERSHIP_CERTIFICATE: return "NETWORK_MEMBERSHIP_CERTIFICATE";
case VERB_NETWORK_CONFIG_REQUEST: return "NETWORK_CONFIG_REQUEST"; case VERB_NETWORK_CONFIG_REQUEST: return "NETWORK_CONFIG_REQUEST";

View File

@ -46,22 +46,20 @@
#include "../ext/lz4/lz4.h" #include "../ext/lz4/lz4.h"
/** /**
* Protocol version -- incremented only for MAJOR changes * Protocol version -- incremented only for major changes
* *
* 1 - 0.2.0 ... 0.2.5 * 1 - 0.2.0 ... 0.2.5
* 2 - 0.3.0 ... 0.4.5 * 2 - 0.3.0 ... 0.4.5
* * Added signature and originating peer to multicast frame * + Added signature and originating peer to multicast frame
* * Double size of multicast frame bloom filter * + Double size of multicast frame bloom filter
* 3 - 0.5.0 ... 0.6.0 * 3 - 0.5.0 ... 0.6.0
* * Yet another multicast redesign * + Yet another multicast redesign
* * New crypto completely changes key agreement cipher * + New crypto completely changes key agreement cipher
* 4 - 0.6.0 ... 1.0.6 * 4 - 0.6.0 ... 1.0.6
* * New identity format based on hashcash design * + New identity format based on hashcash design
* 5 - 1.0.6 ... CURRENT * 5 - 1.0.6 ... CURRENT
* * Supports CIRCUIT_TEST and friends, otherwise compatibie w/v4 * + Supports circuit test, proof of work, and echo
* * + Otherwise backward compatible with 4
* This isn't going to change again for a long time unless your
* author wakes up again at 4am with another great idea. :P
*/ */
#define ZT_PROTO_VERSION 5 #define ZT_PROTO_VERSION 5
@ -660,8 +658,14 @@ public:
*/ */
VERB_EXT_FRAME = 7, VERB_EXT_FRAME = 7,
/* DEPRECATED */ /**
//VERB_P5_MULTICAST_FRAME = 8, * ECHO request (a.k.a. ping):
* <[...] arbitrary payload to be echoed back>
*
* This generates OK with a copy of the transmitted payload. No ERROR
* is generated. Response to ECHO requests is optional.
*/
VERB_ECHO = 8,
/** /**
* Announce interest in multicast group(s): * Announce interest in multicast group(s):