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,42 @@ 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
+ ready , _ := getValueOrErrorSequential (context .Background (), r .routers ,
54
+ func (ctx context.Context , r routing.Routing ) (bool , bool , error ) {
55
+ pm , ok := r .(ProvideManyRouter )
56
+ if ! ok {
57
+ return false , true , nil
58
+ }
59
+
60
+ ready := pm .Ready ()
61
+
62
+ return ready , ! ready , nil
63
+ },
64
+ )
65
+
66
+ return ready
33
67
}
34
68
35
69
// FindProvidersAsync calls FindProvidersAsync per each router sequentially.
0 commit comments