mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-08 14:10:54 +00:00
Security: SecureSession
Make security sessions(secio, noise) share the same implementation `BaseSession` to avoid duplicate implementation of buffered read.
This commit is contained in:
19
libp2p/security/insecure/io.py
Normal file
19
libp2p/security/insecure/io.py
Normal file
@ -0,0 +1,19 @@
|
||||
from libp2p.io.abc import MsgReadWriteCloser, ReadWriteCloser
|
||||
from libp2p.utils import encode_fixedint_prefixed, read_fixedint_prefixed
|
||||
|
||||
|
||||
class PlaintextHandshakeReadWriter(MsgReadWriteCloser):
|
||||
conn: ReadWriteCloser
|
||||
|
||||
def __init__(self, conn: ReadWriteCloser) -> None:
|
||||
self.conn = conn
|
||||
|
||||
async def read_msg(self) -> bytes:
|
||||
return await read_fixedint_prefixed(self.conn)
|
||||
|
||||
async def write_msg(self, msg: bytes) -> None:
|
||||
encoded_msg_bytes = encode_fixedint_prefixed(msg)
|
||||
await self.conn.write(encoded_msg_bytes)
|
||||
|
||||
async def close(self) -> None:
|
||||
await self.conn.close()
|
||||
Reference in New Issue
Block a user