Skip to content

Commit

Permalink
refactor: AutoRelayFeeder with exp. backoff
Browse files Browse the repository at this point in the history
It starts at feeding peers ever 15s, then backs off each time
until it is done once an hour

Should be acceptable until we have smarter mechanism in go-lib2p 0.20
  • Loading branch information
lidel committed Apr 27, 2022
1 parent 195d394 commit 59c16c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 10 additions & 2 deletions core/node/libp2p/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
record "github.com/libp2p/go-libp2p-record"
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"

"github.com/cenkalti/backoff/v4"
"go.uber.org/fx"
)

Expand Down Expand Up @@ -189,15 +190,22 @@ func AutoRelayFeeder(lc fx.Lifecycle, h host.Host, peerChan chan peer.AddrInfo,
go func() {
defer close(done)

t := time.NewTicker(time.Minute / 3) // TODO: this is way too frequent. Should probably use some kind of backoff
// Feed peers more often right after the bootstrap, then backoff
bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 15 * time.Second
bo.Multiplier = 3
bo.MaxInterval = 1 * time.Hour
bo.MaxElapsedTime = 0 // never stop
t := backoff.NewTicker(bo)
defer t.Stop()
for {
select {
case <-t.C:
case <-ctx.Done():
return
}
// TODO: refactor AutoRelayFeeder, for now we skip it if dht missing to fix sharness panics
/* TODO: refactor AutoRelayFeeder after go-libp2p 0.20 ships
for now we skip it if dht missing to fix sharness panics */
if dht == nil {
fmt.Println("AutoRelayFeeder: noop due to missing dht.WAN")
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
bazil.org/fuse v0.0.0-20200117225306-7b5117fecadc
contrib.go.opencensus.io/exporter/prometheus v0.4.0
github.com/blang/semver/v4 v4.0.0
github.com/cenkalti/backoff/v4 v4.1.2
github.com/ceramicnetwork/go-dag-jose v0.1.0
github.com/cespare/xxhash v1.1.0
github.com/cheggaaa/pb v1.0.29
Expand Down Expand Up @@ -135,7 +136,6 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ github.com/ipfs/go-metrics-prometheus v0.0.2 h1:9i2iljLg12S78OhC6UAiXi176xvQGiZa
github.com/ipfs/go-metrics-prometheus v0.0.2/go.mod h1:ELLU99AQQNi+zX6GCGm2lAgnzdSH3u5UVlCdqSXnEks=
github.com/ipfs/go-mfs v0.2.1 h1:5jz8+ukAg/z6jTkollzxGzhkl3yxm022Za9f2nL5ab8=
github.com/ipfs/go-mfs v0.2.1/go.mod h1:Woj80iuw4ajDnIP6+seRaoHpPsc9hmL0pk/nDNDWP88=
github.com/ipfs/go-namesys v0.4.1-0.20220426174228-2e37afbc2bf2 h1:Vr44R5BWU1iGDnloo66+O9OKJcCCiZB5ZVOqdWaHVtw=
github.com/ipfs/go-namesys v0.4.1-0.20220426174228-2e37afbc2bf2/go.mod h1:KLFhk7IN1TB+WqtB6hxuCQFfBi+4b6nsaKgRuJjYUtA=
github.com/ipfs/go-namesys v0.4.1-0.20220427151138-605965e675aa h1:PheaiRiAxx2A6OyOmB9fsuT/MJ1QOR31ipbyNOJgND8=
github.com/ipfs/go-namesys v0.4.1-0.20220427151138-605965e675aa/go.mod h1:KLFhk7IN1TB+WqtB6hxuCQFfBi+4b6nsaKgRuJjYUtA=
github.com/ipfs/go-path v0.0.7/go.mod h1:6KTKmeRnBXgqrTvzFrPV3CamxcgvXX/4z79tfAd2Sno=
Expand Down

0 comments on commit 59c16c3

Please sign in to comment.