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
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
}
......
......@@ -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
}
......
......@@ -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)
}
......@@ -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
}
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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 {
......
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