Skip to content

Commit

Permalink
Merge pull request #121 from jbenet/feat/addrs-in-config
Browse files Browse the repository at this point in the history
config: rename addresses
  • Loading branch information
jbenet committed Sep 26, 2014
2 parents 671b095 + 303ebd8 commit 80a927f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
15 changes: 8 additions & 7 deletions cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions cmd/ipfs/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 16 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
type Identity struct {
PeerID string
PrivKey string
Address string
}

// Datastore tracks the configuration of the datastore.
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?)")
}

Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 80a927f

Please sign in to comment.