do not spam dbhash
This commit is contained in:
parent
4decda916d
commit
36c2581cec
@ -80,7 +80,7 @@ class OnionrCommunicatorDaemon:
|
|||||||
OnionrCommunicatorTimers(self, self.daemonCommands, 5)
|
OnionrCommunicatorTimers(self, self.daemonCommands, 5)
|
||||||
OnionrCommunicatorTimers(self, self.detectAPICrash, 5)
|
OnionrCommunicatorTimers(self, self.detectAPICrash, 5)
|
||||||
peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60)
|
peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60)
|
||||||
OnionrCommunicatorTimers(self, self.lookupBlocks, 7, requiresPeer=True)
|
OnionrCommunicatorTimers(self, self.lookupBlocks, 7, requiresPeer=True, maxThreads=1)
|
||||||
OnionrCommunicatorTimers(self, self.getBlocks, 10, requiresPeer=True)
|
OnionrCommunicatorTimers(self, self.getBlocks, 10, requiresPeer=True)
|
||||||
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
||||||
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
|
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
|
||||||
@ -134,11 +134,19 @@ class OnionrCommunicatorDaemon:
|
|||||||
tryAmount = 2
|
tryAmount = 2
|
||||||
newBlocks = ''
|
newBlocks = ''
|
||||||
existingBlocks = self._core.getBlockList()
|
existingBlocks = self._core.getBlockList()
|
||||||
|
triedPeers = [] # list of peers we've tried this time around
|
||||||
for i in range(tryAmount):
|
for i in range(tryAmount):
|
||||||
peer = self.pickOnlinePeer() # select random online peer
|
peer = self.pickOnlinePeer() # select random online peer
|
||||||
|
# if we've already tried all the online peers this time around, stop
|
||||||
|
if peer in triedPeers:
|
||||||
|
if len(self.onlinePeers) == len(triedPeers):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
newDBHash = self.peerAction(peer, 'getDBHash') # get their db hash
|
newDBHash = self.peerAction(peer, 'getDBHash') # get their db hash
|
||||||
if newDBHash == False:
|
if newDBHash == False:
|
||||||
continue # if request failed, restart loop (peer is added to offline peers automatically)
|
continue # if request failed, restart loop (peer is added to offline peers automatically)
|
||||||
|
triedPeers.append(peer)
|
||||||
if newDBHash != self._core.getAddressInfo(peer, 'DBHash'):
|
if newDBHash != self._core.getAddressInfo(peer, 'DBHash'):
|
||||||
self._core.setAddressInfo(peer, 'DBHash', newDBHash)
|
self._core.setAddressInfo(peer, 'DBHash', newDBHash)
|
||||||
newBlocks = self.peerAction(peer, 'getBlockHashes')
|
newBlocks = self.peerAction(peer, 'getBlockHashes')
|
||||||
@ -263,7 +271,6 @@ class OnionrCommunicatorDaemon:
|
|||||||
'''Adds a new random online peer to self.onlinePeers'''
|
'''Adds a new random online peer to self.onlinePeers'''
|
||||||
retData = False
|
retData = False
|
||||||
tried = self.offlinePeers
|
tried = self.offlinePeers
|
||||||
peerScores = {}
|
|
||||||
if peer != '':
|
if peer != '':
|
||||||
if self._core._utils.validateID(peer):
|
if self._core._utils.validateID(peer):
|
||||||
peerList = [peer]
|
peerList = [peer]
|
||||||
@ -276,17 +283,13 @@ class OnionrCommunicatorDaemon:
|
|||||||
# Avoid duplicating bootstrap addresses in peerList
|
# Avoid duplicating bootstrap addresses in peerList
|
||||||
self.addBootstrapListToPeerList(peerList)
|
self.addBootstrapListToPeerList(peerList)
|
||||||
|
|
||||||
for address in peerList:
|
peerList = onionrpeers.getScoreSortedPeerList(self._core)
|
||||||
# Load peer's profiles into a list
|
|
||||||
profile = onionrpeers.PeerProfiles(address, self._core)
|
|
||||||
peerScores[address] = profile.score
|
|
||||||
|
|
||||||
# Sort peers by their score, greatest to least
|
|
||||||
peerList = sorted(peerScores, key=peerScores.get, reverse=True)
|
|
||||||
|
|
||||||
for address in peerList:
|
for address in peerList:
|
||||||
if len(address) == 0 or address in tried or address in self.onlinePeers:
|
if len(address) == 0 or address in tried or address in self.onlinePeers:
|
||||||
continue
|
continue
|
||||||
|
if self.shutdown:
|
||||||
|
return
|
||||||
if self.peerAction(address, 'ping') == 'pong!':
|
if self.peerAction(address, 'ping') == 'pong!':
|
||||||
logger.info('Connected to ' + address)
|
logger.info('Connected to ' + address)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
@ -300,7 +303,6 @@ class OnionrCommunicatorDaemon:
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
self.peerProfiles.append(onionrpeers.PeerProfiles(address, self._core))
|
self.peerProfiles.append(onionrpeers.PeerProfiles(address, self._core))
|
||||||
self.getPeerProfileInstance(address).addScore(1)
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
tried.append(address)
|
tried.append(address)
|
||||||
@ -329,7 +331,7 @@ class OnionrCommunicatorDaemon:
|
|||||||
# if request failed, (error), mark peer offline
|
# if request failed, (error), mark peer offline
|
||||||
if retData == False:
|
if retData == False:
|
||||||
try:
|
try:
|
||||||
self.getPeerProfileInstance(peer).addScore(-1)
|
self.getPeerProfileInstance(peer).addScore(-2)
|
||||||
self.onlinePeers.remove(peer)
|
self.onlinePeers.remove(peer)
|
||||||
self.getOnlinePeers() # Will only add a new peer to pool if needed
|
self.getOnlinePeers() # Will only add a new peer to pool if needed
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
Loading…
Reference in New Issue
Block a user