p2p

package
v0.0.0-...-eef6c14 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//NodeDB file name of nodeinfo database
	NodeDB = "%s.nodeinfo.db"
	//NodeBucket bolt db bucket
	NodeBucket = "node"
	//MaxWorkers number of workers allowed per standard area
	MaxWorkers = 128
	//DefaultPort default port
	DefaultPort = 9999
	//CentrumURL url of centrum api
	CentrumURL = "https://centrum-dev.herokuapp.com"
	//GizoVersion version of gizo
	GizoVersion = 1
)
View Source
const (
	// when a node is not connected to the network
	DOWN = "DOWN"
	// worker - when a worker connects to a dispatchers standard area
	// dispatcher - when an adjacency is created and topology table, peer table and blockchain have not been synced
	INIT = "INIT"
	// worker - when a node starts receiving and crunching jobs
	LIVE = "LIVE"
	// dispatcher - when an adjacency is created and topology table, peer table and blockchain have been sync
	FULL = "FULL"
	//CONNFULL when the max number of workers is reached
	CONNFULL = "CONNFULL"
	//BLOCK when a block is sent or received
	BLOCK = "BLOCK"
	//BLOCKREQ block request channel
	BLOCKREQ = "BLOCKREQ"
	//WORKERCONNECT worker connect rpc method name
	WORKERCONNECT = "WORKERCONNECT"
	//WORKERDISCONNECT worker disconnect channel
	WORKERDISCONNECT = "worker.disconnect"
	//CONNECTED ack message for connection to dispatcher area
	CONNECTED = "CONNECTED"
	//WORKERREALM realm worker nodes connect to
	WORKERREALM = "gizo.network.worker"
	//DISPATCHERREALM realm dispatcher nodes connect to
	DISPATCHERREALM = "gizo.network.dispatcher"
)

node states

Variables

View Source
var (

	//ErrNoToken occurs when node has not token
	ErrNoToken = errors.New("Centrum: No token in struct")
	//ErrUnableToConnect occurs when node is unable to connect to centrum
	ErrUnableToConnect = errors.New("Centrum: Unable to connect to centrum")
)
View Source
var (
	//ErrJobsFull occurs when jobs map is full
	ErrJobsFull = errors.New("Jobs map full")
)
View Source
var (
	//ErrNoDispatchers occurs when there are no dispaters return from centrum
	ErrNoDispatchers = errors.New("Centrum: no dispatchers available")
)

Functions

func ParseAddr

func ParseAddr(addr string) (map[string]string, error)

ParseAddr returns dispatcher url as a map

Types

type Centrum

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

Centrum communication with centrum

func NewCentrum

func NewCentrum() *Centrum

NewCentrum initlializes centrum

func (Centrum) ConnectWorker

func (c Centrum) ConnectWorker() (map[string]interface{}, error)

ConnectWorker increments dispatchers worker in centrum

func (Centrum) DisconnectWorker

func (c Centrum) DisconnectWorker() (map[string]interface{}, error)

DisconnectWorker decrements dispatchers worker in centrum

func (Centrum) GetDispatchers

func (c Centrum) GetDispatchers() (map[string]interface{}, error)

GetDispatchers returns active dispatchers

func (Centrum) GetToken

func (c Centrum) GetToken() string

GetToken returns token

func (*Centrum) NewDisptcher

func (c *Centrum) NewDisptcher(pub, ip string, port int) error

NewDisptcher registers dispatcher in centrum

func (*Centrum) SetToken

func (c *Centrum) SetToken(token string)

SetToken sets dispatcher token

func (Centrum) Sleep

func (c Centrum) Sleep() (map[string]interface{}, error)

Sleep changes node status to sleep in centrum

func (Centrum) Wake

func (c Centrum) Wake(pub, ip string, port int) (map[string]interface{}, error)

Wake changes node status to active in centrum

type Dispatcher

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

Dispatcher dispatcher node

func NewDispatcher

func NewDispatcher(port int) *Dispatcher

NewDispatcher initalizes dispatcher node

