From 2d12ac4fbbee619edf4e5cb947d9f51af44880e9 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 8 Jun 2020 11:43:56 +0200 Subject: [PATCH] Rename rate limiting to packet rate limiting --- VERSION | 2 +- node/geth_node.go | 8 ++--- params/config.go | 8 ++--- waku/common/rate_limiter.go | 60 ++++++++++++++++++++----------------- waku/waku.go | 4 +-- 5 files changed, 43 insertions(+), 39 deletions(-) diff --git a/VERSION b/VERSION index 1942d77df..316ba4bd9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.54.1 +0.55.0 diff --git a/node/geth_node.go b/node/geth_node.go index ffbd46915..a899a67e6 100644 --- a/node/geth_node.go +++ b/node/geth_node.go @@ -576,10 +576,10 @@ func wakuRateLimiter(wakuCfg *params.WakuConfig, clusterCfg *params.ClusterConfi } return wakucommon.NewPeerRateLimiter( &wakucommon.PeerRateLimiterConfig{ - LimitPerSecIP: wakuCfg.RateLimitIP, - LimitPerSecPeerID: wakuCfg.RateLimitPeerID, - WhitelistedIPs: ips, - WhitelistedPeerIDs: peerIDs, + PacketLimitPerSecIP: wakuCfg.PacketRateLimitIP, + PacketLimitPerSecPeerID: wakuCfg.PacketRateLimitPeerID, + WhitelistedIPs: ips, + WhitelistedPeerIDs: peerIDs, }, &whisper.MetricsRateLimiterHandler{}, &whisper.DropPeerRateLimiterHandler{ diff --git a/params/config.go b/params/config.go index d1179ce98..e03f46960 100644 --- a/params/config.go +++ b/params/config.go @@ -177,13 +177,13 @@ type WakuConfig struct { // EnableRateLimiter set to true enables IP and peer ID rate limiting. EnableRateLimiter bool - // RateLimitIP sets the limit on the number of messages per second + // PacketRateLimitIP sets the limit on the number of messages per second // from a given IP. - RateLimitIP int64 + PacketRateLimitIP int64 - // RateLimitPeerID sets the limit on the number of messages per second + // PacketRateLimitPeerID sets the limit on the number of messages per second // from a given peer ID. - RateLimitPeerID int64 + PacketRateLimitPeerID int64 // RateLimitTolerance is a number of how many a limit must be exceeded // in order to drop a peer. diff --git a/waku/common/rate_limiter.go b/waku/common/rate_limiter.go index 6931092c2..c1605cde5 100644 --- a/waku/common/rate_limiter.go +++ b/waku/common/rate_limiter.go @@ -64,9 +64,13 @@ func (MetricsRateLimiterHandler) ExceedIPLimit() error { // RateLimits contains information about rate limit settings. // It is exchanged using rateLimitingCode packet or in the handshake. type RateLimits struct { - IPLimits uint64 // messages per second from a single IP (default 0, no limits) - PeerIDLimits uint64 // messages per second from a single peer ID (default 0, no limits) - TopicLimits uint64 // messages per second from a single topic (default 0, no limits) + PacketIPLimits uint64 // packets per second from a single IP (default 0, no limits) + PacketPeerIDLimits uint64 // packets per second from a single peer ID (default 0, no limits) + PacketTopicLimits uint64 // packets per second from a single topic (default 0, no limits) + + SizeIPLimits uint64 // bytes per second from a single IP (default 0, no limits) + SizePeerIDLimits uint64 // bytes per second from a single peer ID (default 0, no limits) + SizeTopicLimits uint64 // bytes per second from a single topic (default 0, no limits) } func (r RateLimits) IsZero() bool { @@ -101,26 +105,26 @@ func (h *DropPeerRateLimiterHandler) ExceedIPLimit() error { // PeerRateLimiterConfig represents configurations for initialising a PeerRateLimiter type PeerRateLimiterConfig struct { - LimitPerSecIP int64 - LimitPerSecPeerID int64 - WhitelistedIPs []string - WhitelistedPeerIDs []enode.ID + PacketLimitPerSecIP int64 + PacketLimitPerSecPeerID int64 + WhitelistedIPs []string + WhitelistedPeerIDs []enode.ID } var defaultPeerRateLimiterConfig = PeerRateLimiterConfig{ - LimitPerSecIP: 10, - LimitPerSecPeerID: 5, - WhitelistedIPs: nil, - WhitelistedPeerIDs: nil, + PacketLimitPerSecIP: 10, + PacketLimitPerSecPeerID: 5, + WhitelistedIPs: nil, + WhitelistedPeerIDs: nil, } // PeerRateLimiter represents a rate limiter that limits communication between Peers type PeerRateLimiter struct { - peerIDThrottler *tb.Throttler - ipThrottler *tb.Throttler + packetPeerIDThrottler *tb.Throttler + packetIpThrottler *tb.Throttler - LimitPerSecIP int64 - LimitPerSecPeerID int64 + PacketLimitPerSecIP int64 + PacketLimitPerSecPeerID int64 whitelistedPeerIDs []enode.ID whitelistedIPs []string @@ -135,13 +139,13 @@ func NewPeerRateLimiter(cfg *PeerRateLimiterConfig, handlers ...RateLimiterHandl } return &PeerRateLimiter{ - peerIDThrottler: tb.NewThrottler(time.Millisecond * 100), - ipThrottler: tb.NewThrottler(time.Millisecond * 100), - LimitPerSecIP: cfg.LimitPerSecIP, - LimitPerSecPeerID: cfg.LimitPerSecPeerID, - whitelistedPeerIDs: cfg.WhitelistedPeerIDs, - whitelistedIPs: cfg.WhitelistedIPs, - handlers: handlers, + packetPeerIDThrottler: tb.NewThrottler(time.Millisecond * 100), + packetIpThrottler: tb.NewThrottler(time.Millisecond * 100), + PacketLimitPerSecIP: cfg.PacketLimitPerSecIP, + PacketLimitPerSecPeerID: cfg.PacketLimitPerSecPeerID, + whitelistedPeerIDs: cfg.WhitelistedPeerIDs, + whitelistedIPs: cfg.WhitelistedIPs, + handlers: handlers, } } @@ -228,22 +232,22 @@ func (r *PeerRateLimiter) Decorate(p RateLimiterPeer, rw p2p.MsgReadWriter, runL return <-errC } -// throttleIP throttles a number of messages incoming from a given IP. +// throttleIP throttles a number of packets incoming from a given IP. // It allows 10 packets per second. func (r *PeerRateLimiter) throttleIP(ip string) bool { - if r.LimitPerSecIP == 0 { + if r.PacketLimitPerSecIP == 0 { return false } if stringSliceContains(r.whitelistedIPs, ip) { return false } - return r.ipThrottler.Halt(ip, 1, r.LimitPerSecIP) + return r.packetIpThrottler.Halt(ip, 1, r.PacketLimitPerSecIP) } -// throttlePeer throttles a number of messages incoming from a peer. +// throttlePeer throttles a number of packets incoming from a peer. // It allows 3 packets per second. func (r *PeerRateLimiter) throttlePeer(peerID []byte) bool { - if r.LimitPerSecIP == 0 { + if r.PacketLimitPerSecIP == 0 { return false } var id enode.ID @@ -251,7 +255,7 @@ func (r *PeerRateLimiter) throttlePeer(peerID []byte) bool { if enodeIDSliceContains(r.whitelistedPeerIDs, id) { return false } - return r.peerIDThrottler.Halt(id.String(), 1, r.LimitPerSecPeerID) + return r.packetPeerIDThrottler.Halt(id.String(), 1, r.PacketLimitPerSecPeerID) } func stringSliceContains(s []string, searched string) bool { diff --git a/waku/waku.go b/waku/waku.go index 78557314e..17711f16a 100644 --- a/waku/waku.go +++ b/waku/waku.go @@ -400,8 +400,8 @@ func (w *Waku) RateLimits() common.RateLimits { return common.RateLimits{} } return common.RateLimits{ - IPLimits: uint64(w.rateLimiter.LimitPerSecIP), - PeerIDLimits: uint64(w.rateLimiter.LimitPerSecPeerID), + PacketIPLimits: uint64(w.rateLimiter.PacketLimitPerSecIP), + PacketPeerIDLimits: uint64(w.rateLimiter.PacketLimitPerSecPeerID), } }