added traceback handler
This commit is contained in:
parent
5ea90acd3f
commit
9d546432f5
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
from base64 import b85decode
|
||||
import sys
|
||||
import os
|
||||
|
||||
@ -13,7 +14,7 @@ metadata = json.loads(sys.argv[1])
|
||||
block_type = sys.argv[2]
|
||||
ttl = int(sys.argv[3])
|
||||
|
||||
data = sys.stdin.read()
|
||||
data = b85decode(sys.stdin.read())
|
||||
|
||||
with os.fdopen(sys.stdout.fileno(), 'wb') as stdout:
|
||||
bl = blockcreator.create_anonvdf_block(data, block_type, ttl, **metadata)
|
||||
|
@ -56,6 +56,6 @@ def register_private_blueprints(private_api, app):
|
||||
app.register_blueprint(
|
||||
private_api._too_many.get_by_string('DaemonEventsBP').flask_bp)
|
||||
|
||||
Thread(target=_add_events_bp).start()
|
||||
Thread(target=_add_events_bp, name='Private blueprints adder').start()
|
||||
|
||||
return app
|
||||
|
@ -77,5 +77,7 @@ class BlockCreatorQueue:
|
||||
*self.additional_callback_func_args,
|
||||
**self.additional_callback_func_kwargs)
|
||||
|
||||
Thread(target=_do_create, daemon=True).start()
|
||||
Thread(
|
||||
target=_do_create, daemon=True,
|
||||
name="BlockCreatorQueue block creation").start()
|
||||
return digest
|
||||
|
@ -1,3 +1,4 @@
|
||||
from base64 import b85encode
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
@ -10,6 +11,7 @@ _DIR = os.path.dirname(os.path.realpath(__file__)) + '/../'
|
||||
|
||||
|
||||
def vdf_block(data, data_type, ttl, **metadata):
|
||||
data = b85encode(data)
|
||||
generated = subprocess.Popen(
|
||||
[
|
||||
f'{_DIR}anonvdf-block-creator.py',
|
||||
|
@ -7,6 +7,8 @@ import sys
|
||||
import platform
|
||||
import signal
|
||||
from threading import Thread
|
||||
from threading import enumerate as thread_enumerate
|
||||
import traceback
|
||||
|
||||
from stem.connection import IncorrectPassword
|
||||
import stem
|
||||
@ -44,7 +46,7 @@ from sneakernet import sneakernet_import_thread
|
||||
from onionrstatistics.devreporting import statistics_reporter
|
||||
from setupkvvars import setup_kv
|
||||
from communicatorutils.housekeeping import clean_blocks_not_meeting_pow
|
||||
from blockcreatorqueue import BlockCreatorQueue, PassToSafeDB
|
||||
from blockcreatorqueue import PassToSafeDB
|
||||
from .spawndaemonthreads import spawn_client_threads
|
||||
from .loadsafedb import load_safe_db
|
||||
"""
|
||||
@ -144,7 +146,43 @@ def daemon():
|
||||
logger.info(
|
||||
f"Recieved sigterm in child process or fork, exiting. PID: {pid}")
|
||||
sys.exit(0)
|
||||
|
||||
def _handle_sigusr1(sig, frame):
|
||||
traceback_file = identifyhome.identify_home() + "/traceback"
|
||||
id2name = dict([(th.ident, th.name) for th in thread_enumerate()])
|
||||
code = []
|
||||
for thread_id, stack in sys._current_frames().items():
|
||||
code.append(
|
||||
"\n# Thread: %s(%d)" %
|
||||
(id2name.get(thread_id, ""), thread_id))
|
||||
for filename, lineno, name, line in traceback.extract_stack(stack):
|
||||
code.append(
|
||||
'File: "%s", line %d, in %s' % (filename, lineno, name))
|
||||
if line:
|
||||
code.append(" %s" % (line.strip()))
|
||||
with open(traceback_file, 'w') as tb_f:
|
||||
tb_f.write("\n".join(code))
|
||||
logger.info(
|
||||
f"Wrote traceback of all main process threads to {traceback_file}",
|
||||
terminal=True)
|
||||
|
||||
def _sigusr1_thrower():
|
||||
wait_for_write_pipe = identifyhome.identify_home() + \
|
||||
"/activate-traceback"
|
||||
try:
|
||||
os.mkfifo(wait_for_write_pipe)
|
||||
except FileExistsError:
|
||||
pass
|
||||
with open(wait_for_write_pipe, "r") as f:
|
||||
f.read()
|
||||
os.kill(os.getpid(), signal.SIGUSR1)
|
||||
|
||||
signal.signal(signal.SIGTERM, _handle_sig_term)
|
||||
signal.signal(signal.SIGUSR1, _handle_sigusr1)
|
||||
|
||||
Thread(
|
||||
target=_sigusr1_thrower,
|
||||
daemon=True, name="siguser1 wait and throw").start()
|
||||
|
||||
# Determine if Onionr is in offline mode.
|
||||
# When offline, Onionr can only use LAN and disk transport
|
||||
|
@ -84,7 +84,7 @@ class OnionrRunTestManager:
|
||||
logger.error(last.__name__ + ' failed assertions', terminal=True)
|
||||
except Exception as e:
|
||||
logger.error(last.__name__ + ' failed with non-asserting exception')
|
||||
logger.error(str(e))
|
||||
logger.error(repr(e))
|
||||
else:
|
||||
ep = str(epoch.get_epoch())
|
||||
logger.info(f'All runtime tests passed at {ep}', terminal=True)
|
||||
|
@ -1,15 +1,14 @@
|
||||
import os
|
||||
|
||||
from gevent import sleep
|
||||
|
||||
from oldblocks import insert
|
||||
import logger
|
||||
import config
|
||||
from coredb.blockmetadb import get_block_list
|
||||
from onionrutils import epoch
|
||||
|
||||
|
||||
def test_inserted_housekeeping(testmanager):
|
||||
"""Tests that inserted blocks are proprely deleted"""
|
||||
if config.get('runtests.skip_slow', False):
|
||||
return
|
||||
bl = insert('testdata', expire=12)
|
||||
wait_seconds = 132 # Wait two minutes plus expire time
|
||||
count = 0
|
||||
|
@ -27,6 +27,8 @@ from onionrutils import localcommand
|
||||
def test_own_node(test_manager):
|
||||
if config.get('general.security_level', 0) > 0 or not config.get('transports.tor', True):
|
||||
return
|
||||
if config.get('runtests.skip_slow', False):
|
||||
return
|
||||
socks_port = localcommand.local_command('/gettorsocks')
|
||||
if config.get('general.security_level', 0) > 0:
|
||||
return
|
||||
|
@ -9,10 +9,12 @@ from etc.onionrvalues import BLOCK_EXPORT_FILE_EXT
|
||||
from onionrstorage.removeblock import remove_block
|
||||
from onionrstorage import deleteBlock
|
||||
from coredb.blockmetadb import get_block_list
|
||||
from utils import bettersleep
|
||||
import config
|
||||
from gevent import sleep
|
||||
|
||||
def test_sneakernet_import(test_manager):
|
||||
if not config.get('transports.lan', False):
|
||||
return
|
||||
in_db = lambda b: b in get_block_list()
|
||||
bl = insert(os.urandom(10))
|
||||
assert in_db(bl)
|
||||
|
@ -68,3 +68,13 @@ ZABkAWwAWgBkAGQBbAFaAWQAZAJsAm0DWgMBAGQAZANsBG0FWgUBAGQAZ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agNkA6ECAQBkAWQCbARaBGQBZAJsBVoFZAFkBGwGbQdaBwEAZQRqCKAJZAFlBWoIoAplBWoIoAtlDKEBoQGhAgEAZAVaDXooZAFkBmwObQ9aDwEAZAFkB2wQbRFaEQEAZAFkCGwSbRNaEwEAVwBuLgQAZRRrCnKuAQBaFQEAehBlFmUXZRWDAYMBAQBXADUAZAJaFVsVWABZAG4CWABkC2QJZAqEAVoYZAJTAA==
|
||||
ZABaAGQBZAJsAW0CWgIBAGQBZANsA20EWgQBAGQBZARsBVoFZAFkBGwBWgFkAWQFbAZtB1oHAQBkBmUIZAecAmQIZAmEBFoJZApkC4QAWgplCGQMnAFkDWQOhARaC2QPZBCEAFoMZQhkDJwBZBFkEoQEWg1kE2QUhABaDmQEUwA=
|
||||
ZABaAGQBZAJsAW0CWgIBAGQBZANsA20EWgRtBVoFAQBkAWQEbAZtBloGAQBkAWQFbAdtCFoIAQBkAWQGbAlaCUcAZAdkCIQAZAiDAloKZAZTAA==
|
||||
ZABkAWwAWgBkAGQBbAFaAWQAZAJsAm0DWgMBAGQAZANsBG0FWgUBAGQAZARsBm0HWgcBAGQAZAVsCG0JWgkBAGQAZAZsCm0LWgsBAGQAZAdsDG0NWg0BAGQAZAFsCloKZAhkCYQAWg5kCmQLhABaD2QBUwA=
|
||||
ZABkAWwAWgBkAGQBbAFaAWQAZAFsAloCZABkAmwDbQRaBAEAZABkA2wFbQZaBgEAZABkBGwHbQhaCAEAZABkBWwJbQpaCgEAZABkBmwLbQxaDAEAZABkAWwJWglkB2QIhABaDWQJZAqEAFoOZAFTAA==
|
||||
ZABTAA==
|
||||
ZQBGAGQAUwA=
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
Handle commands for the torgossip server
|
||||
"""
|
||||
from typing import type_check_only
|
||||
from onionrblocks import generators
|
||||
from onionrblocks.generators import anonvdf
|
||||
import blockio
|
||||
|
@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
class GossipCommands(IntEnum):
|
||||
PING = 1,
|
||||
CHECK_HAS_BLOCK = 2,
|
||||
|
@ -25,17 +25,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
plugin_name = 'torgossip'
|
||||
|
||||
try:
|
||||
from server import start_server
|
||||
from peerdb import Peers
|
||||
from peerdb import TorGossipPeers
|
||||
from runtest import torgossip_runtest
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
||||
|
||||
def on_init(api, data=None):
|
||||
shared_state = data
|
||||
|
||||
shared_state.get(Peers)
|
||||
|
||||
shared_state.get_by_string(
|
||||
"OnionrRunTestManager").plugin_tests.append(torgossip_runtest)
|
||||
|
||||
shared_state.get(TorGossipPeers)
|
||||
|
||||
|
||||
Thread(target=start_server, daemon=True, args=[shared_state]).start()
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
Torgossip peer safedb interface
|
||||
"""
|
||||
from typing import TYPE_CHECKING
|
||||
from base64 import b32decode
|
||||
from struct import unpack, pack
|
||||
frome time import time
|
||||
from time import time
|
||||
|
||||
from utils.identifyhome import identify_home
|
||||
import safedb
|
||||
|
@ -1,6 +1,7 @@
|
||||
import socket
|
||||
import os
|
||||
from threading import local
|
||||
import secrets
|
||||
from base64 import b32encode
|
||||
|
||||
from utils import identifyhome
|
||||
from onionrblocks import blockcreator
|
||||
@ -8,6 +9,11 @@ from blockio import subprocgenerate
|
||||
from onionrutils import localcommand
|
||||
import blockio
|
||||
|
||||
|
||||
def _fake_onion():
|
||||
return b32encode(os.urandom(34)).decode('utf-8') + ".onion"
|
||||
|
||||
|
||||
def torgossip_runtest(test_manager):
|
||||
|
||||
|
||||
@ -20,12 +26,13 @@ def torgossip_runtest(test_manager):
|
||||
blockio.store_block(bl, shared_state.get_by_string("SafeDB"))
|
||||
|
||||
tsts = b''
|
||||
for i in range(3):
|
||||
bl = subprocgenerate.vdf_block(b"test" + os.urandom(3), "tst", 100)
|
||||
tsts += bl.id
|
||||
blockio.store_block(bl, shared_state.get_by_string("SafeDB"))
|
||||
|
||||
bl_new = blockcreator.create_anonvdf_block(b"test5", "txt", 10)
|
||||
for i in range(3):
|
||||
bl2 = subprocgenerate.vdf_block(b"what" + os.urandom(4), "tbt", 100)
|
||||
tsts += bl2.id
|
||||
blockio.store_block(bl2, shared_state.get_by_string("SafeDB"))
|
||||
|
||||
bl_new = blockcreator.create_anonvdf_block(b"what", "txt", 10)
|
||||
|
||||
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
||||
@ -41,8 +48,10 @@ def torgossip_runtest(test_manager):
|
||||
assert bl.id in s.recv(10000)
|
||||
|
||||
# test getting a block that doesn't exist
|
||||
s.sendall(b'5' + os.urandom(64))
|
||||
assert s.recv(64) == b"0"
|
||||
s.sendall(b'5' + int(secrets.randbits(64)).to_bytes(64, 'little'))
|
||||
|
||||
#print(len(s.recv(64)))
|
||||
assert s.recv(64)[0] == ord(b'0')
|
||||
|
||||
# test getting a block that does exist
|
||||
s.sendall(b'5' + bl.id)
|
||||
@ -63,8 +72,10 @@ def torgossip_runtest(test_manager):
|
||||
assert s.recv(1000) == tsts[64*2:]
|
||||
|
||||
# test peer list
|
||||
|
||||
shared_state.get_by_string('TorGossipPeers').add_peer()
|
||||
#fake_peer = _fake_onion()
|
||||
#shared_state.get_by_string('TorGossipPeers').add_peer(fake_peer)
|
||||
#s.sendall(b'71')
|
||||
#assert s.recv(100) == fake_peer
|
||||
|
||||
s.sendall(b'9')
|
||||
assert s.recv(64) == b"BYE"
|
||||
|
@ -49,6 +49,9 @@
|
||||
"disabled": [],
|
||||
"enabled": []
|
||||
},
|
||||
"runtests": {
|
||||
"skip_slow": false
|
||||
},
|
||||
"security": {
|
||||
"encrypt_database": false
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user