From f8240bd2cba930c97faa5a2c3ad5f0253b22ba39 Mon Sep 17 00:00:00 2001 From: mhchia Date: Thu, 20 Feb 2020 22:55:11 +0800 Subject: [PATCH] plaintext: use varint msg read/writer --- libp2p/security/insecure/transport.py | 8 +++----- libp2p/tools/interop/daemon.py | 7 ++----- tests_interop/test_echo.py | 1 - 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libp2p/security/insecure/transport.py b/libp2p/security/insecure/transport.py index 42b7bf8..8211944 100644 --- a/libp2p/security/insecure/transport.py +++ b/libp2p/security/insecure/transport.py @@ -3,7 +3,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 FixedSizeLenMsgReadWriter +from libp2p.io.msgio import VarIntLengthMsgReadWriter from libp2p.network.connection.exceptions import RawConnError from libp2p.network.connection.raw_connection_interface import IRawConnection from libp2p.peer.id import ID @@ -20,11 +20,9 @@ from .pb import plaintext_pb2 PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/2.0.0") -SIZE_PLAINTEXT_LEN_BYTES = 4 - -class PlaintextHandshakeReadWriter(FixedSizeLenMsgReadWriter): - size_len_bytes = SIZE_PLAINTEXT_LEN_BYTES +class PlaintextHandshakeReadWriter(VarIntLengthMsgReadWriter): + max_msg_size = 1 << 16 class InsecureSession(BaseSession): diff --git a/libp2p/tools/interop/daemon.py b/libp2p/tools/interop/daemon.py index 4dfcfb6..95d19ef 100644 --- a/libp2p/tools/interop/daemon.py +++ b/libp2p/tools/interop/daemon.py @@ -8,7 +8,6 @@ import trio from libp2p.peer.id import ID from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr -from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID from libp2p.typing import TProtocol from .constants import LOCALHOST_IP @@ -28,10 +27,8 @@ class P2PDProcess(BaseInteractiveProcess): is_pubsub_signing: bool = False, is_pubsub_signing_strict: bool = False, ) -> None: - args = [f"-listen={control_maddr!s}"] - # NOTE: To support `-insecure`, we need to hack `go-libp2p-daemon`. - if security_protocol == PLAINTEXT_PROTOCOL_ID: - args.append("-insecure=true") + # NOTE: To support `-security`, we need to hack `go-libp2p-daemon`. + args = [f"-listen={control_maddr!s}", f"-security={security_protocol}"] if is_pubsub_enabled: args.append("-pubsub") if is_gossipsub: diff --git a/tests_interop/test_echo.py b/tests_interop/test_echo.py index 6a96ac7..e19d267 100644 --- a/tests_interop/test_echo.py +++ b/tests_interop/test_echo.py @@ -6,7 +6,6 @@ import pytest import trio from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr -from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID from libp2p.tools.factories import HostFactory from libp2p.tools.interop.envs import GO_BIN_PATH from libp2p.tools.interop.process import BaseInteractiveProcess