proxy

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DIAL_TIMEOUT  = 10 * time.Second
	WRITE_TIMEOUT = 10 * time.Second
)
View Source
const (
	CONNECTION_TIMEOUT = 10 * time.Minute
	RESPONSE_TIMEOUT   = 30 * time.Second
	RECONNECT_TIMEOUT  = 3 * time.Second
)
View Source
const MAX_CONSEQUENT_INVALID_SHARES = 100

Variables

View Source
var (
	ErrIdleWriteTimeout = fmt.Errorf("connection idle write timeout")
	ErrIdleReadTimeout  = fmt.Errorf("connection idle read timeout")
)
View Source
var (
	ErrDest   = errors.New("destination connection error")
	ErrSource = errors.New("source connection error")
)
View Source
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")
)
View Source
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 ConnectDest(ctx context.Context, destURL *url.URL, valid *validator.Validator, idleReadCloseTimeout, idleWriteCloseTimeout time.Duration, log gi.ILogger) (*ConnDest, error)

func NewDestConn

func NewDestConn(conn *StratumConnection, valid *validator.Validator, url *url.URL, log gi.ILogger) *ConnDest

func (*ConnDest) AutoRead

func (c *ConnDest) AutoRead(ctx context.Context) error

AutoRead reads incoming jobs from the destination connection and caches them so dest will not close the connection

func (*ConnDest) AutoReadStart

func (c *ConnDest) AutoReadStart(ctx context.Context, cb func(err error)) (ok bool)

func (*ConnDest) AutoReadStop

func (c *ConnDest) AutoReadStop() error

func (*ConnDest) GetDiff

func (c *ConnDest) GetDiff() float64

func (*ConnDest) GetExtraNonce

func (c *ConnDest) GetExtraNonce() (extraNonce string, extraNonceSize int)

func (*ConnDest) GetFirstJobSignal

func (c *ConnDest) GetFirstJobSignal() <-chan struct{}

func (*ConnDest) GetHR

func (c *ConnDest) GetHR() gi.Hashrate

func (*ConnDest) GetIdleCloseAt

func (c *ConnDest) GetIdleCloseAt() time.Time

func (*ConnDest) GetLatestJob

func (c *ConnDest) GetLatestJob() (*validator.MiningJob, bool)

func (*ConnDest) GetStats

func (c *ConnDest) GetStats() *DestStats

func (*ConnDest) GetUserName

func (c *ConnDest) GetUserName() string

func (*ConnDest) GetVersionRolling

func (c *ConnDest) GetVersionRolling() (versionRolling bool, versionRollingMask string)

func (*ConnDest) HasJob

func (c *ConnDest) HasJob(jobID string) bool

func (*ConnDest) ID

func (c *ConnDest) ID() string

func (*ConnDest) Read

func (*ConnDest) ResetIdleCloseTimers

func (c *ConnDest) ResetIdleCloseTimers()

func (*ConnDest) SetExtraNonce

func (c *ConnDest) SetExtraNonce(extraNonce string, extraNonceSize int)

func (*ConnDest) SetUserName

func (c *ConnDest) SetUserName(userName string)

func (*ConnDest) SetVersionRolling

func (c *ConnDest) SetVersionRolling(versionRolling bool, versionRollingMask string)

func (*ConnDest) ValidateAndAddShare

func (c *ConnDest) ValidateAndAddShare(msg *sm.MiningSubmit) (float64, error)

func (*ConnDest) Write

