network

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConsensusPacketsSent consensus sent packets size.
	ConsensusPacketsSent = stats.Int64("consensus_packets_sent", "Consensus sent packets size", stats.UnitBytes)
	// ConsensusPacketsRecv consensus received packets size.
	ConsensusPacketsRecv = stats.Int64("consensus_packets_recv", "Consensus received packets size", stats.UnitBytes)
	// ConsensusPacketsRecvBad consensus received packets size.
	ConsensusPacketsRecvBad = stats.Int64("consensus_packets_recv_bad", "Consensus received packets size", stats.UnitBytes)

	// DeclinedClaims consensus claims declined counter.
	DeclinedClaims = stats.Int64("consensus_claims_declined", "Consensus claims declined counter", stats.UnitDimensionless)
	// FailedCheckProof consensus validate proof fails.
	FailedCheckProof = stats.Int64("consensus_proof_failed", "Consensus validate proof fails", stats.UnitDimensionless)
	// ActiveNodes active nodes count after consensus.
	ActiveNodes = stats.Int64("consensus_active_nodes_count", "Active nodes count after consensus", stats.UnitDimensionless)
)
View Source
var (
	// TagPhase is a tag for consensus metrics.
	TagPhase = insmetrics.MustTagKey("phase")
)

Functions

func CheckShortIDCollision

func CheckShortIDCollision(nodes []nodeinfo.NetworkNode, id node.ShortNodeID) bool

CheckShortIDCollision returns true if nodes contains node with such ShortID

func CloseVerbose

func CloseVerbose(closer io.Closer)

func ExcludeOrigin

func ExcludeOrigin(discoveryNodes []nodeinfo.DiscoveryNode, origin reference.Holder) []nodeinfo.DiscoveryNode

ExcludeOrigin returns DiscoveryNode slice without Origin

func FindDiscoveriesInNodeList

func FindDiscoveriesInNodeList(nodes []nodeinfo.NetworkNode, cert nodeinfo.Certificate) (result []nodeinfo.NetworkNode)

FindDiscoveriesInNodeList returns only discovery nodes from active node list

func FindDiscoveryByRef

func FindDiscoveryByRef(cert nodeinfo.Certificate, ref reference.Holder) nodeinfo.DiscoveryNode

FindDiscoveryByRef tries to find discovery node in Certificate by reference

func IsClosedPipe

func IsClosedPipe(err error) bool

func IsConnectionClosed

func IsConnectionClosed(err error) bool

IsConnectionClosed checks err for connection closed, workaround for poll.ErrNetClosing https://github.com/golang/go/issues/4373

func IsDiscovery

func IsDiscovery(nodeID reference.Holder, cert nodeinfo.Certificate) bool

func IsJoinAssistant

func IsJoinAssistant(nodeID reference.Global, cert nodeinfo.Certificate) bool

func JoinAssistant

func JoinAssistant(cert nodeinfo.Certificate) nodeinfo.DiscoveryNode

func NewPulseContext

func NewPulseContext(ctx context.Context, pulseNumber uint32) context.Context

func OriginIsDiscovery

func OriginIsDiscovery(cert nodeinfo.Certificate) bool

func OriginIsJoinAssistant

func OriginIsJoinAssistant(cert nodeinfo.Certificate) bool

Types

type Aborter

type Aborter interface {
	// Abort forces to stop all node components
	Abort(ctx context.Context, reason string)
}

Aborter provide method for immediately stop node

type AborterMock

type AborterMock struct {
	AbortMock mAborterMockAbort
	// contains filtered or unexported fields
}

AborterMock implements Aborter

func NewAborterMock

func NewAborterMock(t minimock.Tester) *AborterMock

NewAborterMock returns a mock for Aborter

func (*AborterMock) Abort

func (mmAbort *AborterMock) Abort(ctx context.Context, reason string)

Abort implements Aborter

func (*AborterMock) AbortAfterCounter

func (mmAbort *AborterMock) AbortAfterCounter() uint64

AbortAfterCounter returns a count of finished AborterMock.Abort invocations

func (*AborterMock) AbortBeforeCounter

func (mmAbort *AborterMock) AbortBeforeCounter() uint64

AbortBeforeCounter returns a count of AborterMock.Abort invocations

