-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: onlinechecker #5340
refactor: onlinechecker #5340
Conversation
Jenkins BuildsClick to see older builds (36)
|
52d4d78
to
a790f39
Compare
vendor/github.com/waku-org/go-waku/waku/v2/peermanager/peer_connector.go
Outdated
Show resolved
Hide resolved
vendor/github.com/waku-org/go-waku/waku/v2/protocol/subscription/subscription_details.go
Outdated
Show resolved
Hide resolved
@kaichaosun @vpavlin @chaitanyaprem |
eab730d
to
f03752a
Compare
@chaitanyaprem @kaichaosun @vpavlin |
f03752a
to
318cfbb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
package onlinechecker | ||
|
||
// OnlineChecker is used to determine if node has connectivity. | ||
type OnlineChecker interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding, there could be a few status for application, Online
, Offline
, GoingOnline
, GoingOffline
, Undetermined
. We may don't need all of these in Waku and Status.
Just wondering will it be better if we can have a enum for such status, and let the interface here return the current status? Something like a StatusProvider.
if err := w.discoverAndConnectPeers(); err != nil { | ||
w.logger.Error("failed to add wakuv2 peers", zap.Error(err)) | ||
} | ||
} | ||
|
||
w.offline = !isOnline | ||
w.onlineChecker.SetOnline(isOnline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about move this line in above if statement? I feel it's more straightforward. Also you may just want to use true
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetOnline
should receive true
or false
depending on wheter the application is conencted or not. Moving it to the if
would mean that IsOnline() would always return true
as SetOnline
would never be called with a false
value to indicate the app is offline.
@@ -1770,15 +1769,15 @@ func (w *Waku) StopDiscV5() error { | |||
} | |||
|
|||
func (w *Waku) ConnectionChanged(state connection.State) { | |||
if !state.Offline && w.offline { | |||
if !state.Offline && !w.onlineChecker.IsOnline() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be improved if we use enum for the different status.
8e1e877
to
15058d2
Compare
15058d2
to
d4c3c58
Compare
d4c3c58
to
ac6fcf0
Compare
I noticed that if the node is offline, the peer connector will still attempt to connect to nodes reported by discv5.
This has a negative impact because the connection to the node will obviously fail, and it will increase the backoff period for the next reconnection attempt.
With this change, the peer connector will no longer attempt to connect to any peer when it's notified that the node is offline.
A similar approach is also used for the filter subscriptions, instead of having to notify each subscription that the node is online/offline, it's done in a single step with the online checker