Skip to content

Commit 2662e8f

Browse files
committed
fix: traverser should skip over identity CIDs
1 parent bb8a59c commit 2662e8f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ipldutil/traverser.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package ipldutil
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"io"
78
"sync"
89

10+
"github.com/ipfs/go-cid"
911
dagpb "github.com/ipld/go-codec-dagpb"
1012
"github.com/ipld/go-ipld-prime"
1113
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1214
"github.com/ipld/go-ipld-prime/node/basicnode"
1315
"github.com/ipld/go-ipld-prime/traversal"
1416
"github.com/ipld/go-ipld-prime/traversal/selector"
17+
"github.com/multiformats/go-multihash"
1518

1619
"github.com/filecoin-project/boost-graphsync/panics"
1720
)
@@ -165,7 +168,23 @@ func (t *traverser) NBlocksTraversed() int {
165168
return t.blocksCount
166169
}
167170

171+
func asIdentity(c cid.Cid) (digest []byte, ok bool, err error) {
172+
dmh, err := multihash.Decode(c.Hash())
173+
if err != nil {
174+
return nil, false, err
175+
}
176+
ok = dmh.Code == multihash.IDENTITY
177+
digest = dmh.Digest
178+
return digest, ok, nil
179+
}
180+
168181
func (t *traverser) loader(lnkCtx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {
182+
if digest, ok, err := asIdentity(lnk.(cidlink.Link).Cid); ok {
183+
return io.NopCloser(bytes.NewReader(digest)), nil
184+
} else if err != nil {
185+
return nil, err
186+
}
187+
169188
// A StorageReadOpener call came in; update the state and release the lock.
170189
// We can't simply unlock the mutex inside the <-t.responses case,
171190
// as then we'd deadlock with the other side trying to send.

0 commit comments

Comments
 (0)