+ remove peers who do not meet the minimum score
* minor bug fixes and documentation improvements * do not cleanup peers if we have no online peers (probably not connected anyway) * do not run peer cleanup until a min * do not spam block list on shutdown during block sync * use correct thread decrement in peerCleanup * added trust int to address table, not used yetmaster
parent
032aa780ef
commit
8694ab078e
|
@ -77,6 +77,7 @@ class OnionrCommunicatorDaemon:
|
||||||
self.header()
|
self.header()
|
||||||
|
|
||||||
# Set timers, function reference, seconds
|
# Set timers, function reference, seconds
|
||||||
|
# requiresPeer True means the timer function won't fire if we have no connected peers
|
||||||
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)
|
||||||
|
@ -85,11 +86,11 @@ 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)
|
||||||
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300)
|
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300, requiresPeer=True)
|
||||||
|
|
||||||
# set loop to execute instantly to load up peer pool (replaced old pool init wait)
|
# set loop to execute instantly to load up peer pool (replaced old pool init wait)
|
||||||
peerPoolTimer.count = (peerPoolTimer.frequency - 1)
|
peerPoolTimer.count = (peerPoolTimer.frequency - 1)
|
||||||
cleanupTimer = (cleanupTimer.frequency - 200)
|
cleanupTimer.count = (cleanupTimer.frequency - 60)
|
||||||
|
|
||||||
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
|
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
|
||||||
try:
|
try:
|
||||||
|
@ -171,6 +172,8 @@ class OnionrCommunicatorDaemon:
|
||||||
def getBlocks(self):
|
def getBlocks(self):
|
||||||
'''download new blocks in queue'''
|
'''download new blocks in queue'''
|
||||||
for blockHash in self.blockQueue:
|
for blockHash in self.blockQueue:
|
||||||
|
if self.shutdown:
|
||||||
|
break
|
||||||
if blockHash in self.currentDownloading:
|
if blockHash in self.currentDownloading:
|
||||||
logger.debug('ALREADY DOWNLOADING ' + blockHash)
|
logger.debug('ALREADY DOWNLOADING ' + blockHash)
|
||||||
continue
|
continue
|
||||||
|
@ -320,7 +323,7 @@ class OnionrCommunicatorDaemon:
|
||||||
def peerCleanup(self):
|
def peerCleanup(self):
|
||||||
'''This just calls onionrpeers.cleanupPeers, which removes dead or bad peers (offline too long, too slow)'''
|
'''This just calls onionrpeers.cleanupPeers, which removes dead or bad peers (offline too long, too slow)'''
|
||||||
onionrpeers.peerCleanup(self._core)
|
onionrpeers.peerCleanup(self._core)
|
||||||
self.decrementThreadCount('getOnlinePeers')
|
self.decrementThreadCount('peerCleanup')
|
||||||
|
|
||||||
def printOnlinePeers(self):
|
def printOnlinePeers(self):
|
||||||
'''logs online peer list'''
|
'''logs online peer list'''
|
||||||
|
|
|
@ -200,7 +200,8 @@ class Core:
|
||||||
powValue text,
|
powValue text,
|
||||||
failure int,
|
failure int,
|
||||||
lastConnect int,
|
lastConnect int,
|
||||||
lastConnectAttempt int
|
lastConnectAttempt int,
|
||||||
|
trust int
|
||||||
);
|
);
|
||||||
''')
|
''')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import core
|
import core, config, logger
|
||||||
class PeerProfiles:
|
class PeerProfiles:
|
||||||
'''
|
'''
|
||||||
PeerProfiles
|
PeerProfiles
|
||||||
|
@ -72,8 +72,20 @@ def getScoreSortedPeerList(coreInst):
|
||||||
return peerList
|
return peerList
|
||||||
|
|
||||||
def peerCleanup(coreInst):
|
def peerCleanup(coreInst):
|
||||||
# TODO, remove peers that have been offline for too long
|
'''Removes peers who have been offline too long'''
|
||||||
if not type(coreInst is core.Core):
|
if not type(coreInst is core.Core):
|
||||||
raise TypeError('coreInst must be instance of core.Core')
|
raise TypeError('coreInst must be instance of core.Core')
|
||||||
|
|
||||||
|
logger.info('Cleaning peers...')
|
||||||
|
|
||||||
|
minScore = int(config.get('peers.minimumScore'))
|
||||||
|
maxPeers = int(config.get('peers.maxStoredPeers'))
|
||||||
|
|
||||||
|
adders = getScoreSortedPeerList(coreInst)
|
||||||
|
adders.reverse()
|
||||||
|
|
||||||
|
for address in adders:
|
||||||
|
# Remove peers that go below the negative score
|
||||||
|
if PeerProfiles(address, coreInst).score < minScore:
|
||||||
|
coreInst.removeAddress(address)
|
||||||
|
logger.warn('Removed address ' + address + '.')
|
|
@ -57,7 +57,7 @@
|
||||||
"blockCacheTotal" : 50000000
|
"blockCacheTotal" : 50000000
|
||||||
},
|
},
|
||||||
"peers":{
|
"peers":{
|
||||||
"minimumScore": 5,
|
"minimumScore": -4000,
|
||||||
"maxStoredPeers": 100,
|
"maxStoredPeers": 100,
|
||||||
"maxConnect": 3
|
"maxConnect": 3
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue