2019-09-29 20:39:03 +00:00
|
|
|
"""
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
view and interact with onionr sites
|
|
|
|
"""
|
2019-11-20 10:52:50 +00:00
|
|
|
|
|
|
|
from typing import Union
|
|
|
|
|
|
|
|
import onionrexceptions
|
|
|
|
from onionrutils import mnemonickeys
|
|
|
|
from onionrutils import stringvalidators
|
|
|
|
from coredb import blockmetadb
|
|
|
|
from onionrblocks.onionrblockapi import Block
|
|
|
|
from onionrtypes import BlockHash
|
|
|
|
|
2019-09-29 20:39:03 +00:00
|
|
|
"""
|
|
|
|
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/>.
|
|
|
|
"""
|
|
|
|
|
2019-09-28 05:37:24 +00:00
|
|
|
|
2019-11-20 10:52:50 +00:00
|
|
|
def find_site(user_id: str) -> Union[BlockHash, None]:
|
|
|
|
"""Returns block hash str for latest block for a site by a given user id"""
|
|
|
|
# If mnemonic delim in key, convert to base32 version
|
|
|
|
if mnemonickeys.DELIMITER in user_id:
|
|
|
|
user_id = mnemonickeys.get_base32(user_id)
|
|
|
|
|
|
|
|
if not stringvalidators.validate_pub_key(user_id):
|
|
|
|
raise onionrexceptions.InvalidPubkey
|
|
|
|
|
2019-09-29 20:39:03 +00:00
|
|
|
found_site = None
|
2020-02-05 07:49:24 +00:00
|
|
|
sites = blockmetadb.get_blocks_by_type('osite')
|
2019-09-28 05:37:24 +00:00
|
|
|
|
2019-11-20 10:52:50 +00:00
|
|
|
# Find site by searching all site blocks. eww O(N) ☹️, TODO: event based
|
2019-09-29 20:39:03 +00:00
|
|
|
for site in sites:
|
|
|
|
site = Block(site)
|
|
|
|
if site.isSigner(user_id) and site.verifySig():
|
|
|
|
found_site = site.hash
|
|
|
|
return found_site
|