mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
chore(bootstrap): remove unecessary request structure
This commit is contained in:
parent
632f3c5cb5
commit
98cf91494d
4
dht.go
4
dht.go
@ -70,7 +70,7 @@ type IpfsDHT struct {
|
||||
bootstrapCfg opts.BootstrapConfig
|
||||
|
||||
triggerAutoBootstrap bool
|
||||
triggerBootstrap chan *bootstrapReq
|
||||
triggerBootstrap chan struct{}
|
||||
latestSelfWalk time.Time // the last time we looked-up our own peerID in the network
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func makeDHT(ctx context.Context, h host.Host, dstore ds.Batching, protocols []p
|
||||
routingTable: rt,
|
||||
protocols: protocols,
|
||||
bucketSize: bucketSize,
|
||||
triggerBootstrap: make(chan *bootstrapReq),
|
||||
triggerBootstrap: make(chan struct{}),
|
||||
}
|
||||
|
||||
dht.ctx = dht.newContextWithLocalTags(ctx)
|
||||
|
@ -43,15 +43,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
type bootstrapReq struct {
|
||||
errChan chan error
|
||||
}
|
||||
|
||||
func makeBootstrapReq() *bootstrapReq {
|
||||
errChan := make(chan error, 1)
|
||||
return &bootstrapReq{errChan}
|
||||
}
|
||||
|
||||
// Bootstrap i
|
||||
func (dht *IpfsDHT) startBootstrapping() error {
|
||||
// scan the RT table periodically & do a random walk on k-buckets that haven't been queried since the given bucket period
|
||||
@ -78,13 +69,10 @@ func (dht *IpfsDHT) startBootstrapping() error {
|
||||
if err := dht.doBootstrap(ctx, walkSelf); err != nil {
|
||||
logger.Warning("bootstrap error: %s", err)
|
||||
}
|
||||
case req := <-dht.triggerBootstrap:
|
||||
case <-dht.triggerBootstrap:
|
||||
logger.Infof("triggering a bootstrap: RT has %d peers", dht.routingTable.Size())
|
||||
err := dht.doBootstrap(ctx, true)
|
||||
select {
|
||||
case req.errChan <- err:
|
||||
close(req.errChan)
|
||||
default:
|
||||
if err := dht.doBootstrap(ctx, true); err != nil {
|
||||
logger.Warning("bootstrap error: %s", err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@ -190,7 +178,7 @@ func (dht *IpfsDHT) selfWalk(ctx context.Context) error {
|
||||
// Note: the context is ignored.
|
||||
func (dht *IpfsDHT) Bootstrap(_ context.Context) error {
|
||||
select {
|
||||
case dht.triggerBootstrap <- makeBootstrapReq():
|
||||
case dht.triggerBootstrap <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return nil
|
||||
|
4
notif.go
4
notif.go
@ -36,7 +36,7 @@ func (nn *netNotifiee) Connected(n network.Network, v network.Conn) {
|
||||
dht.Update(dht.Context(), p)
|
||||
if bootstrap && dht.triggerAutoBootstrap {
|
||||
select {
|
||||
case dht.triggerBootstrap <- makeBootstrapReq():
|
||||
case dht.triggerBootstrap <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ func (nn *netNotifiee) testConnection(v network.Conn) {
|
||||
dht.Update(dht.Context(), p)
|
||||
if bootstrap && dht.triggerAutoBootstrap {
|
||||
select {
|
||||
case dht.triggerBootstrap <- makeBootstrapReq():
|
||||
case dht.triggerBootstrap <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user