do not request offline peers too often and updated logo
This commit is contained in:
parent
24540abe6b
commit
0b192ffb9b
Binary file not shown.
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 5.0 KiB |
@ -108,7 +108,7 @@ class OnionrCommunicate:
|
|||||||
i = random.randint(0, maxN)
|
i = random.randint(0, maxN)
|
||||||
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])
|
newAdders = self.performGet('pex', peerList[i], skipHighFailureAddress=True)
|
||||||
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')
|
||||||
@ -116,7 +116,7 @@ class OnionrCommunicate:
|
|||||||
else:
|
else:
|
||||||
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])
|
newKeys = self.performGet('kex', peerList[i], skipHighFailureAddress=True)
|
||||||
# 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:
|
||||||
@ -217,7 +217,7 @@ class OnionrCommunicate:
|
|||||||
|
|
||||||
return urllib.parse.quote_plus(data)
|
return urllib.parse.quote_plus(data)
|
||||||
|
|
||||||
def performGet(self, action, peer, data=None, peerType='tor'):
|
def performGet(self, action, peer, data=None, skipHighFailureAddress=False, peerType='tor'):
|
||||||
'''
|
'''
|
||||||
Performs a request to a peer through Tor or i2p (currently only Tor)
|
Performs a request to a peer through Tor or i2p (currently only Tor)
|
||||||
'''
|
'''
|
||||||
@ -229,7 +229,6 @@ class OnionrCommunicate:
|
|||||||
if not peer in self.peerData:
|
if not peer in self.peerData:
|
||||||
self.peerData[peer] = {'connectCount': 0, 'failCount': 0, 'lastConnectTime': math.floor(time.time())}
|
self.peerData[peer] = {'connectCount': 0, 'failCount': 0, 'lastConnectTime': math.floor(time.time())}
|
||||||
socksPort = sys.argv[2]
|
socksPort = sys.argv[2]
|
||||||
logger.debug('Contacting ' + peer + ' on port ' + socksPort)
|
|
||||||
'''We use socks5h to use tor as DNS'''
|
'''We use socks5h to use tor as DNS'''
|
||||||
proxies = {'http': 'socks5://127.0.0.1:' + str(socksPort), 'https': 'socks5://127.0.0.1:' + str(socksPort)}
|
proxies = {'http': 'socks5://127.0.0.1:' + str(socksPort), 'https': 'socks5://127.0.0.1:' + str(socksPort)}
|
||||||
headers = {'user-agent': 'PyOnionr'}
|
headers = {'user-agent': 'PyOnionr'}
|
||||||
@ -237,8 +236,13 @@ class OnionrCommunicate:
|
|||||||
if data != None:
|
if data != None:
|
||||||
url = url + '&data=' + self.urlencode(data)
|
url = url + '&data=' + self.urlencode(data)
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, headers=headers, proxies=proxies, timeout=(15, 30))
|
if skipHighFailureAddress and self.peerData[peer]['failCount'] > 10:
|
||||||
retData = r.text
|
retData = False
|
||||||
|
logger.debug('Skipping ' + peer + ' because of high failure rate')
|
||||||
|
else:
|
||||||
|
logger.debug('Contacting ' + peer + ' on port ' + socksPort)
|
||||||
|
r = requests.get(url, headers=headers, proxies=proxies, timeout=(15, 30))
|
||||||
|
retData = r.text
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.warn(action + " failed with peer " + peer + ": " + str(e))
|
logger.warn(action + " failed with peer " + peer + ": " + str(e))
|
||||||
retData = False
|
retData = False
|
||||||
|
@ -41,22 +41,37 @@ class OnionrUtils:
|
|||||||
'''High level function to encrypt a message to a peer and insert it as a block'''
|
'''High level function to encrypt a message to a peer and insert it as a block'''
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def incrementAddressSuccess(self, address):
|
||||||
|
'''Increase the recorded sucesses for an address'''
|
||||||
|
increment = self._core.getAddressInfo(address, 'success') + 1
|
||||||
|
self._core.setAddressInfo(address, 'success', increment)
|
||||||
|
return
|
||||||
|
|
||||||
|
def decrementAddressSuccess(self, address):
|
||||||
|
'''Decrease the recorded sucesses for an address'''
|
||||||
|
increment = self._core.getAddressInfo(address, 'success') - 1
|
||||||
|
self._core.setAddressInfo(address, 'success', increment)
|
||||||
|
return
|
||||||
|
|
||||||
def mergeKeys(self, newKeyList):
|
def mergeKeys(self, newKeyList):
|
||||||
'''Merge ed25519 key list to our database'''
|
'''Merge ed25519 key list to our database'''
|
||||||
retVal = False
|
retVal = False
|
||||||
for key in newKeyList:
|
if newKeyList != False:
|
||||||
if not key in self._core.listPeers(randomOrder=False):
|
for key in newKeyList:
|
||||||
if self._core.addPeer(key):
|
if not key in self._core.listPeers(randomOrder=False):
|
||||||
retVal = True
|
if self._core.addPeer(key):
|
||||||
|
retVal = True
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
|
|
||||||
def mergeAdders(self, newAdderList):
|
def mergeAdders(self, newAdderList):
|
||||||
'''Merge peer adders list to our database'''
|
'''Merge peer adders list to our database'''
|
||||||
retVal = False
|
retVal = False
|
||||||
for adder in newAdderList:
|
if newAdderList != False:
|
||||||
if not adder in self._core.listAdders(randomOrder=False):
|
for adder in newAdderList:
|
||||||
if self._core.addAddress(adder):
|
if not adder in self._core.listAdders(randomOrder=False):
|
||||||
retVal = True
|
if self._core.addAddress(adder):
|
||||||
|
retVal = True
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def localCommand(self, command):
|
def localCommand(self, command):
|
||||||
|
Loading…
Reference in New Issue
Block a user