7
7
"fmt"
8
8
"net/url"
9
9
"os"
10
+ "time"
10
11
11
12
"github.com/filecoin-project/boost/lib/legacy"
12
13
"github.com/filecoin-project/boost/storagemarket/types/legacytypes"
@@ -18,11 +19,11 @@ import (
18
19
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
19
20
chainTypes "github.com/filecoin-project/lotus/chain/types"
20
21
"github.com/google/uuid"
21
- cbor "github.com/ipfs/go-ipld-cbor"
22
- "go.uber.org/fx"
23
-
24
22
"github.com/ipfs/go-datastore"
23
+ cbor "github.com/ipfs/go-ipld-cbor"
25
24
"github.com/ipld/go-ipld-prime"
25
+ "github.com/ipni/go-libipni/ingest/schema"
26
+ "go.uber.org/fx"
26
27
27
28
"github.com/filecoin-project/boost/db"
28
29
bdtypes "github.com/filecoin-project/boost/extern/boostd-data/svc/types"
@@ -71,6 +72,7 @@ type Wrapper struct {
71
72
bitswapEnabled bool
72
73
httpEnabled bool
73
74
stop context.CancelFunc
75
+ removeAllAds bool
74
76
}
75
77
76
78
func NewWrapper (provAddr address.Address , cfg * config.Boost ) func (lc fx.Lifecycle , h host.Host , r repo.LockedRepo , directDealsDB * db.DirectDealsDB , dealsDB * db.DealsDB ,
@@ -127,7 +129,11 @@ func (w *Wrapper) Start(_ context.Context) {
127
129
128
130
log .Info ("starting index provider" )
129
131
130
- go w .checkForUpdates (runCtx )
132
+ if w .cfg .CurioMigration .Enable {
133
+ go w .tryAnnounceRemoveAll (runCtx )
134
+ } else {
135
+ go w .checkForUpdates (runCtx )
136
+ }
131
137
}
132
138
133
139
func (w * Wrapper ) checkForUpdates (ctx context.Context ) {
@@ -867,3 +873,79 @@ func (w *Wrapper) AnnounceBoostDirectDealRemoved(ctx context.Context, dealUUID u
867
873
}
868
874
return annCid , err
869
875
}
876
+
877
+ func (w * Wrapper ) AnnounceRemoveAll (ctx context.Context ) ([]cid.Cid , error ) {
878
+ var allAds []* schema.Advertisement
879
+ _ , ad , err := w .prov .GetLatestAdv (ctx )
880
+ if err != nil {
881
+ return nil , err
882
+ }
883
+ allAds = append (allAds , ad )
884
+
885
+ prev , err := cid .Parse (ad .PreviousID .String ())
886
+ if err != nil {
887
+ return nil , err
888
+ }
889
+
890
+ for prev != cid .Undef {
891
+ ad , err := w .prov .GetAdv (ctx , prev )
892
+ if err != nil {
893
+ return nil , err
894
+ }
895
+
896
+ prev , err = cid .Parse (ad .PreviousID .String ())
897
+ if err != nil {
898
+ return nil , err
899
+ }
900
+ }
901
+
902
+ var entryAds []* schema.Advertisement
903
+
904
+ for _ , ad := range allAds {
905
+ if ! ad .IsRm {
906
+ entryAds = append (entryAds , ad )
907
+ }
908
+ }
909
+
910
+ var newAds []cid.Cid
911
+
912
+ for _ , ad := range entryAds {
913
+ a , err := w .prov .NotifyRemove (ctx , w .h .ID (), ad .ContextID )
914
+ if err != nil {
915
+ if ! errors .Is (err , provider .ErrContextIDNotFound ) {
916
+ return nil , fmt .Errorf ("failed to publish the removal ad: %w" , err )
917
+ }
918
+ }
919
+ newAds = append (newAds , a )
920
+ }
921
+
922
+ return newAds , nil
923
+
924
+ }
925
+
926
+ func (w * Wrapper ) tryAnnounceRemoveAll (ctx context.Context ) {
927
+ ticker := time .NewTicker (time .Minute )
928
+
929
+ for {
930
+ select {
931
+ case <- ticker .C :
932
+ out , err := w .AnnounceRemoveAll (ctx )
933
+ if err != nil {
934
+ log .Errorw ("error while announcing remove all" , "err" , err )
935
+ continue
936
+ }
937
+ if len (out ) > 0 {
938
+ continue
939
+ }
940
+ log .Debugw ("Cleaned up all the IPNI ads" )
941
+ w .removeAllAds = true
942
+ return
943
+ case <- ctx .Done ():
944
+ return
945
+ }
946
+ }
947
+ }
948
+
949
+ func (w * Wrapper ) RemoveAllStatus (ctx context.Context ) bool {
950
+ return w .removeAllAds
951
+ }
0 commit comments