Documentation ¶
Overview ¶
Package muxer implements the muxer/demuxer that allows multiple mini-protocols to run over a single connection.
It's not generally intended for this package to be used outside of this library, but it's possible to use it to do more advanced things than the library interface allows for.
Index ¶
- Constants
- type DiffusionMode
- type Muxer
- func (m *Muxer) ErrorChan() chan error
- func (m *Muxer) RegisterProtocol(protocolId uint16, protocolRole ProtocolRole) (chan *Segment, chan *Segment, chan bool)
- func (m *Muxer) Send(msg *Segment) error
- func (m *Muxer) SetDiffusionMode(diffusionMode DiffusionMode)
- func (m *Muxer) Start()
- func (m *Muxer) Stop()
- func (m *Muxer) UnregisterProtocol(protocolId uint16, protocolRole ProtocolRole)
- type ProtocolRole
- type Segment
- type SegmentHeader
Constants ¶
const ProtocolUnknown uint16 = 0xabcd
Magic number chosen to represent unknown protocols
const SegmentMaxPayloadLength = 65535
Maximum segment payload length
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiffusionMode ¶
type DiffusionMode int
DiffusionMode is an enum for the valid muxer difficusion modes
const ( DiffusionModeNone DiffusionMode = 0 // Default (invalid) diffusion mode DiffusionModeInitiator DiffusionMode = 1 // Initiator-only (client) diffusion mode DiffusionModeResponder DiffusionMode = 2 // Responder-only (server) diffusion mode DiffusionModeInitiatorAndResponder DiffusionMode = 3 // Initiator and responder (full duplex) mode )
Diffusion modes
type Muxer ¶
type Muxer struct {
// contains filtered or unexported fields
}
Muxer wraps a connection to allow running multiple mini-protocols over a single connection
func (*Muxer) RegisterProtocol ¶
func (m *Muxer) RegisterProtocol( protocolId uint16, protocolRole ProtocolRole, ) (chan *Segment, chan *Segment, chan bool)
RegisterProtocol registers the provided protocol ID with the muxer. It returns a channel for sending, a channel for receiving, and a channel to know when the muxer is shutting down. If the muxer is shutting down, this function will return nil values.
func (*Muxer) Send ¶
Send takes a populated Segment and writes it to the connection. A mutex is used to prevent more than one protocol from sending at once
func (*Muxer) SetDiffusionMode ¶
func (m *Muxer) SetDiffusionMode(diffusionMode DiffusionMode)
SetDiffusionMode sets the muxer diffusion mode after the handshake completes
func (*Muxer) Start ¶
func (m *Muxer) Start()
Start unblocks the read loop after the initial handshake to allow it to start processing messages
func (*Muxer) UnregisterProtocol ¶ added in v0.83.0
func (m *Muxer) UnregisterProtocol( protocolId uint16, protocolRole ProtocolRole, )
type ProtocolRole ¶ added in v0.42.0
type ProtocolRole uint
ProtocolRole is an enum of the protocol roles
const ( ProtocolRoleNone ProtocolRole = 0 // Default (invalid) protocol role ProtocolRoleInitiator ProtocolRole = 1 // Initiator (client) protocol role ProtocolRoleResponder ProtocolRole = 2 // Responder (server) protocol role )
Protocol roles
type Segment ¶
type Segment struct { SegmentHeader Payload []byte }
Segment represents basic unit of data in the Ouroboros protocol.
Each chunk of data exchanged by a particular mini-protocol is wrapped in a muxer segment. A segment consists of 4 bytes containing a timestamp, 2 bytes indicating which protocol the data is part of, 2 bytes indicating the size of the payload (up to 65535 bytes), and then the actual payload
type SegmentHeader ¶
SegmentHeader represents the header bytes on a segment
func (*SegmentHeader) GetProtocolId ¶
func (s *SegmentHeader) GetProtocolId() uint16
GetProtocolId returns the protocol ID of the segment
func (*SegmentHeader) IsRequest ¶
func (s *SegmentHeader) IsRequest() bool
IsRequest returns true if the segment is not a response
func (*SegmentHeader) IsResponse ¶
func (s *SegmentHeader) IsResponse() bool
IsResponse returns true if the segment is a response