@cryptotaxi247 / kubo / commits / bc0769e37

ipfs + ipns mounts with flags + config

Juan Batiz-Benet committed Oct 2, 2014 at 03:05 UTC bc0769e370e6e271eebbd8c47d4815525096efcc
3 files changed +60 -44
cmd/ipfs/init.go
+6
@@ -92,6 +92,12 @@ func initCmd(c *commander.Command, inp []string) error {
92 API: "/ip4/127.0.0.1/tcp/5001",
93 }
94
95 + // setup the node mount points.
96 + cfg.Mounts = config.Mounts{
97 + IPFS: "/ipfs",
98 + IPNS: "/ipns",
99 + }
100 +
101 nbits, ok := c.Flag.Lookup("b").Value.Get().(int)
102 if !ok {
103 return errors.New("failed to get bits flag")
cmd/ipfs/mount_unix.go
+47 -44
@@ -3,14 +3,12 @@
3 package main
4
5 import (
6 - "errors"
6 "fmt"
7
8 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
9 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
11 - ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
10
13 - "github.com/jbenet/go-ipfs/daemon"
11 + core "github.com/jbenet/go-ipfs/core"
12 ipns "github.com/jbenet/go-ipfs/fuse/ipns"
13 rofs "github.com/jbenet/go-ipfs/fuse/readonly"
14 )
@@ -30,59 +28,64 @@ var cmdIpfsMount = &commander.Command{
28 }
29
30 func init() {
31 + cmdIpfsMount.Flag.String("f", "", "specify a mountpoint for ipfs")
32 cmdIpfsMount.Flag.String("n", "", "specify a mountpoint for ipns")
34 - cmdIpfsMount.Flag.String("f", "/ipfs", "specify a mountpoint for ipfs")
33 }
34
35 func mountCmd(c *commander.Command, inp []string) error {
38 - conf, err := getConfigDir(c.Parent)
39 - if err != nil {
40 - fmt.Println("Couldnt get config dir")
41 - return err
42 - }
43 - n, err := localNode(conf, true)
36 +
37 + cc, err := setupCmdContext(c, true)
38 if err != nil {
45 - fmt.Println("Local node creation failed.")
39 return err
40 }
41 + defer cc.daemon.Close()
42
49 - // launch the API RPC endpoint.
50 - if n.Config.Addresses.API == "" {
51 - return errors.New("no config.RPCAddress endpoint supplied")
43 + // update fsdir with flag.
44 + fsdir := cc.node.Config.Mounts.IPFS
45 + if val, ok := c.Flag.Lookup("f").Value.Get().(string); ok && val != "" {
46 + fsdir = val
47 }
48 + fsdone := mountIpfs(cc.node, fsdir)
49
54 - maddr, err := ma.NewMultiaddr(n.Config.Addresses.API)
55 - if err != nil {
56 - return err
50 + // get default mount points
51 + nsdir := cc.node.Config.Mounts.IPNS
52 + if val, ok := c.Flag.Lookup("n").Value.Get().(string); ok && val != "" {
53 + nsdir = val
54 }
55 + nsdone := mountIpns(cc.node, nsdir, fsdir)
56
59 - dl, err := daemon.NewDaemonListener(n, maddr, conf)
60 - if err != nil {
61 - fmt.Println("Failed to create daemon listener.")
62 - return err
63 - }
64 - go dl.Listen()
65 - defer dl.Close()
66 -
67 - mp := c.Flag.Lookup("f").Value.Get().(string)
68 - fmt.Printf("Mounting at %s\n", mp)
69 -
70 - var ipnsDone chan struct{}
71 - ns, ok := c.Flag.Lookup("n").Value.Get().(string)
72 - if ok && ns != "" {
73 - ipnsDone = make(chan struct{})
74 - go func() {
75 - err = ipns.Mount(n, ns, mp)
76 - if err != nil {
77 - fmt.Printf("Error mounting ipns: %s\n", err)
78 - }
79 - ipnsDone <- struct{}{}
80 - }()
81 - }
57 + // wait till mounts are done.
58 + err1 := <-fsdone
59 + err2 := <-nsdone
60
83 - err = rofs.Mount(n, mp)
84 - if ipnsDone != nil {
85 - <-ipnsDone
61 + if err1 != nil {
62 + return err1
63 }
87 - return err
64 + return err2
65 +}
66 +
67 +func mountIpfs(node *core.IpfsNode, fsdir string) <-chan error {
68 + done := make(chan error)
69 + fmt.Printf("mounting ipfs at %s\n", fsdir)
70 +
71 + go func() {
72 + err := rofs.Mount(node, fsdir)
73 + done <- err
74 + close(done)
75 + }()
76 +
77 + return done
78 +}
79 +
80 +func mountIpns(node *core.IpfsNode, nsdir, fsdir string) <-chan error {
81 + done := make(chan error)
82 + fmt.Printf("mounting ipns at %s\n", nsdir)
83 +
84 + go func() {
85 + err := ipns.Mount(node, nsdir, fsdir)
86 + done <- err
87 + close(done)
88 + }()
89 +
90 + return done
91 }
config/config.go
+7
@@ -29,6 +29,12 @@ type Addresses struct {
29 API string // address for the local API (RPC)
30 }
31
32 +// Mounts stores the (string) mount points
33 +type Mounts struct {
34 + IPFS string
35 + IPNS string
36 +}
37 +
38 // BootstrapPeer is a peer used to bootstrap the network.
39 type BootstrapPeer struct {
40 Address string
@@ -40,6 +46,7 @@ type Config struct {
46 Identity Identity // local node's peer identity
47 Datastore Datastore // local node's storage
48 Addresses Addresses // local node's addresses
49 + Mounts Mounts // local node's mount points
50 Bootstrap []*BootstrapPeer // local nodes's bootstrap peers
51 }
52