From d9c59c668d8d292bb407af65d6cae86d74c5ffc7 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 20:59:02 +0000 Subject: [PATCH] fix(proxy): preserve miner remote address in API Co-Authored-By: Virgil --- miner.go | 1 + state_impl.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/miner.go b/miner.go index 3cf6413..aaf235c 100644 --- a/miner.go +++ b/miner.go @@ -33,6 +33,7 @@ type Miner struct { extNH bool // NiceHash mode active (fixed byte splitting) algoEnabled bool // proxy is configured to negotiate the algo extension ip string // remote IP (without port, for logging) + remoteAddr string localPort uint16 user string // login params.login (wallet address), custom diff suffix stripped password string // login params.pass diff --git a/state_impl.go b/state_impl.go index 60be609..e7a22ee 100644 --- a/state_impl.go +++ b/state_impl.go @@ -134,9 +134,13 @@ func (p *Proxy) MinerSnapshots() []MinerSnapshot { defer p.minersMu.RUnlock() rows := make([]MinerSnapshot, 0, len(p.miners)) for _, miner := range p.miners { + ip := miner.RemoteAddr() + if ip == "" { + ip = miner.IP() + } rows = append(rows, MinerSnapshot{ ID: miner.id, - IP: miner.ip, + IP: ip, TX: miner.tx, RX: miner.rx, State: miner.state, @@ -721,7 +725,8 @@ func NewMiner(conn net.Conn, localPort uint16, tlsCfg *tls.Config) *Miner { miner.tlsConn = tlsConn } if remote := conn.RemoteAddr(); remote != nil { - miner.ip = hostOnly(remote.String()) + miner.remoteAddr = remote.String() + miner.ip = hostOnly(miner.remoteAddr) } return miner } @@ -767,6 +772,12 @@ func (m *Miner) SetFixedByte(value uint8) { func (m *Miner) IP() string { return m.ip } +func (m *Miner) RemoteAddr() string { + if m == nil { + return "" + } + return m.remoteAddr +} func (m *Miner) User() string { return m.user }