Compare commits
4 Commits
264eeaa988
...
b59e79a21f
Author | SHA1 | Date | |
---|---|---|---|
|
b59e79a21f | ||
|
3b8644fa8f | ||
|
b2ebc56419 | ||
|
bc71d12b77 |
@ -1 +0,0 @@
|
||||
simplenotifications==0.2.18
|
@ -1,8 +0,0 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile --generate-hashes --output-file=requirements-notifications.txt requirements-notifications.in
|
||||
#
|
||||
simplenotifications==0.2.18 \
|
||||
--hash=sha256:b7efd3d834b1922a3279287913d87fe4ef6fad181ca7edf54bfb8f1d973941e0
|
@ -77,6 +77,7 @@ def daemon():
|
||||
logger.info(
|
||||
f"Onionr daemon is running under pid {os.getpid()}", terminal=True)
|
||||
events.event('init', threaded=False)
|
||||
events.event('afterinit', threaded=False)
|
||||
events.event('daemon_start')
|
||||
|
||||
add_onionr_thread(
|
||||
|
@ -21,6 +21,7 @@ import os, re, importlib
|
||||
import traceback
|
||||
|
||||
from . import onionrevents as events
|
||||
from .pluginapis import plugin_apis
|
||||
import config, logger
|
||||
from utils import identifyhome
|
||||
|
||||
|
7
src/onionrplugins/pluginapis.py
Normal file
7
src/onionrplugins/pluginapis.py
Normal file
@ -0,0 +1,7 @@
|
||||
#
|
||||
from typing import Callable, Dict
|
||||
|
||||
# plugin apis are methods intended to be available to the rpc
|
||||
# plugin, this is so plugins can provide apis to other plugins
|
||||
# plugins add their methods during or before afterinit event
|
||||
plugin_apis: Dict[str, Callable] = {}
|
@ -28,11 +28,12 @@ def identify_home() -> str:
|
||||
"""
|
||||
path = os.environ.get('ONIONR_HOME', None)
|
||||
|
||||
|
||||
if path is None:
|
||||
system = platform.system()
|
||||
if system == 'Linux':
|
||||
path = os.path.expanduser('~') + '/.local/share/onionr/'
|
||||
path = os.environ.get(
|
||||
'XDG_DATA_HOME',
|
||||
os.path.expanduser('~') + '/.local/share/onionr/')
|
||||
elif system == 'Darwin':
|
||||
path = os.path.expanduser('~' +
|
||||
'/Library/Application Support/onionr/')
|
||||
|
@ -6,6 +6,7 @@ import sys
|
||||
import os
|
||||
import locale
|
||||
from threading import Thread
|
||||
from time import sleep
|
||||
|
||||
import cherrypy
|
||||
|
||||
@ -37,11 +38,13 @@ PLUGIN_VERSION = '0.0.0'
|
||||
socket_file_path = identifyhome.identify_home() + 'rpc.sock'
|
||||
|
||||
from jsonrpc import JSONRPCResponseManager, dispatcher
|
||||
import jsonrpc
|
||||
import ujson
|
||||
jsonrpc.manager.json = ujson
|
||||
|
||||
# RPC modules map Onionr APIs to the RPC dispacher
|
||||
from rpc import blocks, pluginrpcmethods
|
||||
|
||||
@dispatcher.add_method
|
||||
def foobar(**kwargs):
|
||||
return kwargs["foo"] + kwargs["bar"]
|
||||
|
||||
class OnionrRPC(object):
|
||||
@cherrypy.expose
|
||||
@ -50,16 +53,18 @@ class OnionrRPC(object):
|
||||
# Dispatcher is dictionary {<method_name>: callable}
|
||||
data = cherrypy.request.body.read().decode('utf-8')
|
||||
|
||||
dispatcher["echo"] = lambda s: s
|
||||
dispatcher["add"] = lambda a, b: a + b
|
||||
|
||||
response = JSONRPCResponseManager.handle(data, dispatcher)
|
||||
return response.json
|
||||
|
||||
|
||||
def on_afterinit(api, data=None):
|
||||
pluginrpcmethods.add_plugin_rpc_methods()
|
||||
|
||||
|
||||
def on_init(api, data=None):
|
||||
config = {
|
||||
'server.socket_file': socket_file_path,
|
||||
#'server.socket_file': socket_file_path,
|
||||
'server.socket_port': 0,
|
||||
'engine.autoreload.on': False
|
||||
}
|
||||
cherrypy.config.update(config)
|
||||
|
25
static-data/default-plugins/rpc/rpc/blocks.py
Normal file
25
static-data/default-plugins/rpc/rpc/blocks.py
Normal file
@ -0,0 +1,25 @@
|
||||
from secrets import randbits
|
||||
|
||||
from onionrblocks import Block
|
||||
from jsonrpc import dispatcher
|
||||
import ujson
|
||||
from base64 import b85decode
|
||||
|
||||
from gossip.blockqueues import gossip_block_queues
|
||||
from blockdb import get_blocks_after_timestamp
|
||||
|
||||
|
||||
@dispatcher.add_method
|
||||
def get_blocks(timestamp):
|
||||
return [block.raw for block in get_blocks_after_timestamp(timestamp)]
|
||||
|
||||
|
||||
queue_to_use = randbits(1)
|
||||
@dispatcher.add_method
|
||||
def insert_block(block):
|
||||
block = Block(
|
||||
block['id'], b85decode(block['raw']), auto_verify=False)
|
||||
gossip_block_queues[queue_to_use].put_nowait(block)
|
||||
return "ok"
|
||||
|
||||
#dispatcher['get_blocks_after_timestamp'] = get_blocks_after_timestamp
|
8
static-data/default-plugins/rpc/rpc/pluginrpcmethods.py
Normal file
8
static-data/default-plugins/rpc/rpc/pluginrpcmethods.py
Normal file
@ -0,0 +1,8 @@
|
||||
from jsonrpc import dispatcher
|
||||
|
||||
from onionrplugins.pluginapis import plugin_apis
|
||||
|
||||
|
||||
def add_plugin_rpc_methods():
|
||||
for method in plugin_apis:
|
||||
dispatcher[method] = plugin_apis[method]
|
1
static-data/default-plugins/wot/.env
Normal file
1
static-data/default-plugins/wot/.env
Normal file
@ -0,0 +1 @@
|
||||
PYTHONPATH=./venv/bin/python310:../../src/:./
|
4
static-data/default-plugins/wot/info.json
Normal file
4
static-data/default-plugins/wot/info.json
Normal file
@ -0,0 +1,4 @@
|
||||
{ "name": "example",
|
||||
"version": "0.0.0",
|
||||
"author": "onionr"
|
||||
}
|
52
static-data/default-plugins/wot/main.py
Normal file
52
static-data/default-plugins/wot/main.py
Normal file
@ -0,0 +1,52 @@
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Default example plugin for devs or to test blocks
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import locale
|
||||
from time import sleep
|
||||
import traceback
|
||||
from typing import Set, TYPE_CHECKING
|
||||
from threading import Thread, local
|
||||
import blockdb
|
||||
from gossip.peerset import gossip_peer_set
|
||||
|
||||
|
||||
import logger
|
||||
|
||||
import onionrplugins
|
||||
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
# import after path insert
|
||||
|
||||
"""
|
||||
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/>.
|
||||
"""
|
||||
|
||||
|
||||
plugin_name = 'wot'
|
||||
PLUGIN_VERSION = '0.0.0'
|
||||
|
||||
|
||||
def wot_test(arg: int):
|
||||
return arg + 1
|
||||
|
||||
|
||||
|
||||
def on_init(api, data=None):
|
||||
logger.info(
|
||||
f"Web of Trust Plugin v{PLUGIN_VERSION} enabled", terminal=True)
|
||||
onionrplugins.plugin_apis['wot'] = wot_test
|
0
static-data/default-plugins/wot/wot/__init__.py
Normal file
0
static-data/default-plugins/wot/wot/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user