logging level fixes to make output less spammy about connection blips

This commit is contained in:
Kevin F 2023-01-23 16:20:03 -06:00
parent db59a198f5
commit 0236fc83f4
8 changed files with 38 additions and 13 deletions

View File

@ -22,6 +22,8 @@ def _do_ask_peer(peer):
_ask_peer(peer) _ask_peer(peer)
except TimeoutError: except TimeoutError:
logging.debug("Timed out when asking for new peers") logging.debug("Timed out when asking for new peers")
except ConnectionError:
pass
except Exception: except Exception:
logging.error(format_exc()) logging.error(format_exc())

View File

@ -11,8 +11,8 @@ def connect_peer(peer):
try: try:
s = peer.get_socket(120) s = peer.get_socket(120)
except Exception: except Exception:
logging.warn(f"Could not connect to {peer.transport_address}") logging.debug(f"Could not connect to {peer.transport_address}")
logging.warn(traceback.format_exc()) logging.debug(traceback.format_exc())
else: else:
with s: with s:
s.sendall(command_to_byte(GossipCommands.PING)) s.sendall(command_to_byte(GossipCommands.PING))

View File

@ -88,7 +88,7 @@ def gossip_server():
try: try:
await diffuse_blocks(reader, writer) await diffuse_blocks(reader, writer)
except Exception: except Exception:
logging.warn( logging.debug(
f"Err streaming blocks\n{traceback.format_exc()}", f"Err streaming blocks\n{traceback.format_exc()}",
) )
case GossipCommands.PUT_BLOCKS: case GossipCommands.PUT_BLOCKS:

View File

@ -6,13 +6,17 @@ import sys
import os import os
import locale import locale
from time import sleep from time import sleep
import base64
from logger import log as logging from logger import log as logging
from typing import Set, TYPE_CHECKING from typing import Set, TYPE_CHECKING
import onionrplugins
import requests
import requests_unixsocket
import blockdb import blockdb
from gossip.peerset import gossip_peer_set import config
import onionrblocks
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
@ -37,9 +41,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
plugin_name = 'example' plugin_name = 'example'
PLUGIN_VERSION = '0.0.0' PLUGIN_VERSION = '0.0.0'
rpc_payload_template = {
"method": "echo",
"params": ["example"],
"jsonrpc": "2.0",
"id": 0,
}
def on_blocktest_cmd(api, data=None): def on_blocktest_cmd(api, data=None):
bl = onionrblocks.create_anonvdf_block(input("Enter a message:").encode('utf-8'), b"tst", 3600) message = base64.b64encode(input("Enter a message ").encode('utf-8')).decode('utf-8')
payload = rpc_payload_template
payload['method'] = 'create_and_insert_block'
payload['params'] = [message, "tst", 3600, {}]
req = onionrplugins.pluginapis.plugin_apis['rpc.rpc_client'](json=payload).text
print(req)
def on_printtest_cmd(api, data=None): def on_printtest_cmd(api, data=None):

View File

@ -1,7 +1,9 @@
from secrets import randbits from secrets import randbits
import base64 import base64
from typing import Union from typing import Union
import ujson
from onionrblocks import Block from onionrblocks import Block
import onionrblocks import onionrblocks
from jsonrpc import dispatcher from jsonrpc import dispatcher
@ -28,8 +30,7 @@ def get_blocks(timestamp):
return blocks return blocks
@dispatcher.add_method def _do_create_block(
def create_block(
block_data: 'base64', block_type: str, ttl: int, metadata: dict): block_data: 'base64', block_type: str, ttl: int, metadata: dict):
# Wrapper for onionrblocks.create_block # Wrapper for onionrblocks.create_block
# (take base64 to be compatible with RPC) # (take base64 to be compatible with RPC)
@ -51,14 +52,19 @@ def create_block(
} }
return bl_json return bl_json
@dispatcher.add_method
def create_block(
block_data: 'base64', block_type: str, ttl: int, metadata: dict):
return _do_create_block(block_data, block_type, ttl, metadata)
@dispatcher.add_method @dispatcher.add_method
def create_and_insert_block( def create_and_insert_block(
block_data: 'base64', block_data: 'base64',
block_type: str, ttl: int, metadata: dict) -> str: block_type: str, ttl: int, metadata: dict) -> str:
bl = create_block(block_data, block_type, ttl, metadata)['id'] bl = _do_create_block(block_data, block_type, ttl, metadata)['id']
insert_block(bl) insert_block(bl)
return bl['id'] return bl
# As per dandelion++ spec the edge should be the same. # As per dandelion++ spec the edge should be the same.

View File

@ -0,0 +1 @@
iub5tjg3iu23btf7depeohyefv3n52izqcomprrrn72hvlrnvp5fjlyd,diqljvlqppawyki3lo2emh3sibvhflmn7d736gqcr5m6obrnfn6cytyd

View File

@ -1,6 +1,6 @@
"""Onionr - Private P2P Communication. """Onionr - Private P2P Communication.
Unix transport plugin. Intended for testing Onionr networks using IPC Unix transport plugin. Intended for testing Onionr without actual network traffic.
""" """
import sys import sys
import os import os

View File

@ -80,7 +80,7 @@ def on_init(api, data=None):
except IndexError: except IndexError:
script = '' script = ''
logging.info( logging.info(
f"Generate a web of trust identity with '{script}wot new" + f"Generate a web of trust identity with '{script}wot new " +
"<name>' and restart Onionr") "<name>' and restart Onionr")
return return