Skip to main content

Module client

Module client 

Source
Expand description

The relay client and the local event store behind it.

NostrService wraps the nostr-sdk relay pool. Every event a relay sends is checked (signature and id) by the SDK and kept in an LMDB store, so what was seen once is there at once on the next start, before any relay answers.

Each relay is asked for itself, and which of them sent a note is kept (see Sightings): the pool, asked as one, gives each event once and says no more than who was first.

There are two pools. One holds the account’s own relays: those the config names, and those the account’s relay list (NIP-65) says it writes to. They are asked about everything, and are where what the account writes goes. The other holds other people’s relays, the ones their relay lists name: asked about those people alone, for what the account’s own relays may not have, and sent what is meant for them (see crate::nostr::outbox). They come and go: so many at a time, each let go of when it has not been used for a while.

flowchart TB
    subgraph service["NostrService"]
        home["The home pool: the account's own relays"]
        others["The pool of other people's relays"]
        private["The relay it runs itself"]
        store[("One event store")]
    end
    asked["A question"] -->|"about anyone"| home
    asked -->|"about the people who list a relay"| others
    written["What the account writes"] --> home
    written -->|"if it names someone"| others
    draft["A draft"] --> private
    home --> store
    others --> store
    private --> store
    store -->|"what is shown is read from here"| shown["The model"]

§Finding one’s way in this file

It is long, and in this order:

PartWhat is there
The constantsEvery timeout and limit, each with its reason
The typesReach, Source, RelayUse, and the errors: FetchError, PublishError, FollowError, ListError
Opening, and asking a relayNostrService::open, and the private ask, fetch, gather
Other people’s relaysThe private relays_of, reach_for, connect_to, ask_their_relays
The account’s own relaysNostrService::use_relays_of, and the config’s standing down
EventsNostrService::event, NostrService::publish, NostrService::standing
NotesNostrService::thread, NostrService::cached_feed, NostrService::fetch_feed
ListsNostrService::set_following, NostrService::set_bookmarked, and the private list_to_change they both stand on
DraftsNostrService::keep_draft, NostrService::kept_drafts
SearchingNostrService::search
The account’s relay listsNostrService::relay_lists, NostrService::set_advertised_relays, NostrService::set_listed_relays
ProfilesNostrService::cached_profiles, NostrService::fetch_profiles
The testsAgainst relays started in the test: see crate::guide::testing

The decisions all of this carries out (which relay is asked what, whose word is taken for a relay, where what is written goes) are told in one place, with their diagrams: crate::guide::relays.

Structs§

Asked 🔒
What a relay sent when it was asked.
NostrService
The Nostr client: a relay pool over a local event store. Cheap to clone; clones share the pool and the store.
Notified
One page of what an account is told of.
Own 🔒
The account’s own relays: those the config names, those its relay list names, and which of them are in use.
Reach
How far other people’s relays are reached for.
Reached 🔒
What is remembered of reaching for other people’s relays.
RelayUse
How a relay this is connected to has been doing, since the applet started: what the relays page says under its name.

Enums§

FetchError
Why a request to the relays brought nothing back.
FollowError
Why an account’s contact list was not changed.
ListError
Why a list an account keeps part of to itself (its bookmarks, its search relays) or its relay list was not read, or not changed.
Pool 🔒
Which pool a relay is in.
PublishError
Why an event did not go out.
Source
Where events are looked for.

Constants§

