PR feedback: set protocol_id to constants

This commit is contained in:
mhchia 2019-08-20 11:02:21 +08:00
parent d7d8440b2c
commit 8596f7390f
No known key found for this signature in database
GPG Key ID: 389EFBEA1362589A
3 changed files with 10 additions and 5 deletions

View File

@ -13,9 +13,9 @@ from libp2p.peer.peerstore import PeerStore
from libp2p.peer.peerstore_interface import IPeerStore
from libp2p.routing.interfaces import IPeerRouting
from libp2p.routing.kademlia.kademlia_peer_router import KadmeliaPeerRouter
from libp2p.security.insecure.transport import InsecureTransport
from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID, InsecureTransport
from libp2p.security.secure_transport_interface import ISecureTransport
from libp2p.stream_muxer.mplex.mplex import Mplex
from libp2p.stream_muxer.mplex.mplex import MPLEX_PROTOCOL_ID, Mplex
from libp2p.stream_muxer.muxer_multistream import MuxerClassType
from libp2p.transport.tcp.tcp import TCP
from libp2p.transport.upgrader import TransportUpgrader
@ -96,10 +96,9 @@ def initialize_default_swarm(
# TODO: Parse `transport_opt` to determine transport
transport = TCP()
# TODO TransportUpgrader is not doing anything really
muxer_transports_by_protocol = muxer_opt or {TProtocol("/mplex/6.7.0"): Mplex}
muxer_transports_by_protocol = muxer_opt or {MPLEX_PROTOCOL_ID: Mplex}
security_transports_by_protocol = sec_opt or {
TProtocol("/plaintext/1.0.0"): InsecureTransport(key_pair)
PLAINTEXT_PROTOCOL_ID: InsecureTransport(key_pair)
}
upgrader = TransportUpgrader(
security_transports_by_protocol, muxer_transports_by_protocol

View File

@ -3,6 +3,9 @@ from libp2p.peer.id import ID
from libp2p.security.base_session import BaseSession
from libp2p.security.base_transport import BaseSecureTransport
from libp2p.security.secure_conn_interface import ISecureConn
from libp2p.typing import TProtocol
PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/1.0.0")
class InsecureSession(BaseSession):

View File

@ -8,12 +8,15 @@ from libp2p.network.typing import GenericProtocolHandlerFn
from libp2p.peer.id import ID
from libp2p.security.secure_conn_interface import ISecureConn
from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream
from libp2p.typing import TProtocol
from .constants import HeaderTags
from .exceptions import StreamNotFound
from .mplex_stream import MplexStream
from .utils import decode_uvarint_from_stream, encode_uvarint
MPLEX_PROTOCOL_ID = TProtocol("/mplex/6.7.0")
class Mplex(IMuxedConn):
"""