pex/kex hopefully now working

This commit is contained in:
Kevin Froman 2018-04-03 16:47:48 -05:00
parent fdceb4be90
commit a611643526
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 22 additions and 9 deletions

View File

@ -53,7 +53,7 @@ class OnionrCommunicate:
highFailureRate = 10
heartBeatTimer = 0
heartBeatRate = 5
pexTimer = 1000 # How often we should check for new peers
pexTimer = 25 # How often we should check for new peers
pexCount = 0
logger.debug('Communicator debugging enabled.')
torID = open('data/hs/hostname').read()
@ -79,7 +79,7 @@ class OnionrCommunicate:
self.peerData[i]['failCount'] -= 1
if pexTimer == pexCount:
self.getNewPeers()
pexCount = 0
pexCount = 0 # TODO: do not reset timer if low peer count
if heartBeatRate == heartBeatTimer:
logger.debug('Communicator heartbeat')
heartBeatTimer = 0
@ -97,7 +97,7 @@ class OnionrCommunicate:
def getNewPeers(self):
'''
Get new peers
Get new peers and keys
'''
peersCheck = 5 # Amount of peers to ask for new peers + keys
peersChecked = 0
@ -118,6 +118,8 @@ class OnionrCommunicate:
logger.info('Using ' + peerList[i] + ' to find new peers')
try:
newAdders = self.performGet('pex', peerList[i], skipHighFailureAddress=True)
logger.debug('Attempting to merge address: ')
logger.debug(newAdders)
self._utils.mergeAdders(newAdders)
except requests.exceptions.ConnectionError:
logger.info(peerList[i] + ' connection failed')
@ -126,6 +128,8 @@ class OnionrCommunicate:
try:
logger.info('Using ' + peerList[i] + ' to find new keys')
newKeys = self.performGet('kex', peerList[i], skipHighFailureAddress=True)
logger.debug('Attempting to merge pubkey: ')
logger.debug(newKeys)
# TODO: Require keys to come with POW token (very large amount of POW)
self._utils.mergeKeys(newKeys)
except requests.exceptions.ConnectionError:

View File

@ -359,8 +359,8 @@ class Core:
payload = 'SELECT * FROM peers;'
peerList = []
for i in c.execute(payload):
print('lol - ' + i[2])
peerList.append(i[2])
if type(i[2] != None):
peerList.append(i[2])
peerList.append(self._crypto.pubKey)
conn.close()
return peerList

View File

@ -58,8 +58,8 @@ class OnionrUtils:
'''Merge ed25519 key list to our database'''
retVal = False
if newKeyList != False:
for key in newKeyList:
if not key in self._core.listPeers(randomOrder=False):
for key in newKeyList.split(','):
if not key in self._core.listPeers(randomOrder=False) and type(key) != None and key != self._core._crypto.pubKey:
if self._core.addPeer(key):
retVal = True
return retVal
@ -69,13 +69,22 @@ class OnionrUtils:
'''Merge peer adders list to our database'''
retVal = False
if newAdderList != False:
for adder in newAdderList:
if not adder in self._core.listAdders(randomOrder=False):
for adder in newAdderList.split(','):
if not adder in self._core.listAdders(randomOrder=False) and adder.strip() != self.getMyAddress():
if self._core.addAddress(adder):
logger.info('added ' + adder + ' to db')
input()
retVal = True
else:
logger.debug(adder + " is either our address or already in our DB")
return retVal
def getMyAddress(self):
myAddressFile = open("data/hs/hostname", 'r')
myAddress = myAddressFile.read()
myAddressFile.close()
return myAddress.strip()
def localCommand(self, command):
'''
Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.