channel

package
v0.0.0-...-ff61ee7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

This package contains the core network sending and receiving functionalities, see subpackage csnet for TCP and UDP implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbsMainChannel

type AbsMainChannel struct {
	NumMsgProcessThreads int                                    // number of threads for processing messages
	MyConInfo            channelinterface.NetNodeInfo           // Connection info of the local node
	InternalChan         chan *channelinterface.RcvMsg          // Used to send messages from the receiving threads to the main consensus thread in Recv
	CloseChannel         chan channelinterface.ChannelCloseType // Used to perform shutdown
	Proposal             []*deserialized.DeserializedItem       // The proposal for the next consensus instance, should be nil once processes by the current instance
	SelfMessages         *[]*messages.Message                   // List of messages sent by the local node to itself, pending to be processed
	IsInInit             bool                                   // While true system is recovering, and messages should not be sent
	ConsItem             consinterface.ConsItem                 // The consensus state
	MemberCheckerState   consinterface.ConsStateInterface       // Tracking which public keys are valid for what consensus instance
	BehaviorTracker      channelinterface.BehaviorTracker       // Tracking the bad behavior of the connections
	Ticker               *time.Ticker                           // Ticker will tick at generalconfig.Timeoutrecvms, waking up the main consensus thread to be sure some action is eventually taken even when no messages are received
	Stats                stats.NwStatsInterface                 // Tracks network statistics

	// rand *rand.Rand
	ReprocessCount int32    // Tracks the number of messages that failed inital deserialization becase the system state was not ready (likely from a future consensus instance), and are being reprocessed in a seperate go routine
	DoneLoop       chan int // Used to indicate when we have exited the main loop

	SelfMsgCount int32 // used atomically by threads keeping track of the number of self messages
	// contains filtered or unexported fields
}

AbsMainChannel partially implements channelinterface.MainChannel it implements the methods that are network type agnostic

func (*AbsMainChannel) EndInit

func (tp *AbsMainChannel) EndInit()

EndInit is called once recovery is finished

func (*AbsMainChannel) GetBehaviorTracker

func (tp *AbsMainChannel) GetBehaviorTracker() channelinterface.BehaviorTracker

GetBehaviorTracker returns the BehaviorTracker object

func (*AbsMainChannel) GetStats

func (tp *AbsMainChannel) GetStats() stats.NwStatsInterface

GetStats returns the nw stats object

func (*AbsMainChannel) HasProposal

func (tp *AbsMainChannel) HasProposal(msg *deserialized.DeserializedItem)

HasProposal should be called by the state machine when it is ready with its proposal for the next round of consensus. It should be called after ProposalInfo object interface (package consinterface) method HasDecided had been called for the previous consensus instance.

func (*AbsMainChannel) Init

func (tp *AbsMainChannel) Init(myConInfo channelinterface.NetNodeInfo, consItem consinterface.ConsItem,
	bt channelinterface.BehaviorTracker, msgDropPercent int, numMsgProcessThreads int,
	stats stats.NwStatsInterface)

Init is called to initalize the state of the AbsMainChannelObject

func (*AbsMainChannel) InitInProgress

func (tp *AbsMainChannel) InitInProgress() bool

func (*AbsMainChannel) ProcessMessage

func (tp *AbsMainChannel) ProcessMessage(msg *messages.Message, wasEncrypted bool, encrypter sig.Pub,
	sndRcvChan *channelinterface.SendRecvChannel) (bool, []error)

ProcessMessage is called each time a message has been received from the network, sndRcvChan is the channel that the message was recieved from or nil It tries to deserialze the message then send it to the consensus state If deserialzation fails because it is from a future consensus instance then the message will be placed in the to-be-reprocesses queue The return values are currently unused

func (*AbsMainChannel) Recv

Recv should be called as the main consensus loop every time the node is ready to process a message. It is expected to be called one at a time (not concurrent safe). It will return utils.ErrTimeout after a timeout to ensure progress.

func (*AbsMainChannel) ReprocessMessage

func (tp *AbsMainChannel) ReprocessMessage(rcvMsg *channelinterface.RcvMsg)

Reprocess is called on messages that were unable to be deserialized upon first reception, it is safe to be called by many threads

func (*AbsMainChannel) ReprocessMessageBytes

func (tp *AbsMainChannel) ReprocessMessageBytes(msg []byte)

