Documentation
¶
Overview ¶
Package feed is the host side of a party's reader feed (plan-delivery § Identifiers, Feed socket and Feed frames): one source socket per serving host on GET /feed/<party id>, over which the host's sent and received timeline records reach the party's reader pages live, and a viewer's connect asks the host to replay what it holds.
The Object stores nothing: a record a viewer missed is gone unless a host replays it. So the client keeps every record it sent until the Object acks it, sends the unacked ones again after a reconnect, and answers a replay request from the caller's own records.
Index ¶
- Constants
- Variables
- func At(t time.Time) string
- func CardHeaderValue(s *card.Signed) string
- func Hash(secret string) string
- func NewSecret() (string, error)
- func PutConfig(ctx context.Context, client *http.Client, url, party string, c *Config, ...) error
- type Client
- type Config
- type Delegation
- type Options
- type Refusal
- type Replay
Constants ¶
const ( // ConfigVersion is Config.V. ConfigVersion = 1 // CardHeader carries the root-signed public card, SignatureHeader the // identity key's signature; AtHeader is what a GET's signature covers. CardHeader = "X-Peer-Card" SignatureHeader = "X-Peer-Signature" AtHeader = "X-Peer-At" // AtFormat is a config's at and an X-Peer-At value: RFC 3339 UTC with // milliseconds, so two writes of one party a moment apart still order. AtFormat = "2006-01-02T15:04:05.000Z" )
const ( // PingEvery is the keepalive, as the relay's: Cloudflare drops a socket // silent for about 100 s, and the Object answers each ping with a pong. PingEvery = 30 * time.Second )
Variables ¶
var ( // ErrStale is the Object's 409 on a PUT: it holds a config as new or // newer — another machine of the party wrote one; reload the record and // PUT again. ErrStale = errors.New("feed config: the worker holds a newer config") // ErrNoConfig is the Object's 404 on a GET: no config is set up. ErrNoConfig = errors.New("feed config: the worker holds no config for this party") )
Errors a caller can match.
var ErrRefused = errors.New("feed: the source secret is not this feed's")
ErrRefused is the Object's word that the source secret is not this feed's: the client stops; a serve dials again with the feed record's secret at its next round.
Functions ¶
func CardHeaderValue ¶
CardHeaderValue is a signed card as X-Peer-Card carries it: base64url, no padding, of the root's signature then the card bytes — the envelope #0 form.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one host's source socket on a party's feed. Dial starts it; Send queues a record; Flush waits for the acks; Close ends it.
func Dial ¶
Dial starts a client on the feed of party at url (the worker base, e.g. https://peer.0xtau.com), saying hello as host with the source secret. It returns at once; the socket is opened, and reopened after every close with backoff, until ctx ends, Close is called or the Object refuses the secret.
func (*Client) Close ¶
Close ends the client: the socket closes and nothing more is sent. The records not yet acked are dropped; the feed stores nothing, and the caller's own records serve the replay.
func (*Client) Flush ¶
Flush waits until every sent record is acked. It returns ctx's error when ctx ends first, ErrRefused when the Object refused the secret, and an error when the client itself ended — Close, or the context Dial was given.
func (*Client) Refused ¶
Refused reports whether the Object refused the secret: the client has stopped, and a new one takes the feed record's current secret.
func (*Client) Send ¶
func (c *Client) Send(rec json.RawMessage, n int64)
Send queues record rec under number n, which the Object acks back. It never blocks on the socket: a record sent while the socket is down goes out when it is up again, and one the Object has not acked is sent again after a reconnect. n is the caller's; the Object acks what it was given.
type Config ¶
type Config struct {
V int `json:"v"`
Party string `json:"party"`
At string `json:"at"`
Source string `json:"source"`
Readers []string `json:"readers"`
}
Config is the body of PUT /feed/<party id>/config and the answer to GET.
type Delegation ¶
type Delegation struct {
// contains filtered or unexported fields
}
Delegation is one machine's hand on the party's feed config: the root-signed public card, as X-Peer-Card carries it, and the identity key that signs under it.
func NewDelegation ¶
func NewDelegation(public *card.Signed, id *keys.Identity) *Delegation
NewDelegation is id's delegation under the party's public card.
func (*Delegation) Sign ¶
func (d *Delegation) Sign(msg []byte) string
Sign is the identity key's XEdDSA signature over msg (ecc.CalculateSignature, as a room card's) as X-Peer-Signature carries it: base64url, no padding.
type Options ¶
type Options struct {
// Replay answers a viewer's connect: it hands send every record the host
// holds for the viewer, in order, and returns the party's current reader
// keys, which the client sends as replay_done. Nil replays nothing and
// ends the replay at once.
Replay func(ctx context.Context, r Replay, send func(rec json.RawMessage) error) (readers []string, err error)
// Key takes a viewer's reader key and the hash of its token, when the
// viewer's hello carried a key.
Key func(key, reader string)
// HTTPClient makes the socket's upgrade; nil is http.DefaultClient.
HTTPClient *http.Client
// Log takes the client's lines; nil discards them.
Log io.Writer
}
Options are a client's callbacks and environment; every field may be zero.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package feedtest is an in-process PeerFeed Object (peer worker src/feed.ts) for the host side's tests: the hello check against a source secret and reader tokens, the fan-out of a source's records to every viewer with its ack, the replay request a viewer's connect sends every source with its key, the frames addressed to one viewer, and the signed config at /feed/<party id>/config — verified as the worker verifies it, the card under the party id and the body under the card's current identity key.
|
Package feedtest is an in-process PeerFeed Object (peer worker src/feed.ts) for the host side's tests: the hello check against a source secret and reader tokens, the fan-out of a source's records to every viewer with its ack, the replay request a viewer's connect sends every source with its key, the frames addressed to one viewer, and the signed config at /feed/<party id>/config — verified as the worker verifies it, the card under the party id and the body under the card's current identity key. |