master
go 74 lines 2.2 KB
Raw
1 package repo
2
3 import (
4 "context"
5 "errors"
6 "io"
7 "net"
8
9 filestore "github.com/ipfs/boxo/filestore"
10 keystore "github.com/ipfs/boxo/keystore"
11 rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
12
13 ds "github.com/ipfs/go-datastore"
14 config "github.com/ipfs/kubo/config"
15 ma "github.com/multiformats/go-multiaddr"
16 )
17
18 var ErrApiNotRunning = errors.New("api not running") //nolint
19
20 // Repo represents all persistent data of a given ipfs node.
21 type Repo interface {
22 // Config returns the ipfs configuration file from the repo. Changes made
23 // to the returned config are not automatically persisted.
24 Config() (*config.Config, error)
25
26 // Path is the repo file-system path
27 Path() string
28
29 // UserResourceOverrides returns optional user resource overrides for the
30 // libp2p resource manager.
31 UserResourceOverrides() (rcmgr.PartialLimitConfig, error)
32
33 // BackupConfig creates a backup of the current configuration file using
34 // the given prefix for naming.
35 BackupConfig(prefix string) (string, error)
36
37 // SetConfig persists the given configuration struct to storage.
38 SetConfig(*config.Config) error
39
40 // SetConfigKey sets the given key-value pair within the config and persists it to storage.
41 SetConfigKey(key string, value any) error
42
43 // GetConfigKey reads the value for the given key from the configuration in storage.
44 GetConfigKey(key string) (any, error)
45
46 // Datastore returns a reference to the configured data storage backend.
47 Datastore() Datastore
48
49 // GetStorageUsage returns the number of bytes stored.
50 GetStorageUsage(context.Context) (uint64, error)
51
52 // Keystore returns a reference to the key management interface.
53 Keystore() keystore.Keystore
54
55 // FileManager returns a reference to the filestore file manager.
56 FileManager() *filestore.FileManager
57
58 // SetAPIAddr sets the API address in the repo.
59 SetAPIAddr(addr ma.Multiaddr) error
60
61 // SetGatewayAddr sets the Gateway address in the repo.
62 SetGatewayAddr(addr net.Addr) error
63
64 // SwarmKey returns the configured shared symmetric key for the private networks feature.
65 SwarmKey() ([]byte, error)
66
67 io.Closer
68 }
69
70 // Datastore is the interface required from a datastore to be
71 // acceptable to FSRepo.
72 type Datastore interface {
73 ds.Batching // must be thread-safe
74 }