diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-04-30 19:19:45 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-04-30 19:19:45 -0700 |
commit | 52df59c55299419feb16a5daeed01389f4fafc73 (patch) | |
tree | 5d081b9a9c14566c07cea8b661bf74acee0be312 /node | |
parent | 9464504e4a68755296b96fcc3df4afe1ce79b681 (diff) | |
parent | d3820049b82f756ba6c9c3390d4060ee1ad49925 (diff) | |
download | infinitytier-52df59c55299419feb16a5daeed01389f4fafc73.tar.gz infinitytier-52df59c55299419feb16a5daeed01389f4fafc73.zip |
Merge branch 'adamierymenko-dev' into android-jni
Conflicts:
.gitignore
Diffstat (limited to 'node')
-rw-r--r-- | node/IncomingPacket.cpp | 51 | ||||
-rw-r--r-- | node/Node.cpp | 22 | ||||
-rw-r--r-- | node/Node.hpp | 4 |
3 files changed, 47 insertions, 30 deletions
diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index a8d564bb..453e3945 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -179,18 +179,17 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR) Identity id; unsigned int destAddrPtr = id.deserialize(*this,ZT_PROTO_VERB_HELLO_IDX_IDENTITY) + ZT_PROTO_VERB_HELLO_IDX_IDENTITY; - unsigned int destAddrType = ZT_PROTO_DEST_ADDRESS_TYPE_NONE; - if (destAddrPtr < size()) // ZeroTier One < 1.0.3 did not include this field - destAddrType = (*this)[destAddrPtr++]; - InetAddress destAddr; - switch(destAddrType) { - case ZT_PROTO_DEST_ADDRESS_TYPE_IPV4: - destAddr.set(field(destAddrPtr,4),4,at<uint16_t>(destAddrPtr + 4)); - break; - case ZT_PROTO_DEST_ADDRESS_TYPE_IPV6: - destAddr.set(field(destAddrPtr,16),16,at<uint16_t>(destAddrPtr + 16)); - break; + if (destAddrPtr < size()) { // ZeroTier One < 1.0.3 did not include this field + const unsigned int destAddrType = (*this)[destAddrPtr++]; + switch(destAddrType) { + case ZT_PROTO_DEST_ADDRESS_TYPE_IPV4: + destAddr.set(field(destAddrPtr,4),4,at<uint16_t>(destAddrPtr + 4)); + break; + case ZT_PROTO_DEST_ADDRESS_TYPE_IPV6: + destAddr.set(field(destAddrPtr,16),16,at<uint16_t>(destAddrPtr + 16)); + break; + } } if (source() != id.address()) { @@ -268,12 +267,13 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR) peer->received(RR,_remoteAddress,_linkDesperation,hops(),packetId(),Packet::VERB_HELLO,0,Packet::VERB_NOP); peer->setRemoteVersion(protoVersion,vMajor,vMinor,vRevision); + bool trusted = false; if (RR->topology->isSupernode(id.address())) { RR->node->postNewerVersionIfNewer(vMajor,vMinor,vRevision); - RR->sa->iam(id.address(),_remoteAddress,destAddr,true); - } else { - RR->sa->iam(id.address(),_remoteAddress,destAddr,false); + trusted = true; } + if (destAddr) + RR->sa->iam(id.address(),_remoteAddress,destAddr,trusted); Packet outp(id.address(),RR->identity.address(),Packet::VERB_OK); @@ -328,18 +328,37 @@ bool IncomingPacket::_doOK(const RuntimeEnvironment *RR,const SharedPtr<Peer> &p const unsigned int vMinor = (*this)[ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION]; const unsigned int vRevision = at<uint16_t>(ZT_PROTO_VERB_HELLO__OK__IDX_REVISION); + InetAddress destAddr; + unsigned int destAddrPtr = ZT_PROTO_VERB_HELLO__OK__IDX_REVISION + 2; // dest address, if present, will start after 16-bit revision + if (destAddrPtr < size()) { // ZeroTier One < 1.0.3 did not include this field + const unsigned int destAddrType = (*this)[destAddrPtr++]; + switch(destAddrType) { + case ZT_PROTO_DEST_ADDRESS_TYPE_IPV4: + destAddr.set(field(destAddrPtr,4),4,at<uint16_t>(destAddrPtr + 4)); + break; + case ZT_PROTO_DEST_ADDRESS_TYPE_IPV6: + destAddr.set(field(destAddrPtr,16),16,at<uint16_t>(destAddrPtr + 16)); + break; + } + } + if (vProto < ZT_PROTO_VERSION_MIN) { TRACE("%s(%s): OK(HELLO) dropped, protocol version too old",source().toString().c_str(),_remoteAddress.toString().c_str()); return true; } - TRACE("%s(%s): OK(HELLO), version %u.%u.%u, latency %u",source().toString().c_str(),_remoteAddress.toString().c_str(),vMajor,vMinor,vRevision,latency); + TRACE("%s(%s): OK(HELLO), version %u.%u.%u, latency %u, reported external address %s",source().toString().c_str(),_remoteAddress.toString().c_str(),vMajor,vMinor,vRevision,latency,((destAddr) ? destAddr.toString().c_str() : "(none)")); peer->addDirectLatencyMeasurment(latency); peer->setRemoteVersion(vProto,vMajor,vMinor,vRevision); - if (RR->topology->isSupernode(peer->address())) + bool trusted = false; + if (RR->topology->isSupernode(peer->address())) { RR->node->postNewerVersionIfNewer(vMajor,vMinor,vRevision); + trusted = true; + } + if (destAddr) + RR->sa->iam(peer->address(),_remoteAddress,destAddr,trusted); } break; case Packet::VERB_WHOIS: { diff --git a/node/Node.cpp b/node/Node.cpp index e77a977e..1661e9d1 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -59,7 +59,8 @@ Node::Node( ZT1_VirtualNetworkConfigFunction virtualNetworkConfigFunction, ZT1_EventCallback eventCallback, const char *overrideRootTopology) : - RR(new RuntimeEnvironment(this)), + _RR(this), + RR(&_RR), _uPtr(uptr), _dataStoreGetFunction(dataStoreGetFunction), _dataStorePutFunction(dataStorePutFunction), @@ -86,19 +87,18 @@ Node::Node( TRACE("identity.secret not found, generating..."); RR->identity.generate(); idtmp = RR->identity.toString(true); - if (!dataStorePut("identity.secret",idtmp,true)) { - delete RR; + if (!dataStorePut("identity.secret",idtmp,true)) throw std::runtime_error("unable to write identity.secret"); - } - idtmp = RR->identity.toString(false); - if (!dataStorePut("identity.public",idtmp,false)) { - delete RR; - throw std::runtime_error("unable to write identity.public"); - } } RR->publicIdentityStr = RR->identity.toString(false); RR->secretIdentityStr = RR->identity.toString(true); + idtmp = dataStoreGet("identity.public"); + if (idtmp != RR->publicIdentityStr) { + if (!dataStorePut("identity.public",RR->publicIdentityStr,false)) + throw std::runtime_error("unable to write identity.public"); + } + try { RR->prng = new CMWC4096(); RR->sw = new Switch(RR); @@ -113,7 +113,6 @@ Node::Node( delete RR->mc; delete RR->sw; delete RR->prng; - delete RR; throw; } @@ -138,14 +137,13 @@ Node::Node( Node::~Node() { Mutex::Lock _l(_networks_m); - _networks.clear(); // delete these before we delete RR + _networks.clear(); delete RR->sa; delete RR->topology; delete RR->antiRec; delete RR->mc; delete RR->sw; delete RR->prng; - delete RR; } ZT1_ResultCode Node::processWirePacket( diff --git a/node/Node.hpp b/node/Node.hpp index 396e04c0..70531bf8 100644 --- a/node/Node.hpp +++ b/node/Node.hpp @@ -38,6 +38,7 @@ #include "../include/ZeroTierOne.h" +#include "RuntimeEnvironment.hpp" #include "InetAddress.hpp" #include "Mutex.hpp" #include "MAC.hpp" @@ -52,8 +53,6 @@ namespace ZeroTier { -class RuntimeEnvironment; - /** * Implementation of Node object as defined in CAPI * @@ -229,6 +228,7 @@ public: #endif private: + RuntimeEnvironment _RR; RuntimeEnvironment *RR; void *_uPtr; // _uptr (lower case) is reserved in Visual Studio :P |