From a11d5b0969bdac3fb26010b8620db1120830470a Mon Sep 17 00:00:00 2001 From: Virgil Date: Sun, 5 Apr 2026 00:42:12 +0000 Subject: [PATCH] refactor(proxy): align public comments with AX Co-Authored-By: Virgil --- config.go | 16 ++++++++-------- proxy.go | 28 ++++++++++++++-------------- server.go | 4 ++-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/config.go b/config.go index 0ac1023..8bc555f 100644 --- a/config.go +++ b/config.go @@ -2,8 +2,8 @@ package proxy // Config is the top-level proxy configuration. // -// cfg, result := proxy.LoadConfig("/etc/proxy.json") -// if !result.OK { return result.Error } +// cfg, result := proxy.LoadConfig("/etc/proxy.json") +// if !result.OK { return result.Error } type Config struct { Mode string `json:"mode"` // "nicehash" or "simple" Bind []BindAddr `json:"bind"` // listen addresses @@ -27,7 +27,7 @@ type Config struct { // BindAddr is one TCP listen endpoint. // -// proxy.BindAddr{Host: "0.0.0.0", Port: 3333, TLS: false} +// proxy.BindAddr{Host: "0.0.0.0", Port: 3333, TLS: false} type BindAddr struct { Host string `json:"host"` Port uint16 `json:"port"` @@ -36,7 +36,7 @@ type BindAddr struct { // PoolConfig is one upstream pool entry. // -// proxy.PoolConfig{URL: "pool.lthn.io:3333", User: "WALLET", Pass: "x", Enabled: true} +// proxy.PoolConfig{URL: "pool.lthn.io:3333", User: "WALLET", Pass: "x", Enabled: true} type PoolConfig struct { URL string `json:"url"` User string `json:"user"` @@ -51,7 +51,7 @@ type PoolConfig struct { // TLSConfig controls inbound TLS for miner listeners. // -// proxy.TLSConfig{Enabled: true, CertFile: "/etc/proxy/cert.pem", KeyFile: "/etc/proxy/key.pem"} +// proxy.TLSConfig{Enabled: true, CertFile: "/etc/proxy/cert.pem", KeyFile: "/etc/proxy/key.pem"} type TLSConfig struct { Enabled bool `json:"enabled"` CertFile string `json:"cert"` @@ -62,7 +62,7 @@ type TLSConfig struct { // HTTPConfig controls the monitoring API server. // -// proxy.HTTPConfig{Enabled: true, Host: "127.0.0.1", Port: 8080, Restricted: true} +// proxy.HTTPConfig{Enabled: true, Host: "127.0.0.1", Port: 8080, Restricted: true} type HTTPConfig struct { Enabled bool `json:"enabled"` Host string `json:"host"` @@ -73,7 +73,7 @@ type HTTPConfig struct { // RateLimit controls per-IP connection throttling. // -// proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300} +// proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300} type RateLimit struct { MaxConnectionsPerMinute int `json:"max-connections-per-minute"` // 0 = disabled BanDurationSeconds int `json:"ban-duration"` // 0 = no ban @@ -81,7 +81,7 @@ type RateLimit struct { // WorkersMode selects the login field used as the worker identity. // -// proxy.WorkersByRigID +// proxy.WorkersByRigID type WorkersMode string const ( diff --git a/proxy.go b/proxy.go index c861fc1..9073bd0 100644 --- a/proxy.go +++ b/proxy.go @@ -19,8 +19,8 @@ import ( // Proxy owns the servers, splitters, stats, workers, and monitoring API. // -// p, result := proxy.New(cfg) -// if result.OK { p.Start() } +// p, result := proxy.New(cfg) +// if result.OK { p.Start() } type Proxy struct { config *Config splitter Splitter @@ -45,9 +45,9 @@ type Proxy struct { // Splitter is the shared interface implemented by the NiceHash and simple modes. // -// type stubSplitter struct{} +// type stubSplitter struct{} // -// func (stubSplitter) Connect() {} +// func (stubSplitter) Connect() {} type Splitter interface { // Connect establishes the first pool upstream connection. Connect() @@ -67,7 +67,7 @@ type Splitter interface { // UpstreamStats reports pool connection counts. // -// stats := proxy.UpstreamStats{Active: 1, Sleep: 0, Error: 0, Total: 1} +// stats := proxy.UpstreamStats{Active: 1, Sleep: 0, Error: 0, Total: 1} type UpstreamStats struct { Active uint64 // connections currently receiving jobs Sleep uint64 // idle connections (simple mode reuse pool) @@ -77,14 +77,14 @@ type UpstreamStats struct { // LoginEvent is dispatched when a miner completes login. // -// event := proxy.LoginEvent{Miner: miner} +// event := proxy.LoginEvent{Miner: miner} type LoginEvent struct { Miner *Miner } // SubmitEvent carries one miner share submission. // -// event := proxy.SubmitEvent{Miner: miner, JobID: "job-1", Nonce: "deadbeef", Result: "HASH", RequestID: 2} +// event := proxy.SubmitEvent{Miner: miner, JobID: "job-1", Nonce: "deadbeef", Result: "HASH", RequestID: 2} type SubmitEvent struct { Miner *Miner JobID string @@ -96,14 +96,14 @@ type SubmitEvent struct { // CloseEvent is dispatched when a miner connection closes. // -// event := proxy.CloseEvent{Miner: miner} +// event := proxy.CloseEvent{Miner: miner} type CloseEvent struct { Miner *Miner } // 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) @@ -113,8 +113,8 @@ 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") +// limiter := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300}) +// limiter.Allow("1.2.3.4:3333") type RateLimiter struct { config RateLimit buckets map[string]*tokenBucket @@ -124,7 +124,7 @@ type RateLimiter struct { // tokenBucket is the per-IP refillable counter. // -// bucket := tokenBucket{tokens: 30, lastRefill: time.Now()} +// bucket := tokenBucket{tokens: 30, lastRefill: time.Now()} type tokenBucket struct { tokens int lastRefill time.Time @@ -132,8 +132,8 @@ type tokenBucket struct { // CustomDiff applies a login-time difficulty override. // -// resolver := proxy.NewCustomDiff(50000) -// resolver.Apply(&Miner{user: "WALLET+75000"}) +// resolver := proxy.NewCustomDiff(50000) +// resolver.Apply(&Miner{user: "WALLET+75000"}) type CustomDiff struct { globalDiff uint64 } diff --git a/server.go b/server.go index d2d9fe9..b66ea37 100644 --- a/server.go +++ b/server.go @@ -7,8 +7,8 @@ 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(bind, tlsCfg, rateLimiter, onAccept) +// if result.OK { srv.Start() } type Server struct { addr BindAddr tlsCfg *tls.Config // nil for plain TCP