pulsar

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPulse

func NewPulse(numberDelta uint32, previousPulseNumber core.PulseNumber, entropyGenerator entropygenerator.EntropyGenerator) *core.Pulse

NewPulse creates a new pulse with using of custom GeneratedEntropy Generator

Types

type BftCell added in v0.4.0

type BftCell struct {
	Sign              []byte
	Entropy           core.Entropy
	IsEntropyReceived bool
	// contains filtered or unexported fields
}

BftCell is a cell in NxN btf-grid

func (*BftCell) GetEntropy added in v0.6.1

func (bftCell *BftCell) GetEntropy() core.Entropy

GetEntropy gets Entropy in the thread-safe way

func (*BftCell) GetIsEntropyReceived added in v0.6.1

func (bftCell *BftCell) GetIsEntropyReceived() bool

GetIsEntropyReceived gets IsEntropyReceived in the thread-safe way

func (*BftCell) GetSign added in v0.6.1

func (bftCell *BftCell) GetSign() []byte

GetSign gets Sign in the thread-safe way

func (*BftCell) SetEntropy added in v0.6.1

func (bftCell *BftCell) SetEntropy(entropy core.Entropy)

SetEntropy sets Entropy in the thread-safe way

func (*BftCell) SetIsEntropyReceived added in v0.6.1

func (bftCell *BftCell) SetIsEntropyReceived(isEntropyReceived bool)

SetIsEntropyReceived sets IsEntropyReceived in the thread-safe way

func (*BftCell) SetSign added in v0.6.1

func (bftCell *BftCell) SetSign(sign []byte)

SetSign sets Sign in the thread-safe way

type EntropyPayload added in v0.4.0

type EntropyPayload struct {
	PulseNumber core.PulseNumber
	Entropy     core.Entropy
}

EntropyPayload is a struct for sending Entropy step

type EntropySignaturePayload added in v0.4.0

type EntropySignaturePayload struct {
	PulseNumber core.PulseNumber
	Signature   []byte
}

EntropySignaturePayload is a struct for sending Sign of Entropy step

type Handler added in v0.3.0

type Handler struct {
	Pulsar *Pulsar
}

Handler is a wrapper for rpc-calls It contains rpc-methods logic and pulsar's methods

func (*Handler) HealthCheck added in v0.4.0

func (handler *Handler) HealthCheck(request *Payload, response *Payload) error

HealthCheck is a handler of call with nil-payload It uses for checking connection status between pulsars

func (*Handler) MakeHandshake added in v0.3.0

func (handler *Handler) MakeHandshake(request *Payload, response *Payload) error

MakeHandshake is a handler of call with handshake purpose

func (*Handler) ReceiveChosenSignature added in v0.4.0

func (handler *Handler) ReceiveChosenSignature(request *Payload, response *Payload) error

ReceiveChosenSignature is a handler of call with the confirmation signature

func (*Handler) ReceiveEntropy added in v0.4.0

func (handler *Handler) ReceiveEntropy(request *Payload, response *Payload) error

ReceiveEntropy is a handler of call for receiving Entropy from one of the pulsars

func (*Handler) ReceivePulse added in v0.6.0

func (handler *Handler) ReceivePulse(request *Payload, response *Payload) error

ReceivePulse is a handler of call with the freshest pulse

func (*Handler) ReceiveSignatureForEntropy added in v0.4.0

func (handler *Handler) ReceiveSignatureForEntropy(request *Payload, response *Payload) error

ReceiveSignatureForEntropy is a handler of call for receiving Sign of Entropy from one of the pulsars

func (*Handler) ReceiveVector added in v0.4.0

func (handler *Handler) ReceiveVector(request *Payload, response *Payload) error

ReceiveVector is a handler of call for receiving vector of Entropy

type HandshakePayload added in v0.3.0

type HandshakePayload struct {
	Entropy core.Entropy
}

HandshakePayload is a struct for handshake step

type Neighbour added in v0.3.0

type Neighbour struct {
	ConnectionType    configuration.ConnectionType
	ConnectionAddress string
	OutgoingClient    RPCClientWrapper
	PublicKey         *ecdsa.PublicKey
}

Neighbour is a helper struct, which contains info about pulsar-neighbour

type Payload added in v0.3.0

type Payload struct {
	PublicKey string
	Signature []byte
	Body      interface{}
}

Payload is a base struct for pulsar's rpc-message

type Pulsar

type Pulsar struct {
	Sock               net.Listener
	SockConnectionType configuration.ConnectionType
	RPCServer          *rpc.Server

	Neighbours   map[string]*Neighbour
	PrivateKey   *ecdsa.PrivateKey
	PublicKeyRaw string

	Config configuration.Pulsar

	Storage          pulsarstorage.PulsarStorage
	EntropyGenerator entropygenerator.EntropyGenerator

	StartProcessLock     sync.Mutex
	GeneratedEntropy     core.Entropy
	GeneratedEntropySign []byte

	CurrentSlotEntropy     core.Entropy
	CurrentSlotPulseSender string

	CurrentSlotSenderConfirmations map[string]core.PulseSenderConfirmation

	ProcessingPulseNumber core.PulseNumber

	OwnedBftRow map[string]*BftCell

	BftGridLock sync.RWMutex

	StateSwitcher StateSwitcher
	Certificate   certificate.Certificate
	// contains filtered or unexported fields
}

Pulsar is a base struct for pulsar's node It contains all the stuff, which is needed for working of a pulsar

func NewPulsar

func NewPulsar(
	configuration configuration.Pulsar,
	storage pulsarstorage.PulsarStorage,
	rpcWrapperFactory RPCClientWrapperFactory,
	entropyGenerator entropygenerator.EntropyGenerator,
	stateSwitcher StateSwitcher,
	certificate core.Certificate,
	listener func(string, string) (net.Listener, error)) (*Pulsar, error)

NewPulsar creates a new pulse with using of custom GeneratedEntropy Generator

func (*Pulsar) CheckConnectionsToPulsars added in v0.5.0

func (currentPulsar *Pulsar) CheckConnectionsToPulsars()

CheckConnectionsToPulsars is a method refreshing connections between pulsars

func (*Pulsar) EstablishConnectionToPulsar added in v0.5.0

func (currentPulsar *Pulsar) EstablishConnectionToPulsar(pubKey string) error

EstablishConnectionToPulsar is a method for creating connection to another pulsar

func (*Pulsar) FetchNeighbour added in v0.6.0

func (currentPulsar *Pulsar) FetchNeighbour(pubKey string) (*Neighbour, error)

FetchNeighbour searches neighbour of the pulsar by pubKey of a neighbout

func (*Pulsar) GetBftGridItem added in v0.6.0

func (currentPulsar *Pulsar) GetBftGridItem(row string, column string) *BftCell

GetBftGridItem returns a grid item i nthe thread-safe way

func (*Pulsar) GetLastPulse added in v0.6.1

func (currentPulsar *Pulsar) GetLastPulse() *core.Pulse

GetLastPulse returns last pulse in the thread-safe mode

func (*Pulsar) IsStateFailed added in v0.6.0

func (currentPulsar *Pulsar) IsStateFailed() bool

IsStateFailed checks if state of the pulsar is failed or not

func (*Pulsar) SetBftGridItem added in v0.6.0

func (currentPulsar *Pulsar) SetBftGridItem(key string, value map[string]*BftCell)

SetBftGridItem set item of the bftGrid in the thread-safe way

func (*Pulsar) SetLastPulse added in v0.6.1

func (currentPulsar *Pulsar) SetLastPulse(newPulse *core.Pulse)

SetLastPulse sets last pulse in the thread-safe mode

func (*Pulsar) StartConsensusProcess added in v0.4.0

func (currentPulsar *Pulsar) StartConsensusProcess(pulseNumber core.PulseNumber) error

StartConsensusProcess starts process of calculating consensus between pulsars

func (*Pulsar) StartServer added in v0.4.0

func (currentPulsar *Pulsar) StartServer()

StartServer starts listening of the rpc-server

func (*Pulsar) StopServer added in v0.4.0

func (currentPulsar *Pulsar) StopServer()

StopServer stops listening of the rpc-server

type PulsePayload added in v0.6.0

type PulsePayload struct {
	Pulse core.Pulse
}

PulsePayload is a struct for sending finished pulse to all pulsars

type RPCClientWrapper added in v0.4.0

type RPCClientWrapper interface {
	// Lock takes current neighbour's lock
	Lock()
	// Unlock releases current neighbour's lock
	Unlock()

	// IsInitialised compares underhood rpc-client with nil
	IsInitialised() bool
	// CreateConnection creates connection to an another pulsar
	CreateConnection(connectionType configuration.ConnectionType, connectionAddress string) error
	// Close closes connection
	Close() error

	// Go makes rpc-call to an another pulsar
	Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) *rpc.Call

	// ResetClient clears rpc-client
	ResetClient()
}

RPCClientWrapper describes interface of the wrapper around rpc-client

type RPCClientWrapperFactory added in v0.4.0

type RPCClientWrapperFactory interface {
	CreateWrapper() RPCClientWrapper
}

RPCClientWrapperFactory describes interface for the wrappers factory

type RPCClientWrapperFactoryImpl added in v0.4.0

type RPCClientWrapperFactoryImpl struct {
}

RPCClientWrapperFactoryImpl is a base impl of the RPCClientWrapperFactory

func (RPCClientWrapperFactoryImpl) CreateWrapper added in v0.4.0

CreateWrapper return new RPCClientWrapper

type RPCClientWrapperImpl added in v0.4.0

type RPCClientWrapperImpl struct {
	*sync.Mutex
	*rpc.Client
}

RPCClientWrapperImpl is a standard impl of RPCClientWrapper

func (*RPCClientWrapperImpl) Close added in v0.4.0

func (impl *RPCClientWrapperImpl) Close() error

Close closes connection

func (*RPCClientWrapperImpl) CreateConnection added in v0.4.0

func (impl *RPCClientWrapperImpl) CreateConnection(connectionType configuration.ConnectionType, connectionAddress string) error

CreateConnection creates connection to an another pulsar

func (*RPCClientWrapperImpl) Go added in v0.4.0

func (impl *RPCClientWrapperImpl) Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) *rpc.Call

Go makes rpc-call to an another pulsar

func (*RPCClientWrapperImpl) IsInitialised added in v0.4.0

func (impl *RPCClientWrapperImpl) IsInitialised() bool

IsInitialised compares underhood rpc-client with nil

func (*RPCClientWrapperImpl) Lock added in v0.4.0

func (impl *RPCClientWrapperImpl) Lock()

Lock takes current neighbour's lock

func (*RPCClientWrapperImpl) ResetClient added in v0.5.0

func (impl *RPCClientWrapperImpl) ResetClient()

ResetClient clears rpc-client

func (*RPCClientWrapperImpl) Unlock added in v0.4.0

func (impl *RPCClientWrapperImpl) Unlock()

Unlock releases current neighbour's lock

type RequestType added in v0.3.0

type RequestType string

RequestType is a enum-like strings It identifies the type of the rpc-call

const (
	// HealthCheck is a method for checking connection between pulsars
	HealthCheck RequestType = "Pulsar.HealthCheck"

	// Handshake is a method for creating connection between pulsars
	Handshake RequestType = "Pulsar.MakeHandshake"

	// ReceiveSignatureForEntropy is a method for receiving signs from peers
	ReceiveSignatureForEntropy RequestType = "Pulsar.ReceiveSignatureForEntropy"

	// ReceiveEntropy is a method for receiving Entropy from peers
	ReceiveEntropy RequestType = "Pulsar.ReceiveEntropy"

	// ReceiveVector is a method for receiving vectors from peers
	ReceiveVector RequestType = "Pulsar.ReceiveVector"

	// ReceiveChosenSignature is a method for receiving signature for sending from peers
	ReceiveChosenSignature RequestType = "Pulsar.ReceiveChosenSignature"

	// ReceivePulse is a method for receiving pulse from the sender
	ReceivePulse RequestType = "Pulsar.ReceivePulse"
)

func (RequestType) String added in v0.3.0

func (state RequestType) String() string

type State added in v0.4.0

type State int
const (
	Failed State = iota
	WaitingForStart
	GenerateEntropy
	WaitingForEntropySigns
	SendingEntropy
	WaitingForEntropy
	SendingVector
	WaitingForVectors
	Verifying
	SendingPulseSign
	WaitingForPulseSigns
	SendingPulse
)

func (State) String added in v0.5.0

func (i State) String() string

type StateSwitcher added in v0.5.0

type StateSwitcher interface {
	SwitchToState(state State, args interface{})
	GetState() State

	SetPulsar(pulsar *Pulsar)
	// contains filtered or unexported methods
}

StateSwitcher is a base for pulsar's state machine

type StateSwitcherImpl added in v0.5.0

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

StateSwitcherImpl is a base implementation of the pulsar's state machine

func (*StateSwitcherImpl) GetState added in v0.6.0

func (switcher *StateSwitcherImpl) GetState() State

func (*StateSwitcherImpl) SetPulsar added in v0.5.0

func (switcher *StateSwitcherImpl) SetPulsar(pulsar *Pulsar)

SetPulsar sets pulsar of the current instance

func (*StateSwitcherImpl) SwitchToState added in v0.6.0

func (switcher *StateSwitcherImpl) SwitchToState(state State, args interface{})

type VectorPayload added in v0.4.0

type VectorPayload struct {
	PulseNumber core.PulseNumber
	Vector      map[string]*BftCell
}

VectorPayload is a struct for sending vector of Entropy step

Directories

Path Synopsis
Package pulsartestutil - test utils for pulsar package
Package pulsartestutil - test utils for pulsar package

Jump to

Keyboard shortcuts

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