From b6248c7cb7e3e72780aa8981f8c0e39f5168d658 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 23 Aug 2013 10:54:45 -0400 Subject: [PATCH] VERSION 0.4.4: multicast cleanup, Windows port work In addition to a lot of Windows port work that isn't finished yet (and doesn't affect the *nix platforms at all), this version contains quite a bit of multicast cleanup and code simplification. I also pulled rate limits for now, as it seems to be causing problems. More testing on the testnet is going to be needed. --- node/PacketDecoder.cpp | 54 ++++++++++++++---------------------------- version.h | 2 +- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/node/PacketDecoder.cpp b/node/PacketDecoder.cpp index b4bc21e00..345c79143 100644 --- a/node/PacketDecoder.cpp +++ b/node/PacketDecoder.cpp @@ -105,7 +105,7 @@ bool PacketDecoder::tryDecode(const RuntimeEnvironment *_r) TRACE("NOP from %s(%s)",source().toString().c_str(),_remoteAddress.toString().c_str()); return true; case Packet::VERB_HELLO: - return _doHELLO(_r); // encrypted HELLO is technically allowed, but kind of pointless... :) + return _doHELLO(_r); case Packet::VERB_ERROR: return _doERROR(_r,peer); case Packet::VERB_OK: @@ -238,29 +238,16 @@ bool PacketDecoder::_doHELLO(const RuntimeEnvironment *_r) uint64_t timestamp = at(ZT_PROTO_VERB_HELLO_IDX_TIMESTAMP); Identity id(*this,ZT_PROTO_VERB_HELLO_IDX_IDENTITY); - // Create a new candidate peer that we might decide to add to our - // database. We create it now since we want its keys to send replies - // even in the error case, and the code for keying is in Peer. - SharedPtr candidate(new Peer(_r->identity,id)); - candidate->setPathAddress(_remoteAddress,false); - - // The initial sniff test... is the identity valid, and is it - // the sender's identity? + // Initial sniff test for valid addressing and that this is indeed the + // submitter's identity. if ((id.address().isReserved())||(id.address() != source())) { #ifdef ZT_TRACE if (id.address().isReserved()) { - TRACE("rejected HELLO from %s(%s): identity has reserved address",source().toString().c_str(),_remoteAddress.toString().c_str()); + TRACE("dropped HELLO from %s(%s): identity has reserved address",source().toString().c_str(),_remoteAddress.toString().c_str()); } else { - TRACE("rejected HELLO from %s(%s): identity is not for sender of packet (HELLO is a self-announcement)",source().toString().c_str(),_remoteAddress.toString().c_str()); + TRACE("dropped HELLO from %s(%s): identity is not for sender of packet (HELLO is a self-announcement)",source().toString().c_str(),_remoteAddress.toString().c_str()); } #endif - Packet outp(source(),_r->identity.address(),Packet::VERB_ERROR); - outp.append((unsigned char)Packet::VERB_HELLO); - outp.append(packetId()); - outp.append((unsigned char)((id.address().isReserved()) ? Packet::ERROR_IDENTITY_INVALID : Packet::ERROR_INVALID_REQUEST)); - outp.encrypt(candidate->cryptKey()); - outp.hmacSet(candidate->macKey()); - _r->demarc->send(_localPort,_remoteAddress,outp.data(),outp.size(),-1); return true; } @@ -281,9 +268,9 @@ bool PacketDecoder::_doHELLO(const RuntimeEnvironment *_r) return true; } - // Otherwise we call addPeer() and set up a callback to handle the verdict. - // Topology evaluates the peer in the background, possibly doing the entire - // expensive analysis before determining whether to add it to the database. + SharedPtr candidate(new Peer(_r->identity,id)); + candidate->setPathAddress(_remoteAddress,false); + _CBaddPeerFromHello_Data *arg = new _CBaddPeerFromHello_Data; arg->renv = _r; arg->source = source(); @@ -319,16 +306,15 @@ bool PacketDecoder::_doOK(const RuntimeEnvironment *_r,const SharedPtr &pe if (_r->topology->isSupernode(source())) { // Right now, only supernodes are queried for WHOIS so we only // accept OK(WHOIS) from supernodes. Otherwise peers could - // potentially cache-poison. A more elegant but memory-intensive - // solution would be to remember packet IDs of WHOIS requests. + // potentially cache-poison. _r->topology->addPeer(SharedPtr(new Peer(_r->identity,Identity(*this,ZT_PROTO_VERB_WHOIS__OK__IDX_IDENTITY))),&PacketDecoder::_CBaddPeerFromWhois,const_cast((const void *)_r)); } } break; case Packet::VERB_NETWORK_CONFIG_REQUEST: { SharedPtr nw(_r->nc->network(at(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_NETWORK_ID))); if ((nw)&&(nw->controller() == source())) { - // Only accept OK(NETWORK_CONFIG_REQUEST) from masters for - // networks we have. + // OK(NETWORK_CONFIG_REQUEST) is only accepted from a network's + // controller. unsigned int dictlen = at(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT_LEN); std::string dict((const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT,dictlen),dictlen); if (dict.length()) { @@ -396,8 +382,7 @@ bool PacketDecoder::_doRENDEZVOUS(const RuntimeEnvironment *_r,const SharedPtr

topology->isSupernode(source())) { Address with(field(ZT_PROTO_VERB_RENDEZVOUS_IDX_ZTADDRESS,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); @@ -469,10 +454,7 @@ bool PacketDecoder::_doMULTICAST_LIKE(const RuntimeEnvironment *_r,const SharedP //TRACE("peer %s likes multicast group %s:%.8lx on network %llu",source().toString().c_str(),mac.toString().c_str(),(unsigned long)adi,nwid); _r->multicaster->likesMulticastGroup(nwid,MulticastGroup(mac,adi),source(),now); ++numAccepted; - } else { - ptr += 10; - TRACE("ignored MULTICAST_LIKE from %s(%s): network %.16llx unknown, or sender is not a member of network",source().toString().c_str(),_remoteAddress.toString().c_str(),(unsigned long long)nwid); - } + } else ptr += 10; } Packet outp(source(),_r->identity.address(),Packet::VERB_OK); @@ -537,12 +519,12 @@ bool PacketDecoder::_doMULTICAST_FRAME(const RuntimeEnvironment *_r,const Shared bool isDuplicate = _r->multicaster->checkDuplicate(mccrc,now); if (!isDuplicate) { - if (network->multicastRateGate(originalSubmitterAddress,datalen)) { + //if (network->multicastRateGate(originalSubmitterAddress,datalen)) { network->tap().put(fromMac,mg.mac(),etherType,dataAndSignature,datalen); - } else { - TRACE("dropped MULTICAST_FRAME from original submitter %s, received from %s(%s): sender rate limit exceeded",originalSubmitterAddress.toString().c_str(),source().toString().c_str(),_remoteAddress.toString().c_str()); - return true; - } + //} else { + // TRACE("dropped MULTICAST_FRAME from original submitter %s, received from %s(%s): sender rate limit exceeded",originalSubmitterAddress.toString().c_str(),source().toString().c_str(),_remoteAddress.toString().c_str()); + // return true; + //} /* It's important that we do this *after* rate limit checking, * otherwise supernodes could be used to execute a flood by diff --git a/version.h b/version.h index c68ef0f47..e87363d4e 100644 --- a/version.h +++ b/version.h @@ -41,6 +41,6 @@ /** * Revision: 16-bit (0-65535) */ -#define ZEROTIER_ONE_VERSION_REVISION 3 +#define ZEROTIER_ONE_VERSION_REVISION 4 #endif