config: rename addresses
WARNING: change breaks old configs. @whyrusleeping @perfmode This commit changes the way addresses are stored in config files. It lumps Identity.Address and RPCAddress into Addresses. This commit also fixes several golint issues.
Juan Batiz-Benet committed
Sep 24, 2014 at 05:25 UTC
193aebc4c0fdd6328d21d229be98a93b7017cbab
4 files changed
+30
-27
cmd/ipfs/init.go
+8
-7
@@ -69,12 +69,13 @@ func initCmd(c *commander.Command, inp []string) error {
69
cfg.Datastore.Path = dspath
70
cfg.Datastore.Type = "leveldb"
71
72
- cfg.Identity = new(config.Identity)
73
- // This needs thought
74
- cfg.Identity.Address = "/ip4/127.0.0.1/tcp/5001"
72
+ cfg.Identity = config.Identity{}
73
76
- // local RPC endpoint
77
- cfg.RPCAddress = "/ip4/127.0.0.1/tcp/4001"
74
+ // setup the node addresses.
75
+ cfg.Addresses = config.Addresses{
76
+ Swarm: "/ip4/0.0.0.0/tcp/4001",
77
+ API: "/ip4/127.0.0.1/tcp/5001",
78
+ }
79
80
nbits, ok := c.Flag.Lookup("b").Value.Get().(int)
81
if !ok {
@@ -105,8 +106,8 @@ func initCmd(c *commander.Command, inp []string) error {
106
cfg.Identity.PeerID = id.Pretty()
107
108
// Use these hardcoded bootstrap peers for now.
108
- cfg.Peers = []*config.SavedPeer{
109
- &config.SavedPeer{
109
+ cfg.Peers = []*config.BootstrapPeer{
110
+ &config.BootstrapPeer{
111
// mars.i.ipfs.io
112
PeerID: "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
113
Address: "/ip4/104.131.131.82/tcp/4001",
cmd/ipfs/mount_unix.go
+3
-3
@@ -44,12 +44,12 @@ func mountCmd(c *commander.Command, inp []string) error {
44
return err
45
}
46
47
- // launch the RPC endpoint.
48
- if n.Config.RPCAddress == "" {
47
+ // launch the API RPC endpoint.
48
+ if n.Config.Addresses.API == "" {
49
return errors.New("no config.RPCAddress endpoint supplied")
50
}
51
52
- maddr, err := ma.NewMultiaddr(n.Config.RPCAddress)
52
+ maddr, err := ma.NewMultiaddr(n.Config.Addresses.API)
53
if err != nil {
54
return err
55
}
config/config.go
+16
-14
@@ -14,7 +14,6 @@ import (
14
type Identity struct {
15
PeerID string
16
PrivKey string
17
- Address string
17
}
18
19
// Datastore tracks the configuration of the datastore.
@@ -23,30 +22,33 @@ type Datastore struct {
22
Path string
23
}
24
26
-type SavedPeer struct {
25
+// Addresses stores the (string) multiaddr addresses for the node.
26
+type Addresses struct {
27
+ Swarm string // address for the swarm network
28
+ API string // address for the local API (RPC)
29
+}
30
+
31
+// BootstrapPeer is a peer used to bootstrap the network.
32
+type BootstrapPeer struct {
33
Address string
34
PeerID string // until multiaddr supports ipfs, use another field.
35
}
36
37
// Config is used to load IPFS config files.
38
type Config struct {
33
- Identity *Identity // local node's peer identity
34
- Datastore Datastore // local node's storage
35
- RPCAddress string // local node's RPC address
36
- Peers []*SavedPeer // local nodes's bootstrap peers
39
+ Identity Identity // local node's peer identity
40
+ Datastore Datastore // local node's storage
41
+ Addresses Addresses // local node's addresses
42
+ Peers []*BootstrapPeer // local nodes's bootstrap peers
43
}
44
45
+// DefaultPathRoot is the default parth for the IPFS node's root dir.
46
const DefaultPathRoot = "~/.go-ipfs"
47
+
48
+// DefaultConfigFilePath points to the ipfs node config file.
49
const DefaultConfigFilePath = DefaultPathRoot + "/config"
41
-const DefaultConfigFile = `{
42
- "identity": {},
43
- "datastore": {
44
- "type": "leveldb",
45
- "path": "` + DefaultPathRoot + `/datastore"
46
- }
47
-}
48
-`
50
51
+// DecodePrivateKey is a helper to decode the users PrivateKey
52
func (i *Identity) DecodePrivateKey(passphrase string) (crypto.PrivateKey, error) {
53
pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)
54
if err != nil {
core/core.go
+3
-3
@@ -148,7 +148,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
148
}
149
150
func initIdentity(cfg *config.Config) (*peer.Peer, error) {
151
- if cfg.Identity == nil {
151
+ if cfg.Identity.PeerID == "" {
152
return nil, errors.New("Identity was not set in config (was ipfs init run?)")
153
}
154
@@ -158,8 +158,8 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) {
158
159
// address is optional
160
var addresses []*ma.Multiaddr
161
- if len(cfg.Identity.Address) > 0 {
162
- maddr, err := ma.NewMultiaddr(cfg.Identity.Address)
161
+ if len(cfg.Addresses.Swarm) > 0 {
162
+ maddr, err := ma.NewMultiaddr(cfg.Addresses.Swarm)
163
if err != nil {
164
return nil, err
165
}