func (*AborterMock) MinimockAbortDone

func (m *AborterMock) MinimockAbortDone() bool

MinimockAbortDone returns true if the count of the Abort invocations corresponds the number of defined expectations

func (*AborterMock) MinimockAbortInspect

func (m *AborterMock) MinimockAbortInspect()

MinimockAbortInspect logs each unmet expectation

func (*AborterMock) MinimockFinish

func (m *AborterMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*AborterMock) MinimockWait

func (m *AborterMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

type AborterMockAbortExpectation

type AborterMockAbortExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

AborterMockAbortExpectation specifies expectation struct of the Aborter.Abort

type AborterMockAbortParams

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

AborterMockAbortParams contains parameters of the Aborter.Abort

type Auther

type Auther interface {
	// GetCert returns certificate object by node reference, using discovery nodes for signing
	GetCert(context.Context, reference.Global) (nodeinfo.Certificate, error)
	// ValidateCert checks certificate signature
	// TODO make this cert.validate()
	ValidateCert(context.Context, nodeinfo.AuthorizationCertificate) (bool, error)
}

type BootstrapResult

type BootstrapResult struct {
	Host *legacyhost.Host
	// FirstPulseTime    time.Time
	ReconnectRequired bool
	NetworkSize       int
}

type Bootstrapper

type Bootstrapper interface {
	HandleNodeAuthorizeRequest(context.Context, Packet) (Packet, error)
	HandleNodeBootstrapRequest(context.Context, Packet) (Packet, error)
	HandleUpdateSchedule(context.Context, Packet) (Packet, error)
	HandleReconnect(context.Context, Packet) (Packet, error)
}

Bootstrapper interface used to change behavior of handlers in different network states

type CapturingReader

type CapturingReader struct {
	io.Reader
	// contains filtered or unexported fields
}

func NewCapturingReader

func NewCapturingReader(reader io.Reader) *CapturingReader

func (*CapturingReader) Captured

func (r *CapturingReader) Captured() []byte

func (*CapturingReader) Read

func (r *CapturingReader) Read(p []byte) (int, error)

type Future

type Future interface {
	Request() Packet
	Response() <-chan ReceivedPacket
	WaitResponse(duration time.Duration) (ReceivedPacket, error)
	Cancel()
}

Future allows to handle responses to a previously sent request.

type Gateway

type Gateway interface {
	NewGateway(context.Context, State) Gateway

	Run(context.Context, pulse.Data)

	GetState() State

	OnPulseFromConsensus(context.Context, NetworkedPulse)
	OnConsensusFinished(context.Context, Report)

	UpdateState(context.Context, beat.Beat)

	RequestNodeState(chorus.NodeStateFunc)
	CancelNodeState()

	Auther() Auther
	Bootstrapper() Bootstrapper

	EphemeralMode(census.OnlinePopulation) bool

	FailState(ctx context.Context, reason string)
}

Gateway responds for whole network state

type Gatewayer

type Gatewayer interface {
	Gateway() Gateway
	SwitchState(context.Context, State, pulse.Data)
}

Gatewayer is a network which can change it's Gateway

type HostNetwork

type HostNetwork interface {
	component.Starter
	component.Stopper

	// PublicAddress returns public address that can be published for all nodes.
	PublicAddress() string

	// SendRequest send request to a remote node addressed by reference.
	SendRequest(ctx context.Context, t types.PacketType, requestData interface{}, receiver reference.Global) (Future, error)
	// SendRequestToHost send request packet to a remote host.
	SendRequestToHost(ctx context.Context, t types.PacketType, requestData interface{}, receiver *legacyhost.Host) (Future, error)
	// RegisterRequestHandler register a handler function to process incoming requests of a specific type.
	// All RegisterRequestHandler calls should be executed before Start.
	RegisterRequestHandler(t types.PacketType, handler RequestHandler)
	// BuildResponse create response to an incoming request with Data set to responseData.
	BuildResponse(ctx context.Context, request Packet, responseData interface{}) Packet
}

HostNetwork simple interface to send network requests and process network responses.

type NetworkedPulse

type NetworkedPulse = beat.Beat

type OnConsensusFinished

type OnConsensusFinished func(ctx context.Context, report Report)

type Options

type Options struct {
	// The maximum time to wait for a response to any packet.
	PacketTimeout time.Duration

	// The maximum time to wait for a response to ack packet.
	AckPacketTimeout time.Duration

	// Bootstrap ETA for join the Insolar network
	BootstrapTimeout time.Duration

	// Min bootstrap retry timeout
	MinTimeout time.Duration

	// Max bootstrap retry timeout
	MaxTimeout time.Duration

	// Multiplier for boostrap retry time
	TimeoutMult time.Duration

	// The maximum time to wait for a new pulse
	PulseWatchdogTimeout time.Duration
}

Options contains configuration options for the local host.

func ConfigureOptions

func ConfigureOptions(conf configuration.Configuration) *Options

ConfigureOptions convert daemon configuration to controller options

type Packet

type Packet interface {
	GetSender() reference.Global
	GetSenderHost() *legacyhost.Host
	GetType() types.PacketType
	GetRequest() *rms.Request
	GetResponse() *rms.Response
	GetRequestID() types.RequestID
	String() string
}

Packet is a packet that is transported via network by HostNetwork.

type ReceivedPacket

type ReceivedPacket interface {
	Packet
	Bytes() []byte
}

type Report

type Report struct {
	PulseData       pulse.Data
	PulseNumber     pulse.Number
	MemberPower     member.Power
	MemberMode      member.OpMode
	IsJoiner        bool
	PopulationValid bool
}

type RequestHandler

type RequestHandler func(ctx context.Context, request ReceivedPacket) (response Packet, err error)

RequestHandler handler function to process incoming requests from network and return responses to these requests.

type RoutingTable

type RoutingTable interface {
	// Resolve NodeID -> ShortID, Address. Can initiate network requests.
	Resolve(reference.Global) (*legacyhost.Host, error)
}

RoutingTable contains all routing information of the network.

type State

type State int

State type for bootstrapping process

const (
	// NoNetworkState state means that nodes doesn`t match majority_rule
	NoNetworkState State = iota
	JoinerBootstrap
	DiscoveryBootstrap
	WaitConsensus
	WaitMajority
	WaitMinRoles
	WaitPulsar
	CompleteNetworkState
)

func (State) String

func (i State) String() string

type Status

type Status interface {
	GetNetworkStatus() StatusReply
}

type StatusReply

type StatusReply struct {
	NetworkState    State
	LocalRef        reference.Holder
	LocalRole       member.PrimaryRole
	LocalNode       nodeinfo.NetworkNode
	ActiveListSize  int
	WorkingListSize int
	// Nodes from active list
	Nodes     []nodeinfo.NetworkNode
	Version   string
	Timestamp time.Time
	// node start timestamp for uptime duration
	StartTime time.Time

	PulseNumber pulse.Number
}

type TerminationHandler

type TerminationHandler interface {
	// Leave locks until network accept leaving claim
	Leave(context.Context, pulse.Number)
	OnLeaveApproved(context.Context)
	// Terminating is an accessor
	Terminating() bool
}

TerminationHandler handles such node events as graceful stop, abort, etc.

type TerminationHandlerMock

type TerminationHandlerMock struct {
	LeaveMock mTerminationHandlerMockLeave

	OnLeaveApprovedMock mTerminationHandlerMockOnLeaveApproved

	TerminatingMock mTerminationHandlerMockTerminating
	// contains filtered or unexported fields
}

TerminationHandlerMock implements TerminationHandler

func NewTerminationHandlerMock

func NewTerminationHandlerMock(t minimock.Tester) *TerminationHandlerMock

NewTerminationHandlerMock returns a mock for TerminationHandler

func (*TerminationHandlerMock) Leave

func (mmLeave *TerminationHandlerMock) Leave(ctx context.Context, n1 pulse.Number)

Leave implements TerminationHandler

func (*TerminationHandlerMock) LeaveAfterCounter

func (mmLeave *TerminationHandlerMock) LeaveAfterCounter() uint64

LeaveAfterCounter returns a count of finished TerminationHandlerMock.Leave invocations

func (*TerminationHandlerMock) LeaveBeforeCounter

func (mmLeave *TerminationHandlerMock) LeaveBeforeCounter() uint64

LeaveBeforeCounter returns a count of TerminationHandlerMock.Leave invocations

func (*TerminationHandlerMock) MinimockFinish

func (m *TerminationHandlerMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*TerminationHandlerMock) MinimockLeaveDone

func (m *TerminationHandlerMock) MinimockLeaveDone() bool

MinimockLeaveDone returns true if the count of the Leave invocations corresponds the number of defined expectations

func (*TerminationHandlerMock) MinimockLeaveInspect

func (m *TerminationHandlerMock) MinimockLeaveInspect()

MinimockLeaveInspect logs each unmet expectation

func (*TerminationHandlerMock) MinimockOnLeaveApprovedDone

func (m *TerminationHandlerMock) MinimockOnLeaveApprovedDone() bool

MinimockOnLeaveApprovedDone returns true if the count of the OnLeaveApproved invocations corresponds the number of defined expectations

func (*TerminationHandlerMock) MinimockOnLeaveApprovedInspect

func (m *TerminationHandlerMock) MinimockOnLeaveApprovedInspect()

MinimockOnLeaveApprovedInspect logs each unmet expectation

func (*TerminationHandlerMock) MinimockTerminatingDone

func (m *TerminationHandlerMock) MinimockTerminatingDone() bool

MinimockTerminatingDone returns true if the count of the Terminating invocations corresponds the number of defined expectations

func (*TerminationHandlerMock) MinimockTerminatingInspect

func (m *TerminationHandlerMock) MinimockTerminatingInspect()

MinimockTerminatingInspect logs each unmet expectation

func (*TerminationHandlerMock) MinimockWait

func (m *TerminationHandlerMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*TerminationHandlerMock) OnLeaveApproved

func (mmOnLeaveApproved *TerminationHandlerMock) OnLeaveApproved(ctx context.Context)

OnLeaveApproved implements TerminationHandler

func (*TerminationHandlerMock) OnLeaveApprovedAfterCounter

func (mmOnLeaveApproved *TerminationHandlerMock) OnLeaveApprovedAfterCounter() uint64

OnLeaveApprovedAfterCounter returns a count of finished TerminationHandlerMock.OnLeaveApproved invocations

func (*TerminationHandlerMock) OnLeaveApprovedBeforeCounter

func (mmOnLeaveApproved *TerminationHandlerMock) OnLeaveApprovedBeforeCounter() uint64

OnLeaveApprovedBeforeCounter returns a count of TerminationHandlerMock.OnLeaveApproved invocations

func (*TerminationHandlerMock) Terminating

func (mmTerminating *TerminationHandlerMock) Terminating() (b1 bool)

Terminating implements TerminationHandler

func (*TerminationHandlerMock) TerminatingAfterCounter

func (mmTerminating *TerminationHandlerMock) TerminatingAfterCounter() uint64

TerminatingAfterCounter returns a count of finished TerminationHandlerMock.Terminating invocations

func (*TerminationHandlerMock) TerminatingBeforeCounter

func (mmTerminating *TerminationHandlerMock) TerminatingBeforeCounter() uint64

TerminatingBeforeCounter returns a count of TerminationHandlerMock.Terminating invocations

type TerminationHandlerMockLeaveExpectation

type TerminationHandlerMockLeaveExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

TerminationHandlerMockLeaveExpectation specifies expectation struct of the TerminationHandler.Leave

type TerminationHandlerMockLeaveParams

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

TerminationHandlerMockLeaveParams contains parameters of the TerminationHandler.Leave

type TerminationHandlerMockOnLeaveApprovedExpectation

type TerminationHandlerMockOnLeaveApprovedExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

TerminationHandlerMockOnLeaveApprovedExpectation specifies expectation struct of the TerminationHandler.OnLeaveApproved

type TerminationHandlerMockOnLeaveApprovedParams

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

TerminationHandlerMockOnLeaveApprovedParams contains parameters of the TerminationHandler.OnLeaveApproved

type TerminationHandlerMockTerminatingExpectation

type TerminationHandlerMockTerminatingExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

TerminationHandlerMockTerminatingExpectation specifies expectation struct of the TerminationHandler.Terminating

type TerminationHandlerMockTerminatingResults

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

TerminationHandlerMockTerminatingResults contains results of the TerminationHandler.Terminating

Jump to

Keyboard shortcuts

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