func (*Dispatcher) AddJob

func (d *Dispatcher) AddJob(j job.Job)

AddJob keeps job in memory before being written to the bc

func (*Dispatcher) AddPeer

func (d *Dispatcher) AddPeer(p string, c *client.Client)

AddPeer adds peer connection

func (*Dispatcher) AddWorker

func (d *Dispatcher) AddWorker(pub string)

AddWorker sets worker

func (Dispatcher) Batch

func (d Dispatcher) Batch(jrs []string) (string, error)

Batch executes execs in parallel

func (Dispatcher) BlockByHash

func (d Dispatcher) BlockByHash(hash string) (string, error)

BlockByHash returns block of specified hash

func (Dispatcher) BlockByHeight

func (d Dispatcher) BlockByHeight(height int) (string, error)

BlockByHeight returns block at specified height

func (Dispatcher) BlockHashesHex

func (d Dispatcher) BlockHashesHex() ([]string, error)

BlockHashesHex returns hashes of all blocks in the blockchain

func (Dispatcher) BlockReq

func (d Dispatcher) BlockReq(ctx context.Context, args wamp.List, kwargs, details wamp.Dict) *client.InvokeResult

BlockReq handles peer request for block

func (*Dispatcher) BlockSubscribe

func (d *Dispatcher) BlockSubscribe(peer *client.Client)

BlockSubscribe subscribe and publish to block topic

func (Dispatcher) CancelExec

func (d Dispatcher) CancelExec(hash string) error

CancelExec cancels exc

func (Dispatcher) Chain

func (d Dispatcher) Chain(jrs []string) (string, error)

Chain executes execs one after the other (allows multiple jobs and multiple execs)

func (Dispatcher) Chord

func (d Dispatcher) Chord(jrs []string, callbackJr string) (string, error)

Chord executes execs one after the other then passes results into callback exec as a list (allows multiple jobs and multiple execs)

func (*Dispatcher) EmptyJobs

func (d *Dispatcher) EmptyJobs()

EmptyJobs empties the jobs held in memory

func (Dispatcher) ExecArgs

func (d Dispatcher) ExecArgs(id string, hash string) ([]interface{}, error)

ExecArgs returns arguments of an exec

func (Dispatcher) ExecBackoff

func (d Dispatcher) ExecBackoff(id string, hash string) (float64, error)

ExecBackoff returns time between retries of an exec(seconds)

func (Dispatcher) ExecBy

func (d Dispatcher) ExecBy(id string, hash string) (string, error)

ExecBy returns public key of worker that executed the job

func (Dispatcher) ExecDurationMinutes

func (d Dispatcher) ExecDurationMinutes(id string, hash string) (float64, error)

ExecDurationMinutes returns duration of an exec in minutes

func (Dispatcher) ExecDurationNanoseconds

func (d Dispatcher) ExecDurationNanoseconds(id string, hash string) (int64, error)

ExecDurationNanoseconds returns duration of an exec in nanoseconds

func (Dispatcher) ExecDurationSeconds

func (d Dispatcher) ExecDurationSeconds(id string, hash string) (float64, error)

ExecDurationSeconds returns duration of an exec in seconds

func (Dispatcher) ExecDurationString

func (d Dispatcher) ExecDurationString(id string, hash string) (string, error)

ExecDurationString returns duration of an exec as string

func (Dispatcher) ExecErr

func (d Dispatcher) ExecErr(id string, hash string) (interface{}, error)

ExecErr returns error of an exec - None if no error occured

func (Dispatcher) ExecExecutionTime

func (d Dispatcher) ExecExecutionTime(id string, hash string) (int64, error)

ExecExecutionTime returns scheduled time of exec (unix)

func (Dispatcher) ExecExecutionTimeString

func (d Dispatcher) ExecExecutionTimeString(id string, hash string) (string, error)

ExecExecutionTimeString returns scheduled time of exec (string)

func (Dispatcher) ExecInterval

func (d Dispatcher) ExecInterval(id string, hash string) (int, error)

