From aea52132cb9a4fcb20e8f9bb53f4918227b4391b Mon Sep 17 00:00:00 2001
From: Matt Bell <mappum@gmail.com>
Date: Tue, 28 Oct 2014 23:10:59 -0700
Subject: [PATCH] cmd/ipfs: Initialize IpfsNode when running locally or
 starting daemon

---
 cmd/ipfs/daemon.go | 10 ++++++++--
 cmd/ipfs/ipfs.go   |  9 ++++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go
index 102dadfc1..d39ef3c48 100644
--- a/cmd/ipfs/daemon.go
+++ b/cmd/ipfs/daemon.go
@@ -9,6 +9,7 @@ import (
 
 	cmds "github.com/jbenet/go-ipfs/commands"
 	cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
+	"github.com/jbenet/go-ipfs/core"
 	"github.com/jbenet/go-ipfs/daemon"
 )
 
@@ -20,10 +21,15 @@ var Daemon = &cmds.Command{
 }
 
 func daemonFunc(req cmds.Request, res cmds.Response) {
-	// TODO: spin up a core.IpfsNode
-
 	ctx := req.Context()
 
+	node, err := core.NewIpfsNode(ctx.Config, true)
+	if err != nil {
+		res.SetError(err, cmds.ErrNormal)
+		return
+	}
+	ctx.Node = node
+
 	lk, err := daemon.Lock(ctx.ConfigRoot)
 	if err != nil {
 		res.SetError(fmt.Errorf("Couldn't obtain lock. Is another daemon already running?"), cmds.ErrNormal)
diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go
index e847e623f..6fae87cdb 100644
--- a/cmd/ipfs/ipfs.go
+++ b/cmd/ipfs/ipfs.go
@@ -10,6 +10,7 @@ import (
 	cmdsCli "github.com/jbenet/go-ipfs/commands/cli"
 	cmdsHttp "github.com/jbenet/go-ipfs/commands/http"
 	"github.com/jbenet/go-ipfs/config"
+	"github.com/jbenet/go-ipfs/core"
 	"github.com/jbenet/go-ipfs/core/commands"
 	"github.com/jbenet/go-ipfs/daemon"
 	u "github.com/jbenet/go-ipfs/util"
@@ -110,7 +111,13 @@ func main() {
 			}
 
 		} else {
-			// TODO: spin up node
+			node, err := core.NewIpfsNode(conf, false)
+			if err != nil {
+				fmt.Println(err)
+				os.Exit(1)
+			}
+			ctx.Node = node
+
 			res = root.Call(req)
 		}
 	}
-- 
GitLab