From 30ff0131585c815d88248f4a9e2107f5e1d2a7df Mon Sep 17 00:00:00 2001 From: Virgil Date: Sun, 5 Apr 2026 02:34:53 +0000 Subject: [PATCH] docs(proxy): sharpen AX usage examples Co-Authored-By: Virgil --- core_impl.go | 2 +- log/impl.go | 20 ++++++++++++++++---- state_impl.go | 8 ++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/core_impl.go b/core_impl.go index 05f9d81..3719500 100644 --- a/core_impl.go +++ b/core_impl.go @@ -282,7 +282,7 @@ func (cd *CustomDiff) OnLogin(e Event) { if e.Miner.customDiffResolved { return } - e.Miner.user, e.Miner.customDiff = parseLoginUser(e.Miner.user, cd.globalDiff.Load()) + e.Miner.user, e.Miner.customDiff = resolveLoginCustomDiff(e.Miner.user, cd.globalDiff.Load()) e.Miner.customDiffResolved = true } diff --git a/log/impl.go b/log/impl.go index e36fcca..661ea12 100644 --- a/log/impl.go +++ b/log/impl.go @@ -33,7 +33,10 @@ func (l *AccessLog) Close() { } } -// OnLogin writes `2026-04-04T12:00:00Z CONNECT 10.0.0.1 WALLET XMRig/6.21.0`. +// OnLogin writes a connect line such as: +// +// al.OnLogin(proxy.Event{Miner: &proxy.Miner{}}) +// // 2026-04-04T12:00:00Z CONNECT 10.0.0.1 WALLET XMRig/6.21.0 func (l *AccessLog) OnLogin(e proxy.Event) { if l == nil || e.Miner == nil { return @@ -41,7 +44,10 @@ func (l *AccessLog) OnLogin(e proxy.Event) { l.writeConnectLine(e.Miner.IP(), e.Miner.User(), e.Miner.Agent()) } -// OnClose writes `2026-04-04T12:00:00Z CLOSE 10.0.0.1 WALLET rx=512 tx=4096`. +// OnClose writes a close line such as: +// +// al.OnClose(proxy.Event{Miner: &proxy.Miner{}}) +// // 2026-04-04T12:00:00Z CLOSE 10.0.0.1 WALLET rx=512 tx=4096 func (l *AccessLog) OnClose(e proxy.Event) { if l == nil || e.Miner == nil { return @@ -73,7 +79,10 @@ func (l *ShareLog) Close() { } } -// OnAccept writes `2026-04-04T12:00:00Z ACCEPT WALLET diff=100000 latency=82ms`. +// OnAccept writes an accept line such as: +// +// sl.OnAccept(proxy.Event{Miner: &proxy.Miner{}, Diff: 100000, Latency: 82}) +// // 2026-04-04T12:00:00Z ACCEPT WALLET diff=100000 latency=82ms func (l *ShareLog) OnAccept(e proxy.Event) { if l == nil || e.Miner == nil { return @@ -81,7 +90,10 @@ func (l *ShareLog) OnAccept(e proxy.Event) { l.writeAcceptLine(e.Miner.User(), e.Diff, uint64(e.Latency)) } -// OnReject writes `2026-04-04T12:00:00Z REJECT WALLET reason="Invalid nonce"`. +// OnReject writes a reject line such as: +// +// sl.OnReject(proxy.Event{Miner: &proxy.Miner{}, Error: "Invalid nonce"}) +// // 2026-04-04T12:00:00Z REJECT WALLET reason="Invalid nonce" func (l *ShareLog) OnReject(e proxy.Event) { if l == nil || e.Miner == nil { return diff --git a/state_impl.go b/state_impl.go index 31b8d83..e2ff50d 100644 --- a/state_impl.go +++ b/state_impl.go @@ -1002,7 +1002,7 @@ func (m *Miner) handleLogin(request stratumRequest) { m.ReplyWithError(requestID(request.ID), "Invalid password") return } - m.user, m.customDiff = parseLoginUser(params.Login, m.globalDiff) + m.user, m.customDiff = resolveLoginCustomDiff(params.Login, m.globalDiff) m.customDiffResolved = true m.password = params.Pass m.agent = params.Agent @@ -1033,11 +1033,11 @@ func (m *Miner) handleLogin(request stratumRequest) { m.replyLoginSuccess(requestID(request.ID)) } -func parseLoginUser(login string, globalDiff uint64) (string, uint64) { +func resolveLoginCustomDiff(login string, globalDiff uint64) (string, uint64) { plus := strings.LastIndex(login, "+") if plus >= 0 && plus < len(login)-1 { suffix := login[plus+1:] - if isDigits(suffix) { + if isDecimalDigits(suffix) { if parsed, err := strconv.ParseUint(suffix, 10, 64); err == nil { return login[:plus], parsed } @@ -1050,7 +1050,7 @@ func parseLoginUser(login string, globalDiff uint64) (string, uint64) { return login, 0 } -func isDigits(value string) bool { +func isDecimalDigits(value string) bool { if value == "" { return false }