ABOUT_WAIT 🔒
How long the relays are given to send the notes notifications are about, which only say what was answered or reacted to.
ACCOUNT_RELAYS_MAX 🔒
How many of the relays an account’s own relay list says it writes to are joined to the ones the config names.
AUTHORS_PER_FILTER 🔒
How many authors one filter names. Relays refuse filters past some size, each its own; a long follow list is asked about in filters of this many.
CONNECT_GRACE 🔒
How long after startup a request still waits for relays that are in the middle of connecting, so the first page comes from all of them rather than from whichever answered first. After this, a relay that is still trying is left out of a request instead of holding it up.
CONNECT_POLL 🔒
How often the relays’ connection states are looked at while waiting.
CONNECT_WAIT 🔒
How long a request waits for a first relay to connect before giving up.
DELIVERED_KINDS 🔒
The kinds of event that are sent to the people they name, as well as to the account’s own relays: what is said to someone, or done to what they wrote. Not a contact list, say, which names everyone followed.
ENGAGEMENT_LIMIT 🔒
ENGAGEMENT_NOTES_PER_REQUEST 🔒
How many notes one request asks about at a time, when asking what was made of them, and how many events of a kind it asks for: a note that went everywhere has more reactions than are worth carrying.
ENGAGEMENT_STORE_LIMIT 🔒
How many events of a kind the store is read for, for as many notes. More than a request brings, since the store keeps what earlier requests brought.
FEED_KINDS 🔒
The kinds of event a list of notes is made of: text notes, and comments (NIP-22), which are replies to what is not a text note.
FEED_PAGE
How many notes one page of a feed asks for.
FETCH_TIMEOUT 🔒
How long relays get to answer a request. Every query has one, so nothing loads forever on a relay that stopped answering.
HOLDER_WAIT 🔒
How long the relays get to say which of them has an event that is about to be pointed at. Short: what points at it goes out without, rather than late.
IDS_PER_FILTER 🔒
How many notes one filter asks for by id.
PUBLISH_TIMEOUT 🔒
How long each relay gets to say whether it took an event.
QUOTES_WAIT 🔒
How long the relays get to send the notes that the notes of a page quote, and again for those that these quote in turn. The page waits for them, so that a note is shown with what it quotes or without, and not first one way and then the other.
REACH_AVOID 🔒
How long a relay that did not connect, said no to what it was asked, or did not answer in time is left alone, and the others asked without it; and how near the time it had counts as running out of it.
REACH_BUSY 🔒
REACH_CAP 🔒
How many of other people’s relays one question reaches for, and how many are kept in their pool once those in use are done with, unless said otherwise.
REACH_CONNECT_WAIT 🔒
How long one of other people’s relays gets to connect, and to answer. Shorter than the account’s own get: they are asked for what may well be had already, and a list of notes waits for the slowest of them.
REACH_KEEP 🔒
REACH_SLEEP 🔒
How long one of other people’s relays stays connected with nothing asked of it, how long it stays in the pool unused, and how lately it must have been used not to be let go of to make room for another.
REACH_TIMEOUT 🔒
RECEIPT_LIMIT 🔒
How many of a note’s newest receipts are looked at when the listening starts: enough to find one that arrived just before.
RECEIPT_RETRY 🔒
How long to wait before listening again, when the relays stopped answering in the middle of waiting for a receipt.
RECEIPT_WAIT 🔒
How long the receipt of a zap is waited for after its invoice is shown: about as long as such an invoice can be paid.
RELAYS_PER_PERSON 🔒
How many relays each person is read from, the account’s own among them, when their relay list names as many; and how many of the relays each person reads are sent what is meant for them.
RELAY_LISTS_FRESH 🔒
How long someone’s relay list is taken as known before the relays are asked for it again.
SEARCH_TIMEOUT 🔒
How long a relay that searches gets to answer.
THREAD_ANCESTORS 🔒
How many notes up from the one a thread was opened for are looked for one by one, when nothing else brought them.
THREAD_ASK_AGAIN_UNDER 🔒
A conversation with fewer notes than this naming its root is asked about again, for the notes that name only the note they answer. A larger one has enough to show without the second request.
THREAD_LIMIT 🔒
How many notes of a conversation one request asks for. A thread that went everywhere has thousands; this many are read, and held, at most.
THREAD_PEOPLE 🔒
How many of the people a note names are taken for part of its conversation, when their relays are asked about it.
TIMEOUT_SLACK 🔒

Functions§

default_store_path
Where the event store lives: the user’s data directory, not the cache. It is what the embedded relay will serve, so it is not disposable.
engagement_filters 🔒
The filters that ask what was made of notes: the replies (notes and comments), reposts, reactions and zap receipts that name them, limit of each at most, and the reactions and reposts of account, which must not be among those left out.
feed_filters 🔒
filters_by_id 🔒
The filters that ask for one page of the notes of authors: text notes and comments, the limit newest written at or before until. One filter for every AUTHORS_PER_FILTER authors, and none for nobody.
newest 🔒
The newest of events, which are the versions of something only the last of which counts: a contact list, a bookmark list. None if there is none.
newest_profiles 🔒
Each author’s newest profile among events.