rename receiver to relay
This commit is contained in:
parent
3348c53aea
commit
a1739c4b7a
2 changed files with 19 additions and 19 deletions
36
argh/node.py
36
argh/node.py
|
@ -21,10 +21,10 @@ class Node:
|
||||||
|
|
||||||
max_known_hashes_size = 1024 * 1024
|
max_known_hashes_size = 1024 * 1024
|
||||||
|
|
||||||
def __init__(self, listen_address: NodeAddr, receivers: list[NodeAddr]):
|
def __init__(self, listen_address: NodeAddr, relays: list[NodeAddr]):
|
||||||
self.listen_address = listen_address
|
self.listen_address = listen_address
|
||||||
self.receivers = list(receivers)
|
self.relays = list(relays)
|
||||||
for r in receivers:
|
for r in relays:
|
||||||
if not isinstance(r, NodeAddr):
|
if not isinstance(r, NodeAddr):
|
||||||
raise TypeError(f"{r} must be of type NodeAddr")
|
raise TypeError(f"{r} must be of type NodeAddr")
|
||||||
# internal
|
# internal
|
||||||
|
@ -39,18 +39,18 @@ class Node:
|
||||||
while len(self._known_hashes) > self.max_known_hashes_size:
|
while len(self._known_hashes) > self.max_known_hashes_size:
|
||||||
self._known_hashes.pop(0)
|
self._known_hashes.pop(0)
|
||||||
|
|
||||||
async def _conn_to_receiver(self, r: NodeAddr):
|
async def _conn_to_relay(self, r: NodeAddr):
|
||||||
identifier = r.identifier()
|
identifier = r.identifier()
|
||||||
log("Attempting to connect to receiver", identifier)
|
log("Attempting to connect to relay", identifier)
|
||||||
async for ws in connect(r.ws_uri()):
|
async for ws in connect(r.ws_uri()):
|
||||||
log("Connected to receiver", identifier)
|
log("Connected to relay", identifier)
|
||||||
self._connections[identifier] = ws
|
self._connections[identifier] = ws
|
||||||
try:
|
try:
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
self._relay(msg)
|
self._relay(msg)
|
||||||
except (ConnectionClosed, ConnectionClosedError):
|
except (ConnectionClosed, ConnectionClosedError):
|
||||||
del self._connections[identifier]
|
del self._connections[identifier]
|
||||||
log(f"Lost connection to receiver", identifier, level=1)
|
log(f"Lost connection to relay", identifier, level=1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
async def _conn_from_node_or_client(self, ws: ServerConnection):
|
async def _conn_from_node_or_client(self, ws: ServerConnection):
|
||||||
|
@ -68,18 +68,18 @@ class Node:
|
||||||
del self._connections[identifier]
|
del self._connections[identifier]
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
# connect to receivers
|
# connect to relays
|
||||||
receiver_tasks = []
|
relay_tasks = []
|
||||||
for r in self.receivers:
|
for r in self.relays:
|
||||||
t = asyncio.create_task(self._conn_to_receiver(r))
|
t = asyncio.create_task(self._conn_to_relay(r))
|
||||||
receiver_tasks.append(t)
|
relay_tasks.append(t)
|
||||||
# server loop
|
# server loop
|
||||||
async with serve(self._conn_from_node_or_client, self.listen_address.host, self.listen_address.port) as server:
|
async with serve(self._conn_from_node_or_client, self.listen_address.host, self.listen_address.port) as server:
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
|
|
||||||
def _close():
|
def _close():
|
||||||
log("Cancelling receiver connections")
|
log("Cancelling relay connections")
|
||||||
for r in receiver_tasks:
|
for r in relay_tasks:
|
||||||
r.cancel()
|
r.cancel()
|
||||||
log("Closing server...")
|
log("Closing server...")
|
||||||
server.close()
|
server.close()
|
||||||
|
@ -91,7 +91,7 @@ class Node:
|
||||||
def node_from_yml(yml_data: str) -> Node:
|
def node_from_yml(yml_data: str) -> Node:
|
||||||
d = yml_load(yml_data)
|
d = yml_load(yml_data)
|
||||||
listen_address = NodeAddr(d["listen"]["host"], d["listen"]["port"])
|
listen_address = NodeAddr(d["listen"]["host"], d["listen"]["port"])
|
||||||
receivers = []
|
relays = []
|
||||||
for e in d["receivers"]:
|
for e in d["relays"]:
|
||||||
receivers.append(NodeAddr(e["host"], e["port"]))
|
relays.append(NodeAddr(e["host"], e["port"]))
|
||||||
return Node(listen_address, receivers)
|
return Node(listen_address, relays)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
listen:
|
listen:
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: 7000
|
port: 7000
|
||||||
receivers:
|
relays:
|
||||||
- host: 127.0.1.1
|
- host: 127.0.1.1
|
||||||
port: 7000
|
port: 7000
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue