network

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2019 License: Apache-2.0, BSD-3-Clause-Clear Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BootstrapResult added in v0.8.0

type BootstrapResult struct {
	Host *host.Host
	// FirstPulseTime    time.Time
	ReconnectRequired bool
}

type ClaimQueue added in v0.6.3

type ClaimQueue interface {
	// Pop takes claim from the queue.
	Pop() consensus.ReferendumClaim
	// Front returns claim from the queue without removing it from the queue.
	Front() consensus.ReferendumClaim
	// Length returns the length of the queue
	Length() int
}

ClaimQueue is the queue that contains consensus claims.

type ConsensusNetwork added in v0.6.3

type ConsensusNetwork interface {
	component.Starter
	component.Stopper
	// PublicAddress returns public address that can be published for all nodes.
	PublicAddress() string
	// GetNodeID get current node ID.
	GetNodeID() core.RecordRef

	// SignAndSendPacket send request to a remote node.
	SignAndSendPacket(packet consensus.ConsensusPacket, receiver core.RecordRef, service core.CryptographyService) error
	// RegisterPacketHandler register a handler function to process incoming requests of a specific type.
	RegisterPacketHandler(t consensus.PacketType, handler ConsensusPacketHandler)
}

type ConsensusPacketHandler added in v0.8.0

type ConsensusPacketHandler func(incomingPacket consensus.ConsensusPacket, sender core.RecordRef)

type Controller

type Controller interface {
	component.Initer
	// SendParcel send message to nodeID.
	SendMessage(nodeID core.RecordRef, name string, msg core.Parcel) ([]byte, error)
	// RemoteProcedureRegister register remote procedure that will be executed when message is received.
	RemoteProcedureRegister(name string, method core.RemoteProcedure)
	// SendCascadeMessage sends a message from MessageBus to a cascade of nodes.
	SendCascadeMessage(data core.Cascade, method string, msg core.Parcel) error
	// Bootstrap init complex bootstrap process. Blocks until bootstrap is complete.
	Bootstrap(ctx context.Context) (*BootstrapResult, error)

	// SetLastIgnoredPulse set pulse number after which we will begin setting new pulses to PulseManager
	SetLastIgnoredPulse(number core.PulseNumber)
	// GetLastIgnoredPulse get last pulse that will be ignored
	GetLastIgnoredPulse() core.PulseNumber
}

Controller contains network logic.

type Future

type Future interface {
	GetRequest() Request
	Response() <-chan Response
	GetResponse(duration time.Duration) (Response, error)
}

Future allows to handle responses to a previously sent request.

type HostNetwork

type HostNetwork interface {
	// Start listening to network requests.
	Start(ctx context.Context)
	// Stop listening to network requests.
	Stop()
	// PublicAddress returns public address that can be published for all nodes.
	PublicAddress() string
	// GetNodeID get current node ID.
	GetNodeID() core.RecordRef

	// SendRequest send request to a remote node.
	SendRequest(ctx context.Context, request Request, receiver core.RecordRef) (Future, error)
	// RegisterRequestHandler register a handler function to process incoming requests of a specific type.
	RegisterRequestHandler(t types.PacketType, handler RequestHandler)
	// NewRequestBuilder create packet builder for an outgoing request with sender set to current node.
	NewRequestBuilder() RequestBuilder
	// BuildResponse create response to an incoming request with Data set to responseData.
	BuildResponse(ctx context.Context, request Request, responseData interface{}) Response
}

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

type InternalTransport added in v0.6.3

type InternalTransport interface {
	// Start listening to network requests, should be started in goroutine.
	Start(ctx context.Context)
	// Stop listening to network requests.
	Stop()
	// PublicAddress returns public address that can be published for all nodes.
	PublicAddress() string
	// GetNodeID get current node ID.
	GetNodeID() core.RecordRef

	// SendRequestPacket send request packet to a remote node.
	SendRequestPacket(ctx context.Context, request Request, receiver *host.Host) (Future, error)
	// RegisterPacketHandler register a handler function to process incoming requests of a specific type.
	RegisterPacketHandler(t types.PacketType, handler RequestHandler)
	// NewRequestBuilder create packet builder for an outgoing request with sender set to current node.
	NewRequestBuilder() RequestBuilder
	// BuildResponse create response to an incoming request with Data set to responseData.
	BuildResponse(ctx context.Context, request Request, responseData interface{}) Response
}

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

type MergedListCopy added in v0.8.0

type MergedListCopy struct {
	ActiveList                 map[core.RecordRef]core.Node
	NodesJoinedDuringPrevPulse bool
}

type NodeKeeper

type NodeKeeper interface {
	core.NodeNetwork

	// TODO: remove this interface when bootstrap mechanism completed
	core.SwitcherWorkAround

	// GetCloudHash returns current cloud hash
	GetCloudHash() []byte
	// SetCloudHash set new cloud hash
	SetCloudHash([]byte)
	// GetActiveNode returns active node.
	GetActiveNode(ref core.RecordRef) core.Node
	// AddActiveNodes add active nodes.
	AddActiveNodes([]core.Node)
	// GetActiveNodes returns active nodes.
	GetActiveNodes() []core.Node
	// GetActiveNodeByShortID get active node by short ID. Returns nil if node is not found.
	GetActiveNodeByShortID(shortID core.ShortNodeID) core.Node
	// SetState set state of the NodeKeeper
	SetState(core.NodeNetworkState)
	// GetOriginJoinClaim get origin NodeJoinClaim
	GetOriginJoinClaim() (*consensus.NodeJoinClaim, error)
	// GetOriginAnnounceClaim get origin NodeAnnounceClaim
	GetOriginAnnounceClaim(mapper consensus.BitSetMapper) (*consensus.NodeAnnounceClaim, error)
	// NodesJoinedDuringPreviousPulse returns true if the last Sync call contained approved Join claims
	NodesJoinedDuringPreviousPulse() bool
	// AddPendingClaim add pending claim to the internal queue of claims
	AddPendingClaim(consensus.ReferendumClaim) bool
	// GetClaimQueue get the internal queue of claims
	GetClaimQueue() ClaimQueue
	// GetUnsyncList get unsync list for current pulse. Has copy of active node list from nodekeeper as internal state.
	// Should be called when nodekeeper state is ReadyNodeNetworkState.
	GetUnsyncList() UnsyncList
	// GetSparseUnsyncList get sparse unsync list for current pulse with predefined length of active node list.
	// Does not contain active list, should collect active list during its lifetime via AddClaims.
	// Should be called when nodekeeper state is WaitingNodeNetworkState.
	GetSparseUnsyncList(length int) UnsyncList
	// Sync move unsync -> sync
	Sync(list UnsyncList)
	// MoveSyncToActive merge sync list with active nodes
	MoveSyncToActive(ctx context.Context) error
	// AddTemporaryMapping add temporary mapping till the next pulse for consensus
	AddTemporaryMapping(nodeID core.RecordRef, shortID core.ShortNodeID, address string) error
	// ResolveConsensus get temporary mapping by short ID
	ResolveConsensus(shortID core.ShortNodeID) *host.Host
	// ResolveConsensusRef get temporary mapping by node ID
	ResolveConsensusRef(nodeID core.RecordRef) *host.Host
}

NodeKeeper manages unsync, sync and active lists.

type Packet

type Packet interface {
	GetSender() core.RecordRef
	GetSenderHost() *host.Host
	GetType() types.PacketType
	GetData() interface{}
	GetRequestID() RequestID
}

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

type PartitionPolicy added in v0.6.3

type PartitionPolicy interface {
	ShardsCount() int
}

PartitionPolicy contains all rules how to initiate globule resharding.

