Documentation
¶
Overview ¶
Package s3d is `bstore s3d`, the S3 gateway of spec section 16: a reader and a writer for clients that speak S3, authenticated with AWS Signature Version 4 in gateway mode. Reads are proven against the bucket's chain (package reader); writes are published by the identity an access key maps to (package publish). docs/s3.md is the operator's guide and the compatibility matrix.
Index ¶
- Constants
- Variables
- type AccessKey
- type Auth
- type BountyConfig
- type BucketConfig
- type Config
- type Key
- type Limits
- type ListedObject
- type LocalProvider
- type ObjectAnswer
- type Options
- type RaceConfig
- type Server
- func (s *Server) AddBucket(b BucketConfig) (string, error)
- func (s *Server) Addr() string
- func (s *Server) BucketNames() []string
- func (s *Server) Close() error
- func (s *Server) Identity(name string) string
- func (s *Server) ListObjects(ctx context.Context, name, after string, max int) (objs []ListedObject, more bool, err error)
- func (s *Server) ReadObject(ctx context.Context, bucket, key string, head bool, cond http.Header) (*ObjectAnswer, error)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Start(ctx context.Context) error
Constants ¶
const MaxListed = 1000
MaxListed is the most objects a ListObjects page holds.
Variables ¶
var ErrNoBucket = errors.New("gateway: no such bucket")
ErrNoBucket is a read of a bucket the configuration does not name.
var ErrRefused = errors.New("gateway: the object was refused")
ErrRefused is an object that fails its checks: what verifies names the owner or the writer at fault, and trying again does not help. S3 answers it 500.
var ErrShed = errors.New("gateway: the read was refused for now")
ErrShed is a read this gateway refused because it is shedding load or cannot prove or fetch the object now: what S3 answers as 503. The caller may try again.
Functions ¶
This section is empty.
Types ¶
type AccessKey ¶
type AccessKey struct {
ID string `json:"id"`
Secret string `json:"secret,omitempty"`
SecretFile string `json:"secret_file,omitempty"`
Identity string `json:"identity"`
Buckets []string `json:"buckets,omitempty"`
}
AccessKey is one S3 access key.
type Auth ¶
type Auth struct {
Key *Key
// Seed is the request's signature: a streaming body's chunks chain
// from it, and replay protection is keyed by it.
Seed string
Scope string
Time time.Time
Payload string // the x-amz-content-sha256 value
Presign bool
// contains filtered or unexported fields
}
Auth is a request whose signature verified.
type BountyConfig ¶
type BountyConfig struct {
Satoshis uint64 `json:"satoshis"`
T uint64 `json:"t"`
K uint64 `json:"k"`
RetentionSeconds uint64 `json:"retention_seconds"`
DeadlineBlocks uint64 `json:"deadline_blocks"`
CheckC uint64 `json:"check_c"`
}
BountyConfig is the hold bounty a put asks for (spec section 4.3).
type BucketConfig ¶
type BucketConfig struct {
Bucket string `json:"bucket"`
Owner string `json:"owner"`
ID string `json:"id"`
}
BucketConfig is one bucket chain the gateway serves: the identifier, the owner's key and the bucket id (spec sections 3.3 and 16.1).
func (*BucketConfig) Check ¶ added in v0.37.0
func (b *BucketConfig) Check() (string, error)
Check holds one bucket entry to the rules of the configuration's buckets and returns its S3 name.
type Config ¶
type Config struct {
// Data is the data directory: identities/<name>/ (each a wallet, its
// funding trees and its outbox), store/ (the local closures), uploads/,
// state.json. Absolute.
Data string `json:"data"`
// Listen is the address S3 is served on; TLSCert and TLSKey, when both
// set, serve it over TLS (otherwise a proxy in front terminates it).
Listen string `json:"listen"`
TLSCert string `json:"tls_cert,omitempty"`
TLSKey string `json:"tls_key,omitempty"`
// ETagMD5 makes ETags S3's MD5s (a part's MD5; the MD5 of the parts'
// MD5s for a multipart upload), at the cost of an MD5 over every body.
// Off, an object's ETag is its content hash (its SHA-256, what
// x-amz-checksum-sha256 carries) and a part's its SHA-256.
ETagMD5 bool `json:"etag_md5,omitempty"`
// Region is the SigV4 region clients sign for; Domain, when set, also
// serves virtual-host addressing (<bucket>.<domain>).
Region string `json:"region"`
Domain string `json:"domain,omitempty"`
// Chain is the chain view (nodeapi.ParseChain: woc:main, woc:test,
// asset:URL; default woc:main or woc:test by Mainnet); Node, the older
// key, a node's asset API, is chain asset:URL. Settle is the settlement
// leg (publish.ParseSettler: arcade:main, arcade:URL, arc:URL, rpc:URL,
// tcp:ADDR; default GorillaPool's arcade), with RPCUser, RPCPass,
// ArcadeKey; Headers a header source (bcommon headers; default
// woc:main or woc:test), HeadersToken its bearer token. WoCKey and
// WoCRate are a WhatsOnChain API key and its requests a second: a busy
// gateway needs one, or a node. On a regtest chain set chain, settle
// and headers.
Chain string `json:"chain,omitempty"`
Node string `json:"node,omitempty"`
Settle string `json:"settle,omitempty"`
RPCUser string `json:"rpc_user,omitempty"`
RPCPass string `json:"rpc_pass,omitempty"`
ArcadeKey string `json:"arcade_key,omitempty"`
Headers string `json:"headers,omitempty"`
HeadersToken string `json:"headers_token,omitempty"`
WoCKey string `json:"woc_key,omitempty"`
WoCRate float64 `json:"woc_rate,omitempty"`
// Hosts are the overlay hosts asked and written to; Facade, when set,
// is the plane; Providers are providers pieces and entries are
// unicast to (their submit route). Quorum is how many hosts must take
// an entry when there is no facade.
Hosts []string `json:"hosts"`
Facade string `json:"facade,omitempty"`
Providers []string `json:"providers,omitempty"`
Quorum int `json:"quorum,omitempty"`
// LocalProvider, when set, runs a provider in this process: a storage
// node. Every piece is handed to it as a function call, beside the
// facade and the providers named, with no socket and no copy.
LocalProvider *LocalProvider `json:"local_provider,omitempty"`
// ReadOnlyGateway, read_only, is a gateway that serves reads only and
// names no facade, provider or local provider (ReadOnly). It is asked
// for, never inferred: a writer whose delivery settings are missing or
// mistyped is refused at start, not demoted.
ReadOnlyGateway bool `json:"read_only,omitempty"`
// CA, when set, is a PEM file of certificates trusted, besides the
// system's, for TLS to hosts, providers and advertisers.
CA string `json:"ca,omitempty"`
// FetchPrivate lets the gateway fetch from advertised URLs whose host
// resolves to a loopback, private or link-local address; off, such an
// advertisement is never fetched from.
FetchPrivate bool `json:"fetch_private,omitempty"`
// KeepFetched keeps, in the local store, each object a read fetched
// from an advertiser, so the next read of it is served from disk. Off,
// the store holds this gateway's own writes only. The store's bound
// (store_bytes) covers what is kept.
KeepFetched bool `json:"keep_fetched,omitempty"`
// ReadMemoryMS, when positive, is for how many milliseconds a bucket's
// latest token is held to be the latest after a read proved it so: a
// key already proven against it is answered meanwhile without asking a
// host, and a new token is seen at most this late. Zero (the default)
// asks a host for every read. At most 60000.
ReadMemoryMS int `json:"read_memory_ms,omitempty"`
// Identities are the writer identities, each with a wallet under
// identities/<name>; AccessKeys map S3 access keys to them; Buckets are
// the chains served.
Identities []string `json:"identities"`
AccessKeys []AccessKey `json:"access_keys"`
Buckets []BucketConfig `json:"buckets"`
// Bounty, when set, is the hold bounty every put asks for; HoldAhead is
// how many mined hold outputs of it each identity keeps ready.
Bounty *BountyConfig `json:"bounty,omitempty"`
HoldAhead int `json:"hold_ahead,omitempty"`
// HoldTree is how many hold outputs one transaction carries: by
// default, and at most, what hosts admit of a mined transaction (1,024).
HoldTree int `json:"hold_tree,omitempty"`
Limits Limits `json:"limits"`
// PieceTree and EntryTree size funding trees. Fee is the miner fee
// policy (feepolicy.Config; default 100 satoshis per 1000 bytes, floor
// 100, capped at 100/1000); FeeRate and FeeFloor are its older keys,
// still read and held to the same cap.
PieceTree int `json:"piece_tree"`
EntryTree int `json:"entry_tree"`
Fee *feepolicy.Config `json:"fee,omitempty"`
FeeRate uint64 `json:"fee_sat_per_byte,omitempty"`
FeeFloor uint64 `json:"fee_floor,omitempty"`
Mainnet bool `json:"mainnet"`
// RefuseUnmined makes fund -beef take mined payments only.
RefuseUnmined bool `json:"refuse_unmined,omitempty"`
// The payment acceptance rule a settlement is remitted by (accept_
// keys, docs/s3.md).
acceptcfg.Config
// PieceWorkers is how many piece carriers a put mints and sends at once
// (default 16); PieceAhead how many piece outputs are kept ready ahead
// of the puts, across the current tree, the trees held for a switch
// and the trees being minted, with more trees minted in the background
// when fewer are left (default sixteen trees of piece_tree);
// EntryAhead the same for entry trees (default sixteen trees of
// entry_tree). A
// writer is held to the entry outputs ready per block interval: set
// entry_ahead to the puts one block interval must absorb, and the
// gateway keeps that many ready across as many trees of entry_tree
// outputs as it takes, each entry carrier carrying only its own tree.
PieceWorkers int `json:"piece_workers,omitempty"`
PieceAhead int `json:"piece_ahead,omitempty"`
EntryAhead int `json:"entry_ahead,omitempty"`
// Race is the hold race, settlement and reclaim the gateway runs in the
// background for its own puts.
Race RaceConfig `json:"race"`
// StoreBytes bounds the local closures kept for reading the gateway's
// own writes and for copies.
StoreBytes int64 `json:"store_bytes"`
// OutboxBytes bounds what each identity's outbox may owe its targets
// (a provider that is down) before a put is refused with 503
// SlowDown; 0 is 8 GiB.
OutboxBytes int64 `json:"outbox_bytes,omitempty"`
// MetricsListen, when set, serves /metrics there, and only there.
MetricsListen string `json:"metrics_listen,omitempty"`
// PprofListen, when set, serves Go's net/http/pprof there (a loopback
// address: the profiles are the process's internals), with mutex and
// block profiling on.
PprofListen string `json:"pprof_listen,omitempty"`
}
Config is the gateway's configuration file, JSON; an unknown key is refused. Every field has a default but Data, Hosts, Identities, AccessKeys and Buckets.
func LoadConfig ¶
LoadConfig reads and checks a configuration file.
func (*Config) IdentityDir ¶
IdentityDir is an identity's directory.
type Key ¶
type Key struct {
ID string
Secret string
Identity string
// Buckets are the S3 bucket names the key may use; empty is every
// configured bucket.
Buckets map[string]bool
}
Key is one access key.
type Limits ¶
type Limits struct {
// MaxObject bounds a PutObject body; MaxUpload a multipart upload's
// assembled object; MaxPart one part; MaxParts the part numbers.
MaxObject int64 `json:"max_object"`
MaxUpload int64 `json:"max_upload"`
MaxPart int64 `json:"max_part"`
MaxParts int `json:"max_parts"`
// Uploads open at once, in all and per access key; UploadSeconds how
// long one may stay open.
Uploads int `json:"uploads"`
UploadsPerKey int `json:"uploads_per_key"`
UploadSeconds int `json:"upload_seconds"`
// Writes are puts, copies and completions at once; PartWrites part
// uploads at once; Reads object reads at once. Past each the gateway
// answers 503 SlowDown.
Writes int `json:"writes"`
PartWrites int `json:"part_writes"`
Reads int `json:"reads"`
// PartWriters is how many part blobs are written to the disk at once,
// across every upload: parts in flight are hashed as they stream in
// and queue for a writer, so the drive sees this many streams, not one
// per part. Default 2.
PartWriters int `json:"part_writers"`
// Stages are put and copy bodies streaming in at once; Lookups the
// heads, gets and listings asking hosts at once.
Stages int `json:"stages"`
Lookups int `json:"lookups"`
// MinRate is the slowest a request body may arrive, bytes a second
// averaged after its first IdleSeconds; slower is cut off.
MinRate int64 `json:"min_rate"`
// ReplayPerKey bounds the signatures one access key has remembered
// against replay; past it that key's writes are refused with SlowDown.
// A signature is remembered for the 15 minutes it could be replayed,
// so this bounds a key's sustained writes to ReplayPerKey / 900 a
// second. The default is one replay window at RequestsPerSec, so the
// request rate, not this, is what holds a key back.
ReplayPerKey int `json:"replay_per_key"`
// RequestsPerSec and Burst bound the requests of one access key.
RequestsPerSec float64 `json:"requests_per_sec"`
Burst float64 `json:"burst"`
// IdleSeconds is the longest a request body or a response may stall.
IdleSeconds int `json:"idle_seconds"`
// DeleteKeys bounds one DeleteObjects request.
DeleteKeys int `json:"delete_keys"`
}
Limits are the gateway's hardening; zero takes the default.
type ListedObject ¶ added in v0.40.0
ListedObject is one object of a ListObjects page: its key, its size in bytes, its ETag (quoted, as a read answers it) and when its entry was made.
type LocalProvider ¶ added in v0.24.0
type LocalProvider struct {
// Config is the provider's configuration file, as bstore-provider run
// takes it; the provider listens and advertises as it would alone.
Config string `json:"config"`
// Verify, true unless set false, checks every piece the gateway hands
// over as any submission is checked. False takes the gateway's own
// account of each piece it minted (its hash, record, funding output and
// txid) as given, which saves the provider most of its work per piece:
// the operator's choice for a provider that trusts only its own gateway.
Verify *bool `json:"verify,omitempty"`
}
LocalProvider is a provider run in the gateway's process (Config).
func (*LocalProvider) Verifies ¶ added in v0.24.0
func (l *LocalProvider) Verifies() bool
Verifies reports whether the local provider checks what it is handed.
type ObjectAnswer ¶ added in v0.35.0
type ObjectAnswer struct {
Status int
Header http.Header
Root [32]byte // the object's closure root (200, 206, 304)
// contains filtered or unexported fields
}
ObjectAnswer is what a read answers to a caller in this process: what GetObject or HeadObject would have sent, without the HTTP exchange.
Status is 200, 206, 304, 404, 412 or 416. Header carries the object's Content-Type, Content-Length, ETag, Last-Modified, Accept-Ranges and Content-Range as the status has them; a 412 carries the validators too. User metadata and the S3 checksum headers are not given. A 200 or 206 of a read that was not a head has a body: WriteTo writes it, once. Such an answer holds one of the gateway's read slots (limits.reads) until Close, which must be called, written or not; closing any other answer is harmless. WriteTo is called by one goroutine; Close may be called again and from another.
func (*ObjectAnswer) Close ¶ added in v0.35.0
func (a *ObjectAnswer) Close() error
Close ends the read.
func (*ObjectAnswer) WriteTo ¶ added in v0.35.0
func (a *ObjectAnswer) WriteTo(w io.Writer) (int64, error)
WriteTo writes the answer's body to w: each blob the range overlaps is fetched whole and held to its hash before a byte of it is written, and a whole object is held to its content hash before its last blob is (spec section 15.2). An error before the first byte reached w means nothing was sent. An error of w itself, or of the read's context, comes back as it is; one of the object's is ErrShed or ErrRefused.
type Options ¶
type Options struct {
Now func() time.Time
Logf func(format string, args ...any)
// Tick paces the background work.
Tick time.Duration
// LockWait is how long an identity another process has open (a
// command run against it) is waited for at start.
LockWait time.Duration
// NoListen starts the gateway without its S3 listener: its only
// reader is the program it runs in (ReadObject). The metrics and
// profile listeners are served as configured.
NoListen bool
}
Options are what an embedding caller may set beyond the configuration.
type RaceConfig ¶ added in v0.3.0
type RaceConfig struct {
// Off leaves races to the command line, run against a stopped gateway.
Off bool `json:"off,omitempty"`
// WindowSeconds is the race window (default an hour); TickSeconds the
// pause between passes (default 10).
WindowSeconds int64 `json:"window_seconds,omitempty"`
TickSeconds int `json:"tick_seconds,omitempty"`
// Budget is the most paid for one settlement challenge a provider
// prices (default 0: only free answers).
Budget uint64 `json:"budget,omitempty"`
// NoPublish keeps failed challenges unpublished as outcome records.
NoPublish bool `json:"no_publish,omitempty"`
// Parallel is how many open races a pass steps at once (default 8).
Parallel int `json:"parallel,omitempty"`
}
RaceConfig is the gateway's background race (spec section 9.4): for each identity's own puts with a bounty, the race judged, settled by rank once closed, the remittances sent, and the hold output reclaimed after the deadline when nothing settled, as `bstore holds`, `settle` and `reclaim` would. On by default.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is one running gateway.
func New ¶
New opens a gateway over a checked configuration: every identity's wallet (bstore s3d init creates them), its funding trees and outbox, the local store and the state.
func (*Server) AddBucket ¶ added in v0.37.0
func (s *Server) AddBucket(b BucketConfig) (string, error)
AddBucket serves one more bucket from now on, held to the rules of the configuration's buckets, and returns its S3 name: a site a web node is asked to serve. Only a gateway that serves reads only takes one: on a writing gateway every access key not limited to named buckets could publish to it, so a writer serves the buckets its configuration names. A bucket served already under the same chain is no change; another chain under its S3 name is refused. The bucket is not written to the configuration file: the program that adds it adds it again at its next start. Reads in this process (ReadObject) reach it, and so does every access key not limited to named buckets; a key limited to named buckets does not.
func (*Server) BucketNames ¶ added in v0.35.0
BucketNames are the S3 names of the buckets served, sorted.
func (*Server) ListObjects ¶ added in v0.40.0
func (s *Server) ListObjects(ctx context.Context, name, after string, max int) (objs []ListedObject, more bool, err error)
ListObjects is a page of the objects of the bucket with the S3 name name, in key order after the key given, as ListObjectsV2 with no prefix and no delimiter answers them: proven complete against the bucket's latest token and merged with the gateway's own pending entries, at most max (1 to MaxListed; anything else is MaxListed). more says a page follows, after the last key of this one. The error is ErrNoBucket for a bucket the configuration does not name, ErrShed for a listing refused for now (a bound, or the hosts did not prove a page).
func (*Server) ReadObject ¶ added in v0.35.0
func (s *Server) ReadObject(ctx context.Context, bucket, key string, head bool, cond http.Header) (*ObjectAnswer, error)
ReadObject is GetObject (or HeadObject, when head) for a caller in this process: the key is proven and the object opened exactly as for an S3 request, with no signature, no access key and no request rate bound, which are the S3 face's. bucket is the bucket's S3 name. cond carries Range and the conditional headers under their canonical names (a request's own Header does), or is nil. ctx is the read's: it bounds the proof, the opening and WriteTo.
A key proven absent answers 404, and so does a key no object can have (S3 answers that one 400). No failure to prove or fetch is ever a 404: a read refused for now is ErrShed, an object that fails its checks ErrRefused.