@cryptotaxi247 / kubo / commits / 51bf1b6cd

Significanly improve GC UX with verifcid

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

Jakub Sztandera committed Mar 4, 2018 at 01:29 UTC 51bf1b6cd4f1fa2bb2fa0a57d0af6a3e430b5af7
2 files changed +35 -1
core/commands/pin.go
+10
@@ -17,6 +17,7 @@ import (
17 path "github.com/ipfs/go-ipfs/path"
18 resolver "github.com/ipfs/go-ipfs/path/resolver"
19 pin "github.com/ipfs/go-ipfs/pin"
20 + "github.com/ipfs/go-ipfs/thirdparty/verifcid"
21 uio "github.com/ipfs/go-ipfs/unixfs/io"
22
23 u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
@@ -608,6 +609,15 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
609 return status
610 }
611
612 + if err := verifcid.ValidateCid(root); err != nil {
613 + status := PinStatus{Ok: false}
614 + if opts.explain {
615 + status.BadNodes = []BadNode{BadNode{Cid: key, Err: err.Error()}}
616 + }
617 + visited[key] = status
618 + return status
619 + }
620 +
621 links, err := getLinks(ctx, root)
622 if err != nil {
623 status := PinStatus{Ok: false}
pin/gc/gc.go
+25 -1
@@ -5,11 +5,13 @@ import (
5 "context"
6 "errors"
7 "fmt"
8 + "strings"
9
10 bserv "github.com/ipfs/go-ipfs/blockservice"
11 offline "github.com/ipfs/go-ipfs/exchange/offline"
12 dag "github.com/ipfs/go-ipfs/merkledag"
13 pin "github.com/ipfs/go-ipfs/pin"
14 + "github.com/ipfs/go-ipfs/thirdparty/verifcid"
15
16 dstore "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
17 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
@@ -129,12 +131,34 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
131 // adds them to the given cid.Set, using the provided dag.GetLinks function
132 // to walk the tree.
133 func Descendants(ctx context.Context, getLinks dag.GetLinks, set *cid.Set, roots []*cid.Cid) error {
134 + verifyGetLinks := func(ctx context.Context, c *cid.Cid) ([]*ipld.Link, error) {
135 + err := verifcid.ValidateCid(c)
136 + if err != nil {
137 + return nil, err
138 + }
139 +
140 + return getLinks(ctx, c)
141 + }
142 +
143 + verboseCidError := func(err error) error {
144 + if strings.Contains(err.Error(), verifcid.ErrBelowMinimumHashLength.Error()) ||
145 + strings.Contains(err.Error(), verifcid.ErrPossiblyInsecureHashFunction.Error()) {
146 + err = fmt.Errorf("\"%s\"\nPlease run 'ipfs pin verify'"+
147 + " to list insecure hashes. If you want to read them,"+
148 + " please downgrade your go-ipfs to 0.4.13\n", err)
149 + log.Error(err)
150 + }
151 + return err
152 + }
153 +
154 for _, c := range roots {
155 set.Add(c)
156
157 // EnumerateChildren recursively walks the dag and adds the keys to the given set
136 - err := dag.EnumerateChildren(ctx, getLinks, c, set.Visit)
158 + err := dag.EnumerateChildren(ctx, verifyGetLinks, c, set.Visit)
159 +
160 if err != nil {
161 + err = verboseCidError(err)
162 return err
163 }
164 }