Skip to content

Commit f0631c4

Browse files
provider: daemon (#1126)
* provider: adding provide and reprovide queue * provider: network operations * add some tests * schedule prefix len computations * provider schedule * provider: handleProvide * addressed review * use go-test/random * satisfy linter * log errors during initial prefix len measurement * address review * satisfy linter * address review * provider: explore swarm * provider: batch provide * provider: batch reprovide * provider: catchup pending work * provider: options * provide: handle reprovide * provider: daemon * cancel context of external functions + tests * fix panic when adding key to trie if superstring already exists * address review * decrease minimal region size from replicationFactor+1 to replicationFactor * simplify unscheduleSubsumedPrefixesNoClock * address review * fix test to match region size (now: replicationFactor, before: replicationFactor+1) * dequeue outside of go routine * close connectivity * address review * optimise expensive calls to trie.Size()
1 parent a67da4b commit f0631c4

File tree

6 files changed

+245
-86
lines changed

6 files changed

+245
-86
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/gammazero/deque v1.0.0
88
github.com/google/gopacket v1.1.19
99
github.com/google/uuid v1.6.0
10-
github.com/guillaumemichel/reservedpool v0.1.0
10+
github.com/guillaumemichel/reservedpool v0.2.0
1111
github.com/hashicorp/golang-lru v1.0.2
1212
github.com/ipfs/boxo v0.33.1
1313
github.com/ipfs/go-cid v0.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
113113
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
114114
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
115115
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
116-
github.com/guillaumemichel/reservedpool v0.1.0 h1:QOG3bsExi+Erk2TBzGan87uqA48Ns27uhhnwgCJup+Y=
117-
github.com/guillaumemichel/reservedpool v0.1.0/go.mod h1:sXSDIaef81TFdAJglsCFCMfgF5E5Z5xK1tFhjDhvbUc=
116+
github.com/guillaumemichel/reservedpool v0.2.0 h1:q73gtdMFJHtW+dDJ/fwtk34p7JprQv8fJSK7dEjf8Sw=
117+
github.com/guillaumemichel/reservedpool v0.2.0/go.mod h1:sXSDIaef81TFdAJglsCFCMfgF5E5Z5xK1tFhjDhvbUc=
118118
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
119119
github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
120120
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=

provider/datastore/keystore.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func NewKeyStore(d ds.Batching, opts ...KeyStoreOption) (*KeyStore, error) {
151151
}
152152
}
153153
keyStore := KeyStore{
154+
done: make(chan struct{}),
154155
ds: d,
155156
base: ds.NewKey(cfg.base),
156157
prefixLen: cfg.prefixBits,

provider/internal/connectivity/connectivity.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
// is invoked exactly once.
2424
type ConnectivityChecker struct {
2525
done chan struct{}
26+
closed bool
2627
closeOnce sync.Once
2728

2829
online atomic.Bool
@@ -58,17 +59,14 @@ func New(checkFunc func() bool, backOnlineNotify func(), opts ...Option) (*Conne
5859
}
5960

6061
// Close stops any running connectivity checks and prevents future ones.
61-
func (c *ConnectivityChecker) Close() {
62-
c.closeOnce.Do(func() { close(c.done) })
63-
}
64-
65-
func (c *ConnectivityChecker) closed() bool {
66-
select {
67-
case <-c.done:
68-
return true
69-
default:
70-
return false
71-
}
62+
func (c *ConnectivityChecker) Close() error {
63+
c.closeOnce.Do(func() {
64+
close(c.done)
65+
c.mutex.Lock()
66+
c.closed = true
67+
c.mutex.Unlock()
68+
})
69+
return nil
7270
}
7371

7472
// IsOnline returns true if the node is currently online, false otherwise.
@@ -86,13 +84,13 @@ func (c *ConnectivityChecker) IsOnline() bool {
8684
// - Exit if context is cancelled, or ConnectivityChecker is closed.
8785
// - When node is found back online, run the `backOnlineNotify` callback.
8886
func (c *ConnectivityChecker) TriggerCheck() {
89-
if c.closed() {
90-
// Noop
91-
return
92-
}
9387
if !c.mutex.TryLock() {
9488
return // already checking
9589
}
90+
if c.closed {
91+
c.mutex.Unlock()
92+
return
93+
}
9694
if c.online.Load() && c.clock.Now().Sub(c.lastCheck) < c.onlineCheckInterval {
9795
c.mutex.Unlock()
9896
return // last check was too recent
@@ -117,7 +115,9 @@ func (c *ConnectivityChecker) TriggerCheck() {
117115
return
118116
case <-ticker.C:
119117
if c.checkFunc() {
120-
if !c.closed() {
118+
select {
119+
case <-c.done:
120+
default:
121121
// Node is back online.
122122
c.online.Store(true)
123123
c.lastCheck = c.clock.Now()

0 commit comments

Comments
 (0)