File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11package ipldutil
22
33import (
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+
168181func (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.
You can’t perform that action at this time.
0 commit comments