From e6072da8e409ef16d32d3ab25aa655437536efaa Mon Sep 17 00:00:00 2001 From: nolash Date: Mon, 25 Jan 2021 18:22:06 +0100 Subject: [PATCH] Add tcp server --- CHANGELOG | 1 + crypto_dev_signer/runnable/signer.py | 26 ++++++++++++++++++++++---- setup.py | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e2c4007..3c5a15c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Remove unused insert_key method in keystore interface - Add transaction executor helper, with adapter helper for eth - Fix bitlength of integers in all tx fields before rlp encoding + - Add tcp server * 0.4.12 - Enforce hex strings in signer backend for sign message * 0.4.11 diff --git a/crypto_dev_signer/runnable/signer.py b/crypto_dev_signer/runnable/signer.py index e0cf04a..aada7d1 100755 --- a/crypto_dev_signer/runnable/signer.py +++ b/crypto_dev_signer/runnable/signer.py @@ -17,10 +17,10 @@ from crypto_dev_signer.eth.transaction import EIP155Transaction from crypto_dev_signer.keystore import ReferenceKeystore from crypto_dev_signer.error import UnknownAccountError -#logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(level=logging.WARNING) logg = logging.getLogger() -config_dir = os.path.join('/usr/local/etc/cic-eth') +config_dir = '.' db = None signer = None @@ -165,7 +165,14 @@ def process_input(j): return (rpc_id, methods[m](p)) -def start_server(): +def start_server_lo(spec): + s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM) + s.bind(spec) + logg.debug('created tcp socket {}'.format(spec)) + start_server(s) + + +def start_server_ipc(socket_path): socket_dir = os.path.dirname(socket_path) try: fi = os.stat(socket_dir) @@ -180,7 +187,12 @@ def start_server(): pass s = socket.socket(family = socket.AF_UNIX, type = socket.SOCK_STREAM) s.bind(socket_path) + logg.debug('created unix ipc socket {}'.format(socket_path)) + start_server(s) + +def start_server(s): s.listen(10) + logg.debug('server started') while True: (csock, caddr) = s.accept() d = csock.recv(4096) @@ -235,7 +247,13 @@ def main(): arg = json.loads(sys.argv[1]) except: logg.info('no json rpc command detected, starting socket server') - start_server() + socket_spec = socket_path.split(':') + if len(socket_spec) == 2: + host = socket_spec[0] + port = int(socket_spec[1]) + start_server_lo((host, port)) + else: + start_server_ipc(socket_path) sys.exit(0) (rpc_id, response) = process_input(arg) diff --git a/setup.py b/setup.py index 68ba52c..084b2be 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ f.close() setup( name="crypto-dev-signer", - version="0.4.13b10", + version="0.4.13b11", description="A signer and keystore daemon and library for cryptocurrency software development", author="Louis Holbrook", author_email="dev@holbrook.no",