mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Avoid using message-based IO in the plaintext protocol
Can reuse the machinery in `secio` but need to generalize the "buffering" there
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
from typing import Optional
|
||||
|
||||
from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.io.msgio import MsgIOReadWriter
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
|
||||
@ -14,7 +13,6 @@ class BaseSession(ISecureConn):
|
||||
|
||||
local_peer: ID
|
||||
local_private_key: PrivateKey
|
||||
conn: MsgIOReadWriter
|
||||
remote_peer_id: ID
|
||||
remote_permanent_pubkey: PublicKey
|
||||
|
||||
@ -22,27 +20,14 @@ class BaseSession(ISecureConn):
|
||||
self,
|
||||
local_peer: ID,
|
||||
local_private_key: PrivateKey,
|
||||
conn: MsgIOReadWriter,
|
||||
peer_id: Optional[ID] = None,
|
||||
) -> None:
|
||||
self.local_peer = local_peer
|
||||
self.local_private_key = local_private_key
|
||||
self.remote_peer_id = peer_id
|
||||
self.remote_permanent_pubkey = None
|
||||
|
||||
self.conn = conn
|
||||
self.initiator = peer_id is not None
|
||||
|
||||
async def write(self, data: bytes) -> int:
|
||||
await self.conn.write(data)
|
||||
return len(data)
|
||||
|
||||
async def read(self, n: int = -1) -> bytes:
|
||||
return await self.conn.read(n)
|
||||
|
||||
async def close(self) -> None:
|
||||
await self.conn.close()
|
||||
|
||||
def get_local_peer(self) -> ID:
|
||||
return self.local_peer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user