s3d

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 44 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"`
	// 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"`
	// Node is a Teranode asset API; Settle the settlement leg (tcp:,
	// rpc: or arcade:, with RPCUser, RPCPass, ArcadeKey); Headers a header
	// source (bcommon headers).
	Node      string `json:"node"`
	Settle    string `json:"settle"`
	RPCUser   string `json:"rpc_user,omitempty"`
	RPCPass   string `json:"rpc_pass,omitempty"`
	ArcadeKey string `json:"arcade_key,omitempty"`
	Headers   string `json:"headers"`
	// 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"`
	// 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"`
	Limits    Limits        `json:"limits"`
	// PieceTree and EntryTree size funding trees; FeeRate and FeeFloor are
	// the fee policy.
	PieceTree int    `json:"piece_tree"`
	EntryTree int    `json:"entry_tree"`
	FeeRate   uint64 `json:"fee_sat_per_byte"`
	FeeFloor  uint64 `json:"fee_floor"`
	Mainnet   bool   `json:"mainnet"`
	// StoreBytes bounds the local closures kept for reading the gateway's
	// own writes and for copies.
	StoreBytes int64 `json:"store_bytes"`
	// MetricsListen, when set, serves /metrics there, and only there.
	MetricsListen string `json:"metrics_listen,omitempty"`
}

Config is the gateway's configuration file, JSON; an unknown key is refused. Every field has a default but Data, Node, Settle, Headers, 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.

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"`
	// 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 wait.
	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 Options

type Options struct {
	Now  func() time.Time
	Logf func(format string, args ...any)
	// Tick paces the background work.
	Tick time.Duration
}

Options are what an embedding caller may set beyond the configuration.

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