run black
This commit is contained in:
parent
9e0a806218
commit
7a04ebb51f
|
@ -90,9 +90,7 @@ class Mplex(IMuxedConn):
|
||||||
# Stream not created yet
|
# Stream not created yet
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def open_stream(
|
async def open_stream(self, protocol_id: str, multi_addr: Multiaddr) -> IMuxedStream:
|
||||||
self, protocol_id: str, multi_addr: Multiaddr
|
|
||||||
) -> IMuxedStream:
|
|
||||||
"""
|
"""
|
||||||
creates a new muxed_stream
|
creates a new muxed_stream
|
||||||
:param protocol_id: protocol_id of stream
|
:param protocol_id: protocol_id of stream
|
||||||
|
|
|
@ -47,11 +47,7 @@ class MplexStream(IMuxedStream):
|
||||||
write to stream
|
write to stream
|
||||||
:return: number of bytes written
|
:return: number of bytes written
|
||||||
"""
|
"""
|
||||||
flag = (
|
flag = HeaderTags.MessageInitiator if self.initiator else HeaderTags.MessageReceiver
|
||||||
HeaderTags.MessageInitiator
|
|
||||||
if self.initiator
|
|
||||||
else HeaderTags.MessageReceiver
|
|
||||||
)
|
|
||||||
return await self.mplex_conn.send_message(flag, data, self.stream_id)
|
return await self.mplex_conn.send_message(flag, data, self.stream_id)
|
||||||
|
|
||||||
async def close(self) -> bool:
|
async def close(self) -> bool:
|
||||||
|
@ -93,11 +89,7 @@ class MplexStream(IMuxedStream):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not self.remote_closed:
|
if not self.remote_closed:
|
||||||
flag = (
|
flag = HeaderTags.ResetInitiator if self.initiator else HeaderTags.ResetInitiator
|
||||||
HeaderTags.ResetInitiator
|
|
||||||
if self.initiator
|
|
||||||
else HeaderTags.ResetInitiator
|
|
||||||
)
|
|
||||||
await self.mplex_conn.send_message(flag, None, self.stream_id)
|
await self.mplex_conn.send_message(flag, None, self.stream_id)
|
||||||
|
|
||||||
self.local_closed = True
|
self.local_closed = True
|
||||||
|
|
|
@ -32,9 +32,7 @@ def decode_uvarint(buff: bytes, index: int) -> Tuple[int, int]:
|
||||||
return result, index + 1
|
return result, index + 1
|
||||||
|
|
||||||
|
|
||||||
async def decode_uvarint_from_stream(
|
async def decode_uvarint_from_stream(reader: asyncio.StreamReader, timeout: float) -> int:
|
||||||
reader: asyncio.StreamReader, timeout: float
|
|
||||||
) -> int:
|
|
||||||
shift = 0
|
shift = 0
|
||||||
result = 0
|
result = 0
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -30,9 +30,7 @@ class TCPListener(IListener):
|
||||||
:return: return True if successful
|
:return: return True if successful
|
||||||
"""
|
"""
|
||||||
self.server = await asyncio.start_server(
|
self.server = await asyncio.start_server(
|
||||||
self.handler,
|
self.handler, maddr.value_for_protocol("ip4"), maddr.value_for_protocol("tcp")
|
||||||
maddr.value_for_protocol("ip4"),
|
|
||||||
maddr.value_for_protocol("tcp"),
|
|
||||||
)
|
)
|
||||||
socket = self.server.sockets[0]
|
socket = self.server.sockets[0]
|
||||||
self.multiaddrs.append(_multiaddr_from_socket(socket))
|
self.multiaddrs.append(_multiaddr_from_socket(socket))
|
||||||
|
|
|
@ -3,4 +3,3 @@ from typing import NewType, Callable
|
||||||
|
|
||||||
|
|
||||||
THandler = Callable[[StreamReader, StreamWriter], None]
|
THandler = Callable[[StreamReader, StreamWriter], None]
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,7 @@ class TransportUpgrader:
|
||||||
security_multistream: SecurityMultistream
|
security_multistream: SecurityMultistream
|
||||||
muxer: Sequence[str]
|
muxer: Sequence[str]
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, secOpt: Dict[TProtocol, ISecureTransport], muxerOpt: Sequence[str]) -> None:
|
||||||
self, secOpt: Dict[TProtocol, ISecureTransport], muxerOpt: Sequence[str]
|
|
||||||
) -> None:
|
|
||||||
# Store security option
|
# Store security option
|
||||||
self.security_multistream = SecurityMultistream()
|
self.security_multistream = SecurityMultistream()
|
||||||
for key in secOpt:
|
for key in secOpt:
|
||||||
|
@ -46,9 +44,7 @@ class TransportUpgrader:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def upgrade_connection(
|
def upgrade_connection(
|
||||||
conn: IRawConnection,
|
conn: IRawConnection, generic_protocol_handler: GenericProtocolHandlerFn, peer_id: ID
|
||||||
generic_protocol_handler: GenericProtocolHandlerFn,
|
|
||||||
peer_id: ID,
|
|
||||||
) -> Mplex:
|
) -> Mplex:
|
||||||
"""
|
"""
|
||||||
Upgrade raw connection to muxed connection
|
Upgrade raw connection to muxed connection
|
||||||
|
|
|
@ -8,7 +8,9 @@ from libp2p.peer.peerdata import PeerData
|
||||||
from libp2p.peer.peerinfo import InvalidAddrError, PeerInfo, info_from_p2p_addr
|
from libp2p.peer.peerinfo import InvalidAddrError, PeerInfo, info_from_p2p_addr
|
||||||
|
|
||||||
ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||||
VALID_MULTI_ADDR_STR = "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" # noqa: E501
|
VALID_MULTI_ADDR_STR = (
|
||||||
|
"/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ"
|
||||||
|
) # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
def test_init_():
|
def test_init_():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user