mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
fix(provider): wait for fullrt crawl completion before providing
This commit is contained in:
parent
aa3c88dcdd
commit
7ea71cfa0d
@ -322,6 +322,25 @@ type dhtImpl interface {
|
||||
Host() host.Host
|
||||
MessageSender() dht_pb.MessageSender
|
||||
}
|
||||
|
||||
type fullrtRouter struct {
|
||||
*fullrt.FullRT
|
||||
}
|
||||
|
||||
// GetClosestPeers overrides fullrt.FullRT's GetClosestPeers and returns an
|
||||
// error if the fullrt's initial network crawl isn't complete yet.
|
||||
func (fr *fullrtRouter) GetClosestPeers(ctx context.Context, key string) ([]peer.ID, error) {
|
||||
if !fr.Ready() {
|
||||
return nil, errors.New("fullrt: initial network crawl still running")
|
||||
}
|
||||
return fr.FullRT.GetClosestPeers(ctx, key)
|
||||
}
|
||||
|
||||
var (
|
||||
_ dhtImpl = &dht.IpfsDHT{}
|
||||
_ dhtImpl = &fullrtRouter{}
|
||||
)
|
||||
|
||||
type addrsFilter interface {
|
||||
FilteredAddrs() []ma.Multiaddr
|
||||
}
|
||||
@ -400,7 +419,7 @@ func SweepingProviderOpt(cfg *config.Config) fx.Option {
|
||||
}
|
||||
case *fullrt.FullRT:
|
||||
if inDht != nil {
|
||||
impl = inDht
|
||||
impl = &fullrtRouter{inDht}
|
||||
}
|
||||
}
|
||||
if impl == nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user