Documentation
¶
Overview ¶
package: client / transport type: adapter job: the branch table — listing it, and reading one branch's head or the archive's limits: transport only; the table is itself a claim the Sequencer mints (-> ranke-go)
Branches are handles, not resources: every head here is a moving target, advanced by the next contribution that lands on it.
package: client / transport type: adapter job: the official Go client for a running ranke-db — one base URL, one credential, and the generated request plumbing every call shares limits: transport only; what a route means is the OpenAPI contract's (-> openapi/openapi.yaml) and what travels over it is the library's (-> ranke-go)
Every request and path string comes from openapi/client, generated from the contract, so a spec change breaks this build where a hand-written path would drift in silence.
By topic: errors.go, read.go, branches.go, system.go, verification.go, contribute.go, dev.go, seq.go (result framing).
package: client / transport type: adapter job: POST /contribute — a claim set and the external content it names, sent as one contribution stream, with the content gathered from the Universe rather than left to the caller limits: builds and posts the stream; framing it is the library's (-> ranke-go codec_wire), and admitting it is the server's Sequencer
package: client / transport type: logic job: the contributor claim a signing key contributes under, and the registrations a scope holds, read back by key or in full limits: builds and reads; contributing it is contribute.go's and verifying it the server's
A branch holds its own contributor claim for a key, dated when it was added — the moment the archive witnessed (paper 01 §Nodes) — so no branch depends on another's.
package: client / transport type: logic job: `R-DEXPIRY`'s key window — the bounds a contributor claim states, shortened by any expiry edge naming it limits: reads the bounds and answers whether a date falls inside; the server verifies (-> ranke-go verify_expiry)
package: client / transport type: adapter job: POST /dev/clock — the dev sequencer's clock, reachable only through Client.Dev so a production consumer never meets it on the client's own surface limits: the route alone; whether it exists is the stack's launch flag, and this reports its absence rather than failing on it
package: client / transport type: errors job: a refused request as a Go error — the contract's {code, error} body behind the seven categories core emits, each an errors.Is sentinel limits: naming failures only; who emits which is core's (-> internal/core/core.go)
package: client / transport type: domain types job: the contract's JSON payloads, under this package's name limits: aliases only; every shape is generated from openapi/openapi.yaml, so a spec change moves the field here too rather than leaving a parallel copy behind
package: client / transport type: adapter job: the reads — POST /query in either framing, the by-id claim and content routes across the three scopes, and /health with the wait a caller would otherwise spend on a guessed sleep limits: transport only; the read language is the library's (-> ranke-go query_codec) and splitting the answer is seq.go's
package: client / transport type: io job: the two framings a read arrives in — RFC 7464 JSON text sequences and RFC 8742 CBOR sequences — split into records, and each record read back as the result it carries limits: the response side only; the contribution stream is the format's and stays there (-> ranke-go codec_wire)
Framing is the endpoint contract's, these being media types a response negotiates, and ranke-go ships the encode direction alone.
package: client / transport type: adapter job: the system routes — what this credential resolves to, and what the stack is made of limits: transport only; the answers are the stack's configuration (-> config)
package: client / transport type: adapter job: the verification runs — start one, poll it, cancel it, delete it limits: transport only; the three depths and what each proves are the library's (-> ranke-go verify)
Index ¶
- Constants
- Variables
- func ContributorWindows(held, expiries []ranke.Claim) (map[string]ContributorWindow, error)
- func ExternalContent(claims []ranke.Claim) ([]ranke.ContentRef, error)
- func MaxCreatedAt(claims []ranke.Claim) time.Time
- func NewContributor(pair ranke.Keypair) (ranke.Contributor, error)
- type ArchiveInfo
- type BranchEntry
- type BranchInfo
- type Client
- func (c *Client) ArchiveInfo(ctx context.Context) (*ArchiveInfo, error)
- func (c *Client) BaseURL() string
- func (c *Client) BranchHead(ctx context.Context, branch string) (string, error)
- func (c *Client) BranchInfo(ctx context.Context, branch string) (*BranchInfo, error)
- func (c *Client) Branches(ctx context.Context) ([]BranchEntry, error)
- func (c *Client) CancelVerification(ctx context.Context, id string) (*VerificationReport, error)
- func (c *Client) Contribute(ctx context.Context, u ranke.Universe, branch string, claims []ranke.Claim, ...) (*ContributionResult, error)
- func (c *Client) ContributorFor(ctx context.Context, scope Scope, pubkey []byte, at time.Time) (ranke.Claim, error)
- func (c *Client) Contributors(ctx context.Context, scope Scope) ([]ranke.Claim, error)
- func (c *Client) ContributorsFor(ctx context.Context, scope Scope, pubkey []byte) ([]ranke.Claim, error)
- func (c *Client) DeleteVerification(ctx context.Context, id string) error
- func (c *Client) Dev() *DevClient
- func (c *Client) Expiries(ctx context.Context, scope Scope) ([]ranke.Claim, error)
- func (c *Client) GetClaim(ctx context.Context, scope Scope, id ranke.Id) (ranke.Claim, error)
- func (c *Client) GetContent(ctx context.Context, scope Scope, id ranke.Id) (*Content, error)
- func (c *Client) Health(ctx context.Context) (*Health, error)
- func (c *Client) Layers(ctx context.Context) ([]StorageLayer, error)
- func (c *Client) Query(ctx context.Context, q ranke.Query) ([]ranke.QueryResult, error)
- func (c *Client) QueryClaims(ctx context.Context, q ranke.Query) ([]ranke.Claim, error)
- func (c *Client) QueryRaw(ctx context.Context, q ranke.Query) ([][]byte, ranke.ResultEncoding, error)
- func (c *Client) StartVerification(ctx context.Context, cfg VerificationConfig) (*VerificationReport, error)
- func (c *Client) Verification(ctx context.Context, id string) (*VerificationReport, error)
- func (c *Client) Verifications(ctx context.Context) ([]VerificationReport, error)
- func (c *Client) WaitReady(ctx context.Context, within time.Duration) error
- func (c *Client) Whoami(ctx context.Context) (*Subject, error)
- type Clock
- type Content
- type ContributeOption
- type ContributionResult
- type ContributorWindow
- type DevClient
- type Error
- type Health
- type Option
- type Scope
- type StorageLayer
- type Subject
- type VerificationConfig
- type VerificationFailure
- type VerificationReport
Constants ¶
const ( MediaJSONSeq = "application/json-seq" MediaCBORSeq = "application/cbor-seq" )
Media types the read endpoints answer with, each mirroring output.encoding, which the server pins before execution so the response always declares what it wrote.
const DefaultTimeout = 60 * time.Second
DefaultTimeout bounds a request the caller supplied no client for; the generated constructor leaves http.Client's zero value, which waits forever.
Variables ¶
var ( // ErrNoBaseURL is a client built against nothing. ErrNoBaseURL = errors.New("ranke/client: base URL is required") // ErrCredentials is several credentials at once, which the endpoint cannot route. ErrCredentials = errors.New("ranke/client: present one credential, not several") // ErrNilClaim is a nil claim, or a nil id in a by-id read. ErrNilClaim = errors.New("ranke/client: nil claim") // ErrNoPubkey is a read narrowed to a key, with no key given. ErrNoPubkey = errors.New("ranke/client: a pubkey is required") // ErrNoLiveContributor is a key with no registration admitting the instant asked // about — none at all, or none whose window still stands. ErrNoLiveContributor = errors.New("ranke/client: no contributor claim admits this key") // ErrUniverseNeedsHead is a closure read asked of `$universe`, which offers no head to // walk from and requires one (`R-QHEAD`); a claim there is reached by id. ErrUniverseNeedsHead = errors.New("ranke/client: a $universe read needs a head") // ErrNoUniverse is external content named with no Universe to read the bytes from. ErrNoUniverse = errors.New("ranke/client: claims name external content, so a Universe is required") // ErrContentMissing is a blob a claim addresses that the Universe does not hold. ErrContentMissing = errors.New("ranke/client: the Universe holds no content under this hash") // ErrUnknownFraming is a response whose media type names no sequence this can split. ErrUnknownFraming = errors.New("ranke/client: response is neither a JSON nor a CBOR sequence") // ErrRouteBoundary is a read asking for routes and for claims at once, which the // response carries no boundary for (-> routesAreReadable). ErrRouteBoundary = errors.New("ranke/client: a read of claims cannot be shaped as paths, the response carrying no route boundary") )
Sentinels for what a caller gets wrong before a request is made; a refusal from the server arrives as an *Error.
var ( // ErrUnauthenticated is a missing or invalid credential. ErrUnauthenticated = errors.New("ranke/client: unauthenticated") // ErrForbidden is an authenticated account without the grant the request needs. ErrForbidden = errors.New("ranke/client: forbidden") // ErrNotFound is an unknown or out-of-scope branch, claim or content. For a by-id // read the two are indistinguishable, which is the point of a scoped closure. ErrNotFound = errors.New("ranke/client: not found") // ErrConflict is a contribution that clashes with the head it would merge onto. ErrConflict = errors.New("ranke/client: conflict") // ErrBusy is a refusal for want of a free slot, which is worth retrying. ErrBusy = errors.New("ranke/client: busy") // ErrInvalid is a malformed request — including both credentials at once, which the // endpoint routes on the presented scheme and so cannot resolve. ErrInvalid = errors.New("ranke/client: invalid request") // ErrUnimplemented is a capability this stack does not offer, which is how a // production stack answers the dev-only routes. ErrUnimplemented = errors.New("ranke/client: not implemented") )
The categories the server emits, as sentinels to branch on. A code the server adds later arrives as an *Error with that Code and no sentinel, rather than as a match on the wrong one.
Functions ¶
func ContributorWindows ¶ added in v1.25.0
func ContributorWindows(held, expiries []ranke.Claim) (map[string]ContributorWindow, error)
Windows reads the window of each contributor claim in held, keyed by id. The carriers of an expiry edge are the `contribution/expiry` claims and the contributor claims themselves, a successor key's claim being free to retire its predecessor (`R-DEXPIRY`).
func ExternalContent ¶
func ExternalContent(claims []ranke.Claim) ([]ranke.ContentRef, error)
ExternalContent lists each distinct blob the claims address, edges included, in order of first appearance so a stream reproduces.
func MaxCreatedAt ¶
MaxCreatedAt is the latest created_at among claims, zero when there are none.
func NewContributor ¶ added in v1.26.0
func NewContributor(pair ranke.Keypair) (ranke.Contributor, error)
NewContributor builds the contributor claim pair signs under, bound to the key so it signs at once. A contribution carries it, every signature resolving through a contributor its own closure reaches (`V-SIG`).
Dated now, `created_at` being the moment the claim was added and nothing else (paper 01 §Nodes) — so a caller whose clock runs ahead of the server's is refused by the ceiling `R-C2DATE` sets at the base time.
Types ¶
type ArchiveInfo ¶
type ArchiveInfo = api.ArchiveInfo
ArchiveInfo reports the Ranke-Archive as a whole — the branch-table head every $archive-scoped read is rooted at, with its height and when it last moved.
type BranchEntry ¶
type BranchEntry = api.BranchEntry
BranchEntry is one row of the branch table: a name and the head it resolves to.
type BranchInfo ¶
type BranchInfo = api.BranchInfo
BranchInfo is one branch's head with its height and when it last moved.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one ranke-db instance.
func New ¶
New returns a client for the instance at baseURL, a bare host:port being read as http. Several credentials are refused here: the endpoint routes on the scheme presented, so two of them name two authenticators. Presenting none reaches a NoAuth endpoint, which only a request carrying no credential header at all can.
func (*Client) ArchiveInfo ¶
func (c *Client) ArchiveInfo(ctx context.Context) (*ArchiveInfo, error)
ArchiveInfo reports the Ranke-Archive as a whole. It is the only route that names the branch-table head, which is what a client needs to address the $archive scope in a query or a grant.
func (*Client) BranchHead ¶
BranchHead reads one branch's current head claim id.
func (*Client) BranchInfo ¶
BranchInfo reads one branch's head with its height and when it last moved.
func (*Client) Branches ¶
func (c *Client) Branches(ctx context.Context) ([]BranchEntry, error)
Branches lists every branch the table holds, each with its current head. It is reachable without knowing a branch name, so a client discovers what it may address before using the routes that take one, and the listing is answered from one archive snapshot, so the heads are consistent with each other.
func (*Client) CancelVerification ¶
CancelVerification stops a running run and keeps its report, partial findings and all, freeing the concurrency slot. It is idempotent: cancelling a run that already finished returns its report unchanged.
func (*Client) Contribute ¶
func (c *Client) Contribute( ctx context.Context, u ranke.Universe, branch string, claims []ranke.Claim, opts ...ContributeOption, ) (*ContributionResult, error)
Contribute merges claims into branch atomically, with the content they address, and returns the new branch-table head with the ids that landed. Content addressing makes it idempotent: re-contributing yields the same ids.
It takes a Universe so the blobs cannot be forgotten — a claim carries only its content_hash, and dedup reads that hash rather than fetching it. Claims naming no external content need none, and nil is then the honest answer.
func (*Client) ContributorFor ¶ added in v1.28.0
func (c *Client) ContributorFor(ctx context.Context, scope Scope, pubkey []byte, at time.Time) (ranke.Claim, error)
ContributorFor returns the registration pubkey signs under at `at`: of the claims carrying that key, the first whose window admits the instant (`R-C4KEY`). Picking another among several is the caller's, over the reads this composes (-> ContributorsFor, Expiries).
func (*Client) Contributors ¶ added in v1.25.0
Contributors returns the `contribution/contributor` claims scope holds, oldest first (`R-QSORT`), each carrying its pubkey inline — the keys that scope admits (`V-SIG`).
func (*Client) ContributorsFor ¶ added in v1.27.0
func (c *Client) ContributorsFor(ctx context.Context, scope Scope, pubkey []byte) ([]ranke.Claim, error)
ContributorsFor returns the claims among those carrying pubkey, in the order they arrived. It reads the content because RQL filters fields alone, the set being one pubkey per contributor.
func (*Client) DeleteVerification ¶
DeleteVerification stops the run if it is still going, then removes the record — so a subsequent read is a not-found. Cancel keeps the report; this does not.
func (*Client) Expiries ¶ added in v1.25.0
Expiries returns the `contribution/expiry` claims scope holds, whose edge shortens a key's window (`R-DEXPIRY`). A contributor claim may carry such an edge too, so a window reads both.
func (*Client) GetClaim ¶
GetClaim fetches one claim by id within scope, as the signed CBOR its id is taken over. A claim outside that closure is answered as one that never existed.
func (*Client) GetContent ¶
GetContent streams the content of claim id within scope. Content is addressed by the claim rather than by a raw hash, so the read stays scoped as the route is. The body is handed over unread: buffering arbitrary bytes decides what a caller can afford.
func (*Client) Health ¶
Health reports the instance as up, the identity it merges under, and its build.
func (*Client) Layers ¶
func (c *Client) Layers(ctx context.Context) ([]StorageLayer, error)
Layers lists the storage stack's read-through tiers, top (cache) to bottom (authoritative). A layer's name is what a query pins execution to and what a verification run reads directly.
func (*Client) Query ¶
Query returns q's results, each record read back into the QueryResult ranke-go describes it with, a reported run ending with the KindReport element ranke.ReportOf reads off the tail. A read cut short by a limit is a complete answer to the query as bounded (`R-QLIMIT`), so truncation stays in the report rather than becoming an error.
func (*Client) QueryClaims ¶
QueryClaims shapes q so every record is a stored record, and decodes each. The envelope in CBOR is fixed here, being the bytes whose hash is the id (`R-QCANON`); a serialized claim is a rendering no id covers, and `R-QDETAIL` refuses json outright.
func (*Client) QueryRaw ¶
func (c *Client) QueryRaw(ctx context.Context, q ranke.Query) ([][]byte, ranke.ResultEncoding, error)
QueryRaw returns each record of the result sequence as bytes, split by the framing the response declares. It names no payload, so a result kind added upstream needs no release here.
func (*Client) StartVerification ¶
func (c *Client) StartVerification(ctx context.Context, cfg VerificationConfig) (*VerificationReport, error)
StartVerification begins a run over cfg's closure and returns the report it opens with. The run is asynchronous: poll Verification until status leaves running.
A stack already at its run limit refuses with ErrBusy, which is the one refusal here worth retrying.
func (*Client) Verification ¶
Verification reads one run's report. While the run is still going the progress counters advance between polls.
func (*Client) Verifications ¶
func (c *Client) Verifications(ctx context.Context) ([]VerificationReport, error)
Verifications lists the runs the stack holds, running and finished alike.
func (*Client) WaitReady ¶
WaitReady polls /health until it answers or within elapses, so a caller starting a stack waits for the fact rather than a guessed interval. A settled refusal ends the wait at once, retrying an answer already given only spending the window.
type Clock ¶
Clock is where the dev sequencer's clock stands. Available is false against a stack that mounts no dev routes, which is every production one.
type Content ¶
type Content struct {
// MediaType is the claim's encoding, as the endpoint declares it.
MediaType string
Body io.ReadCloser
}
Content is a claim's content as the server streams it. The caller closes Body.
type ContributeOption ¶
type ContributeOption func(*ranke.WireConstraints)
ContributeOption declares what a contribution asks beyond appending to a branch that exists. A declaration only narrows what the server allows, so asking still needs the right to match.
func Creating ¶
func Creating() ContributeOption
Creating declares that the branches named may be brought into being. Without it a contribution to a branch the archive lacks is refused however the account is granted, so a branch created by a typo is one the client asked for.
func Referencing ¶
func Referencing(scopes ...string) ContributeOption
Referencing replaces the scopes the claims may reference, which default to the branch being written. The server narrows the declaration to what the grants reach.
type ContributionResult ¶
type ContributionResult = api.ContributionResult
ContributionResult is what a merge produced: the new branch-table head and the ids absorbed under it.
type ContributorWindow ¶ added in v1.25.0
type ContributorWindow struct {
From *time.Time
Until *time.Time
// Revoked reports Until as an expiry edge's date rather than the claim's own — an early
// expiry someone asked for.
Revoked bool
}
Window is a contributor key's validity: the closed span between its bounds, each standing on its own, an absent bound leaving that end open (`R-DEXPIRY`).
func ContributorWindowOf ¶ added in v1.25.0
ContributorWindowOf reads the window of the contributor claim self, with carriers searched for the expiry edges naming it. An expiry only shortens the end, and the earliest of several wins, so a revocation cannot extend a key someone already retired.
func (ContributorWindow) Admits ¶ added in v1.25.0
func (w ContributorWindow) Admits(at time.Time) bool
Admits reports at as falling inside the window, which `R-C4KEY` requires of every claim the key signs.
func (ContributorWindow) String ¶ added in v1.25.0
func (w ContributorWindow) String() string
String renders the window for a listing, each open end as a dash.
type DevClient ¶
type DevClient struct {
// contains filtered or unexported fields
}
DevClient is the development-only surface. It is reached through Client.Dev, which keeps these routes out of the way of a consumer that has no business with them: a real deployment mounts none of them.
func (*DevClient) AdvanceClock ¶
AdvanceClock moves the dev sequencer's clock to at least at, so a client whose story has its own schedule can make the archive's recorded times follow it.
The clock only moves forward: an instant already passed is accepted and changes nothing. A stack without the dev routes answers 501, which comes back as Available false rather than as an error — a caller running against both kinds of deployment should not have to branch on which one it reached.
func (*DevClient) AdvanceClockPast ¶
AdvanceClockPast moves the clock to the latest created_at the claims carry, which is what a dev contribution needs: the sequencer stamps its merge from the clock, and a merge dated before a claim it absorbs would break `V-MONO`. A fixed offset from wall-clock now cannot know where a batch's own story ends.
type Error ¶
Error is a request the server refused. Code is the contract's machine-readable category and is what to branch on — through errors.Is against the sentinels above, so a misspelt code is a compile error rather than a comparison that never matches.
func (*Error) Unwrap ¶
Unwrap returns the sentinel this category stands for, so errors.Is answers for it. A category the client does not name unwraps to nil, leaving the *Error itself: the status is read only where no code came with it, since a code the server adds later would otherwise match on whichever sentinel its status happens to share.
type Option ¶
type Option func(*settings)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient supplies the transport, for timeouts, proxies or a test server. It replaces DefaultTimeout.
func WithMacaroon ¶
WithMacaroon presents a base64 binary macaroon as `Authorization: Macaroon`. Its own option because the endpoint sends every other scheme, Bearer included, to the JWT authenticator, where a macaroon 401s with nothing naming the cause.
type Scope ¶
type Scope string
Scope names which of the three by-id routes a read takes: a branch, or one of the two reserved scopes.
type StorageLayer ¶
type StorageLayer = api.StorageLayer
StorageLayer names one read-through tier and the adapter behind it.
type Subject ¶
Subject is what a credential resolved to: the account, its grants, and the caveats the credential itself carries.
type VerificationConfig ¶
type VerificationConfig = api.VerificationConfig
VerificationConfig is a run's parameters — the closure, the depth, the layer.
type VerificationFailure ¶
type VerificationFailure = api.VerificationFailure
VerificationFailure is one claim or object a run found wanting.
type VerificationReport ¶
type VerificationReport = api.VerificationReport
VerificationReport is a point-in-time record of a run, config included.