refactor(proxy): clarify agent-facing names

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 23:10:35 +00:00
parent 0bb5ce827b
commit 167ecc2bdc
4 changed files with 48 additions and 48 deletions

View file

@ -56,12 +56,12 @@ func LoadConfig(path string) (*Config, Result) {
return nil, errorResult(err) return nil, errorResult(err)
} }
cfg := &Config{} config := &Config{}
if err := json.Unmarshal(data, cfg); err != nil { if err := json.Unmarshal(data, config); err != nil {
return nil, errorResult(err) return nil, errorResult(err)
} }
cfg.configPath = path config.configPath = path
return cfg, cfg.Validate() return config, config.Validate()
} }
// Validate checks that mandatory bind and pool settings are present. // Validate checks that mandatory bind and pool settings are present.
@ -324,9 +324,9 @@ func (w *ConfigWatcher) Start() {
mod := info.ModTime() mod := info.ModTime()
if mod.After(w.lastMod) { if mod.After(w.lastMod) {
w.lastMod = mod w.lastMod = mod
cfg, result := LoadConfig(w.path) config, result := LoadConfig(w.path)
if result.OK && cfg != nil { if result.OK && config != nil {
w.onChange(cfg) w.onChange(config)
} }
} }
case <-w.done: case <-w.done:

View file

@ -8,20 +8,20 @@ import (
) )
func init() { func init() {
proxy.RegisterSplitterFactory("nicehash", func(cfg *proxy.Config, events *proxy.EventBus) proxy.Splitter { proxy.RegisterSplitterFactory("nicehash", func(config *proxy.Config, eventBus *proxy.EventBus) proxy.Splitter {
return NewNonceSplitter(cfg, events, pool.NewStrategyFactory(cfg)) return NewNonceSplitter(config, eventBus, pool.NewStrategyFactory(config))
}) })
} }
// NewNonceSplitter creates a NiceHash splitter. // NewNonceSplitter creates a NiceHash splitter.
func NewNonceSplitter(config *proxy.Config, events *proxy.EventBus, factory pool.StrategyFactory) *NonceSplitter { func NewNonceSplitter(config *proxy.Config, eventBus *proxy.EventBus, factory pool.StrategyFactory) *NonceSplitter {
if factory == nil { if factory == nil {
factory = pool.NewStrategyFactory(config) factory = pool.NewStrategyFactory(config)
} }
return &NonceSplitter{ return &NonceSplitter{
byID: make(map[int64]*NonceMapper), byID: make(map[int64]*NonceMapper),
config: config, config: config,
events: events, events: eventBus,
strategyFactory: factory, strategyFactory: factory,
} }
} }
@ -212,13 +212,13 @@ func (s *NonceSplitter) addMapperLocked() *NonceMapper {
} }
// NewNonceMapper creates a mapper for one upstream connection. // NewNonceMapper creates a mapper for one upstream connection.
func NewNonceMapper(id int64, cfg *proxy.Config, strategy pool.Strategy) *NonceMapper { func NewNonceMapper(id int64, config *proxy.Config, strategy pool.Strategy) *NonceMapper {
return &NonceMapper{ return &NonceMapper{
id: id, id: id,
storage: NewNonceStorage(), storage: NewNonceStorage(),
strategy: strategy, strategy: strategy,
pending: make(map[int64]SubmitContext), pending: make(map[int64]SubmitContext),
config: cfg, config: config,
} }
} }

View file

