2026-04-04 11:16:28 +01:00
|
|
|
package pool
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"sync"
|
|
|
|
|
|
2026-04-04 16:10:33 +01:00
|
|
|
"dappco.re/go/proxy"
|
2026-04-04 11:16:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// FailoverStrategy wraps an ordered slice of PoolConfig entries.
|
|
|
|
|
//
|
2026-04-05 01:30:08 +00:00
|
|
|
// strategy := pool.NewFailoverStrategy([]proxy.PoolConfig{
|
|
|
|
|
// {URL: "primary.example:3333", Enabled: true},
|
|
|
|
|
// {URL: "backup.example:3333", Enabled: true},
|
|
|
|
|
// }, listener, cfg)
|
2026-04-04 11:16:28 +01:00
|
|
|
// strategy.Connect()
|
|
|
|
|
type FailoverStrategy struct {
|
|
|
|
|
pools []proxy.PoolConfig
|
|
|
|
|
current int
|
|
|
|
|
client *StratumClient
|
|
|
|
|
listener StratumListener
|
2026-04-04 22:06:18 +00:00
|
|
|
config *proxy.Config
|
2026-04-04 19:20:29 +00:00
|
|
|
closing bool
|
2026-04-04 11:16:28 +01:00
|
|
|
mu sync.Mutex
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 01:02:31 +00:00
|
|
|
// StrategyFactory creates a FailoverStrategy for a given StratumListener.
|
2026-04-04 11:16:28 +01:00
|
|
|
//
|
|
|
|
|
// factory := pool.NewStrategyFactory(cfg)
|
2026-04-05 01:02:31 +00:00
|
|
|
// strategy := factory(listener)
|
2026-04-04 11:16:28 +01:00
|
|
|
type StrategyFactory func(listener StratumListener) Strategy
|
|
|
|
|
|
2026-04-05 01:02:31 +00:00
|
|
|
// Strategy is the interface splitters use to submit shares and inspect pool state.
|
2026-04-04 11:16:28 +01:00
|
|
|
type Strategy interface {
|
|
|
|
|
Connect()
|
|
|
|
|
Submit(jobID, nonce, result, algo string) int64
|
|
|
|
|
Disconnect()
|
|
|
|
|
IsActive() bool
|
|
|
|
|
}
|
2026-04-04 22:52:01 +00:00
|
|
|
|
|
|
|
|
// ReloadableStrategy re-establishes an upstream connection after config changes.
|
|
|
|
|
//
|
|
|
|
|
// strategy.ReloadPools()
|
|
|
|
|
type ReloadableStrategy interface {
|
|
|
|
|
ReloadPools()
|
|
|
|
|
}
|