Skip to content

Commit b44ee6b

Browse files
committed
IPNS-over-PubSub as an independent transport initial spec
1 parent 0c3f803 commit b44ee6b

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

naming/pubsub.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# ![](https://img.shields.io/badge/status-wip-orange.svg?style=flat-square) IPNS PubSub Router
2+
3+
Authors:
4+
5+
- Adin Schmahmann ([@aschmahmann](https://github.com/aschmahmann))
6+
7+
Reviewers:
8+
9+
-----
10+
11+
# Abstract
12+
13+
[Inter-Planetary Naming System (IPNS)](/README.md) is a naming system responsible for the creating, reading and updating of mutable pointers to data.
14+
IPNS consists of a pubic/private asymmetric cryptographic key pair, a record type and a protocol.
15+
Part of the protocol involves a routing layer that is used for the distribution and discovery of new or updated IPNS records.
16+
17+
The IPNS PubSub router uses as a base [libp2p PubSub](https://github.com/libp2p/specs/tree/master/pubsub), but layers on it persistence so as to ensure IPNS updates are always available to a connected network.
18+
An inherent property of the IPNS PubSub Router is that IPNS records are republishable by peers other than the peer that originated the record.
19+
This implies that as long as a peer on the network has an IPNS record it can be made available to other peers (although the records may be ignored if they are received after the IPNS record's End-of-Life/EOL).
20+
21+
# Organization of this document
22+
23+
- [Introduction](#introduction)
24+
- [Protocol](#protocol)
25+
- [Overview](#overview)
26+
- [API Spec](#api-spec)
27+
- [Integration with IPFS](#integration-with-ipfs)
28+
29+
# Introduction
30+
31+
Each time a node publishes an updated IPNS record for a particular key it is propagated by the router into the network where network nodes can choose to accept or reject the new record.
32+
When a node attempts to retrieve an IPNS record from the network it uses the router to query for the IPNS record(s) associated with the IPNS key; the node then validates the received records.
33+
34+
In this spec we address building a router based on a PubSub system, particularly focusing on libp2p PubSub.
35+
36+
# PubSub Protocol Overview
37+
38+
The protocol has four components:
39+
- [IPNS Records and Validation](/README.md)
40+
- [libp2p PubSub](https://github.com/libp2p/specs/tree/master/pubsub)
41+
- Translating an IPNS record name to/from a PubSub topic
42+
- Layering persistence onto libp2p PubSub
43+
44+
# Translating an IPNS record name to/from a PubSub topic
45+
46+
For a given IPNS local record key described in the IPNS Specification the PubSub topic is:
47+
48+
**Topic format:** `/record/base64url-unpadded(key)`
49+
50+
where base64url-unpadded is an unpadded base64url as specified in [IETF RFC 4648](https://tools.ietf.org/html/rfc4648)
51+
52+
# Layering persistence onto libp2p PubSub
53+
54+
libp2p PubSub does not have any notion of persistent data built into it. However, we can layer persistence on top of PubSub by utilizing [libp2p Fetch](https://github.com/libp2p/specs/).
55+
56+
The protocol has the following steps:
57+
1. Start State: Node `A` subscribes to the PubSub topic `t` corresponding to the local IPNS record key `k`
58+
2. `A` notices that a node `B` has connected to it and subscribed to `t`
59+
3. Some time passes (might be 0 seconds, or could use a more complex system to determine the duration)
60+
4. `A` sends `B` a Fetch request for `k`
61+
5. If Fetch returns a record that supersedes `A`'s current record then `A` updates its record and Publishes it to the network
62+
63+
Note: PubSub does not guarantee that the a message sent by a peer `A` will be received by a peer `B` and it's possible
64+
(e.g. in systems like [gossipsub](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub))
65+
that this is true even if `A` and `B` are already connected. Therefore, whenever `A` notices **any** node that has
66+
connected to it and subscribed to `t` it should run the Fetch protocol as described above. However, developers may have routers
67+
with properties that allow the amount of time in step 3 to increase arbitrarily large (including infinite) amounts.
68+
69+
# Protocol
70+
71+
A node `A` putting and getting updates to an IPNS key `k`, with computed PubSub topic `t`
72+
73+
1. PubSub subscribe to `t`
74+
2. Run the persistence protocol, both to fetch data and return data to those that request it
75+
3. When updating a record do a PubSub Publish and keep the record locally
76+
4. When receiving a record if it's better than the current record keep it and republish the message
77+
5. (Optional) Periodically republish the best record available
78+
79+
Note: 5 is optional because it is not necessary. However, receiving duplicate records are already handled efficiently
80+
by the above logic and properly running the persistence protocol can be difficult (as in the example below). Periodic
81+
republishing can then act as a fall-back plan in the event of errors in the persistence protocol.
82+
83+
Persistence Error Example:
84+
1. `B` connects to `A`
85+
2. `A` gets the latest record (`R1`) from `B`
86+
3. `B` then disconnects from `A`
87+
4. `B` publishes `R2`
88+
5. `B` reconnects to `A`
89+
90+
If `A`'s checking of when `B` reconnects has problems it could miss `R2` (e.g. if it polled subscribed peers
91+
every 10 seconds)
92+
93+
# Implementations
94+
95+
- <https://github.com/ipfs/go-ipfs/tree/master/namesys>

0 commit comments

Comments
 (0)