link

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 12 Imported by: 2

README

GoDoc MIT licensed Go Report Card

mux can be based on TCP, Websocket(should implement io.ReadWriteCloser), something stream

link low level should implement io.ReadWriteCloser

  • io.ReadWritCloser
  • io.closeWriter

version

not recommend
  • version 0
  • version 1
recommend
  • version 2 or master

API doc

godoc link

Thanks

  • @Hex11 He gives me a lot of help to broaden my horizon and mind.

  • smux A lot of codes learn from This project.

Documentation

Index

Constants

View Source
const (
	ClientMode mode = iota
	ServerMode
)
View Source
const (
	Version = 6

	VersionLength = 1
	IDLength      = 4
	CMDLength     = 1

	HeaderWithoutPayloadLength = VersionLength + IDLength + CMDLength

	PSH   Cmd = 1 << 7
	CLOSE Cmd = 1 << 6
	PING  Cmd = 1 << 5
	ACK   Cmd = 1 << 4 // [4 bytes data readableBufSize] tell peer the readable size
	NEW   Cmd = 1 << 3 // can take some data to reduce dial time, [4 bytes readableBufSize + optional data]
	ACPT  Cmd = 1 << 2 // take [4 bytes readableBufSize]
)

Variables

View Source
var (
	ErrManagerClosed = xerrors.New("manager is closed")
	ErrLinkClosed    = xerrors.New("link is closed")
	ErrTimeout       = xerrors.New("io timeout")
)

Functions

This section is empty.

Types

type Addr added in v0.3.0

type Addr struct {
	ID string
}

func (Addr) Network added in v0.3.0

func (a Addr) Network() string

func (Addr) String added in v0.3.0

func (a Addr) String() string

type Cmd added in v0.4.0

type Cmd = uint8

type Config

type Config struct {
	AcceptQueueSize   int
	KeepaliveInterval time.Duration // if config mode is ServerMode, KeepaliveInterval will be ignored
	BufferSize        int
	DebugLog          bool // enable debug log
	Mode              mode // manager run mode
	ReadBufSize       int32
}

Config manager config.

func DefaultConfig

func DefaultConfig(mode mode) Config

DefaultConfig default config.

func KeepaliveConfig

func KeepaliveConfig(mode mode) Config

KeepaliveConfig DefaultConfig enable keepalive.

type ErrCmd added in v0.4.0

type ErrCmd struct {
	Receive uint8
}

func (ErrCmd) Error added in v0.4.0

func (ec ErrCmd) Error() string

type ErrVersion added in v0.3.0

type ErrVersion struct {
	Receive     uint8
	NeedVersion uint8
}

func (ErrVersion) Error added in v0.3.0

func (ev ErrVersion) Error() string
type Link interface {
	net.Conn
}

type Manager

type Manager interface {
	Dial(ctx context.Context) (link Link, err error)
	DialData(ctx context.Context, b []byte) (link Link, err error)
	Accept() (link Link, err error)
	IsClosed() bool
	io.Closer
}

func NewManager

func NewManager(conn net.Conn, config Config) Manager

NewManager create a manager based on conn, if config is nil, will use DefaultConfig.

type Packet

type Packet struct {
	Version uint8

	ID uint32

	// CMD 1 byte
	// PSH    0b1000,0000
	// CLOSE  0b0100,0000
	// PING   0b0010,0000
	// ACK    0b0001,0000
	// NEW    0b0000,1000
	// ACPT   0b0000,0100
	// RSV    0b0000,0000
	CMD Cmd

	PayloadLength int
	Payload       []byte
	// contains filtered or unexported fields
}

header[VersionLength + IDLength + CMDLength + indefinite length bytes] [payload]

Jump to

Keyboard shortcuts

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