gpa

package
v0.7.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

package gpa stands for generic pure (distributed) algorithm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AckHandler

type AckHandler interface {
	GPA
	DismissPeer(peerID NodeID) // To avoid resending messages to dead peers.
	MakeTickInput(time.Time) Input
	NestedMessage(msg Message) OutMessages
	NestedCall(c func(GPA) OutMessages) OutMessages
}

func NewAckHandler

func NewAckHandler(me NodeID, nested GPA, resendPeriod time.Duration) AckHandler

type BasicMessage added in v1.0.3

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

func NewBasicMessage added in v1.0.3

func NewBasicMessage(recipient NodeID) BasicMessage

func (*BasicMessage) Recipient added in v1.0.3

func (msg *BasicMessage) Recipient() NodeID

func (*BasicMessage) Sender added in v1.0.3

func (msg *BasicMessage) Sender() NodeID

func (*BasicMessage) SetSender added in v1.0.3

func (msg *BasicMessage) SetSender(sender NodeID)

type Fallback added in v1.0.3

type Fallback map[MessageType]func(data []byte) (Message, error)

type GPA

type GPA interface {
	Input(inp Input) OutMessages     // Can return nil for NoMessages.
	Message(msg Message) OutMessages // Can return nil for NoMessages.
	Output() Output
	StatusString() string // Status of the protocol as a string.
	UnmarshalMessage(data []byte) (Message, error)
}

Generic interface for functional style distributed algorithms. GPA stands for Generic Pure Algorithm.

func MakeTestSilentNode

func MakeTestSilentNode() GPA

func NewOwnHandler

func NewOwnHandler(me NodeID, target GPA) GPA

func NewOwnHandlerWithOutPredicate added in v1.0.3

func NewOwnHandlerWithOutPredicate(me NodeID, target GPA, outPredicate func(Message) bool) GPA

func NewTestRound

func NewTestRound(nodeIDs []NodeID, me NodeID) GPA

type Input

type Input interface{}

type Mapper added in v1.0.3

type Mapper map[MessageType]func() Message

type Message

type Message interface {
	Read(r io.Reader) error
	Write(w io.Writer) error
	Recipient() NodeID // The sender should indicate the recipient.
	SetSender(NodeID)  // The transport later will set a validated sender for a message.
}

func UnmarshalMessage added in v1.0.3

func UnmarshalMessage(data []byte, mapper Mapper, fallback ...Fallback) (Message, error)

type MessageType added in v1.0.3

type MessageType rwutil.Kind

func (*MessageType) Read added in v1.0.3

func (m *MessageType) Read(rr *rwutil.Reader)

func (MessageType) ReadAndVerify added in v1.0.3

func (m MessageType) ReadAndVerify(rr *rwutil.Reader)

func (MessageType) Write added in v1.0.3

func (m MessageType) Write(ww *rwutil.Writer)

type MsgWrapper

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

MsgWrapper can be used to compose an algorithm out of other abstractions. These messages are meant to wrap and route the messages of the sub-algorithms.

func NewMsgWrapper

func NewMsgWrapper(msgType MessageType, subsystemFunc func(subsystem byte, index int) (GPA, error)) *MsgWrapper

func (*MsgWrapper) DelegateInput added in v1.0.3

func (w *MsgWrapper) DelegateInput(subsystem byte, index int, input Input) (GPA, OutMessages, error)

func (*MsgWrapper) DelegateMessage added in v1.0.3

func (w *MsgWrapper) DelegateMessage(msg *WrappingMsg) (GPA, OutMessages, error)

func (*MsgWrapper) UnmarshalMessage

func (w *MsgWrapper) UnmarshalMessage(data []byte) (Message, error)

func (*MsgWrapper) WrapMessage

func (w *MsgWrapper) WrapMessage(subsystem byte, index int, msg Message) Message

func (*MsgWrapper) WrapMessages

func (w *MsgWrapper) WrapMessages(subsystem byte, index int, msgs OutMessages) OutMessages

type NodeID

type NodeID [32]byte

func MakeTestNodeIDFromIndex added in v1.0.3

func MakeTestNodeIDFromIndex(index int) NodeID

