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

* feat:Register for reachability change and log status

Co-authored-by: richΛrd <info@richardramos.me>

---------

Co-authored-by: richΛrd <info@richardramos.me>
This commit is contained in:
Prem Chaitanya Prathi 2023-08-20 18:06:35 +05:30 committed by GitHub
parent ee17c23345
commit 8a9c4d68e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -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"
@ -344,3 +345,27 @@ 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", zap.Error(err))
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 reachability changed", zap.Stringer("newReachability", reachability))
case <-ctx.Done():
return
}
}
}()
}

View File

@ -408,6 +408,7 @@ func (w *WakuNode) Start(ctx context.Context) error {
return err
}
w.peermanager.Start(ctx)
w.registerAndMonitorReachability(ctx)
}
w.store = w.storeFactory(w)