2026-04-04 11:16:28 +01:00
|
|
|
package simple
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-04 10:29:02 +00:00
|
|
|
"sync"
|
2026-04-04 11:16:28 +01:00
|
|
|
"time"
|
|
|
|
|
|
2026-04-04 16:10:33 +01:00
|
|
|
"dappco.re/go/proxy"
|
|
|
|
|
"dappco.re/go/proxy/pool"
|
2026-04-04 11:16:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SimpleMapper holds one outbound pool connection and serves at most one active miner
|
|
|
|
|
// at a time. It becomes idle when the miner disconnects and may be reclaimed for the
|
|
|
|
|
// next login.
|
|
|
|
|
//
|
|
|
|
|
// m := simple.NewSimpleMapper(id, strategy)
|
|
|
|
|
type SimpleMapper struct {
|
2026-04-04 18:25:36 +00:00
|
|
|
id int64
|
|
|
|
|
miner *proxy.Miner // nil when idle
|
|
|
|
|
currentJob proxy.Job
|
2026-04-04 20:24:06 +00:00
|
|
|
prevJob proxy.Job
|
2026-04-04 18:25:36 +00:00
|
|
|
strategy pool.Strategy
|
|
|
|
|
idleAt time.Time // zero when active
|
|
|
|
|
stopped bool
|
|
|
|
|
events *proxy.EventBus
|
2026-04-04 18:38:28 +00:00
|
|
|
pending map[int64]submitContext
|
2026-04-04 18:25:36 +00:00
|
|
|
mu sync.Mutex
|
2026-04-04 11:16:28 +01:00
|
|
|
}
|
2026-04-04 18:38:28 +00:00
|
|
|
|
|
|
|
|
type submitContext struct {
|
|
|
|
|
RequestID int64
|
2026-04-05 00:32:43 +00:00
|
|
|
Diff uint64
|
2026-04-04 18:38:28 +00:00
|
|
|
StartedAt time.Time
|
2026-04-04 20:24:06 +00:00
|
|
|
JobID string
|
2026-04-04 18:38:28 +00:00
|
|
|
}
|
2026-04-04 22:57:19 +00:00
|
|
|
|
|
|
|
|
// NewSimpleMapper creates a passthrough mapper for one pool connection.
|
|
|
|
|
//
|
|
|
|
|
// m := simple.NewSimpleMapper(7, strategy)
|
|
|
|
|
func NewSimpleMapper(id int64, strategy pool.Strategy) *SimpleMapper {
|
|
|
|
|
return &SimpleMapper{
|
|
|
|
|
id: id,
|
|
|
|
|
strategy: strategy,
|
|
|
|
|
pending: make(map[int64]submitContext),
|
|
|
|
|
}
|
|
|
|
|
}
|