Browse Source

Add beacon broadcasting back into Node.

Adam Ierymenko 10 years ago
parent
commit
c9af603b9f
2 changed files with 11 additions and 0 deletions
  1. 10 0
      node/Node.cpp
  2. 1 0
      node/Node.hpp

+ 10 - 0
node/Node.cpp

@@ -73,6 +73,7 @@ Node::Node(
 	_startTimeAfterInactivity(0),
 	_lastPingCheck(0),
 	_lastHousekeepingRun(0),
+	_lastBeacon(0),
 	_coreDesperation(0)
 {
 	_newestVersionSeen[0] = ZEROTIER_ONE_VERSION_MAJOR;
@@ -252,6 +253,15 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,uint64_t *nextBackgroun
 		} catch ( ... ) {
 			return ZT1_RESULT_FATAL_ERROR_INTERNAL;
 		}
+
+		if ((now - _lastBeacon) >= ZT_BEACON_INTERVAL) {
+			_lastBeacon = now;
+			char beacon[13];
+			*(reinterpret_cast<uint32_t *>(beacon)) = RR->prng->next32();
+			*(reinterpret_cast<uint32_t *>(beacon + 4)) = RR->prng->next32();
+			RR->identity.address().copyTo(beacon + 8,5);
+			putPacket(ZT_DEFAULTS.v4Broadcast,beacon,13,0);
+		}
 	}
 
 	if ((now - _lastHousekeepingRun) >= ZT_HOUSEKEEPING_PERIOD) {

+ 1 - 0
node/Node.hpp

@@ -252,6 +252,7 @@ private:
 	uint64_t _startTimeAfterInactivity;
 	uint64_t _lastPingCheck;
 	uint64_t _lastHousekeepingRun;
+	uint64_t _lastBeacon;
 	unsigned int _coreDesperation;
 	unsigned int _newestVersionSeen[3]; // major, minor, revision
 	bool _online;