Peer.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2018 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * You can be released from the requirements of the license by purchasing
  21. * a commercial license. Buying such a license is mandatory as soon as you
  22. * develop commercial closed-source software that incorporates or links
  23. * directly against ZeroTier software without disclosing the source code
  24. * of your own application.
  25. */
  26. #include "../version.h"
  27. #include "Constants.hpp"
  28. #include "Peer.hpp"
  29. #include "Node.hpp"
  30. #include "Switch.hpp"
  31. #include "Network.hpp"
  32. #include "SelfAwareness.hpp"
  33. #include "Packet.hpp"
  34. #include "Trace.hpp"
  35. #include "InetAddress.hpp"
  36. namespace ZeroTier {
  37. Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Identity &peerIdentity) :
  38. RR(renv),
  39. _lastReceive(0),
  40. _lastNontrivialReceive(0),
  41. _lastTriedMemorizedPath(0),
  42. _lastDirectPathPushSent(0),
  43. _lastDirectPathPushReceive(0),
  44. _lastCredentialRequestSent(0),
  45. _lastWhoisRequestReceived(0),
  46. _lastEchoRequestReceived(0),
  47. _lastComRequestReceived(0),
  48. _lastComRequestSent(0),
  49. _lastCredentialsReceived(0),
  50. _lastTrustEstablishedPacketReceived(0),
  51. _lastSentFullHello(0),
  52. _vProto(0),
  53. _vMajor(0),
  54. _vMinor(0),
  55. _vRevision(0),
  56. _id(peerIdentity),
  57. _directPathPushCutoffCount(0),
  58. _credentialsCutoffCount(0)
  59. {
  60. if (!myIdentity.agree(peerIdentity,_key,ZT_PEER_SECRET_KEY_LENGTH))
  61. throw ZT_EXCEPTION_INVALID_ARGUMENT;
  62. }
  63. void Peer::received(
  64. void *tPtr,
  65. const SharedPtr<Path> &path,
  66. const unsigned int hops,
  67. const uint64_t packetId,
  68. const Packet::Verb verb,
  69. const uint64_t inRePacketId,
  70. const Packet::Verb inReVerb,
  71. const bool trustEstablished,
  72. const uint64_t networkId)
  73. {
  74. const int64_t now = RR->node->now();
  75. _lastReceive = now;
  76. switch (verb) {
  77. case Packet::VERB_FRAME:
  78. case Packet::VERB_EXT_FRAME:
  79. case Packet::VERB_NETWORK_CONFIG_REQUEST:
  80. case Packet::VERB_NETWORK_CONFIG:
  81. case Packet::VERB_MULTICAST_FRAME:
  82. _lastNontrivialReceive = now;
  83. break;
  84. default: break;
  85. }
  86. if (trustEstablished) {
  87. _lastTrustEstablishedPacketReceived = now;
  88. path->trustedPacketReceived(now);
  89. }
  90. if (hops == 0) {
  91. // If this is a direct packet (no hops), update existing paths or learn new ones
  92. bool havePath = false;
  93. {
  94. Mutex::Lock _l(_paths_m);
  95. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  96. if (_paths[i].p) {
  97. if (_paths[i].p == path) {
  98. _paths[i].lr = now;
  99. havePath = true;
  100. break;
  101. }
  102. } else break;
  103. }
  104. }
  105. bool attemptToContact = false;
  106. if ((!havePath)&&(RR->node->shouldUsePathForZeroTierTraffic(tPtr,_id.address(),path->localSocket(),path->address()))) {
  107. Mutex::Lock _l(_paths_m);
  108. // Paths are redunant if they duplicate an alive path to the same IP or
  109. // with the same local socket and address family.
  110. bool redundant = false;
  111. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  112. if (_paths[i].p) {
  113. if ( (_paths[i].p->alive(now)) && ( ((_paths[i].p->localSocket() == path->localSocket())&&(_paths[i].p->address().ss_family == path->address().ss_family)) || (_paths[i].p->address().ipsEqual2(path->address())) ) ) {
  114. redundant = true;
  115. break;
  116. }
  117. } else break;
  118. }
  119. if (!redundant) {
  120. unsigned int replacePath = ZT_MAX_PEER_NETWORK_PATHS;
  121. int replacePathQuality = 0;
  122. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  123. if (_paths[i].p) {
  124. const int q = _paths[i].p->quality(now);
  125. if (q > replacePathQuality) {
  126. replacePathQuality = q;
  127. replacePath = i;
  128. }
  129. } else {
  130. replacePath = i;
  131. break;
  132. }
  133. }
  134. if (replacePath != ZT_MAX_PEER_NETWORK_PATHS) {
  135. if (verb == Packet::VERB_OK) {
  136. RR->t->peerLearnedNewPath(tPtr,networkId,*this,path,packetId);
  137. _paths[replacePath].lr = now;
  138. _paths[replacePath].p = path;
  139. _paths[replacePath].priority = 1;
  140. } else {
  141. attemptToContact = true;
  142. }
  143. }
  144. }
  145. }
  146. if (attemptToContact) {
  147. attemptToContactAt(tPtr,path->localSocket(),path->address(),now,true);
  148. path->sent(now);
  149. RR->t->peerConfirmingUnknownPath(tPtr,networkId,*this,path,packetId,verb);
  150. }
  151. }
  152. // If we have a trust relationship periodically push a message enumerating
  153. // all known external addresses for ourselves. We now do this even if we
  154. // have a current path since we'll want to use new ones too.
  155. if (this->trustEstablished(now)) {
  156. if ((now - _lastDirectPathPushSent) >= ZT_DIRECT_PATH_PUSH_INTERVAL) {
  157. _lastDirectPathPushSent = now;
  158. std::vector<InetAddress> pathsToPush;
  159. std::vector<InetAddress> dps(RR->node->directPaths());
  160. for(std::vector<InetAddress>::const_iterator i(dps.begin());i!=dps.end();++i)
  161. pathsToPush.push_back(*i);
  162. // Do symmetric NAT prediction if we are communicating indirectly.
  163. if (hops > 0) {
  164. std::vector<InetAddress> sym(RR->sa->getSymmetricNatPredictions());
  165. for(unsigned long i=0,added=0;i<sym.size();++i) {
  166. InetAddress tmp(sym[(unsigned long)RR->node->prng() % sym.size()]);
  167. if (std::find(pathsToPush.begin(),pathsToPush.end(),tmp) == pathsToPush.end()) {
  168. pathsToPush.push_back(tmp);
  169. if (++added >= ZT_PUSH_DIRECT_PATHS_MAX_PER_SCOPE_AND_FAMILY)
  170. break;
  171. }
  172. }
  173. }
  174. if (pathsToPush.size() > 0) {
  175. std::vector<InetAddress>::const_iterator p(pathsToPush.begin());
  176. while (p != pathsToPush.end()) {
  177. Packet outp(_id.address(),RR->identity.address(),Packet::VERB_PUSH_DIRECT_PATHS);
  178. outp.addSize(2); // leave room for count
  179. unsigned int count = 0;
  180. while ((p != pathsToPush.end())&&((outp.size() + 24) < 1200)) {
  181. uint8_t addressType = 4;
  182. switch(p->ss_family) {
  183. case AF_INET:
  184. break;
  185. case AF_INET6:
  186. addressType = 6;
  187. break;
  188. default: // we currently only push IP addresses
  189. ++p;
  190. continue;
  191. }
  192. outp.append((uint8_t)0); // no flags
  193. outp.append((uint16_t)0); // no extensions
  194. outp.append(addressType);
  195. outp.append((uint8_t)((addressType == 4) ? 6 : 18));
  196. outp.append(p->rawIpData(),((addressType == 4) ? 4 : 16));
  197. outp.append((uint16_t)p->port());
  198. ++count;
  199. ++p;
  200. }
  201. if (count) {
  202. outp.setAt(ZT_PACKET_IDX_PAYLOAD,(uint16_t)count);
  203. outp.armor(_key,true);
  204. path->send(RR,tPtr,outp.data(),outp.size(),now);
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. SharedPtr<Path> Peer::getBestPath(int64_t now,bool includeExpired) const
  212. {
  213. Mutex::Lock _l(_paths_m);
  214. unsigned int bestPath = ZT_MAX_PEER_NETWORK_PATHS;
  215. long bestPathQuality = 2147483647;
  216. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  217. if (_paths[i].p) {
  218. if ((includeExpired)||((now - _paths[i].lr) < ZT_PEER_PATH_EXPIRATION)) {
  219. const long q = _paths[i].p->quality(now) / _paths[i].priority;
  220. if (q <= bestPathQuality) {
  221. bestPathQuality = q;
  222. bestPath = i;
  223. }
  224. }
  225. } else break;
  226. }
  227. if (bestPath != ZT_MAX_PEER_NETWORK_PATHS)
  228. return _paths[bestPath].p;
  229. return SharedPtr<Path>();
  230. }
  231. void Peer::introduce(void *const tPtr,const int64_t now,const SharedPtr<Peer> &other) const
  232. {
  233. unsigned int myBestV4ByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  234. unsigned int myBestV6ByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  235. long myBestV4QualityByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  236. long myBestV6QualityByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  237. unsigned int theirBestV4ByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  238. unsigned int theirBestV6ByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  239. long theirBestV4QualityByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  240. long theirBestV6QualityByScope[ZT_INETADDRESS_MAX_SCOPE+1];
  241. for(int i=0;i<=ZT_INETADDRESS_MAX_SCOPE;++i) {
  242. myBestV4ByScope[i] = ZT_MAX_PEER_NETWORK_PATHS;
  243. myBestV6ByScope[i] = ZT_MAX_PEER_NETWORK_PATHS;
  244. myBestV4QualityByScope[i] = 2147483647;
  245. myBestV6QualityByScope[i] = 2147483647;
  246. theirBestV4ByScope[i] = ZT_MAX_PEER_NETWORK_PATHS;
  247. theirBestV6ByScope[i] = ZT_MAX_PEER_NETWORK_PATHS;
  248. theirBestV4QualityByScope[i] = 2147483647;
  249. theirBestV6QualityByScope[i] = 2147483647;
  250. }
  251. Mutex::Lock _l1(_paths_m);
  252. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  253. if (_paths[i].p) {
  254. const long q = _paths[i].p->quality(now) / _paths[i].priority;
  255. const unsigned int s = (unsigned int)_paths[i].p->ipScope();
  256. switch(_paths[i].p->address().ss_family) {
  257. case AF_INET:
  258. if (q <= myBestV4QualityByScope[s]) {
  259. myBestV4QualityByScope[s] = q;
  260. myBestV4ByScope[s] = i;
  261. }
  262. break;
  263. case AF_INET6:
  264. if (q <= myBestV6QualityByScope[s]) {
  265. myBestV6QualityByScope[s] = q;
  266. myBestV6ByScope[s] = i;
  267. }
  268. break;
  269. }
  270. } else break;
  271. }
  272. Mutex::Lock _l2(other->_paths_m);
  273. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  274. if (other->_paths[i].p) {
  275. const long q = other->_paths[i].p->quality(now) / other->_paths[i].priority;
  276. const unsigned int s = (unsigned int)other->_paths[i].p->ipScope();
  277. switch(other->_paths[i].p->address().ss_family) {
  278. case AF_INET:
  279. if (q <= theirBestV4QualityByScope[s]) {
  280. theirBestV4QualityByScope[s] = q;
  281. theirBestV4ByScope[s] = i;
  282. }
  283. break;
  284. case AF_INET6:
  285. if (q <= theirBestV6QualityByScope[s]) {
  286. theirBestV6QualityByScope[s] = q;
  287. theirBestV6ByScope[s] = i;
  288. }
  289. break;
  290. }
  291. } else break;
  292. }
  293. unsigned int mine = ZT_MAX_PEER_NETWORK_PATHS;
  294. unsigned int theirs = ZT_MAX_PEER_NETWORK_PATHS;
  295. for(int s=ZT_INETADDRESS_MAX_SCOPE;s>=0;--s) {
  296. if ((myBestV6ByScope[s] != ZT_MAX_PEER_NETWORK_PATHS)&&(theirBestV6ByScope[s] != ZT_MAX_PEER_NETWORK_PATHS)) {
  297. mine = myBestV6ByScope[s];
  298. theirs = theirBestV6ByScope[s];
  299. break;
  300. }
  301. if ((myBestV4ByScope[s] != ZT_MAX_PEER_NETWORK_PATHS)&&(theirBestV4ByScope[s] != ZT_MAX_PEER_NETWORK_PATHS)) {
  302. mine = myBestV4ByScope[s];
  303. theirs = theirBestV4ByScope[s];
  304. break;
  305. }
  306. }
  307. if (mine != ZT_MAX_PEER_NETWORK_PATHS) {
  308. unsigned int alt = (unsigned int)RR->node->prng() & 1; // randomize which hint we send first for black magickal NAT-t reasons
  309. const unsigned int completed = alt + 2;
  310. while (alt != completed) {
  311. if ((alt & 1) == 0) {
  312. Packet outp(_id.address(),RR->identity.address(),Packet::VERB_RENDEZVOUS);
  313. outp.append((uint8_t)0);
  314. other->_id.address().appendTo(outp);
  315. outp.append((uint16_t)other->_paths[theirs].p->address().port());
  316. if (other->_paths[theirs].p->address().ss_family == AF_INET6) {
  317. outp.append((uint8_t)16);
  318. outp.append(other->_paths[theirs].p->address().rawIpData(),16);
  319. } else {
  320. outp.append((uint8_t)4);
  321. outp.append(other->_paths[theirs].p->address().rawIpData(),4);
  322. }
  323. outp.armor(_key,true);
  324. _paths[mine].p->send(RR,tPtr,outp.data(),outp.size(),now);
  325. } else {
  326. Packet outp(other->_id.address(),RR->identity.address(),Packet::VERB_RENDEZVOUS);
  327. outp.append((uint8_t)0);
  328. _id.address().appendTo(outp);
  329. outp.append((uint16_t)_paths[mine].p->address().port());
  330. if (_paths[mine].p->address().ss_family == AF_INET6) {
  331. outp.append((uint8_t)16);
  332. outp.append(_paths[mine].p->address().rawIpData(),16);
  333. } else {
  334. outp.append((uint8_t)4);
  335. outp.append(_paths[mine].p->address().rawIpData(),4);
  336. }
  337. outp.armor(other->_key,true);
  338. other->_paths[theirs].p->send(RR,tPtr,outp.data(),outp.size(),now);
  339. }
  340. ++alt;
  341. }
  342. }
  343. }
  344. void Peer::sendHELLO(void *tPtr,const int64_t localSocket,const InetAddress &atAddress,int64_t now)
  345. {
  346. Packet outp(_id.address(),RR->identity.address(),Packet::VERB_HELLO);
  347. outp.append((unsigned char)ZT_PROTO_VERSION);
  348. outp.append((unsigned char)ZEROTIER_ONE_VERSION_MAJOR);
  349. outp.append((unsigned char)ZEROTIER_ONE_VERSION_MINOR);
  350. outp.append((uint16_t)ZEROTIER_ONE_VERSION_REVISION);
  351. outp.append(now);
  352. RR->identity.serialize(outp,false);
  353. atAddress.serialize(outp);
  354. outp.append((uint64_t)RR->topology->planetWorldId());
  355. outp.append((uint64_t)RR->topology->planetWorldTimestamp());
  356. const unsigned int startCryptedPortionAt = outp.size();
  357. std::vector<World> moons(RR->topology->moons());
  358. std::vector<uint64_t> moonsWanted(RR->topology->moonsWanted());
  359. outp.append((uint16_t)(moons.size() + moonsWanted.size()));
  360. for(std::vector<World>::const_iterator m(moons.begin());m!=moons.end();++m) {
  361. outp.append((uint8_t)m->type());
  362. outp.append((uint64_t)m->id());
  363. outp.append((uint64_t)m->timestamp());
  364. }
  365. for(std::vector<uint64_t>::const_iterator m(moonsWanted.begin());m!=moonsWanted.end();++m) {
  366. outp.append((uint8_t)World::TYPE_MOON);
  367. outp.append(*m);
  368. outp.append((uint64_t)0);
  369. }
  370. outp.cryptField(_key,startCryptedPortionAt,outp.size() - startCryptedPortionAt);
  371. RR->node->expectReplyTo(outp.packetId());
  372. if (atAddress) {
  373. outp.armor(_key,false); // false == don't encrypt full payload, but add MAC
  374. RR->node->putPacket(tPtr,localSocket,atAddress,outp.data(),outp.size());
  375. } else {
  376. RR->sw->send(tPtr,outp,false); // false == don't encrypt full payload, but add MAC
  377. }
  378. }
  379. void Peer::attemptToContactAt(void *tPtr,const int64_t localSocket,const InetAddress &atAddress,int64_t now,bool sendFullHello)
  380. {
  381. if ( (!sendFullHello) && (_vProto >= 5) && (!((_vMajor == 1)&&(_vMinor == 1)&&(_vRevision == 0))) ) {
  382. Packet outp(_id.address(),RR->identity.address(),Packet::VERB_ECHO);
  383. RR->node->expectReplyTo(outp.packetId());
  384. outp.armor(_key,true);
  385. RR->node->putPacket(tPtr,localSocket,atAddress,outp.data(),outp.size());
  386. } else {
  387. sendHELLO(tPtr,localSocket,atAddress,now);
  388. }
  389. }
  390. void Peer::tryMemorizedPath(void *tPtr,int64_t now)
  391. {
  392. if ((now - _lastTriedMemorizedPath) >= ZT_TRY_MEMORIZED_PATH_INTERVAL) {
  393. _lastTriedMemorizedPath = now;
  394. InetAddress mp;
  395. if (RR->node->externalPathLookup(tPtr,_id.address(),-1,mp))
  396. attemptToContactAt(tPtr,-1,mp,now,true);
  397. }
  398. }
  399. unsigned int Peer::doPingAndKeepalive(void *tPtr,int64_t now)
  400. {
  401. unsigned int sent = 0;
  402. Mutex::Lock _l(_paths_m);
  403. const bool sendFullHello = ((now - _lastSentFullHello) >= ZT_PEER_PING_PERIOD);
  404. _lastSentFullHello = now;
  405. // Right now we only keep pinging links that have the maximum priority. The
  406. // priority is used to track cluster redirections, meaning that when a cluster
  407. // redirects us its redirect target links override all other links and we
  408. // let those old links expire.
  409. long maxPriority = 0;
  410. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  411. if (_paths[i].p)
  412. maxPriority = std::max(_paths[i].priority,maxPriority);
  413. else break;
  414. }
  415. unsigned int j = 0;
  416. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  417. if (_paths[i].p) {
  418. // Clean expired and reduced priority paths
  419. if ( ((now - _paths[i].lr) < ZT_PEER_PATH_EXPIRATION) && (_paths[i].priority == maxPriority) ) {
  420. if ((sendFullHello)||(_paths[i].p->needsHeartbeat(now))) {
  421. attemptToContactAt(tPtr,_paths[i].p->localSocket(),_paths[i].p->address(),now,sendFullHello);
  422. _paths[i].p->sent(now);
  423. sent |= (_paths[i].p->address().ss_family == AF_INET) ? 0x1 : 0x2;
  424. }
  425. if (i != j)
  426. _paths[j] = _paths[i];
  427. ++j;
  428. }
  429. } else break;
  430. }
  431. while(j < ZT_MAX_PEER_NETWORK_PATHS) {
  432. _paths[j].lr = 0;
  433. _paths[j].p.zero();
  434. _paths[j].priority = 1;
  435. ++j;
  436. }
  437. return sent;
  438. }
  439. void Peer::clusterRedirect(void *tPtr,const SharedPtr<Path> &originatingPath,const InetAddress &remoteAddress,const int64_t now)
  440. {
  441. SharedPtr<Path> np(RR->topology->getPath(originatingPath->localSocket(),remoteAddress));
  442. RR->t->peerRedirected(tPtr,0,*this,np);
  443. attemptToContactAt(tPtr,originatingPath->localSocket(),remoteAddress,now,true);
  444. {
  445. Mutex::Lock _l(_paths_m);
  446. // New priority is higher than the priority of the originating path (if known)
  447. long newPriority = 1;
  448. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  449. if (_paths[i].p) {
  450. if (_paths[i].p == originatingPath) {
  451. newPriority = _paths[i].priority;
  452. break;
  453. }
  454. } else break;
  455. }
  456. newPriority += 2;
  457. // Erase any paths with lower priority than this one or that are duplicate
  458. // IPs and add this path.
  459. unsigned int j = 0;
  460. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  461. if (_paths[i].p) {
  462. if ((_paths[i].priority >= newPriority)&&(!_paths[i].p->address().ipsEqual2(remoteAddress))) {
  463. if (i != j)
  464. _paths[j] = _paths[i];
  465. ++j;
  466. }
  467. }
  468. }
  469. if (j < ZT_MAX_PEER_NETWORK_PATHS) {
  470. _paths[j].lr = now;
  471. _paths[j].p = np;
  472. _paths[j].priority = newPriority;
  473. ++j;
  474. while (j < ZT_MAX_PEER_NETWORK_PATHS) {
  475. _paths[j].lr = 0;
  476. _paths[j].p.zero();
  477. _paths[j].priority = 1;
  478. ++j;
  479. }
  480. }
  481. }
  482. }
  483. void Peer::resetWithinScope(void *tPtr,InetAddress::IpScope scope,int inetAddressFamily,int64_t now)
  484. {
  485. Mutex::Lock _l(_paths_m);
  486. for(unsigned int i=0;i<ZT_MAX_PEER_NETWORK_PATHS;++i) {
  487. if (_paths[i].p) {
  488. if ((_paths[i].p->address().ss_family == inetAddressFamily)&&(_paths[i].p->ipScope() == scope)) {
  489. attemptToContactAt(tPtr,_paths[i].p->localSocket(),_paths[i].p->address(),now,false);
  490. _paths[i].p->sent(now);
  491. _paths[i].lr = 0; // path will not be used unless it speaks again
  492. }
  493. } else break;
  494. }
  495. }
  496. } // namespace ZeroTier