func MakeTestNodeIDs

func MakeTestNodeIDs(n int) []NodeID

func NodeIDFromPublicKey added in v1.0.3

func NodeIDFromPublicKey(pubKey *cryptolib.PublicKey) NodeID

func NodeIDsFromPublicKeys added in v1.0.3

func NodeIDsFromPublicKeys(pubKeys []*cryptolib.PublicKey) []NodeID

func RandomTestNodeID added in v1.0.3

func RandomTestNodeID() NodeID

func ShuffleNodeIDs

func ShuffleNodeIDs(nodeIDs []NodeID) []NodeID

func (NodeID) Equals added in v1.0.3

func (niT NodeID) Equals(other NodeID) bool

func (NodeID) ShortString added in v1.0.3

func (niT NodeID) ShortString() string

func (NodeID) String added in v1.0.3

func (niT NodeID) String() string

type OutMessages

type OutMessages interface {
	//
	// Add single message to the out messages.
	Add(msg Message) OutMessages
	//
	// Add several messages.
	AddMany(msgs []Message) OutMessages
	//
	// Add all the messages collected to other OutMessages.
	// The added OutMsgs object is marked done here.
	AddAll(msgs OutMessages) OutMessages
	//
	// Mark this instance as freezed, after this it cannot be appended.
	Done() OutMessages
	//
	// Returns a number of elements in the collection.
	Count() int
	//
	// Iterates over the collection, stops on first error.
	// Collection can be appended while iterating.
	Iterate(callback func(msg Message) error) error
	//
	// Iterated over the collection.
	// Collection can be appended while iterating.
	MustIterate(callback func(msg Message))
	//
	// Returns contents of the collection as an array of messages.
	AsArray() []Message
}

A buffer for collecting out messages. It is used to decrease array reallocations, if a slice would be used directly. Additionally, you can safely append to the OutMessages while you iterate over it. It should be implemented as a deep-list, allowing efficient appends and iterations.

func NoMessages

func NoMessages() OutMessages

A convenience function to return from the Input or Message functions in GPA.

type Output

type Output interface{}

type OwnHandler

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

OwnHandler is a GPA instance handling own messages immediately.

The idea is instead of checking if a message for myself in the actual protocols, one just send a message, and this handler passes it back as an ordinary message.

func (*OwnHandler) Input

func (o *OwnHandler) Input(input Input) OutMessages

func (*OwnHandler) Message

func (o *OwnHandler) Message(msg Message) OutMessages

func (*OwnHandler) Output

func (o *OwnHandler) Output() Output

func (*OwnHandler) StatusString

func (o *OwnHandler) StatusString() string

func (*OwnHandler) UnmarshalMessage

func (o *OwnHandler) UnmarshalMessage(data []byte) (Message, error)

type TestContext

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

Imitates a cluster of nodes and the medium performing the message exchange. Inputs are processes in-order for each node individually.

func NewTestContext

func NewTestContext(nodes map[NodeID]GPA) *TestContext

func (*TestContext) AddInputs

func (tc *TestContext) AddInputs(inputs map[NodeID]Input)

Will add new inputs to the existing set. The inputs will be overridden, if exist for the same nodes.

func (*TestContext) MsgCounts added in v1.0.3

func (tc *TestContext) MsgCounts() (int, int)

func (*TestContext) NumberOfOutputs

func (tc *TestContext) NumberOfOutputs() int

Returns a number of non-nil outputs.

func (*TestContext) NumberOfOutputsPredicate

func (tc *TestContext) NumberOfOutputsPredicate(outNum int) func() bool

Will run until there will be at least outNum of non-nil outputs generated.

func (*TestContext) OutOfMessagesPredicate

func (tc *TestContext) OutOfMessagesPredicate() func() bool

Will run until all the messages will be processed.

func (*TestContext) PrintAllStatusStrings added in v1.0.3

func (tc *TestContext) PrintAllStatusStrings(prefix string, logFunc func(format string, args ...any))

func (*TestContext) RunAll

func (tc *TestContext) RunAll()

func (*TestContext) RunUntil

func (tc *TestContext) RunUntil(predicate func() bool)

func (*TestContext) WithCall

