mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Noise: add noise option in the factories and tests
This commit is contained in:
@ -6,14 +6,15 @@ import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.io.abc import ReadWriteCloser
|
||||
from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID
|
||||
from libp2p.tools.factories import HostFactory, PubsubFactory
|
||||
from libp2p.tools.interop.daemon import make_p2pd
|
||||
from libp2p.tools.interop.utils import connect
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def is_host_secure():
|
||||
return False
|
||||
def security_protocol():
|
||||
return PLAINTEXT_PROTOCOL_ID
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -38,7 +39,11 @@ def is_pubsub_signing_strict():
|
||||
|
||||
@pytest.fixture
|
||||
async def p2pds(
|
||||
num_p2pds, is_host_secure, is_gossipsub, is_pubsub_signing, is_pubsub_signing_strict
|
||||
num_p2pds,
|
||||
security_protocol,
|
||||
is_gossipsub,
|
||||
is_pubsub_signing,
|
||||
is_pubsub_signing_strict,
|
||||
):
|
||||
async with AsyncExitStack() as stack:
|
||||
p2pds = [
|
||||
@ -46,7 +51,7 @@ async def p2pds(
|
||||
make_p2pd(
|
||||
get_unused_tcp_port(),
|
||||
get_unused_tcp_port(),
|
||||
is_host_secure,
|
||||
security_protocol,
|
||||
is_gossipsub=is_gossipsub,
|
||||
is_pubsub_signing=is_pubsub_signing,
|
||||
is_pubsub_signing_strict=is_pubsub_signing_strict,
|
||||
@ -62,14 +67,16 @@ async def p2pds(
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def pubsubs(num_hosts, is_host_secure, is_gossipsub, is_pubsub_signing_strict):
|
||||
async def pubsubs(num_hosts, security_protocol, is_gossipsub, is_pubsub_signing_strict):
|
||||
if is_gossipsub:
|
||||
yield PubsubFactory.create_batch_with_gossipsub(
|
||||
num_hosts, is_secure=is_host_secure, strict_signing=is_pubsub_signing_strict
|
||||
num_hosts,
|
||||
security_protocol=security_protocol,
|
||||
strict_signing=is_pubsub_signing_strict,
|
||||
)
|
||||
else:
|
||||
yield PubsubFactory.create_batch_with_floodsub(
|
||||
num_hosts, is_host_secure, strict_signing=is_pubsub_signing_strict
|
||||
num_hosts, security_protocol, strict_signing=is_pubsub_signing_strict
|
||||
)
|
||||
|
||||
|
||||
@ -97,8 +104,10 @@ async def is_to_fail_daemon_stream():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def py_to_daemon_stream_pair(p2pds, is_host_secure, is_to_fail_daemon_stream):
|
||||
async with HostFactory.create_batch_and_listen(is_host_secure, 1) as hosts:
|
||||
async def py_to_daemon_stream_pair(p2pds, security_protocol, is_to_fail_daemon_stream):
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
1, security_protocol=security_protocol
|
||||
) as hosts:
|
||||
assert len(p2pds) >= 1
|
||||
host = hosts[0]
|
||||
p2pd = p2pds[0]
|
||||
|
||||
@ -6,8 +6,10 @@ from libp2p.tools.interop.utils import connect
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_connect(is_host_secure, p2pds):
|
||||
async with HostFactory.create_batch_and_listen(is_host_secure, 1) as hosts:
|
||||
async def test_connect(security_protocol, p2pds):
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
1, security_protocol=security_protocol
|
||||
) as hosts:
|
||||
p2pd = p2pds[0]
|
||||
host = hosts[0]
|
||||
assert len(await p2pd.control.list_peers()) == 0
|
||||
|
||||
@ -6,6 +6,7 @@ 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
|
||||
@ -20,10 +21,10 @@ class EchoProcess(BaseInteractiveProcess):
|
||||
_peer_info: PeerInfo
|
||||
|
||||
def __init__(
|
||||
self, port: int, is_secure: bool, destination: Multiaddr = None
|
||||
self, port: int, security_protocol: TProtocol, destination: Multiaddr = None
|
||||
) -> None:
|
||||
args = [f"-l={port}"]
|
||||
if not is_secure:
|
||||
if security_protocol == PLAINTEXT_PROTOCOL_ID:
|
||||
args.append("-insecure")
|
||||
if destination is not None:
|
||||
args.append(f"-d={str(destination)}")
|
||||
@ -61,9 +62,11 @@ class EchoProcess(BaseInteractiveProcess):
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_insecure_conn_py_to_go(is_host_secure):
|
||||
async with HostFactory.create_batch_and_listen(is_host_secure, 1) as hosts:
|
||||
go_proc = EchoProcess(get_unused_tcp_port(), is_host_secure)
|
||||
async def test_insecure_conn_py_to_go(security_protocol):
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
1, security_protocol=security_protocol
|
||||
) as hosts:
|
||||
go_proc = EchoProcess(get_unused_tcp_port(), security_protocol)
|
||||
await go_proc.start()
|
||||
|
||||
host = hosts[0]
|
||||
@ -78,8 +81,10 @@ async def test_insecure_conn_py_to_go(is_host_secure):
|
||||
|
||||
|
||||
@pytest.mark.trio
|
||||
async def test_insecure_conn_go_to_py(is_host_secure):
|
||||
async with HostFactory.create_batch_and_listen(is_host_secure, 1) as hosts:
|
||||
async def test_insecure_conn_go_to_py(security_protocol):
|
||||
async with HostFactory.create_batch_and_listen(
|
||||
1, security_protocol=security_protocol
|
||||
) as hosts:
|
||||
host = hosts[0]
|
||||
expected_data = "Hello, world!\n"
|
||||
reply_data = "Replyooo!\n"
|
||||
@ -94,6 +99,6 @@ async def test_insecure_conn_go_to_py(is_host_secure):
|
||||
|
||||
host.set_stream_handler(ECHO_PROTOCOL_ID, _handle_echo)
|
||||
py_maddr = host.get_addrs()[0]
|
||||
go_proc = EchoProcess(get_unused_tcp_port(), is_host_secure, py_maddr)
|
||||
go_proc = EchoProcess(get_unused_tcp_port(), security_protocol, py_maddr)
|
||||
await go_proc.start()
|
||||
await event_handler_finished.wait()
|
||||
|
||||
@ -54,7 +54,7 @@ def validate_pubsub_msg(msg: rpc_pb2.Message, data: bytes, from_peer_id: ID) ->
|
||||
@pytest.mark.parametrize("num_p2pds", (2,))
|
||||
@pytest.mark.trio
|
||||
async def test_pubsub(
|
||||
p2pds, is_gossipsub, is_host_secure, is_pubsub_signing_strict, nursery
|
||||
p2pds, is_gossipsub, security_protocol, is_pubsub_signing_strict, nursery
|
||||
):
|
||||
pubsub_factory = None
|
||||
if is_gossipsub:
|
||||
@ -63,7 +63,7 @@ async def test_pubsub(
|
||||
pubsub_factory = PubsubFactory.create_batch_with_floodsub
|
||||
|
||||
async with pubsub_factory(
|
||||
1, is_secure=is_host_secure, strict_signing=is_pubsub_signing_strict
|
||||
1, security_protocol=security_protocol, strict_signing=is_pubsub_signing_strict
|
||||
) as pubsubs:
|
||||
#
|
||||
# Test: Recognize pubsub peers on connection.
|
||||
|
||||
Reference in New Issue
Block a user