Skip to content

Commit 03b2d30

Browse files
authored
Merge branch 'main' into enhancement/yamuxstream-lock
2 parents e50a805 + 74f4aaf commit 03b2d30

40 files changed

+9319
-93
lines changed

.github/workflows/tox.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,48 @@ jobs:
3636
- uses: actions/setup-python@v5
3737
with:
3838
python-version: ${{ matrix.python }}
39+
40+
- name: Install Nim for interop testing
41+
if: matrix.toxenv == 'interop'
42+
run: |
43+
echo "Installing Nim for nim-libp2p interop testing..."
44+
curl -sSf https://nim-lang.org/choosenim/init.sh | sh -s -- -y --firstInstall
45+
echo "$HOME/.nimble/bin" >> $GITHUB_PATH
46+
echo "$HOME/.choosenim/toolchains/nim-stable/bin" >> $GITHUB_PATH
47+
48+
- name: Cache nimble packages
49+
if: matrix.toxenv == 'interop'
50+
uses: actions/cache@v4
51+
with:
52+
path: |
53+
~/.nimble
54+
~/.choosenim/toolchains/*/lib
55+
key: ${{ runner.os }}-nimble-${{ hashFiles('**/nim_echo_server.nim') }}
56+
restore-keys: |
57+
${{ runner.os }}-nimble-
58+
59+
- name: Build nim interop binaries
60+
if: matrix.toxenv == 'interop'
61+
run: |
62+
export PATH="$HOME/.nimble/bin:$HOME/.choosenim/toolchains/nim-stable/bin:$PATH"
63+
cd tests/interop/nim_libp2p
64+
./scripts/setup_nim_echo.sh
65+
3966
- run: |
4067
python -m pip install --upgrade pip
4168
python -m pip install tox
42-
- run: |
69+
70+
- name: Run Tests or Generate Docs
71+
run: |
72+
if [[ "${{ matrix.toxenv }}" == 'docs' ]]; then
73+
export TOXENV=docs
74+
else
75+
export TOXENV=py${{ matrix.python }}-${{ matrix.toxenv }}
76+
fi
77+
# Set PATH for nim commands during tox
78+
if [[ "${{ matrix.toxenv }}" == 'interop' ]]; then
79+
export PATH="$HOME/.nimble/bin:$HOME/.choosenim/toolchains/nim-stable/bin:$PATH"
80+
fi
4381
python -m tox run -r
4482
4583
windows:

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ ______________________________________________________________________
6161

6262
### Discovery
6363

