Commit c2cc4b1d authored by Jeromy's avatar Jeromy

a little cleanup, ipfs 'works' for basic file adds and cats

parent 691d1b36
...@@ -2,6 +2,10 @@ package main ...@@ -2,6 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/gonuts/flag" "github.com/gonuts/flag"
"github.com/jbenet/commander" "github.com/jbenet/commander"
core "github.com/jbenet/go-ipfs/core" core "github.com/jbenet/go-ipfs/core"
...@@ -9,9 +13,6 @@ import ( ...@@ -9,9 +13,6 @@ import (
dag "github.com/jbenet/go-ipfs/merkledag" dag "github.com/jbenet/go-ipfs/merkledag"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
mh "github.com/jbenet/go-multihash" mh "github.com/jbenet/go-multihash"
"io/ioutil"
"os"
"path/filepath"
) )
// Error indicating the max depth has been exceded. // Error indicating the max depth has been exceded.
...@@ -41,7 +42,7 @@ func addCmd(c *commander.Command, inp []string) error { ...@@ -41,7 +42,7 @@ func addCmd(c *commander.Command, inp []string) error {
return nil return nil
} }
n, err := localNode() n, err := localNode(false)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -26,7 +26,7 @@ func catCmd(c *commander.Command, inp []string) error { ...@@ -26,7 +26,7 @@ func catCmd(c *commander.Command, inp []string) error {
return nil return nil
} }
n, err := localNode() n, err := localNode(false)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -67,12 +67,12 @@ func main() { ...@@ -67,12 +67,12 @@ func main() {
return return
} }
func localNode() (*core.IpfsNode, error) { func localNode(online bool) (*core.IpfsNode, error) {
//todo implement config file flag //todo implement config file flag
cfg, err := config.Load("") cfg, err := config.Load("")
if err != nil { if err != nil {
return nil, err return nil, err
} }
return core.NewIpfsNode(cfg) return core.NewIpfsNode(cfg, online)
} }
...@@ -27,7 +27,7 @@ func lsCmd(c *commander.Command, inp []string) error { ...@@ -27,7 +27,7 @@ func lsCmd(c *commander.Command, inp []string) error {
return nil return nil
} }
n, err := localNode() n, err := localNode(false)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -31,7 +31,7 @@ func mountCmd(c *commander.Command, inp []string) error { ...@@ -31,7 +31,7 @@ func mountCmd(c *commander.Command, inp []string) error {
return nil return nil
} }
n, err := localNode() n, err := localNode(true)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -36,7 +36,7 @@ func refCmd(c *commander.Command, inp []string) error { ...@@ -36,7 +36,7 @@ func refCmd(c *commander.Command, inp []string) error {
return nil return nil
} }
n, err := localNode() n, err := localNode(false)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -33,7 +33,7 @@ func WriteConfigFile(filename string, cfg interface{}) error { ...@@ -33,7 +33,7 @@ func WriteConfigFile(filename string, cfg interface{}) error {
// WriteFile writes the buffer at filename // WriteFile writes the buffer at filename
func WriteFile(filename string, buf []byte) error { func WriteFile(filename string, buf []byte) error {
err := os.MkdirAll(filepath.Dir(filename), 755) err := os.MkdirAll(filepath.Dir(filename), 0775)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -55,7 +55,7 @@ type IpfsNode struct { ...@@ -55,7 +55,7 @@ type IpfsNode struct {
} }
// NewIpfsNode constructs a new IpfsNode based on the given config. // 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 { if cfg == nil {
return nil, fmt.Errorf("configuration required") return nil, fmt.Errorf("configuration required")
} }
...@@ -65,34 +65,37 @@ func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) { ...@@ -65,34 +65,37 @@ func NewIpfsNode(cfg *config.Config) (*IpfsNode, error) {
return nil, err return nil, err
} }
maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/4001") var swap *bitswap.BitSwap
if err != nil { if online {
return nil, err maddr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/4001")
} if err != nil {
return nil, err
}
local := &peer.Peer{ local := &peer.Peer{
ID: peer.ID(cfg.Identity.PeerID), ID: peer.ID(cfg.Identity.PeerID),
Addresses: []*ma.Multiaddr{maddr}, Addresses: []*ma.Multiaddr{maddr},
} }
if len(local.ID) == 0 { if len(local.ID) == 0 {
mh, err := u.Hash([]byte("blah blah blah ID")) 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 { if err != nil {
return nil, err 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 := dht.NewDHT(local, net, d)
route.Start() route.Start()
swap := bitswap.NewBitSwap(local, net, d, route) swap = bitswap.NewBitSwap(local, net, d, route)
}
bs, err := bserv.NewBlockService(d, swap) bs, err := bserv.NewBlockService(d, swap)
if err != nil { if err != nil {
......
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