multiplexer

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LinkSize is the encoded buffer size of Link for wire format
	LinkSize = 18
)

Variables

View Source
var (
	ErrDestinationNotFound = fmt.Errorf("destination not found among peers")
)
View Source
var MessagingLink = Link{}

MessagingLink defines Link in which implementation should consider as Messaing channel

Functions

func Connect

func Connect(ctx context.Context, dst, src net.Conn) <-chan error

func IsTimeout

func IsTimeout(err error) bool

func RegisterConstructor added in v0.5.0

func RegisterConstructor(p protocol.Protocol, c Constructor)

func RegisterDialer added in v0.5.0

func RegisterDialer(p protocol.Protocol, d DialFunc)

Types

type Channel added in v0.2.0

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

Channel is a helper struct to coordinate the sending and closing of a channel between different goroutines to avoid data race

func NewChannel added in v0.2.0

func NewChannel() *Channel

func (*Channel) Close added in v0.2.0

func (c *Channel) Close() bool

func (*Channel) Closed added in v0.2.0

func (c *Channel) Closed() <-chan struct{}

func (*Channel) Incoming added in v0.2.0

func (c *Channel) Incoming() <-chan LinkConnection

func (*Channel) Put added in v0.2.0

func (c *Channel) Put(l LinkConnection)

func (*Channel) Run added in v0.2.0

func (c *Channel) Run(ctx context.Context)

type Config

type Config struct {
	Logger    *zap.Logger
	Conn      interface{}
	Peer      uint64
	Initiator bool
	Wait      time.Duration
}

func (*Config) Validate

func (p *Config) Validate() error

type Constructor

type Constructor func(Config) (Peer, error)

func New added in v0.5.0

type DialFunc added in v0.5.0

type DialFunc func(addr string, c *tls.Config) (connector interface{}, handshake net.Conn, closer func(), err error)

DialFunc is the function signature to help with establishing session with the peer. handshake will be used to negotiate on applcation layer. Connector should be passed to Config.Conn in Peer's constructor.

func Dialer added in v0.5.0

func Dialer(p protocol.Protocol) (DialFunc, error)
type Link struct {
	Source      uint64
	Destination uint64
	Protocol    protocol.Protocol // used for initial multiplexer handshake only
	ALPN        alpn.ALPN         // used to specify the expected application protocol
}

Link defines a bidirectional source and target. It can be used for negotiations on protocol during initial handshake

func (*Link) Flip

func (s *Link) Flip() Link

func (*Link) MarshalBinary added in v0.5.1

func (s *Link) MarshalBinary() ([]byte, error)

func (Link) MarshalLogObject added in v0.5.0

func (l Link) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Link) UnmarshalBinary added in v0.5.1

func (s *Link) UnmarshalBinary(b []byte) error

type LinkConnection

type LinkConnection struct {
	Conn net.Conn
	Link Link
}

LinkConnection contains the net.Conn associated with the Link

type Peer

type Peer interface {
	// Start will accept incoming connections from another Peer
	Start(context.Context)
	// Null should disconnect the incoming Peer if an incoming connection is accepted
	Null(context.Context)
	// Addr should return the Peer's net.Addr
	Addr() net.Addr
	// Initiator should return if the Peer initiated the connection
	Initiator() bool
	// Protocol returns the multiplexer protocol in used with the peer
	Protocol() protocol.Protocol
	// Peer returns the uint64 identifier of the connected Peer
	Peer() uint64
	// Messaging opens a dedicated bidirectional stream to handle in-band control messages
	Messaging(context.Context) (net.Conn, error)
	// Bidirectional establishs a virtual link between the Source and Destination via this Peer
	Bidirectional(context.Context, net.Conn, Link) (<-chan error, error)
	// Direct requests a direct link to destination without automatic bidirectional handling
	Direct(context.Context, Link) (net.Conn, error)
	// Handle returns a receving channel where Bidirectional request is made from a connected peer
	Handle() <-chan LinkConnection
	// NotifyClose returns a notifying channel, unblocks when the Peer disconnects
	NotifyClose() <-chan struct{}
	// Bye closes the session and LinkConnection channel
	Bye() error
}

Peer defines the behavior of a multiplexer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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