@@ -59,9 +59,13 @@ import (
59
59
"github.com/ipfs/go-cid"
60
60
"github.com/ipfs/go-datastore"
61
61
ipldcbor "github.com/ipfs/go-ipld-cbor"
62
- ipld "github.com/ipfs/go-ipld-format"
62
+ ipldformat "github.com/ipfs/go-ipld-format"
63
63
logging "github.com/ipfs/go-log/v2"
64
64
"github.com/ipld/go-car"
65
+ "github.com/ipld/go-ipld-prime"
66
+ "github.com/ipld/go-ipld-prime/codec/dagjson"
67
+ "github.com/ipld/go-ipld-prime/datamodel"
68
+ "github.com/ipld/go-ipld-prime/traversal/selector"
65
69
"github.com/libp2p/go-libp2p"
66
70
"github.com/libp2p/go-libp2p/core/host"
67
71
"github.com/multiformats/go-multihash"
@@ -711,7 +715,7 @@ func (f *TestFramework) WaitDealSealed(ctx context.Context, deal *cid.Cid) error
711
715
}
712
716
}
713
717
714
- func (f * TestFramework ) Retrieve (ctx context.Context , t * testing.T , deal * cid.Cid , root cid.Cid , carExport bool ) string {
718
+ func (f * TestFramework ) Retrieve (ctx context.Context , t * testing.T , deal * cid.Cid , root cid.Cid , extractCar bool , selectorNode datamodel. Node ) string {
715
719
// perform retrieval.
716
720
info , err := f .FullNode .ClientGetDealInfo (ctx , * deal )
717
721
require .NoError (t , err )
@@ -720,7 +724,7 @@ func (f *TestFramework) Retrieve(ctx context.Context, t *testing.T, deal *cid.Ci
720
724
require .NoError (t , err )
721
725
require .NotEmpty (t , offers , "no offers" )
722
726
723
- return f .retrieve (ctx , t , offers [0 ], carExport )
727
+ return f .retrieve (ctx , t , offers [0 ], extractCar , selectorNode )
724
728
}
725
729
726
730
func (f * TestFramework ) ExtractFileFromCAR (ctx context.Context , t * testing.T , file * os.File ) string {
@@ -739,7 +743,7 @@ func (f *TestFramework) ExtractFileFromCAR(ctx context.Context, t *testing.T, fi
739
743
require .NoError (t , err )
740
744
}
741
745
742
- reg := ipld .Registry {}
746
+ reg := ipldformat .Registry {}
743
747
reg .Register (cid .DagProtobuf , dag .DecodeProtobufBlock )
744
748
reg .Register (cid .DagCBOR , ipldcbor .DecodeBlock )
745
749
reg .Register (cid .Raw , dag .DecodeRawBlock )
@@ -758,15 +762,17 @@ func (f *TestFramework) ExtractFileFromCAR(ctx context.Context, t *testing.T, fi
758
762
return tmpFile
759
763
}
760
764
761
- func (f * TestFramework ) RetrieveDirect (ctx context.Context , t * testing.T , root cid.Cid , pieceCid * cid.Cid , carExport bool ) string {
765
+ func (f * TestFramework ) RetrieveDirect (ctx context.Context , t * testing.T , root cid.Cid , pieceCid * cid.Cid , carExport bool , extractCar bool , selectorNode datamodel. Node ) string {
762
766
offer , err := f .FullNode .ClientMinerQueryOffer (ctx , f .MinerAddr , root , pieceCid )
763
767
require .NoError (t , err )
764
768
765
- return f .retrieve (ctx , t , offer , carExport )
769
+ return f .retrieve (ctx , t , offer , extractCar , selectorNode )
766
770
}
767
771
768
- func (f * TestFramework ) retrieve (ctx context.Context , t * testing.T , offer lapi.QueryOffer , carExport bool ) string {
772
+ func (f * TestFramework ) retrieve (ctx context.Context , t * testing.T , offer lapi.QueryOffer , extractCar bool , selectorNode datamodel. Node ) string {
769
773
p := path .Join (t .TempDir (), "ret-car-" + t .Name ())
774
+ err := os .MkdirAll (path .Dir (p ), 0755 )
775
+ require .NoError (t , err )
770
776
carFile , err := os .Create (p )
771
777
require .NoError (t , err )
772
778
@@ -779,7 +785,17 @@ func (f *TestFramework) retrieve(ctx context.Context, t *testing.T, offer lapi.Q
779
785
updates , err := f .FullNode .ClientGetRetrievalUpdates (updatesCtx )
780
786
require .NoError (t , err )
781
787
782
- retrievalRes , err := f .FullNode .ClientRetrieve (ctx , offer .Order (caddr ))
788
+ order := offer .Order (caddr )
789
+ if selectorNode != nil {
790
+ _ , err := selector .CompileSelector (selectorNode )
791
+ require .NoError (t , err )
792
+ jsonSelector , err := ipld .Encode (selectorNode , dagjson .Encode )
793
+ require .NoError (t , err )
794
+ sel := lapi .Selector (jsonSelector )
795
+ order .DataSelector = & sel
796
+ }
797
+
798
+ retrievalRes , err := f .FullNode .ClientRetrieve (ctx , order )
783
799
require .NoError (t , err )
784
800
consumeEvents:
785
801
for {
@@ -812,11 +828,11 @@ consumeEvents:
812
828
},
813
829
lapi.FileRef {
814
830
Path : carFile .Name (),
815
- IsCAR : carExport ,
831
+ IsCAR : true ,
816
832
}))
817
833
818
834
ret := carFile .Name ()
819
- if carExport {
835
+ if extractCar {
820
836
ret = f .ExtractFileFromCAR (ctx , t , carFile )
821
837
}
822
838
0 commit comments