emux

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 15 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, 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 (
	ErrClosed         = net.ErrClosed
	ErrTimeout        = fmt.Errorf("timeout")
	ErrAlreadyStarted = fmt.Errorf("session already started")
)
View Source
var (
	HandshakeData          = []byte("EMUX ")
	DefaultClientHandshake = NewHandshake(HandshakeData, true)
	DefaultServerHandshake = NewHandshake(HandshakeData, false)
)

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

View Source
var (
	DefaultInstruction = Instruction{
		Close:             0x00,
		Connect:           0xa0,
		Connected:         0xa1,
		Disconnect:        0xc0,
		Disconnected:      0xc1,
		Data:              0xb0,
		MaxDataPacketSize: bufSize - 1 - 2*binary.MaxVarintLen64,
	}
	DefaultTimeout     = 30 * time.Second
	DefaultIdleTimeout = 600 * time.Second
)

Functions

func NewConn added in v0.2.1

func NewConn(stm io.ReadWriteCloser, localAddr net.Addr, remoteAddr net.Addr) net.Conn

Types

type BytesPool

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

BytesPool is the interface for a bytes pool.

type Client added in v0.0.12

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

func NewClient added in v0.0.12

func NewClient(ctx context.Context, stm io.ReadWriteCloser, instruction *Instruction) *Client

func (Client) Clear added in v0.2.0

func (s Client) Clear()

func (Client) Close added in v0.0.12

func (s Client) Close() error

func (*Client) Dial added in v0.0.12

func (c *Client) Dial(ctx context.Context) (io.ReadWriteCloser, error)

func (Client) IsClear added in v0.2.0

func (s Client) IsClear() bool

func (Client) IsClosed added in v0.0.12

func (s Client) IsClosed() bool

type Decode

type Decode struct {
	io.Reader
	// 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
	Instruction Instruction
	Timeout     time.Duration
	IdleTimeout time.Duration
	Retry       int
	// contains filtered or unexported fields
}

func NewDialer

func NewDialer(ctx context.Context, dialer Dialer) *DialerSession

func (*DialerSession) Close added in v0.2.0

func (d *DialerSession) Close() error

func (*DialerSession) DialContext

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

type Encode

type Encode struct {
	io.Writer
	// contains filtered or unexported fields
}

func NewEncode

func NewEncode(w io.Writer) *Encode

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 uint8, sid uint64) error

func (*Encode) WriteUvarint

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

type Handshake

type Handshake interface {
	Handshake(ctx context.Context, rw io.ReadWriter) error
}

func NewHandshake

func NewHandshake(h []byte, send bool) Handshake

type Instruction added in v0.0.13

type Instruction struct {
	Close uint8 // close all sessions and connections, only command

	Connect      uint8 // create a connect stream, with both command and stream id
	Connected    uint8 // reply to connect, with both command and stream id
	Disconnect   uint8 // disconnect a stream and report the reason, with both command and stream id
	Disconnected uint8 // reply to disconnect, with both command and stream id

	Data uint8 // data packet, all fields

	MaxDataPacketSize uint64 // max data packet size
}

func (Instruction) Info added in v0.2.0

func (i Instruction) Info(cmd uint8) string

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
	Instruction Instruction
	Timeout     time.Duration
	IdleTimeout time.Duration
	// contains filtered or unexported fields
}

func NewListenConfig added in v0.1.0

func NewListenConfig(ctx context.Context, 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
	Instruction Instruction
	Timeout     time.Duration
	IdleTimeout time.Duration
	// 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

func (*ListenerSession) IsClosed added in v0.1.3

func (l *ListenerSession) IsClosed() bool

type Logger

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

Logger is the interface for logging.

type Server added in v0.0.12

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

func NewServer added in v0.0.12

func NewServer(ctx context.Context, stm io.ReadWriteCloser, instruction *Instruction) *Server

func (*Server) Accept added in v0.0.12

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

func (*Server) AcceptTo added in v0.1.6

func (s *Server) AcceptTo(acceptChan chan io.ReadWriteCloser) error

func (Server) Clear added in v0.2.0

func (s Server) Clear()

func (*Server) Close added in v0.0.12

func (s *Server) Close() error

func (Server) IsClear added in v0.2.0

func (s Server) IsClear() bool

func (Server) IsClosed added in v0.0.12

func (s Server) IsClosed() bool

Jump to

Keyboard shortcuts

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