diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-27 09:53:43 -0700 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-10-27 09:53:43 -0700 |
commit | 9617208e4027bec8a72e72a1fd89aa19ea9367d8 (patch) | |
tree | 6e8a7402dc7da5d6e713cb25b931329b86665230 /node | |
parent | fb3b7a3baaf1fc1a6d922ea7aaa24a37c7a14952 (diff) | |
download | infinitytier-9617208e4027bec8a72e72a1fd89aa19ea9367d8.tar.gz infinitytier-9617208e4027bec8a72e72a1fd89aa19ea9367d8.zip |
Some cleanup, and use VERB_PUSH_DIRECT_PATHS to redirect newer peers.
Diffstat (limited to 'node')
-rw-r--r-- | node/IncomingPacket.cpp | 2 | ||||
-rw-r--r-- | node/Packet.hpp | 3 | ||||
-rw-r--r-- | node/Peer.cpp | 50 |
3 files changed, 36 insertions, 19 deletions
diff --git a/node/IncomingPacket.cpp b/node/IncomingPacket.cpp index c8526dfb..d8f458e8 100644 --- a/node/IncomingPacket.cpp +++ b/node/IncomingPacket.cpp @@ -280,8 +280,8 @@ bool IncomingPacket::_doHELLO(const RuntimeEnvironment *RR) // VALID -- if we made it here, packet passed identity and authenticity checks! - peer->received(RR,_localAddress,_remoteAddress,hops(),pid,Packet::VERB_HELLO,0,Packet::VERB_NOP); peer->setRemoteVersion(protoVersion,vMajor,vMinor,vRevision); + peer->received(RR,_localAddress,_remoteAddress,hops(),pid,Packet::VERB_HELLO,0,Packet::VERB_NOP); if (destAddr) RR->sa->iam(id.address(),_remoteAddress,destAddr,RR->topology->isRoot(id),RR->node->now()); diff --git a/node/Packet.hpp b/node/Packet.hpp index 0e8426b6..985d25d0 100644 --- a/node/Packet.hpp +++ b/node/Packet.hpp @@ -924,9 +924,6 @@ public: * 0x04 - Disable encryption (trust: privacy) * 0x08 - Disable encryption and authentication (trust: ultimate) * - * Address types and addresses are of the same format as the destination - * address type and address in HELLO. - * * The receiver may, upon receiving a push, attempt to establish a * direct link to one or more of the indicated addresses. It is the * responsibility of the sender to limit which peers it pushes direct diff --git a/node/Peer.cpp b/node/Peer.cpp index 31a20eea..f16f1421 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -85,23 +85,43 @@ void Peer::received( bool redirected = false; if ((RR->cluster)&&(hops == 0)&&(verb != Packet::VERB_OK)&&(verb != Packet::VERB_ERROR)&&(verb != Packet::VERB_RENDEZVOUS)&&(verb != Packet::VERB_PUSH_DIRECT_PATHS)) { InetAddress redirectTo(RR->cluster->findBetterEndpoint(_id.address(),remoteAddr,false)); - if (redirectTo) { - // For older peers we send RENDEZVOUS with ourselves. This will only work if we are - // a root server. - Packet outp(_id.address(),RR->identity.address(),Packet::VERB_RENDEZVOUS); - outp.append((uint8_t)0); // no flags - RR->identity.address().appendTo(outp); - outp.append((uint16_t)redirectTo.port()); - if (redirectTo.ss_family == AF_INET) { - outp.append((uint8_t)4); - outp.append(redirectTo.rawIpData(),4); + if ((redirectTo.ss_family == AF_INET)||(redirectTo.ss_family == AF_INET6)) { + if (_vProto >= 5) { + // For newer peers we can send a more idiomatic verb: PUSH_DIRECT_PATHS. + Packet outp(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS); + outp.append((uint16_t)1); // count == 1 + outp.append((uint8_t)0); // no flags + outp.append((uint16_t)0); // no extensions + if (redirectTo.ss_family == AF_INET) { + outp.append((uint8_t)4); + outp.append((uint8_t)6); + outp.append(redirectTo.rawIpData(),4); + } else { + outp.append((uint8_t)6); + outp.append((uint8_t)18); + outp.append(redirectTo.rawIpData(),16); + } + outp.append((uint16_t)redirectTo.port()); + outp.armor(_key,true); + RR->antiRec->logOutgoingZT(outp.data(),outp.size()); + RR->node->putPacket(localAddr,remoteAddr,outp.data(),outp.size()); } else { - outp.append((uint8_t)16); - outp.append(redirectTo.rawIpData(),16); + // For older peers we use RENDEZVOUS to coax them into contacting us elsewhere. + Packet outp(_id.address(),RR->identity.address(),Packet::VERB_RENDEZVOUS); + outp.append((uint8_t)0); // no flags + RR->identity.address().appendTo(outp); + outp.append((uint16_t)redirectTo.port()); + if (redirectTo.ss_family == AF_INET) { + outp.append((uint8_t)4); + outp.append(redirectTo.rawIpData(),4); + } else { + outp.append((uint8_t)16); + outp.append(redirectTo.rawIpData(),16); + } + outp.armor(_key,true); + RR->antiRec->logOutgoingZT(outp.data(),outp.size()); + RR->node->putPacket(localAddr,remoteAddr,outp.data(),outp.size()); } - outp.armor(_key,true); - RR->antiRec->logOutgoingZT(outp.data(),outp.size()); - RR->node->putPacket(localAddr,remoteAddr,outp.data(),outp.size()); redirected = true; } } |