@cryptotaxi247 / kubo / commits / bea4ed78d

feat(cmd/daemon) add --gcr option to run GCR routing client

Brian Tiger Chow committed Feb 12, 2015 at 13:41 UTC bea4ed78d5d7b64f4d6f77af19bb2406de9da58a
1 file changed +26
cmd/ipfs/daemon.go
+26
@@ -10,6 +10,8 @@ import (
10 "github.com/jbenet/go-ipfs/core"
11 commands "github.com/jbenet/go-ipfs/core/commands"
12 corehttp "github.com/jbenet/go-ipfs/core/corehttp"
13 + "github.com/jbenet/go-ipfs/core/corerouting"
14 + peer "github.com/jbenet/go-ipfs/p2p/peer"
15 fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo"
16 util "github.com/jbenet/go-ipfs/util"
17 "github.com/jbenet/go-ipfs/util/debugerror"
@@ -17,6 +19,7 @@ import (
19
20 const (
21 initOptionKwd = "init"
22 + gcrKwd = "gcr"
23 mountKwd = "mount"
24 writableKwd = "writable"
25 ipfsMountKwd = "mount-ipfs"
@@ -39,6 +42,7 @@ the daemon.
42
43 Options: []cmds.Option{
44 cmds.BoolOption(initOptionKwd, "Initialize IPFS with default settings if not already initialized"),
45 + cmds.BoolOption(gcrKwd, "Enables Grandcentral Routing"),
46 cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem"),
47 cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"),
48 cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"),
@@ -103,6 +107,28 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
107 nb := core.NewNodeBuilder().Online()
108 nb.SetRepo(repo)
109
110 + useGCR, _, err := req.Option(gcrKwd).Bool()
111 + if err != nil {
112 + res.SetError(err, cmds.ErrNormal)
113 + return
114 + }
115 + if useGCR {
116 + servers, err := repo.Config().GCR.ServerIPFSAddrs()
117 + if err != nil {
118 + res.SetError(err, cmds.ErrNormal)
119 + repo.Close() // because ownership hasn't been transferred to the node
120 + return
121 + }
122 + var infos []peer.PeerInfo
123 + for _, addr := range servers {
124 + infos = append(infos, peer.PeerInfo{
125 + ID: addr.ID(),
126 + Addrs: []ma.Multiaddr{addr.Transport()},
127 + })
128 + }
129 + nb.SetRouting(corerouting.SupernodeClient(infos...))
130 + }
131 +
132 node, err := nb.Build(ctx.Context)
133 if err != nil {
134 res.SetError(err, cmds.ErrNormal)