docs: add some documentation for QUIC transport

This commit is contained in:
Akash Mondal
2025-09-05 05:41:06 +00:00
parent 09c9709a3e
commit f3976b7d2f
7 changed files with 93 additions and 2 deletions

View File

@ -0,0 +1,35 @@
import secrets
import multiaddr
import trio
from libp2p import (
new_host,
)
from libp2p.crypto.secp256k1 import (
create_new_key_pair,
)
async def main():
# Create a key pair for the host
secret = secrets.token_bytes(32)
key_pair = create_new_key_pair(secret)
# Create a host with the key pair
host = new_host(key_pair=key_pair, enable_quic=True)
# Configure the listening address
port = 8000
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/udp/{port}/quic-v1")
# Start the host
async with host.run(listen_addrs=[listen_addr]):
print("libp2p has started with QUIC transport")
print("libp2p is listening on:", host.get_addrs())
# Keep the host running
await trio.sleep_forever()
# Run the async function
trio.run(main)

View File

@ -142,9 +142,9 @@ def main() -> None:
QUIC provides built-in TLS security and stream multiplexing over UDP.
To use it, first run 'python ./echo_quic_fixed.py -p <PORT>', where <PORT> is
To use it, first run 'echo-quic-demo -p <PORT>', where <PORT> is
the UDP port number. Then, run another host with ,
'python ./echo_quic_fixed.py -d <DESTINATION>'
'echo-quic-demo -d <DESTINATION>'
where <DESTINATION> is the QUIC multiaddress of the previous listener host.
"""