@ -8,13 +8,13 @@ import (
) )
func init() { func init() {
proxy.RegisterSplitterFactory("simple", func(cfg *proxy.Config, events *proxy.EventBus) proxy.Splitter { proxy.RegisterSplitterFactory("simple", func(config *proxy.Config, eventBus *proxy.EventBus) proxy.Splitter {
return NewSimpleSplitter(cfg, events, pool.NewStrategyFactory(cfg)) return NewSimpleSplitter(config, eventBus, pool.NewStrategyFactory(config))
}) })
} }
// NewSimpleSplitter creates the passthrough splitter. // NewSimpleSplitter creates the passthrough splitter.
func NewSimpleSplitter(config *proxy.Config, events *proxy.EventBus, factory pool.StrategyFactory) *SimpleSplitter { func NewSimpleSplitter(config *proxy.Config, eventBus *proxy.EventBus, factory pool.StrategyFactory) *SimpleSplitter {
if factory == nil { if factory == nil {
factory = pool.NewStrategyFactory(config) factory = pool.NewStrategyFactory(config)
} }
@ -22,7 +22,7 @@ func NewSimpleSplitter(config *proxy.Config, events *proxy.EventBus, factory poo
active: make(map[int64]*SimpleMapper), active: make(map[int64]*SimpleMapper),
idle: make(map[int64]*SimpleMapper), idle: make(map[int64]*SimpleMapper),
config: config, config: config,
events: events, events: eventBus,
factory: factory, factory: factory,
} }
} }

View file

