go-proxy/pool/client.go
Snider b8cf8713c5 fix: correct module path to dappco.re/go/proxy
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-04 16:10:33 +01:00

44 lines
1.5 KiB
Go

// Package pool implements the outbound stratum pool client and failover strategy.
//
// client := pool.NewStratumClient(poolCfg, listener)
// client.Connect()
package pool
import (
"crypto/tls"
"net"
"sync"
"dappco.re/go/proxy"
)
// StratumClient is one outbound stratum TCP (optionally TLS) connection to a pool.
// The proxy presents itself to the pool as a standard stratum miner using the
// wallet address and password from PoolConfig.
//
// client := pool.NewStratumClient(poolCfg, listener)
// client.Connect()
type StratumClient struct {
cfg proxy.PoolConfig
listener StratumListener
conn net.Conn
tlsConn *tls.Conn // nil if plain TCP
sessionID string // pool-assigned session id from login reply
seq int64 // atomic JSON-RPC request id counter
active bool // true once first job received
pending map[int64]struct{}
closedOnce sync.Once
mu sync.Mutex
sendMu sync.Mutex
}
// StratumListener receives events from the pool connection.
type StratumListener interface {
// OnJob is called when the pool pushes a new job notification or the login reply contains a job.
OnJob(job proxy.Job)
// OnResultAccepted is called when the pool accepts or rejects a submitted share.
// sequence matches the value returned by Submit(). errorMessage is "" on accept.
OnResultAccepted(sequence int64, accepted bool, errorMessage string)
// OnDisconnect is called when the pool TCP connection closes for any reason.
OnDisconnect()
}