work on netcheck and configuration
This commit is contained in:
parent
823bcc48b9
commit
53577a4c10
@ -27,6 +27,8 @@ from defusedxml import minidom
|
||||
class OnionrCommunicatorDaemon:
|
||||
def __init__(self, debug, developmentMode):
|
||||
|
||||
self.isOnline = True # Assume we're connected to the internet
|
||||
|
||||
# list of timer instances
|
||||
self.timers = []
|
||||
|
||||
@ -93,6 +95,7 @@ class OnionrCommunicatorDaemon:
|
||||
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
||||
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
|
||||
OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True)
|
||||
netCheckTimer = OnionrCommunicatorTimers(self, self.daemonTools.netCheck, 600)
|
||||
announceTimer = OnionrCommunicatorTimers(self, self.daemonTools.announceNode, 305, requiresPeer=True, maxThreads=1)
|
||||
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300, requiresPeer=True)
|
||||
|
||||
|
@ -53,4 +53,13 @@ class DaemonTools:
|
||||
if self.daemon._core._utils.doPostRequest(url, data) == 'Success':
|
||||
retData = True
|
||||
self.daemon.decrementThreadCount('announceNode')
|
||||
return retData
|
||||
return retData
|
||||
|
||||
def netCheck(self):
|
||||
'''Check if we are connected to the internet or not when we can't connect to any peers'''
|
||||
if len(self.daemon.onlinePeers) != 0:
|
||||
if not self.daemon._core._utils.checkNetwork():
|
||||
logger.warn('Network check failed, are you connected to the internet?')
|
||||
self.daemon.isOnline = False
|
||||
|
||||
self.daemon.decrementThreadCount('netCheck')
|
@ -131,8 +131,12 @@ class OnionrUtils:
|
||||
if not config.get('tor.v3onions') and len(adder) == 62:
|
||||
continue
|
||||
if self._core.addAddress(adder):
|
||||
logger.info('Added %s to db.' % adder, timestamp = True)
|
||||
retVal = True
|
||||
# Check if we have the maxmium amount of allowed stored peers
|
||||
if config.get('peers.maxStoredPeers') > len(self._core.listAdders):
|
||||
logger.info('Added %s to db.' % adder, timestamp = True)
|
||||
retVal = True
|
||||
else:
|
||||
logger.warn('Reached the maximum amount of peers in the net database as allowed by your config.')
|
||||
else:
|
||||
pass
|
||||
#logger.debug('%s is either our address or already in our DB' % adder)
|
||||
@ -630,6 +634,23 @@ class OnionrUtils:
|
||||
except AttributeError:
|
||||
pass
|
||||
return data
|
||||
|
||||
def checkNetwork(self):
|
||||
'''Check if we are connected to the internet (through Tor)'''
|
||||
retData = False
|
||||
connectURLs = []
|
||||
try:
|
||||
with open('static-data/connect-check.txt', 'r') as connectTest:
|
||||
connectURLs = connectTest.read().split(',')
|
||||
|
||||
for url in connectURLs:
|
||||
if self.doGetRequest(url) != False:
|
||||
retData = True
|
||||
break
|
||||
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return retData
|
||||
|
||||
def size(path='.'):
|
||||
'''
|
||||
@ -655,4 +676,4 @@ def humanSize(num, suffix='B'):
|
||||
if abs(num) < 1024.0:
|
||||
return "%.1f %s%s" % (num, unit, suffix)
|
||||
num /= 1024.0
|
||||
return "%.1f %s%s" % (num, 'Yi', suffix)
|
||||
return "%.1f %s%s" % (num, 'Yi', suffix)
|
@ -58,7 +58,7 @@
|
||||
},
|
||||
"peers":{
|
||||
"minimumScore": -100,
|
||||
"maxStoredPeers": 500,
|
||||
"maxStoredPeers": 5000,
|
||||
"maxConnect": 5
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user