diff --git a/core_impl.go b/core_impl.go index b56055e..ada5363 100644 --- a/core_impl.go +++ b/core_impl.go @@ -218,7 +218,7 @@ func (cd *CustomDiff) OnLogin(e Event) { // if limiter.Allow("203.0.113.42:3333") { /* accept */ } func NewRateLimiter(cfg RateLimit) *RateLimiter { return &RateLimiter{ - cfg: cfg, + config: cfg, buckets: make(map[string]*tokenBucket), banned: make(map[string]time.Time), } @@ -226,7 +226,7 @@ func NewRateLimiter(cfg RateLimit) *RateLimiter { // Allow returns true if the IP address is permitted to open a new connection. func (rl *RateLimiter) Allow(ip string) bool { - if rl == nil || rl.cfg.MaxConnectionsPerMinute <= 0 { + if rl == nil || rl.config.MaxConnectionsPerMinute <= 0 { return true } host := hostOnly(ip) @@ -244,14 +244,14 @@ func (rl *RateLimiter) Allow(ip string) bool { bucket, ok := rl.buckets[host] if !ok { - bucket = &tokenBucket{tokens: rl.cfg.MaxConnectionsPerMinute, lastRefill: now} + bucket = &tokenBucket{tokens: rl.config.MaxConnectionsPerMinute, lastRefill: now} rl.buckets[host] = bucket } - refillBucket(bucket, rl.cfg.MaxConnectionsPerMinute, now) + refillBucket(bucket, rl.config.MaxConnectionsPerMinute, now) if bucket.tokens <= 0 { - if rl.cfg.BanDurationSeconds > 0 { - rl.banned[host] = now.Add(time.Duration(rl.cfg.BanDurationSeconds) * time.Second) + if rl.config.BanDurationSeconds > 0 { + rl.banned[host] = now.Add(time.Duration(rl.config.BanDurationSeconds) * time.Second) } return false } @@ -263,7 +263,7 @@ func (rl *RateLimiter) Allow(ip string) bool { // Tick removes expired ban entries and refills token buckets. func (rl *RateLimiter) Tick() { - if rl == nil || rl.cfg.MaxConnectionsPerMinute <= 0 { + if rl == nil || rl.config.MaxConnectionsPerMinute <= 0 { return } now := time.Now() @@ -277,7 +277,7 @@ func (rl *RateLimiter) Tick() { } } for _, bucket := range rl.buckets { - refillBucket(bucket, rl.cfg.MaxConnectionsPerMinute, now) + refillBucket(bucket, rl.config.MaxConnectionsPerMinute, now) } } diff --git a/pool/client.go b/pool/client.go index 6f7f60f..3b23e4c 100644 --- a/pool/client.go +++ b/pool/client.go @@ -19,7 +19,7 @@ import ( // client := pool.NewStratumClient(poolCfg, listener) // client.Connect() type StratumClient struct { - cfg proxy.PoolConfig + config proxy.PoolConfig listener StratumListener conn net.Conn tlsConn *tls.Conn // nil if plain TCP diff --git a/pool/impl.go b/pool/impl.go index bf48b03..64acfb9 100644 --- a/pool/impl.go +++ b/pool/impl.go @@ -27,7 +27,7 @@ func NewStrategyFactory(cfg *proxy.Config) StrategyFactory { // NewStratumClient constructs a pool client. func NewStratumClient(cfg proxy.PoolConfig, listener StratumListener) *StratumClient { return &StratumClient{ - cfg: cfg, + config: cfg, listener: listener, pending: make(map[int64]struct{}), } @@ -48,7 +48,7 @@ func (c *StratumClient) Connect() proxy.Result { if c == nil { return proxy.Result{OK: false, Error: errors.New("client is nil")} } - addr := c.cfg.URL + addr := c.config.URL if addr == "" { return proxy.Result{OK: false, Error: errors.New("pool url is empty")} } @@ -56,7 +56,7 @@ func (c *StratumClient) Connect() proxy.Result { if err != nil { return proxy.Result{OK: false, Error: err} } - if c.cfg.TLS { + if c.config.TLS { host := addr if strings.Contains(addr, ":") { host, _, _ = net.SplitHostPort(addr) @@ -67,7 +67,7 @@ func (c *StratumClient) Connect() proxy.Result { _ = conn.Close() return proxy.Result{OK: false, Error: err} } - if fp := strings.TrimSpace(strings.ToLower(c.cfg.TLSFingerprint)); fp != "" { + if fp := strings.TrimSpace(strings.ToLower(c.config.TLSFingerprint)); fp != "" { cert := tlsConn.ConnectionState().PeerCertificates if len(cert) == 0 { _ = tlsConn.Close() @@ -94,14 +94,14 @@ func (c *StratumClient) Login() { return } params := map[string]any{ - "login": c.cfg.User, - "pass": c.cfg.Pass, + "login": c.config.User, + "pass": c.config.Pass, } - if c.cfg.RigID != "" { - params["rigid"] = c.cfg.RigID + if c.config.RigID != "" { + params["rigid"] = c.config.RigID } - if c.cfg.Algo != "" { - params["algo"] = []string{c.cfg.Algo} + if c.config.Algo != "" { + params["algo"] = []string{c.config.Algo} } req := map[string]any{ "id": 1, @@ -339,7 +339,7 @@ func NewFailoverStrategy(pools []proxy.PoolConfig, listener StratumListener, cfg return &FailoverStrategy{ pools: pools, listener: listener, - cfg: cfg, + config: cfg, } } @@ -361,12 +361,12 @@ func (s *FailoverStrategy) connectLocked(start int) { } retries := 1 retryPause := time.Second - if s.cfg != nil { - if s.cfg.Retries > 0 { - retries = s.cfg.Retries + if s.config != nil { + if s.config.Retries > 0 { + retries = s.config.Retries } - if s.cfg.RetryPause > 0 { - retryPause = time.Duration(s.cfg.RetryPause) * time.Second + if s.config.RetryPause > 0 { + retryPause = time.Duration(s.config.RetryPause) * time.Second } } for attempt := 0; attempt < retries; attempt++ { @@ -389,8 +389,8 @@ func (s *FailoverStrategy) currentPools() []proxy.PoolConfig { if s == nil { return nil } - if s.cfg != nil && len(s.cfg.Pools) > 0 { - return s.cfg.Pools + if s.config != nil && len(s.config.Pools) > 0 { + return s.config.Pools } return s.pools } @@ -431,7 +431,7 @@ func (s *FailoverStrategy) Tick(ticks uint64) { s.mu.Lock() client := s.client s.mu.Unlock() - if client != nil && client.cfg.Keepalive { + if client != nil && client.config.Keepalive { client.Keepalive() } } diff --git a/pool/strategy.go b/pool/strategy.go index c9e1986..c2ed1df 100644 --- a/pool/strategy.go +++ b/pool/strategy.go @@ -17,7 +17,7 @@ type FailoverStrategy struct { current int client *StratumClient listener StratumListener - cfg *proxy.Config + config *proxy.Config closing bool mu sync.Mutex } diff --git a/proxy.go b/proxy.go index c9a8e8d..dfee952 100644 --- a/proxy.go +++ b/proxy.go @@ -106,7 +106,7 @@ type ConfigWatcher struct { // rl := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300}) // if rl.Allow("1.2.3.4:3333") { proceed() } type RateLimiter struct { - cfg RateLimit + config RateLimit buckets map[string]*tokenBucket banned map[string]time.Time mu sync.Mutex diff --git a/splitter/nicehash/impl.go b/splitter/nicehash/impl.go index 654a484..542acaa 100644 --- a/splitter/nicehash/impl.go +++ b/splitter/nicehash/impl.go @@ -20,7 +20,7 @@ func NewNonceSplitter(cfg *proxy.Config, events *proxy.EventBus, factory pool.St } return &NonceSplitter{ byID: make(map[int64]*NonceMapper), - cfg: cfg, + config: cfg, events: events, strategyFactory: factory, } @@ -171,7 +171,7 @@ func (s *NonceSplitter) Disconnect() { func (s *NonceSplitter) addMapperLocked() *NonceMapper { id := s.seq s.seq++ - mapper := NewNonceMapper(id, s.cfg, nil) + mapper := NewNonceMapper(id, s.config, nil) mapper.events = s.events mapper.lastUsed = time.Now() mapper.strategy = s.strategyFactory(mapper) @@ -191,7 +191,7 @@ func NewNonceMapper(id int64, cfg *proxy.Config, strategy pool.Strategy) *NonceM storage: NewNonceStorage(), strategy: strategy, pending: make(map[int64]SubmitContext), - cfg: cfg, + config: cfg, } } diff --git a/splitter/nicehash/mapper.go b/splitter/nicehash/mapper.go index 1b51044..fa192fd 100644 --- a/splitter/nicehash/mapper.go +++ b/splitter/nicehash/mapper.go @@ -18,7 +18,7 @@ type NonceMapper struct { storage *NonceStorage strategy pool.Strategy // manages pool client lifecycle and failover pending map[int64]SubmitContext // sequence → {requestID, minerID} - cfg *proxy.Config + config *proxy.Config events *proxy.EventBus active bool // true once pool has sent at least one job suspended int // > 0 when pool connection is in error/reconnecting diff --git a/splitter/nicehash/splitter.go b/splitter/nicehash/splitter.go index 27cd940..e766d7c 100644 --- a/splitter/nicehash/splitter.go +++ b/splitter/nicehash/splitter.go @@ -24,7 +24,7 @@ import ( type NonceSplitter struct { mappers []*NonceMapper byID map[int64]*NonceMapper - cfg *proxy.Config + config *proxy.Config events *proxy.EventBus strategyFactory pool.StrategyFactory mu sync.RWMutex diff --git a/splitter/simple/impl.go b/splitter/simple/impl.go index 9f7c7eb..3fee973 100644 --- a/splitter/simple/impl.go +++ b/splitter/simple/impl.go @@ -21,7 +21,7 @@ func NewSimpleSplitter(cfg *proxy.Config, events *proxy.EventBus, factory pool.S return &SimpleSplitter{ active: make(map[int64]*SimpleMapper), idle: make(map[int64]*SimpleMapper), - cfg: cfg, + config: cfg, events: events, factory: factory, } @@ -55,9 +55,9 @@ func (s *SimpleSplitter) OnLogin(event *proxy.LoginEvent) { defer s.mu.Unlock() now := time.Now() - if s.cfg.ReuseTimeout > 0 { + if s.config.ReuseTimeout > 0 { for id, mapper := range s.idle { - if mapper.strategy != nil && mapper.strategy.IsActive() && !mapper.idleAt.IsZero() && now.Sub(mapper.idleAt) <= time.Duration(s.cfg.ReuseTimeout)*time.Second { + if mapper.strategy != nil && mapper.strategy.IsActive() && !mapper.idleAt.IsZero() && now.Sub(mapper.idleAt) <= time.Duration(s.config.ReuseTimeout)*time.Second { delete(s.idle, id) mapper.miner = event.Miner mapper.idleAt = time.Time{} @@ -109,7 +109,7 @@ func (s *SimpleSplitter) OnClose(event *proxy.CloseEvent) { mapper.miner = nil mapper.idleAt = time.Now() event.Miner.SetRouteID(-1) - if s.cfg.ReuseTimeout > 0 { + if s.config.ReuseTimeout > 0 { s.idle[mapper.id] = mapper return } @@ -128,7 +128,7 @@ func (s *SimpleSplitter) GC() { defer s.mu.Unlock() now := time.Now() for id, mapper := range s.idle { - if mapper.stopped || (s.cfg.ReuseTimeout > 0 && now.Sub(mapper.idleAt) > time.Duration(s.cfg.ReuseTimeout)*time.Second) { + if mapper.stopped || (s.config.ReuseTimeout > 0 && now.Sub(mapper.idleAt) > time.Duration(s.config.ReuseTimeout)*time.Second) { if mapper.strategy != nil { mapper.strategy.Disconnect() } diff --git a/splitter/simple/splitter.go b/splitter/simple/splitter.go index a78ccea..28ba70b 100644 --- a/splitter/simple/splitter.go +++ b/splitter/simple/splitter.go @@ -20,7 +20,7 @@ import ( type SimpleSplitter struct { active map[int64]*SimpleMapper // minerID → mapper idle map[int64]*SimpleMapper // mapperID → mapper (reuse pool, keyed by mapper seq) - cfg *proxy.Config + config *proxy.Config events *proxy.EventBus factory pool.StrategyFactory mu sync.Mutex diff --git a/state_impl.go b/state_impl.go index bae4892..4c70211 100644 --- a/state_impl.go +++ b/state_impl.go @@ -1663,7 +1663,7 @@ func (s *Server) listen() Result { // IsActive reports whether the limiter has enabled rate limiting. func (rl *RateLimiter) IsActive() bool { - return rl != nil && rl.cfg.MaxConnectionsPerMinute > 0 + return rl != nil && rl.config.MaxConnectionsPerMinute > 0 } func nextMinerID() int64 { return atomic.AddInt64(&minerSeq, 1) }