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:
Alex Stokes
2019-09-04 09:28:53 -07:00
parent f86ba7283d
commit b214f88f75
3 changed files with 28 additions and 22 deletions

View File

@ -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