Documentation
¶
Index ¶
- Variables
- func GenerateKeys(name string) (string, string, error)
- type Option
- type Record
- type Store
- type SumDB
- func (s *SumDB) Handler() http.Handler
- func (s *SumDB) Lookup(ctx context.Context, mod module.Version) (int64, error)
- func (s *SumDB) ReadRecords(ctx context.Context, id, n int64) ([][]byte, error)
- func (s *SumDB) ReadTileData(ctx context.Context, t tlog.Tile) ([]byte, error)
- func (s *SumDB) Signed(ctx context.Context) ([]byte, error)
- type TxStore
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("record not found")
ErrNotFound is returned when a requested record does not exist in the store.
Functions ¶
func GenerateKeys ¶
GenerateKeys creates a new keypair and returns the encoded signer key, and verifier key.
The name identifies the key (e.g., "sum.golang.org").
The signer key is secret and must be stored securely. The verifier key can be shared publicly for clients to verify signatures.
Types ¶
type Option ¶
type Option func(*SumDB)
Option configures a SumDB instance.
func WithHTTPClient ¶
WithHTTPClient sets the client used to communicate with the proxy.
func WithUpstream ¶
WithUpstream sets the upstream proxy to query when no records are found.
type Store ¶
type Store interface {
// RecordID returns the ID of the record for the given module path and version.
// Returns ErrNotFound if no record exists.
RecordID(ctx context.Context, path, version string) (int64, error)
// Records returns records with IDs in the interval [id, id+n).
// The returned slice may have fewer than n records if the range extends
// beyond the current tree size.
Records(ctx context.Context, id, n int64) ([]*Record, error)
// AddRecord adds a new entry for the specified module.
// The record's ID field is ignored; the store assigns the next sequential ID.
// Returns the assigned ID.
AddRecord(ctx context.Context, r *Record) (int64, error)
// ReadHashes returns the hashes at the given storage indexes.
// Indexes are computed using tlog.StoredHashIndex(level, n).
// The returned slice must have the same length as indexes.
ReadHashes(ctx context.Context, indexes []int64) ([]tlog.Hash, error)
// WriteHashes stores hashes at the given storage indexes.
// indexes and hashes must have the same length.
WriteHashes(ctx context.Context, indexes []int64, hashes []tlog.Hash) error
// TreeSize returns the current number of records in the tree.
TreeSize(ctx context.Context) (int64, error)
// SetTreeSize updates the tree size.
// This should be called after successfully adding a record and its hashes.
SetTreeSize(ctx context.Context, size int64) error
}
Store defines the persistence interface for sumdb data. Implementations must be safe for concurrent use.
A Store instance should only be used by a single SumDB. Sharing a Store across multiple SumDB instances is not supported and may corrupt the Merkle tree, as write serialization is handled at the SumDB level.
type SumDB ¶
type SumDB struct {
// contains filtered or unexported fields
}
SumDB is a checksum database server that implements the Go sumdb protocol.
It implements the ServerOpts interface defined in https://pkg.go.dev/golang.org/x/mod@v0.31.0/sumdb#ServerOps.
func New ¶
New creates a new SumDB instance with the given server name and signing key. The name identifies this sumdb (e.g., "sum.example.com"). The skey must be in note signer format: "PRIVATE+KEY+<name>+<hash>+<keydata>".
NB: You can use GenerateKeys to create a valid signing key.
func (*SumDB) Lookup ¶
Lookup finds or creates a record for the given module version. If the record doesn't exist, it fetches the module from the upstream proxy, computes the checksums, and stores the new record with its tree hashes. Concurrent lookups for the same module are deduplicated via singleflight.
func (*SumDB) ReadRecords ¶
ReadRecords returns the raw data for records with IDs in [id, id+n).
func (*SumDB) ReadTileData ¶
ReadTileData returns the raw record data for a data tile. Data tiles (L=-1) contain concatenated record data rather than hashes.
type TxStore ¶ added in v0.1.1
type TxStore interface {
Store
// WithTx executes fn within a database transaction.
// If fn returns nil, the transaction is committed.
// If fn returns an error or panics, the transaction is rolled back.
//
// The Store passed to fn represents the transactional view and must be used
// for all operations within the callback.
WithTx(ctx context.Context, fn func(Store) error) error
}
TxStore is an optional extension of Store that provides transaction support. When a Store implements TxStore, atomic operations will use transactions.
Implementations that do not support transactions can simply implement Store. The SumDB will detect TxStore support at runtime and use transactions when available.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
db
command
Command db demonstrates using sumdb with SQLite storage.
|
Command db demonstrates using sumdb with SQLite storage. |
|
internal
|
|
|
signer
Package signer provides Ed25519 signing and verification for sumdb tree heads.
|
Package signer provides Ed25519 signing and verification for sumdb tree heads. |
|
tree
Package tree provides Merkle tree operations for sumdb using tlog.
|
Package tree provides Merkle tree operations for sumdb using tlog. |