work on site finder and fixed friend adding

This commit is contained in:
Kevin Froman 2019-09-29 15:39:03 -05:00
parent 0067bd36b5
commit b077f72e5f
7 changed files with 49 additions and 13 deletions

View File

@ -61,6 +61,7 @@ def onionr_main():
if __name__ == "__main__":
onionr_main()
# Cleanup standard out/err because Python refuses to do it itsself
try:
sys.stderr.close()
except (IOError, BrokenPipeError) as e:

View File

@ -1,9 +1,9 @@
'''
"""
Onionr - Private P2P Communication
view and interact with onionr sites
'''
'''
"""
"""
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
the Free Software Foundation, either version 3 of the License, or
@ -16,7 +16,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
"""
import base64
import binascii

View File

@ -1,10 +1,39 @@
"""
Onionr - Private P2P Communication
view and interact with onionr sites
"""
"""
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from typing import Union
import onionrexceptions
from onionrutils import mnemonickeys
from onionrutils import stringvalidators
from coredb import blockmetadb
from onionrblocks.onionrblockapi import Block
def find_site(user_id: str)->str:
def find_site(user_id: str)->Union[str, None]:
"""Returns block hash string for latest block for a site by a given user id"""
if '-' in user_id: user_id = mnemonickeys.get_base32(user_id)
if not stringvalidators.validate_pub_key(user_id): raise onionrexceptions.InvalidPubkey
found_site = None
sites = blockmetadb.get_blocks_by_type('zsite')
#for
for site in sites:
site = Block(site)
if site.isSigner(user_id) and site.verifySig():
found_site = site.hash
return found_site

View File

@ -0,0 +1,4 @@
import zipfile
def get_zip_site_file(path):
with zipfile.ZipFile(zip_file, 'r') as zf:
for member in zf.infolist():

View File

@ -22,13 +22,13 @@ import unpaddedbase32
from onionrusers import onionrusers
from onionrutils import bytesconverter, epoch
from utils import identifyhome
from onionrutils import mnemonickeys
import mnemonic
class ContactManager(onionrusers.OnionrUser):
def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5):
try:
if " " in publicKey:
publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey)
if mnemonickeys.DELIMITER in publicKey:
publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey.split(mnemonickeys.DELIMITER))
publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey))
except ValueError:
pass

View File

@ -67,7 +67,7 @@ class OnionrUser:
if saveUser:
try:
keydb.addkeys.add_peer(publicKey)
except AssertionError:
except (AssertionError, ValueError) as e:
pass
self.trust = keydb.userinfo.get_user_info(self.publicKey, 'trust')

View File

@ -25,6 +25,8 @@ import unpaddedbase32
import onionrcrypto
from etc import onionrvalues
DELIMITER = '-'
m = mnemonic.Mnemonic('english')
def get_human_readable_ID(pub=''):
@ -35,8 +37,8 @@ def get_human_readable_ID(pub=''):
if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE:
pub = base64.b32decode(pub)
return m.to_mnemonic(pub).replace(' ', '-')
return m.to_mnemonic(pub).replace(' ', DELIMITER)
def get_base32(words):
'''converts mnemonic to base32'''
return unpaddedbase32.b32encode(m.to_entropy(words.replace('-', ' ')))
return unpaddedbase32.b32encode(m.to_entropy(words.replace(DELIMITER, ' ')))