Skip to content

Commit 087b37f

Browse files
committed
Update examples/rate_limiter.ks for better code
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 9fbdd82 commit 087b37f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

examples/rate_limiter.ks

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ config network {
3838
var src_ip = 0x7F000001 // Placeholder IP (127.0.0.1)
3939

4040
// Update the count
41-
packet_counts[src_ip] += 1
41+
if (packet_counts[src_ip] != none) {
42+
packet_counts[src_ip] += 1
43+
} else {
44+
packet_counts[src_ip] = 0
45+
}
4246

4347
// Rate limiting: drop if too many packets
4448
if (packet_counts[src_ip] > network.limit) {

0 commit comments

Comments
 (0)