From bea4ed78d5d7b64f4d6f77af19bb2406de9da58a Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow <brian.holderchow@gmail.com> Date: Thu, 12 Feb 2015 13:41:48 -0800 Subject: [PATCH] feat(cmd/daemon) add --gcr option to run GCR routing client --- cmd/ipfs/daemon.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 1c9aae7aa..b55941b48 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -10,6 +10,8 @@ import ( "github.com/jbenet/go-ipfs/core" commands "github.com/jbenet/go-ipfs/core/commands" corehttp "github.com/jbenet/go-ipfs/core/corehttp" + "github.com/jbenet/go-ipfs/core/corerouting" + peer "github.com/jbenet/go-ipfs/p2p/peer" fsrepo "github.com/jbenet/go-ipfs/repo/fsrepo" util "github.com/jbenet/go-ipfs/util" "github.com/jbenet/go-ipfs/util/debugerror" @@ -17,6 +19,7 @@ import ( const ( initOptionKwd = "init" + gcrKwd = "gcr" mountKwd = "mount" writableKwd = "writable" ipfsMountKwd = "mount-ipfs" @@ -39,6 +42,7 @@ the daemon. Options: []cmds.Option{ cmds.BoolOption(initOptionKwd, "Initialize IPFS with default settings if not already initialized"), + cmds.BoolOption(gcrKwd, "Enables Grandcentral Routing"), cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem"), cmds.BoolOption(writableKwd, "Enable writing objects (with POST, PUT and DELETE)"), cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"), @@ -103,6 +107,28 @@ func daemonFunc(req cmds.Request, res cmds.Response) { nb := core.NewNodeBuilder().Online() nb.SetRepo(repo) + useGCR, _, err := req.Option(gcrKwd).Bool() + if err != nil { + res.SetError(err, cmds.ErrNormal) + return + } + if useGCR { + servers, err := repo.Config().GCR.ServerIPFSAddrs() + if err != nil { + res.SetError(err, cmds.ErrNormal) + repo.Close() // because ownership hasn't been transferred to the node + return + } + var infos []peer.PeerInfo + for _, addr := range servers { + infos = append(infos, peer.PeerInfo{ + ID: addr.ID(), + Addrs: []ma.Multiaddr{addr.Transport()}, + }) + } + nb.SetRouting(corerouting.SupernodeClient(infos...)) + } + node, err := nb.Build(ctx.Context) if err != nil { res.SetError(err, cmds.ErrNormal) -- GitLab