feat(waku)_: add PeerExchange rate-limit (#5507)
* feat(waku)_: add PeerExchange rate-limit * fix_: unintentional wg.Add change
This commit is contained in:
parent
ea35803eef
commit
33c2f231b0
|
@ -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() {
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue