Re-resolve DNS on failed peer ready for testing
This commit is contained in:
parent
ae393bc66d
commit
a8633090e4
@ -205,6 +205,7 @@ def build_config(_config_file):
|
|||||||
'PORT': config.getint(section, 'PORT'),
|
'PORT': config.getint(section, 'PORT'),
|
||||||
'MASTER_SOCKADDR': (gethostbyname(config.get(section, 'MASTER_IP')), config.getint(section, 'MASTER_PORT')),
|
'MASTER_SOCKADDR': (gethostbyname(config.get(section, 'MASTER_IP')), config.getint(section, 'MASTER_PORT')),
|
||||||
'MASTER_IP': gethostbyname(config.get(section, 'MASTER_IP')),
|
'MASTER_IP': gethostbyname(config.get(section, 'MASTER_IP')),
|
||||||
|
'_MASTER_IP': config.get(section, 'MASTER_IP'),
|
||||||
'MASTER_PORT': config.getint(section, 'MASTER_PORT'),
|
'MASTER_PORT': config.getint(section, 'MASTER_PORT'),
|
||||||
'PASSPHRASE': bytes(config.get(section, 'PASSPHRASE'), 'utf-8'),
|
'PASSPHRASE': bytes(config.get(section, 'PASSPHRASE'), 'utf-8'),
|
||||||
'CALLSIGN': bytes(config.get(section, 'CALLSIGN').ljust(8)[:8], 'utf-8'),
|
'CALLSIGN': bytes(config.get(section, 'CALLSIGN').ljust(8)[:8], 'utf-8'),
|
||||||
|
15
hblink.py
15
hblink.py
@ -306,6 +306,7 @@ class HBSYSTEM(DatagramProtocol):
|
|||||||
|
|
||||||
elif self._config['MODE'] == 'PEER':
|
elif self._config['MODE'] == 'PEER':
|
||||||
self._stats = self._config['STATS']
|
self._stats = self._config['STATS']
|
||||||
|
self._stats['DNS_TIME'] = time()
|
||||||
self.send_system = self.send_master
|
self.send_system = self.send_master
|
||||||
self.maintenance_loop = self.peer_maintenance_loop
|
self.maintenance_loop = self.peer_maintenance_loop
|
||||||
self.datagramReceived = self.peer_datagramReceived
|
self.datagramReceived = self.peer_datagramReceived
|
||||||
@ -318,10 +319,14 @@ class HBSYSTEM(DatagramProtocol):
|
|||||||
self.datagramReceived = self.peer_datagramReceived
|
self.datagramReceived = self.peer_datagramReceived
|
||||||
self.dereg = self.peer_dereg
|
self.dereg = self.peer_dereg
|
||||||
|
|
||||||
|
def loopingErrHandle(self,failure):
|
||||||
|
logger.error('(GLOBAL - hblink.py) Unhandled error in timed loop.\n %s', failure)
|
||||||
|
|
||||||
def startProtocol(self):
|
def startProtocol(self):
|
||||||
# Set up periodic loop for tracking pings from peers. Run every 'PING_TIME' seconds
|
# Set up periodic loop for tracking pings from peers. Run every 'PING_TIME' seconds
|
||||||
self._system_maintenance = task.LoopingCall(self.maintenance_loop)
|
self._system_maintenance = task.LoopingCall(self.maintenance_loop)
|
||||||
self._system_maintenance_loop = self._system_maintenance.start(self._CONFIG['GLOBAL']['PING_TIME'])
|
self._system_maintenance_loop = self._system_maintenance.start(self._CONFIG['GLOBAL']['PING_TIME'])
|
||||||
|
self._system_maintenance_loop.addErrback(self.loopingErrHandle)
|
||||||
|
|
||||||
# Aliased in __init__ to maintenance_loop if system is a master
|
# Aliased in __init__ to maintenance_loop if system is a master
|
||||||
def master_maintenance_loop(self):
|
def master_maintenance_loop(self):
|
||||||
@ -357,11 +362,11 @@ class HBSYSTEM(DatagramProtocol):
|
|||||||
self._stats['NUM_OUTSTANDING'] = 0
|
self._stats['NUM_OUTSTANDING'] = 0
|
||||||
self._stats['PING_OUTSTANDING'] = False
|
self._stats['PING_OUTSTANDING'] = False
|
||||||
self._stats['CONNECTION'] = 'RPTL_SENT'
|
self._stats['CONNECTION'] = 'RPTL_SENT'
|
||||||
if self._stats['DNS_TIME'] < (time() - 1):
|
if self._stats['DNS_TIME'] < (time() - 600):
|
||||||
self._stats['DNS_TIME'] = time()
|
self._stats['DNS_TIME'] = time()
|
||||||
_d = client.getHostByName(self._config['_MASTER_IP'])
|
_d = client.getHostByName(self._config['_MASTER_IP'])
|
||||||
_d.addCallback(self.updateSockaddr)
|
_d.addCallback(self.updateSockaddr)
|
||||||
_d.addErrback(self,_d)
|
_d.addErrback(self.updateSockaddr_errback)
|
||||||
self.send_master(b''.join([RPTL, self._config['RADIO_ID']]))
|
self.send_master(b''.join([RPTL, self._config['RADIO_ID']]))
|
||||||
logger.info('(%s) Sending login request to master %s:%s', self._system, self._config['MASTER_IP'], self._config['MASTER_PORT'])
|
logger.info('(%s) Sending login request to master %s:%s', self._system, self._config['MASTER_IP'], self._config['MASTER_PORT'])
|
||||||
# If we are connected, sent a ping to the master and increment the counter
|
# If we are connected, sent a ping to the master and increment the counter
|
||||||
@ -374,10 +379,10 @@ class HBSYSTEM(DatagramProtocol):
|
|||||||
def updateSockaddr(self,ip):
|
def updateSockaddr(self,ip):
|
||||||
self._config['MASTER_IP'] = ip
|
self._config['MASTER_IP'] = ip
|
||||||
self._config['MASTER_SOCKADDR'] = (ip, self._config['MASTER_PORT'])
|
self._config['MASTER_SOCKADDR'] = (ip, self._config['MASTER_PORT'])
|
||||||
logger.debug('(%s) hostname resolution performed',self._system)
|
logger.debug('(%s) hostname resolution performed: %s',self._system,ip)
|
||||||
|
|
||||||
def updateSockaddr_errback(self,d):
|
def updateSockaddr_errback(self,failure):
|
||||||
logger.debug('(%s) hostname resolution error',self._system)
|
logger.debug('(%s) hostname resolution error: %s',self._system,failure)
|
||||||
|
|
||||||
def send_peers(self, _packet):
|
def send_peers(self, _packet):
|
||||||
for _peer in self._peers:
|
for _peer in self._peers:
|
||||||
|
Loading…
Reference in New Issue
Block a user