From 3062212bdde8e2730e4ada9a91490834a8ffeff7 Mon Sep 17 00:00:00 2001 From: Arseniy Klempner Date: Wed, 31 Jul 2024 17:15:42 -0700 Subject: [PATCH] feat: subscribe to libp2p eventbus --- wakuv2/waku.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 9e5544134..30978f6c3 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -14,7 +14,7 @@ // along with the Waku library. If not, see . // // This software uses the go-ethereum library, which is licensed -// under the GNU Lesser General Public Library, version 3 or any later. +// under the GNU Lesser General Public License, version 3 or any later. package wakuv2 @@ -53,6 +53,7 @@ import ( "github.com/libp2p/go-libp2p" pubsub "github.com/libp2p/go-libp2p-pubsub" + libp2pEvent "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/metrics" "github.com/waku-org/go-waku/waku/v2/dnsdisc" @@ -1440,6 +1441,30 @@ func (w *Waku) Start() error { w.wg.Add(1) go w.seedBootnodesForDiscV5() + subscription, err := w.node.Host().EventBus().Subscribe(libp2pEvent.WildcardSubscription) + if err != nil { + w.logger.Error("failed to subscribe to peer identification completed event", zap.Error(err)) + } + + go func() { + for { + select { + case e, ok := <-subscription.Out(): + if !ok { + w.logger.Info("subscription closed") + return + } + // event := e.(libp2pEvent.EvtPeerIdentificationFailed) + w.logger.Info("AK: ", zap.Any("event", e)) + case <-time.After(5 * time.Second): + w.logger.Info("tick") + case <-w.ctx.Done(): + subscription.Close() + return + } + } + }() + return nil }