emux

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 12 Imported by: 1

README

EMux

EMux(Express Multiplexing) is a simple, fast stream Multiplexer. EMux is using a custom protocol, is not compatible with any other agreement, any similarity is purely coincidental.

Go Report Card GoDoc GitHub license gocover.io

This project is to add protocol support for the Bridge, or it can be used alone

The following is the implementation of other proxy protocols

License

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HandshakeData    = []byte("EMUX ")
	DefaultHandshake = NewHandshake(HandshakeData)
)

DefaultHandshake 0 5 +---------+---------+---------+---------+---------+ | "EMUX " | +---------+---------+---------+---------+---------+

View Source
var (
	ErrTimeout = fmt.Errorf("timeout")
)

Functions

This section is empty.

Types

type BytesPool

type BytesPool interface {
	Get() []byte
	Put([]byte)
}

type Cmd

type Cmd uint8
const (
	CmdConnect      Cmd = 0xa0 // create a connect stream, with both command and stream id
	CmdConnected    Cmd = 0xa1 // reply to connect, with both command and stream id
	CmdDisconnect   Cmd = 0xc0 // disconnect a stream and report the reason, with both command and stream id
	CmdDisconnected Cmd = 0xc1 // reply to disconnect, with both command and stream id

	CmdData Cmd = 0xb0 // data packet, all fields
)

func (Cmd) String

func (i Cmd) String() string

type Decode

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

func NewDecode

func NewDecode(r io.Reader) *Decode

func (*Decode) ReadByte

func (d *Decode) ReadByte() (byte, error)

func (*Decode) ReadBytes

func (d *Decode) ReadBytes() ([]byte, error)

func (*Decode) ReadUvarint

func (d *Decode) ReadUvarint() (uint64, error)

func (*Decode) WriteTo

func (d *Decode) WriteTo(w io.Writer, buf []byte) (int64, error)

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer contains options for connecting to an address.

type DialerSession

type DialerSession struct {
	BytesPool BytesPool
	Logger    Logger
	Handshake Handshake
	// contains filtered or unexported fields
}

func NewDialer

func NewDialer(dialer Dialer) *DialerSession

func (*DialerSession) DialContext

func (d *DialerSession) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type Encode

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

func NewEncode

func NewEncode(w io.Writer) *Encode

func (*Encode) Flush

func (e *Encode) Flush() error

func (*Encode) WriteByte

func (e *Encode) WriteByte(b byte) error

func (*Encode) WriteBytes

func (e *Encode) WriteBytes(b []byte) error

func (*Encode) WriteCmd

func (e *Encode) WriteCmd(cmd Cmd, sid uint64) error

func (*Encode) WriteUvarint

func (e *Encode) WriteUvarint(v uint64) error

type Handshake

type Handshake interface {
	Handshake(rw io.ReadWriter) error
}

func NewHandshake

func NewHandshake(h []byte) Handshake

type ListenConfig

type ListenConfig interface {
	Listen(ctx context.Context, network, address string) (net.Listener, error)
}

ListenConfig contains options for listening to an address.

type ListenConfigSession

type ListenConfigSession struct {
	Logger    Logger
	BytesPool BytesPool
	Handshake Handshake
	// contains filtered or unexported fields
}

func NewListenerConfig

func NewListenerConfig(listener ListenConfig) *ListenConfigSession

func (*ListenConfigSession) Listen

func (l *ListenConfigSession) Listen(ctx context.Context, network, address string) (net.Listener, error)

type ListenerSession

type ListenerSession struct {
	BytesPool BytesPool
	Logger    Logger
	Handshake Handshake
	// contains filtered or unexported fields
}

func NewListener

func NewListener(ctx context.Context, listener net.Listener) *ListenerSession

func (*ListenerSession) Accept

func (l *ListenerSession) Accept() (net.Conn, error)

func (*ListenerSession) Addr

func (l *ListenerSession) Addr() net.Addr

func (*ListenerSession) Close

func (l *ListenerSession) Close() error

type Logger

type Logger interface {
	Println(v ...interface{})
}

Logger is the interface for logging.

type Session

type Session struct {
	Logger    Logger
	BytesPool BytesPool
	// contains filtered or unexported fields
}

func NewSession

func NewSession(s io.ReadWriteCloser) *Session

func (*Session) Accept

func (s *Session) Accept() (io.ReadWriteCloser, error)

func (*Session) Close

func (s *Session) Close() error

func (*Session) IsClosed

func (s *Session) IsClosed() bool

func (*Session) Open

func (s *Session) Open() (io.ReadWriteCloser, error)

Jump to

Keyboard shortcuts

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