func (c *ConnDest) Write(ctx context.Context, msg i.MiningMessageGeneric) 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 (*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

type DestConnFactory

type DestConnFactory = func(ctx context.Context, url *url.URL, srcWorker, srcAddr string) (*ConnDest, error)

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 (s *DestStats) GetStatsMap() map[string]int

func (*DestStats) IncWeAcceptedTheyAccepted

func (s *DestStats) IncWeAcceptedTheyAccepted()

func (*DestStats) IncWeAcceptedTheyRejected

func (s *DestStats) IncWeAcceptedTheyRejected()

func (*DestStats) IncWeRejectedTheyAccepted

func (s *DestStats) IncWeRejectedTheyAccepted()

type GetContractFromStoreFn

type GetContractFromStoreFn func(id string) (resources.Contract, bool)

type GlobalHashrateCounter

type GlobalHashrateCounter interface {
	OnSubmit(workerName string, diff float64)
	OnConnect(workerName string)
}

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

func (*HandlerFirstConnect) Connect

func (p *HandlerFirstConnect) Connect(ctx context.Context) error

type HandlerMining

type HandlerMining struct {
	// contains filtered or unexported fields
}

func NewHandlerMining

func NewHandlerMining(proxy *Proxy) *HandlerMining

type Hashrate

type Hashrate interface {
	GetHashrateAvgGHSCustom(ID string) (hrGHS float64, ok bool)
	GetHashrateAvgGHSAll() map[string]float64
	GetTotalWork() float64
	GetTotalDuration() time.Duration
	GetLastSubmitTime() time.Time
	GetTotalShares() int
}

type HashrateCounter

type HashrateCounter interface {
	OnSubmit(diff float64)
}

type HashrateCounterFunc

type HashrateCounterFunc func(diff float64)

type HashrateFactory

type HashrateFactory = func() *hashrate.Hashrate

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) Run

func (p *Pipe) Run(ctx context.Context) error

func (*Pipe) SetDest

func (p *Pipe) SetDest(dest i.StratumReadWriter)

func (*Pipe) SetSource

func (p *Pipe) SetSource(source i.StratumReadWriter)

func (*Pipe) StartDestToSource

func (p *Pipe) StartDestToSource(ctx context.Context)

func (*Pipe) StartSourceToDest

func (p *Pipe) StartSourceToDest(ctx context.Context)

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) Connect

func (p *Proxy) Connect(ctx context.Context) error

runs proxy until handshake is done

func (*Proxy) ConnectDest

func (p *Proxy) ConnectDest(ctx context.Context, newDestURL *url.URL) error

func (*Proxy) GetConnectedAt

func (p *Proxy) GetConnectedAt() time.Time

func (*Proxy) GetDest

func (p *Proxy) GetDest() *url.URL

func (*Proxy) GetDestByJobID

func (p *Proxy) GetDestByJobID(jobID string) *ConnDest

func (*Proxy) GetDestByJobIDAndValidate

func (p *Proxy) GetDestByJobIDAndValidate(msg *stratumv1_message.MiningSubmit) (*ConnDest, float64, error)

func (*Proxy) GetDestConns

func (p *Proxy) GetDestConns() *map[string]string

func (*Proxy) GetDestWorkerName

func (p *Proxy) GetDestWorkerName() string

func (*Proxy) GetDifficulty

func (p *Proxy) GetDifficulty() float64

func (*Proxy) GetHashrate

func (p *Proxy) GetHashrate() Hashrate

func (*Proxy) GetID

func (p *Proxy) GetID() string

Getters

func (*Proxy) GetIncomingContractID

func (p *Proxy) GetIncomingContractID() *string

func (*Proxy) GetMinerConnectedAt

func (p *Proxy) GetMinerConnectedAt() time.Time

func (*Proxy) GetSourceWorkerName

func (p *Proxy) GetSourceWorkerName() string

func (*Proxy) GetStats

func (p *Proxy) GetStats() map[string]int

func (*Proxy) IsVetting

func (p *Proxy) IsVetting() bool

func (*Proxy) Run

func (p *Proxy) Run(ctx context.Context) error

func (*Proxy) SetDest

func (p *Proxy) SetDest(ctx context.Context, newDestURL *url.URL, onSubmit func(diff float64)) error

func (*Proxy) SetDestWithoutAutoread

func (p *Proxy) SetDestWithoutAutoread(ctx context.Context, newDestURL *url.URL, onSubmit func(diff float64)) error

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 {
	WeAcceptedShares       atomic.Uint64 // shares that passed our validator (incl AcceptedUsRejectedThem)
	WeRejectedShares       atomic.Uint64 // shares that failed during validation (incl RejectedUsAcceptedThem)
	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 (*StratumConnection) ResetIdleCloseTimers

func (c *StratumConnection) ResetIdleCloseTimers()

func (*StratumConnection) Write

Write writes message to the connection. Safe for concurrent use, cause underlying TCPConn is thread-safe

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL