feed

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: GPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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"
)
View Source
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

View Source
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.

View Source
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 At

func At(t time.Time) string

At formats t as a config's at.

func CardHeaderValue

func CardHeaderValue(s *card.Signed) string

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.

func Hash

func Hash(secret string) string

Hash is a secret or token as the Object stores it.

func NewSecret

func NewSecret() (string, error)

NewSecret mints a source secret or a reader token.

func PutConfig

func PutConfig(ctx context.Context, client *http.Client, url, party string, c *Config, d *Delegation) error

PutConfig writes c as the party's config on the feed at url (the worker base) under d. Readers nil is sent as an empty list.

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

func Dial(ctx context.Context, url, party, secret, host string, opt Options) *Client

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

func (c *Client) Close() error

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

func (c *Client) Flush(ctx context.Context) error

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) Pending

func (c *Client) Pending() int

Pending is how many sent records the Object has not acked.

func (*Client) Refused

func (c *Client) Refused() bool

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.

func GetConfig

func GetConfig(ctx context.Context, client *http.Client, url, party string, at time.Time, d *Delegation) (*Config, error)

GetConfig reads the config the Object holds, the request signed over at.

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) Card

func (d *Delegation) Card() string

Card is the X-Peer-Card value.

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.

type Refusal

type Refusal struct {
	Status  int
	Code    string
	Message string
}

Refusal is the Object's word on a request it did not take.

func (*Refusal) Error

func (r *Refusal) Error() string

type Replay

type Replay struct {
	Viewer string `json:"viewer"`
	Reader string `json:"reader"`
	Key    string `json:"key,omitempty"`
}

Replay is the Object's word that a viewer connected: who to replay to, the hash of its reader token, and the reader key its page holds, when any.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL