Documentation
¶
Overview ¶
Package client provides client support for interacting with logs that uses the tlog-tiles API.
Package stream provides support for streaming contiguous entries from logs.
Index ¶
- Variables
- func Entries[T any](bundles iter.Seq2[Bundle, error], unbundle func([]byte) ([]T, error)) iter.Seq2[Entry[T], error]
- func EntryBundles(ctx context.Context, numWorkers uint, getSize TreeSizeFunc, ...) iter.Seq2[Bundle, error]
- func FetchCheckpoint(ctx context.Context, f CheckpointFetcherFunc, v note.Verifier, origin string) (*log.Checkpoint, []byte, *note.Note, error)
- func FetchLeafHashes(ctx context.Context, f TileFetcherFunc, first, N, logSize uint64) ([][]byte, error)
- func FetchRangeNodes(ctx context.Context, s uint64, f TileFetcherFunc) ([][]byte, error)
- func GetEntryBundle(ctx context.Context, f EntryBundleFetcherFunc, i, logSize uint64) (api.EntryBundle, error)
- type Bundle
- type CheckpointFetcherFunc
- type ConsensusCheckpointFunc
- type Entry
- type EntryBundleFetcherFunc
- type ErrInconsistency
- type FileFetcher
- type HTTPFetcher
- func (h HTTPFetcher) ReadCheckpoint(ctx context.Context) ([]byte, error)
- func (h HTTPFetcher) ReadEntryBundle(ctx context.Context, i uint64, p uint8) ([]byte, error)
- func (h HTTPFetcher) ReadTile(ctx context.Context, l, i uint64, p uint8) ([]byte, error)
- func (h *HTTPFetcher) SetAuthorizationHeader(v string)
- type LogStateTracker
- type ProofBuilder
- type TileFetcherFunc
- type TreeSizeFunc
Constants ¶
This section is empty.
Variables ¶
var (
NKey = attribute.Key("N")
)
Functions ¶
func Entries ¶ added in v1.0.0
func Entries[T any](bundles iter.Seq2[Bundle, error], unbundle func([]byte) ([]T, error)) iter.Seq2[Entry[T], error]
Entries consumes an iterator of Bundle structs and transforms it using the provided unbundle function, and returns an iterator over the transformed data.
Different unbundle implementations can be provided to return raw entry bytes, parsed entry structs, or derivations of entries (e.g. hashes) as needed.
func EntryBundles ¶ added in v1.0.0
func EntryBundles(ctx context.Context, numWorkers uint, getSize TreeSizeFunc, getBundle EntryBundleFetcherFunc, fromEntry uint64, N uint64) iter.Seq2[Bundle, error]
EntryBundles produces an iterator which returns a stream of Bundle structs which cover the requested range of entries in their natural order in the log.
If the adaptor encounters an error while reading an entry bundle, the encountered error will be returned via the iterator.
This adaptor is optimised for the case where calling getBundle has some appreciable latency, and works around that by maintaining a read-ahead cache of subsequent bundles which is populated a number of parallel requests to getBundle. The request parallelism is set by the value of the numWorkers paramemter, which can be tuned to balance throughput against consumption of resources, but such balancing needs to be mindful of the nature of the source infrastructure, and how concurrent requests affect performance (e.g. GCS buckets vs. files on a single disk).
func FetchCheckpoint ¶
func FetchCheckpoint(ctx context.Context, f CheckpointFetcherFunc, v note.Verifier, origin string) (*log.Checkpoint, []byte, *note.Note, error)
FetchCheckpoint retrieves and opens a checkpoint from the log. Returns both the parsed structure and the raw serialised checkpoint.
func FetchLeafHashes ¶
func FetchLeafHashes(ctx context.Context, f TileFetcherFunc, first, N, logSize uint64) ([][]byte, error)
FetchLeafHashes fetches N consecutive leaf hashes starting with the leaf at index first.
func FetchRangeNodes ¶
FetchRangeNodes returns the set of nodes representing the compact range covering a log of size s.
func GetEntryBundle ¶
func GetEntryBundle(ctx context.Context, f EntryBundleFetcherFunc, i, logSize uint64) (api.EntryBundle, error)
GetEntryBundle fetches the entry bundle at the given _tile index_.
Types ¶
type Bundle ¶ added in v1.0.0
type Bundle struct {
// RangeInfo decribes which of the entries in this bundle are relevent.
RangeInfo layout.RangeInfo
// Data is the raw serialised bundle, as fetched from the log.
//
// For a tlog-tiles compliant log, this can be unmarshaled using api.EntryBundle.
Data []byte
}
Bundle represents an entry bundle in a log, along with some metadata about which parts of the bundle are relevent.
type CheckpointFetcherFunc ¶
CheckpointFetcherFunc is the signature of a function which can retrieve the latest checkpoint from a log's data storage.
Note that the implementation of this MUST return (either directly or wrapped) an os.ErrIsNotExist when the file referenced by path does not exist, e.g. a HTTP based implementation MUST return this error when it receives a 404 StatusCode.
type ConsensusCheckpointFunc ¶
type ConsensusCheckpointFunc func(ctx context.Context, logSigV note.Verifier, origin string) (*log.Checkpoint, []byte, *note.Note, error)
ConsensusCheckpointFunc is a function which returns the largest checkpoint known which is signed by logSigV and satisfies some consensus algorithm.
This is intended to provide a hook for adding a consensus view of a log, e.g. via witnessing.
func UnilateralConsensus ¶
func UnilateralConsensus(f CheckpointFetcherFunc) ConsensusCheckpointFunc
UnilateralConsensus blindly trusts the source log, returning the checkpoint it provided.
type Entry ¶ added in v1.0.0
type Entry[T any] struct { // Index is the index of the entry in the log. Index uint64 // Entry is the entry from the log. Entry T }
Entry represents a single leaf in a log.
type EntryBundleFetcherFunc ¶
EntryBundleFetcherFunc is the signature of a function which can fetch the raw data for a given entry bundle.
Note that the implementation of this MUST:
- when asked to fetch a partial entry bundle (i.e. p != 0), fall-back to fetching the corresponding full bundle if the partial one does not exist.
- return (either directly or wrapped) an os.ErrIsNotExist when neither the requested bundle nor any fallback bundle exists.
type ErrInconsistency ¶
ErrInconsistency should be returned when there has been an error proving consistency between log states. The raw log state representations are included as-returned by the target log, this ensures that evidence of inconsistent log updates are available to the caller of the method(s) returning this error.
func (ErrInconsistency) Error ¶
func (e ErrInconsistency) Error() string
func (ErrInconsistency) Unwrap ¶
func (e ErrInconsistency) Unwrap() error
type FileFetcher ¶
type FileFetcher struct {
Root string
}
FileFetcher knows how to fetch log artifacts from a filesystem rooted at Root.
func (FileFetcher) ReadCheckpoint ¶
func (f FileFetcher) ReadCheckpoint(_ context.Context) ([]byte, error)
func (FileFetcher) ReadEntryBundle ¶
type HTTPFetcher ¶
type HTTPFetcher struct {
// contains filtered or unexported fields
}
HTTPFetcher knows how to fetch log artifacts from a log being served via HTTP.
func NewHTTPFetcher ¶
NewHTTPFetcher creates a new HTTPFetcher for the log rooted at the given URL, using the provided HTTP client.
rootURL should end in a trailing slash. c may be nil, in which case http.DefaultClient will be used.
func (HTTPFetcher) ReadCheckpoint ¶
func (h HTTPFetcher) ReadCheckpoint(ctx context.Context) ([]byte, error)
func (HTTPFetcher) ReadEntryBundle ¶
func (*HTTPFetcher) SetAuthorizationHeader ¶
func (h *HTTPFetcher) SetAuthorizationHeader(v string)
SetAuthorizationHeader sets the value to be used with an Authorization: header for every request made by this fetcher.
type LogStateTracker ¶
type LogStateTracker struct {
// contains filtered or unexported fields
}
LogStateTracker represents a client-side view of a target log's state. This tracker handles verification that updates to the tracked log state are consistent with previously seen states.
func NewLogStateTracker ¶
func NewLogStateTracker(ctx context.Context, tF TileFetcherFunc, checkpointRaw []byte, nV note.Verifier, origin string, cc ConsensusCheckpointFunc) (*LogStateTracker, error)
NewLogStateTracker creates a newly initialised tracker. If a serialised LogState representation is provided then this is used as the initial tracked state, otherwise a log state is fetched from the target log.
func (*LogStateTracker) Latest ¶
func (lst *LogStateTracker) Latest() log.Checkpoint
func (*LogStateTracker) Update ¶
Update attempts to update the local view of the target log's state. If a more recent logstate is found, this method will attempt to prove that it is consistent with the local state before updating the tracker's view. Returns the old checkpoint, consistency proof, and newer checkpoint used to update. If the LatestConsistent checkpoint is 0 sized, no consistency proof will be returned since it would be meaningless to do so.
type ProofBuilder ¶
type ProofBuilder struct {
// contains filtered or unexported fields
}
ProofBuilder knows how to build inclusion and consistency proofs from tiles. Since the tiles commit only to immutable nodes, the job of building proofs is slightly more complex as proofs can touch "ephemeral" nodes, so these need to be synthesized. This object constructs a cache internally to make it efficient for multiple operations at a given tree size.
func NewProofBuilder ¶
func NewProofBuilder(ctx context.Context, treeSize uint64, f TileFetcherFunc) (*ProofBuilder, error)
NewProofBuilder creates a new ProofBuilder object for a given tree size. The returned ProofBuilder can be re-used for proofs related to a given tree size, but it is not thread-safe and should not be accessed concurrently.
func (*ProofBuilder) ConsistencyProof ¶
func (pb *ProofBuilder) ConsistencyProof(ctx context.Context, smaller, larger uint64) ([][]byte, error)
ConsistencyProof constructs a consistency proof between the provided tree sizes.
func (*ProofBuilder) InclusionProof ¶
InclusionProof constructs an inclusion proof for the leaf at index in a tree of the given size.
type TileFetcherFunc ¶
TileFetcherFunc is the signature of a function which can fetch the raw data for a given tile.
Note that the implementation of this MUST:
- when asked to fetch a partial tile (i.e. p != 0), fall-back to fetching the corresponding full tile if the partial one does not exist.
- return (either directly or wrapped) an os.ErrIsNotExist when neither the requested tile nor any fallback tile exists.