Skip to content

Commit

Permalink
dnet: generalize rpc to work with remote hosts as well as localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
lunar-mining committed Oct 18, 2023
1 parent d401aff commit 37db5a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions bin/dnet/config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
[[nodes]]
name = "darkirc"
host = "localhost"
port = 26660

[[nodes]]
name = "taud"
host = "localhost"
port = 23330

[[nodes]]
name = "agorism"
host = "agorism.dev"
port = 26660

12 changes: 7 additions & 5 deletions bin/dnet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ def __init__(self):
self.model = Model()
self.view = View(self.model)

async def subscribe(self, rpc, name, port):
async def subscribe(self, rpc, name, host, port):
info = {}
while True:
try:
#logging.debug(f"Start {name} RPC on port {port}")
await rpc.start("localhost", port)
await rpc.start(host, port)
logging.debug(f"Started {name} RPC on port {port}")
break
# TODO: offline node handling
except OSError:
except Exception as e:
logging.debug(f"failed to connect {host}:{port} {e}")
pass

data = await rpc._make_request("p2p.get_info", [])
Expand Down Expand Up @@ -79,7 +80,8 @@ async def start_connect_slots(self, nodes):
for i, node in enumerate(nodes):
rpc = JsonRpc()
subscribe = tg.create_task(self.subscribe(
rpc, node['name'], node['port']))
rpc, node['name'], node['host'],
node['port']))
nodes = tg.create_task(self.update_info())

async def update_info(self):
Expand Down
1 change: 1 addition & 0 deletions bin/dnet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def update_node(self, key, value):
self.nodes[key] = value

def handle_nodes(self, node):
logging.debug(node)
channel_lookup = {}
name = list(node.keys())[0]
values = list(node.values())[0]
Expand Down
5 changes: 3 additions & 2 deletions bin/dnet/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

class JsonRpc:

async def start(self, server, port):
reader, writer = await asyncio.open_connection(server, port)
async def start(self, host, port):
logging.info(f"trying to connect to {host}:{port}")
reader, writer = await asyncio.open_connection(host, port)
self.reader = reader
self.writer = writer

Expand Down

0 comments on commit 37db5a0

Please sign in to comment.