-
Notifications
You must be signed in to change notification settings - Fork 18
/
kv.go
53 lines (42 loc) · 1.66 KB
/
kv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package authdb
import (
"context"
"time"
"github.com/zeebo/errs"
)
// Invalid is the class of error that is returned for invalid records.
var Invalid = errs.Class("invalid")
// Record is a key/value store record.
type Record struct {
SatelliteAddress string
MacaroonHead []byte // 32 bytes probably
EncryptedSecretKey []byte
EncryptedAccessGrant []byte
ExpiresAt *time.Time
Public bool // if true, knowledge of secret key is not required
}
// KeyHash is the key portion of the key/value store.
type KeyHash [32]byte
// KV is an abstract key/value store of KeyHash to Records.
type KV interface {
// Put stores the record in the key/value store.
// It is an error if the key already exists.
Put(ctx context.Context, keyHash KeyHash, record *Record) (err error)
// Get retrieves the record from the key/value store.
// It returns nil if the key does not exist.
// If the record is invalid, the error contains why.
Get(ctx context.Context, keyHash KeyHash) (record *Record, err error)
// DeleteUnused deletes expired and invalid records from the key/value store
// and returns any error encountered.
//
// Batch deletion and usage of asOfSystemInterval, selectSize and deleteSize
// parameters depends on the implementation.
DeleteUnused(ctx context.Context, asOfSystemInterval time.Duration, selectSize, deleteSize int) (count, rounds int64, deletesPerHead map[string]int64, err error)
// Ping attempts to do a DB roundtrip. If it can't it will return an
// error.
Ping(ctx context.Context) error
// Close closes the database.
Close() error
}