mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
New multi-router configuration system based on https://hackmd.io/G1KRDEX5T3qyfoBMkIrBew#Methods - Added a new routing type: "custom" - Added specific struct types for different Routers (instead of map[string]interface{}) - Added `Duration` config type, to make easier time string parsing - Added config documentation. - Use the latest go-delegated-routing library version with GET support. - Added changelog notes for this feature. It: - closes #9157 - closes #9079 - closes #9186
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package routing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ipfs/go-cid"
|
|
drc "github.com/ipfs/go-delegated-routing/client"
|
|
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
"github.com/libp2p/go-libp2p/core/routing"
|
|
)
|
|
|
|
var _ routing.Routing = &reframeRoutingWrapper{}
|
|
var _ routinghelpers.ProvideManyRouter = &reframeRoutingWrapper{}
|
|
|
|
// reframeRoutingWrapper is a wrapper needed to construct the routing.Routing interface from
|
|
// delegated-routing library.
|
|
type reframeRoutingWrapper struct {
|
|
*drc.Client
|
|
*drc.ContentRoutingClient
|
|
}
|
|
|
|
func (c *reframeRoutingWrapper) Provide(ctx context.Context, id cid.Cid, announce bool) error {
|
|
return c.ContentRoutingClient.Provide(ctx, id, announce)
|
|
}
|
|
|
|
func (c *reframeRoutingWrapper) FindProvidersAsync(ctx context.Context, cid cid.Cid, count int) <-chan peer.AddrInfo {
|
|
return c.ContentRoutingClient.FindProvidersAsync(ctx, cid, count)
|
|
}
|
|
|
|
func (c *reframeRoutingWrapper) Bootstrap(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (c *reframeRoutingWrapper) FindPeer(ctx context.Context, id peer.ID) (peer.AddrInfo, error) {
|
|
return peer.AddrInfo{}, routing.ErrNotSupported
|
|
}
|
|
|
|
type ProvideManyRouter interface {
|
|
routinghelpers.ProvideManyRouter
|
|
routing.Routing
|
|
}
|