refactor(proxy): clarify config path naming

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 20:53:49 +00:00
parent c7d688ccfa
commit ce7d3301fc
6 changed files with 13 additions and 16 deletions

View file

@ -77,6 +77,9 @@ type ResultsResponse struct {
}
// RegisterRoutes wires the monitoring endpoints onto the supplied router.
//
// proxyapi.RegisterRoutes(mux, p)
// // GET /1/summary, /1/workers, and /1/miners are now live.
func RegisterRoutes(r Router, p *proxy.Proxy) {
if r == nil || p == nil {
return

View file

@ -22,7 +22,7 @@ type Config struct {
RetryPause int `json:"retry-pause"` // seconds between retries
Watch bool `json:"watch"` // hot-reload on file change
RateLimit RateLimit `json:"rate-limit"` // per-IP connection rate limit
sourcePath string
configPath string
}
// BindAddr is one TCP listen endpoint.

View file

@ -59,7 +59,7 @@ func LoadConfig(path string) (*Config, Result) {
if err := json.Unmarshal(data, cfg); err != nil {
return nil, errorResult(err)
}
cfg.sourcePath = path
cfg.configPath = path
return cfg, cfg.Validate()
}

View file

@ -95,7 +95,7 @@ func TestProxy_New_Watch_Good(t *testing.T) {
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool.example:3333", Enabled: true}},
Watch: true,
sourcePath: "/tmp/proxy.json",
configPath: "/tmp/proxy.json",
}
proxyInstance, result := New(cfg)

View file

@ -91,11 +91,8 @@ type CloseEvent struct {
}
// ConfigWatcher polls a config file for mtime changes and calls onChange on modification.
// Uses 1-second polling; does not require fsnotify.
//
// w := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) {
// p.Reload(cfg)
// })
// w := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) { p.Reload(cfg) })
// w.Start()
type ConfigWatcher struct {
path string
@ -105,12 +102,9 @@ type ConfigWatcher struct {
}
// RateLimiter implements per-IP token bucket connection rate limiting.
// Each unique IP has a bucket initialised to MaxConnectionsPerMinute tokens.
// Each connection attempt consumes one token. Tokens refill at 1 per (60/max) seconds.
// An IP that empties its bucket is added to a ban list for BanDurationSeconds.
//
// rl := proxy.NewRateLimiter(cfg.RateLimit)
// if !rl.Allow("1.2.3.4") { conn.Close(); return }
// rl := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300})
// if rl.Allow("1.2.3.4:3333") { proceed() }
type RateLimiter struct {
cfg RateLimit
buckets map[string]*tokenBucket

View file

@ -77,8 +77,8 @@ func New(cfg *Config) (*Proxy, Result) {
}
p.events.Subscribe(EventAccept, p.onShareSettled)
p.events.Subscribe(EventReject, p.onShareSettled)
if cfg.Watch && cfg.sourcePath != "" {
p.watcher = NewConfigWatcher(cfg.sourcePath, p.Reload)
if cfg.Watch && cfg.configPath != "" {
p.watcher = NewConfigWatcher(cfg.configPath, p.Reload)
}
if factory, ok := getSplitterFactory(cfg.Mode); ok {
@ -314,12 +314,12 @@ func (p *Proxy) Reload(cfg *Config) {
preservedBind := append([]BindAddr(nil), p.config.Bind...)
preservedMode := p.config.Mode
preservedWorkers := p.config.Workers
preservedSourcePath := p.config.sourcePath
preservedConfigPath := p.config.configPath
*p.config = *cfg
p.config.Bind = preservedBind
p.config.Mode = preservedMode
p.config.Workers = preservedWorkers
p.config.sourcePath = preservedSourcePath
p.config.configPath = preservedConfigPath
}
if p.customDiff != nil {
p.customDiff.globalDiff = cfg.CustomDiff