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.
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 ¶
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) MarshalBinary ¶
func (*Message) UnmarshalBinary ¶
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 ¶
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.