Skip to content

Commit

Permalink
node cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayBlagoev committed Apr 13, 2024
1 parent 9fc9bae commit 98d2a3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions deccom/nodes/streamnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ def __init__(self, p: Peer, protocol: StreamProtocol, ip_addr="0.0.0.0", port=No

async def listen(self):
loop = asyncio.get_running_loop()
listen = loop.create_datagram_endpoint(self.protocol_type.get_lowest, local_addr=(self.ip_addr, self.port))
self.transport, self.protocol = await listen
self.udp = loop.create_datagram_endpoint(self.protocol_type.get_lowest, local_addr=(self.ip_addr, self.port))

self.transport, self.protocol = await self.udp
print(self.protocol_type.get_lowest_stream().handle_connection)
self.server = await asyncio.start_server(
self.protocol_type.get_lowest_stream().handle_connection, sock=self.s)

await self.protocol_type.start(self.peer)

async def close(self):
self.udp.close()
self.transport.close()
self.server.close()
async def stream_data(self, node_id, data):
# print("sending stream")

Expand Down
2 changes: 2 additions & 0 deletions deccom/protocols/abstractprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def check_if_have(submodule, attr, name = None)->bool:
async def _lower_stop(self):
return
async def stop(self):
if not self.started:
return
self.started = False

return await self._lower_stop()
Expand Down
2 changes: 1 addition & 1 deletion deccom/protocols/streamprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class StreamProtocol(AbstractProtocol):
"_lower_get_peer": "get_peer",

})
required_lower = AbstractProtocol.required_lower + ["get_peer", "set_connected_callback", "set_disconnected_callback"]
required_lower = AbstractProtocol.required_lower + ["get_peer"]
def __init__(self, always_connect: bool, submodule=None, callback: Callable[[tuple[str, int], bytes], None] = lambda addr, data: print(addr, data),disconnected_callback = lambda addr,nodeid: print(nodeid, "disconnected"),
connected_callback = lambda addr, peer: ..., stream_callback = lambda data, node_id, addr: ..., stream_close_callback = lambda node_id,addr: ...):
super().__init__(submodule, callback)
Expand Down

0 comments on commit 98d2a3f

Please sign in to comment.