mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
added: logs
This commit is contained in:
@ -15,6 +15,7 @@ from libp2p.crypto.keys import (
|
||||
from libp2p.crypto.rsa import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.crypto.x25519 import create_new_key_pair as create_new_x25519_key_pair
|
||||
from libp2p.custom_types import (
|
||||
TProtocol,
|
||||
)
|
||||
@ -22,11 +23,17 @@ from libp2p.security.insecure.transport import (
|
||||
PLAINTEXT_PROTOCOL_ID,
|
||||
InsecureTransport,
|
||||
)
|
||||
from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID
|
||||
from libp2p.security.noise.transport import Transport as NoiseTransport
|
||||
import libp2p.security.secio.transport as secio
|
||||
from libp2p.stream_muxer.mplex.mplex import (
|
||||
MPLEX_PROTOCOL_ID,
|
||||
Mplex,
|
||||
)
|
||||
from libp2p.stream_muxer.yamux.yamux import (
|
||||
Yamux,
|
||||
)
|
||||
from libp2p.stream_muxer.yamux.yamux import PROTOCOL_ID as YAMUX_PROTOCOL_ID
|
||||
|
||||
|
||||
def generate_new_rsa_identity() -> KeyPair:
|
||||
@ -39,7 +46,7 @@ async def build_host(transport: str, ip: str, port: str, sec_protocol: str, muxe
|
||||
key_pair = create_new_key_pair()
|
||||
host = new_host(
|
||||
key_pair,
|
||||
{MPLEX_PROTOCOL_ID: Mplex},
|
||||
{TProtocol(MPLEX_PROTOCOL_ID): Mplex},
|
||||
{
|
||||
TProtocol(PLAINTEXT_PROTOCOL_ID): InsecureTransport(key_pair),
|
||||
TProtocol(secio.ID): secio.Transport(key_pair),
|
||||
@ -47,6 +54,33 @@ async def build_host(transport: str, ip: str, port: str, sec_protocol: str, muxe
|
||||
)
|
||||
muladdr = multiaddr.Multiaddr(f"/ip4/{ip}/tcp/{port}")
|
||||
return (host, muladdr)
|
||||
case ("insecure", "yamux"):
|
||||
key_pair = create_new_key_pair()
|
||||
host = new_host(
|
||||
key_pair,
|
||||
{TProtocol(YAMUX_PROTOCOL_ID): Yamux},
|
||||
{
|
||||
TProtocol(PLAINTEXT_PROTOCOL_ID): InsecureTransport(key_pair),
|
||||
TProtocol(secio.ID): secio.Transport(key_pair),
|
||||
},
|
||||
)
|
||||
muladdr = multiaddr.Multiaddr(f"/ip4/{ip}/tcp/{port}")
|
||||
return (host, muladdr)
|
||||
case ("noise", "yamux"):
|
||||
key_pair = create_new_key_pair()
|
||||
noise_key_pair = create_new_x25519_key_pair()
|
||||
|
||||
host = new_host(
|
||||
key_pair,
|
||||
{TProtocol(YAMUX_PROTOCOL_ID): Yamux},
|
||||
{
|
||||
NOISE_PROTOCOL_ID: NoiseTransport(
|
||||
key_pair, noise_privkey=noise_key_pair.private_key
|
||||
)
|
||||
},
|
||||
)
|
||||
muladdr = multiaddr.Multiaddr(f"/ip4/{ip}/tcp/{port}")
|
||||
return (host, muladdr)
|
||||
case _:
|
||||
raise ValueError("Protocols not supported")
|
||||
|
||||
|
||||
@ -89,10 +89,18 @@ async def run_test(
|
||||
|
||||
handshake_start = time.perf_counter()
|
||||
|
||||
logger.info("GETTING READY FOR CONNECTION")
|
||||
await host.connect(info)
|
||||
stream = await host.new_stream(info.peer_id, [PING_PROTOCOL_ID])
|
||||
logger.info("HOST CONNECTED")
|
||||
|
||||
# TILL HERE EVERYTHING IS FINE
|
||||
|
||||
stream = await host.new_stream(info.peer_id, [PING_PROTOCOL_ID])
|
||||
logger.info("CREATED NEW STREAM")
|
||||
|
||||
# DOES NOT MORE FORWARD FROM THIS
|
||||
logger.info("Remote conection established")
|
||||
|
||||
nursery.start_soon(send_ping, stream)
|
||||
|
||||
handshake_plus_ping = (time.perf_counter() - handshake_start) * 1000.0
|
||||
|
||||
Reference in New Issue
Block a user