feat: subscribe to libp2p eventbus

This commit is contained in:
Arseniy Klempner 2024-07-31 17:15:42 -07:00
parent 570ef17c77
commit 3062212bdd
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
1 changed files with 26 additions and 1 deletions

View File

@ -14,7 +14,7 @@
// along with the Waku library. If not, see <http://www.gnu.org/licenses/>.
//
// 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
}