Commit 80a927f2 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

Merge pull request #121 from jbenet/feat/addrs-in-config

config: rename addresses
parents 671b0956 303ebd89
......@@ -69,12 +69,13 @@ func initCmd(c *commander.Command, inp []string) error {
cfg.Datastore.Path = dspath
cfg.Datastore.Type = "leveldb"
cfg.Identity = new(config.Identity)
// This needs thought
cfg.Identity.Address = "/ip4/127.0.0.1/tcp/5001"
cfg.Identity = config.Identity{}
// local RPC endpoint
cfg.RPCAddress = "/ip4/127.0.0.1/tcp/4001"
// setup the node addresses.
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)
if !ok {
......@@ -105,8 +106,8 @@ func initCmd(c *commander.Command, inp []string) error {
cfg.Identity.PeerID = id.Pretty()
// Use these hardcoded bootstrap peers for now.
cfg.Peers = []*config.SavedPeer{
&config.SavedPeer{
cfg.Bootstrap = []*config.BootstrapPeer{
&config.BootstrapPeer{
// mars.i.ipfs.io
PeerID: "QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
Address: "/ip4/104.131.131.82/tcp/4001",
......
......@@ -44,12 +44,12 @@ func mountCmd(c *commander.Command, inp []string) error {
return err
}
// launch the RPC endpoint.
if n.Config.RPCAddress == "" {
// launch the API RPC endpoint.
if n.Config.Addresses.API == "" {
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 {
return err
}
......
......@@ -14,7 +14,6 @@ import (
type Identity struct {
PeerID string
PrivKey string
Address string
}
// Datastore tracks the configuration of the datastore.
......@@ -23,30 +22,33 @@ type Datastore struct {
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
PeerID string // until multiaddr supports ipfs, use another field.
}
// Config is used to load IPFS config files.
type Config struct {
Identity *Identity // local node's peer identity
Datastore Datastore // local node's storage
RPCAddress string // local node's RPC address
Peers []*SavedPeer // local nodes's bootstrap peers
Identity Identity // local node's peer identity
Datastore Datastore // local node's storage
Addresses Addresses // local node's addresses
Bootstrap []*BootstrapPeer // local nodes's bootstrap peers
}
// DefaultPathRoot is the default parth for the IPFS node's root dir.
const DefaultPathRoot = "~/.go-ipfs"
// DefaultConfigFilePath points to the ipfs node config file.
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) {
pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)
if err != nil {
......
......@@ -148,7 +148,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, 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?)")
}
......@@ -158,8 +158,8 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) {
// address is optional
var addresses []*ma.Multiaddr
if len(cfg.Identity.Address) > 0 {
maddr, err := ma.NewMultiaddr(cfg.Identity.Address)
if len(cfg.Addresses.Swarm) > 0 {
maddr, err := ma.NewMultiaddr(cfg.Addresses.Swarm)
if err != nil {
return nil, err
}
......@@ -186,7 +186,7 @@ func initIdentity(cfg *config.Config) (*peer.Peer, error) {
}
func initConnections(ctx context.Context, cfg *config.Config, pstore peer.Peerstore, route *dht.IpfsDHT) {
for _, p := range cfg.Peers {
for _, p := range cfg.Bootstrap {
if p.PeerID == "" {
u.PErr("error: peer does not include PeerID. %v\n", p)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment