p2p

package
v0.0.0-...-37d4934 Latest Latest
Warning

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

Go to latest
Published: May 26, 2018 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeDB           = "nodeinfo.db"
	NodeBucket       = "node"
	DispatcherScheme = "gizo" //FIXME: use better one
	MaxWorkers       = 128
	DefaultPort      = 9999
	CentrumURL       = "https://centrum-dev.herokuapp.com"
	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"
)

node states

View Source
const (
	HELLO            = "HELLO"
	INVALIDMESSAGE   = "INVALIDMESSAGE" // invalid message
	CONNFULL         = "CONNFULL"       // max workers reached
	JOB              = "JOB"
	INVALIDSIGNATURE = "JOB"
	RESULT           = "RESULT"
	SHUT             = "SHUT"
	SHUTACK          = "SHUTACK"
	BLOCK            = "BLOCK"
	BLOCKREQ         = "BLOCKREQ"
	BLOCKRES         = "BLOCKRES"
	PEERCONNECT      = "PEERCONNECT"
	PEERDISCONNECT   = "PEERDISCONNECT"
	CANCEL           = "CANCEL"
)

Variables

View Source
var (
	ErrJobsFull = errors.New("Jobs array full")
)
View Source
var (
	ErrNoDispatchers = errors.New("Centrum: no dispatchers available")
)
View Source
var (
	ErrNoToken = errors.New("Centrum: No token in struct")
)

Functions

func BlockMessage

func BlockMessage(payload, priv []byte) []byte

func BlockReqMessage

func BlockReqMessage(payload, priv []byte) []byte

func BlockResMessage

func BlockResMessage(payload, priv []byte) []byte

func CancelMessage

func CancelMessage(priv []byte) []byte

func ConnFullMessage

func ConnFullMessage() []byte

func HelloMessage

func HelloMessage(payload []byte) []byte

func InvalidMessage

func InvalidMessage() []byte

func InvalidSignature

func InvalidSignature() []byte

func JobMessage

func JobMessage(payload, priv []byte) []byte

func ParseAddr

func ParseAddr(addr string) (map[string]interface{}, error)

ParseAddr returns dispatcher url as a map

func PeerConnectMessage

func PeerConnectMessage(payload, priv []byte) []byte

func PeerDisconnectMessage

func PeerDisconnectMessage(payload, priv []byte) []byte

func ResultMessage

func ResultMessage(payload, priv []byte) []byte

func ShutAckMessage

func ShutAckMessage(priv []byte) []byte

func ShutMessage

func ShutMessage(priv []byte) []byte

Types

type Centrum

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

func NewCentrum

func NewCentrum() *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{}

GetDispatchers returns active dispatchers

func (Centrum) GetToken

func (c Centrum) GetToken() string

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)

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() (map[string]interface{}, error)

Wake changes node status to active in centrum

type Dispatcher

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

func NewDispatcher

func NewDispatcher(port int) *Dispatcher

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(s interface{}, n *DispatcherInfo)

func (Dispatcher) Batch

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

func (Dispatcher) BlockByHash

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

func (Dispatcher) BlockByHeight

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

func (Dispatcher) BlockHashesHex

func (d Dispatcher) BlockHashesHex() []string

BlockHashesHex returns hashes of all blocks in the bc

func (Dispatcher) BroadcastPeers

func (d Dispatcher) BroadcastPeers(m []byte)

BroadcastPeers sends message to all peers

func (Dispatcher) BroadcastWorkers

func (d Dispatcher) BroadcastWorkers(m []byte)

BroadcastWorkers sends message to all workers

func (Dispatcher) CancelExec

func (d Dispatcher) CancelExec(hash []byte) error

func (Dispatcher) Chain

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

func (Dispatcher) Chord

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

func (*Dispatcher) EmptyJobs

func (d *Dispatcher) EmptyJobs()

func (Dispatcher) ExecArgs

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

func (Dispatcher) ExecBackoff

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

func (Dispatcher) ExecBy

func (d Dispatcher) ExecBy(id string, hash []byte) (string, error)

func (Dispatcher) ExecDurationMinutes

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

func (Dispatcher) ExecDurationNanoseconds

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

func (Dispatcher) ExecDurationSeconds

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

func (Dispatcher) ExecDurationString

func (d Dispatcher) ExecDurationString(id string, hash []byte) (string, error)

func (Dispatcher) ExecErr

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

func (Dispatcher) ExecExecutionTime

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

func (Dispatcher) ExecExecutionTimeString

func (d Dispatcher) ExecExecutionTimeString(id string, hash []byte) (string, error)

func (Dispatcher) ExecInterval

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

func (Dispatcher) ExecPriority

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

func (Dispatcher) ExecResult

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

func (Dispatcher) ExecRetries

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

func (Dispatcher) ExecStatus

func (d Dispatcher) ExecStatus(id string, hash []byte) (string, error)

func (Dispatcher) ExecTimestamp

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

func (Dispatcher) ExecTimestampString

func (d Dispatcher) ExecTimestampString(id string, hash []byte) (string, error)

func (Dispatcher) ExecTtlHours

func (d Dispatcher) ExecTtlHours(id string, hash []byte) (float64, error)

func (Dispatcher) ExecTtlMinutes

func (d Dispatcher) ExecTtlMinutes(id string, hash []byte) (float64, error)

func (Dispatcher) ExecTtlNanoseconds

func (d Dispatcher) ExecTtlNanoseconds(id string, hash []byte) (int64, error)

func (Dispatcher) ExecTtlSeconds

func (d Dispatcher) ExecTtlSeconds(id string, hash []byte) (float64, error)

func (Dispatcher) ExecTtlString

func (d Dispatcher) ExecTtlString(id string, hash []byte) (string, error)

func (Dispatcher) GetAssignedWorker

func (d Dispatcher) GetAssignedWorker(hash []byte) *melody.Session

GetAssignedWorker returns worker assigned to execute job

func (Dispatcher) GetBC

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

func (Dispatcher) GetBench

func (d Dispatcher) GetBench() benchmark.Engine

func (Dispatcher) GetBenchmarks

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

func (Dispatcher) GetDWS

func (d Dispatcher) GetDWS() *melody.Melody

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

func (Dispatcher) GetJC

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

func (Dispatcher) GetJobPQ

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

func (Dispatcher) GetJobs

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

func (Dispatcher) GetPeer

func (d Dispatcher) GetPeer(n interface{}) *DispatcherInfo

func (Dispatcher) GetPeers

func (d Dispatcher) GetPeers() map[interface{}]*DispatcherInfo

func (Dispatcher) GetPeersPubs

func (d Dispatcher) GetPeersPubs() []string

func (Dispatcher) GetPort

func (d Dispatcher) GetPort() int

func (Dispatcher) GetPrivByte

func (d Dispatcher) GetPrivByte() []byte

func (Dispatcher) GetPrivString

func (d Dispatcher) GetPrivString() string

func (Dispatcher) GetPubByte

func (d Dispatcher) GetPubByte() []byte

func (Dispatcher) GetPubString

func (d Dispatcher) GetPubString() string

func (Dispatcher) GetRPC

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

func (Dispatcher) GetUptimeString

func (d Dispatcher) GetUptimeString() string

func (Dispatcher) GetUptme

func (d Dispatcher) GetUptme() int64

func (Dispatcher) GetWWS

func (d Dispatcher) GetWWS() *melody.Melody

func (Dispatcher) GetWorker

func (d Dispatcher) GetWorker(s *melody.Session) *WorkerInfo

func (Dispatcher) GetWorkerPQ

func (d Dispatcher) GetWorkerPQ() *WorkerPriorityQueue

func (Dispatcher) GetWorkers

func (d Dispatcher) GetWorkers() map[*melody.Session]*WorkerInfo

func (Dispatcher) GetWriteQ

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

func (Dispatcher) IsJobPrivate

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

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)

func (Dispatcher) JobLatestExec

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

func (Dispatcher) JobName

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

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)

func (Dispatcher) JobSubmisstionTimeUnix

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

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)

func (Dispatcher) LatestBlock

func (d Dispatcher) LatestBlock() string

func (Dispatcher) LatestBlockHeight

func (d Dispatcher) LatestBlockHeight() int

func (Dispatcher) MulticastPeers

func (d Dispatcher) MulticastPeers(m []byte, peers []string)

MulticastPeers sends message to specified peers

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)

func (Dispatcher) NewJob

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

func (Dispatcher) PeerCount

func (d Dispatcher) PeerCount() int

PeerCount returns the number of peers a node has

func (Dispatcher) Peers

func (d Dispatcher) Peers() []string

Peers returns the public keys of its peers

func (Dispatcher) PendingCount

func (d Dispatcher) PendingCount() int

PendingCount returns number of job waiting to be written to the bc

func (Dispatcher) PublicKey

func (d Dispatcher) PublicKey() string

func (Dispatcher) Register

func (d Dispatcher) Register()

Register registers dispatcher with centrum

func (Dispatcher) Rpc

func (d Dispatcher) Rpc()

func (Dispatcher) SaveToken

func (d Dispatcher) SaveToken()

SaveToken saves token got from centrum to db

func (Dispatcher) Score

func (d Dispatcher) Score() float64

func (*Dispatcher) SetIP

func (d *Dispatcher) SetIP(ip string)

func (*Dispatcher) SetWorker

func (d *Dispatcher) SetWorker(s *melody.Session, w *WorkerInfo)

func (Dispatcher) Solo

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

func (Dispatcher) Start

func (d Dispatcher) Start()

Start spins up services

func (Dispatcher) Version

func (d Dispatcher) Version() string

Version returns nodes version

func (Dispatcher) WorkerExists

func (d Dispatcher) WorkerExists(s *melody.Session) bool

func (Dispatcher) WorkersCount

func (d Dispatcher) WorkersCount() int

func (Dispatcher) WorkersCountBusy

func (d Dispatcher) WorkersCountBusy() int

func (Dispatcher) WorkersCountNotBusy

func (d Dispatcher) WorkersCountNotBusy() int

func (Dispatcher) WriteJobs

func (d Dispatcher) WriteJobs(jobs []job.Job)

WriteJobs writes jobs to the bc

type DispatcherBody

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

type DispatcherInfo

type DispatcherInfo struct {
	Pub   []byte
	Peers []string
}

DispatcherInfo message used to create and maintain adjacency between dispatcher nodes

func DeserializeDispatcherInfo

func DeserializeDispatcherInfo(b []byte) DispatcherInfo

func NewDispatcherInfo

func NewDispatcherInfo(pub []byte, p []string) *DispatcherInfo

func (*DispatcherInfo) AddPeer

func (w *DispatcherInfo) AddPeer(n string)

func (DispatcherInfo) GetPeers

func (d DispatcherInfo) GetPeers() []string

func (DispatcherInfo) GetPub

func (d DispatcherInfo) GetPub() []byte

func (DispatcherInfo) Serialize

func (d DispatcherInfo) Serialize() []byte

func (*DispatcherInfo) SetPeers

func (d *DispatcherInfo) SetPeers(n []string)

func (*DispatcherInfo) SetPub

func (d *DispatcherInfo) SetPub(pub []byte)

type PeerMessage

type PeerMessage struct {
	Message   string
	Payload   []byte
	Signature [][]byte
}

PeerMessage message sent between nodes

func DeserializePeerMessage

func DeserializePeerMessage(b []byte) PeerMessage

func NewPeerMessage

func NewPeerMessage(message string, payload []byte, priv []byte) PeerMessage

func (PeerMessage) GetMessage

func (m PeerMessage) GetMessage() string

func (PeerMessage) GetPayload

func (m PeerMessage) GetPayload() []byte

func (PeerMessage) GetSignature

func (m PeerMessage) GetSignature() [][]byte

func (PeerMessage) Serialize

func (m PeerMessage) Serialize() []byte

func (*PeerMessage) SetMessage

func (m *PeerMessage) SetMessage(message string)

func (*PeerMessage) SetPayload

func (m *PeerMessage) SetPayload(payload []byte)

func (*PeerMessage) VerifySignature

func (m *PeerMessage) VerifySignature(pub string) bool

type Version

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

func DeserializeVersion

func DeserializeVersion(b []byte) Version

func NewVersion

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

func (Version) GetBlocks

func (v Version) GetBlocks() []string

func (Version) GetHeight

func (v Version) GetHeight() int

func (Version) GetVersion

func (v Version) GetVersion() int

func (Version) Serialize

func (v Version) Serialize() []byte

type Worker

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

func NewWorker

func NewWorker() *Worker

func (*Worker) Connect

func (w *Worker) Connect()

func (*Worker) Dial

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

func (Worker) Disconnect

func (w Worker) Disconnect()

func (Worker) GetBusy

func (w Worker) GetBusy() bool

func (Worker) GetDispatcher

func (w Worker) GetDispatcher() string

func (*Worker) GetDispatchers

func (w *Worker) GetDispatchers()

func (Worker) GetItem

func (w Worker) GetItem() qItem.Item

func (Worker) GetPrivByte

func (w Worker) GetPrivByte() []byte

func (Worker) GetPrivString

func (w Worker) GetPrivString() string

func (Worker) GetPubByte

func (w Worker) GetPubByte() []byte

func (Worker) GetPubString

func (w Worker) GetPubString() string

func (Worker) GetShortlist

func (w Worker) GetShortlist() []string

func (Worker) GetState

func (w Worker) GetState() string

func (Worker) GetUptimeString

func (w Worker) GetUptimeString() string

func (Worker) GetUptme

func (w Worker) GetUptme() int64

func (Worker) NodeTypeDispatcher

func (w Worker) NodeTypeDispatcher() bool

func (*Worker) SetBusy

func (w *Worker) SetBusy(b bool)

func (*Worker) SetDispatcher

func (w *Worker) SetDispatcher(d string)

func (*Worker) SetItem

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

func (*Worker) SetShortlist

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

func (*Worker) SetState

func (w *Worker) SetState(s string)

func (*Worker) Start

func (w *Worker) Start()

func (Worker) WatchInterrupt

func (w Worker) WatchInterrupt()

type WorkerInfo

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

func NewWorkerInfo

func NewWorkerInfo(pub string) *WorkerInfo

func (*WorkerInfo) Assign

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

func (*WorkerInfo) Busy

func (w *WorkerInfo) Busy() bool

func (WorkerInfo) GetJob

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

func (WorkerInfo) GetPub

func (w WorkerInfo) GetPub() string

func (WorkerInfo) GetShut

func (w WorkerInfo) GetShut() bool

func (*WorkerInfo) SetJob

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

func (*WorkerInfo) SetPub

func (w *WorkerInfo) SetPub(pub string)

func (*WorkerInfo) SetShut

func (w *WorkerInfo) SetShut(s bool)

type WorkerPriorityQueue

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

func NewWorkerPriorityQueue

func NewWorkerPriorityQueue() *WorkerPriorityQueue

func (WorkerPriorityQueue) Len

func (pq WorkerPriorityQueue) Len() int

func (WorkerPriorityQueue) Pop

func (pq WorkerPriorityQueue) Pop() *melody.Session

func (WorkerPriorityQueue) Push

func (pq WorkerPriorityQueue) Push(s *melody.Session, priority int)

func (WorkerPriorityQueue) Remove

func (pq WorkerPriorityQueue) Remove(s *melody.Session)

Jump to

Keyboard shortcuts

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