pulsar

package
v0.7.1-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: Apache-2.0 Imports: 23 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

func (*EntropyPayload) Hash added in v0.7.5

func (ep *EntropyPayload) Hash(hashProvider core.Hasher) ([]byte, error)

Hash calculates hash of payload

type EntropySignaturePayload added in v0.4.0

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

EntropySignaturePayload is a struct for sending Sign of Entropy step

func (*EntropySignaturePayload) Hash added in v0.7.5

func (es *EntropySignaturePayload) Hash(hashProvider core.Hasher) ([]byte, error)

Hash calculates hash of payload

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 NewHandler added in v0.7.5

func NewHandler(pulsar *Pulsar) *Handler

NewHandler is a constructor of Handler

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

func (*HandshakePayload) Hash added in v0.7.5

func (hp *HandshakePayload) Hash(hashProvider core.Hasher) ([]byte, error)

Hash calculates hash of payload

type Neighbour added in v0.3.0

type Neighbour struct {
	ConnectionType    configuration.ConnectionType
	ConnectionAddress string
	OutgoingClient    RPCClientWrapper
	PublicKey         crypto.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      PayloadData
}

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

type PayloadData added in v0.7.5

type PayloadData interface {
	Hash(hashProvider core.Hasher) ([]byte, error)
}

PayloadData is a body of Payload

type Pulsar

type Pulsar struct {
	ID string

	Sock               net.Listener
	SockConnectionType configuration.ConnectionType
	RPCServer          *rpc.Server

	Neighbours map[string]*Neighbour

	PublicKey    crypto.PublicKey
	PublicKeyRaw string

	Config configuration.Pulsar

	Storage          pulsarstorage.PulsarStorage
	EntropyGenerator entropygenerator.EntropyGenerator

	StartProcessLock sync.Mutex

	GeneratedEntropySign []byte

	CurrentSlotPulseSender string

	CurrentSlotSenderConfirmations map[string]core.PulseSenderConfirmation

	ProcessingPulseNumber core.PulseNumber

	BftGridLock sync.RWMutex

	StateSwitcher              StateSwitcher
	Certificate                certificate.Certificate
	CryptographyService        core.CryptographyService
	PlatformCryptographyScheme core.PlatformCryptographyScheme
	KeyProcessor               core.KeyProcessor
	PulseDistributor           core.PulseDistributor
	// 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,
	cryptographyService core.CryptographyService,
	scheme core.PlatformCryptographyScheme,
	keyProcessor core.KeyProcessor,
	pulseDistributor core.PulseDistributor,
	storage pulsarstorage.PulsarStorage,
	rpcWrapperFactory RPCClientWrapperFactory,
	entropyGenerator entropygenerator.EntropyGenerator,
	stateSwitcher StateSwitcher,
	listener func(string, string) (net.Listener, error)) (*Pulsar, error)

NewPulsar creates a new pulse with using of custom GeneratedEntropy Generator

func (*Pulsar) AddItemToVector added in v0.7.5

func (currentPulsar *Pulsar) AddItemToVector(pubKey string, cell *BftCell)

func (*Pulsar) CheckConnectionsToPulsars added in v0.5.0

func (currentPulsar *Pulsar) CheckConnectionsToPulsars(ctx context.Context)

CheckConnectionsToPulsars is a method refreshing connections between pulsars

func (*Pulsar) ClearVector added in v0.7.5

func (currentPulsar *Pulsar) ClearVector()

func (*Pulsar) CreateVectorCopy added in v0.7.5

func (currentPulsar *Pulsar) CreateVectorCopy() map[string]*BftCell

func (*Pulsar) EstablishConnectionToPulsar added in v0.5.0

func (currentPulsar *Pulsar) EstablishConnectionToPulsar(ctx context.Context, 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) GetCurrentSlotEntropy added in v0.6.3

func (currentPulsar *Pulsar) GetCurrentSlotEntropy() *core.Entropy

GetCurrentSlotEntropy returns currentSlotEntropy in the thread-safe mode

func (*Pulsar) GetGeneratedEntropy added in v0.6.3

func (currentPulsar *Pulsar) GetGeneratedEntropy() *core.Entropy

GetGeneratedEntropy returns generatedEntropy in the thread-safe mode

func (*Pulsar) GetItemFromVector added in v0.7.5

func (currentPulsar *Pulsar) GetItemFromVector(pubKey string) (*BftCell, bool)

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) SetCurrentSlotEntropy added in v0.6.3

func (currentPulsar *Pulsar) SetCurrentSlotEntropy(currentSlotEntropy *core.Entropy)

SetCurrentSlotEntropy sets currentSlotEntropy in the thread-safe mode

func (*Pulsar) SetGeneratedEntropy added in v0.6.3

func (currentPulsar *Pulsar) SetGeneratedEntropy(currentSlotEntropy *core.Entropy)

SetGeneratedEntropy sets generatedEntropy in the thread-safe mode

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(ctx context.Context, pulseNumber core.PulseNumber) error

StartConsensusProcess starts process of calculating consensus between pulsars

func (*Pulsar) StartServer added in v0.4.0

func (currentPulsar *Pulsar) StartServer(ctx context.Context)

StartServer starts listening of the rpc-server

func (*Pulsar) StopServer added in v0.4.0

func (currentPulsar *Pulsar) StopServer(ctx context.Context)

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

func (*PulsePayload) Hash added in v0.7.5

func (pp *PulsePayload) Hash(hashProvider core.Hasher) ([]byte, error)

Hash calculates hash of payload

type PulseSenderConfirmationPayload added in v0.7.5

type PulseSenderConfirmationPayload struct {
	core.PulseSenderConfirmation
}

PulseSenderConfirmationPayload is a struct with info about pulse's confirmations

func (*PulseSenderConfirmationPayload) Hash added in v0.7.5

func (ps *PulseSenderConfirmationPayload) Hash(hashProvider core.Hasher) ([]byte, error)

Hash calculates hash of payload

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 means that current iteration is broken
	Failed State = iota

	// WaitingForStart means that state machine is waiting for the start
	WaitingForStart

	// GenerateEntropy means that state machine is generating entropy for a current slot
	GenerateEntropy

	// WaitingForEntropySigns means that state machine is waiting for other pulsars' signs of entropy
	WaitingForEntropySigns

	// SendingEntropy means that state machine is sending entropy to other pulsars
	SendingEntropy

	// WaitingForEntropy means that state machine is waiting for the entropy for other pulsars
	WaitingForEntropy

	// SendingVector means that state machine is sending verctor to other pulsars
	SendingVector

	// WaitingForVectors means that state machine is waiting for other pulsars' vectors
	WaitingForVectors

	// Verifying means that state machine is verifying bft-table
	Verifying

	// SendingPulseSign means that state machine is sending sign to chosen pulsar
	SendingPulseSign

	// WaitingForPulseSigns means that state machine is waiting for signs to chosen pulsar
	WaitingForPulseSigns

	// SendingPulseSign means that state machine is sending pulse to network
	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(ctx context.Context, 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(ctx context.Context, state State, args interface{})

SwitchToState switches the state-machine to another step

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

func (*VectorPayload) Hash added in v0.7.5

func (vp *VectorPayload) Hash(hashProvider core.Hasher) ([]byte, error)

Hash calculates hash of payload

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