ExecInterval returns time between retries of an exec(seconds)

func (Dispatcher) ExecPriority

func (d Dispatcher) ExecPriority(id string, hash string) (int, error)

ExecPriority returns priority of an exec

func (Dispatcher) ExecResult

func (d Dispatcher) ExecResult(id string, hash string) (interface{}, error)

ExecResult result of an exec - None if error occurs

func (Dispatcher) ExecRetries

func (d Dispatcher) ExecRetries(id string, hash string) (int, error)

ExecRetries returns number of retries attempted by the worker

func (Dispatcher) ExecStatus

func (d Dispatcher) ExecStatus(id string, hash string) (string, error)

ExecStatus returns status of exec

func (Dispatcher) ExecTTLHours

func (d Dispatcher) ExecTTLHours(id string, hash string) (float64, error)

ExecTTLHours returns ttl of exec (hours)

func (Dispatcher) ExecTTLMinutes

func (d Dispatcher) ExecTTLMinutes(id string, hash string) (float64, error)

ExecTTLMinutes ttl of exec (minutes)

func (Dispatcher) ExecTTLNanoseconds

func (d Dispatcher) ExecTTLNanoseconds(id string, hash string) (int64, error)

ExecTTLNanoseconds returns tll of exec (nanoseconds)

func (Dispatcher) ExecTTLSeconds

func (d Dispatcher) ExecTTLSeconds(id string, hash string) (float64, error)

ExecTTLSeconds returns ttl of exec (seconds)

func (Dispatcher) ExecTTLString

func (d Dispatcher) ExecTTLString(id string, hash string) (string, error)

ExecTTLString returns ttl of exec (string)

func (Dispatcher) ExecTimestamp

func (d Dispatcher) ExecTimestamp(id string, hash string) (int64, error)

ExecTimestamp returns timestamp of exec - when the job started running (unix)

func (Dispatcher) ExecTimestampString

func (d Dispatcher) ExecTimestampString(id string, hash string) (string, error)

ExecTimestampString returns timestamp of exec - when the job started running (string)

func (Dispatcher) GetAssignedWorker

func (d Dispatcher) GetAssignedWorker(hash string) string

GetAssignedWorker returns worker assigned to execute job

func (Dispatcher) GetBC

func (d Dispatcher) GetBC() *core.BlockChain

GetBC returns blockchain object

func (Dispatcher) GetBench

func (d Dispatcher) GetBench() benchmark.Engine

GetBench returns node benchmark

func (Dispatcher) GetBenchmarks

func (d Dispatcher) GetBenchmarks() []benchmark.Benchmark

GetBenchmarks return node benchmarks per difficulty

func (*Dispatcher) GetDispatchersAndSync

func (d *Dispatcher) GetDispatchersAndSync()

GetDispatchersAndSync get's dispatchers from centrum and syncs with the node with the highest verison

func (Dispatcher) GetIP

func (d Dispatcher) GetIP() string

GetIP returns ip address of node

func (Dispatcher) GetJC

func (d Dispatcher) GetJC() *cache.JobCache

GetJC returns job cache object

func (Dispatcher) GetJobPQ

func (d Dispatcher) GetJobPQ() *queue.JobPriorityQueue

GetJobPQ returns priority of job execs

func (Dispatcher) GetJobs

func (d Dispatcher) GetJobs() map[string]job.Job

GetJobs returns jobs held in memory to be written to the bc

func (Dispatcher) GetPeers

func (d Dispatcher) GetPeers() map[string]*client.Client

GetPeers returns peers

func (Dispatcher) GetPort

func (d Dispatcher) GetPort() int

GetPort returns node port

func (Dispatcher) GetPrivByte

func (d Dispatcher) GetPrivByte() []byte

GetPrivByte returns private key of node as bytes

func (Dispatcher) GetPrivString

func (d Dispatcher) GetPrivString() string

GetPrivString returns private key of node as string

func (Dispatcher) GetPubByte

func (d Dispatcher) GetPubByte() []byte

