mirror of https://github.com/status-im/go-waku.git
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:
parent
ee17c23345
commit
8a9c4d68e3
|
@ -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
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue