提交 193aebc4 作者: Juan Batiz-Benet

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.
上级 ac7404a6
...@@ -69,12 +69,13 @@ func initCmd(c *commander.Command, inp []string) error { ...@@ -69,12 +69,13 @@ func initCmd(c *commander.Command, inp []string) error {
cfg.Datastore.Path = dspath cfg.Datastore.Path = dspath
cfg.Datastore.Type = "leveldb" cfg.Datastore.Type = "leveldb"
cfg.Identity = new(config.Identity) cfg.Identity = config.Identity{}
// This needs thought
cfg.Identity.Address = "/ip4/127.0.0.1/tcp/5001"
// local RPC endpoint // setup the node addresses.
cfg.RPCAddress = "/ip4/127.0.0.1/tcp/4001" cfg.Addresses = config.Addresses{
Swarm: "/ip4/0.0.0.0/tcp/4001",
API: "/ip4/127.0.0.1/tcp/5001",
}
nbits, ok := c.Flag.Lookup("b").Value.Get().(int) nbits, ok := c.Flag.Lookup("b").Value.Get().(int)
if !ok { if !ok {
...@@ -105,8 +106,8 @@ func initCmd(c *commander.Command, inp []string) error { ...@@ -105,8 +106,8 @@ func initCmd(c *commander.Command, inp []string) error {
cfg.Identity.PeerID = id.Pretty() cfg.Identity.PeerID = id.Pretty()
// Use these hardcoded bootstrap peers for now. // Use these hardcoded bootstrap peers for now.
cfg.Peers = []*config.SavedPeer{ cfg.Peers = []*config.BootstrapPeer{
&config.SavedPeer{ &config.BootstrapPeer{
// mars.i.ipfs.io // mars.i.ipfs.io
PeerID: "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ", PeerID: "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
Address: "/ip4/104.131.131.82/tcp/4001", Address: "/ip4/104.131.131.82/tcp/4001",
......
...@@ -44,12 +44,12 @@ func mountCmd(c *commander.Command, inp []string) error { ...@@ -44,12 +44,12 @@ func mountCmd(c *commander.Command, inp []string) error {
return err return err
} }
// launch the RPC endpoint. // launch the API RPC endpoint.
if n.Config.RPCAddress == "" { if n.Config.Addresses.API == "" {
return errors.New("no config.RPCAddress endpoint supplied") return errors.New("no config.RPCAddress endpoint supplied")
} }
maddr, err := ma.NewMultiaddr(n.Config.RPCAddress) maddr, err := ma.NewMultiaddr(n.Config.Addresses.API)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
type Identity struct { type Identity struct {
PeerID string PeerID string
PrivKey string PrivKey string
Address string
} }
// Datastore tracks the configuration of the datastore. // Datastore tracks the configuration of the datastore.
...@@ -23,30 +22,33 @@ type Datastore struct { ...@@ -23,30 +22,33 @@ type Datastore struct {
Path string Path string
} }
type SavedPeer struct { // Addresses stores the (string) multiaddr addresses for the node.
type Addresses struct {
Swarm string // address for the swarm network
API string // address for the local API (RPC)
}
// BootstrapPeer is a peer used to bootstrap the network.
type BootstrapPeer struct {
Address string Address string
PeerID string // until multiaddr supports ipfs, use another field. PeerID string // until multiaddr supports ipfs, use another field.
} }
// Config is used to load IPFS config files. // Config is used to load IPFS config files.
type Config struct { type Config struct {
Identity *Identity // local node's peer identity Identity Identity // local node's peer identity
Datastore Datastore // local node's storage Datastore Datastore // local node's storage
RPCAddress string // local node's RPC address Addresses Addresses // local node's addresses
Peers []*SavedPeer // local nodes's bootstrap peers Peers []*BootstrapPeer // local nodes's bootstrap peers
} }
// DefaultPathRoot is the default parth for the IPFS node's root dir.
const DefaultPathRoot = "~/.go-ipfs" const DefaultPathRoot = "~/.go-ipfs"
// DefaultConfigFilePath points to the ipfs node config file.
const DefaultConfigFilePath = DefaultPathRoot + "/config" const DefaultConfigFilePath = DefaultPathRoot + "/config"
const DefaultConfigFile = `{
"identity": {},
"datastore": {
"type": "leveldb",
"path": "` + DefaultPathRoot + `/datastore"
}
}
`
// DecodePrivateKey is a helper to decode the users PrivateKey
func (i *Identity) DecodePrivateKey(passphrase string) (crypto.PrivateKey, error) { func (i *Identity) DecodePrivateKey(passphrase string) (crypto.PrivateKey, error) {
pkb, err := base64.StdEncoding.DecodeString(i.PrivKey) pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)
if err != nil { if err != nil {
......
...@@ -148,7 +148,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) { ...@@ -148,7 +148,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
} }
func initIdentity(cfg *config.Config) (*peer.Peer, error) { func initIdentity(cfg *config.Config) (*peer.Peer, error) {
if cfg.Identity == nil { if cfg.Identity.PeerID == "" {
return nil, errors.New("Identity was not set in config (was ipfs init run?)") return nil, errors.New("Identity was not set in config (was ipfs init run?)")
} }
...@@ -158,8 +158,8 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) { ...@@ -158,8 +158,8 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) {
// address is optional // address is optional
var addresses []*ma.Multiaddr var addresses []*ma.Multiaddr
if len(cfg.Identity.Address) > 0 { if len(cfg.Addresses.Swarm) > 0 {
maddr, err := ma.NewMultiaddr(cfg.Identity.Address) maddr, err := ma.NewMultiaddr(cfg.Addresses.Swarm)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论