GetPubByte returns public key of node as bytes

func (Dispatcher) GetPubString

func (d Dispatcher) GetPubString() string

GetPubString returns public key of node as bytes

func (Dispatcher) GetRPC

func (d Dispatcher) GetRPC() *rpc.HTTPService

GetRPC returns hprose rpc http server

func (Dispatcher) GetUptime

func (d Dispatcher) GetUptime() int64

GetUptime returns uptime of node

func (Dispatcher) GetUptimeString

func (d Dispatcher) GetUptimeString() string

GetUptimeString returns uptime of node as string

func (Dispatcher) GetWorker

func (d Dispatcher) GetWorker(s string) *WorkerInfo

GetWorker returns specified worker

func (Dispatcher) GetWorkerPQ

func (d Dispatcher) GetWorkerPQ() *WorkerPriorityQueue

GetWorkerPQ returns the workers priotity queue

func (Dispatcher) GetWorkers

func (d Dispatcher) GetWorkers() map[string]*WorkerInfo

GetWorkers returns workers in the standard area

func (Dispatcher) GetWriteQ

func (d Dispatcher) GetWriteQ() *lane.Queue

GetWriteQ returns queue of jobs to be written to the bc

func (Dispatcher) IsJobPrivate

func (d Dispatcher) IsJobPrivate(id string) (bool, error)

IsJobPrivate returns if job is private (true) / public (false)

func (Dispatcher) Job

func (d Dispatcher) Job(id string) (string, error)

Job returns a job

func (Dispatcher) JobExecs

func (d Dispatcher) JobExecs(id string) (string, error)

JobExecs returns all execs of a job

func (Dispatcher) JobLatestExec

func (d Dispatcher) JobLatestExec(id string) (string, error)

JobLatestExec returns latest exec of job

func (Dispatcher) JobName

func (d Dispatcher) JobName(id string) (string, error)

JobName returns name of job

func (Dispatcher) JobQueueCount

func (d Dispatcher) JobQueueCount() int

JobQueueCount returns nubmer of jobs waiting to be executed

func (Dispatcher) JobSubmisstionTimeString

func (d Dispatcher) JobSubmisstionTimeString(id string) (string, error)

JobSubmisstionTimeString returns submission time of job (string)

func (Dispatcher) JobSubmisstionTimeUnix

func (d Dispatcher) JobSubmisstionTimeUnix(id string) (int64, error)

JobSubmisstionTimeUnix returns submission time of job (unix)

func (Dispatcher) KeyPair

func (d Dispatcher) KeyPair() (string, error)

KeyPair returns new pub and priv keypair

func (Dispatcher) Latest15Blocks

func (d Dispatcher) Latest15Blocks() (string, error)

Latest15Blocks returns array of most recent 15 blocks

func (Dispatcher) LatestBlock

func (d Dispatcher) LatestBlock() (string, error)

LatestBlock returns latest block in the blockchain

func (Dispatcher) LatestBlockHeight

func (d Dispatcher) LatestBlockHeight() (int, error)

LatestBlockHeight height of latest block in the blockchain

func (Dispatcher) NewExec

func (d Dispatcher) NewExec(args []interface{}, retries, priority int, backoff int64, execTime int64, interval int, ttl int64, pub string, envs string) (string, error)

NewExec returns exec with specified config

func (Dispatcher) NewJob

func (d Dispatcher) NewJob(task string, name string, priv bool, privKey string) (string, error)

NewJob deploys job to the blockchain and returns ID

func (Dispatcher) PeerCount

func (d Dispatcher) PeerCount() int

PeerCount returns the number of peers a node has

func (Dispatcher) PendingCount

func (d Dispatcher) PendingCount() int

PendingCount returns number of jobs waiting to be written to the blockchain

func (Dispatcher) PublicKey

func (d Dispatcher) PublicKey() string

PublicKey returns public key of node

func (Dispatcher) RPC

func (d Dispatcher) RPC()

RPC exposes rpc functions

func (Dispatcher) Register

func (d Dispatcher) Register()

Register registers dispatcher with centrum

func (Dispatcher) SaveToken

func (d Dispatcher) SaveToken()

SaveToken saves token got from centrum to db

func (Dispatcher) Score

func (d Dispatcher) Score() float64

Score returns benchmark score of node

func (*Dispatcher) SetIP

func (d *Dispatcher) SetIP(ip string)

SetIP sets ip address of node

func (Dispatcher) Solo

func (d Dispatcher) Solo(jr string) (string, error)

Solo executes a single exec

func (Dispatcher) Start

func (d Dispatcher) Start()

Start spins up services

func (Dispatcher) Version

func (d Dispatcher) Version() (string, error)

Version returns dispatcher node's version information

func (*Dispatcher) WorkerConnect

func (d *Dispatcher) WorkerConnect(ctx context.Context, args wamp.List, kwargs, details wamp.Dict) *client.InvokeResult

WorkerConnect handles workers request to join area

func (Dispatcher) WorkerDisconnect

func (d Dispatcher) WorkerDisconnect()

WorkerDisconnect handles worker disconnect

func (Dispatcher) WorkersCount

func (d Dispatcher) WorkersCount() int

WorkersCount returns number of workers in a dispatchers standard area

func (Dispatcher) WorkersCountBusy

func (d Dispatcher) WorkersCountBusy() int

WorkersCountBusy returns number of workers in a dispatchers standard area that are busy

func (Dispatcher) WorkersCountNotBusy

func (d Dispatcher) WorkersCountNotBusy() int

WorkersCountNotBusy returns number of workers in a dispatchers standard area that are not busy

func (Dispatcher) WriteJobsAndPublish

func (d Dispatcher) WriteJobsAndPublish(jobs map[string]job.Job)

WriteJobsAndPublish writes jobs to the bc

type DispatcherBody

type DispatcherBody struct {
	Pub  string `url:"pub"`
	IP   string `url:"ip"`
	Port int    `url:"port"`
}

DispatcherBody message sent to centrum

type Version

type Version struct {
	Version int
	Height  int
	Blocks  []string
}

Version used for node synchornization

func NewVersion

func NewVersion(version int, height int, blocks []string) Version

NewVersion initializes a version

func (Version) GetBlocks

func (v Version) GetBlocks() []string

GetBlocks returns blocks

func (Version) GetHeight

func (v Version) GetHeight() int

GetHeight return height

func (Version) GetVersion

func (v Version) GetVersion() int

GetVersion returns version

type Worker

type Worker struct {
	Pub        []byte //public key of the node
	Dispatcher string
	// contains filtered or unexported fields
}

Worker worker node

func NewWorker

func NewWorker() *Worker

NewWorker initializes worker node

func (Worker) CancelJobSubscription

func (w Worker) CancelJobSubscription()

CancelJobSubscription handles cancellation requests

func (Worker) CancelTopic

func (w Worker) CancelTopic() string

CancelTopic channel that dispatcher emits cancel req to worker

func (*Worker) Connect

func (w *Worker) Connect()

Connect connects to dispatcher

func (*Worker) Dial

func (w *Worker) Dial(url string) error

Dial attempts ws connections to dispatcher

func (Worker) Disconnect

func (w Worker) Disconnect()

Disconnect disconnects from dispatcher

func (Worker) GetBusy

func (w Worker) GetBusy() bool

GetBusy returns if worker is busy

func (Worker) GetDispatcher

func (w Worker) GetDispatcher() string

GetDispatcher returns connected dispatcher

func (*Worker) GetDispatchers

func (w *Worker) GetDispatchers()

GetDispatchers connects to centrum to get dispatchers

func (Worker) GetItem

func (w Worker) GetItem() qItem.Item

GetItem returns worker item

func (Worker) GetPrivByte

func (w Worker) GetPrivByte() []byte

GetPrivByte returns private key as byte

func (Worker) GetPrivString

func (w Worker) GetPrivString() string

GetPrivString returns private key as string

