Documentation
¶
Index ¶
- Constants
- Variables
- func NewPipeSync(stream1, stream2 i.StratumReadWriter, interceptor1, interceptor2 Interceptor) *pipeSync
- type ConnDest
- func (c *ConnDest) AutoRead(ctx context.Context) error
- func (c *ConnDest) AutoReadStart(ctx context.Context, cb func(err error)) (ok bool)
- func (c *ConnDest) AutoReadStop() error
- func (c *ConnDest) GetDiff() float64
- func (c *ConnDest) GetExtraNonce() (extraNonce string, extraNonceSize int)
- func (c *ConnDest) GetFirstJobSignal() <-chan struct{}
- func (c *ConnDest) GetHR() gi.Hashrate
- func (c *ConnDest) GetIdleCloseAt() time.Time
- func (c *ConnDest) GetLatestJob() (*validator.MiningJob, bool)
- func (c *ConnDest) GetStats() *DestStats
- func (c *ConnDest) GetUserName() string
- func (c *ConnDest) GetVersionRolling() (versionRolling bool, versionRollingMask string)
- func (c *ConnDest) HasJob(jobID string) bool
- func (c *ConnDest) ID() string
- func (c *ConnDest) Read(ctx context.Context) (i.MiningMessageGeneric, error)
- func (c *ConnDest) ResetIdleCloseTimers()
- func (c *ConnDest) SetExtraNonce(extraNonce string, extraNonceSize int)
- func (c *ConnDest) SetUserName(userName string)
- func (c *ConnDest) SetVersionRolling(versionRolling bool, versionRollingMask string)
- func (c *ConnDest) ValidateAndAddShare(msg *sm.MiningSubmit) (float64, error)
- func (c *ConnDest) Write(ctx context.Context, msg i.MiningMessageGeneric) error
- func (s *ConnDest) WriteAwaitRes(parentCtx context.Context, msg i.MiningMessageWithID) (resMsg i.MiningMessageWithID, err error)
- type ConnSource
- func (c *ConnSource) GetConnectedAt() time.Time
- func (c *ConnSource) GetExtraNonce() (extraNonce string, extraNonceSize int)
- func (c *ConnSource) GetID() string
- func (c *ConnSource) GetNegotiatedVersionRollingMask() string
- func (c *ConnSource) GetStats() *SourceStats
- func (c *ConnSource) GetUserName() string
- func (c *ConnSource) GetVersionRolling() (mask string, minBitCount int)
- func (c *ConnSource) Read(ctx context.Context) (interfaces.MiningMessageGeneric, error)
- func (c *ConnSource) SetExtraNonce(extraNonce string, extraNonceSize int)
- func (c *ConnSource) SetNegotiatedVersionRollingMask(mask string)
- func (c *ConnSource) SetUserName(userName string)
- func (c *ConnSource) SetVersionRolling(mask string, minBitCount int)
- func (c *ConnSource) Write(ctx context.Context, msg interfaces.MiningMessageGeneric) error
- type DestConnFactory
- type DestStats
- type GetContractFromStoreFn
- type GlobalHashrateCounter
- type HandlerChangeDest
- type HandlerFirstConnect
- type HandlerMining
- type Hashrate
- type HashrateCounter
- type HashrateCounterFunc
- type HashrateFactory
- type Interceptor
- type Pipe
- func (p *Pipe) GetDest() i.StratumReadWriter
- func (p *Pipe) GetSource() i.StratumReadWriter
- func (p *Pipe) Run(ctx context.Context) error
- func (p *Pipe) SetDest(dest i.StratumReadWriter)
- func (p *Pipe) SetSource(source i.StratumReadWriter)
- func (p *Pipe) StartDestToSource(ctx context.Context)
- func (p *Pipe) StartSourceToDest(ctx context.Context)
- func (p *Pipe) StopDestToSource() <-chan struct{}
- func (p *Pipe) StopSourceToDest() <-chan struct{}
- type Proxy
- func (p *Proxy) Connect(ctx context.Context) error
- func (p *Proxy) ConnectDest(ctx context.Context, newDestURL *url.URL) error
- func (p *Proxy) GetConnectedAt() time.Time
- func (p *Proxy) GetDest() *url.URL
- func (p *Proxy) GetDestByJobID(jobID string) *ConnDest
- func (p *Proxy) GetDestByJobIDAndValidate(msg *stratumv1_message.MiningSubmit) (*ConnDest, float64, error)
- func (p *Proxy) GetDestConns() *map[string]string
- func (p *Proxy) GetDestWorkerName() string
- func (p *Proxy) GetDifficulty() float64
- func (p *Proxy) GetHashrate() Hashrate
- func (p *Proxy) GetID() string
- func (p *Proxy) GetIncomingContractID() *string
- func (p *Proxy) GetMinerConnectedAt() time.Time
- func (p *Proxy) GetSourceWorkerName() string
- func (p *Proxy) GetStats() map[string]int
- func (p *Proxy) IsVetting() bool
- func (p *Proxy) Run(ctx context.Context) error
- func (p *Proxy) SetDest(ctx context.Context, newDestURL *url.URL, onSubmit func(diff float64)) error
- func (p *Proxy) SetDestWithoutAutoread(ctx context.Context, newDestURL *url.URL, onSubmit func(diff float64)) error
- func (p *Proxy) VettingDone() <-chan struct{}
- type ResultHandler
- type SourceStats
- type StratumConnection
- func (c *StratumConnection) Close() error
- func (c *StratumConnection) GetConnectedAt() time.Time
- func (c *StratumConnection) GetID() string
- func (c *StratumConnection) GetIdleCloseAt() time.Time
- func (c *StratumConnection) LocalPort() string
- func (c *StratumConnection) Read(ctx context.Context) (interfaces.MiningMessageGeneric, error)
- func (c *StratumConnection) ResetIdleCloseTimers()
- func (c *StratumConnection) Write(ctx context.Context, msg interfaces.MiningMessageGeneric) error
Constants ¶
const ( DIAL_TIMEOUT = 10 * time.Second WRITE_TIMEOUT = 10 * time.Second )
const ( CONNECTION_TIMEOUT = 10 * time.Minute RESPONSE_TIMEOUT = 30 * time.Second RECONNECT_TIMEOUT = 3 * time.Second )
const MAX_CONSEQUENT_INVALID_SHARES = 100
Variables ¶
var ( ErrIdleWriteTimeout = fmt.Errorf("connection idle write timeout") ErrIdleReadTimeout = fmt.Errorf("connection idle read timeout") )
var ( ErrDest = errors.New("destination connection error") ErrSource = errors.New("source connection error") )
var ( ErrNotStratum = errors.New("not a stratum protocol") // means that incoming connection is not a stratum protocol ErrUnknownContract = errors.New("incoming connection for unknown contract") ErrNotAValidator = errors.New("not a validator for this contract") )
var ( ErrConnectDest = errors.New("failure during connecting to destination") ErrConnectSource = errors.New("failure during source connection") ErrHandshakeDest = errors.New("failure during handshake with destination") ErrHandshakeSource = errors.New("failure during handshake with source") ErrProxy = errors.New("proxy error") ErrNotAuthorizedPool = errors.New("not authorized in the pool") ErrChangeDest = errors.New("destination change error") ErrAutoreadStarted = errors.New("autoread already started") )
Functions ¶
func NewPipeSync ¶
func NewPipeSync(stream1, stream2 i.StratumReadWriter, interceptor1, interceptor2 Interceptor) *pipeSync
Provides a way to synchronize two i.StratumReadWriters. Only one message from either stream can be processed at a time, it gives deternimistic message write order
Types ¶
type ConnDest ¶
type ConnDest struct {
// contains filtered or unexported fields
}
ConnDest is a destination connection, a wrapper around StratumConnection, with destination specific state variables
func ConnectDest ¶
func NewDestConn ¶
func (*ConnDest) AutoRead ¶
AutoRead reads incoming jobs from the destination connection and caches them so dest will not close the connection
func (*ConnDest) AutoReadStart ¶
func (*ConnDest) AutoReadStop ¶
func (*ConnDest) GetExtraNonce ¶
func (*ConnDest) GetFirstJobSignal ¶
func (c *ConnDest) GetFirstJobSignal() <-chan struct{}
func (*ConnDest) GetIdleCloseAt ¶
func (*ConnDest) GetUserName ¶
func (*ConnDest) GetVersionRolling ¶
func (*ConnDest) ResetIdleCloseTimers ¶
func (c *ConnDest) ResetIdleCloseTimers()
func (*ConnDest) SetExtraNonce ¶
func (*ConnDest) SetUserName ¶
func (*ConnDest) SetVersionRolling ¶
func (*ConnDest) ValidateAndAddShare ¶
func (c *ConnDest) ValidateAndAddShare(msg *sm.MiningSubmit) (float64, error)
func (*ConnDest) WriteAwaitRes ¶
func (s *ConnDest) WriteAwaitRes(parentCtx context.Context, msg i.MiningMessageWithID) (resMsg i.MiningMessageWithID, err error)
WriteAwaitRes writes message to the destination connection and awaits for the response
type ConnSource ¶
type ConnSource struct {
// contains filtered or unexported fields
}
ConnSource is a miner connection, a wrapper around StratumConnection that adds miner specific state variables
func NewSourceConn ¶
func NewSourceConn(conn *StratumConnection, log globalInterfaces.ILogger) *ConnSource
func (*ConnSource) GetConnectedAt ¶
func (c *ConnSource) GetConnectedAt() time.Time
func (*ConnSource) GetExtraNonce ¶
func (c *ConnSource) GetExtraNonce() (extraNonce string, extraNonceSize int)
func (*ConnSource) GetID ¶
func (c *ConnSource) GetID() string
func (*ConnSource) GetNegotiatedVersionRollingMask ¶
func (c *ConnSource) GetNegotiatedVersionRollingMask() string
GetNegotiatedVersionRollingMask returns actual version rolling mask after negotiation with server
func (*ConnSource) GetStats ¶
func (c *ConnSource) GetStats() *SourceStats
func (*ConnSource) GetUserName ¶
func (c *ConnSource) GetUserName() string
func (*ConnSource) GetVersionRolling ¶
func (c *ConnSource) GetVersionRolling() (mask string, minBitCount int)
func (*ConnSource) Read ¶
func (c *ConnSource) Read(ctx context.Context) (interfaces.MiningMessageGeneric, error)
func (*ConnSource) SetExtraNonce ¶
func (c *ConnSource) SetExtraNonce(extraNonce string, extraNonceSize int)
func (*ConnSource) SetNegotiatedVersionRollingMask ¶
func (c *ConnSource) SetNegotiatedVersionRollingMask(mask string)
SetNegotiatedVersionRollingMask sets actual version rolling mask after negotiation with server
func (*ConnSource) SetUserName ¶
func (c *ConnSource) SetUserName(userName string)
func (*ConnSource) SetVersionRolling ¶
func (c *ConnSource) SetVersionRolling(mask string, minBitCount int)
func (*ConnSource) Write ¶
func (c *ConnSource) Write(ctx context.Context, msg interfaces.MiningMessageGeneric) error
type DestConnFactory ¶
type DestStats ¶
type DestStats struct { WeAcceptedTheyAccepted atomic.Uint64 // our validator accepted and dest accepted WeAcceptedTheyRejected atomic.Uint64 // our validator accepted and dest rejected WeRejectedTheyAccepted atomic.Uint64 // our validator rejected, but dest accepted }
func (*DestStats) GetStatsMap ¶
func (*DestStats) IncWeAcceptedTheyAccepted ¶
func (s *DestStats) IncWeAcceptedTheyAccepted()
func (*DestStats) IncWeAcceptedTheyRejected ¶
func (s *DestStats) IncWeAcceptedTheyRejected()
func (*DestStats) IncWeRejectedTheyAccepted ¶
func (s *DestStats) IncWeRejectedTheyAccepted()
type GetContractFromStoreFn ¶
type GlobalHashrateCounter ¶
type HandlerChangeDest ¶
type HandlerChangeDest struct {
// contains filtered or unexported fields
}
HandlerChangeDest is the collection of functions that are used when the destination connection is changed
func NewHandlerChangeDest ¶
func NewHandlerChangeDest(proxy *Proxy, destFactory DestConnFactory) *HandlerChangeDest
type HandlerFirstConnect ¶
type HandlerFirstConnect struct {
// contains filtered or unexported fields
}
func NewHandlerFirstConnect ¶
func NewHandlerFirstConnect(proxy *Proxy) *HandlerFirstConnect
type HandlerMining ¶
type HandlerMining struct {
// contains filtered or unexported fields
}
func NewHandlerMining ¶
func NewHandlerMining(proxy *Proxy) *HandlerMining
type HashrateCounter ¶
type HashrateCounter interface {
OnSubmit(diff float64)
}
type HashrateCounterFunc ¶
type HashrateCounterFunc func(diff float64)
type HashrateFactory ¶
type Interceptor ¶
type Interceptor = func(context.Context, i.MiningMessageGeneric) (i.MiningMessageGeneric, error)
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
func NewPipe ¶
func NewPipe(source, dest i.StratumReadWriter, sourceInterceptor, destInterceptor Interceptor, log gi.ILogger) *Pipe
NewPipe creates a new pipe between source and dest, allowing to intercept messages and separately control start and stop on both directions of the duplex
func (*Pipe) GetDest ¶
func (p *Pipe) GetDest() i.StratumReadWriter
func (*Pipe) GetSource ¶
func (p *Pipe) GetSource() i.StratumReadWriter
func (*Pipe) SetDest ¶
func (p *Pipe) SetDest(dest i.StratumReadWriter)
func (*Pipe) SetSource ¶
func (p *Pipe) SetSource(source i.StratumReadWriter)
func (*Pipe) StartDestToSource ¶
func (*Pipe) StartSourceToDest ¶
func (*Pipe) StopDestToSource ¶
func (p *Pipe) StopDestToSource() <-chan struct{}
func (*Pipe) StopSourceToDest ¶
func (p *Pipe) StopSourceToDest() <-chan struct{}
type Proxy ¶
type Proxy struct { // config ID string // contains filtered or unexported fields }
func NewProxy ¶
func NewProxy(ID string, source *ConnSource, destFactory DestConnFactory, hashrateFactory HashrateFactory, globalHashrate GlobalHashrateCounter, destURL *url.URL, notPropagateWorkerName bool, vettingShares int, maxCachedDests int, log gi.ILogger, getContractFromStoreFn GetContractFromStoreFn) *Proxy
func (*Proxy) ConnectDest ¶
func (*Proxy) GetConnectedAt ¶
func (*Proxy) GetDestByJobID ¶
func (*Proxy) GetDestByJobIDAndValidate ¶
func (p *Proxy) GetDestByJobIDAndValidate(msg *stratumv1_message.MiningSubmit) (*ConnDest, float64, error)
func (*Proxy) GetDestConns ¶
func (*Proxy) GetDestWorkerName ¶
func (*Proxy) GetDifficulty ¶
func (*Proxy) GetHashrate ¶
func (*Proxy) GetIncomingContractID ¶
func (*Proxy) GetMinerConnectedAt ¶
func (*Proxy) GetSourceWorkerName ¶
func (*Proxy) SetDestWithoutAutoread ¶
func (*Proxy) VettingDone ¶
func (p *Proxy) VettingDone() <-chan struct{}
type ResultHandler ¶
type ResultHandler = func(a *m.MiningResult) (msg i.MiningMessageWithID, err error)
type SourceStats ¶
type SourceStats struct { WeAcceptedTheyRejected atomic.Uint64 // shares that passed our validator, but rejected by the destination WeRejectedTheyAccepted atomic.Uint64 // shares that failed our validator, but accepted by the destination }
func (*SourceStats) GetStatsMap ¶
func (s *SourceStats) GetStatsMap() map[string]int
func (*SourceStats) IncWeAcceptedShares ¶
func (s *SourceStats) IncWeAcceptedShares()
func (*SourceStats) IncWeAcceptedTheyRejected ¶
func (s *SourceStats) IncWeAcceptedTheyRejected()
func (*SourceStats) IncWeRejectedShares ¶
func (s *SourceStats) IncWeRejectedShares()
func (*SourceStats) IncWeRejectedTheyAccepted ¶
func (s *SourceStats) IncWeRejectedTheyAccepted()
type StratumConnection ¶
type StratumConnection struct {
// contains filtered or unexported fields
}
func Connect ¶
func Connect(address *url.URL, idleReadCloseTimeout, idleWriteCloseTimeout time.Duration, log gi.ILogger) (*StratumConnection, error)
Connect connects to destination with default close timeouts
func CreateConnection ¶
func CreateConnection(conn net.Conn, address string, idleReadTimeout, idleWriteTimeout time.Duration, log gi.ILogger) *StratumConnection
CreateConnection creates a new StratumConnection and starts background timer for its closure
func (*StratumConnection) Close ¶
func (c *StratumConnection) Close() error
func (*StratumConnection) GetConnectedAt ¶
func (c *StratumConnection) GetConnectedAt() time.Time
func (*StratumConnection) GetID ¶
func (c *StratumConnection) GetID() string
func (*StratumConnection) GetIdleCloseAt ¶
func (c *StratumConnection) GetIdleCloseAt() time.Time
func (*StratumConnection) LocalPort ¶
func (c *StratumConnection) LocalPort() string
func (*StratumConnection) Read ¶
func (c *StratumConnection) Read(ctx context.Context) (interfaces.MiningMessageGeneric, error)
func (*StratumConnection) ResetIdleCloseTimers ¶
func (c *StratumConnection) ResetIdleCloseTimers()
func (*StratumConnection) Write ¶
func (c *StratumConnection) Write(ctx context.Context, msg interfaces.MiningMessageGeneric) error
Write writes message to the connection. Safe for concurrent use, cause underlying TCPConn is thread-safe