mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Plaintext: use existing msgio reader
This commit is contained in:
@ -1,19 +0,0 @@
|
||||
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()
|
||||
@ -5,6 +5,7 @@ from libp2p.crypto.keys import PrivateKey, PublicKey
|
||||
from libp2p.crypto.pb import crypto_pb2
|
||||
from libp2p.crypto.serialization import deserialize_public_key
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.io.msgio import BaseMsgReadWriter
|
||||
from libp2p.network.connection.exceptions import RawConnError
|
||||
from libp2p.network.connection.raw_connection_interface import IRawConnection
|
||||
from libp2p.peer.id import ID
|
||||
@ -14,7 +15,6 @@ from libp2p.security.exceptions import HandshakeFailure
|
||||
from libp2p.security.secure_conn_interface import ISecureConn
|
||||
from libp2p.typing import TProtocol
|
||||
|
||||
from .io import PlaintextHandshakeReadWriter
|
||||
from .pb import plaintext_pb2
|
||||
|
||||
# Reference: https://github.com/libp2p/go-libp2p-core/blob/master/sec/insecure/insecure.go
|
||||
@ -22,6 +22,12 @@ from .pb import plaintext_pb2
|
||||
|
||||
PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/2.0.0")
|
||||
|
||||
SIZE_PLAINTEXT_LEN_BYTES = 4
|
||||
|
||||
|
||||
class PlaintextHandshakeReadWriter(BaseMsgReadWriter):
|
||||
size_len_bytes = SIZE_PLAINTEXT_LEN_BYTES
|
||||
|
||||
|
||||
class InsecureSession(BaseSession):
|
||||
def __init__(
|
||||
|
||||
Reference in New Issue
Block a user