diff --git a/onionr/api.py b/onionr/api.py index ccfc39db..606aaffe 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -317,9 +317,6 @@ class API: resp = Response(self._utils.getBlockDBHash()) elif action == 'getBlockHashes': resp = Response('\n'.join(self._core.getBlockList())) - elif action == 'directMessage': - resp = Response(self._core.handle_direct_connection(data)) - elif action == 'announce': if data != '': # TODO: require POW for this diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 59ae7d77..cd7c3df1 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -85,9 +85,11 @@ class OnionrCommunicatorDaemon: OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58) OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True) OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True) + cleanupTimer = OnionrCommunicatorTimers(self, onionrpeers.peerCleanup, 300) # set loop to execute instantly to load up peer pool (replaced old pool init wait) peerPoolTimer.count = (peerPoolTimer.frequency - 1) + cleanupTimer = (cleanupTimer.frequency - 200) # Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking try: @@ -149,7 +151,11 @@ class OnionrCommunicatorDaemon: triedPeers.append(peer) if newDBHash != self._core.getAddressInfo(peer, 'DBHash'): self._core.setAddressInfo(peer, 'DBHash', newDBHash) - newBlocks = self.peerAction(peer, 'getBlockHashes') + try: + newBlocks = self.peerAction(peer, 'getBlockHashes') + except Exception as error: + logger.warn("could not get new blocks with " + peer, error=error) + newBlocks = False if newBlocks != False: # if request was a success for i in newBlocks.split('\n'): @@ -248,7 +254,7 @@ class OnionrCommunicatorDaemon: '''Manages the self.onlinePeers attribute list, connects to more peers if we have none connected''' logger.info('Refreshing peer pool.') - maxPeers = 4 + maxPeers = 6 needed = maxPeers - len(self.onlinePeers) for i in range(needed): @@ -278,13 +284,13 @@ class OnionrCommunicatorDaemon: raise onionrexceptions.InvalidAddress('Will not attempt connection test to invalid address') else: peerList = self._core.listAdders() + + peerList = onionrpeers.getScoreSortedPeerList(self._core) if len(peerList) == 0 or useBootstrap: # Avoid duplicating bootstrap addresses in peerList self.addBootstrapListToPeerList(peerList) - peerList = onionrpeers.getScoreSortedPeerList(self._core) - for address in peerList: if len(address) == 0 or address in tried or address in self.onlinePeers: continue @@ -331,12 +337,13 @@ class OnionrCommunicatorDaemon: # if request failed, (error), mark peer offline if retData == False: try: - self.getPeerProfileInstance(peer).addScore(-2) + self.getPeerProfileInstance(peer).addScore(-10) self.onlinePeers.remove(peer) self.getOnlinePeers() # Will only add a new peer to pool if needed except ValueError: pass else: + self._core.setAddressInfo(peer, 'lastConnect', self._core._utils.getEpoch()) self.getPeerProfileInstance(peer).addScore(1) return retData diff --git a/onionr/core.py b/onionr/core.py index e147dc72..8f01e9ca 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -590,7 +590,7 @@ class Core: if unsaved: execute = 'SELECT hash FROM hashes WHERE dataSaved != 1 ORDER BY RANDOM();' else: - execute = 'SELECT hash FROM hashes ORDER BY RANDOM();' + execute = 'SELECT hash FROM hashes ORDER BY dateReceived DESC;' rows = list() for row in c.execute(execute): for i in row: diff --git a/onionr/onionrpeers.py b/onionr/onionrpeers.py index bfc8445b..5488e748 100644 --- a/onionr/onionrpeers.py +++ b/onionr/onionrpeers.py @@ -69,4 +69,8 @@ def getScoreSortedPeerList(coreInst): # Sort peers by their score, greatest to least peerList = sorted(peerScores, key=peerScores.get, reverse=True) - return peerList \ No newline at end of file + return peerList + +def peerCleanup(): + # TODO, remove peers that have been offline for too long + return \ No newline at end of file diff --git a/onionr/static-data/index.html b/onionr/static-data/index.html index f9df9eb7..93e48beb 100644 --- a/onionr/static-data/index.html +++ b/onionr/static-data/index.html @@ -1,5 +1,7 @@
The content on this server is not necessarily created or intentionally stored by the owner of the server.
+The content on this server is not necessarily created by the server owner, and was not necessarily stored with the owner's knowledge.
+ +Onionr is a decentralized, distributed data storage system, that anyone can insert data into.
To learn more about Onionr, see the website at https://Onionr.VoidNet.tech/