added self check, bootstrap node file

This commit is contained in:
Kevin Froman 2018-04-22 18:35:00 -05:00
parent 0ce3c7d940
commit 7706d4e04c
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 25 additions and 3 deletions

View File

@ -263,7 +263,7 @@ 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)
'''
@ -271,6 +271,13 @@ class OnionrCommunicate:
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:
self.peerData[peer] = {'connectCount': 0, 'failCount': 0, 'lastConnectTime': math.floor(time.time())}

View File

@ -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):