Skip to content

Commit

Permalink
fix: traverser should skip over identity CIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Sep 19, 2023
1 parent 94b2566 commit 1be7c1a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ipldutil/traverser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ipldutil

import (
"bytes"
"context"
"errors"
"io"
Expand All @@ -12,7 +13,9 @@ import (
"github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/ipld/go-ipld-prime/traversal"
"github.com/ipld/go-ipld-prime/traversal/selector"
"github.com/multiformats/go-multihash"

"github.com/ipfs/go-cid"
"github.com/ipfs/go-graphsync/panics"
)

Expand Down Expand Up @@ -165,7 +168,23 @@ func (t *traverser) NBlocksTraversed() int {
return t.blocksCount
}

func asIdentity(c cid.Cid) (digest []byte, ok bool, err error) {
dmh, err := multihash.Decode(c.Hash())
if err != nil {
return nil, false, err
}
ok = dmh.Code == multihash.IDENTITY
digest = dmh.Digest
return digest, ok, nil
}

func (t *traverser) loader(lnkCtx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) {
if digest, ok, err := asIdentity(lnk.(cidlink.Link).Cid); ok {
return io.NopCloser(bytes.NewReader(digest)), nil
} else if err != nil {
return nil, err
}

// A StorageReadOpener call came in; update the state and release the lock.
// We can't simply unlock the mutex inside the <-t.responses case,
// as then we'd deadlock with the other side trying to send.
Expand Down

0 comments on commit 1be7c1a

Please sign in to comment.