diff --git a/onionr/communicator.py b/onionr/communicator.py index e8a27b24..da36179b 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -263,13 +263,20 @@ class OnionrCommunicate: ''' return urllib.parse.quote_plus(data) - def performGet(self, action, peer, data=None, skipHighFailureAddress=False, peerType='tor'): + def performGet(self, action, peer, data=None, skipHighFailureAddress=False, peerType='tor', selfCheck=True): ''' Performs a request to a peer through Tor or i2p (currently only Tor) ''' if not peer.endswith('.onion') and not peer.endswith('.onion/'): raise PeerError('Currently only Tor .onion peers are supported. You must manually specify .onion') + + if len(self._core.hsAdder.strip()) == 0: + raise Exception("Could not perform self address check in performGet due to not knowing our address") + if selfCheck: + if peer.replace('/', '') == self._core.hsAdder: + logger.warn('Tried to performget to own hidden service, but selfCheck was not set to false') + return # Store peer in peerData dictionary (non permanent) if not peer in self.peerData: diff --git a/onionr/core.py b/onionr/core.py index f363d8bc..8fb5fd82 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -44,6 +44,9 @@ class Core: self.addressDB = 'data/address.db' self.hsAdder = '' + self.bootstrapFileLocation = 'static-data/bootstrap-nodes.txt' + self.bootstrapList = [] + if not os.path.exists('data/'): os.mkdir('data/') if not os.path.exists('data/blocks/'): @@ -54,10 +57,20 @@ class Core: if os.path.exists('data/hs/hostname'): with open('data/hs/hostname', 'r') as hs: self.hsAdder = hs.read() + else: + logger.warn('Warning: address bootstrap file not found ' + self.bootstrapFileLocation) + + # Load bootstrap address list + if os.path.exists(self.bootstrapFileLocation): + with open(self.bootstrapFileLocation, 'r') as bootstrap: + bootstrap = bootstrap.read() + for i in bootstrap.split('\n'): + self.bootstrapList.append(i) self._utils = onionrutils.OnionrUtils(self) # Initialize the crypto object self._crypto = onionrcrypto.OnionrCrypto(self) + except Exception as error: logger.error('Failed to initialize core Onionr library.', error=error) logger.fatal('Cannot recover from error.') @@ -574,8 +587,10 @@ class Core: announceAmount = 2 nodeList = self.listAdders() if len(nodeList) == 0: - self.addAddress('onionragxuddecmg.onion') - nodeList.append('onionragxuddecmg.onion') + for i in self.bootstrapList: + if self._utils.validateID(i): + self.addAddress(i) + nodeList.append(i) if announceAmount > len(nodeList): announceAmount = len(nodeList) for i in range(announceAmount):