nomos-specs/mixnet/connection.py

25 lines
547 B
Python
Raw Normal View History

2024-07-03 23:29:26 +09:00
import abc
from mixnet.framework.framework import Framework
2024-07-03 23:29:26 +09:00
class SimplexConnection(abc.ABC):
@abc.abstractmethod
async def send(self, data: bytes) -> None:
pass
@abc.abstractmethod
async def recv(self) -> bytes:
pass
class LocalSimplexConnection(SimplexConnection):
def __init__(self, framework: Framework):
self.queue = framework.queue()
2024-07-03 23:29:26 +09:00
async def send(self, data: bytes) -> None:
await self.queue.put(data)
async def recv(self) -> bytes:
return await self.queue.get()