func (Worker) GetPubByte

func (w Worker) GetPubByte() []byte

GetPubByte returns public key as bytes

func (Worker) GetPubString

func (w Worker) GetPubString() string

GetPubString returns public key as string

func (Worker) GetShortlist

func (w Worker) GetShortlist() []string

GetShortlist returs shortlists

func (Worker) GetState

func (w Worker) GetState() string

GetState returns worker state

func (Worker) GetUptimeString

func (w Worker) GetUptimeString() string

GetUptimeString returns uptime as string

func (Worker) GetUptme

func (w Worker) GetUptme() int64

GetUptme returns node uptime

func (Worker) JobSubscription

func (w Worker) JobSubscription()

JobSubscription handles job execution

func (Worker) JobTopic

func (w Worker) JobTopic() string

JobTopic channel that dispatcher emits jobs to worker

func (Worker) ResultTopic

func (w Worker) ResultTopic() string

ResultTopic channel that worker emits result to dispatcher

func (*Worker) SetBusy

func (w *Worker) SetBusy(b bool)

SetBusy sets busy status

func (*Worker) SetDispatcher

func (w *Worker) SetDispatcher(d string)

SetDispatcher sets connected dispatcher

func (*Worker) SetItem

func (w *Worker) SetItem(i qItem.Item)

SetItem sets item

func (*Worker) SetShortlist

func (w *Worker) SetShortlist(s []string)

SetShortlist sets shortlists

func (*Worker) SetState

func (w *Worker) SetState(s string)

SetState sets worker state

func (Worker) Start

func (w Worker) Start()

Start runs a worker

func (Worker) WatchInterrupt

func (w Worker) WatchInterrupt()

WatchInterrupt watchs for interrupt

type WorkerInfo

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

WorkerInfo information about worker

func NewWorkerInfo

func NewWorkerInfo(pub string) *WorkerInfo

NewWorkerInfo initalizes worker info

func (*WorkerInfo) Assign

func (w *WorkerInfo) Assign(j *qItem.Item)

Assign assigns job to worker

func (*WorkerInfo) Busy

func (w *WorkerInfo) Busy() bool

Busy checks if worker is busy

func (WorkerInfo) CancelTopic

func (w WorkerInfo) CancelTopic() string

CancelTopic channel that dispatcher emits cancel req to worker

func (WorkerInfo) GetJob

func (w WorkerInfo) GetJob() *qItem.Item

GetJob returns job

func (WorkerInfo) GetPub

func (w WorkerInfo) GetPub() string

GetPub returns public key

func (WorkerInfo) GetShut

func (w WorkerInfo) GetShut() bool

GetShut returns shut

func (WorkerInfo) JobTopic

func (w WorkerInfo) JobTopic() string

JobTopic channel that dispatcher emits jobs to worker

func (WorkerInfo) ResultTopic

func (w WorkerInfo) ResultTopic() string

ResultTopic channel that worker emits result to dispatcher

func (*WorkerInfo) SetJob

func (w *WorkerInfo) SetJob(j *qItem.Item)

SetJob sets job

func (*WorkerInfo) SetPub

func (w *WorkerInfo) SetPub(pub string)

SetPub sets public key

func (*WorkerInfo) SetShut

func (w *WorkerInfo) SetShut(s bool)

SetShut sets shut

type WorkerPriorityQueue

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

WorkerPriorityQueue priotity queue of workers

func NewWorkerPriorityQueue

func NewWorkerPriorityQueue() *WorkerPriorityQueue

NewWorkerPriorityQueue initializes worker priority queue

func (WorkerPriorityQueue) Len

func (pq WorkerPriorityQueue) Len() int

Len returns priority queues length

func (WorkerPriorityQueue) Pop

func (pq WorkerPriorityQueue) Pop() string

Pop returns next worker in the priority queue

func (WorkerPriorityQueue) Push

func (pq WorkerPriorityQueue) Push(s string, priority int)

Push adds worker to the priority queue

Jump to

Keyboard shortcuts

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