From 032aa780ef9270a78ee5f087fbe3b5da9345e914 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 2 Aug 2018 15:18:01 -0500 Subject: [PATCH] * fixed bug causing onionr to usually only have 1 peer at once * do not crash when loading new peer profile * removed code for defunct *address* proof of work + added maxStoredPeers and maxConnect config options (TODO) + added lastConnectAttempt to address db + added command to cause instant peer exchange + added connectCheck.txt for TODO connection testing --- onionr/communicator2.py | 9 +++++++++ onionr/onionr.py | 7 +++++++ onionr/onionrpeers.py | 2 +- onionr/onionrutils.py | 7 +++---- onionr/static-data/connect-check.txt | 1 + onionr/static-data/default_config.json | 4 +++- 6 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 onionr/static-data/connect-check.txt diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 0bc6e59d..51f9ac12 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -260,6 +260,8 @@ class OnionrCommunicatorDaemon: for i in range(needed): if len(self.onlinePeers) == 0: self.connectNewPeer(useBootstrap=True) + else: + self.connectNewPeer() if self.shutdown: break else: @@ -338,6 +340,9 @@ class OnionrCommunicatorDaemon: url = 'http://' + peer + '/public/?action=' + action if len(data) > 0: url += '&data=' + data + + self._core.setAddressInfo(peer, 'lastConnectAttempt', self._core._utils.getEpoch()) # mark the time we're trying to request this peer + retData = self._core._utils.doGetRequest(url, port=self.proxyPort) # if request failed, (error), mark peer offline if retData == False: @@ -390,6 +395,10 @@ class OnionrCommunicatorDaemon: for i in self.timers: if i.timerFunction.__name__ == 'lookupKeys': i.count = (i.frequency - 1) + elif cmd[0] == 'pex': + for i in self.timers: + if i.timerFunction.__name__ == 'lookupAdders': + i.count = (i.frequency - 1) elif cmd[0] == 'uploadBlock': self.blockToUpload = cmd[1] threading.Thread(target=self.uploadBlock).start() diff --git a/onionr/onionr.py b/onionr/onionr.py index acf14374..a430fe08 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -196,6 +196,7 @@ class Onionr: 'introduce': self.onionrCore.introduceNode, 'connect': self.addAddress, 'kex': self.doKEX, + 'pex': self.doPEX, 'getpassword': self.printWebPassword } @@ -218,6 +219,7 @@ class Onionr: 'import-blocks': 'import blocks from the disk (Onionr is transport-agnostic!)', 'listconn': 'list connected peers', 'kex': 'exchange keys with peers (done automatically)', + 'pex': 'exchange addresses with peers (done automatically)', 'introduce': 'Introduce your node to the public Onionr network', } @@ -329,6 +331,11 @@ class Onionr: logger.info('Sending kex to command queue...') self.onionrCore.daemonQueueAdd('kex') + def doPEX(self): + '''make communicator do pex''' + logger.info('Sending pex to command queue...') + self.onionrCore.daemonQueueAdd('pex') + def listKeys(self): ''' Displays a list of keys (used to be called peers) (?) diff --git a/onionr/onionrpeers.py b/onionr/onionrpeers.py index 73737cf9..e5148c02 100644 --- a/onionr/onionrpeers.py +++ b/onionr/onionrpeers.py @@ -41,7 +41,7 @@ class PeerProfiles: '''Load the node's score from the database''' try: self.success = int(self.coreInst.getAddressInfo(self.address, 'success')) - except TypeError: + except (TypeError, ValueError) as e: self.success = 0 self.score = self.success diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 105519e9..7a6b9cd3 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -125,10 +125,9 @@ class OnionrUtils: if newAdderList != False: for adder in newAdderList.split(','): if not adder in self._core.listAdders(randomOrder = False) and adder.strip() != self.getMyAddress(): - if adder[:4] == '0000': - if self._core.addAddress(adder): - logger.info('Added %s to db.' % adder, timestamp = True) - retVal = True + if self._core.addAddress(adder): + logger.info('Added %s to db.' % adder, timestamp = True) + retVal = True else: pass #logger.debug('%s is either our address or already in our DB' % adder) diff --git a/onionr/static-data/connect-check.txt b/onionr/static-data/connect-check.txt new file mode 100644 index 00000000..009a2a9a --- /dev/null +++ b/onionr/static-data/connect-check.txt @@ -0,0 +1 @@ +https://3g2upl4pq6kufc4m.onion/robots.txt,http://expyuzz4wqqyqhjn.onion/robots.txt,https://onionr.voidnet.tech/ diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json index 04c00835..5f928f6d 100644 --- a/onionr/static-data/default_config.json +++ b/onionr/static-data/default_config.json @@ -57,6 +57,8 @@ "blockCacheTotal" : 50000000 }, "peers":{ - "minimumScore": 5 + "minimumScore": 5, + "maxStoredPeers": 100, + "maxConnect": 3 } }