multiplex

package
v0.0.0-...-5f124ca Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EncryptionMethodPlain = iota
	EncryptionMethodAES256GCM
	EncryptionMethodChaha20Poly1305
	EncryptionMethodAES128GCM
)

Variables

View Source
var ErrBrokenSession = errors.New("broken session")
View Source
var ErrBrokenStream = errors.New("broken stream")
View Source
var ErrTimeout = errors.New("deadline exceeded")
View Source
var UNLIMITED_VALVE = &UnlimitedValve{}

Functions

func NewDatagramBufferedPipe

func NewDatagramBufferedPipe() *datagramBufferedPipe

func NewStreamBuffer

func NewStreamBuffer() *streamBuffer

streamBuffer is a wrapper around streamBufferedPipe. Its main function is to sort frames in order, and wait for frames to arrive if they have arrived out-of-order. Then it writes the payload of frames into a streamBufferedPipe.

func NewStreamBufferedPipe

func NewStreamBufferedPipe() *streamBufferedPipe

Types

type Frame

type Frame struct {
	StreamID uint32
	Seq      uint64
	Closing  uint8
	Payload  []byte
}

type LimitedValve

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

Valve needs to be universal, across all sessions that belong to a user

func MakeValve

func MakeValve(rxRate, txRate int64) *LimitedValve

func (*LimitedValve) AddRx

func (v *LimitedValve) AddRx(n int64)

func (*LimitedValve) AddTx

func (v *LimitedValve) AddTx(n int64)

func (*LimitedValve) GetRx

func (v *LimitedValve) GetRx() int64

func (*LimitedValve) GetTx

func (v *LimitedValve) GetTx() int64

func (*LimitedValve) Nullify

func (v *LimitedValve) Nullify() (int64, int64)

type Obfuscator

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

Obfuscator is responsible for serialisation, obfuscation, and optional encryption of data frames.

func MakeObfuscator

func MakeObfuscator(encryptionMethod byte, sessionKey [32]byte) (o Obfuscator, err error)

type Session

type Session struct {
	SessionConfig
	// contains filtered or unexported fields
}

A Session represents a self-contained communication chain between local and remote. It manages its streams, controls serialisation and encryption of data sent and received using the supplied Obfuscator, and send and receive data through a manged connection pool filled with underlying connections added to it.

func MakeSession

func MakeSession(id uint32, config SessionConfig) *Session

func (*Session) Accept

func (sesh *Session) Accept() (net.Conn, error)

Accept is similar to net.Listener's Accept(). It blocks and returns an incoming stream

func (*Session) AddConnection

func (sesh *Session) AddConnection(conn net.Conn)

AddConnection is used to add an underlying connection to the connection pool

func (*Session) Addr

func (sesh *Session) Addr() net.Addr

func (*Session) Close

func (sesh *Session) Close() error

func (*Session) GetSessionKey

func (sesh *Session) GetSessionKey() [32]byte

func (*Session) IsClosed

func (sesh *Session) IsClosed() bool

func (*Session) OpenStream

func (sesh *Session) OpenStream() (*Stream, error)

OpenStream is similar to net.Dial. It opens up a new stream

func (*Session) SetTerminalMsg

func (sesh *Session) SetTerminalMsg(msg string)

func (*Session) TerminalMsg

func (sesh *Session) TerminalMsg() string

type SessionConfig

type SessionConfig struct {
	Obfuscator

	// Valve is used to limit transmission rates, and record and limit usage
	Valve

	Unordered bool

	// A Singleplexing session always has just one stream
	Singleplex bool

	// maximum size of an obfuscated frame, including headers and overhead
	MsgOnWireSizeLimit int

	// InactivityTimeout sets the duration a Session waits while it has no active streams before it closes itself
	InactivityTimeout time.Duration
}

type Stream

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

Stream implements net.Conn. It represents an optionally-ordered, full-duplex, self-contained connection. If the session it belongs to runs in ordered mode, it provides ordering guarantee regardless of the underlying connection used. If the underlying connections the session uses are reliable, Stream is reliable. If they are not, Stream does not guarantee reliability.

func (*Stream) Close

func (s *Stream) Close() error

active close. Close locally and tell the remote that this stream is being closed

func (*Stream) LocalAddr

func (s *Stream) LocalAddr() net.Addr

func (*Stream) Read

func (s *Stream) Read(buf []byte) (n int, err error)

Read implements io.Read

func (*Stream) ReadFrom

func (s *Stream) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom continuously read data from r and send it off, until either r returns error or nothing has been read for readFromTimeout amount of time

func (*Stream) RemoteAddr

func (s *Stream) RemoteAddr() net.Addr

func (*Stream) SetDeadline

func (s *Stream) SetDeadline(t time.Time) error

the following functions are purely for implementing net.Conn interface. they are not used TODO: implement the following

func (*Stream) SetReadDeadline

func (s *Stream) SetReadDeadline(t time.Time) error

func (*Stream) SetReadFromTimeout

func (s *Stream) SetReadFromTimeout(d time.Duration)

func (*Stream) SetWriteDeadline

func (s *Stream) SetWriteDeadline(t time.Time) error

func (*Stream) SetWriteToTimeout

func (s *Stream) SetWriteToTimeout(d time.Duration)

func (*Stream) Write

func (s *Stream) Write(in []byte) (n int, err error)

Write implements io.Write

func (*Stream) WriteTo

func (s *Stream) WriteTo(w io.Writer) (int64, error)

WriteTo continuously write data Stream has received into the writer w.

type UnlimitedValve

type UnlimitedValve struct{}

func (*UnlimitedValve) AddRx

func (v *UnlimitedValve) AddRx(n int64)

func (*UnlimitedValve) AddTx

func (v *UnlimitedValve) AddTx(n int64)

func (*UnlimitedValve) GetRx

func (v *UnlimitedValve) GetRx() int64

func (*UnlimitedValve) GetTx

func (v *UnlimitedValve) GetTx() int64

func (*UnlimitedValve) Nullify

func (v *UnlimitedValve) Nullify() (int64, int64)

type Valve

type Valve interface {
	AddRx(n int64)
	AddTx(n int64)
	GetRx() int64
	GetTx() int64
	Nullify() (int64, int64)
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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