mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
refactor(routing) expose Bootstrap() error on routing interface
This commit is contained in:
@ -106,7 +106,7 @@ func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error) {
|
|||||||
proc.Go(periodic) // run one right now.
|
proc.Go(periodic) // run one right now.
|
||||||
|
|
||||||
// kick off dht bootstrapping.
|
// kick off dht bootstrapping.
|
||||||
dbproc, err := thedht.Bootstrap(dht.DefaultBootstrapConfig)
|
dbproc, err := thedht.BootstrapWithConfig(dht.DefaultBootstrapConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
proc.Close()
|
proc.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -4,6 +4,7 @@ package dht
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -44,13 +45,18 @@ var DefaultBootstrapConfig = BootstrapConfig{
|
|||||||
Timeout: time.Duration(20 * time.Second),
|
Timeout: time.Duration(20 * time.Second),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dht *IpfsDHT) Bootstrap(context.Context) error {
|
||||||
|
// Bootstrap satisfies the routing interface
|
||||||
|
return errors.New("TODO: perform DHT bootstrap")
|
||||||
|
}
|
||||||
|
|
||||||
// Bootstrap ensures the dht routing table remains healthy as peers come and go.
|
// Bootstrap ensures the dht routing table remains healthy as peers come and go.
|
||||||
// it builds up a list of peers by requesting random peer IDs. The Bootstrap
|
// it builds up a list of peers by requesting random peer IDs. The Bootstrap
|
||||||
// process will run a number of queries each time, and run every time signal fires.
|
// process will run a number of queries each time, and run every time signal fires.
|
||||||
// These parameters are configurable.
|
// These parameters are configurable.
|
||||||
//
|
//
|
||||||
// Bootstrap returns a process, so the user can stop it.
|
// Bootstrap returns a process, so the user can stop it.
|
||||||
func (dht *IpfsDHT) Bootstrap(config BootstrapConfig) (goprocess.Process, error) {
|
func (dht *IpfsDHT) BootstrapWithConfig(config BootstrapConfig) (goprocess.Process, error) {
|
||||||
sig := time.Tick(config.Period)
|
sig := time.Tick(config.Period)
|
||||||
return dht.BootstrapOnSignal(config, sig)
|
return dht.BootstrapOnSignal(config, sig)
|
||||||
}
|
}
|
||||||
|
@ -84,4 +84,8 @@ func (c *client) Ping(ctx context.Context, p peer.ID) (time.Duration, error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *client) Bootstrap(context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var _ routing.IpfsRouting = &client{}
|
var _ routing.IpfsRouting = &client{}
|
||||||
|
@ -89,5 +89,9 @@ func (c *offlineRouting) Ping(ctx context.Context, p peer.ID) (time.Duration, er
|
|||||||
return 0, ErrOffline
|
return 0, ErrOffline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *offlineRouting) Bootstrap(context.Context) (error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ensure offlineRouting matches the IpfsRouting interface
|
// ensure offlineRouting matches the IpfsRouting interface
|
||||||
var _ routing.IpfsRouting = &offlineRouting{}
|
var _ routing.IpfsRouting = &offlineRouting{}
|
||||||
|
@ -40,4 +40,10 @@ type IpfsRouting interface {
|
|||||||
|
|
||||||
// Ping a peer, log the time it took
|
// Ping a peer, log the time it took
|
||||||
Ping(context.Context, peer.ID) (time.Duration, error)
|
Ping(context.Context, peer.ID) (time.Duration, error)
|
||||||
|
|
||||||
|
// Bootstrap allows callers to hint to the routing system to get into a
|
||||||
|
// Boostrapped state
|
||||||
|
Bootstrap(context.Context) error
|
||||||
|
|
||||||
|
// TODO expose io.Closer or plain-old Close error
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user