type PulseHandler added in v0.6.3

type PulseHandler interface {
	HandlePulse(ctx context.Context, pulse core.Pulse)
}

PulseHandler interface to process new pulse.

type Request

type Request Packet

Request is a packet that is sent from the current node.

type RequestBuilder

type RequestBuilder interface {
	Type(packetType types.PacketType) RequestBuilder
	Data(data interface{}) RequestBuilder
	Build() Request
}

RequestBuilder allows to build a Request.

type RequestHandler

type RequestHandler func(context.Context, Request) (Response, error)

RequestHandler handler function to process incoming requests from network.

type RequestID added in v0.7.5

type RequestID uint64

RequestID is 64 bit unsigned int request id.

type Response

type Response Packet

Response is a packet that is received in response to a previously sent Request.

type RoutingTable added in v0.6.3

type RoutingTable interface {
	// Inject inject dependencies from components
	Inject(nodeKeeper NodeKeeper)
	// Resolve NodeID -> ShortID, Address. Can initiate network requests.
	Resolve(core.RecordRef) (*host.Host, error)
	// ResolveConsensus ShortID -> NodeID, Address for node inside current globe for current consensus.
	ResolveConsensus(core.ShortNodeID) (*host.Host, error)
	// ResolveConsensusRef NodeID -> ShortID, Address for node inside current globe for current consensus.
	ResolveConsensusRef(core.RecordRef) (*host.Host, error)
	// AddToKnownHosts add host to routing table.
	AddToKnownHosts(*host.Host)
	// Rebalance recreate shards of routing table with known hosts according to new partition policy.
	Rebalance(PartitionPolicy)
	// GetRandomNodes get a specified number of random nodes. Returns less if there are not enough nodes in network.
	GetRandomNodes(count int) []host.Host
}

RoutingTable contains all routing information of the network.

type UnsyncList

type UnsyncList interface {
	consensus.BitSetMapper
	// ApproveSync
	ApproveSync([]core.RecordRef)
	// AddClaims
	AddClaims(map[core.RecordRef][]consensus.ReferendumClaim) error
	// AddNode
	AddNode(node core.Node, bitsetIndex uint16)
	// GetClaims
	GetClaims(nodeID core.RecordRef) []consensus.ReferendumClaim
	// AddProof
	AddProof(nodeID core.RecordRef, proof *consensus.NodePulseProof)
	// GetProof
	GetProof(nodeID core.RecordRef) *consensus.NodePulseProof
	// GetGlobuleHashSignature
	GetGlobuleHashSignature(ref core.RecordRef) (consensus.GlobuleHashSignature, bool)
	// SetGlobuleHashSignature
	SetGlobuleHashSignature(core.RecordRef, consensus.GlobuleHashSignature)
	// CalculateHash calculate node list hash based on active node list and claims
	CalculateHash(core.PlatformCryptographyScheme) ([]byte, error)
	// GetActiveNode get active node by reference ID for current consensus
	GetActiveNode(ref core.RecordRef) core.Node
	// GetActiveNodes get active nodes for current consensus
	GetActiveNodes() []core.Node
	// GetMergedCopy returns copy of unsyncList with claims applied
	GetMergedCopy() (*MergedListCopy, error)
	//
	RemoveNode(nodeID core.RecordRef)
}

UnsyncList is interface to manage unsync list

Directories

Path Synopsis
Package transport provides network transport interface.
Package transport provides network transport interface.
host
Package host is a fundamental part of networking system.
Package host is a fundamental part of networking system.
packet
Package packet provides network messaging protocol and serialization layer.
Package packet provides network messaging protocol and serialization layer.
relay
Package relay is an implementation of relay mechanism.
Package relay is an implementation of relay mechanism.
resolver
Package resolver provides interface (and default implementation) to retrieve public network address.
Package resolver provides interface (and default implementation) to retrieve public network address.

Jump to

Keyboard shortcuts

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