From 4bf3bcbd555025c5e76301ca49f74cafa526d902 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 13 Jul 2015 09:29:51 -0700 Subject: Fixes to PUSH_DIRECT_PATHS. --- node/IncomingPacket.cpp | 12 ++++++++---- node/Peer.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'node') diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index 6c3a0932..deebac9b 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -906,7 +906,7 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha unsigned int count = at(ZT_PACKET_IDX_PAYLOAD); unsigned int ptr = ZT_PACKET_IDX_PAYLOAD + 2; - while (count) { // if ptr overflows Buffer will throw + while (count--) { // if ptr overflows Buffer will throw // TODO: properly handle blacklisting, support other features... see Packet.hpp. unsigned int flags = (*this)[ptr++]; @@ -914,18 +914,22 @@ bool IncomingPacket::_doPUSH_DIRECT_PATHS(const RuntimeEnvironment *RR,const Sha unsigned int extLen = at(ptr); ptr += 2; ptr += extLen; // unused right now unsigned int addrType = (*this)[ptr++]; - unsigned int addrLen = (*this)[ptr++]; + switch(addrType) { case 4: { InetAddress a(field(ptr,4),4,at(ptr + 4)); - if ( ((flags & (0x01 | 0x02)) == 0) && (Path::isAddressValidForPath(a)) ) + if ( ((flags & (0x01 | 0x02)) == 0) && (Path::isAddressValidForPath(a)) ) { + TRACE("attempting to contact %s at pushed direct path %s",peer->address().toString().c_str(),a.toString().c_str()); peer->attemptToContactAt(RR,a,RR->node->now()); + } } break; case 6: { InetAddress a(field(ptr,16),16,at(ptr + 16)); - if ( ((flags & (0x01 | 0x02)) == 0) && (Path::isAddressValidForPath(a)) ) + if ( ((flags & (0x01 | 0x02)) == 0) && (Path::isAddressValidForPath(a)) ) { + TRACE("attempting to contact %s at pushed direct path %s",peer->address().toString().c_str(),a.toString().c_str()); peer->attemptToContactAt(RR,a,RR->node->now()); + } } break; } ptr += addrLen; diff --git a/node/Peer.cpp b/node/Peer.cpp index 84aa8bef..ba765c72 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -255,7 +255,7 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_ outp.append(flags); outp.append((uint8_t)((p->metric() >= 0) ? ((p->metric() <= 255) ? p->metric() : 255) : 0)); - outp.append((uint16_t)0); + outp.append((uint16_t)0); // no extensions outp.append(addressType); outp.append((uint8_t)((addressType == 4) ? 6 : 18)); outp.append(p->address().rawIpData(),((addressType == 4) ? 4 : 16)); -- cgit v1.2.3