proxy

package
v0.0.0-...-624ef01 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ValidateNormal just checks that there is a valid job ID and the share is
	// not a duplicate for this job
	ValidateNormal

	// ValidateFormat checks the results and nonce for valid size
	ValidateFormat

	// ValidateDiff checks that the result difficulty meets the target
	// NOT WORKING - the idea would be to include previous levels also
	ValidateDiff

	// ValidateFull TODO checks nonce against blob for result
	// maybe not worth it!
	ValidateFull
)
View Source
const (
	// MaxUint protects IDs from overflow if the process runs for thousands of years
	MaxUint = ^uint64(0)
)

Variables

View Source
var (
	ErrMalformedJob        = errors.New("bad job format from pool")
	ErrUnknownTargetFormat = errors.New("unrecognized format for job target")
)
View Source
var (
	ErrBadJobID       = errors.New("invalid job id")
	ErrDuplicateShare = errors.New("duplicate share")
	ErrMalformedShare = errors.New("malformed share")
)
View Source
var (
	ErrMalformedShareResult = errors.New("result is the correct length")
	ErrDiffTooLow           = errors.New("share difficulty too low")
)

Functions

This section is empty.

Types

type AuthReply

type AuthReply struct {
	Token  string `json:"token"`
	Hashes string `json:"hashes"`
}

type Director

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

Director might be refactored to "ProxyGroup"

func GetDirector

func GetDirector() *Director

func (*Director) GetStats

func (d *Director) GetStats() *Stats

func (*Director) NextProxy

func (d *Director) NextProxy() *Proxy

NextProxy gets the first available proxy that has room. If no proxy is available, a new one is created.

type Job

type Job struct {
	Blob   string `json:"blob"`
	ID     string `json:"job_id"`
	Target string `json:"target"`
	// contains filtered or unexported fields
}

Job is a mining job. Break it up and send chunks to workers.

func NewJob

func NewJob(blobBytes []byte, nonce uint32, id, target string) *Job

NewJob builds a job for distribution to a worker

func NewJobFromServer

func NewJobFromServer(job map[string]interface{}) (*Job, error)

NewJobFromServer creates a Job from a pool notice

func (*Job) Next

func (j *Job) Next() *Job

Next returns the next version of this job for worker distribution and increments the nonce

func (*Job) Nonce

func (j *Job) Nonce() (nonce uint32, blobBytes []byte, err error)

Nonce extracts the nonce from the job blob and returns it.

type LoginReply

type LoginReply struct {
	ID     string          `json:"id"`
	Job    *Job            `json:"job"`
	Status string          `json:"status"`
	Error  *jsonrpc2.Error `json:"error,omitempty"`
}

type Mining

type Mining struct{}

RPC proxy service

func (*Mining) Auth

func (m *Mining) Auth(p PassThruParams, resp *AuthReply) error

Auth is special login method for Coinhive miners

func (*Mining) Getjob

func (m *Mining) Getjob(p PassThruParams, resp *Job) error

func (*Mining) Keepalived

func (m *Mining) Keepalived(p PassThruParams, resp *StatusReply) error

Keepalived lets the client tell you they're still there, and you get to say "I'm still here too" Right now, we don't keep track of idle connections, so this doesn't really matter.

func (*Mining) Login

func (m *Mining) Login(p PassThruParams, resp *LoginReply) error

func (*Mining) Submit

func (m *Mining) Submit(p PassThruParams, resp *StatusReply) error

Submit accepts shares from a worker and passes them through to the pool. This does NOT currently recognize which worker or even what type of worker is doing the submiting, and does not return a Coinhive friendly response. But the coinhive miner doesn't care, it just doesn't keep up with submissions.

type PassThruParams

type PassThruParams map[string]interface{}

PassThruParams is a generic type for handling RPC requests. It can (should) contain the context of the request in order to be handled correctly. Other than the context, everything else should be shipped off to the pool as is. If that is not the correct behavior, use another type for params.

func (PassThruParams) Context

func (p PassThruParams) Context() context.Context

Context implements jsonrpc2.WithContext

func (*PassThruParams) SetContext

func (p *PassThruParams) SetContext(ctx context.Context)

SetContext implements jsonrpc2.WithContext

type Proxy

type Proxy struct {
	ID uint64
	SC *stratum.Client
	DC *stratum.Client
	SS *stratum.Server
	// contains filtered or unexported fields
}

Proxy manages a group of workers.

func New

func New(id uint64) *Proxy

New creates a new proxy, starts the work thread, and returns a pointer to it.

func (*Proxy) Add

func (p *Proxy) Add(w Worker)

Add a worker to the proxy - safe for concurrent use.

func (*Proxy) NextJob

func (p *Proxy) NextJob() *Job

NextJob gets gets the next job (on the current block) and increments the nonce

func (*Proxy) Remove

func (p *Proxy) Remove(w Worker)

Remove a worker from the proxy - safe for concurrent use.

func (*Proxy) Submit

func (p *Proxy) Submit(params map[string]interface{}) (*StatusReply, error)

Submit sends worker shares to the pool. Safe for concurrent use.

type Stats

type Stats struct {
	Timestamp time.Time

	Alive     time.Duration
	Proxies   int
	Workers   int
	Shares    uint64
	NewShares uint64
	// contains filtered or unexported fields
}

Stats is a struct containing information about server uptime and activity, generated on demand

type StatusReply

type StatusReply struct {
	Status string          `json:"status"`
	Error  *jsonrpc2.Error `json:"error,omitempty"`
}

type Worker

type Worker interface {
	// ID is used to distinguish this worker from other workers on the proxy.
	ID() uint64
	// SetID allows proxies to assign this value when a connection is established.
	SetID(uint64)

	// Workers must implement this method to establish communication with their assigned
	// proxy.  The proxy connection should be stored in order to 1. Submit Shares and 2. Disconnect Cleanly
	SetProxy(*Proxy)
	Proxy() *Proxy

	// Disconnect closes the connection to the proxy from the worker.
	// Ideally it sets up the worker to try and reconnect to a new proxy through the director.
	Disconnect()

	NewJob(*Job)
}

Worker does the work for the proxy. It exposes methods that allow interface with the proxy.

Jump to

Keyboard shortcuts

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