Skip to content

Commit 9978caf

Browse files
committedJul 21, 2015
Merge pull request #1500 from ipfs/feat/global-timeout
add a global timeout flag
2 parents 13d49d9 + bb3a75a commit 9978caf

38 files changed

+210
-171
lines changed
 

‎cmd/ipfs/daemon.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
110110
// let the user know we're going.
111111
fmt.Printf("Initializing daemon...\n")
112112

113-
ctx := req.Context()
113+
ctx := req.InvocContext()
114114

115115
go func() {
116116
select {
117-
case <-ctx.Context.Done():
117+
case <-req.Context().Done():
118118
fmt.Println("Received interrupt signal, shutting down...")
119119
}
120120
}()
@@ -141,8 +141,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
141141
// configured. Consider moving this into a config helper method
142142
// `IsInitialized` where the quality of the signal can be improved over
143143
// time, and many call-sites can benefit.
144-
if !util.FileExists(req.Context().ConfigRoot) {
145-
err := initWithDefaults(os.Stdout, req.Context().ConfigRoot)
144+
if !util.FileExists(req.InvocContext().ConfigRoot) {
145+
err := initWithDefaults(os.Stdout, req.InvocContext().ConfigRoot)
146146
if err != nil {
147147
res.SetError(err, cmds.ErrNormal)
148148
return
@@ -152,7 +152,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
152152

153153
// acquire the repo lock _before_ constructing a node. we need to make
154154
// sure we are permitted to access the resources (datastore, etc.)
155-
repo, err := fsrepo.Open(req.Context().ConfigRoot)
155+
repo, err := fsrepo.Open(req.InvocContext().ConfigRoot)
156156
if err != nil {
157157
res.SetError(err, cmds.ErrNormal)
158158
return
@@ -190,7 +190,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
190190
nb.SetRouting(corerouting.SupernodeClient(infos...))
191191
}
192192

193-
node, err := nb.Build(ctx.Context)
193+
node, err := nb.Build(req.Context())
194194
if err != nil {
195195
log.Error("error from node construction: ", err)
196196
res.SetError(err, cmds.ErrNormal)
@@ -205,13 +205,13 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
205205
node.Close()
206206

207207
select {
208-
case <-ctx.Context.Done():
208+
case <-req.Context().Done():
209209
log.Info("Gracefully shut down daemon")
210210
default:
211211
}
212212
}()
213213

214-
req.Context().ConstructNode = func() (*core.IpfsNode, error) {
214+
req.InvocContext().ConstructNode = func() (*core.IpfsNode, error) {
215215
return node, nil
216216
}
217217

@@ -258,7 +258,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
258258

259259
// serveHTTPApi collects options, creates listener, prints status message and starts serving requests
260260
func serveHTTPApi(req cmds.Request) (error, <-chan error) {
261-
cfg, err := req.Context().GetConfig()
261+
cfg, err := req.InvocContext().GetConfig()
262262
if err != nil {
263263
return fmt.Errorf("serveHTTPApi: GetConfig() failed: %s", err), nil
264264
}
@@ -299,7 +299,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
299299
},
300300
})
301301
var opts = []corehttp.ServeOption{
302-
corehttp.CommandsOption(*req.Context()),
302+
corehttp.CommandsOption(*req.InvocContext()),
303303
corehttp.WebUIOption,
304304
apiGw.ServeOption(),
305305
corehttp.VersionOption(),
@@ -313,7 +313,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
313313
opts = append(opts, corehttp.RedirectOption("", cfg.Gateway.RootRedirect))
314314
}
315315

316-
node, err := req.Context().ConstructNode()
316+
node, err := req.InvocContext().ConstructNode()
317317
if err != nil {
318318
return fmt.Errorf("serveHTTPGateway: ConstructNode() failed: %s", err), nil
319319
}
@@ -341,7 +341,7 @@ func printSwarmAddrs(node *core.IpfsNode) {
341341

342342
// serveHTTPGateway collects options, creates listener, prints status message and starts serving requests
343343
func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
344-
cfg, err := req.Context().GetConfig()
344+
cfg, err := req.InvocContext().GetConfig()
345345
if err != nil {
346346
return fmt.Errorf("serveHTTPGateway: GetConfig() failed: %s", err), nil
347347
}
@@ -382,7 +382,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
382382
opts = append(opts, corehttp.RedirectOption("", cfg.Gateway.RootRedirect))
383383
}
384384

385-
node, err := req.Context().ConstructNode()
385+
node, err := req.InvocContext().ConstructNode()
386386
if err != nil {
387387
return fmt.Errorf("serveHTTPGateway: ConstructNode() failed: %s", err), nil
388388
}
@@ -397,7 +397,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
397397

398398
//collects options and opens the fuse mountpoint
399399
func mountFuse(req cmds.Request) error {
400-
cfg, err := req.Context().GetConfig()
400+
cfg, err := req.InvocContext().GetConfig()
401401
if err != nil {
402402
return fmt.Errorf("mountFuse: GetConfig() failed: %s", err)
403403
}
@@ -418,7 +418,7 @@ func mountFuse(req cmds.Request) error {
418418
nsdir = cfg.Mounts.IPNS
419419
}
420420

421-
node, err := req.Context().ConstructNode()
421+
node, err := req.InvocContext().ConstructNode()
422422
if err != nil {
423423
return fmt.Errorf("mountFuse: ConstructNode() failed: %s", err)
424424
}

‎cmd/ipfs/init.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var initCmd = &cmds.Command{
3434
// TODO cmds.StringOption("event-logs", "l", "Location for machine-readable event logs"),
3535
},
3636
PreRun: func(req cmds.Request) error {
37-
daemonLocked, err := fsrepo.LockedByOtherProcess(req.Context().ConfigRoot)
37+
daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
3838
if err != nil {
3939
return err
4040
}
@@ -48,7 +48,7 @@ var initCmd = &cmds.Command{
4848
return nil
4949
},
5050
Run: func(req cmds.Request, res cmds.Response) {
51-
if req.Context().Online {
51+
if req.InvocContext().Online {
5252
res.SetError(errors.New("init must be run offline only!"), cmds.ErrNormal)
5353
return
5454
}
@@ -69,7 +69,7 @@ var initCmd = &cmds.Command{
6969
nBitsForKeypair = nBitsForKeypairDefault
7070
}
7171

72-
if err := doInit(os.Stdout, req.Context().ConfigRoot, force, nBitsForKeypair); err != nil {
72+
if err := doInit(os.Stdout, req.InvocContext().ConfigRoot, force, nBitsForKeypair); err != nil {
7373
res.SetError(err, cmds.ErrNormal)
7474
return
7575
}

‎cmd/ipfs/main.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
192192
return nil, errors.New("constructing node without a request")
193193
}
194194

195-
cmdctx := i.req.Context()
195+
cmdctx := i.req.InvocContext()
196196
if cmdctx == nil {
197197
return nil, errors.New("constructing node without a request context")
198198
}
199199

200-
r, err := fsrepo.Open(i.req.Context().ConfigRoot)
200+
r, err := fsrepo.Open(i.req.InvocContext().ConfigRoot)
201201
if err != nil { // repo is owned by the node
202202
return nil, err
203203
}
@@ -238,7 +238,7 @@ func (i *cmdInvocation) Parse(ctx context.Context, args []string) error {
238238
log.Debugf("config path is %s", repoPath)
239239

240240
// this sets up the function that will initialize the config lazily.
241-
cmdctx := i.req.Context()
241+
cmdctx := i.req.InvocContext()
242242
cmdctx.ConfigRoot = repoPath
243243
cmdctx.LoadConfig = loadConfig
244244
// this sets up the function that will initialize the node
@@ -279,10 +279,13 @@ func callPreCommandHooks(ctx context.Context, details cmdDetails, req cmds.Reque
279279
}
280280

281281
func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd *cmds.Command) (cmds.Response, error) {
282-
log.Info(config.EnvDir, " ", req.Context().ConfigRoot)
282+
log.Info(config.EnvDir, " ", req.InvocContext().ConfigRoot)
283283
var res cmds.Response
284284

285-
req.Context().Context = ctx
285+
err := req.SetRootContext(ctx)
286+
if err != nil {
287+
return nil, err
288+
}
286289

287290
details, err := commandDetails(req.Path(), root)
288291
if err != nil {
@@ -309,7 +312,7 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd
309312

310313
if useDaemon {
311314

312-
cfg, err := req.Context().GetConfig()
315+
cfg, err := req.InvocContext().GetConfig()
313316
if err != nil {
314317
return nil, err
315318
}
@@ -335,6 +338,11 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd
335338
} else {
336339
log.Debug("Executing command locally")
337340

341+
err := req.SetRootContext(ctx)
342+
if err != nil {
343+
return nil, err
344+
}
345+
338346
// Okay!!!!! NOW we can call the command.
339347
res = root.Call(req)
340348

@@ -392,7 +400,7 @@ func commandShouldRunOnDaemon(details cmdDetails, req cmds.Request, root *cmds.C
392400

393401
// at this point need to know whether daemon is running. we defer
394402
// to this point so that some commands dont open files unnecessarily.
395-
daemonLocked, err := fsrepo.LockedByOtherProcess(req.Context().ConfigRoot)
403+
daemonLocked, err := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot)
396404
if err != nil {
397405
return false, err
398406
}

‎cmd/ipfswatch/main.go

-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ func IsHidden(path string) bool {
185185

186186
func cmdCtx(node *core.IpfsNode, repoPath string) commands.Context {
187187
return commands.Context{
188-
// TODO deprecate this shit
189-
Context: context.Background(),
190188
Online: true,
191189
ConfigRoot: repoPath,
192190
LoadConfig: func(path string) (*config.Config, error) {

‎commands/http/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (c *client) Send(req cmds.Request) (cmds.Response, error) {
8484

8585
ec := make(chan error, 1)
8686
rc := make(chan cmds.Response, 1)
87-
dc := req.Context().Context.Done()
87+
dc := req.Context().Done()
8888

8989
go func() {
9090
httpRes, err := http.DefaultClient.Do(httpReq)
@@ -181,7 +181,7 @@ func getResponse(httpRes *http.Response, req cmds.Request) (cmds.Response, error
181181
dec := json.NewDecoder(httpRes.Body)
182182
outputType := reflect.TypeOf(req.Command().Type)
183183

184-
ctx := req.Context().Context
184+
ctx := req.Context()
185185

186186
for {
187187
var v interface{}

‎commands/http/handler.go

+7-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/rs/cors"
12-
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
1312

1413
cmds "github.com/ipfs/go-ipfs/commands"
1514
u "github.com/ipfs/go-ipfs/util"
@@ -106,20 +105,14 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
106105
http.Error(w, err.Error(), http.StatusInternalServerError)
107106
return
108107
}
109-
ctx, cancel := context.WithCancel(node.Context())
110-
defer cancel()
111-
/*
112-
TODO(cryptix): the next line looks very fishy to me..
113-
It looks like the the context for the command request beeing prepared here is shared across all incoming requests..
114108

115-
I assume it really isn't because ServeHTTP() doesn't take a pointer receiver, but it's really subtule..
116-
117-
Shouldn't the context be just put on the command request?
118-
119-
ps: take note of the name clash - commands.Context != context.Context
120-
*/
121-
i.ctx.Context = ctx
122-
req.SetContext(i.ctx)
109+
//ps: take note of the name clash - commands.Context != context.Context
110+
req.SetInvocContext(i.ctx)
111+
err = req.SetRootContext(node.Context())
112+
if err != nil {
113+
http.Error(w, err.Error(), http.StatusInternalServerError)
114+
return
115+
}
123116

124117
// call the command
125118
res := i.root.Call(req)

‎commands/option.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,25 @@ func (ov OptionValue) String() (value string, found bool, err error) {
154154

155155
// Flag names
156156
const (
157-
EncShort = "enc"
158-
EncLong = "encoding"
159-
RecShort = "r"
160-
RecLong = "recursive"
161-
ChanOpt = "stream-channels"
157+
EncShort = "enc"
158+
EncLong = "encoding"
159+
RecShort = "r"
160+
RecLong = "recursive"
161+
ChanOpt = "stream-channels"
162+
TimeoutOpt = "timeout"
162163
)
163164

164165
// options that are used by this package
165166
var OptionEncodingType = StringOption(EncShort, EncLong, "The encoding type the output should be encoded with (json, xml, or text)")
166167
var OptionRecursivePath = BoolOption(RecShort, RecLong, "Add directory paths recursively")
167168
var OptionStreamChannels = BoolOption(ChanOpt, "Stream channel output")
169+
var OptionTimeout = StringOption(TimeoutOpt, "set a global timeout on the command")
168170

169171
// global options, added to every command
170172
var globalOptions = []Option{
171173
OptionEncodingType,
172174
OptionStreamChannels,
175+
OptionTimeout,
173176
}
174177

175178
// the above array of Options, wrapped in a Command

‎commands/request.go

+56-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"reflect"
99
"strconv"
10+
"time"
1011

1112
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
1213
"github.com/ipfs/go-ipfs/commands/files"
@@ -18,10 +19,6 @@ import (
1819
type OptMap map[string]interface{}
1920

2021
type Context struct {
21-
// this Context is temporary. Will be replaced soon, as we get
22-
// rid of this variable entirely.
23-
Context context.Context
24-
2522
Online bool
2623
ConfigRoot string
2724

@@ -75,8 +72,10 @@ type Request interface {
7572
SetArguments([]string)
7673
Files() files.File
7774
SetFiles(files.File)
78-
Context() *Context
79-
SetContext(Context)
75+
Context() context.Context
76+
SetRootContext(context.Context) error
77+
InvocContext() *Context
78+
SetInvocContext(Context)
8079
Command() *Command
8180
Values() map[string]interface{}
8281
Stdin() io.Reader
@@ -91,6 +90,7 @@ type request struct {
9190
files files.File
9291
cmd *Command
9392
ctx Context
93+
rctx context.Context
9494
optionDefs map[string]Option
9595
values map[string]interface{}
9696
stdin io.Reader
@@ -130,6 +130,16 @@ func (r *request) Options() OptMap {
130130
return output
131131
}
132132

133+
func (r *request) SetRootContext(ctx context.Context) error {
134+
ctx, err := getContext(ctx, r)
135+
if err != nil {
136+
return err
137+
}
138+
139+
r.rctx = ctx
140+
return nil
141+
}
142+
133143
// SetOption sets the value of the option for given name.
134144
func (r *request) SetOption(name string, val interface{}) {
135145
// find the option with the specified name
@@ -173,11 +183,37 @@ func (r *request) SetFiles(f files.File) {
173183
r.files = f
174184
}
175185

176-
func (r *request) Context() *Context {
186+
func (r *request) Context() context.Context {
187+
return r.rctx
188+
}
189+
190+
func getContext(base context.Context, req Request) (context.Context, error) {
191+
tout, found, err := req.Option("timeout").String()
192+
if err != nil {
193+
return nil, fmt.Errorf("error parsing timeout option: %s", err)
194+
}
195+
196+
var ctx context.Context
197+
if found {
198+
duration, err := time.ParseDuration(tout)
199+
if err != nil {
200+
return nil, fmt.Errorf("error parsing timeout option: %s", err)
201+
}
202+
203+
tctx, _ := context.WithTimeout(base, duration)
204+
ctx = tctx
205+
} else {
206+
cctx, _ := context.WithCancel(base)
207+
ctx = cctx
208+
}
209+
return ctx, nil
210+
}
211+
212+
func (r *request) InvocContext() *Context {
177213
return &r.ctx
178214
}
179215

180-
func (r *request) SetContext(ctx Context) {
216+
func (r *request) SetInvocContext(ctx Context) {
181217
r.ctx = ctx
182218
}
183219

@@ -274,22 +310,26 @@ func NewEmptyRequest() (Request, error) {
274310
// NewRequest returns a request initialized with given arguments
275311
// An non-nil error will be returned if the provided option values are invalid
276312
func NewRequest(path []string, opts OptMap, args []string, file files.File, cmd *Command, optDefs map[string]Option) (Request, error) {
277-
if path == nil {
278-
path = make([]string, 0)
279-
}
280313
if opts == nil {
281314
opts = make(OptMap)
282315
}
283-
if args == nil {
284-
args = make([]string, 0)
285-
}
286316
if optDefs == nil {
287317
optDefs = make(map[string]Option)
288318
}
289319

290-
ctx := Context{Context: context.TODO()}
320+
ctx := Context{}
291321
values := make(map[string]interface{})
292-
req := &request{path, opts, args, file, cmd, ctx, optDefs, values, os.Stdin}
322+
req := &request{
323+
path: path,
324+
options: opts,
325+
arguments: args,
326+
files: file,
327+
cmd: cmd,
328+
ctx: ctx,
329+
optionDefs: optDefs,
330+
values: values,
331+
stdin: os.Stdin,
332+
}
293333
err := req.ConvertOptions()
294334
if err != nil {
295335
return nil, err

‎core/commands/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ remains to be implemented.
8888
return nil
8989
},
9090
Run: func(req cmds.Request, res cmds.Response) {
91-
n, err := req.Context().GetNode()
91+
n, err := req.InvocContext().GetNode()
9292
if err != nil {
9393
res.SetError(err, cmds.ErrNormal)
9494
return

‎core/commands/bitswap.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Print out all blocks currently on the bitswap wantlist for the local peer`,
3333
},
3434
Type: KeyList{},
3535
Run: func(req cmds.Request, res cmds.Response) {
36-
nd, err := req.Context().GetNode()
36+
nd, err := req.InvocContext().GetNode()
3737
if err != nil {
3838
res.SetError(err, cmds.ErrNormal)
3939
return
@@ -78,7 +78,7 @@ var bitswapStatCmd = &cmds.Command{
7878
},
7979
Type: bitswap.Stat{},
8080
Run: func(req cmds.Request, res cmds.Response) {
81-
nd, err := req.Context().GetNode()
81+
nd, err := req.InvocContext().GetNode()
8282
if err != nil {
8383
res.SetError(err, cmds.ErrNormal)
8484
return

‎core/commands/block.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
12-
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
1312
"github.com/ipfs/go-ipfs/blocks"
1413
key "github.com/ipfs/go-ipfs/blocks/key"
1514
cmds "github.com/ipfs/go-ipfs/commands"
@@ -115,7 +114,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
115114
cmds.FileArg("data", true, false, "The data to be stored as an IPFS block").EnableStdin(),
116115
},
117116
Run: func(req cmds.Request, res cmds.Response) {
118-
n, err := req.Context().GetNode()
117+
n, err := req.InvocContext().GetNode()
119118
if err != nil {
120119
res.SetError(err, cmds.ErrNormal)
121120
return
@@ -163,7 +162,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
163162
}
164163

165164
func getBlockForKey(req cmds.Request, skey string) (*blocks.Block, error) {
166-
n, err := req.Context().GetNode()
165+
n, err := req.InvocContext().GetNode()
167166
if err != nil {
168167
return nil, err
169168
}
@@ -178,7 +177,7 @@ func getBlockForKey(req cmds.Request, skey string) (*blocks.Block, error) {
178177
}
179178

180179
k := key.Key(h)
181-
b, err := n.Blocks.GetBlock(context.TODO(), k)
180+
b, err := n.Blocks.GetBlock(req.Context(), k)
182181
if err != nil {
183182
return nil, err
184183
}

‎core/commands/bootstrap.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ in the bootstrap list).
6666
return
6767
}
6868

69-
r, err := fsrepo.Open(req.Context().ConfigRoot)
69+
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
7070
if err != nil {
7171
res.SetError(err, cmds.ErrNormal)
7272
return
@@ -142,7 +142,7 @@ var bootstrapRemoveCmd = &cmds.Command{
142142
return
143143
}
144144

145-
r, err := fsrepo.Open(req.Context().ConfigRoot)
145+
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
146146
if err != nil {
147147
res.SetError(err, cmds.ErrNormal)
148148
return
@@ -191,7 +191,7 @@ var bootstrapListCmd = &cmds.Command{
191191
},
192192

193193
Run: func(req cmds.Request, res cmds.Response) {
194-
r, err := fsrepo.Open(req.Context().ConfigRoot)
194+
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
195195
if err != nil {
196196
res.SetError(err, cmds.ErrNormal)
197197
return

‎core/commands/cat.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ it contains.
2727
cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to be outputted").EnableStdin(),
2828
},
2929
Run: func(req cmds.Request, res cmds.Response) {
30-
node, err := req.Context().GetNode()
30+
node, err := req.InvocContext().GetNode()
3131
if err != nil {
3232
res.SetError(err, cmds.ErrNormal)
3333
return
3434
}
3535

36-
readers, length, err := cat(req.Context().Context, node, req.Arguments())
36+
readers, length, err := cat(req.Context(), node, req.Arguments())
3737
if err != nil {
3838
res.SetError(err, cmds.ErrNormal)
3939
return

‎core/commands/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Set the value of the 'datastore.path' key:
6565
args := req.Arguments()
6666
key := args[0]
6767

68-
r, err := fsrepo.Open(req.Context().ConfigRoot)
68+
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
6969
if err != nil {
7070
res.SetError(err, cmds.ErrNormal)
7171
return
@@ -141,7 +141,7 @@ included in the output of this command.
141141
},
142142

143143
Run: func(req cmds.Request, res cmds.Response) {
144-
filename, err := config.Filename(req.Context().ConfigRoot)
144+
filename, err := config.Filename(req.InvocContext().ConfigRoot)
145145
if err != nil {
146146
res.SetError(err, cmds.ErrNormal)
147147
return
@@ -166,7 +166,7 @@ variable set to your preferred text editor.
166166
},
167167

168168
Run: func(req cmds.Request, res cmds.Response) {
169-
filename, err := config.Filename(req.Context().ConfigRoot)
169+
filename, err := config.Filename(req.InvocContext().ConfigRoot)
170170
if err != nil {
171171
res.SetError(err, cmds.ErrNormal)
172172
return
@@ -192,7 +192,7 @@ can't be undone.
192192
cmds.FileArg("file", true, false, "The file to use as the new config"),
193193
},
194194
Run: func(req cmds.Request, res cmds.Response) {
195-
r, err := fsrepo.Open(req.Context().ConfigRoot)
195+
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
196196
if err != nil {
197197
res.SetError(err, cmds.ErrNormal)
198198
return

‎core/commands/dht.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var queryDhtCmd = &cmds.Command{
4545
cmds.BoolOption("verbose", "v", "Write extra information"),
4646
},
4747
Run: func(req cmds.Request, res cmds.Response) {
48-
n, err := req.Context().GetNode()
48+
n, err := req.InvocContext().GetNode()
4949
if err != nil {
5050
res.SetError(err, cmds.ErrNormal)
5151
return
@@ -58,7 +58,7 @@ var queryDhtCmd = &cmds.Command{
5858
}
5959

6060
events := make(chan *notif.QueryEvent)
61-
ctx := notif.RegisterForQueryEvents(req.Context().Context, events)
61+
ctx := notif.RegisterForQueryEvents(req.Context(), events)
6262

6363
closestPeers, err := dht.GetClosestPeers(ctx, key.Key(req.Arguments()[0]))
6464
if err != nil {
@@ -152,7 +152,7 @@ FindProviders will return a list of peers who are able to provide the value requ
152152
cmds.BoolOption("verbose", "v", "Write extra information"),
153153
},
154154
Run: func(req cmds.Request, res cmds.Response) {
155-
n, err := req.Context().GetNode()
155+
n, err := req.InvocContext().GetNode()
156156
if err != nil {
157157
res.SetError(err, cmds.ErrNormal)
158158
return
@@ -170,7 +170,7 @@ FindProviders will return a list of peers who are able to provide the value requ
170170
res.SetOutput((<-chan interface{})(outChan))
171171

172172
events := make(chan *notif.QueryEvent)
173-
ctx := notif.RegisterForQueryEvents(req.Context().Context, events)
173+
ctx := notif.RegisterForQueryEvents(req.Context(), events)
174174

175175
pchan := dht.FindProvidersAsync(ctx, key.B58KeyDecode(req.Arguments()[0]), numProviders)
176176
go func() {
@@ -265,7 +265,7 @@ var findPeerDhtCmd = &cmds.Command{
265265
cmds.StringArg("peerID", true, true, "The peer to search for"),
266266
},
267267
Run: func(req cmds.Request, res cmds.Response) {
268-
n, err := req.Context().GetNode()
268+
n, err := req.InvocContext().GetNode()
269269
if err != nil {
270270
res.SetError(err, cmds.ErrNormal)
271271
return
@@ -287,7 +287,7 @@ var findPeerDhtCmd = &cmds.Command{
287287
res.SetOutput((<-chan interface{})(outChan))
288288

289289
events := make(chan *notif.QueryEvent)
290-
ctx := notif.RegisterForQueryEvents(req.Context().Context, events)
290+
ctx := notif.RegisterForQueryEvents(req.Context(), events)
291291

292292
go func() {
293293
defer close(outChan)
@@ -375,7 +375,7 @@ GetValue will return the value stored in the dht at the given key.
375375
cmds.BoolOption("verbose", "v", "Write extra information"),
376376
},
377377
Run: func(req cmds.Request, res cmds.Response) {
378-
n, err := req.Context().GetNode()
378+
n, err := req.InvocContext().GetNode()
379379
if err != nil {
380380
res.SetError(err, cmds.ErrNormal)
381381
return
@@ -391,7 +391,7 @@ GetValue will return the value stored in the dht at the given key.
391391
res.SetOutput((<-chan interface{})(outChan))
392392

393393
events := make(chan *notif.QueryEvent)
394-
ctx := notif.RegisterForQueryEvents(req.Context().Context, events)
394+
ctx := notif.RegisterForQueryEvents(req.Context(), events)
395395

396396
go func() {
397397
defer close(outChan)
@@ -483,7 +483,7 @@ PutValue will store the given key value pair in the dht.
483483
cmds.BoolOption("verbose", "v", "Write extra information"),
484484
},
485485
Run: func(req cmds.Request, res cmds.Response) {
486-
n, err := req.Context().GetNode()
486+
n, err := req.InvocContext().GetNode()
487487
if err != nil {
488488
res.SetError(err, cmds.ErrNormal)
489489
return
@@ -499,7 +499,7 @@ PutValue will store the given key value pair in the dht.
499499
res.SetOutput((<-chan interface{})(outChan))
500500

501501
events := make(chan *notif.QueryEvent)
502-
ctx := notif.RegisterForQueryEvents(req.Context().Context, events)
502+
ctx := notif.RegisterForQueryEvents(req.Context(), events)
503503

504504
key := key.B58KeyDecode(req.Arguments()[0])
505505
data := req.Arguments()[1]

‎core/commands/diag.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ that consume the dot format to generate graphs of the network.
9090
},
9191

9292
Run: func(req cmds.Request, res cmds.Response) {
93-
n, err := req.Context().GetNode()
93+
n, err := req.InvocContext().GetNode()
9494
if err != nil {
9595
res.SetError(err, cmds.ErrNormal)
9696
return

‎core/commands/dns.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The resolver will give:
6262
if recursive {
6363
depth = namesys.DefaultDepthLimit
6464
}
65-
output, err := resolver.ResolveN(req.Context().Context, name, depth)
65+
output, err := resolver.ResolveN(req.Context(), name, depth)
6666
if err != nil {
6767
res.SetError(err, cmds.ErrNormal)
6868
return

‎core/commands/get.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
5959
return
6060
}
6161

62-
node, err := req.Context().GetNode()
62+
node, err := req.InvocContext().GetNode()
6363
if err != nil {
6464
res.SetError(err, cmds.ErrNormal)
6565
return
@@ -69,9 +69,9 @@ may also specify the level of compression by specifying '-l=<1-9>'.
6969
var reader io.Reader
7070
if archive, _, _ := req.Option("archive").Bool(); !archive && cmplvl != gzip.NoCompression {
7171
// only use this when the flag is '-C' without '-a'
72-
reader, err = getZip(req.Context().Context, node, p, cmplvl)
72+
reader, err = getZip(req.Context(), node, p, cmplvl)
7373
} else {
74-
reader, err = get(req.Context().Context, node, p, cmplvl)
74+
reader, err = get(req.Context(), node, p, cmplvl)
7575
}
7676
if err != nil {
7777
res.SetError(err, cmds.ErrNormal)

‎core/commands/id.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ipfs id supports the format option for output with the following keys:
5656
cmds.StringOption("f", "format", "optional output format"),
5757
},
5858
Run: func(req cmds.Request, res cmds.Response) {
59-
node, err := req.Context().GetNode()
59+
node, err := req.InvocContext().GetNode()
6060
if err != nil {
6161
res.SetError(err, cmds.ErrNormal)
6262
return
@@ -86,7 +86,7 @@ ipfs id supports the format option for output with the following keys:
8686
return
8787
}
8888

89-
p, err := node.Routing.FindPeer(req.Context().Context, id)
89+
p, err := node.Routing.FindPeer(req.Context(), id)
9090
if err == kb.ErrLookupFailure {
9191
res.SetError(errors.New(offlineIdErrorMessage), cmds.ErrClient)
9292
return

‎core/commands/ipns.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Resolve the value of another name:
4747
},
4848
Run: func(req cmds.Request, res cmds.Response) {
4949

50-
n, err := req.Context().GetNode()
50+
n, err := req.InvocContext().GetNode()
5151
if err != nil {
5252
res.SetError(err, cmds.ErrNormal)
5353
return
@@ -81,7 +81,7 @@ Resolve the value of another name:
8181
}
8282

8383
resolver := namesys.NewRoutingResolver(n.Routing)
84-
output, err := resolver.ResolveN(n.Context(), name, depth)
84+
output, err := resolver.ResolveN(req.Context(), name, depth)
8585
if err != nil {
8686
res.SetError(err, cmds.ErrNormal)
8787
return

‎core/commands/log.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var logTailCmd = &cmds.Command{
8080
},
8181

8282
Run: func(req cmds.Request, res cmds.Response) {
83-
path := fmt.Sprintf("%s/logs/events.log", req.Context().ConfigRoot)
83+
path := fmt.Sprintf("%s/logs/events.log", req.InvocContext().ConfigRoot)
8484

8585
outChan := make(chan interface{})
8686

@@ -99,7 +99,7 @@ var logTailCmd = &cmds.Command{
9999
}
100100
defer t.Stop()
101101

102-
done := req.Context().Context.Done()
102+
done := req.Context().Done()
103103

104104
for line := range t.Lines {
105105
// return when context closes

‎core/commands/ls.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ it contains, with the following format:
5050
cmds.BoolOption("headers", "", "Print table headers (Hash, Name, Size)"),
5151
},
5252
Run: func(req cmds.Request, res cmds.Response) {
53-
node, err := req.Context().GetNode()
53+
node, err := req.InvocContext().GetNode()
5454
if err != nil {
5555
res.SetError(err, cmds.ErrNormal)
5656
return
@@ -66,7 +66,7 @@ it contains, with the following format:
6666

6767
var dagnodes []*merkledag.Node
6868
for _, fpath := range paths {
69-
dagnode, err := core.Resolve(req.Context().Context, node, path.Path(fpath))
69+
dagnode, err := core.Resolve(req.Context(), node, path.Path(fpath))
7070
if err != nil {
7171
res.SetError(err, cmds.ErrNormal)
7272
return
@@ -81,7 +81,7 @@ it contains, with the following format:
8181
Links: make([]LsLink, len(dagnode.Links)),
8282
}
8383
for j, link := range dagnode.Links {
84-
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute)
84+
ctx, cancel := context.WithTimeout(req.Context(), time.Minute)
8585
defer cancel()
8686
link.Node, err = link.GetNode(ctx, node.DAG)
8787
if err != nil {

‎core/commands/mount_unix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ baz
9797
cmds.StringOption("ipns-path", "n", "The path where IPNS should be mounted"),
9898
},
9999
Run: func(req cmds.Request, res cmds.Response) {
100-
cfg, err := req.Context().GetConfig()
100+
cfg, err := req.InvocContext().GetConfig()
101101
if err != nil {
102102
res.SetError(err, cmds.ErrNormal)
103103
return
104104
}
105105

106-
node, err := req.Context().GetNode()
106+
node, err := req.InvocContext().GetNode()
107107
if err != nil {
108108
res.SetError(err, cmds.ErrNormal)
109109
return

‎core/commands/object.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ output is the raw data of the object.
9393
cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format").EnableStdin(),
9494
},
9595
Run: func(req cmds.Request, res cmds.Response) {
96-
n, err := req.Context().GetNode()
96+
n, err := req.InvocContext().GetNode()
9797
if err != nil {
9898
res.SetError(err, cmds.ErrNormal)
9999
return
100100
}
101101

102102
fpath := path.Path(req.Arguments()[0])
103-
node, err := core.Resolve(req.Context().Context, n, fpath)
103+
node, err := core.Resolve(req.Context(), n, fpath)
104104
if err != nil {
105105
res.SetError(err, cmds.ErrNormal)
106106
return
@@ -123,14 +123,14 @@ multihash.
123123
cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format").EnableStdin(),
124124
},
125125
Run: func(req cmds.Request, res cmds.Response) {
126-
n, err := req.Context().GetNode()
126+
n, err := req.InvocContext().GetNode()
127127
if err != nil {
128128
res.SetError(err, cmds.ErrNormal)
129129
return
130130
}
131131

132132
fpath := path.Path(req.Arguments()[0])
133-
node, err := core.Resolve(req.Context().Context, n, fpath)
133+
node, err := core.Resolve(req.Context(), n, fpath)
134134
if err != nil {
135135
res.SetError(err, cmds.ErrNormal)
136136
return
@@ -182,15 +182,15 @@ This command outputs data in the following encodings:
182182
cmds.StringArg("key", true, false, "Key of the object to retrieve (in base58-encoded multihash format)").EnableStdin(),
183183
},
184184
Run: func(req cmds.Request, res cmds.Response) {
185-
n, err := req.Context().GetNode()
185+
n, err := req.InvocContext().GetNode()
186186
if err != nil {
187187
res.SetError(err, cmds.ErrNormal)
188188
return
189189
}
190190

191191
fpath := path.Path(req.Arguments()[0])
192192

193-
object, err := core.Resolve(req.Context().Context, n, fpath)
193+
object, err := core.Resolve(req.Context(), n, fpath)
194194
if err != nil {
195195
res.SetError(err, cmds.ErrNormal)
196196
return
@@ -248,15 +248,15 @@ var objectStatCmd = &cmds.Command{
248248
cmds.StringArg("key", true, false, "Key of the object to retrieve (in base58-encoded multihash format)").EnableStdin(),
249249
},
250250
Run: func(req cmds.Request, res cmds.Response) {
251-
n, err := req.Context().GetNode()
251+
n, err := req.InvocContext().GetNode()
252252
if err != nil {
253253
res.SetError(err, cmds.ErrNormal)
254254
return
255255
}
256256

257257
fpath := path.Path(req.Arguments()[0])
258258

259-
object, err := core.Resolve(req.Context().Context, n, fpath)
259+
object, err := core.Resolve(req.Context(), n, fpath)
260260
if err != nil {
261261
res.SetError(err, cmds.ErrNormal)
262262
return
@@ -335,7 +335,7 @@ and then run
335335
cmds.StringOption("inputenc", "Encoding type of input data, either \"protobuf\" or \"json\""),
336336
},
337337
Run: func(req cmds.Request, res cmds.Response) {
338-
n, err := req.Context().GetNode()
338+
n, err := req.InvocContext().GetNode()
339339
if err != nil {
340340
res.SetError(err, cmds.ErrNormal)
341341
return
@@ -397,7 +397,7 @@ Available templates:
397397
cmds.StringArg("template", false, false, "optional template to use"),
398398
},
399399
Run: func(req cmds.Request, res cmds.Response) {
400-
n, err := req.Context().GetNode()
400+
n, err := req.InvocContext().GetNode()
401401
if err != nil {
402402
res.SetError(err, cmds.ErrNormal)
403403
return
@@ -461,7 +461,7 @@ resulting object hash.
461461
},
462462
Type: Object{},
463463
Run: func(req cmds.Request, res cmds.Response) {
464-
nd, err := req.Context().GetNode()
464+
nd, err := req.InvocContext().GetNode()
465465
if err != nil {
466466
res.SetError(err, cmds.ErrNormal)
467467
return
@@ -473,7 +473,7 @@ resulting object hash.
473473
return
474474
}
475475

476-
ctx, cancel := context.WithTimeout(req.Context().Context, time.Second*30)
476+
ctx, cancel := context.WithTimeout(req.Context(), time.Second*30)
477477
rnode, err := nd.DAG.Get(ctx, rhash)
478478
if err != nil {
479479
res.SetError(err, cmds.ErrNormal)
@@ -535,7 +535,7 @@ func appendDataCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
535535
return "", fmt.Errorf("not enough arguments for set-data")
536536
}
537537

538-
nd, err := req.Context().GetNode()
538+
nd, err := req.InvocContext().GetNode()
539539
if err != nil {
540540
return "", err
541541
}
@@ -555,7 +555,7 @@ func setDataCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
555555
return "", fmt.Errorf("not enough arguments for set-data")
556556
}
557557

558-
nd, err := req.Context().GetNode()
558+
nd, err := req.InvocContext().GetNode()
559559
if err != nil {
560560
return "", err
561561
}
@@ -575,7 +575,7 @@ func rmLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
575575
return "", fmt.Errorf("not enough arguments for rm-link")
576576
}
577577

578-
nd, err := req.Context().GetNode()
578+
nd, err := req.InvocContext().GetNode()
579579
if err != nil {
580580
return "", err
581581
}
@@ -600,7 +600,7 @@ func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
600600
return "", fmt.Errorf("not enough arguments for add-link")
601601
}
602602

603-
nd, err := req.Context().GetNode()
603+
nd, err := req.InvocContext().GetNode()
604604
if err != nil {
605605
return "", err
606606
}
@@ -610,7 +610,7 @@ func addLinkCaller(req cmds.Request, root *dag.Node) (key.Key, error) {
610610

611611
parts := strings.Split(path, "/")
612612

613-
nnode, err := insertNodeAtPath(req.Context().Context, nd.DAG, root, parts, childk)
613+
nnode, err := insertNodeAtPath(req.Context(), nd.DAG, root, parts, childk)
614614
if err != nil {
615615
return "", err
616616
}

‎core/commands/pin.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ on disk.
4444
},
4545
Type: PinOutput{},
4646
Run: func(req cmds.Request, res cmds.Response) {
47-
n, err := req.Context().GetNode()
47+
n, err := req.InvocContext().GetNode()
4848
if err != nil {
4949
res.SetError(err, cmds.ErrNormal)
5050
return
@@ -60,7 +60,12 @@ on disk.
6060
recursive = false
6161
}
6262

63-
added, err := corerepo.Pin(n, req.Arguments(), recursive)
63+
go func() {
64+
<-req.Context().Done()
65+
log.Error("CONTEXT IS OVER!")
66+
}()
67+
68+
added, err := corerepo.Pin(n, req.Context(), req.Arguments(), recursive)
6469
if err != nil {
6570
res.SetError(err, cmds.ErrNormal)
6671
return
@@ -109,7 +114,7 @@ collected if needed.
109114
},
110115
Type: PinOutput{},
111116
Run: func(req cmds.Request, res cmds.Response) {
112-
n, err := req.Context().GetNode()
117+
n, err := req.InvocContext().GetNode()
113118
if err != nil {
114119
res.SetError(err, cmds.ErrNormal)
115120
return
@@ -125,7 +130,7 @@ collected if needed.
125130
recursive = false // default
126131
}
127132

128-
removed, err := corerepo.Unpin(n, req.Arguments(), recursive)
133+
removed, err := corerepo.Unpin(n, req.Context(), req.Arguments(), recursive)
129134
if err != nil {
130135
res.SetError(err, cmds.ErrNormal)
131136
return
@@ -177,7 +182,7 @@ Defaults to "direct".
177182
cmds.BoolOption("quiet", "q", "Write just hashes of objects"),
178183
},
179184
Run: func(req cmds.Request, res cmds.Response) {
180-
n, err := req.Context().GetNode()
185+
n, err := req.InvocContext().GetNode()
181186
if err != nil {
182187
res.SetError(err, cmds.ErrNormal)
183188
return

‎core/commands/ping.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ trip latency information.
7575
},
7676
},
7777
Run: func(req cmds.Request, res cmds.Response) {
78-
ctx := req.Context().Context
79-
n, err := req.Context().GetNode()
78+
ctx := req.Context()
79+
n, err := req.InvocContext().GetNode()
8080
if err != nil {
8181
res.SetError(err, cmds.ErrNormal)
8282
return

‎core/commands/publish.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Publish an <ipfs-path> to another public key (not implemented):
5151
},
5252
Run: func(req cmds.Request, res cmds.Response) {
5353
log.Debug("Begin Publish")
54-
n, err := req.Context().GetNode()
54+
n, err := req.InvocContext().GetNode()
5555
if err != nil {
5656
res.SetError(err, cmds.ErrNormal)
5757
return
@@ -90,7 +90,7 @@ Publish an <ipfs-path> to another public key (not implemented):
9090

9191
// TODO n.Keychain.Get(name).PrivKey
9292
// TODO(cryptix): is req.Context().Context a child of n.Context()?
93-
output, err := publish(req.Context().Context, n, n.PrivateKey, path.Path(pstr))
93+
output, err := publish(req.Context(), n, n.PrivateKey, path.Path(pstr))
9494
if err != nil {
9595
res.SetError(err, cmds.ErrNormal)
9696
return

‎core/commands/refs.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Note: list all refs recursively with -r.
5656
cmds.BoolOption("recursive", "r", "Recursively list links of child nodes"),
5757
},
5858
Run: func(req cmds.Request, res cmds.Response) {
59-
ctx := req.Context().Context
60-
n, err := req.Context().GetNode()
59+
ctx := req.Context()
60+
n, err := req.InvocContext().GetNode()
6161
if err != nil {
6262
res.SetError(err, cmds.ErrNormal)
6363
return
@@ -156,8 +156,8 @@ Displays the hashes of all local objects.
156156
},
157157

158158
Run: func(req cmds.Request, res cmds.Response) {
159-
ctx := req.Context().Context
160-
n, err := req.Context().GetNode()
159+
ctx := req.Context()
160+
n, err := req.InvocContext().GetNode()
161161
if err != nil {
162162
res.SetError(err, cmds.ErrNormal)
163163
return

‎core/commands/repo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ order to reclaim hard disk space.
3737
cmds.BoolOption("quiet", "q", "Write minimal output"),
3838
},
3939
Run: func(req cmds.Request, res cmds.Response) {
40-
n, err := req.Context().GetNode()
40+
n, err := req.InvocContext().GetNode()
4141
if err != nil {
4242
res.SetError(err, cmds.ErrNormal)
4343
return
4444
}
4545

46-
gcOutChan, err := corerepo.GarbageCollectAsync(n, req.Context().Context)
46+
gcOutChan, err := corerepo.GarbageCollectAsync(n, req.Context())
4747
if err != nil {
4848
res.SetError(err, cmds.ErrNormal)
4949
return

‎core/commands/resolve.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Resolve the value of another name recursively:
5757
},
5858
Run: func(req cmds.Request, res cmds.Response) {
5959

60-
n, err := req.Context().GetNode()
60+
n, err := req.InvocContext().GetNode()
6161
if err != nil {
6262
res.SetError(err, cmds.ErrNormal)
6363
return
@@ -78,7 +78,7 @@ Resolve the value of another name recursively:
7878
depth = namesys.DefaultDepthLimit
7979
}
8080

81-
output, err := n.Namesys.ResolveN(n.Context(), name, depth)
81+
output, err := n.Namesys.ResolveN(req.Context(), name, depth)
8282
if err != nil {
8383
res.SetError(err, cmds.ErrNormal)
8484
return

‎core/commands/stat.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var statBwCmd = &cmds.Command{
4040
},
4141

4242
Run: func(req cmds.Request, res cmds.Response) {
43-
nd, err := req.Context().GetNode()
43+
nd, err := req.InvocContext().GetNode()
4444
if err != nil {
4545
res.SetError(err, cmds.ErrNormal)
4646
return
@@ -121,7 +121,7 @@ var statBwCmd = &cmds.Command{
121121
}
122122
select {
123123
case <-time.After(interval):
124-
case <-req.Context().Context.Done():
124+
case <-req.Context().Done():
125125
return
126126
}
127127
}

‎core/commands/swarm.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ipfs swarm peers lists the set of peers this node is connected to.
6161
Run: func(req cmds.Request, res cmds.Response) {
6262

6363
log.Debug("ipfs swarm peers")
64-
n, err := req.Context().GetNode()
64+
n, err := req.InvocContext().GetNode()
6565
if err != nil {
6666
res.SetError(err, cmds.ErrNormal)
6767
return
@@ -101,7 +101,7 @@ ipfs swarm addrs lists all addresses this node is aware of.
101101
},
102102
Run: func(req cmds.Request, res cmds.Response) {
103103

104-
n, err := req.Context().GetNode()
104+
n, err := req.InvocContext().GetNode()
105105
if err != nil {
106106
res.SetError(err, cmds.ErrNormal)
107107
return
@@ -164,7 +164,7 @@ ipfs swarm addrs local lists all local addresses the node is listening on.
164164
},
165165
Run: func(req cmds.Request, res cmds.Response) {
166166

167-
n, err := req.Context().GetNode()
167+
n, err := req.InvocContext().GetNode()
168168
if err != nil {
169169
res.SetError(err, cmds.ErrNormal)
170170
return
@@ -213,7 +213,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
213213
Run: func(req cmds.Request, res cmds.Response) {
214214
ctx := context.TODO()
215215

216-
n, err := req.Context().GetNode()
216+
n, err := req.InvocContext().GetNode()
217217
if err != nil {
218218
res.SetError(err, cmds.ErrNormal)
219219
return
@@ -266,7 +266,7 @@ ipfs swarm disconnect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQA
266266
cmds.StringArg("address", true, true, "address of peer to connect to").EnableStdin(),
267267
},
268268
Run: func(req cmds.Request, res cmds.Response) {
269-
n, err := req.Context().GetNode()
269+
n, err := req.InvocContext().GetNode()
270270
if err != nil {
271271
res.SetError(err, cmds.ErrNormal)
272272
return
@@ -386,7 +386,7 @@ Filters default to those specified under the "Swarm.AddrFilters" config key.
386386
"rm": swarmFiltersRmCmd,
387387
},
388388
Run: func(req cmds.Request, res cmds.Response) {
389-
n, err := req.Context().GetNode()
389+
n, err := req.InvocContext().GetNode()
390390
if err != nil {
391391
res.SetError(err, cmds.ErrNormal)
392392
return
@@ -433,7 +433,7 @@ add your filters to the ipfs config file.
433433
cmds.StringArg("address", true, true, "multiaddr to filter").EnableStdin(),
434434
},
435435
Run: func(req cmds.Request, res cmds.Response) {
436-
n, err := req.Context().GetNode()
436+
n, err := req.InvocContext().GetNode()
437437
if err != nil {
438438
res.SetError(err, cmds.ErrNormal)
439439
return
@@ -475,7 +475,7 @@ remove your filters from the ipfs config file.
475475
cmds.StringArg("address", true, true, "multiaddr filter to remove").EnableStdin(),
476476
},
477477
Run: func(req cmds.Request, res cmds.Response) {
478-
n, err := req.Context().GetNode()
478+
n, err := req.InvocContext().GetNode()
479479
if err != nil {
480480
res.SetError(err, cmds.ErrNormal)
481481
return

‎core/commands/tour.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ IPFS very quickly. To start, run:
3737

3838
func tourRunFunc(req cmds.Request, res cmds.Response) {
3939

40-
cfg, err := req.Context().GetConfig()
40+
cfg, err := req.InvocContext().GetConfig()
4141
if err != nil {
4242
res.SetError(err, cmds.ErrNormal)
4343
return
@@ -78,8 +78,8 @@ var cmdIpfsTourNext = &cmds.Command{
7878

7979
Run: func(req cmds.Request, res cmds.Response) {
8080
w := new(bytes.Buffer)
81-
path := req.Context().ConfigRoot
82-
cfg, err := req.Context().GetConfig()
81+
path := req.InvocContext().ConfigRoot
82+
cfg, err := req.InvocContext().GetConfig()
8383
if err != nil {
8484
res.SetError(err, cmds.ErrNormal)
8585
return
@@ -116,8 +116,8 @@ var cmdIpfsTourRestart = &cmds.Command{
116116
},
117117

118118
Run: func(req cmds.Request, res cmds.Response) {
119-
path := req.Context().ConfigRoot
120-
cfg, err := req.Context().GetConfig()
119+
path := req.InvocContext().ConfigRoot
120+
cfg, err := req.InvocContext().GetConfig()
121121
if err != nil {
122122
res.SetError(err, cmds.ErrNormal)
123123
return
@@ -138,7 +138,7 @@ var cmdIpfsTourList = &cmds.Command{
138138
},
139139

140140
Run: func(req cmds.Request, res cmds.Response) {
141-
cfg, err := req.Context().GetConfig()
141+
cfg, err := req.InvocContext().GetConfig()
142142
if err != nil {
143143
res.SetError(err, cmds.ErrNormal)
144144
return

‎core/commands/unixfs/ls.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ size is the IPFS link size.
5252
cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from").EnableStdin(),
5353
},
5454
Run: func(req cmds.Request, res cmds.Response) {
55-
node, err := req.Context().GetNode()
55+
node, err := req.InvocContext().GetNode()
5656
if err != nil {
5757
res.SetError(err, cmds.ErrNormal)
5858
return
@@ -66,7 +66,7 @@ size is the IPFS link size.
6666
}
6767

6868
for _, fpath := range paths {
69-
ctx := req.Context().Context
69+
ctx := req.Context()
7070
merkleNode, err := core.Resolve(ctx, node, path.Path(fpath))
7171
if err != nil {
7272
res.SetError(err, cmds.ErrNormal)

‎core/commands/update.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var updateCmd = &cmds.Command{
3333
},
3434

3535
Run: func(req cmds.Request, res cmds.Response) {
36-
n, err := req.Context().GetNode()
36+
n, err := req.InvocContext().GetNode()
3737
if err != nil {
3838
res.SetError(err, cmds.ErrNormal)
3939
return
@@ -73,7 +73,7 @@ var UpdateCheckCmd = &cmds.Command{
7373
},
7474

7575
Run: func(req cmds.Request, res cmds.Response) {
76-
n, err := req.Context().GetNode()
76+
n, err := req.InvocContext().GetNode()
7777
if err != nil {
7878
res.SetError(err, cmds.ErrNormal)
7979
return
@@ -109,7 +109,7 @@ var UpdateLogCmd = &cmds.Command{
109109
},
110110

111111
Run: func(req cmds.Request, res cmds.Response) {
112-
n, err := req.Context().GetNode()
112+
n, err := req.InvocContext().GetNode()
113113
if err != nil {
114114
res.SetError(err, cmds.ErrNormal)
115115
return

‎core/corerepo/pinning.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ import (
2525
path "github.com/ipfs/go-ipfs/path"
2626
)
2727

28-
func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]key.Key, error) {
29-
// TODO(cryptix): do we want a ctx as first param for (Un)Pin() as well, just like core.Resolve?
30-
ctx := n.Context()
31-
28+
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]key.Key, error) {
3229
dagnodes := make([]*merkledag.Node, 0)
3330
for _, fpath := range paths {
3431
dagnode, err := core.Resolve(ctx, n, path.Path(fpath))
@@ -62,9 +59,7 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]key.Key, error) {
6259
return out, nil
6360
}
6461

65-
func Unpin(n *core.IpfsNode, paths []string, recursive bool) ([]key.Key, error) {
66-
// TODO(cryptix): do we want a ctx as first param for (Un)Pin() as well, just like core.Resolve?
67-
ctx := n.Context()
62+
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]key.Key, error) {
6863

6964
dagnodes := make([]*merkledag.Node, 0)
7065
for _, fpath := range paths {

‎test/sharness/t0081-repo-pinning.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ test_expect_success "some are no longer there" '
242242

243243
test_expect_success "recursive pin fails without objects" '
244244
ipfs pin rm "$HASH_DIR1" &&
245-
test_must_fail ipfs pin add -r "$HASH_DIR1" 2>err_expected8 &&
245+
test_must_fail ipfs pin add -r "$HASH_DIR1" --timeout=500ms 2>err_expected8 &&
246246
grep "context deadline exceeded" err_expected8
247247
'
248248

‎test/supernode_client/main.go

-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ func toPeerInfo(bootstrap config.BootstrapPeer) (p peer.PeerInfo, err error) {
233233

234234
func cmdCtx(node *core.IpfsNode, repoPath string) commands.Context {
235235
return commands.Context{
236-
// TODO deprecate this shit
237-
Context: context.Background(),
238236
Online: true,
239237
ConfigRoot: repoPath,
240238
LoadConfig: func(path string) (*config.Config, error) {

0 commit comments

Comments
 (0)
Please sign in to comment.