diff --git a/proxy.go b/proxy.go index 867326c..aab5894 100644 --- a/proxy.go +++ b/proxy.go @@ -14,10 +14,12 @@ import ( "time" ) -// Proxy owns the servers, splitters, stats, workers, and monitoring API. +// Proxy is the top-level orchestrator. // // p, result := proxy.New(cfg) -// if result.OK { p.Start() } +// if result.OK { +// p.Start() +// } type Proxy struct { config *Config configMu sync.RWMutex @@ -110,7 +112,9 @@ type CloseEvent struct { // ConfigWatcher polls a config file for changes. // -// watcher := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) { p.Reload(cfg) }) +// watcher := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) { +// p.Reload(cfg) +// }) type ConfigWatcher struct { path string onChange func(*Config) @@ -121,7 +125,9 @@ type ConfigWatcher struct { // RateLimiter throttles new connections per source IP. // // limiter := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300}) -// limiter.Allow("1.2.3.4:3333") +// if limiter.Allow("1.2.3.4:3333") { +// // accept the socket +// } type RateLimiter struct { config RateLimit buckets map[string]*tokenBucket diff --git a/server.go b/server.go index b66ea37..f268d06 100644 --- a/server.go +++ b/server.go @@ -7,8 +7,15 @@ import ( // Server listens on one BindAddr and creates a Miner for each accepted connection. // -// srv, result := proxy.NewServer(bind, tlsCfg, rateLimiter, onAccept) -// if result.OK { srv.Start() } +// srv, result := proxy.NewServer( +// proxy.BindAddr{Host: "0.0.0.0", Port: 3333, TLS: false}, +// nil, +// proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30}), +// onAccept, +// ) +// if result.OK { +// srv.Start() +// } type Server struct { addr BindAddr tlsCfg *tls.Config // nil for plain TCP