work on site finder and fixed friend adding
This commit is contained in:
parent
0067bd36b5
commit
b077f72e5f
@ -61,6 +61,7 @@ def onionr_main():
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
onionr_main()
|
onionr_main()
|
||||||
|
|
||||||
|
# Cleanup standard out/err because Python refuses to do it itsself
|
||||||
try:
|
try:
|
||||||
sys.stderr.close()
|
sys.stderr.close()
|
||||||
except (IOError, BrokenPipeError) as e:
|
except (IOError, BrokenPipeError) as e:
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'''
|
"""
|
||||||
Onionr - Private P2P Communication
|
Onionr - Private P2P Communication
|
||||||
|
|
||||||
view and interact with onionr sites
|
view and interact with onionr sites
|
||||||
'''
|
"""
|
||||||
'''
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
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
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
"""
|
||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
|
|
||||||
|
@ -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
|
import onionrexceptions
|
||||||
from onionrutils import mnemonickeys
|
from onionrutils import mnemonickeys
|
||||||
from onionrutils import stringvalidators
|
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 '-' in user_id: user_id = mnemonickeys.get_base32(user_id)
|
||||||
if not stringvalidators.validate_pub_key(user_id): raise onionrexceptions.InvalidPubkey
|
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
|
||||||
|
4
onionr/httpapi/onionrsitesapi/zsite.py
Normal file
4
onionr/httpapi/onionrsitesapi/zsite.py
Normal 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():
|
@ -22,13 +22,13 @@ import unpaddedbase32
|
|||||||
from onionrusers import onionrusers
|
from onionrusers import onionrusers
|
||||||
from onionrutils import bytesconverter, epoch
|
from onionrutils import bytesconverter, epoch
|
||||||
from utils import identifyhome
|
from utils import identifyhome
|
||||||
|
from onionrutils import mnemonickeys
|
||||||
import mnemonic
|
import mnemonic
|
||||||
class ContactManager(onionrusers.OnionrUser):
|
class ContactManager(onionrusers.OnionrUser):
|
||||||
def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5):
|
def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5):
|
||||||
try:
|
try:
|
||||||
if " " in publicKey:
|
if mnemonickeys.DELIMITER in publicKey:
|
||||||
publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey)
|
publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey.split(mnemonickeys.DELIMITER))
|
||||||
publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey))
|
publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
@ -67,7 +67,7 @@ class OnionrUser:
|
|||||||
if saveUser:
|
if saveUser:
|
||||||
try:
|
try:
|
||||||
keydb.addkeys.add_peer(publicKey)
|
keydb.addkeys.add_peer(publicKey)
|
||||||
except AssertionError:
|
except (AssertionError, ValueError) as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.trust = keydb.userinfo.get_user_info(self.publicKey, 'trust')
|
self.trust = keydb.userinfo.get_user_info(self.publicKey, 'trust')
|
||||||
|
@ -25,6 +25,8 @@ import unpaddedbase32
|
|||||||
import onionrcrypto
|
import onionrcrypto
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
|
|
||||||
|
DELIMITER = '-'
|
||||||
|
|
||||||
m = mnemonic.Mnemonic('english')
|
m = mnemonic.Mnemonic('english')
|
||||||
|
|
||||||
def get_human_readable_ID(pub=''):
|
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:
|
if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE:
|
||||||
pub = base64.b32decode(pub)
|
pub = base64.b32decode(pub)
|
||||||
|
|
||||||
return m.to_mnemonic(pub).replace(' ', '-')
|
return m.to_mnemonic(pub).replace(' ', DELIMITER)
|
||||||
|
|
||||||
def get_base32(words):
|
def get_base32(words):
|
||||||
'''converts mnemonic to base32'''
|
'''converts mnemonic to base32'''
|
||||||
return unpaddedbase32.b32encode(m.to_entropy(words.replace('-', ' ')))
|
return unpaddedbase32.b32encode(m.to_entropy(words.replace(DELIMITER, ' ')))
|
||||||
|
Loading…
Reference in New Issue
Block a user