@cryptotaxi247 / kubo / commits / 0d48dda98

Extract repo/config

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jul 22, 2018 at 21:35 UTC 0d48dda98d0d3e78ff3169c7b05dc7131a916b20
19 files changed -848
repo/config/addresses.go deleted
-10
@@ -1,10 +0,0 @@
1 -package config
2 -
3 -// Addresses stores the (string) multiaddr addresses for the node.
4 -type Addresses struct {
5 - Swarm []string // addresses for the swarm to listen on
6 - Announce []string // swarm addresses to announce to the network
7 - NoAnnounce []string // swarm addresses not to announce to the network
8 - API string // address for the local API (RPC)
9 - Gateway string // address to listen on for IPFS HTTP object gateway
10 -}
repo/config/api.go deleted
-5
@@ -1,5 +0,0 @@
1 -package config
2 -
3 -type API struct {
4 - HTTPHeaders map[string][]string // HTTP headers to return with the API.
5 -}
repo/config/bootstrap_peers.go deleted
-87
@@ -1,87 +0,0 @@
1 -package config
2 -
3 -import (
4 - "errors"
5 - "fmt"
6 -
7 - iaddr "gx/ipfs/QmNysBQN8FUSE2TKUYRFiMrn7Fiqk5RPeCz33cKaLa6syn/go-ipfs-addr"
8 - // Needs to be imported so that users can import this package directly
9 - // and still parse the bootstrap addresses.
10 - _ "gx/ipfs/QmfXU2MhWoegxHoeMd3A2ytL2P6CY4FfqGWc23LTNWBwZt/go-multiaddr-dns"
11 -)
12 -
13 -// DefaultBootstrapAddresses are the hardcoded bootstrap addresses
14 -// for IPFS. they are nodes run by the IPFS team. docs on these later.
15 -// As with all p2p networks, bootstrap is an important security concern.
16 -//
17 -// NOTE: This is here -- and not inside cmd/ipfs/init.go -- because of an
18 -// import dependency issue. TODO: move this into a config/default/ package.
19 -var DefaultBootstrapAddresses = []string{
20 - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
21 - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
22 - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
23 - "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
24 - "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", // mars.i.ipfs.io
25 - "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", // pluto.i.ipfs.io
26 - "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn.i.ipfs.io
27 - "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus.i.ipfs.io
28 - "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth.i.ipfs.io
29 - "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM", // pluto.i.ipfs.io
30 - "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu", // saturn.i.ipfs.io
31 - "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64", // venus.i.ipfs.io
32 - "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd", // earth.i.ipfs.io
33 -}
34 -
35 -// BootstrapPeer is a peer used to bootstrap the network.
36 -type BootstrapPeer iaddr.IPFSAddr
37 -
38 -// ErrInvalidPeerAddr signals an address is not a valid peer address.
39 -var ErrInvalidPeerAddr = errors.New("invalid peer address")
40 -
41 -func (c *Config) BootstrapPeers() ([]BootstrapPeer, error) {
42 - return ParseBootstrapPeers(c.Bootstrap)
43 -}
44 -
45 -// DefaultBootstrapPeers returns the (parsed) set of default bootstrap peers.
46 -// if it fails, it returns a meaningful error for the user.
47 -// This is here (and not inside cmd/ipfs/init) because of module dependency problems.
48 -func DefaultBootstrapPeers() ([]BootstrapPeer, error) {
49 - ps, err := ParseBootstrapPeers(DefaultBootstrapAddresses)
50 - if err != nil {
51 - return nil, fmt.Errorf(`failed to parse hardcoded bootstrap peers: %s
52 -This is a problem with the ipfs codebase. Please report it to the dev team.`, err)
53 - }
54 - return ps, nil
55 -}
56 -
57 -func (c *Config) SetBootstrapPeers(bps []BootstrapPeer) {
58 - c.Bootstrap = BootstrapPeerStrings(bps)
59 -}
60 -
61 -func ParseBootstrapPeer(addr string) (BootstrapPeer, error) {
62 - ia, err := iaddr.ParseString(addr)
63 - if err != nil {
64 - return nil, err
65 - }
66 - return BootstrapPeer(ia), err
67 -}
68 -
69 -func ParseBootstrapPeers(addrs []string) ([]BootstrapPeer, error) {
70 - peers := make([]BootstrapPeer, len(addrs))
71 - var err error
72 - for i, addr := range addrs {
73 - peers[i], err = ParseBootstrapPeer(addr)
74 - if err != nil {
75 - return nil, err
76 - }
77 - }
78 - return peers, nil
79 -}
80 -
81 -func BootstrapPeerStrings(bps []BootstrapPeer) []string {
82 - bpss := make([]string, len(bps))
83 - for i, p := range bps {
84 - bpss[i] = p.String()
85 - }
86 - return bpss
87 -}
repo/config/config.go deleted
-111
@@ -1,111 +0,0 @@
1 -// package config implements the ipfs config file datastructures and utilities.
2 -package config
3 -
4 -import (
5 - "bytes"
6 - "encoding/json"
7 - "fmt"
8 - "os"
9 - "path/filepath"
10 - "strings"
11 -
12 - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"
13 -)
14 -
15 -// Config is used to load ipfs config files.
16 -type Config struct {
17 - Identity Identity // local node's peer identity
18 - Datastore Datastore // local node's storage
19 - Addresses Addresses // local node's addresses
20 - Mounts Mounts // local node's mount points
21 - Discovery Discovery // local node's discovery mechanisms
22 - Routing Routing // local node's routing settings
23 - Ipns Ipns // Ipns settings
24 - Bootstrap []string // local nodes's bootstrap peer addresses
25 - Gateway Gateway // local node's gateway server options
26 - API API // local node's API settings
27 - Swarm SwarmConfig
28 -
29 - Reprovider Reprovider
30 - Experimental Experiments
31 -}
32 -
33 -const (
34 - // DefaultPathName is the default config dir name
35 - DefaultPathName = ".ipfs"
36 - // DefaultPathRoot is the path to the default config dir location.
37 - DefaultPathRoot = "~/" + DefaultPathName
38 - // DefaultConfigFile is the filename of the configuration file
39 - DefaultConfigFile = "config"
40 - // EnvDir is the environment variable used to change the path root.
41 - EnvDir = "IPFS_PATH"
42 -)
43 -
44 -// PathRoot returns the default configuration root directory
45 -func PathRoot() (string, error) {
46 - dir := os.Getenv(EnvDir)
47 - var err error
48 - if len(dir) == 0 {
49 - dir, err = homedir.Expand(DefaultPathRoot)
50 - }
51 - return dir, err
52 -}
53 -
54 -// Path returns the path `extension` relative to the configuration root. If an
55 -// empty string is provided for `configroot`, the default root is used.
56 -func Path(configroot, extension string) (string, error) {
57 - if len(configroot) == 0 {
58 - dir, err := PathRoot()
59 - if err != nil {
60 - return "", err
61 - }
62 - return filepath.Join(dir, extension), nil
63 -
64 - }
65 - return filepath.Join(configroot, extension), nil
66 -}
67 -
68 -// Filename returns the configuration file path given a configuration root
69 -// directory. If the configuration root directory is empty, use the default one
70 -func Filename(configroot string) (string, error) {
71 - return Path(configroot, DefaultConfigFile)
72 -}
73 -
74 -// HumanOutput gets a config value ready for printing
75 -func HumanOutput(value interface{}) ([]byte, error) {
76 - s, ok := value.(string)
77 - if ok {
78 - return []byte(strings.Trim(s, "\n")), nil
79 - }
80 - return Marshal(value)
81 -}
82 -
83 -// Marshal configuration with JSON
84 -func Marshal(value interface{}) ([]byte, error) {
85 - // need to prettyprint, hence MarshalIndent, instead of Encoder
86 - return json.MarshalIndent(value, "", " ")
87 -}
88 -
89 -func FromMap(v map[string]interface{}) (*Config, error) {
90 - buf := new(bytes.Buffer)
91 - if err := json.NewEncoder(buf).Encode(v); err != nil {
92 - return nil, err
93 - }
94 - var conf Config
95 - if err := json.NewDecoder(buf).Decode(&conf); err != nil {
96 - return nil, fmt.Errorf("failure to decode config: %s", err)
97 - }
98 - return &conf, nil
99 -}
100 -
101 -func ToMap(conf *Config) (map[string]interface{}, error) {
102 - buf := new(bytes.Buffer)
103 - if err := json.NewEncoder(buf).Encode(conf); err != nil {
104 - return nil, err
105 - }
106 - var m map[string]interface{}
107 - if err := json.NewDecoder(buf).Decode(&m); err != nil {
108 - return nil, fmt.Errorf("failure to decode config: %s", err)
109 - }
110 - return m, nil
111 -}
repo/config/datastore.go deleted
-32
@@ -1,32 +0,0 @@
1 -package config
2 -
3 -import (
4 - "encoding/json"
5 -)
6 -
7 -// DefaultDataStoreDirectory is the directory to store all the local IPFS data.
8 -const DefaultDataStoreDirectory = "datastore"
9 -
10 -// Datastore tracks the configuration of the datastore.
11 -type Datastore struct {
12 - StorageMax string // in B, kB, kiB, MB, ...
13 - StorageGCWatermark int64 // in percentage to multiply on StorageMax
14 - GCPeriod string // in ns, us, ms, s, m, h
15 -
16 - // deprecated fields, use Spec
17 - Type string `json:",omitempty"`
18 - Path string `json:",omitempty"`
19 - NoSync bool `json:",omitempty"`
20 - Params *json.RawMessage `json:",omitempty"`
21 -
22 - Spec map[string]interface{}
23 -
24 - HashOnRead bool
25 - BloomFilterSize int
26 -}
27 -
28 -// DataStorePath returns the default data store path given a configuration root
29 -// (set an empty string to have the default configuration root)
30 -func DataStorePath(configroot string) (string, error) {
31 - return Path(configroot, DefaultDataStoreDirectory)
32 -}
repo/config/discovery.go deleted
-12
@@ -1,12 +0,0 @@
1 -package config
2 -
3 -type Discovery struct {
4 - MDNS MDNS
5 -}
6 -
7 -type MDNS struct {
8 - Enabled bool
9 -
10 - // Time in seconds between discovery rounds
11 - Interval int
12 -}
repo/config/experiments.go deleted
-8
@@ -1,8 +0,0 @@
1 -package config
2 -
3 -type Experiments struct {
4 - FilestoreEnabled bool
5 - UrlstoreEnabled bool
6 - ShardingEnabled bool
7 - Libp2pStreamMounting bool
8 -}
repo/config/gateway.go deleted
-9
@@ -1,9 +0,0 @@
1 -package config
2 -
3 -// Gateway contains options for the HTTP gateway server.
4 -type Gateway struct {
5 - HTTPHeaders map[string][]string // HTTP headers to return with the gateway
6 - RootRedirect string
7 - Writable bool
8 - PathPrefixes []string
9 -}
repo/config/identity.go deleted
-29
@@ -1,29 +0,0 @@
1 -package config
2 -
3 -import (
4 - "encoding/base64"
5 -
6 - ic "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
7 -)
8 -
9 -const IdentityTag = "Identity"
10 -const PrivKeyTag = "PrivKey"
11 -const PrivKeySelector = IdentityTag + "." + PrivKeyTag
12 -
13 -// Identity tracks the configuration of the local node's identity.
14 -type Identity struct {
15 - PeerID string
16 - PrivKey string `json:",omitempty"`
17 -}
18 -
19 -// DecodePrivateKey is a helper to decode the users PrivateKey
20 -func (i *Identity) DecodePrivateKey(passphrase string) (ic.PrivKey, error) {
21 - pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)
22 - if err != nil {
23 - return nil, err
24 - }
25 -
26 - // currently storing key unencrypted. in the future we need to encrypt it.
27 - // TODO(security)
28 - return ic.UnmarshalPrivateKey(pkb)
29 -}
repo/config/init.go deleted
-181
@@ -1,181 +0,0 @@
1 -package config
2 -
3 -import (
4 - "encoding/base64"
5 - "errors"
6 - "fmt"
7 - "io"
8 - "time"
9 -
10 - ci "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
11 - peer "gx/ipfs/QmcZSzKEM5yDfpZbeEEZaVmaZ1zXm6JWTbrQZSB8hCVPzk/go-libp2p-peer"
12 -)
13 -
14 -func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
15 - identity, err := identityConfig(out, nBitsForKeypair)
16 - if err != nil {
17 - return nil, err
18 - }
19 -
20 - bootstrapPeers, err := DefaultBootstrapPeers()
21 - if err != nil {
22 - return nil, err
23 - }
24 -
25 - datastore := DefaultDatastoreConfig()
26 -
27 - conf := &Config{
28 - API: API{
29 - HTTPHeaders: map[string][]string{
30 - "Server": {"go-ipfs/" + CurrentVersionNumber},
31 - },
32 - },
33 -
34 - // setup the node's default addresses.
35 - // NOTE: two swarm listen addrs, one tcp, one utp.
36 - Addresses: addressesConfig(),
37 -
38 - Datastore: datastore,
39 - Bootstrap: BootstrapPeerStrings(bootstrapPeers),
40 - Identity: identity,
41 - Discovery: Discovery{
42 - MDNS: MDNS{
43 - Enabled: true,
44 - Interval: 10,
45 - },
46 - },
47 -
48 - Routing: Routing{
49 - Type: "dht",
50 - },
51 -
52 - // setup the node mount points.
53 - Mounts: Mounts{
54 - IPFS: "/ipfs",
55 - IPNS: "/ipns",
56 - },
57 -
58 - Ipns: Ipns{
59 - ResolveCacheSize: 128,
60 - },
61 -
62 - Gateway: Gateway{
63 - RootRedirect: "",
64 - Writable: false,
65 - PathPrefixes: []string{},
66 - HTTPHeaders: map[string][]string{
67 - "Access-Control-Allow-Origin": []string{"*"},
68 - "Access-Control-Allow-Methods": []string{"GET"},
69 - "Access-Control-Allow-Headers": []string{"X-Requested-With", "Range"},
70 - },
71 - },
72 - Reprovider: Reprovider{
73 - Interval: "12h",
74 - Strategy: "all",
75 - },
76 - Swarm: SwarmConfig{
77 - ConnMgr: ConnMgr{
78 - LowWater: DefaultConnMgrLowWater,
79 - HighWater: DefaultConnMgrHighWater,
80 - GracePeriod: DefaultConnMgrGracePeriod.String(),
81 - Type: "basic",
82 - },
83 - },
84 - }
85 -
86 - return conf, nil
87 -}
88 -
89 -// DefaultConnMgrHighWater is the default value for the connection managers
90 -// 'high water' mark
91 -const DefaultConnMgrHighWater = 900
92 -
93 -// DefaultConnMgrLowWater is the default value for the connection managers 'low
94 -// water' mark
95 -const DefaultConnMgrLowWater = 600
96 -
97 -// DefaultConnMgrGracePeriod is the default value for the connection managers
98 -// grace period
99 -const DefaultConnMgrGracePeriod = time.Second * 20
100 -
101 -func addressesConfig() Addresses {
102 - return Addresses{
103 - Swarm: []string{
104 - "/ip4/0.0.0.0/tcp/4001",
105 - // "/ip4/0.0.0.0/udp/4002/utp", // disabled for now.
106 - "/ip6/::/tcp/4001",
107 - },
108 - Announce: []string{},
109 - NoAnnounce: []string{},
110 - API: "/ip4/127.0.0.1/tcp/5001",
111 - Gateway: "/ip4/127.0.0.1/tcp/8080",
112 - }
113 -}
114 -
115 -// DefaultDatastoreConfig is an internal function exported to aid in testing.
116 -func DefaultDatastoreConfig() Datastore {
117 - return Datastore{
118 - StorageMax: "10GB",
119 - StorageGCWatermark: 90, // 90%
120 - GCPeriod: "1h",
121 - BloomFilterSize: 0,
122 - Spec: map[string]interface{}{
123 - "type": "mount",
124 - "mounts": []interface{}{
125 - map[string]interface{}{
126 - "mountpoint": "/blocks",
127 - "type": "measure",
128 - "prefix": "flatfs.datastore",
129 - "child": map[string]interface{}{
130 - "type": "flatfs",
131 - "path": "blocks",
132 - "sync": true,
133 - "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
134 - },
135 - },
136 - map[string]interface{}{
137 - "mountpoint": "/",
138 - "type": "measure",
139 - "prefix": "leveldb.datastore",
140 - "child": map[string]interface{}{
141 - "type": "levelds",
142 - "path": "datastore",
143 - "compression": "none",
144 - },
145 - },
146 - },
147 - },
148 - }
149 -}
150 -
151 -// identityConfig initializes a new identity.
152 -func identityConfig(out io.Writer, nbits int) (Identity, error) {
153 - // TODO guard higher up
154 - ident := Identity{}
155 - if nbits < 1024 {
156 - return ident, errors.New("bitsize less than 1024 is considered unsafe")
157 - }
158 -
159 - fmt.Fprintf(out, "generating %v-bit RSA keypair...", nbits)
160 - sk, pk, err := ci.GenerateKeyPair(ci.RSA, nbits)
161 - if err != nil {
162 - return ident, err
163 - }
164 - fmt.Fprintf(out, "done\n")
165 -
166 - // currently storing key unencrypted. in the future we need to encrypt it.
167 - // TODO(security)
168 - skbytes, err := sk.Bytes()
169 - if err != nil {
170 - return ident, err
171 - }
172 - ident.PrivKey = base64.StdEncoding.EncodeToString(skbytes)
173 -
174 - id, err := peer.IDFromPublicKey(pk)
175 - if err != nil {
176 - return ident, err
177 - }
178 - ident.PeerID = id.Pretty()
179 - fmt.Fprintf(out, "peer identity: %s\n", ident.PeerID)
180 - return ident, nil
181 -}
repo/config/ipns.go deleted
-8
@@ -1,8 +0,0 @@
1 -package config
2 -
3 -type Ipns struct {
4 - RepublishPeriod string
5 - RecordLifetime string
6 -
7 - ResolveCacheSize int
8 -}
repo/config/mounts.go deleted
-8
@@ -1,8 +0,0 @@
1 -package config
2 -
3 -// Mounts stores the (string) mount points
4 -type Mounts struct {
5 - IPFS string
6 - IPNS string
7 - FuseAllowOther bool
8 -}
repo/config/profile.go deleted
-199
@@ -1,199 +0,0 @@
1 -package config
2 -
3 -import "time"
4 -
5 -// Transformer is a function which takes configuration and applies some filter to it
6 -type Transformer func(c *Config) error
7 -
8 -// Profile contains the profile transformer the description of the profile
9 -type Profile struct {
10 - // Description briefly describes the functionality of the profile
11 - Description string
12 -
13 - // Transform takes ipfs configuration and applies the profile to it
14 - Transform Transformer
15 -}
16 -
17 -// defaultServerFilters has a list of non-routable IPv4 prefixes
18 -// according to http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
19 -var defaultServerFilters = []string{
20 - "/ip4/10.0.0.0/ipcidr/8",
21 - "/ip4/100.64.0.0/ipcidr/10",
22 - "/ip4/169.254.0.0/ipcidr/16",
23 - "/ip4/172.16.0.0/ipcidr/12",
24 - "/ip4/192.0.0.0/ipcidr/24",
25 - "/ip4/192.0.0.0/ipcidr/29",
26 - "/ip4/192.0.0.8/ipcidr/32",
27 - "/ip4/192.0.0.170/ipcidr/32",
28 - "/ip4/192.0.0.171/ipcidr/32",
29 - "/ip4/192.0.2.0/ipcidr/24",
30 - "/ip4/192.168.0.0/ipcidr/16",
31 - "/ip4/198.18.0.0/ipcidr/15",
32 - "/ip4/198.51.100.0/ipcidr/24",
33 - "/ip4/203.0.113.0/ipcidr/24",
34 - "/ip4/240.0.0.0/ipcidr/4",
35 -}
36 -
37 -// Profiles is a map holding configuration transformers. Docs are in docs/config.md
38 -var Profiles = map[string]Profile{
39 - "server": {
40 - Description: `Disables local host discovery, recommended when
41 -running IPFS on machines with public IPv4 addresses.`,
42 -
43 - Transform: func(c *Config) error {
44 - c.Addresses.NoAnnounce = appendSingle(c.Addresses.NoAnnounce, defaultServerFilters)
45 - c.Swarm.AddrFilters = appendSingle(c.Swarm.AddrFilters, defaultServerFilters)
46 - c.Discovery.MDNS.Enabled = false
47 - c.Swarm.DisableNatPortMap = true
48 - return nil
49 - },
50 - },
51 -
52 - "local-discovery": {
53 - Description: `Sets default values to fields affected by the server
54 -profile, enables discovery in local networks.`,
55 -
56 - Transform: func(c *Config) error {
57 - c.Addresses.NoAnnounce = deleteEntries(c.Addresses.NoAnnounce, defaultServerFilters)
58 - c.Swarm.AddrFilters = deleteEntries(c.Swarm.AddrFilters, defaultServerFilters)
59 - c.Discovery.MDNS.Enabled = true
60 - c.Swarm.DisableNatPortMap = false
61 - return nil
62 - },
63 - },
64 - "test": {
65 - Description: `Reduces external interference of IPFS daemon, this
66 -is useful when using the daemon in test environments.`,
67 -
68 - Transform: func(c *Config) error {
69 - c.Addresses.API = "/ip4/127.0.0.1/tcp/0"
70 - c.Addresses.Gateway = "/ip4/127.0.0.1/tcp/0"
71 - c.Addresses.Swarm = []string{
72 - "/ip4/127.0.0.1/tcp/0",
73 - }
74 -
75 - c.Swarm.DisableNatPortMap = true
76 -
77 - c.Bootstrap = []string{}
78 - c.Discovery.MDNS.Enabled = false
79 - return nil
80 - },
81 - },
82 - "default-networking": {
83 - Description: `Restores default network settings.
84 -Inverse profile of the test profile.`,
85 -
86 - Transform: func(c *Config) error {
87 - c.Addresses = addressesConfig()
88 -
89 - bootstrapPeers, err := DefaultBootstrapPeers()
90 - if err != nil {
91 - return err
92 - }
93 - c.Bootstrap = appendSingle(c.Bootstrap, BootstrapPeerStrings(bootstrapPeers))
94 -
95 - c.Swarm.DisableNatPortMap = false
96 - c.Discovery.MDNS.Enabled = true
97 - return nil
98 - },
99 - },
100 - "badgerds": {
101 - Description: `Replaces default datastore configuration with experimental
102 -badger datastore.
103 -
104 -If you apply this profile after ipfs init, you will need
105 -to convert your datastore to the new configuration.
106 -You can do this using ipfs-ds-convert.
107 -
108 -For more on ipfs-ds-convert see
109 -$ ipfs-ds-convert --help
110 -and
111 -$ ipfs-ds-convert convert --help
112 -
113 -WARNING: badger datastore is experimental.
114 -Make sure to backup your data frequently.`,
115 -
116 - Transform: func(c *Config) error {
117 - c.Datastore.Spec = map[string]interface{}{
118 - "type": "measure",
119 - "prefix": "badger.datastore",
120 - "child": map[string]interface{}{
121 - "type": "badgerds",
122 - "path": "badgerds",
123 - "syncWrites": true,
124 - },
125 - }
126 - return nil
127 - },
128 - },
129 - "default-datastore": {
130 - Description: `Restores default datastore configuration.
131 -
132 -If you apply this profile after ipfs init, you will need
133 -to convert your datastore to the new configuration.
134 -You can do this using ipfs-ds-convert.
135 -
136 -For more on ipfs-ds-convert see
137 -$ ipfs-ds-convert --help
138 -and
139 -$ ipfs-ds-convert convert --help
140 -`,
141 -
142 - Transform: func(c *Config) error {
143 - c.Datastore.Spec = DefaultDatastoreConfig().Spec
144 - return nil
145 - },
146 - },
147 - "lowpower": {
148 - Description: `Reduces daemon overhead on the system. May affect node
149 -functionality - performance of content discovery and data
150 -fetching may be degraded.
151 -`,
152 - Transform: func(c *Config) error {
153 - c.Routing.Type = "dhtclient"
154 - c.Reprovider.Interval = "0"
155 -
156 - c.Swarm.ConnMgr.LowWater = 20
157 - c.Swarm.ConnMgr.HighWater = 40
158 - c.Swarm.ConnMgr.GracePeriod = time.Minute.String()
159 - return nil
160 - },
161 - },
162 -}
163 -
164 -func appendSingle(a []string, b []string) []string {
165 - out := make([]string, 0, len(a)+len(b))
166 - m := map[string]bool{}
167 - for _, f := range a {
168 - if !m[f] {
169 - out = append(out, f)
170 - }
171 - m[f] = true
172 - }
173 - for _, f := range b {
174 - if !m[f] {
175 - out = append(out, f)
176 - }
177 - m[f] = true
178 - }
179 - return out
180 -}
181 -
182 -func deleteEntries(arr []string, del []string) []string {
183 - m := map[string]struct{}{}
184 - for _, f := range arr {
185 - m[f] = struct{}{}
186 - }
187 - for _, f := range del {
188 - delete(m, f)
189 - }
190 - return mapKeys(m)
191 -}
192 -
193 -func mapKeys(m map[string]struct{}) []string {
194 - out := make([]string, 0, len(m))
195 - for f := range m {
196 - out = append(out, f)
197 - }
198 - return out
199 -}
repo/config/reprovider.go deleted
-6
@@ -1,6 +0,0 @@
1 -package config
2 -
3 -type Reprovider struct {
4 - Interval string // Time period to reprovide locally stored objects to the network
5 - Strategy string // Which keys to announce
6 -}
repo/config/routing.go deleted
-7
@@ -1,7 +0,0 @@
1 -package config
2 -
3 -// Routing defines configuration options for libp2p routing
4 -type Routing struct {
5 - // Type sets default daemon routing mode.
6 - Type string
7 -}
repo/config/serialize/serialize.go deleted
-71
@@ -1,71 +0,0 @@
1 -package fsrepo
2 -
3 -import (
4 - "encoding/json"
5 - "errors"
6 - "fmt"
7 - "io"
8 - "os"
9 - "path/filepath"
10 -
11 - "github.com/ipfs/go-ipfs/repo/config"
12 -
13 - "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
14 - "gx/ipfs/QmdYwCmx8pZRkzdcd8MhmLJqYVoVTC1aGsy5Q4reMGLNLg/atomicfile"
15 -)
16 -
17 -// ReadConfigFile reads the config from `filename` into `cfg`.
18 -func ReadConfigFile(filename string, cfg interface{}) error {
19 - f, err := os.Open(filename)
20 - if err != nil {
21 - return err
22 - }
23 - defer f.Close()
24 - if err := json.NewDecoder(f).Decode(cfg); err != nil {
25 - return fmt.Errorf("failure to decode config: %s", err)
26 - }
27 - return nil
28 -}
29 -
30 -// WriteConfigFile writes the config from `cfg` into `filename`.
31 -func WriteConfigFile(filename string, cfg interface{}) error {
32 - err := os.MkdirAll(filepath.Dir(filename), 0775)
33 - if err != nil {
34 - return err
35 - }
36 -
37 - f, err := atomicfile.New(filename, 0660)
38 - if err != nil {
39 - return err
40 - }
41 - defer f.Close()
42 -
43 - return encode(f, cfg)
44 -}
45 -
46 -// encode configuration with JSON
47 -func encode(w io.Writer, value interface{}) error {
48 - // need to prettyprint, hence MarshalIndent, instead of Encoder
49 - buf, err := config.Marshal(value)
50 - if err != nil {
51 - return err
52 - }
53 - _, err = w.Write(buf)
54 - return err
55 -}
56 -
57 -// Load reads given file and returns the read config, or error.
58 -func Load(filename string) (*config.Config, error) {
59 - // if nothing is there, fail. User must run 'ipfs init'
60 - if !util.FileExists(filename) {
61 - return nil, errors.New("ipfs not initialized, please run 'ipfs init'")
62 - }
63 -
64 - var cfg config.Config
65 - err := ReadConfigFile(filename, &cfg)
66 - if err != nil {
67 - return nil, err
68 - }
69 -
70 - return &cfg, err
71 -}
repo/config/serialize/serialize_test.go deleted
-37
@@ -1,37 +0,0 @@
1 -package fsrepo
2 -
3 -import (
4 - "os"
5 - "runtime"
6 - "testing"
7 -
8 - config "github.com/ipfs/go-ipfs/repo/config"
9 -)
10 -
11 -func TestConfig(t *testing.T) {
12 - const filename = ".ipfsconfig"
13 - cfgWritten := new(config.Config)
14 - cfgWritten.Identity.PeerID = "faketest"
15 -
16 - err := WriteConfigFile(filename, cfgWritten)
17 - if err != nil {
18 - t.Fatal(err)
19 - }
20 - cfgRead, err := Load(filename)
21 - if err != nil {
22 - t.Fatal(err)
23 - }
24 - if cfgWritten.Identity.PeerID != cfgRead.Identity.PeerID {
25 - t.Fatal()
26 - }
27 - st, err := os.Stat(filename)
28 - if err != nil {
29 - t.Fatalf("cannot stat config file: %v", err)
30 - }
31 -
32 - if runtime.GOOS != "windows" { // see https://golang.org/src/os/types_windows.go
33 - if g := st.Mode().Perm(); g&0117 != 0 {
34 - t.Fatalf("config file should not be executable or accessible to world: %v", g)
35 - }
36 - }
37 -}
repo/config/swarm.go deleted
-19
@@ -1,19 +0,0 @@
1 -package config
2 -
3 -type SwarmConfig struct {
4 - AddrFilters []string
5 - DisableBandwidthMetrics bool
6 - DisableNatPortMap bool
7 - DisableRelay bool
8 - EnableRelayHop bool
9 -
10 - ConnMgr ConnMgr
11 -}
12 -
13 -// ConnMgr defines configuration options for the libp2p connection manager
14 -type ConnMgr struct {
15 - Type string
16 - LowWater int
17 - HighWater int
18 - GracePeriod string
19 -}
repo/config/version.go deleted
-9
@@ -1,9 +0,0 @@
1 -package config
2 -
3 -// CurrentCommit is the current git commit, this is set as a ldflag in the Makefile
4 -var CurrentCommit string
5 -
6 -// CurrentVersionNumber is the current application's version literal
7 -const CurrentVersionNumber = "0.4.18-dev"
8 -
9 -const ApiVersion = "/go-ipfs/" + CurrentVersionNumber + "/"