diff --git a/core/commands/pin.go b/core/commands/pin.go index d27b0212110c..bb10519185e6 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -12,6 +12,7 @@ import ( cid "github.com/ipfs/go-cid" cidenc "github.com/ipfs/go-cidutil/cidenc" cmds "github.com/ipfs/go-ipfs-cmds" + exchange "github.com/ipfs/go-ipfs-exchange-interface" offline "github.com/ipfs/go-ipfs-exchange-offline" pin "github.com/ipfs/go-ipfs-pinner" ipld "github.com/ipfs/go-ipld-format" @@ -186,20 +187,32 @@ var addPinCmd = &cmds.Command{ func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder, paths []string, recursive bool) ([]string, error) { added := make([]string, len(paths)) for i, b := range paths { - rp, err := api.ResolvePath(ctx, path.New(b)) + rp, err := pinAdd(ctx, api, path.New(b), recursive) if err != nil { return nil, err } - - if err := api.Pin().Add(ctx, rp, options.Pin.Recursive(recursive)); err != nil { - return nil, err - } added[i] = enc.Encode(rp.Cid()) } return added, nil } +func pinAdd(ctx context.Context, api coreiface.CoreAPI, path path.Path, recursive bool) (path.Resolved, error) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + ctx = exchange.NewSession(ctx) + + rp, err := api.ResolvePath(ctx, path) + if err != nil { + return nil, err + } + + if err := api.Pin().Add(ctx, rp, options.Pin.Recursive(recursive)); err != nil { + return nil, err + } + return rp, nil +} + var rmPinCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Remove pinned objects from local storage.", diff --git a/core/commands/refs.go b/core/commands/refs.go index 4a7285cc95c3..19ab8c8432e2 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -7,6 +7,7 @@ import ( "io" "strings" + exchange "github.com/ipfs/go-ipfs-exchange-interface" cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" cid "github.com/ipfs/go-cid" @@ -102,6 +103,12 @@ NOTE: List all references recursively by using the flag '-r'. format = " -> " } + // Assume all these requests are related and put them into a + // single session. + ctx, cancel := context.WithCancel(ctx) + ctx = exchange.NewSession(ctx) + defer cancel() + objs, err := objectsForPaths(ctx, api, req.Arguments) if err != nil { return err diff --git a/core/coreapi/pin.go b/core/coreapi/pin.go index 70b69b5b36c1..a3b59d3dd973 100644 --- a/core/coreapi/pin.go +++ b/core/coreapi/pin.go @@ -3,8 +3,10 @@ package coreapi import ( "context" "fmt" + bserv "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" + exchange "github.com/ipfs/go-ipfs-exchange-interface" offline "github.com/ipfs/go-ipfs-exchange-offline" pin "github.com/ipfs/go-ipfs-pinner" ipld "github.com/ipfs/go-ipld-format" @@ -17,6 +19,8 @@ import ( type PinAPI CoreAPI func (api *PinAPI) Add(ctx context.Context, p path.Path, opts ...caopts.PinAddOption) error { + ctx = exchange.NewSession(ctx) + dagNode, err := api.core().ResolveNode(ctx, p) if err != nil { return fmt.Errorf("pin: %s", err) @@ -80,6 +84,8 @@ func (api *PinAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.PinRmOpti } func (api *PinAPI) Update(ctx context.Context, from path.Path, to path.Path, opts ...caopts.PinUpdateOption) error { + ctx = exchange.NewSession(ctx) + settings, err := caopts.PinUpdateOptions(opts...) if err != nil { return err diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index f91d42b61600..fdb1ed943f45 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -16,6 +16,7 @@ import ( humanize "github.com/dustin/go-humanize" "github.com/ipfs/go-cid" + exchange "github.com/ipfs/go-ipfs-exchange-interface" files "github.com/ipfs/go-ipfs-files" dag "github.com/ipfs/go-merkledag" mfs "github.com/ipfs/go-mfs" @@ -89,6 +90,11 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // the hour is a hard fallback, we don't expect it to happen, but just in case ctx, cancel := context.WithTimeout(r.Context(), time.Hour) defer cancel() + + // Always create a root session for http requests. + // That way we do all path resolution etc in the same session. + ctx = exchange.NewSession(ctx) + r = r.WithContext(ctx) defer func() { diff --git a/go.mod b/go.mod index fe9c69970883..f3290fc63697 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gogo/protobuf v1.3.1 github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/golang-lru v0.5.4 - github.com/ipfs/go-bitswap v0.2.11 + github.com/ipfs/go-bitswap v0.2.12-0.20200423051144-fa8848292027 github.com/ipfs/go-block-format v0.0.2 github.com/ipfs/go-blockservice v0.1.3 github.com/ipfs/go-cid v0.0.5 @@ -33,7 +33,7 @@ require ( github.com/ipfs/go-ipfs-cmds v0.2.2 github.com/ipfs/go-ipfs-config v0.5.2 github.com/ipfs/go-ipfs-ds-help v0.1.1 - github.com/ipfs/go-ipfs-exchange-interface v0.0.1 + github.com/ipfs/go-ipfs-exchange-interface v0.0.2-0.20200423055703-2e8ddd22ab43 github.com/ipfs/go-ipfs-exchange-offline v0.0.1 github.com/ipfs/go-ipfs-files v0.0.8 github.com/ipfs/go-ipfs-pinner v0.0.4 @@ -46,7 +46,7 @@ require ( github.com/ipfs/go-ipld-git v0.0.3 github.com/ipfs/go-ipns v0.0.2 github.com/ipfs/go-log v1.0.4 - github.com/ipfs/go-merkledag v0.3.1 + github.com/ipfs/go-merkledag v0.3.2-0.20200423061109-59b2ffa4efde github.com/ipfs/go-metrics-interface v0.0.1 github.com/ipfs/go-metrics-prometheus v0.0.2 github.com/ipfs/go-mfs v0.1.1 diff --git a/go.sum b/go.sum index 2fbc7c1f6acc..882f4fc280c5 100644 --- a/go.sum +++ b/go.sum @@ -212,8 +212,8 @@ github.com/ipfs/go-bitswap v0.1.0/go.mod h1:FFJEf18E9izuCqUtHxbWEvq+reg7o4CW5wSA github.com/ipfs/go-bitswap v0.1.2/go.mod h1:qxSWS4NXGs7jQ6zQvoPY3+NmOfHHG47mhkiLzBpJQIs= github.com/ipfs/go-bitswap v0.1.3/go.mod h1:YEQlFy0kkxops5Vy+OxWdRSEZIoS7I7KDIwoa5Chkps= github.com/ipfs/go-bitswap v0.1.8/go.mod h1:TOWoxllhccevbWFUR2N7B1MTSVVge1s6XSMiCSA4MzM= -github.com/ipfs/go-bitswap v0.2.11 h1:BN9wu9bv55FzGYX7RQ0UdNtBisLzy++6JC+mseSZqIs= -github.com/ipfs/go-bitswap v0.2.11/go.mod h1:SDXpLeKZagyVVc8/z7sGtmM/lz8lyAmSzrUx3Ge3GXw= +github.com/ipfs/go-bitswap v0.2.12-0.20200423051144-fa8848292027 h1:4zbxNF/vrSw1zV3hfJ3lEmYoVCcCS50ZEw4Kn/sroB4= +github.com/ipfs/go-bitswap v0.2.12-0.20200423051144-fa8848292027/go.mod h1:2lkrFZYpk4VxBIC+blbKYSmqfAySh7bhbmEW/hT68+s= github.com/ipfs/go-block-format v0.0.1/go.mod h1:DK/YYcsSUIVAFNwo/KZCdIIbpN0ROH/baNLgayt4pFc= github.com/ipfs/go-block-format v0.0.2 h1:qPDvcP19izTjU8rgo6p7gTXZlkMkF5bz5G3fqIsSCPE= github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= @@ -302,6 +302,9 @@ github.com/ipfs/go-ipfs-ds-help v0.1.1 h1:IW/bXGeaAZV2VH0Kuok+Ohva/zHkHmeLFBxC1k github.com/ipfs/go-ipfs-ds-help v0.1.1/go.mod h1:SbBafGJuGsPI/QL3j9Fc5YPLeAu+SzOkI0gFwAg+mOs= github.com/ipfs/go-ipfs-exchange-interface v0.0.1 h1:LJXIo9W7CAmugqI+uofioIpRb6rY30GUu7G6LUfpMvM= github.com/ipfs/go-ipfs-exchange-interface v0.0.1/go.mod h1:c8MwfHjtQjPoDyiy9cFquVtVHkO9b9Ob3FG91qJnWCM= +github.com/ipfs/go-ipfs-exchange-interface v0.0.2-0.20200423051052-ccb5de3a8346/go.mod h1:uChpHomshgrKU+8Uh6y1bh3SKn0jBRrdz4tHGKdDYao= +github.com/ipfs/go-ipfs-exchange-interface v0.0.2-0.20200423055703-2e8ddd22ab43 h1:m6tthCWsKZHixR2WqO4O5Hq61nRIS13NVxPA/LsFWPE= +github.com/ipfs/go-ipfs-exchange-interface v0.0.2-0.20200423055703-2e8ddd22ab43/go.mod h1:uChpHomshgrKU+8Uh6y1bh3SKn0jBRrdz4tHGKdDYao= github.com/ipfs/go-ipfs-exchange-offline v0.0.1 h1:P56jYKZF7lDDOLx5SotVh5KFxoY6C81I1NSHW1FxGew= github.com/ipfs/go-ipfs-exchange-offline v0.0.1/go.mod h1:WhHSFCVYX36H/anEKQboAzpUws3x7UeEGkzQc3iNkM0= github.com/ipfs/go-ipfs-files v0.0.2/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= @@ -314,7 +317,6 @@ github.com/ipfs/go-ipfs-pinner v0.0.4 h1:EmxhS3vDsCK/rZrsgxX0Le9m2drBcGlUd7ah/Vy github.com/ipfs/go-ipfs-pinner v0.0.4/go.mod h1:s4kFZWLWGDudN8Jyd/GTpt222A12C2snA2+OTdy/7p8= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= -github.com/ipfs/go-ipfs-pq v0.0.1 h1:zgUotX8dcAB/w/HidJh1zzc1yFq6Vm8J7T2F4itj/RU= github.com/ipfs/go-ipfs-pq v0.0.1/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY= github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= github.com/ipfs/go-ipfs-pq v0.0.2/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY= @@ -361,13 +363,12 @@ github.com/ipfs/go-log/v2 v2.0.5/go.mod h1:eZs4Xt4ZUJQFM3DlanGhy7TkwwawCZcSByscw github.com/ipfs/go-merkledag v0.0.3/go.mod h1:Oc5kIXLHokkE1hWGMBHw+oxehkAaTOqtEb7Zbh6BhLA= github.com/ipfs/go-merkledag v0.0.6/go.mod h1:QYPdnlvkOg7GnQRofu9XZimC5ZW5Wi3bKys/4GQQfto= github.com/ipfs/go-merkledag v0.1.0/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= -github.com/ipfs/go-merkledag v0.2.3 h1:aMdkK9G1hEeNvn3VXfiEMLY0iJnbiQQUHnM0HFJREsE= github.com/ipfs/go-merkledag v0.2.3/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= github.com/ipfs/go-merkledag v0.2.4/go.mod h1:SQiXrtSts3KGNmgOzMICy5c0POOpUNQLvB3ClKnBAlk= -github.com/ipfs/go-merkledag v0.3.0 h1:1bXv/ZRPZLVdij/a33CkXMVdxUdred9sz4xyph+0ls0= github.com/ipfs/go-merkledag v0.3.0/go.mod h1:4pymaZLhSLNVuiCITYrpViD6vmfZ/Ws4n/L9tfNv3S4= -github.com/ipfs/go-merkledag v0.3.1 h1:3UqWINBEr3/N+r6OwgFXAddDP/8zpQX/8J7IGVOCqRQ= github.com/ipfs/go-merkledag v0.3.1/go.mod h1:fvkZNNZixVW6cKSZ/JfLlON5OlgTXNdRLz0p6QG/I2M= +github.com/ipfs/go-merkledag v0.3.2-0.20200423061109-59b2ffa4efde h1:bWYCZGl1VKnXUVkLhT/4Bn0OY9JuTsTvckLqOpCNpIg= +github.com/ipfs/go-merkledag v0.3.2-0.20200423061109-59b2ffa4efde/go.mod h1:v/YrENXnd3fuLUb8USpUavtceC90CegoDif+wiY/ttw= github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= github.com/ipfs/go-metrics-prometheus v0.0.2 h1:9i2iljLg12S78OhC6UAiXi176xvQGiZaGVF1CUVdE+s= @@ -379,7 +380,6 @@ github.com/ipfs/go-path v0.0.7 h1:H06hKMquQ0aYtHiHryOMLpQC1qC3QwXwkahcEVD51Ho= github.com/ipfs/go-path v0.0.7/go.mod h1:6KTKmeRnBXgqrTvzFrPV3CamxcgvXX/4z79tfAd2Sno= github.com/ipfs/go-peertaskqueue v0.0.4/go.mod h1:03H8fhyeMfKNFWqzYEVyMbcPUeYrqP1MX6Kd+aN+rMQ= github.com/ipfs/go-peertaskqueue v0.1.0/go.mod h1:Jmk3IyCcfl1W3jTW3YpghSwSEC6IJ3Vzz/jUmWw8Z0U= -github.com/ipfs/go-peertaskqueue v0.1.1 h1:+gPjbI+V3NktXZOqJA1kzbms2pYmhjgQQal0MzZrOAY= github.com/ipfs/go-peertaskqueue v0.1.1/go.mod h1:Jmk3IyCcfl1W3jTW3YpghSwSEC6IJ3Vzz/jUmWw8Z0U= github.com/ipfs/go-peertaskqueue v0.2.0 h1:2cSr7exUGKYyDeUyQ7P/nHPs9P7Ht/B+ROrpN1EJOjc= github.com/ipfs/go-peertaskqueue v0.2.0/go.mod h1:5/eNrBEbtSKWCG+kQK8K8fGNixoYUnr+P7jivavs9lY= @@ -399,7 +399,6 @@ github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785/go.mod h1:bDD github.com/ipld/go-ipld-prime-proto v0.0.0-20191113031812-e32bd156a1e5 h1:lSip43rAdyGA+yRQuy6ju0ucZkWpYc1F2CTQtZTVW/4= github.com/ipld/go-ipld-prime-proto v0.0.0-20191113031812-e32bd156a1e5/go.mod h1:gcvzoEDBjwycpXt3LBE061wT9f46szXGHAmj9uoP6fU= github.com/jackpal/gateway v1.0.4/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= -github.com/jackpal/gateway v1.0.4/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= @@ -758,7 +757,6 @@ github.com/marten-seemann/qtls v0.9.0 h1:8Zguhc72eS+DH5EAb0BpAPIy3HDXYcihQi4xoDZ github.com/marten-seemann/qtls v0.9.0/go.mod h1:T1MmAdDPyISzxlK6kjRr0pcZFBVd1OZbBb/j3cvzHhk= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= -github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=