upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--66.md250
1 files changed, 250 insertions, 0 deletions
diff --git a/66.md b/66.md
new file mode 100644
index 0000000..b242e85
--- /dev/null
+++ b/66.md
@@ -0,0 +1,250 @@
1# NIP-66: Relay Discovery and Liveness Monitoring
2
3`draft` `optional`
4
5You want to find relays. You may want to discover relays based on criteria that's up to date. You may even want to ensure that you have a complete dataset. You probably want to filter relays based on their reported liveness.
6
7In its purest form:
8
9```json
10{
11 "kind": 30166,
12 "created_at": 1722173222,
13 "content": "{}",
14 "tags": [
15 [ "d", "wss://somerelay.abc/" ]
16 ],
17 "pubkey": "<pubkey>",
18 "sig": "<signature>",
19 "id": "<eventid>"
20}
21```
22
23This event signals that the relay at `wss://somerelay.abc/` was reported "online" by `<pubkey>` at timestamp `1722173222`. This event **MAY** be extended upon to include more information.
24
25## Kinds
26`NIP-66` defines two (2) event kinds, `30166` and `10166`
27
28| kind | name | description |
29|-------|----------------------------|-----------------------------------------------------------------------------------------|
30| [30166](#k30166) | Relay Discovery | A PRE that is published by a monitor when a relay is online |
31| [10166](#k10166) | Relay Monitor Announcement | An RE that stores data that signals the intent of a pubkey to monitor relays and publish `30166` events at a regular _frequency_ |
32
33## Ontology
34- `Relay Operator`: someone who operates a relay
35- `Monitor`: A pubkey that monitors relays and publishes `30166` events at the frequency specified in their `10166` event.
36- `Ad-hoc Monitor`: A pubkey that monitors relays and publishes `30166` events at an irregular frequency.
37- `Monitor Service`: A group or individual that monitors relays using one or more `Monitors`.
38- `Check`: a specific data point that is tested or aggregated by a monitor.
39
40## `30166`: "Relay Discovery" <a id="k30166"></a>
41
42### Summary
43`30166` is a `NIP-33` Parameterized-Replaceable Event [PRE], referred to as a "Relay Discovery" event. These events are optimized with a small footprint for protocol-level relay Discovery.
44
45### Purpose
46Discovery of relays over nostr.
47
48### Schema
49
50#### Content
51`30166` content fields **SHOULD** include the stringified JSON of the relay's NIP-11 informational document. This data **MAY** be provided for informational purposes only.
52
53#### `created_at`
54The `created_at` field in a NIP-66 event should reflect the time when the relay liveness (and potentially other data points) was checked.
55
56#### `tags`
57
58##### Meta Tags (unindexed)
59- `rtt-open` The relay's open **round-trip time** in milliseconds.
60- `rtt-read` The relay's read **round-trip time** in milliseconds.
61- `rtt-write` The relay's write **round-trip time** in milliseconds.
62
63_Other `rtt` values **MAY** be present. This NIP should be updated if there is value found in more `rtt` values._
64
65##### Single Letter Tags (indexed)
66- `d` The relay URL/URI. The `#d` tag **must** be included in the `event.tags[]` array. Index position `1` **must** be the relay websocket URL/URI. If a URL it **SHOULD** be [normalized](https://datatracker.ietf.org/doc/html/rfc3986#section-6). For relays not accessible via conventional means but rather by an npub/pubkey, an npub/pubkey **MAY** be used in place of a URL.
67 ```json
68 [ "d", "wss://somerelay.abc/"]
69 ```
70
71- `n`: Network
72 ```json
73 [ "n", "clearnet" ]
74 ```
75
76- `T`: Relay Type. Enumerated [relay type](https://github.com/nostr-protocol/nips/issues/1282) formatted as `PascalCase`
77 ```json
78 ["T", "PrivateInbox" ]
79 ```
80
81- `N`: Supported Nips _From NIP-11 "Informational Document" `nip11.supported_nips[]`_
82 ```json
83 [ "N", "42" ]
84 ```
85
86- `R`: Requirements _NIP-11 "Informational Document" `nip11.limitations.payment_required`, `nip11.limitations.auth_required` and/or any other boolean value within `nip11.limitations[]` that is added in the future_
87 ```json
88 [ "R", "payment" ],
89 [ "R", "auth" ],
90 ```
91 Since the nostr protocol does not currently support filtering on whether an indexed tag **is** or **is not** set, to make "public" and "no auth" relays discoverable requires a `!` flag
92
93 ```json
94 [ "R", "!payment" ], //no payment required, is public
95 [ "R", "!auth" ], //no authentication required
96 ```
97
98- `t`: "Topics" _From NIP-11 "Informational Document" `nip11.tags[]`_
99 ```json
100 [ "t", "nsfw" ]
101 ```
102
103- `k`: Accepted/Blocked Kinds [`NIP-22`]
104 ```json
105 [ "k", "0" ],
106 [ "k", "3" ],
107 [ "k", "10002" ]
108 ```
109
110 or for blocked kinds
111
112 ```json
113 [ "k", "!0" ]
114 [ "k", "!3" ],
115 [ "k", "!10002" ]
116 ```
117
118- `g`: `NIP-52` `g` tags (geohash)
119 ```json
120 [ "g", "9r1652whz" ]
121 ```
122
123- `30166` **MAY** be extended with global tags defined by other NIPs that do no collide with locally defined indices, including but not limited to: `p`, `t`, `e`, `a`, `i` and `l/L`.
124
125#### Robust Example of a `30166` Event
126_Relay was online, and you can filter on a number of different tags_
127```json
128{
129 "id": "<eventid>",
130 "pubkey": "<monitor's pubkey>",
131 "created_at": "<created_at [some recent date ...]>",
132 "signature": "<signature>",
133 "content": "{}",
134 "kind": 30166,
135 "tags": [
136 ["d","wss://some.relay/"],
137 ["n", "clearnet"],
138 ["N", "40"],
139 ["N", "33"],
140 ["R", "!payment"],
141 ["R", "auth"],
142 ["g", "ww8p1r4t8"],
143 ["p", "somehexkey..."],
144 ["l", "en", "ISO-639-1"],
145 ["t", "nsfw" ],
146 ["rtt-open", 234 ]
147 ]
148}
149```
150
151## `10166`: "Relay Monitor Announcement" Events <a id="k10166"></a>
152
153### Summary
154`10166` is a replacable event herein referred to as "Relay Monitor Announcement" events. These events contain information about a publisher's intent to monitor and publish data as `30166` events. This event is optional and is intended for monitors who intend to provide monitoring services at a regular and predictable frequency.
155
156### Purpose
157To provide a directory of monitors, their intent to publish, their criteria and parameters of monitoring activities. Absence of this event implies the monitor is ad-hoc and does not publish events at a predictable frequency, and relies on mechanisms to infer data integrity, such as web-of-trust.
158
159### Schema
160
161#### Standard Tags
162
163- `frequency` The frequency **in seconds** at which the monitor publishes events. A string-integer at index `1` represents the expected frequency the monitor will publish `30166` events. There should only be `1` frequency per monitor.
164
165 ```json
166 [ "frequency", "3600" ]
167 ```
168
169- `timeout` (optional) The timeout values for various checks conducted by a monitor. Index `1` is the monitor's timeout in milliseconds. Index `2` describes what test the timeout is used for. If no index `2` is provided, it is inferred that the timeout provided applies to all tests. These values can assist relay operators in understanding data signaled by the monitor in _Relay Discovery Events_.
170 ```json
171 [ "timeout", "2000", "open" ],
172 [ "timeout", "2000", "read" ],
173 [ "timeout", "3000", "write" ],
174 [ "timeout", "2000", "nip11" ],
175 [ "timeout", "4000", "ssl" ]
176 ```
177
178#### Indexed Tags
179- `c` "Checks" **SHOULD** be a lowercase string describing the check(s) conducted by a monitor. Due to the rapidly evolving nature of relays, enumeration is organic and not strictly defined. But examples of some checks could be websocket `open/read/write/auth`, `nip11` checks, `dns` and `geo` checks, and and any other checks the monitor may deem useful.. Other checks **MAY** be included. New types of checks **SHOULD** be added to this NIP as they are needed.
180 ```json
181 [ "c", "ws" ],
182 [ "c", "nip11" ],
183 [ "c", "dns" ],
184 [ "c", "geo" ],
185 [ "c", "ssl" ],
186 ```
187
188- `g`: `NIP-52` `g` tags (geohash)
189 ```json
190 [ "g", "9r1652whz" ]
191 ```
192
193- Any other globally defined indexable tags **MAY** be included as found necessary.
194
195### Other Requirements
196Monitors **SHOULD** have the following
197- A published `0` (NIP-1) event
198- A published `10002` (NIP-65) event that defines the relays the monitor publishes to.
199
200### Robust Example of a `10166` Event
201```json
202{
203 "id": "<eventid>",
204 "pubkey": "<monitor's pubkey>",
205 "created_at": "<created_at [some recent date ...]>",
206 "signature": "<signature>",
207 "content": "",
208 "tags": [
209
210 [ "timeout", "open", "5000" ],
211 [ "timeout", "read", "3000" ],
212 [ "timeout", "write", "3000" ],
213 [ "timeout", "nip11", "3000" ],
214
215 [ "frequency", "3600" ],
216
217 [ "c", "ws" ],
218 [ "c", "nip11" ],
219 [ "c", "ssl" ],
220 [ "c", "dns" ],
221 [ "c", "geo" ]
222
223 [ "g", "ww8p1r4t8" ]
224 ]
225}
226```
227
228## Methodology
229
230### Monitors
2311. A _Relay Monitor_ checks the liveness and potentially other attributes of a relay.
232
2332. _Relay Monitor_ publishes a kind `30166` note when a relay it is monitoring is online. If the monitor has a `10166` event, events should be published at the frequency defined in their `10166` note.
234
235_Any pubkey that publishes `30166` events **SHOULD** at a minimum be checking that the relay is available by websocket and behaves like a relay_
236
237### Clients
2381. In most cases, a client **SHOULD** filter on `30166` events using either a statically or dynamically defined monitor's `pubkey` and a `created_at` value respective of the monitor's published `frequency`. If the monitor has no stated frequency, other mechanisms should be employed to determine data integrity.
239
2402. _Relay Liveness_ is subjectively determined by the client, starting with the `frequency` value of a monitor.
241
2423. The liveness of a _Relay Monitor_ can be subjectively determined by detecting whether the _Relay Monitor_ has published events with respect to `frequency` value of any particular monitor.
243
2444. The reliability and trustworthiness of a _Relay Monitor_ could be established via web-of-trust, reviews or similar mechanisms.
245
246## Risk Mitigation
247
248- When a client implements `NIP-66` events, the client should have a fallback if `NIP-66` events cannot be located.
249
250- A `Monitor` or `Ad-hoc Monitor` may publish erroneous `30166` events, intentionally or otherwise. Therefor, it's important to program defensively to limit the impact of such events. This can be achieved with web-of-trust, reviews, fallbacks and/or data-aggregation for example.