Documentation ¶
Overview ¶
Package wire contains the basic wire communication infrastructure like wire message en- and decoding. The actual (de)serialization functions are found in package pkg/io.
Index ¶
- func Encode(msg Msg, w io.Writer) error
- func IndexOfAddr(addrs []Address, addr Address) int
- func RegisterDecoder(t Type, decoder func(io.Reader) (Msg, error))
- func RegisterExternalDecoder(t Type, decoder func(io.Reader) (Msg, error), name string)
- func TestMsg(t *testing.T, msg Msg)
- type Account
- type Address
- type Addresses
- type AddressesWithLen
- type AuthResponseMsg
- type Bus
- type Cache
- type Cacher
- type Consumer
- type Envelope
- type LocalBus
- type Msg
- type PingMsg
- type PongMsg
- type Predicate
- type Publisher
- type Receiver
- type Relay
- type ShutdownMsg
- type Subscriber
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode encodes a message into an io.Writer. It also encodes the message type whereas the Msg.Encode implementation is assumed not to write the type.
func IndexOfAddr ¶ added in v0.5.0
IndexOfAddr returns the index of the given address in the address slice, or -1 if it is not part of the slice.
func RegisterDecoder ¶ added in v0.4.0
RegisterDecoder sets the decoder of messages of Type `t`.
func RegisterExternalDecoder ¶ added in v0.4.0
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.
Types ¶
type Account ¶ added in v0.4.0
Account is a node's permanent Perun identity, which is used to establish authenticity within the Perun peer-to-peer network. For now, it is just a stub.
type Address ¶ added in v0.4.0
Address is a Perun node's network address, which is used as a permanent identity within the Perun peer-to-peer network. For now, it is based on type wallet.Address.
type Addresses ¶ added in v0.4.0
type Addresses []Address
Addresses is a helper type for encoding and decoding address slices in situations where the length of the slice is known.
type AddressesWithLen ¶ added in v0.4.0
type AddressesWithLen []Address
AddressesWithLen is a helper type for encoding and decoding address slices of unknown length.
type AuthResponseMsg ¶ added in v0.4.0
type AuthResponseMsg struct { }
AuthResponseMsg is the response message in the peer authentication protocol.
This will be expanded later to contain signatures.
func (*AuthResponseMsg) Decode ¶ added in v0.4.0
func (m *AuthResponseMsg) Decode(r io.Reader) (err error)
Decode decodes an AuthResponseMsg from an io.Reader.
func (*AuthResponseMsg) Encode ¶ added in v0.4.0
func (m *AuthResponseMsg) Encode(w io.Writer) error
Encode encodes this AuthResponseMsg into an io.Writer.
func (*AuthResponseMsg) Type ¶ added in v0.4.0
func (m *AuthResponseMsg) Type() Type
Type returns AuthResponse.
type Bus ¶ added in v0.4.0
type Bus interface { Publisher // SubscribeClient should route all messages with clientAddr as recipient to // the provided Consumer. Every address may only be subscribed to once. SubscribeClient(c Consumer, clientAddr Address) error }
A Bus is a central message bus over which all clients of a channel network communicate. It is used as the transport layer abstraction for the client.Client.
type Cache ¶ added in v0.4.0
type Cache struct {
// contains filtered or unexported fields
}
Cache is a message cache. The default value is a valid empty cache.
func (*Cache) Cache ¶ added in v0.4.0
Cache is a message cache. The default value is a valid empty cache.
func (*Cache) Flush ¶ added in v0.4.0
func (c *Cache) Flush()
Flush empties the message cache and removes all predicates.
func (*Cache) Get ¶ added in v0.4.0
Get retrieves all messages from the cache that match the predicate. They are removed from the Cache.
type Cacher ¶ added in v0.4.0
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 Consumer ¶ added in v0.4.0
type Consumer interface { // The producer calls OnClose() to unregister the Consumer after it is // closed. sync.OnCloser // Put is called by the emitter when relaying a message. Put(*Envelope) }
Consumer consumes messages fed into it via Put().
type Envelope ¶ added in v0.4.0
type Envelope struct { Sender Address // Sender of the message. Recipient Address // Recipient of the message. // Msg contained in this Envelope. Not embedded so Envelope doesn't implement Msg. Msg Msg }
An Envelope encapsulates a message with routing information, that is, the sender and intended recipient.
type LocalBus ¶ added in v0.4.0
type LocalBus struct {
// contains filtered or unexported fields
}
LocalBus is a bus that only sends message in the same process.
func NewLocalBus ¶ added in v0.4.0
func NewLocalBus() *LocalBus
NewLocalBus creates a new local bus, which only targets receivers that lie within the same process.
type Msg ¶ added in v0.4.0
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 NewAuthResponseMsg ¶ added in v0.4.0
NewAuthResponseMsg creates an authentication response message.
type PingMsg ¶ added in v0.4.0
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.
type PongMsg ¶ added in v0.4.0
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.
type Publisher ¶ added in v0.4.0
type Publisher interface { // Publish should return nil when the message was delivered (outgoing) or is // guaranteed to be eventually delivered (cached), depending on the goal of the // implementation. Publish(context.Context, *Envelope) error }
A Publisher allows to publish a message in a messaging network.
type Receiver ¶ added in v0.4.0
Receiver is a helper object that can subscribe to different message categories from multiple peers. Receivers must only be used by a single execution context at a time. If multiple contexts need to access a peer's messages, then multiple receivers have to be created.
type Relay ¶ added in v0.4.0
Relay handles (un)registering Consumers for a message Relay's messages.
func NewRelay ¶ added in v0.4.0
func NewRelay() *Relay
NewRelay returns a new Relay which logs unhandled messages.
func (*Relay) Cache ¶ added in v0.4.0
Cache enables caching of messages that don't match any consumer. They are only cached if they match the given predicate, within the given context.
func (*Relay) SetDefaultMsgHandler ¶ added in v0.4.0
SetDefaultMsgHandler sets the default message handler.
type ShutdownMsg ¶ added in v0.4.0
type ShutdownMsg struct {
Reason string
}
ShutdownMsg is sent when orderly shutting down a connection.
func (*ShutdownMsg) Decode ¶ added in v0.4.0
func (m *ShutdownMsg) Decode(r io.Reader) error
Decode implements msg.Decode.
func (*ShutdownMsg) Encode ¶ added in v0.4.0
func (m *ShutdownMsg) Encode(w io.Writer) error
Encode implements msg.Encode.
func (*ShutdownMsg) Type ¶ added in v0.4.0
func (m *ShutdownMsg) Type() Type
Type implements msg.Type.
type Subscriber ¶ added in v0.4.0
type Subscriber interface { // Subscribe adds a Consumer to the subscriptions. // If the Consumer is already subscribed, Subscribe panics. Subscribe(Consumer, Predicate) error }
A Subscriber allows to subscribe Consumers, which will receive messages that match a predicate.
type Type ¶ added in v0.4.0
type Type uint8
Type is an enumeration used for (de)serializing messages and identifying a message's Type.
const ( Ping Type = iota Pong Shutdown AuthResponse LedgerChannelProposal LedgerChannelProposalAcc SubChannelProposal SubChannelProposalAcc ChannelProposalRej ChannelUpdate ChannelUpdateAcc ChannelUpdateRej ChannelSync LastType // upper bound on the message types of the Perun wire protocol )
Enumeration of message categories known to the Perun framework.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package net contains the abstract communication logic between peers.
|
Package net contains the abstract communication logic between peers. |
simple
Package simple contains simplistic implementation for the wire.Dialer and wire.Listener interfaces.
|
Package simple contains simplistic implementation for the wire.Dialer and wire.Listener interfaces. |
test
Package test contains the testing types for wire/net.
|
Package test contains the testing types for wire/net. |
Package test contains implementations of the peer interfaces that are useful for testing.
|
Package test contains implementations of the peer interfaces that are useful for testing. |