Rename PacketDecoder to much more descriptive IncomingPacket

This commit is contained in:
Adam Ierymenko 2014-09-24 09:04:09 -07:00
parent 9180a30986
commit 557801a09e
5 changed files with 29 additions and 29 deletions

@ -35,7 +35,7 @@
#include "Defaults.hpp" #include "Defaults.hpp"
#include "RuntimeEnvironment.hpp" #include "RuntimeEnvironment.hpp"
#include "Topology.hpp" #include "Topology.hpp"
#include "PacketDecoder.hpp" #include "IncomingPacket.hpp"
#include "Switch.hpp" #include "Switch.hpp"
#include "Peer.hpp" #include "Peer.hpp"
#include "NodeConfig.hpp" #include "NodeConfig.hpp"
@ -45,7 +45,7 @@
namespace ZeroTier { namespace ZeroTier {
bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r) bool IncomingPacket::tryDecode(const RuntimeEnvironment *_r)
{ {
if ((!encrypted())&&(verb() == Packet::VERB_HELLO)) { if ((!encrypted())&&(verb() == Packet::VERB_HELLO)) {
// Unencrypted HELLOs are handled here since they are used to // Unencrypted HELLOs are handled here since they are used to
@ -117,7 +117,7 @@ bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r)
} }
} }
bool PacketDecoder::_doERROR(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doERROR(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
Packet::Verb inReVerb = (Packet::Verb)(*this)[ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB]; Packet::Verb inReVerb = (Packet::Verb)(*this)[ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB];
@ -164,7 +164,7 @@ bool PacketDecoder::_doERROR(const RuntimeEnvironment *_r,const SharedPtr<Peer>
return true; return true;
} }
bool PacketDecoder::_doHELLO(const RuntimeEnvironment *_r) bool IncomingPacket::_doHELLO(const RuntimeEnvironment *_r)
{ {
try { try {
unsigned int protoVersion = (*this)[ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION]; unsigned int protoVersion = (*this)[ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION];
@ -271,7 +271,7 @@ bool PacketDecoder::_doHELLO(const RuntimeEnvironment *_r)
return true; return true;
} }
bool PacketDecoder::_doOK(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doOK(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
Packet::Verb inReVerb = (Packet::Verb)(*this)[ZT_PROTO_VERB_OK_IDX_IN_RE_VERB]; Packet::Verb inReVerb = (Packet::Verb)(*this)[ZT_PROTO_VERB_OK_IDX_IN_RE_VERB];
@ -332,7 +332,7 @@ bool PacketDecoder::_doOK(const RuntimeEnvironment *_r,const SharedPtr<Peer> &pe
return true; return true;
} }
bool PacketDecoder::_doWHOIS(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doWHOIS(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
if (payloadLength() == ZT_ADDRESS_LENGTH) { if (payloadLength() == ZT_ADDRESS_LENGTH) {
@ -366,7 +366,7 @@ bool PacketDecoder::_doWHOIS(const RuntimeEnvironment *_r,const SharedPtr<Peer>
return true; return true;
} }
bool PacketDecoder::_doRENDEZVOUS(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doRENDEZVOUS(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
/* /*
@ -410,7 +410,7 @@ bool PacketDecoder::_doRENDEZVOUS(const RuntimeEnvironment *_r,const SharedPtr<P
return true; return true;
} }
bool PacketDecoder::_doFRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doFRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
SharedPtr<Network> network(_r->nc->network(at<uint64_t>(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID))); SharedPtr<Network> network(_r->nc->network(at<uint64_t>(ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID)));
@ -449,7 +449,7 @@ bool PacketDecoder::_doFRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer>
return true; return true;
} }
bool PacketDecoder::_doEXT_FRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doEXT_FRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
SharedPtr<Network> network(_r->nc->network(at<uint64_t>(ZT_PROTO_VERB_EXT_FRAME_IDX_NETWORK_ID))); SharedPtr<Network> network(_r->nc->network(at<uint64_t>(ZT_PROTO_VERB_EXT_FRAME_IDX_NETWORK_ID)));
@ -518,7 +518,7 @@ bool PacketDecoder::_doEXT_FRAME(const RuntimeEnvironment *_r,const SharedPtr<Pe
return true; return true;
} }
bool PacketDecoder::_doMULTICAST_FRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doMULTICAST_FRAME(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
Address origin(Address(field(ZT_PROTO_VERB_MULTICAST_FRAME_IDX_ORIGIN,ZT_PROTO_VERB_MULTICAST_FRAME_LEN_ORIGIN),ZT_ADDRESS_LENGTH)); Address origin(Address(field(ZT_PROTO_VERB_MULTICAST_FRAME_IDX_ORIGIN,ZT_PROTO_VERB_MULTICAST_FRAME_LEN_ORIGIN),ZT_ADDRESS_LENGTH));
@ -767,7 +767,7 @@ bool PacketDecoder::_doMULTICAST_FRAME(const RuntimeEnvironment *_r,const Shared
return true; return true;
} }
bool PacketDecoder::_doMULTICAST_LIKE(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doMULTICAST_LIKE(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
Address src(source()); Address src(source());
@ -793,7 +793,7 @@ bool PacketDecoder::_doMULTICAST_LIKE(const RuntimeEnvironment *_r,const SharedP
return true; return true;
} }
bool PacketDecoder::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
CertificateOfMembership com; CertificateOfMembership com;
@ -829,7 +829,7 @@ bool PacketDecoder::_doNETWORK_MEMBERSHIP_CERTIFICATE(const RuntimeEnvironment *
return true; return true;
} }
bool PacketDecoder::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
uint64_t nwid = at<uint64_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID); uint64_t nwid = at<uint64_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID);
@ -872,7 +872,7 @@ bool PacketDecoder::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *_r,const
return true; return true;
} }
bool PacketDecoder::_doNETWORK_CONFIG_REFRESH(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer) bool IncomingPacket::_doNETWORK_CONFIG_REFRESH(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer)
{ {
try { try {
unsigned int ptr = ZT_PACKET_IDX_PAYLOAD; unsigned int ptr = ZT_PACKET_IDX_PAYLOAD;
@ -893,7 +893,7 @@ bool PacketDecoder::_doNETWORK_CONFIG_REFRESH(const RuntimeEnvironment *_r,const
return true; return true;
} }
void PacketDecoder::_sendErrorNeedCertificate(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer,uint64_t nwid) void IncomingPacket::_sendErrorNeedCertificate(const RuntimeEnvironment *_r,const SharedPtr<Peer> &peer,uint64_t nwid)
{ {
Packet outp(source(),_r->identity.address(),Packet::VERB_ERROR); Packet outp(source(),_r->identity.address(),Packet::VERB_ERROR);
outp.append((unsigned char)verb()); outp.append((unsigned char)verb());

@ -25,8 +25,8 @@
* LLC. Start here: http://www.zerotier.com/ * LLC. Start here: http://www.zerotier.com/
*/ */
#ifndef ZT_PACKETDECODER_HPP #ifndef ZT_INCOMINGPACKET_HPP
#define ZT_PACKETDECODER_HPP #define ZT_INCOMINGPACKET_HPP
#include <stdexcept> #include <stdexcept>
@ -63,9 +63,9 @@ class Network;
/** /**
* Subclass of packet that handles the decoding of it * Subclass of packet that handles the decoding of it
*/ */
class PacketDecoder : public Packet class IncomingPacket : public Packet
{ {
friend class SharedPtr<PacketDecoder>; friend class SharedPtr<IncomingPacket>;
public: public:
/** /**
@ -77,7 +77,7 @@ public:
* @throws std::out_of_range Range error processing packet * @throws std::out_of_range Range error processing packet
*/ */
template<unsigned int C2> template<unsigned int C2>
PacketDecoder(const Buffer<C2> &b,const SharedPtr<Socket> &fromSock,const InetAddress &remoteAddress) IncomingPacket(const Buffer<C2> &b,const SharedPtr<Socket> &fromSock,const InetAddress &remoteAddress)
throw(std::out_of_range) : throw(std::out_of_range) :
Packet(b), Packet(b),
_receiveTime(Utils::now()), _receiveTime(Utils::now()),

@ -166,7 +166,7 @@ public:
/** /**
* Set or update this network's configuration * Set or update this network's configuration
* *
* This is called by PacketDecoder when an update comes over the wire, or * This is called in IncomingPacket when an update comes over the wire, or
* internally when an old config is reloaded from disk. * internally when an old config is reloaded from disk.
* *
* This also cancels any netconf failure flags. * This also cancels any netconf failure flags.
@ -181,7 +181,7 @@ public:
bool setConfiguration(const Dictionary &conf,bool saveToDisk = true); bool setConfiguration(const Dictionary &conf,bool saveToDisk = true);
/** /**
* Set netconf failure to 'access denied' -- called by PacketDecoder when netconf master reports this * Set netconf failure to 'access denied' -- called in IncomingPacket when netconf master reports this
*/ */
inline void setAccessDenied() inline void setAccessDenied()
{ {

@ -547,7 +547,7 @@ unsigned long Switch::doTimerTasks()
{ {
Mutex::Lock _l(_rxQueue_m); Mutex::Lock _l(_rxQueue_m);
for(std::list< SharedPtr<PacketDecoder> >::iterator i(_rxQueue.begin());i!=_rxQueue.end();) { for(std::list< SharedPtr<IncomingPacket> >::iterator i(_rxQueue.begin());i!=_rxQueue.end();) {
if ((now - (*i)->receiveTime()) > ZT_RECEIVE_QUEUE_TIMEOUT) { if ((now - (*i)->receiveTime()) > ZT_RECEIVE_QUEUE_TIMEOUT) {
TRACE("RX %s -> %s timed out",(*i)->source().toString().c_str(),(*i)->destination().toString().c_str()); TRACE("RX %s -> %s timed out",(*i)->source().toString().c_str(),(*i)->destination().toString().c_str());
_rxQueue.erase(i++); _rxQueue.erase(i++);
@ -664,7 +664,7 @@ void Switch::doAnythingWaitingForPeer(const SharedPtr<Peer> &peer)
{ // finish processing any packets waiting on peer's public key / identity { // finish processing any packets waiting on peer's public key / identity
Mutex::Lock _l(_rxQueue_m); Mutex::Lock _l(_rxQueue_m);
for(std::list< SharedPtr<PacketDecoder> >::iterator rxi(_rxQueue.begin());rxi!=_rxQueue.end();) { for(std::list< SharedPtr<IncomingPacket> >::iterator rxi(_rxQueue.begin());rxi!=_rxQueue.end();) {
if ((*rxi)->tryDecode(_r)) if ((*rxi)->tryDecode(_r))
_rxQueue.erase(rxi++); _rxQueue.erase(rxi++);
else ++rxi; else ++rxi;
@ -755,7 +755,7 @@ void Switch::_handleRemotePacketFragment(const SharedPtr<Socket> &fromSock,const
// We have all fragments -- assemble and process full Packet // We have all fragments -- assemble and process full Packet
//TRACE("packet %.16llx is complete, assembling and processing...",pid); //TRACE("packet %.16llx is complete, assembling and processing...",pid);
SharedPtr<PacketDecoder> packet(dqe->second.frag0); SharedPtr<IncomingPacket> packet(dqe->second.frag0);
for(unsigned int f=1;f<tf;++f) for(unsigned int f=1;f<tf;++f)
packet->append(dqe->second.frags[f - 1].payload(),dqe->second.frags[f - 1].payloadLength()); packet->append(dqe->second.frags[f - 1].payload(),dqe->second.frags[f - 1].payloadLength());
_defragQueue.erase(dqe); _defragQueue.erase(dqe);
@ -772,7 +772,7 @@ void Switch::_handleRemotePacketFragment(const SharedPtr<Socket> &fromSock,const
void Switch::_handleRemotePacketHead(const SharedPtr<Socket> &fromSock,const InetAddress &fromAddr,const Buffer<4096> &data) void Switch::_handleRemotePacketHead(const SharedPtr<Socket> &fromSock,const InetAddress &fromAddr,const Buffer<4096> &data)
{ {
SharedPtr<PacketDecoder> packet(new PacketDecoder(data,fromSock,fromAddr)); SharedPtr<IncomingPacket> packet(new IncomingPacket(data,fromSock,fromAddr));
Address source(packet->source()); Address source(packet->source());
Address destination(packet->destination()); Address destination(packet->destination());

@ -44,7 +44,7 @@
#include "Array.hpp" #include "Array.hpp"
#include "Network.hpp" #include "Network.hpp"
#include "SharedPtr.hpp" #include "SharedPtr.hpp"
#include "PacketDecoder.hpp" #include "IncomingPacket.hpp"
#include "Socket.hpp" #include "Socket.hpp"
/* Ethernet frame types that might be relevant to us */ /* Ethernet frame types that might be relevant to us */
@ -246,7 +246,7 @@ private:
std::map< Address,WhoisRequest > _outstandingWhoisRequests; std::map< Address,WhoisRequest > _outstandingWhoisRequests;
Mutex _outstandingWhoisRequests_m; Mutex _outstandingWhoisRequests_m;
std::list< SharedPtr<PacketDecoder> > _rxQueue; std::list< SharedPtr<IncomingPacket> > _rxQueue;
Mutex _rxQueue_m; Mutex _rxQueue_m;
struct TXQueueEntry struct TXQueueEntry
@ -267,7 +267,7 @@ private:
struct DefragQueueEntry struct DefragQueueEntry
{ {
uint64_t creationTime; uint64_t creationTime;
SharedPtr<PacketDecoder> frag0; SharedPtr<IncomingPacket> frag0;
Packet::Fragment frags[ZT_MAX_PACKET_FRAGMENTS - 1]; Packet::Fragment frags[ZT_MAX_PACKET_FRAGMENTS - 1];
unsigned int totalFragments; // 0 if only frag0 received, waiting for frags unsigned int totalFragments; // 0 if only frag0 received, waiting for frags
uint32_t haveFragments; // bit mask, LSB to MSB uint32_t haveFragments; // bit mask, LSB to MSB