@ -963,17 +963,17 @@ type stratumRequest struct {
} }
func (m *Miner) handleLine(line []byte) bool { func (m *Miner) handleLine(line []byte) bool {
var req stratumRequest var request stratumRequest
if err := json.Unmarshal(line, &req); err != nil { if err := json.Unmarshal(line, &request); err != nil {
return false return false
} }
switch req.Method { switch request.Method {
case "login": case "login":
m.handleLogin(req) m.handleLogin(request)
case "submit": case "submit":
m.handleSubmit(req) m.handleSubmit(request)
case "keepalived": case "keepalived":
m.handleKeepalived(req) m.handleKeepalived(request)
} }
return true return true
} }
@ -986,17 +986,17 @@ type loginParams struct {
RigID string `json:"rigid"` RigID string `json:"rigid"`
} }
func (m *Miner) handleLogin(req stratumRequest) { func (m *Miner) handleLogin(request stratumRequest) {
if m.state != MinerStateWaitLogin { if m.state != MinerStateWaitLogin {
return return
} }
var params loginParams var params loginParams
if err := json.Unmarshal(req.Params, &params); err != nil || strings.TrimSpace(params.Login) == "" { if err := json.Unmarshal(request.Params, &params); err != nil || strings.TrimSpace(params.Login) == "" {
m.ReplyWithError(requestID(req.ID), "Invalid payment address provided") m.ReplyWithError(requestID(request.ID), "Invalid payment address provided")
return return
} }
if m.accessPassword != "" && params.Pass != m.accessPassword { if m.accessPassword != "" && params.Pass != m.accessPassword {
m.ReplyWithError(requestID(req.ID), "Invalid password") m.ReplyWithError(requestID(request.ID), "Invalid password")
return return
} }
m.user, m.customDiff = parseLoginUser(params.Login, m.globalDiff) m.user, m.customDiff = parseLoginUser(params.Login, m.globalDiff)
@ -1018,16 +1018,16 @@ func (m *Miner) handleLogin(req stratumRequest) {
if m.MapperID() < 0 { if m.MapperID() < 0 {
m.state = MinerStateWaitLogin m.state = MinerStateWaitLogin
m.rpcID = "" m.rpcID = ""
m.ReplyWithError(requestID(req.ID), "Proxy is full, try again later") m.ReplyWithError(requestID(request.ID), "Proxy is full, try again later")
return return
} }
} else if m.RouteID() < 0 { } else if m.RouteID() < 0 {
m.state = MinerStateWaitLogin m.state = MinerStateWaitLogin
m.rpcID = "" m.rpcID = ""
m.ReplyWithError(requestID(req.ID), "Proxy is unavailable, try again later") m.ReplyWithError(requestID(request.ID), "Proxy is unavailable, try again later")
return return
} }
m.replyLoginSuccess(requestID(req.ID)) m.replyLoginSuccess(requestID(request.ID))
} }
func parseLoginUser(login string, globalDiff uint64) (string, uint64) { func parseLoginUser(login string, globalDiff uint64) (string, uint64) {
@ -1044,9 +1044,9 @@ func parseLoginUser(login string, globalDiff uint64) (string, uint64) {
return login, 0 return login, 0
} }
func (m *Miner) handleSubmit(req stratumRequest) { func (m *Miner) handleSubmit(request stratumRequest) {
if m.state != MinerStateReady { if m.state != MinerStateReady {
m.ReplyWithError(requestID(req.ID), "Unauthenticated") m.ReplyWithError(requestID(request.ID), "Unauthenticated")
return return
} }
var params struct { var params struct {
@ -1056,20 +1056,20 @@ func (m *Miner) handleSubmit(req stratumRequest) {
Result string `json:"result"` Result string `json:"result"`
Algo string `json:"algo"` Algo string `json:"algo"`
} }
if err := json.Unmarshal(req.Params, &params); err != nil { if err := json.Unmarshal(request.Params, &params); err != nil {
m.ReplyWithError(requestID(req.ID), "Invalid nonce") m.ReplyWithError(requestID(request.ID), "Invalid nonce")
return return
} }
if params.ID != m.rpcID { if params.ID != m.rpcID {
m.ReplyWithError(requestID(req.ID), "Unauthenticated") m.ReplyWithError(requestID(request.ID), "Unauthenticated")
return return
} }
if params.JobID == "" { if params.JobID == "" {
m.ReplyWithError(requestID(req.ID), "Missing job id") m.ReplyWithError(requestID(request.ID), "Missing job id")
return return
} }
if !isLowerHex8(params.Nonce) { if !isLowerHex8(params.Nonce) {
m.ReplyWithError(requestID(req.ID), "Invalid nonce") m.ReplyWithError(requestID(request.ID), "Invalid nonce")
return return
} }
if m.onSubmit != nil { if m.onSubmit != nil {
@ -1079,15 +1079,15 @@ func (m *Miner) handleSubmit(req stratumRequest) {
Nonce: params.Nonce, Nonce: params.Nonce,
Result: params.Result, Result: params.Result,
Algo: params.Algo, Algo: params.Algo,
RequestID: requestID(req.ID), RequestID: requestID(request.ID),
}) })
} }
m.touchActivity() m.touchActivity()
} }
func (m *Miner) handleKeepalived(req stratumRequest) { func (m *Miner) handleKeepalived(request stratumRequest) {
m.touchActivity() m.touchActivity()
m.Success(requestID(req.ID), "KEEPALIVED") m.Success(requestID(request.ID), "KEEPALIVED")
} }
func requestID(id any) int64 { func requestID(id any) int64 {
@ -1432,18 +1432,18 @@ func insertTopDiff(top *[10]uint64, diff uint64) {
// //
// workers := proxy.NewWorkers(proxy.WorkersByRigID, bus) // workers := proxy.NewWorkers(proxy.WorkersByRigID, bus)
// workers.OnLogin(proxy.Event{Miner: miner}) // workers.OnLogin(proxy.Event{Miner: miner})
func NewWorkers(mode WorkersMode, bus *EventBus) *Workers { func NewWorkers(mode WorkersMode, eventBus *EventBus) *Workers {
workers := &Workers{ workers := &Workers{
mode: mode, mode: mode,
nameIndex: make(map[string]int), nameIndex: make(map[string]int),
idIndex: make(map[int64]int), idIndex: make(map[int64]int),
} }
workers.bindEvents(bus) workers.bindEvents(eventBus)
return workers return workers
} }
func (w *Workers) bindEvents(bus *EventBus) { func (w *Workers) bindEvents(eventBus *EventBus) {
if w == nil || bus == nil { if w == nil || eventBus == nil {
return return
} }
w.mu.Lock() w.mu.Lock()
@ -1451,10 +1451,10 @@ func (w *Workers) bindEvents(bus *EventBus) {
if w.subscribed { if w.subscribed {
return return
} }
bus.Subscribe(EventLogin, w.OnLogin) eventBus.Subscribe(EventLogin, w.OnLogin)
bus.Subscribe(EventAccept, w.OnAccept) eventBus.Subscribe(EventAccept, w.OnAccept)
bus.Subscribe(EventReject, w.OnReject) eventBus.Subscribe(EventReject, w.OnReject)
bus.Subscribe(EventClose, w.OnClose) eventBus.Subscribe(EventClose, w.OnClose)
w.subscribed = true w.subscribed = true
} }