status

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: GPL-3.0 Imports: 15 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 status is what a party knows about each peer beyond the session itself, and the roster page that shows it (design §8 花名册页).

The activity record, key "act.<channel>" in the party's store beside the channel's "ss." record, holds the channel's last message from the peer and the unread count: serve notes every message it births, peer send notes every message it commits. It is advisory — a failed note is logged by the caller and never costs a message — and shared by every host of the party like the rest of the store, so any host's serve or status reads the same numbers.

Unread counts the peer's messages born on this party since the party last sent anything on the channel; an ack from the peer is not counted. The store knows no reader, so "read" is "answered": sending on the channel — a reply, an ack, anything — clears it.

Index

Constants

View Source
const ActiveWindow = 30 * 24 * time.Hour

ActiveWindow is how long a peer counts as active after its last message: the relay's retention, past which what it sent is gone unread anyway.

View Source
const RowSchema = "peer-roster@1"

RowSchema is the K7 schema id of a roster page record.

View Source
const StaleBeats = 3

StaleBeats is the heartbeat rule: a row not written for more than this many beats reads stale — the serve that kept it is gone.

View Source
const Timeout = 30 * time.Second

Timeout bounds one request when NewPage is given no client.

Variables

This section is empty.

Functions

func ActivityKey

func ActivityKey(channel string) string

ActivityKey is a channel's activity record key.

func NoteIn

func NoteIn(ctx context.Context, b store.Backend, channel string, seq int64, at time.Time, kind string) error

NoteIn records a message from the peer born under relay seq: the newest by seq is the last message, and every one but an ack is unread.

func NoteOut

func NoteOut(ctx context.Context, b store.Backend, channel string, at time.Time) error

NoteOut records a message this party committed on the channel: what came before it is answered.

func RowKey

func RowKey(root ed25519.PublicKey) string

RowKey is a peer's roster page key: "peer." and the root public key in lowercase hex. The party id itself ("ed25519:" + base64url) carries a colon and capitals, which a /d/ key cannot.

Types

type Activity

type Activity struct {
	V int `json:"v"`
	// LastAt and LastKind are the peer's newest message born here: its own
	// at stamp and kind; LastSeq the relay seq it came under. Zero before
	// the first.
	LastAt   time.Time `json:"lastAt"`
	LastKind string    `json:"lastKind"`
	LastSeq  int64     `json:"lastSeq"`
	// Unread is the peer's messages born since SentAt, acks not counted.
	Unread int `json:"unread"`
	// SentAt is the at stamp of this party's newest message committed on
	// the channel; zero before the first.
	SentAt time.Time `json:"sentAt"`
}

Activity is one channel's activity record.

func LoadActivity

func LoadActivity(ctx context.Context, b store.Backend, channel string) (*Activity, int64, error)

LoadActivity reads a channel's activity record; absent, it is the zero record at version 0.

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

Error is a /d/ refusal: the status and the body's code and message.

func (*Error) Error

func (e *Error) Error() string

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page is the roster page's /d/ store: plaintext rows under RowSchema, CAS by ?v= with the owner Bearer. It remembers the version it last read or wrote per key — the first write of a key reads it — so a round's write is one PUT; a conflict, another host's write in between, is retried once at the version the refusal names.

func NewPage

func NewPage(base, slug, bearer string, client *http.Client) *Page

NewPage opens the page slug on the ccc-pages service at base with the owner login "<user>:<token>"; a nil client is one with Timeout.

func (*Page) Create

func (p *Page) Create(ctx context.Context, key, schema string, data any) (created bool, err error)

Create writes data under key and schema only if the key is absent: one PUT at ?v=0. A key already there answers created false and no error — the caller's key names its content, so what is there is what it would write. It is the timeline's write; the roster's rows, rewritten every round, are Put's.

func (*Page) Get

func (p *Page) Get(ctx context.Context, key string) (*Row, error)

Get reads the row under key; an absent row is nil, nil.

func (*Page) Put

func (p *Page) Put(ctx context.Context, key string, row *Row) error

Put writes the row under key.

type Row

type Row struct {
	Name    string `json:"name"`
	Party   string `json:"party"`
	Channel string `json:"channel"`
	Side    string `json:"side"`
	State   string `json:"state"`
	// LastAt and LastKind are the peer's last message, null and "" before one.
	LastAt   *time.Time `json:"lastAt"`
	LastKind string     `json:"lastKind"`
	Unread   int        `json:"unread"`
	// Active: the channel has a session and the peer sent within ActiveWindow.
	Active bool `json:"active"`
	// Beat is the serve interval in seconds; At this write's time.
	Beat int64     `json:"beat"`
	At   time.Time `json:"at"`
}

Row is one peer's roster page record, plaintext on a private page. It names the peer and the channel, never the host that wrote it, the login or any local id (design §3.6).

func (*Row) Stale

func (r *Row) Stale(now time.Time) bool

Stale reports whether the row outlived its heartbeat: now − at > 3 × beat.

Jump to

Keyboard shortcuts

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