msg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package msg contains all message types, as well as serialising and deserialising logic used in peer communications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(msg Msg, w io.Writer) (err error)

Encode encodes a message into an io.Writer.

func RegisterDecoder

func RegisterDecoder(t Type, decoder func(io.Reader) (Msg, error))

RegisterDecoder sets the decoder of messages of Type `t`.

func RegisterExternalDecoder

func RegisterExternalDecoder(t Type, decoder func(io.Reader) (Msg, error), name string)

RegisterExternalDecoder sets the decoder of messages of external type `t`. This is like RegisterDecoder but for message types not part of the Perun wire protocol and thus not known natively. This can be used by users of the framework to create additional message types and send them over the same peer connection. It also comes in handy to register types for testing.

func TestMsg

func TestMsg(t *testing.T, msg Msg)

TestMsg performs generic tests on a wire.Msg object

Types

type Cache

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

Cache is a message cache. The default value is a valid empty cache.

func (*Cache) Cache

func (c *Cache) Cache(ctx context.Context, p Predicate)

Cache is a message cache. The default value is a valid empty cache.

func (*Cache) Flush

func (c *Cache) Flush()

Flush empties the message cache. Predicates are retained.

func (*Cache) Get

func (c *Cache) Get(p Predicate) []MsgAnnex

Get retrieves all messages from the cache that match the predicate. They are removed from the Cache.

func (*Cache) Put

func (c *Cache) Put(m Msg, a interface{}) bool

Put puts the message into the cache if it matches any active prediacte. If it matches several predicates, it is still only added once to the cache.

func (*Cache) Size

func (c *Cache) Size() int

Size returns the number of messages held in the message cache.

type Cacher

type Cacher interface {
	// Cache should enable the caching of messages
	Cache(context.Context, Predicate)
}

A Cacher has the Cache method to enable caching of messages.

type Msg

type Msg interface {
	// Type returns the message's type.
	Type() Type
	// encoding of payload. Type byte should not be encoded.
	perunio.Encoder
}

Msg is the top-level abstraction for all messages sent between perun nodes.

func Decode

func Decode(r io.Reader) (Msg, error)

Decode decodes a message from an io.Reader.

type MsgAnnex

type MsgAnnex struct {
	Msg   Msg
	Annex interface{}
}

MsgAnnex is a tuple of a message together with some arbitrary additional data (Annex)

type PingMsg

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

PingMsg is a ping request. It contains the time at which it was sent, so that the recipient can also measure the time it took to transmit the ping request.

func NewPingMsg

func NewPingMsg() *PingMsg

func (*PingMsg) Decode

func (m *PingMsg) Decode(reader io.Reader) error

func (PingMsg) Encode

func (m PingMsg) Encode(writer io.Writer) error

func (*PingMsg) Type

func (m *PingMsg) Type() Type

type PongMsg

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

PongMsg is the response to a ping message. It contains the time at which it was sent, so that the recipient knows how long the ping request took to be transmitted, and how quickly the response was sent.

func NewPongMsg

func NewPongMsg() *PongMsg

func (*PongMsg) Decode

func (m *PongMsg) Decode(reader io.Reader) error

func (PongMsg) Encode

func (m PongMsg) Encode(writer io.Writer) error

func (*PongMsg) Type

func (m *PongMsg) Type() Type

type Predicate

type Predicate = func(Msg) bool

A Predicate defines a message filter.

type Type

type Type uint8

Type is an enumeration used for (de)serializing messages and identifying a message's Type.

const (
	Ping Type = iota
	Pong
	AuthResponse
	ChannelProposal
	ChannelProposalAcc
	ChannelProposalRej
	ChannelUpdate
	ChannelUpdateAcc
	ChannelUpdateRej
	LastType // upper bound on the message types of the Perun wire protocol
)

Enumeration of message categories known to the Perun framework.

func (Type) String

func (t Type) String() string

String returns the name of a message type if it is valid and name known or otherwise its numerical representation.

func (Type) Valid

func (t Type) Valid() bool

Valid checks whether a decoder is known for the type.

Jump to

Keyboard shortcuts

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