package proxy import ( "crypto/tls" "net" "sync" "time" ) // MinerState represents the lifecycle state of one miner connection. // // WaitLogin → WaitReady → Ready → Closing type MinerState int const ( MinerStateWaitLogin MinerState = iota // connection open, awaiting login request (10s timeout) MinerStateWaitReady // login validated, awaiting upstream pool job (600s timeout) MinerStateReady // receiving jobs, accepting submit requests MinerStateClosing // TCP close in progress ) // Miner is the state machine for one miner TCP connection. // // // created by Server on accept: // m := proxy.NewMiner(conn, 3333, nil) // m.Start() type Miner struct { id int64 // monotonically increasing per-process; atomic assignment rpcID string // UUID v4 sent to miner as session id state MinerState stateMu sync.RWMutex extAlgo bool // miner sent algo list in login params algoExtension bool // config allows forwarding algo negotiation extNH bool // NiceHash mode active (fixed byte splitting) ip string // remote IP (without port, for logging) localPort uint16 user string // login params.login (wallet address), custom diff suffix stripped password string // login params.pass agent string // login params.agent rigID string // login params.rigid (optional extension) algo []string fixedByte uint8 // NiceHash slot index (0-255) mapperID int64 // which NonceMapper owns this miner; -1 = unassigned routeID int64 // SimpleMapper ID in simple mode; -1 = unassigned customDiff uint64 // 0 = use pool diff; non-zero = cap diff to this value diff uint64 // last difficulty sent to this miner from the pool rx uint64 // bytes received from miner tx uint64 // bytes sent to miner connectedAt time.Time lastActivityAt time.Time events *EventBus splitter Splitter currentJob *Job closeOnce sync.Once accessPassword string conn net.Conn tlsConn *tls.Conn // nil if plain TCP sendMu sync.Mutex // serialises writes to conn buf [16384]byte // per-miner send buffer; avoids per-write allocations }