let example node.py run as second node server

This commit is contained in:
Brian Muller 2021-04-12 10:07:48 -04:00
parent 1194bda2ad
commit 5053e5e61c
No known key found for this signature in database
GPG Key ID: 19A500213CC84E3B
2 changed files with 16 additions and 4 deletions

View File

@ -24,10 +24,21 @@ def parse_arguments():
return parser.parse_args() return parser.parse_args()
async def connect_to_bootstrap_node(args): def connect_to_bootstrap_node(args):
await server.listen(8469) loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(server.listen(8469))
bootstrap_node = (args.ip, int(args.port)) bootstrap_node = (args.ip, int(args.port))
await server.bootstrap([bootstrap_node]) loop.run_until_complete(server.bootstrap([bootstrap_node]))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
server.stop()
loop.close()
def create_bootstrap_node(): def create_bootstrap_node():
@ -49,7 +60,7 @@ def main():
args = parse_arguments() args = parse_arguments()
if args.ip and args.port: if args.ip and args.port:
asyncio.run(connect_to_bootstrap_node(args)) connect_to_bootstrap_node(args)
else: else:
create_bootstrap_node() create_bootstrap_node()

View File

@ -1,5 +1,6 @@
import random import random
import hashlib import hashlib
# pylint: disable=no-name-in-module
from struct import pack from struct import pack
import pytest import pytest