docs(proxy): sharpen AX examples
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
5a3fcf4fab
commit
ecd4130457
6 changed files with 23 additions and 14 deletions
11
config.go
11
config.go
|
|
@ -2,11 +2,12 @@ package proxy
|
||||||
|
|
||||||
// Config is the top-level proxy configuration.
|
// Config is the top-level proxy configuration.
|
||||||
//
|
//
|
||||||
// cfg, result := proxy.LoadConfig("/etc/proxy.json")
|
// cfg := &proxy.Config{
|
||||||
// if !result.OK {
|
// Mode: "nicehash",
|
||||||
// return result.Error
|
// 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 {
|
type Config struct {
|
||||||
Mode string `json:"mode"` // "nicehash" or "simple"
|
Mode string `json:"mode"` // "nicehash" or "simple"
|
||||||
Bind []BindAddr `json:"bind"` // listen addresses
|
Bind []BindAddr `json:"bind"` // listen addresses
|
||||||
|
|
@ -76,7 +77,7 @@ type HTTPConfig struct {
|
||||||
|
|
||||||
// RateLimit controls per-IP connection throttling.
|
// RateLimit controls per-IP connection throttling.
|
||||||
//
|
//
|
||||||
// proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300}
|
// limiter := proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30, BanDurationSeconds: 300})
|
||||||
type RateLimit struct {
|
type RateLimit struct {
|
||||||
MaxConnectionsPerMinute int `json:"max-connections-per-minute"` // 0 = disabled
|
MaxConnectionsPerMinute int `json:"max-connections-per-minute"` // 0 = disabled
|
||||||
BanDurationSeconds int `json:"ban-duration"` // 0 = no ban
|
BanDurationSeconds int `json:"ban-duration"` // 0 = no ban
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ import "sync"
|
||||||
// EventBus dispatches proxy lifecycle events to synchronous listeners.
|
// EventBus dispatches proxy lifecycle events to synchronous listeners.
|
||||||
//
|
//
|
||||||
// bus := proxy.NewEventBus()
|
// bus := proxy.NewEventBus()
|
||||||
// bus.Subscribe(proxy.EventLogin, func(e proxy.Event) { _ = e.Miner.User() })
|
// bus.Subscribe(proxy.EventLogin, func(e proxy.Event) {
|
||||||
|
// _ = e.Miner.User()
|
||||||
|
// })
|
||||||
// bus.Subscribe(proxy.EventAccept, stats.OnAccept)
|
// bus.Subscribe(proxy.EventAccept, stats.OnAccept)
|
||||||
type EventBus struct {
|
type EventBus struct {
|
||||||
listeners map[EventType][]EventHandler
|
listeners map[EventType][]EventHandler
|
||||||
|
|
|
||||||
7
job.go
7
job.go
|
|
@ -2,7 +2,12 @@ package proxy
|
||||||
|
|
||||||
// Job holds one pool work unit and its metadata.
|
// 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.BlobWithFixedByte(0x2A)
|
||||||
// _ = j.DifficultyFromTarget()
|
// _ = j.DifficultyFromTarget()
|
||||||
type Job struct {
|
type Job struct {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
// Line format (connect): 2026-04-04T12:00:00Z CONNECT <ip> <user> <agent>
|
// 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>
|
// 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.EventLogin, al.OnLogin)
|
||||||
// bus.Subscribe(proxy.EventClose, al.OnClose)
|
// bus.Subscribe(proxy.EventClose, al.OnClose)
|
||||||
type AccessLog struct {
|
type AccessLog struct {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
// proxy.BindAddr{Host: "0.0.0.0", Port: 3333, TLS: false},
|
// proxy.BindAddr{Host: "0.0.0.0", Port: 3333, TLS: false},
|
||||||
// nil,
|
// nil,
|
||||||
// proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30}),
|
// proxy.NewRateLimiter(proxy.RateLimit{MaxConnectionsPerMinute: 30}),
|
||||||
// onAccept,
|
// func(conn net.Conn, port uint16) { _ = conn; _ = port },
|
||||||
// )
|
// )
|
||||||
// if result.OK {
|
// if result.OK {
|
||||||
// srv.Start()
|
// srv.Start()
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
// Workers tracks per-identity aggregates derived from miner login fields.
|
// Workers tracks per-identity aggregates derived from miner login fields.
|
||||||
//
|
//
|
||||||
// workers := proxy.NewWorkers(proxy.WorkersByRigID, bus)
|
// workers := proxy.NewWorkers(proxy.WorkersByRigID, bus)
|
||||||
// workers.OnLogin(proxy.Event{Miner: miner})
|
// workers.OnLogin(proxy.Event{Miner: &proxy.Miner{rigID: "rig-alpha", user: "WALLET", ip: "10.0.0.1"}})
|
||||||
type Workers struct {
|
type Workers struct {
|
||||||
mode WorkersMode
|
mode WorkersMode
|
||||||
entries []WorkerRecord // ordered by first-seen (stable)
|
entries []WorkerRecord // ordered by first-seen (stable)
|
||||||
|
|
@ -20,7 +20,8 @@ type Workers struct {
|
||||||
|
|
||||||
// WorkerRecord is the aggregate row returned by Workers.List().
|
// 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 {
|
type WorkerRecord struct {
|
||||||
Name string
|
Name string
|
||||||
LastIP string
|
LastIP string
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue