s3d

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 52 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 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

This section is empty.

Variables

This section is empty.

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

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"`
	// 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"`
	// 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

func LoadConfig(path string) (*Config, error)

LoadConfig reads and checks a configuration file.

func (*Config) Check

func (c *Config) Check() error

Check holds the configuration to its rules and fills the defaults.

func (*Config) IdentityDir

func (c *Config) IdentityDir(name string) string

IdentityDir is an identity's directory.

func (*Config) Spec added in v0.9.0

func (c *Config) Spec() chaincfg.Spec

Spec is the chain, settlement and fee settings, for chaincfg.

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 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 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
}

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

func New(ctx context.Context, cfg *Config, opts Options) (*Server, error)

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

func (s *Server) Addr() string

Addr is where the gateway listens, once started.

func (*Server) Close

func (s *Server) Close() error

Close stops serving, waits for the background work, and saves.

func (*Server) Identity

func (s *Server) Identity(name string) string

Identity is an identity's key, 66 hex digits.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the S3 surface. Paths are never cleaned: a key is the decoded path after the bucket, exactly.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start listens and starts the background work.

Jump to

Keyboard shortcuts

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