Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ concurrency:
jobs:
go-test:
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected]
with:
go-versions: '["1.23.x", "1.24.x"]'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/libp2p/go-libp2p-kad-dht

go 1.23.10
go 1.24

require (
github.com/filecoin-project/go-clock v0.1.0
github.com/gammazero/deque v1.0.0
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -48,6 +47,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/filecoin-project/go-clock v0.1.0 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-logr/logr v1.4.3 // indirect
Expand Down
25 changes: 14 additions & 11 deletions provider/internal/connectivity/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"sync"
"sync/atomic"
"time"

"github.com/filecoin-project/go-clock"
)

const (
Expand Down Expand Up @@ -43,7 +41,6 @@ type ConnectivityChecker struct {

online atomic.Bool

clock clock.Clock
lastCheck time.Time
onlineCheckInterval time.Duration // minimum check interval when online

Expand All @@ -64,7 +61,6 @@ func New(checkFunc func() bool, opts ...Option) (*ConnectivityChecker, error) {
c := &ConnectivityChecker{
done: make(chan struct{}),
checkFunc: checkFunc,
clock: cfg.clock,
onlineCheckInterval: cfg.onlineCheckInterval,
onOffline: cfg.onOffline,
onOnline: cfg.onOnline,
Expand Down Expand Up @@ -139,7 +135,7 @@ func (c *ConnectivityChecker) TriggerCheck() {
c.mutex.Unlock()
return
}
if c.online.Load() && c.clock.Now().Sub(c.lastCheck) < c.onlineCheckInterval {
if c.online.Load() && time.Since(c.lastCheck) < c.onlineCheckInterval {
c.mutex.Unlock()
return // last check was too recent
}
Expand All @@ -148,7 +144,7 @@ func (c *ConnectivityChecker) TriggerCheck() {
defer c.mutex.Unlock()

if c.checkFunc() {
c.lastCheck = c.clock.Now()
c.lastCheck = time.Now()
return
}

Expand All @@ -165,13 +161,20 @@ func (c *ConnectivityChecker) TriggerCheck() {
func (c *ConnectivityChecker) probeLoop(init bool) {
var offlineC <-chan time.Time
if !init {
offlineTimer := c.clock.Timer(c.offlineDelay)
defer offlineTimer.Stop()
offlineC = offlineTimer.C
if c.offlineDelay == 0 {
if c.onOffline != nil {
// Online -> Offline
c.onOffline()
}
} else {
offlineTimer := time.NewTimer(c.offlineDelay)
defer offlineTimer.Stop()
offlineC = offlineTimer.C
}
}

delay := initialBackoffDelay
timer := c.clock.Timer(delay)
timer := time.NewTimer(delay)
defer timer.Stop()
for {
select {
Expand Down Expand Up @@ -202,7 +205,7 @@ func (c *ConnectivityChecker) probe() bool {
// Node is back Online.
c.online.Store(true)

c.lastCheck = c.clock.Now()
c.lastCheck = time.Now()
if c.onOnline != nil {
c.onOnline()
}
Expand Down
Loading
Loading