Skip to content

Commit aa542b1

Browse files
authored
Merge pull request #1237 from Winter-Soren/enh/1231-add-gossipsub-1.3-support
enh/1231-add-gossipsub-1.3-support
2 parents 4f7aa12 + 1ebcba9 commit aa542b1

15 files changed

Lines changed: 1646 additions & 187 deletions

docs/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Examples
2424
examples.multiple_connections
2525
tls-support
2626
gossipsub-1.2
27+
gossipsub-1.3
2728
examples.websocket
2829
examples.tls
2930
examples.tcp

docs/gossipsub-1.3.rst

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
GossipSub 1.3 Extensions and Topic Observation
2+
==============================================
3+
4+
Overview
5+
--------
6+
7+
Py-libp2p supports the GossipSub v1.3 Extensions Control Message mechanism and the
8+
Topic Observation extension. These features require negotiating the
9+
``/meshsub/1.3.0`` protocol (or later) with peers.
10+
11+
Topic Observation
12+
-----------------
13+
14+
The Topic Observation extension allows a peer to receive IHAVE notifications for
15+
a topic without being a full subscriber. This is useful for presence awareness:
16+
knowing when messages are published on a topic without actually receiving the
17+
message payloads.
18+
19+
Lifecycle
20+
~~~~~~~~~
21+
22+
1. **Start observing**: Call ``start_observing_topic(topic)`` to send OBSERVE
23+
control messages to in-topic peers that support the extension. The router
24+
will then send IHAVE notifications to you when new messages arrive on that
25+
topic.
26+
27+
2. **Receive IHAVE**: As an observer, you receive IHAVE control messages
28+
containing message IDs. These are presence notifications only; observers do
29+
not typically reply with IWANT to fetch the actual messages.
30+
31+
3. **Stop observing**: Call ``stop_observing_topic(topic)`` to send UNOBSERVE
32+
control messages and stop receiving IHAVE notifications for that topic.
33+
34+
API Usage Snippet
35+
~~~~~~~~~~~~~~~~~
36+
37+
The snippet below demonstrates the Topic Observation API calls. It is not a
38+
complete runnable program (host setup, service lifecycle, and peer wiring are
39+
omitted for brevity). For a runnable end-to-end example, see
40+
:doc:`examples.pubsub`.
41+
42+
.. code-block:: python
43+
44+
from libp2p import new_host
45+
from libp2p.pubsub.gossipsub import PROTOCOL_ID_V13, GossipSub
46+
from libp2p.pubsub.pubsub import Pubsub
47+
48+
# Create host and Pubsub with a v1.3-capable GossipSub router.
49+
host = new_host()
50+
gossipsub = GossipSub(
51+
protocols=[PROTOCOL_ID_V13],
52+
degree=6,
53+
degree_low=4,
54+
degree_high=12,
55+
)
56+
pubsub = Pubsub(host, gossipsub)
57+
58+
# Start observing a topic (IHAVE-only presence notifications).
59+
# In practice, call this once Pubsub/GossipSub services are running.
60+
await gossipsub.start_observing_topic("my-topic")
61+
62+
# ... later, when done ...
63+
await gossipsub.stop_observing_topic("my-topic")
64+
65+
Protocol Requirements
66+
~~~~~~~~~~~~~~~~~~~~~
67+
68+
* Topic Observation requires both peers to negotiate ``/meshsub/1.3.0`` (or
69+
later) and to advertise support via the Extensions Control Message.
70+
* Extensions are only sent when the negotiated protocol is v1.3+; peers on
71+
v1.1/v1.2 do not receive extension fields.
72+
73+
Specification References
74+
------------------------
75+
76+
* `GossipSub v1.3 Extensions <https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.3.md>`_
77+
* `Topic Observation proposal <https://ethresear.ch/t/gossipsub-topic-observation-proposed-gossipsub-1-3/20907>`_
78+
79+
Related Documentation
80+
---------------------
81+
82+
* :doc:`gossipsub-1.2` - GossipSub 1.2 features (IDONTWANT, etc.)
83+
* :doc:`examples.pubsub` - PubSub chat example
84+
* :doc:`libp2p.pubsub` - Complete PubSub API documentation

docs/libp2p.pubsub.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ libp2p.pubsub package
33

44
Py-libp2p provides a comprehensive PubSub implementation with support for both FloodSub and GossipSub protocols, including the latest GossipSub 1.2 specification with IDONTWANT control messages for improved bandwidth efficiency.
55

6-
For detailed information about GossipSub 1.2 features and configuration, see :doc:`gossipsub-1.2`.
6+
For detailed information about GossipSub features and configuration, see
7+
:doc:`gossipsub-1.2` (IDONTWANT, etc.) and :doc:`gossipsub-1.3` (v1.3 extensions,
8+
Topic Observation).
79

810
Subpackages
911
-----------

0 commit comments

Comments
 (0)