@cryptotaxi247 / kubo / commits / 9c60623f1

go-ipfs-config: make datastore configuration nicely customizable

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> make things super customizable License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> better json format License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> Migrate to new flatfs License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jeromy committed Mar 15, 2016 at 13:46 UTC 9c60623f12f948f8175cf373ee28bbf5792a4355
2 files changed +48 -26
config/datastore.go
+19 -16
@@ -1,40 +1,43 @@
1 package config
2
3 -import (
4 - "encoding/json"
5 -)
6 -
3 // DefaultDataStoreDirectory is the directory to store all the local IPFS data.
4 const DefaultDataStoreDirectory = "datastore"
5
6 // Datastore tracks the configuration of the datastore.
7 type Datastore struct {
12 - Type string
13 - Path string
8 StorageMax string // in B, kB, kiB, MB, ...
9 StorageGCWatermark int64 // in percentage to multiply on StorageMax
10 GCPeriod string // in ns, us, ms, s, m, h
11 + Path string
12 + NoSync bool // deprecated
13 +
14 + Spec map[string]interface{}
15
18 - Params *json.RawMessage
19 - NoSync bool
16 HashOnRead bool
17 BloomFilterSize int
18 }
19
24 -func (d *Datastore) ParamData() []byte {
25 - if d.Params == nil {
26 - return nil
27 - }
28 -
29 - return []byte(*d.Params)
30 -}
31 -
20 type S3Datastore struct {
21 Region string `json:"region"`
22 Bucket string `json:"bucket"`
23 ACL string `json:"acl"`
24 }
25
26 +type FlatDS struct {
27 + Path string
28 + ShardFunc string
29 + Sync bool
30 +}
31 +
32 +type LevelDB struct {
33 + Path string
34 + Compression string
35 +}
36 +
37 +type SbsDS struct {
38 + Path string
39 +}
40 +
41 // DataStorePath returns the default data store path given a configuration root
42 // (set an empty string to have the default configuration root)
43 func DataStorePath(configroot string) (string, error) {
config/init.go
+29 -10
@@ -42,7 +42,7 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
42 Gateway: "/ip4/127.0.0.1/tcp/8080",
43 },
44
45 - Datastore: datastore,
45 + Datastore: *datastore,
46 Bootstrap: BootstrapPeerStrings(bootstrapPeers),
47 Identity: identity,
48 Discovery: Discovery{MDNS{
@@ -79,19 +79,38 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
79 return conf, nil
80 }
81
82 -func datastoreConfig() (Datastore, error) {
83 - dspath, err := DataStorePath("")
84 - if err != nil {
85 - return Datastore{}, err
86 - }
87 - return Datastore{
88 - Path: dspath,
89 - Type: "leveldb",
82 +func datastoreConfig() (*Datastore, error) {
83 + return &Datastore{
84 StorageMax: "10GB",
85 StorageGCWatermark: 90, // 90%
86 GCPeriod: "1h",
93 - HashOnRead: false,
87 BloomFilterSize: 0,
88 + Spec: map[string]interface{}{
89 + "type": "mount",
90 + "mounts": []interface{}{
91 + map[string]interface{}{
92 + "mountpoint": "/blocks",
93 + "type": "measure",
94 + "prefix": "flatfs.datastore",
95 + "child": map[string]interface{}{
96 + "type": "flatfs",
97 + "path": "blocks",
98 + "nosync": false,
99 + "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
100 + },
101 + },
102 + map[string]interface{}{
103 + "mountpoint": "/",
104 + "type": "measure",
105 + "prefix": "leveldb.datastore",
106 + "child": map[string]interface{}{
107 + "type": "levelds",
108 + "path": "datastore",
109 + "compression": "none",
110 + },
111 + },
112 + },
113 + },
114 }, nil
115 }
116