func (tc *TestContext) WithCall(call func() []Message) *TestContext

func (*TestContext) WithInput added in v1.0.3

func (tc *TestContext) WithInput(nodeID NodeID, input Input) *TestContext

func (*TestContext) WithInputChannel added in v1.0.3

func (tc *TestContext) WithInputChannel(inputCh <-chan map[NodeID]Input) *TestContext

func (*TestContext) WithInputProbability

func (tc *TestContext) WithInputProbability(inputProb float64) *TestContext

func (*TestContext) WithInputs

func (tc *TestContext) WithInputs(inputs map[NodeID]Input) *TestContext

func (*TestContext) WithMessage added in v1.0.3

func (tc *TestContext) WithMessage(msg Message) *TestContext

func (*TestContext) WithMessageChannel added in v1.0.3

func (tc *TestContext) WithMessageChannel(msgCh <-chan Message) *TestContext

func (*TestContext) WithMessageDeliveryProbability

func (tc *TestContext) WithMessageDeliveryProbability(msgDeliveryProb float64) *TestContext

func (*TestContext) WithMessages

func (tc *TestContext) WithMessages(msgs []Message) *TestContext

func (*TestContext) WithOutputHandler added in v1.0.3

func (tc *TestContext) WithOutputHandler(outputHandler func(nodeID NodeID, output Output)) *TestContext

type TestMessage

type TestMessage struct {
	ID int
	// contains filtered or unexported fields
}

Just a message for test cases.

func (*TestMessage) Read added in v1.0.3

func (msg *TestMessage) Read(r io.Reader) error

func (*TestMessage) Recipient

func (msg *TestMessage) Recipient() NodeID

func (*TestMessage) SetSender

func (msg *TestMessage) SetSender(sender NodeID)

func (*TestMessage) Write added in v1.0.3

func (msg *TestMessage) Write(w io.Writer) error

type WrappingMsg

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

The message that contains another, and its routing info.

func (*WrappingMsg) Index

func (msg *WrappingMsg) Index() int

func (*WrappingMsg) Read added in v1.0.3

func (msg *WrappingMsg) Read(r io.Reader) error

note: never called, unfinished concept version

func (*WrappingMsg) Recipient

func (msg *WrappingMsg) Recipient() NodeID

func (*WrappingMsg) SetSender

func (msg *WrappingMsg) SetSender(sender NodeID)

func (*WrappingMsg) Subsystem

func (msg *WrappingMsg) Subsystem() byte

func (*WrappingMsg) Wrapped

func (msg *WrappingMsg) Wrapped() Message

func (*WrappingMsg) Write added in v1.0.3

func (msg *WrappingMsg) Write(w io.Writer) error

Directories

Path Synopsis
aba
craig
TODO: That's Craig's "Good-Case-Coin-Free" ABA consensus.
TODO: That's Craig's "Good-Case-Coin-Free" ABA consensus.
Here we implement the Asynchronous Common Subset algorithm from the HBBFT paper:
Here we implement the Asynchronous Common Subset algorithm from the HBBFT paper:
package acss implements "Asynchronous Complete Secret Sharing" as described in
package acss implements "Asynchronous Complete Secret Sharing" as described in
crypto
This package is a copy of <https://github.com/Wollac/async.go/tree/main/pkg/acss/crypto>
This package is a copy of <https://github.com/Wollac/async.go/tree/main/pkg/acss/crypto>
nonce
nonce package implements NonceDKG as described in <https://github.com/iotaledger/crypto-tss/>.
nonce package implements NonceDKG as described in <https://github.com/iotaledger/crypto-tss/>.
cc
blssig
blssig package implements a Common Coin (CC) based on a BLS Threshold signatures as described in the Appendix C of
blssig package implements a Common Coin (CC) based on a BLS Threshold signatures as described in the Appendix C of
semi
semi package implements a Common Coin (CC) that produces deterministic values only for some of the rounds.
semi package implements a Common Coin (CC) that produces deterministic values only for some of the rounds.
rbc
bracha
package bracha implements Bracha's Reliable Broadcast.
package bracha implements Bracha's Reliable Broadcast.

Jump to

Keyboard shortcuts

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