diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 8a45bbdbc..ac4e965a0 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -340,6 +340,10 @@ func New(nodeKey *ecdsa.PrivateKey, fleet string, cfg *Config, logger *zap.Logge } } + if cfg.EnablePeerExchangeServer { + opts = append(opts, node.WithPeerExchange(peer_exchange.WithRateLimiter(1, 1))) + } + waku.options = opts waku.logger.Info("setup the go-waku node successfully") @@ -1325,13 +1329,6 @@ func (w *Waku) Start() error { } } - if w.cfg.EnablePeerExchangeServer { - err := w.node.PeerExchange().Start(w.ctx) - if err != nil { - return err - } - } - w.wg.Add(2) go func() { diff --git a/wakuv2/waku_test.go b/wakuv2/waku_test.go index 11ab976fa..c313a186e 100644 --- a/wakuv2/waku_test.go +++ b/wakuv2/waku_test.go @@ -341,6 +341,11 @@ func TestPeerExchange(t *testing.T) { }, options) require.NoError(t, err) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + require.NoError(t, discV5Node.node.PeerExchange().Request(ctx, 1)) + require.Error(t, discV5Node.node.PeerExchange().Request(ctx, 1)) //should fail due to rate limit + require.NoError(t, lightNode.Stop()) require.NoError(t, pxServerNode.Stop()) require.NoError(t, discV5Node.Stop())