pex/kex hopefully now working
This commit is contained in:
parent
fdceb4be90
commit
a611643526
@ -53,7 +53,7 @@ class OnionrCommunicate:
|
|||||||
highFailureRate = 10
|
highFailureRate = 10
|
||||||
heartBeatTimer = 0
|
heartBeatTimer = 0
|
||||||
heartBeatRate = 5
|
heartBeatRate = 5
|
||||||
pexTimer = 1000 # How often we should check for new peers
|
pexTimer = 25 # How often we should check for new peers
|
||||||
pexCount = 0
|
pexCount = 0
|
||||||
logger.debug('Communicator debugging enabled.')
|
logger.debug('Communicator debugging enabled.')
|
||||||
torID = open('data/hs/hostname').read()
|
torID = open('data/hs/hostname').read()
|
||||||
@ -79,7 +79,7 @@ class OnionrCommunicate:
|
|||||||
self.peerData[i]['failCount'] -= 1
|
self.peerData[i]['failCount'] -= 1
|
||||||
if pexTimer == pexCount:
|
if pexTimer == pexCount:
|
||||||
self.getNewPeers()
|
self.getNewPeers()
|
||||||
pexCount = 0
|
pexCount = 0 # TODO: do not reset timer if low peer count
|
||||||
if heartBeatRate == heartBeatTimer:
|
if heartBeatRate == heartBeatTimer:
|
||||||
logger.debug('Communicator heartbeat')
|
logger.debug('Communicator heartbeat')
|
||||||
heartBeatTimer = 0
|
heartBeatTimer = 0
|
||||||
@ -97,7 +97,7 @@ class OnionrCommunicate:
|
|||||||
|
|
||||||
def getNewPeers(self):
|
def getNewPeers(self):
|
||||||
'''
|
'''
|
||||||
Get new peers
|
Get new peers and keys
|
||||||
'''
|
'''
|
||||||
peersCheck = 5 # Amount of peers to ask for new peers + keys
|
peersCheck = 5 # Amount of peers to ask for new peers + keys
|
||||||
peersChecked = 0
|
peersChecked = 0
|
||||||
@ -118,6 +118,8 @@ class OnionrCommunicate:
|
|||||||
logger.info('Using ' + peerList[i] + ' to find new peers')
|
logger.info('Using ' + peerList[i] + ' to find new peers')
|
||||||
try:
|
try:
|
||||||
newAdders = self.performGet('pex', peerList[i], skipHighFailureAddress=True)
|
newAdders = self.performGet('pex', peerList[i], skipHighFailureAddress=True)
|
||||||
|
logger.debug('Attempting to merge address: ')
|
||||||
|
logger.debug(newAdders)
|
||||||
self._utils.mergeAdders(newAdders)
|
self._utils.mergeAdders(newAdders)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
logger.info(peerList[i] + ' connection failed')
|
logger.info(peerList[i] + ' connection failed')
|
||||||
@ -126,6 +128,8 @@ class OnionrCommunicate:
|
|||||||
try:
|
try:
|
||||||
logger.info('Using ' + peerList[i] + ' to find new keys')
|
logger.info('Using ' + peerList[i] + ' to find new keys')
|
||||||
newKeys = self.performGet('kex', peerList[i], skipHighFailureAddress=True)
|
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)
|
# TODO: Require keys to come with POW token (very large amount of POW)
|
||||||
self._utils.mergeKeys(newKeys)
|
self._utils.mergeKeys(newKeys)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
|
@ -359,8 +359,8 @@ class Core:
|
|||||||
payload = 'SELECT * FROM peers;'
|
payload = 'SELECT * FROM peers;'
|
||||||
peerList = []
|
peerList = []
|
||||||
for i in c.execute(payload):
|
for i in c.execute(payload):
|
||||||
print('lol - ' + i[2])
|
if type(i[2] != None):
|
||||||
peerList.append(i[2])
|
peerList.append(i[2])
|
||||||
peerList.append(self._crypto.pubKey)
|
peerList.append(self._crypto.pubKey)
|
||||||
conn.close()
|
conn.close()
|
||||||
return peerList
|
return peerList
|
||||||
|
@ -58,8 +58,8 @@ class OnionrUtils:
|
|||||||
'''Merge ed25519 key list to our database'''
|
'''Merge ed25519 key list to our database'''
|
||||||
retVal = False
|
retVal = False
|
||||||
if newKeyList != False:
|
if newKeyList != False:
|
||||||
for key in newKeyList:
|
for key in newKeyList.split(','):
|
||||||
if not key in self._core.listPeers(randomOrder=False):
|
if not key in self._core.listPeers(randomOrder=False) and type(key) != None and key != self._core._crypto.pubKey:
|
||||||
if self._core.addPeer(key):
|
if self._core.addPeer(key):
|
||||||
retVal = True
|
retVal = True
|
||||||
return retVal
|
return retVal
|
||||||
@ -69,13 +69,22 @@ class OnionrUtils:
|
|||||||
'''Merge peer adders list to our database'''
|
'''Merge peer adders list to our database'''
|
||||||
retVal = False
|
retVal = False
|
||||||
if newAdderList != False:
|
if newAdderList != False:
|
||||||
for adder in newAdderList:
|
for adder in newAdderList.split(','):
|
||||||
if not adder in self._core.listAdders(randomOrder=False):
|
if not adder in self._core.listAdders(randomOrder=False) and adder.strip() != self.getMyAddress():
|
||||||
if self._core.addAddress(adder):
|
if self._core.addAddress(adder):
|
||||||
logger.info('added ' + adder + ' to db')
|
logger.info('added ' + adder + ' to db')
|
||||||
|
input()
|
||||||
retVal = True
|
retVal = True
|
||||||
|
else:
|
||||||
|
logger.debug(adder + " is either our address or already in our DB")
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
|
def getMyAddress(self):
|
||||||
|
myAddressFile = open("data/hs/hostname", 'r')
|
||||||
|
myAddress = myAddressFile.read()
|
||||||
|
myAddressFile.close()
|
||||||
|
return myAddress.strip()
|
||||||
|
|
||||||
def localCommand(self, command):
|
def localCommand(self, command):
|
||||||
'''
|
'''
|
||||||
Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.
|
Send a command to the local http API server, securely. Intended for local clients, DO NOT USE for remote peers.
|
||||||
|
Loading…
Reference in New Issue
Block a user