work on netcheck and configuration
This commit is contained in:
parent
823bcc48b9
commit
53577a4c10
@ -27,6 +27,8 @@ from defusedxml import minidom
|
|||||||
class OnionrCommunicatorDaemon:
|
class OnionrCommunicatorDaemon:
|
||||||
def __init__(self, debug, developmentMode):
|
def __init__(self, debug, developmentMode):
|
||||||
|
|
||||||
|
self.isOnline = True # Assume we're connected to the internet
|
||||||
|
|
||||||
# list of timer instances
|
# list of timer instances
|
||||||
self.timers = []
|
self.timers = []
|
||||||
|
|
||||||
@ -93,6 +95,7 @@ class OnionrCommunicatorDaemon:
|
|||||||
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
||||||
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
|
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
|
||||||
OnionrCommunicatorTimers(self, self.lookupAdders, 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)
|
announceTimer = OnionrCommunicatorTimers(self, self.daemonTools.announceNode, 305, requiresPeer=True, maxThreads=1)
|
||||||
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300, requiresPeer=True)
|
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300, requiresPeer=True)
|
||||||
|
|
||||||
|
@ -54,3 +54,12 @@ class DaemonTools:
|
|||||||
retData = True
|
retData = True
|
||||||
self.daemon.decrementThreadCount('announceNode')
|
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:
|
if not config.get('tor.v3onions') and len(adder) == 62:
|
||||||
continue
|
continue
|
||||||
if self._core.addAddress(adder):
|
if self._core.addAddress(adder):
|
||||||
logger.info('Added %s to db.' % adder, timestamp = True)
|
# Check if we have the maxmium amount of allowed stored peers
|
||||||
retVal = True
|
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:
|
else:
|
||||||
pass
|
pass
|
||||||
#logger.debug('%s is either our address or already in our DB' % adder)
|
#logger.debug('%s is either our address or already in our DB' % adder)
|
||||||
@ -631,6 +635,23 @@ class OnionrUtils:
|
|||||||
pass
|
pass
|
||||||
return data
|
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='.'):
|
def size(path='.'):
|
||||||
'''
|
'''
|
||||||
Returns the size of a folder's contents in bytes
|
Returns the size of a folder's contents in bytes
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
},
|
},
|
||||||
"peers":{
|
"peers":{
|
||||||
"minimumScore": -100,
|
"minimumScore": -100,
|
||||||
"maxStoredPeers": 500,
|
"maxStoredPeers": 5000,
|
||||||
"maxConnect": 5
|
"maxConnect": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user