Merge branch 'refactoring2' of https://gitlab.com/beardog/onionr into refactoring2
commit
c083d54abb
|
@ -219,6 +219,8 @@ class OnionrCommunicatorDaemon:
|
||||||
for i in range(needed):
|
for i in range(needed):
|
||||||
if len(self.onlinePeers) == 0:
|
if len(self.onlinePeers) == 0:
|
||||||
self.connectNewPeer(useBootstrap=True)
|
self.connectNewPeer(useBootstrap=True)
|
||||||
|
if len(self.onlinePeers) == 0:
|
||||||
|
logger.warn('Could not connect to any peer.')
|
||||||
self.decrementThreadCount('getOnlinePeers')
|
self.decrementThreadCount('getOnlinePeers')
|
||||||
|
|
||||||
def addBootstrapListToPeerList(self, peerList):
|
def addBootstrapListToPeerList(self, peerList):
|
||||||
|
@ -256,9 +258,6 @@ class OnionrCommunicatorDaemon:
|
||||||
else:
|
else:
|
||||||
tried.append(address)
|
tried.append(address)
|
||||||
logger.debug('Failed to connect to ' + address)
|
logger.debug('Failed to connect to ' + address)
|
||||||
else:
|
|
||||||
if len(self.onlinePeers) == 0:
|
|
||||||
logger.warn('Could not connect to any peer')
|
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
def printOnlinePeers(self):
|
def printOnlinePeers(self):
|
||||||
|
|
|
@ -59,27 +59,7 @@ 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
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
self._core.insertBlock(message, header='pm', sign=True, encryptType='sym', symKey=pubkey)
|
||||||
# We sign PMs here rather than in core.insertBlock in order to mask the sender's pubkey
|
|
||||||
payload = {'sig': '', 'msg': '', 'id': self._core._crypto.pubKey}
|
|
||||||
|
|
||||||
sign = self._core._crypto.edSign(message, self._core._crypto.privKey, encodeResult=True)
|
|
||||||
#encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
|
||||||
|
|
||||||
payload['sig'] = sign
|
|
||||||
payload['msg'] = message
|
|
||||||
payload = json.dumps(payload)
|
|
||||||
message = payload
|
|
||||||
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
|
||||||
|
|
||||||
|
|
||||||
block = self._core.insertBlock(encrypted, header='pm', sign=False)
|
|
||||||
if block == '':
|
|
||||||
logger.error('Could not send PM')
|
|
||||||
else:
|
|
||||||
logger.info('Sent PM, hash: %s' % block)
|
|
||||||
except Exception as error:
|
|
||||||
logger.error('Failed to send PM.', error=error)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -214,6 +194,7 @@ class OnionrUtils:
|
||||||
break
|
break
|
||||||
|
|
||||||
return pass1
|
return pass1
|
||||||
|
|
||||||
def getHumanReadableID(self, pub=''):
|
def getHumanReadableID(self, pub=''):
|
||||||
'''gets a human readable ID from a public key'''
|
'''gets a human readable ID from a public key'''
|
||||||
if pub == '':
|
if pub == '':
|
||||||
|
@ -322,7 +303,7 @@ class OnionrUtils:
|
||||||
|
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
def validateMetadata(metadata):
|
def validateMetadata(self, metadata):
|
||||||
'''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string'''
|
'''Validate metadata meets onionr spec (does not validate proof value computation), take in either dictionary or json string'''
|
||||||
# TODO, make this check sane sizes
|
# TODO, make this check sane sizes
|
||||||
retData = False
|
retData = False
|
||||||
|
@ -346,6 +327,9 @@ class OnionrUtils:
|
||||||
if self._core.requirements.blockMetadataLengths[i] < len(metadata[i]):
|
if self._core.requirements.blockMetadataLengths[i] < len(metadata[i]):
|
||||||
logger.warn('Block metadata key ' + i + ' exceeded maximum size')
|
logger.warn('Block metadata key ' + i + ' exceeded maximum size')
|
||||||
break
|
break
|
||||||
|
if i == 'time':
|
||||||
|
if not self.isIntegerString(metadata[i]):
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
# if metadata loop gets no errors, it does not break, therefore metadata is valid
|
# if metadata loop gets no errors, it does not break, therefore metadata is valid
|
||||||
retData = True
|
retData = True
|
||||||
|
@ -369,6 +353,14 @@ class OnionrUtils:
|
||||||
retVal = True
|
retVal = True
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
|
def isIntegerString(self, data):
|
||||||
|
'''Check if a string is a valid base10 integer'''
|
||||||
|
try:
|
||||||
|
int(data)
|
||||||
|
except ValueError:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def validateID(self, id):
|
def validateID(self, id):
|
||||||
'''
|
'''
|
||||||
|
@ -565,6 +557,8 @@ class OnionrUtils:
|
||||||
proxies = {'http': 'socks5h://127.0.0.1:' + str(port), 'https': 'socks5h://127.0.0.1:' + str(port)}
|
proxies = {'http': 'socks5h://127.0.0.1:' + str(port), 'https': 'socks5h://127.0.0.1:' + str(port)}
|
||||||
r = requests.get(url, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30))
|
r = requests.get(url, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30))
|
||||||
retData = r.text
|
retData = r.text
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise KeyboardInterrupt
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.debug('Error: %s' % str(e))
|
logger.debug('Error: %s' % str(e))
|
||||||
retData = False
|
retData = False
|
||||||
|
|
Loading…
Reference in New Issue