mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Put back legacy code to listen for LAN announcements to support same network location with pre-1.0.4 clients.
This commit is contained in:
parent
d78e3bb307
commit
fe20f0d7cd
2 changed files with 26 additions and 6 deletions
|
@ -65,7 +65,8 @@ static const char *etherTypeName(const unsigned int etherType)
|
||||||
#endif // ZT_TRACE
|
#endif // ZT_TRACE
|
||||||
|
|
||||||
Switch::Switch(const RuntimeEnvironment *renv) :
|
Switch::Switch(const RuntimeEnvironment *renv) :
|
||||||
RR(renv)
|
RR(renv),
|
||||||
|
_lastBeaconResponse(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +77,25 @@ Switch::~Switch()
|
||||||
void Switch::onRemotePacket(const InetAddress &fromAddr,const void *data,unsigned int len)
|
void Switch::onRemotePacket(const InetAddress &fromAddr,const void *data,unsigned int len)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (len > ZT_PROTO_MIN_FRAGMENT_LENGTH) {
|
if (len == 13) {
|
||||||
|
/* LEGACY: before VERB_PUSH_DIRECT_PATHS, peers used broadcast
|
||||||
|
* announcements on the LAN to solve the 'same network problem.' We
|
||||||
|
* no longer send these, but we'll listen for them for a while to
|
||||||
|
* locate peers with versions <1.0.4. */
|
||||||
|
Address beaconAddr(reinterpret_cast<const char *>(data) + 8,5);
|
||||||
|
if (beaconAddr == RR->identity.address())
|
||||||
|
return;
|
||||||
|
SharedPtr<Peer> peer(RR->topology->getPeer(beaconAddr));
|
||||||
|
if (peer) { // we'll only respond to beacons from known peers
|
||||||
|
const uint64_t now = RR->node->now();
|
||||||
|
if ((now - _lastBeaconResponse) >= 2500) { // limit rate of responses
|
||||||
|
_lastBeaconResponse = now;
|
||||||
|
Packet outp(peer->address(),RR->identity.address(),Packet::VERB_NOP);
|
||||||
|
outp.armor(peer->key(),false);
|
||||||
|
RR->node->putPacket(fromAddr,outp.data(),outp.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (len > ZT_PROTO_MIN_FRAGMENT_LENGTH) {
|
||||||
if (((const unsigned char *)data)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] == ZT_PACKET_FRAGMENT_INDICATOR) {
|
if (((const unsigned char *)data)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] == ZT_PACKET_FRAGMENT_INDICATOR) {
|
||||||
_handleRemotePacketFragment(fromAddr,data,len);
|
_handleRemotePacketFragment(fromAddr,data,len);
|
||||||
} else if (len >= ZT_PROTO_MIN_PACKET_LENGTH) {
|
} else if (len >= ZT_PROTO_MIN_PACKET_LENGTH) {
|
||||||
|
|
|
@ -99,20 +99,20 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a packet to a ZeroTier address (destination in packet)
|
* Send a packet to a ZeroTier address (destination in packet)
|
||||||
*
|
*
|
||||||
* The packet must be fully composed with source and destination but not
|
* The packet must be fully composed with source and destination but not
|
||||||
* yet encrypted. If the destination peer is known the packet
|
* yet encrypted. If the destination peer is known the packet
|
||||||
* is sent immediately. Otherwise it is queued and a WHOIS is dispatched.
|
* is sent immediately. Otherwise it is queued and a WHOIS is dispatched.
|
||||||
*
|
*
|
||||||
* The packet may be compressed. Compression isn't done here.
|
* The packet may be compressed. Compression isn't done here.
|
||||||
*
|
*
|
||||||
* Needless to say, the packet's source must be this node. Otherwise it
|
* Needless to say, the packet's source must be this node. Otherwise it
|
||||||
* won't be encrypted right. (This is not used for relaying.)
|
* won't be encrypted right. (This is not used for relaying.)
|
||||||
*
|
*
|
||||||
* The network ID should only be specified for frames and other actual
|
* The network ID should only be specified for frames and other actual
|
||||||
* network traffic. Other traffic such as controller requests and regular
|
* network traffic. Other traffic such as controller requests and regular
|
||||||
* protocol messages should specify zero.
|
* protocol messages should specify zero.
|
||||||
*
|
*
|
||||||
* @param packet Packet to send
|
* @param packet Packet to send
|
||||||
* @param encrypt Encrypt packet payload? (always true except for HELLO)
|
* @param encrypt Encrypt packet payload? (always true except for HELLO)
|
||||||
* @param nwid Related network ID or 0 if message is not in-network traffic
|
* @param nwid Related network ID or 0 if message is not in-network traffic
|
||||||
|
@ -168,7 +168,7 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform retries and other periodic timer tasks
|
* Perform retries and other periodic timer tasks
|
||||||
*
|
*
|
||||||
* This can return a very long delay if there are no pending timer
|
* This can return a very long delay if there are no pending timer
|
||||||
* tasks. The caller should cap this comparatively vs. other values.
|
* tasks. The caller should cap this comparatively vs. other values.
|
||||||
*
|
*
|
||||||
|
@ -184,6 +184,7 @@ private:
|
||||||
bool _trySend(const Packet &packet,bool encrypt,uint64_t nwid);
|
bool _trySend(const Packet &packet,bool encrypt,uint64_t nwid);
|
||||||
|
|
||||||
const RuntimeEnvironment *const RR;
|
const RuntimeEnvironment *const RR;
|
||||||
|
uint64_t _lastBeaconResponse;
|
||||||
|
|
||||||
// Outsanding WHOIS requests and how many retries they've undergone
|
// Outsanding WHOIS requests and how many retries they've undergone
|
||||||
struct WhoisRequest
|
struct WhoisRequest
|
||||||
|
|
Loading…
Add table
Reference in a new issue