docs(proxy): sharpen AX examples

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-05 01:52:20 +00:00
parent 5a3fcf4fab
commit ecd4130457
6 changed files with 23 additions and 14 deletions

View file

@ -2,11 +2,12 @@ package proxy
// Config is the top-level proxy configuration.
//
// cfg, result := proxy.LoadConfig("/etc/proxy.json")
// if !result.OK {
// return result.Error
// cfg := &proxy.Config{
// Mode: "nicehash",
// Bind: []proxy.BindAddr{{Host: "0.0.0.0", Port: 3333}},
// Pools: []proxy.PoolConfig{{URL: "pool.example:3333", Enabled: true}},
// Workers: proxy.WorkersByRigID,
// }
// cfg.Workers = proxy.WorkersByRigID
type Config struct {
Mode string `json:"mode"` // "nicehash" or "simple"
Bind []BindAddr `json:"bind"` // listen addresses
@ -76,7 +77,7 @@ type HTTPConfig struct {
// RateLimit controls per-IP connection throttling.
//
// proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300}
// limiter := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300})
type RateLimit struct {
MaxConnectionsPerMinute int `json:"max-connections-per-minute"` // 0 = disabled
BanDurationSeconds int `json:"ban-duration"` // 0 = no ban

View file

@ -4,9 +4,11 @@ import "sync"
// EventBus dispatches proxy lifecycle events to synchronous listeners.
//
// bus := proxy.NewEventBus()
// bus.Subscribe(proxy.EventLogin, func(e proxy.Event) { _ = e.Miner.User() })
// bus.Subscribe(proxy.EventAccept, stats.OnAccept)
// bus := proxy.NewEventBus()
// bus.Subscribe(proxy.EventLogin, func(e proxy.Event) {
// _ = e.Miner.User()
// })
// bus.Subscribe(proxy.EventAccept, stats.OnAccept)
type EventBus struct {
listeners map[EventType][]EventHandler
mu sync.RWMutex

7
job.go
View file

@ -2,7 +2,12 @@ package proxy
// Job holds one pool work unit and its metadata.
//
// j := proxy.Job{Blob: strings.Repeat("0", 160), JobID: "4BiGm3/RgGQzgkTI", Target: "b88d0600", Algo: "cn/r"}
// j := proxy.Job{
// Blob: strings.Repeat("0", 160),
// JobID: "4BiGm3/RgGQzgkTI",
// Target: "b88d0600",
// Algo: "cn/r",
// }
// _ = j.BlobWithFixedByte(0x2A)
// _ = j.DifficultyFromTarget()
type Job struct {

View file

@ -15,7 +15,7 @@ import (
// Line format (connect): 2026-04-04T12:00:00Z CONNECT <ip> <user> <agent>
// Line format (close): 2026-04-04T12:00:00Z CLOSE <ip> <user> rx=<bytes> tx=<bytes>
//
// al, result := log.NewAccessLog("/var/log/proxy-access.log")
// al := log.NewAccessLog("/var/log/proxy-access.log")
// bus.Subscribe(proxy.EventLogin, al.OnLogin)
// bus.Subscribe(proxy.EventClose, al.OnClose)
type AccessLog struct {

View file

@ -11,7 +11,7 @@ import (
// proxy.BindAddr{Host: "0.0.0.0", Port: 3333, TLS: false},
// nil,
// proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30}),
// onAccept,
// func(conn net.Conn, port uint16) { _ = conn; _ = port },
// )
// if result.OK {
// srv.Start()

View file

@ -7,8 +7,8 @@ import (
// Workers tracks per-identity aggregates derived from miner login fields.
//
// workers := proxy.NewWorkers(proxy.WorkersByRigID, bus)
// workers.OnLogin(proxy.Event{Miner: miner})
// workers := proxy.NewWorkers(proxy.WorkersByRigID, bus)
// workers.OnLogin(proxy.Event{Miner: &proxy.Miner{rigID: "rig-alpha", user: "WALLET", ip: "10.0.0.1"}})
type Workers struct {
mode WorkersMode
entries []WorkerRecord // ordered by first-seen (stable)
@ -20,7 +20,8 @@ type Workers struct {
// WorkerRecord is the aggregate row returned by Workers.List().
//
// hr60 := record.Hashrate(60)
// record := proxy.WorkerRecord{Name: "rig-alpha"}
// _ = record.Hashrate(60)
type WorkerRecord struct {
Name string
LastIP string