64-
| **Discovery** | **Status** | **Source** |
65-
| -------------------- | :--------: | :--------------------------------------------------------------------------------: |
66-
| **`bootstrap`** || [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/bootstrap) |
67-
| **`random-walk`** | 🌱 | |
68-
| **`mdns-discovery`** || [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/mdns) |
69-
| **`rendezvous`** | 🌱 | |
64+
| **Discovery** | **Status** | **Source** |
65+
| -------------------- | :--------: | :----------------------------------------------------------------------------------: |
66+
| **`bootstrap`** || [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/bootstrap) |
67+
| **`random-walk`** | | [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/random_walk) |
68+
| **`mdns-discovery`** || [source](https://github.com/libp2p/py-libp2p/tree/main/libp2p/discovery/mdns) |
69+
| **`rendezvous`** | 🌱 | |
7070

7171
______________________________________________________________________
7272

docs/examples.echo_quic.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
QUIC Echo Demo
2+
==============
3+
4+
This example demonstrates a simple ``echo`` protocol using **QUIC transport**.
5+
6+
QUIC provides built-in TLS security and stream multiplexing over UDP, making it an excellent transport choice for libp2p applications.
7+
8+
.. code-block:: console
9+
10+
$ python -m pip install libp2p
11+
Collecting libp2p
12+
...
13+
Successfully installed libp2p-x.x.x
14+
$ echo-quic-demo
15+
Run this from the same folder in another console:
16+
17+
echo-quic-demo -d /ip4/127.0.0.1/udp/8000/quic-v1/p2p/16Uiu2HAmAsbxRR1HiGJRNVPQLNMeNsBCsXT3rDjoYBQzgzNpM5mJ
18+
19+
Waiting for incoming connection...
20+
21+
Copy the line that starts with ``echo-quic-demo -p 8001``, open a new terminal in the same
22+
folder and paste it in:
23+
24+
.. code-block:: console
25+
26+
$ echo-quic-demo -d /ip4/127.0.0.1/udp/8000/quic-v1/p2p/16Uiu2HAmE3N7KauPTmHddYPsbMcBp2C6XAmprELX3YcFEN9iXiBu
27+
28+
I am 16Uiu2HAmE3N7KauPTmHddYPsbMcBp2C6XAmprELX3YcFEN9iXiBu
29+
STARTING CLIENT CONNECTION PROCESS
30+
CLIENT CONNECTED TO SERVER
31+
Sent: hi, there!
32+
Got: ECHO: hi, there!
33+
34+
**Key differences from TCP Echo:**
35+
36+
- Uses UDP instead of TCP: ``/udp/8000`` instead of ``/tcp/8000``
37+
- Includes QUIC protocol identifier: ``/quic-v1`` in the multiaddr
38+
- Built-in TLS security (no separate security transport needed)
39+
- Native stream multiplexing over a single QUIC connection
40+
41+
.. literalinclude:: ../examples/echo/echo_quic.py
42+
:language: python
43+
:linenos:

docs/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Examples
99
examples.identify_push
1010
examples.chat
1111
examples.echo
12+
examples.echo_quic
1213
examples.ping
1314
examples.pubsub
1415
examples.circuit_relay

docs/getting_started.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ For Python, the most common transport is TCP. Here's how to set up a basic TCP t
2828
.. literalinclude:: ../examples/doc-examples/example_transport.py
2929
:language: python
3030

31+
Also, QUIC is a modern transport protocol that provides built-in TLS security and stream multiplexing over UDP:
32+
33+
.. literalinclude:: ../examples/doc-examples/example_quic_transport.py
34+
:language: python
35+
3136
Connection Encryption
3237
^^^^^^^^^^^^^^^^^^^^^
3338

docs/libp2p.transport.quic.rst

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
libp2p.transport.quic package
2+
=============================
3+
4+
Submodules
5+
----------
6+
7+
libp2p.transport.quic.config module
8+
-----------------------------------
9+
10+
.. automodule:: libp2p.transport.quic.config
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
15+
libp2p.transport.quic.connection module
16+
---------------------------------------
17+
18+
.. automodule:: libp2p.transport.quic.connection
19+
:members:
20+
:undoc-members:
21+
:show-inheritance:
22+
23+
libp2p.transport.quic.exceptions module
24+
---------------------------------------
25+
26+
.. automodule:: libp2p.transport.quic.exceptions
27+
:members:
28+
:undoc-members:
29+
:show-inheritance:
30+
31+
libp2p.transport.quic.listener module
32+
-------------------------------------
33+
34+
.. automodule:: libp2p.transport.quic.listener
35+
:members:
36+
:undoc-members:
37+
:show-inheritance:
38+
39+
libp2p.transport.quic.security module
40+
-------------------------------------
41+
42+
.. automodule:: libp2p.transport.quic.security
43+
:members:
44+
:undoc-members:
45+
:show-inheritance:
46+
47+
libp2p.transport.quic.stream module
48+
-----------------------------------
49+
50+
.. automodule:: libp2p.transport.quic.stream
51+
:members:
52+
:undoc-members:
53+
:show-inheritance:
54+
55+
libp2p.transport.quic.transport module
56+
--------------------------------------
57+
58+
.. automodule:: libp2p.transport.quic.transport
59+
:members:
60+
:undoc-members:
61+
:show-inheritance:
62+
63+
libp2p.transport.quic.utils module
64+
----------------------------------
65+
66+
.. automodule:: libp2p.transport.quic.utils
67+
:members:
68+
:undoc-members:
69+
:show-inheritance:
70+
71+
Module contents
72+
---------------
73+
74+
.. automodule:: libp2p.transport.quic
75+
:members:
76+
:undoc-members:
77+
:show-inheritance:

docs/libp2p.transport.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Subpackages
99

1010
libp2p.transport.tcp
1111

12+
.. toctree::
13+
:maxdepth: 4
14+
15+
libp2p.transport.quic
16+
1217
Submodules
1318
----------
1419

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import secrets
2+
3+
import multiaddr
4+
import trio
5+
6+
from libp2p import (
7+
new_host,
8+
)
9+
from libp2p.crypto.secp256k1 import (
10+
create_new_key_pair,
11+
)
12+
13+
14+
async def main():
15+
# Create a key pair for the host
16+
secret = secrets.token_bytes(32)
17+
key_pair = create_new_key_pair(secret)
18+
19+
# Create a host with the key pair
20+
host = new_host(key_pair=key_pair, enable_quic=True)
21+
22+
# Configure the listening address
23+
port = 8000
24+
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/udp/{port}/quic-v1")
25+
26+
# Start the host
27+
async with host.run(listen_addrs=[listen_addr]):
28+
print("libp2p has started with QUIC transport")
29+
print("libp2p is listening on:", host.get_addrs())
30+
# Keep the host running
31+
await trio.sleep_forever()
32+
33+
34+
# Run the async function
35+
trio.run(main)

0 commit comments

Comments
 (0)