Merge nick's fixes

This commit is contained in:
Kevin 2019-12-01 08:10:00 +00:00
parent 1de668a9e5
commit 8a4102cbd1
5 changed files with 52 additions and 59 deletions

View file

@ -85,10 +85,7 @@ class PrivateAPI:
logger.error("client password needs to be set")
return False
try:
if not hmac.compare_digest(self.clientToken, token):
return False
else:
return True
return hmac.compare_digest(self.clientToken, token)
except TypeError:
return False

View file

@ -1,6 +1,3 @@
from onionrutils import epoch
def replay_timestamp_validation(timestamp):
if epoch.get_epoch() - int(timestamp) > 2419200:
return False
else:
return True
return epoch.get_epoch() - int(timestamp) <= 2419200

View file

@ -41,10 +41,8 @@ def peer_cleanup():
if peerprofiles.PeerProfiles(address).score < min_score:
keydb.removekeys.remove_address(address)
try:
if (int(epoch.get_epoch()) - int(keydb.transportinfo.get_address_info(address, 'lastConnect'))) >= 600:
expireTime = 600
else:
expireTime = 86400
lastConnect = int(keydb.transportinfo.get_address_info(address, 'lastConnect'))
expireTime = 86400 - int(epoch.get_epoch()) - lastConnect
blacklist.addToDB(address, dataType=1, expire=expireTime)
except sqlite3.IntegrityError: #TODO just make sure its not a unique constraint issue
pass

View file

@ -1,8 +1,10 @@
'''
Onionr - Private P2P Communication
z-fill (zero fill) a string to a specific length, intended for reconstructing block hashes
z-fill (zero fill) a string to a specific length
intended for reconstructing block hashes
'''
from typing import Union
'''
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,10 +19,16 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
def reconstruct_hash(hex_hash, length=64):
def reconstruct_hash(hex_hash: Union[str, bytes],
length: int = 64) -> Union[str, bytes]:
"""Pad hash hex string with zeros, return result"""
return hex_hash.zfill(length)
def deconstruct_hash(hex_hash):
def deconstruct_hash(hex_hash: Union[str, bytes]) -> Union[str, bytes]:
"""Remove leading zeros from hex hash, return result"""
new_hash = ''
ret_bytes = False
try:
@ -40,4 +48,4 @@ def deconstruct_hash(hex_hash):
if ret_bytes:
new_hash = new_hash.encode()
return new_hash
return new_hash