2025-02-03 15:31:18 -05:00
2025-02-03 15:31:18 -05:00
2025-02-01 14:36:31 -05:00
2025-02-01 14:36:31 -05:00
2025-02-01 14:36:31 -05:00
2025-02-01 14:36:31 -05:00
2025-02-01 14:36:31 -05:00
2025-02-01 14:36:31 -05:00
2025-02-02 00:22:46 -05:00
2025-02-01 14:36:31 -05:00
2025-02-01 14:36:31 -05:00

go-limit

A simple, thread-safe connection limiter for Go's net.Listener that manages concurrent connections and rate limiting. Factored out from sam-forwarder to be used in go-i2ptunnel.

Install

go get github.com/go-i2p/go-limit

Quick Start

package main

import (
    "log"
    "net"
    "github.com/go-i2p/go-limit"
)

func main() {
    base, _ := net.Listen("tcp", ":8080")
    
    listener := limitedlistener.NewLimitedListener(base,
        limitedlistener.WithMaxConnections(1000),  // max concurrent
        limitedlistener.WithRateLimit(100))        // per second
    defer listener.Close()

    for {
        conn, err := listener.Accept()
        if err != nil {
            log.Printf("Accept error: %v", err)
            continue
        }
        go handleConnection(conn)
    }
}

Features

  • Limit concurrent connections
  • Rate limiting (connections per second)
  • Connection tracking
  • Real-time statistics

Configuration

// Set maximum concurrent connections
WithMaxConnections(1000)

// Set rate limit (connections per second)
WithRateLimit(100.0)

// Get current stats
stats := listener.GetStats()

License

MIT License

Support

Issues and PRs welcome at github.com/go-i2p/go-limit

Description
No description provided
Readme 104 KiB
Languages
Go 98.4%
Makefile 1.6%