ReprocessMessageBytes is called on messages that have already been received and need to be reprocesses. It is safe to be called by many threads.

func (*AbsMainChannel) SendToSelf

SendToSelf sends a deserialzed message to the current processes after a timeout, it returns the timer or nil if timeout <= 0, this method is concurrent safe.

func (*AbsMainChannel) SendToSelfInternal

func (tp *AbsMainChannel) SendToSelfInternal(buff []byte)

SendToSelf internal can be called by the main thread (usually from within the Send function) to send a serialized message to the local node, it is not concurrent safe

func (*AbsMainChannel) SetMemberCheckerState

func (tp *AbsMainChannel) SetMemberCheckerState(memberCheckerState consinterface.ConsStateInterface)

func (*AbsMainChannel) StartInit

func (tp *AbsMainChannel) StartInit()

StartInit is called when the system is starting and is recovering from disk At this point any calls to Send/SendToSelf should not send any messages as the system is just replying events

type ChannelTimer

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

ChannelTimer is returned from SendToSelf. The process that creates the timer is responsible for stopping it before the test returns.

func (*ChannelTimer) Stop

func (ct *ChannelTimer) Stop() bool

Stop should be called when the timer is no longer needed.

type EncryptInterface

type EncryptInterface interface {
	FailedGetPub()
	GotPub(pubBytes []byte, randBytes []byte) error
	GetRandomBytes() (ret [24]byte)
	GetMyPubBytes() []byte
	WaitForPub() (err error)
	Decode(msg []byte, includeSize bool) ([]byte, error)
	GetExternalPub() sig.Pub
	Encode(msg []byte, includeSize bool) []byte
}

func GenerateEncrypter

func GenerateEncrypter(myPriv sig.Priv,
	shouldWaitForPub bool,
	externalPub sig.Pub) EncryptInterface

type Encrypter

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

func NewEcrypter

func NewEcrypter(myPriv sig.Priv,
	shouldWaitForPub bool,
	externalPub sig.Pub) *Encrypter

func (*Encrypter) Decode

func (enc *Encrypter) Decode(msg []byte, includeSize bool) ([]byte, error)

func (*Encrypter) Encode

func (enc *Encrypter) Encode(msg []byte, includeSize bool) []byte

func (*Encrypter) FailedGetPub

func (enc *Encrypter) FailedGetPub()

func (*Encrypter) GetExternalPub

func (enc *Encrypter) GetExternalPub() sig.Pub

func (*Encrypter) GetMyPubBytes

func (enc *Encrypter) GetMyPubBytes() []byte

func (*Encrypter) GetRandomBytes

func (enc *Encrypter) GetRandomBytes() [24]byte

func (*Encrypter) GotPub

func (enc *Encrypter) GotPub(pubBytes []byte, randBytes []byte) error

func (*Encrypter) WaitForPub

func (enc *Encrypter) WaitForPub() (err error)

type SleepEncrypter

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

func NewSleepEcrypter

func NewSleepEcrypter(myPriv sig.Priv,
	shouldWaitForPub bool,
	externalPub sig.Pub) *SleepEncrypter

func (*SleepEncrypter) Decode

func (enc *SleepEncrypter) Decode(msg []byte, includeSize bool) ([]byte, error)

func (*SleepEncrypter) Encode

func (enc *SleepEncrypter) Encode(msg []byte, includeSize bool) []byte

func (*SleepEncrypter) FailedGetPub

func (enc *SleepEncrypter) FailedGetPub()

func (*SleepEncrypter) GetExternalPub

func (enc *SleepEncrypter) GetExternalPub() sig.Pub

func (*SleepEncrypter) GetMyPubBytes

func (enc *SleepEncrypter) GetMyPubBytes() []byte

func (*SleepEncrypter) GetRandomBytes

func (enc *SleepEncrypter) GetRandomBytes() (ret [24]byte)

func (*SleepEncrypter) GotPub

func (enc *SleepEncrypter) GotPub(pubBytes []byte, randBytes []byte) error

func (*SleepEncrypter) WaitForPub

func (enc *SleepEncrypter) WaitForPub() (err error)

Directories

Path Synopsis
This package contains the code for maintining and using TCP and UDP networking for the consensus.
This package contains the code for maintining and using TCP and UDP networking for the consensus.

Jump to

Keyboard shortcuts

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