protocol

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// Culprit is empty if the identity of the misbehaving party cannot be known.
	Culprits []party.ID
	// Err is the underlying error.
	Err error
}

Error is a custom error for protocols which contains information about the responsible round in which it occurred, and the party responsible.

func (Error) Error

func (e Error) Error() string

Error implement error.

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap implement errors.Wrapper.

type Handler

type Handler interface {
	// Result should return the result of running the protocol, or an error
	Result() (interface{}, error)
	// Listen returns a channel which will receive new messages
	Listen() <-chan *Message
	// Stop should abort the protocol execution.
	Stop()
	// CanAccept checks whether or not a message can be accepted at the current point in the protocol.
	CanAccept(msg *Message) bool
	// Accept advances the protocol execution after receiving a message.
	Accept(msg *Message)
}

Handler represents some kind of handler for a protocol.

type Message

type Message struct {
	// SSID is a byte string which uniquely identifies the session this message belongs to.
	SSID []byte
	// From is the party.ID of the sender
	From party.ID
	// To is the intended recipient for this message. If To == "", then the message should be sent to all.
	To party.ID
	// Protocol identifies the protocol this message belongs to
	Protocol string
	// RoundNumber is the index of the round this message belongs to
	RoundNumber round.Number
	// Data is the actual content consumed by the round.
	Data []byte
	// Broadcast indicates whether this message should be reliably broadcast to all participants.
	Broadcast bool
	// BroadcastVerification is the hash of all messages broadcast by the parties,
	// and is included in all messages in the round following a broadcast round.
	BroadcastVerification []byte
}

func (*Message) Hash

func (m *Message) Hash() []byte

Hash returns a 64 byte hash of the message content, including the headers. Can be used to produce a signature for the message.

func (Message) IsFor

func (m Message) IsFor(id party.ID) bool

IsFor returns true if the message is intended for the designated party.

func (*Message) MarshalBinary

func (m *Message) MarshalBinary() ([]byte, error)

func (Message) String

func (m Message) String() string

String implements fmt.Stringer.

func (*Message) UnmarshalBinary

func (m *Message) UnmarshalBinary(data []byte) error

type MultiHandler

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

MultiHandler represents an execution of a given protocol. It provides a simple interface for the user to receive/deliver protocol messages.

func NewMultiHandler

func NewMultiHandler(create StartFunc, sessionID []byte) (*MultiHandler, error)

NewMultiHandler expects a StartFunc for the desired protocol. It returns a handler that the user can interact with.

func (*MultiHandler) Accept

func (h *MultiHandler) Accept(msg *Message)

Accept tries to process the given message. If an abort occurs, the channel returned by Listen() is closed, and an error is returned by Result().

This function may be called concurrently from different threads but may block until all previous calls have finished.

func (*MultiHandler) CanAccept

func (h *MultiHandler) CanAccept(msg *Message) bool

CanAccept returns true if the message is designated for this protocol protocol execution.

func (*MultiHandler) Listen

func (h *MultiHandler) Listen() <-chan *Message

Listen returns a channel with outgoing messages that must be sent to other parties. The message received should be _reliably_ broadcast if msg.Broadcast is true. The channel is closed when either an error occurs or the protocol detects an error.

func (*MultiHandler) Result

func (h *MultiHandler) Result() (interface{}, error)

Result returns the protocol result if the protocol completed successfully. Otherwise an error is returned.

func (*MultiHandler) Stop

func (h *MultiHandler) Stop()

Stop cancels the current execution of the protocol, and alerts the other users.

func (*MultiHandler) String

func (h *MultiHandler) String() string

type StartFunc

type StartFunc func(sessionID []byte) (round.Session, error)

StartFunc is function that creates the first round of a protocol. It returns the first round initialized with the session information. If the creation fails (likely due to misconfiguration), and error is returned.

An optional sessionID can be provided, which should unique among all protocol executions.

type TwoPartyHandler

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

TwoPartyHandler represents a restriction of the Handler for 2 party protocols.

func NewTwoPartyHandler

func NewTwoPartyHandler(create StartFunc, sessionID []byte, leader bool) (*TwoPartyHandler, error)

func (*TwoPartyHandler) Accept

func (h *TwoPartyHandler) Accept(msg *Message)

func (*TwoPartyHandler) CanAccept

func (h *TwoPartyHandler) CanAccept(msg *Message) bool

func (*TwoPartyHandler) Listen

func (h *TwoPartyHandler) Listen() <-chan *Message

func (*TwoPartyHandler) Result

func (h *TwoPartyHandler) Result() (interface{}, error)

func (*TwoPartyHandler) Stop

func (h *TwoPartyHandler) Stop()

func (*TwoPartyHandler) String

func (h *TwoPartyHandler) String() string

Jump to

Keyboard shortcuts

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