feat(waku)_: add PeerExchange rate-limit (#5507)

* feat(waku)_: add PeerExchange rate-limit

* fix_: unintentional wg.Add change
This commit is contained in:
Vaclav Pavlin 2024-07-12 15:21:21 +02:00 committed by GitHub
parent ea35803eef
commit 33c2f231b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 7 deletions

View File

@ -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() {

View File

@ -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())