Wot adjustments, blockdb plugin events

This commit is contained in:
Kevin F 2022-10-01 04:25:46 +00:00
parent 20393a547e
commit 4572f255fb
10 changed files with 46 additions and 21 deletions

View File

@ -1,6 +1,7 @@
from typing import Callable, Generator, List
from onionrblocks import Block
from onionrplugins import onionrevents
import db
@ -15,8 +16,9 @@ block_storage_observers: List[Callable] = []
def add_block_to_db(block: Block):
# Raises db.DuplicateKey if dupe
db.set_if_new(block_db_path, block.id, block.raw)
onionrevents.event('before_block_db_add', block, threaded=False)
db.set_if_new(block_db_path, block.id, block.raw) # Raises db.DuplicateKey if dupe
onionrevents.event('after_block_db_add', block, threaded=False)
def has_block(block_hash):

View File

@ -0,0 +1 @@
import tty

View File

@ -14,6 +14,7 @@ from gossip.peerset import gossip_peer_set
from logger import log as logging
import onionrplugins
from onionrplugins.pluginapis import plugin_apis
locale.setlocale(locale.LC_ALL, '')
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
@ -34,15 +35,24 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
plugin_name = 'wot'
PLUGIN_VERSION = '0.0.0'
PLUGIN_VERSION = '0.0.1'
from wot.identity import identities
from wot.loadfromblocks import load_identities_from_blocks
from wot.identity import get_distance
def on_init(api, data=None):
logging.info(
f"Web of Trust Plugin v{PLUGIN_VERSION} enabled")
#onionrplugins.plugin_apis['wot'] = wot_test
plugin_apis['wot.get_distance'] = get_distance
list(map(lambda x: identities.add(x), load_identities_from_blocks()))
list(
map(
lambda x: identities.add(x),
load_identities_from_blocks())
)
def on_wot_cmd(api, data=None):
return

View File

@ -1,20 +1,11 @@
from typing import TYPE_CHECKING
from enum import IntEnum, auto
import struct
import msgpack
from .identityprocessing import process_identity_announce
if TYPE_CHECKING:
from onionrblocks import Block
from wot.exceptions import InvalidWotBlock
class WotCommand(IntEnum):
TRUST = 1
REVOKE_TRUST = auto()
ANNOUNCE = auto()
REVOKE = auto()
from wot.wotcommand import WotCommand
class WotPayload:
@ -26,6 +17,14 @@ class WotPayload:
match wot_command(WotCommand):
case WotCommand.TRUST:
pass
case WotCommand.REVOKE_TRUST:
pass
case WotCommand.ANNOUNCE:
process_identity_announce(block_data[1:])
case WotCommand.REVOKE:
pass
case _:
raise InvalidWotBlock('Invalid WOT command')
def process_block(bl: 'Block'):

View File

@ -2,7 +2,7 @@ from logger import log as logging
from nacl.signing import VerifyKey
from wot.blockprocessingevent import WotCommand
from wot.wotcommand import WotCommand
from wot.identity import Identity
from wot.identity.identityset import identities

View File

@ -2,7 +2,7 @@ from logger import log as logging
from nacl.signing import VerifyKey
from wot.blockprocessingevent import WotCommand
from wot.wotcommand import WotCommand
from wot.identity import Identity
from wot.identity.identityset import identities

View File

@ -5,7 +5,9 @@ from nacl.signing import VerifyKey
from logger import log as logging
from wot.getbykey import get_identity_by_key
from wot.blockprocessingevent import WotCommand
from wot.wotcommand import WotCommand
from utils import identifyhome
def process_revoke_signature(revoke_signature_payload):

View File

@ -4,7 +4,7 @@ from logger import log as logging
from nacl.signing import VerifyKey
from wot.getbykey import get_identity_by_key
from wot.blockprocessingevent import WotCommand
from wot.wotcommand import WotCommand
def process_trust_signature(sig_payload: bytes):

View File

@ -0,0 +1,7 @@
from enum import IntEnum, auto
class WotCommand(IntEnum):
TRUST = 1
REVOKE_TRUST = auto()
ANNOUNCE = auto()
REVOKE = auto()

View File

@ -5,6 +5,7 @@ from enum import IntEnum, auto
from nacl.signing import SigningKey, VerifyKey
from nacl.exceptions import BadSignatureError
import nacl
import nacl.exceptions
import secrets
import onionrblocks
@ -43,8 +44,11 @@ class TestRevokeIdentityPayload(unittest.TestCase):
signed = signing_key.sign(wot_cmd + bytes(main_iden.key))
revoke_payload = wot_cmd + bytes(signing_key.verify_key) + signed.signature
revoke_payload = bytearray(revoke_payload)
revoke_payload[63] = revoke_payload[63] + 1
revoke_payload = bytes(revoke_payload)
self.assertRaises(nacl.exceptions.Inv process_identity_revoke(revoke_payload)
self.assertRaises(nacl.exceptions.BadSignatureError, process_identity_revoke, revoke_payload)
self.assertEqual(len(identities), 1)