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