Skip to content
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

feat: register for local node's reachability change #651

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 26 additions & 0 deletions waku/v2/node/localnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/libp2p/go-libp2p/core/event"
ma "github.com/multiformats/go-multiaddr"
"github.com/waku-org/go-waku/waku/v2/protocol"
wenr "github.com/waku-org/go-waku/waku/v2/protocol/enr"
Expand Down Expand Up @@ -344,3 +345,28 @@ func (w *WakuNode) watchTopicShards(ctx context.Context) error {

return nil
}

func (w *WakuNode) registerAndMonitorReachability(ctx context.Context) {
var myEventSub event.Subscription
var err error
if myEventSub, err = w.host.EventBus().Subscribe(new(event.EvtLocalReachabilityChanged)); err != nil {
w.log.Error("Failed to register with libp2p for reachability status")
chaitanyaprem marked this conversation as resolved.
Show resolved Hide resolved
return
}
w.wg.Add(1)
go func() {
defer myEventSub.Close()
defer w.wg.Done()

for {
select {
case evt := <-myEventSub.Out():
reachability := evt.(event.EvtLocalReachabilityChanged).Reachability
w.log.Info("Node Reachabilitiy Changed to",
zap.String("NewReachabilitiy", reachability.String()))
chaitanyaprem marked this conversation as resolved.
Show resolved Hide resolved
case <-ctx.Done():
return
}
}
}()
}
1 change: 1 addition & 0 deletions waku/v2/node/wakunode2.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ func (w *WakuNode) Start(ctx context.Context) error {
return err
}
w.peermanager.Start(ctx)
w.registerAndMonitorReachability(ctx)
}

w.store = w.storeFactory(w)
Expand Down