diff --git a/cmd/ipfs/add.go b/cmd/ipfs/add.go index c80d8ce18d4917fd7cdf97e5f719c4d70b91ad0a..f114dd5e9774906f29a15953db80cec5aef56164 100644 --- a/cmd/ipfs/add.go +++ b/cmd/ipfs/add.go @@ -2,6 +2,10 @@ package main import ( "fmt" + "io/ioutil" + "os" + "path/filepath" + "github.com/gonuts/flag" "github.com/jbenet/commander" core "github.com/jbenet/go-ipfs/core" @@ -9,9 +13,6 @@ import ( dag "github.com/jbenet/go-ipfs/merkledag" u "github.com/jbenet/go-ipfs/util" mh "github.com/jbenet/go-multihash" - "io/ioutil" - "os" - "path/filepath" ) // Error indicating the max depth has been exceded. @@ -41,7 +42,7 @@ func addCmd(c *commander.Command, inp []string) error { return nil } - n, err := localNode() + n, err := localNode(false) if err != nil { return err } diff --git a/cmd/ipfs/cat.go b/cmd/ipfs/cat.go index 74cb8b00d1d52be5502dbfa18eed59be50a3c801..41a1a25241d9008c1f7727d5b340e07ee7b489b5 100644 --- a/cmd/ipfs/cat.go +++ b/cmd/ipfs/cat.go @@ -26,7 +26,7 @@ func catCmd(c *commander.Command, inp []string) error { return nil } - n, err := localNode() + n, err := localNode(false) if err != nil { return err } diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index b141e039673261033bd89ab4743958d114c45cc4..e7a955d513d54fd6dce8420a8c3be8be0e894827 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -67,12 +67,12 @@ func main() { return } -func localNode() (*core.IpfsNode, error) { +func localNode(online bool) (*core.IpfsNode, error) { //todo implement config file flag cfg, err := config.Load("") if err != nil { return nil, err } - return core.NewIpfsNode(cfg) + return core.NewIpfsNode(cfg, online) } diff --git a/cmd/ipfs/ls.go b/cmd/ipfs/ls.go index 7c2135c0cd36fe01d97e96a4d50b7232e0adc993..6a4270ce9ba39ec0aab40e5770a4512e14df5b47 100644 --- a/cmd/ipfs/ls.go +++ b/cmd/ipfs/ls.go @@ -27,7 +27,7 @@ func lsCmd(c *commander.Command, inp []string) error { return nil } - n, err := localNode() + n, err := localNode(false) if err != nil { return err } diff --git a/cmd/ipfs/mount_unix.go b/cmd/ipfs/mount_unix.go index b6c69db9a860e691e863b4a368a446d944aaf9d7..4f6e34402f7621956f0adae58fc39f73a04461ce 100644 --- a/cmd/ipfs/mount_unix.go +++ b/cmd/ipfs/mount_unix.go @@ -31,7 +31,7 @@ func mountCmd(c *commander.Command, inp []string) error { return nil } - n, err := localNode() + n, err := localNode(true) if err != nil { return err } diff --git a/cmd/ipfs/refs.go b/cmd/ipfs/refs.go index df3c5d1f4184ff71889c2427788a031f0d970c63..34623252d7544fe96e253b8d074a97405ea7f634 100644 --- a/cmd/ipfs/refs.go +++ b/cmd/ipfs/refs.go @@ -36,7 +36,7 @@ func refCmd(c *commander.Command, inp []string) error { return nil } - n, err := localNode() + n, err := localNode(false) if err != nil { return err } diff --git a/config/serialize.go b/config/serialize.go index dc9835cca1e97c0706b87e4ef12126f75a99fe94..bf495a2603d50710f31775a099078b975c373104 100644 --- a/config/serialize.go +++ b/config/serialize.go @@ -33,7 +33,7 @@ func WriteConfigFile(filename string, cfg interface{}) error { // WriteFile writes the buffer at filename func WriteFile(filename string, buf []byte) error { - err := os.MkdirAll(filepath.Dir(filename), 755) + err := os.MkdirAll(filepath.Dir(filename), 0775) if err != nil { return err } diff --git a/core/core.go b/core/core.go index 01ff8c18af4f72bc4eaa1e72c1c82addbb186ecb..43bf632c4d52f9f26ed2a2ad2fb30fe51478e03f 100644 --- a/core/core.go +++ b/core/core.go @@ -55,7 +55,7 @@ type IpfsNode struct { } // NewIpfsNode constructs a new IpfsNode based on the given config. -func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) { +func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) { if cfg == nil { return nil, fmt.Errorf("configuration required") } @@ -65,34 +65,37 @@ func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) { return nil, err } - maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/4001") - if err != nil { - return nil, err - } + var swap *bitswap.BitSwap + if online { + maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/4001") + if err != nil { + return nil, err + } - local := &peer.Peer{ - ID: peer.ID(cfg.Identity.PeerID), - Addresses: []*ma.Multiaddr{maddr}, - } + local := &peer.Peer{ + ID: peer.ID(cfg.Identity.PeerID), + Addresses: []*ma.Multiaddr{maddr}, + } - if len(local.ID) == 0 { - mh, err := u.Hash([]byte("blah blah blah ID")) + if len(local.ID) == 0 { + mh, err := u.Hash([]byte("blah blah blah ID")) + if err != nil { + return nil, err + } + local.ID = peer.ID(mh) + } + + net := swarm.NewSwarm(local) + err = net.Listen() if err != nil { return nil, err } - local.ID = peer.ID(mh) - } - - net := swarm.NewSwarm(local) - err = net.Listen() - if err != nil { - return nil, err - } - route := dht.NewDHT(local, net, d) - route.Start() + route := dht.NewDHT(local, net, d) + route.Start() - swap := bitswap.NewBitSwap(local, net, d, route) + swap = bitswap.NewBitSwap(local, net, d, route) + } bs, err := bserv.NewBlockService(d, swap) if err != nil {