9
9
"github.com/ipfs/go-cid"
10
10
"github.com/libp2p/go-libp2p-core/peer"
11
11
"github.com/libp2p/go-libp2p-core/routing"
12
+ "github.com/multiformats/go-multihash"
12
13
)
13
14
14
15
var _ routing.Routing = & composableSequential {}
@@ -27,9 +28,40 @@ func NewComposableSequential(routers []*SequentialRouter) *composableSequential
27
28
// If some router fails and the IgnoreError flag is true, we continue to the next router.
28
29
// Context timeout error will be also ignored if the flag is set.
29
30
func (r * composableSequential ) Provide (ctx context.Context , cid cid.Cid , provide bool ) error {
30
- return executeSequential (ctx , r .routers , func (ctx context.Context , r routing.Routing ) error {
31
- return r .Provide (ctx , cid , provide )
32
- })
31
+ return executeSequential (ctx , r .routers ,
32
+ func (ctx context.Context , r routing.Routing ) error {
33
+ return r .Provide (ctx , cid , provide )
34
+ })
35
+ }
36
+
37
+ // ProvideMany will call all supported Routers sequentially.
38
+ func (r * composableSequential ) ProvideMany (ctx context.Context , keys []multihash.Multihash ) error {
39
+ return executeSequential (ctx , r .routers ,
40
+ func (ctx context.Context , r routing.Routing ) error {
41
+ pm , ok := r .(ProvideManyRouter )
42
+ if ! ok {
43
+ return nil
44
+ }
45
+ return pm .ProvideMany (ctx , keys )
46
+ },
47
+ )
48
+ }
49
+
50
+ // Ready will call all supported ProvideMany Routers sequentially.
51
+ // If some of them are not ready, this method will return false.
52
+ func (r * composableSequential ) Ready () bool {
53
+ for _ , ro := range r .routers {
54
+ pm , ok := ro .Router .(ProvideManyRouter )
55
+ if ! ok {
56
+ continue
57
+ }
58
+
59
+ if ! pm .Ready () {
60
+ return false
61
+ }
62
+ }
63
+
64
+ return true
33
65
}
34
66
35
67
// FindProvidersAsync calls FindProvidersAsync per each router sequentially.
0 commit comments