mode

package
v0.0.0-...-0eaabd3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInterfaceIsNil        = errors.New("interface is nil")
	ErrModeNotSupported      = errors.New("mode is not supported")
	ErrAmbiguousModeAnnounce = errors.New("ambiguous mode announce, expected other byte sequence")
)
View Source
var (
	ErrChecksumMismatch = errors.New("checksum mismatch")
)

Functions

This section is empty.

Types

type ErrNotMultiple

type ErrNotMultiple struct {
	Len int
}

func (ErrNotMultiple) Error

func (e ErrNotMultiple) Error() string

type Mode

type Mode interface {
	WriteMsg([]byte) error // this is not same as the io.Writer
	ReadMsg() ([]byte, error)
	// contains filtered or unexported methods
}

Mode is an interface that defines how the connection sides determine the size of transmitted messages. Unlike HTTP or UDP connections, raw TCP connections and WebSockets don't have a standard way to determine the size of transmitted or received messages. Their main purpose is to transmit bytes in the correct order. Mode allows the connection sides to avoid analyzing traffic or using end-of-message sequences.

In the MTProto world, Mode acts like a microprotocol. It packages messages in a container that announces its size in advance.

func Detect

func Detect(conn io.ReadWriter) (Mode, error)

Detect detects mode based on first byte sequence returned from conn

func New

func New(v Variant, conn io.ReadWriter) (Mode, error)

type Variant

type Variant uint8
const (
	Abridged Variant = iota
	Intermediate
	PaddedIntermediate
	Full
)

func GetVariant

func GetVariant(m Mode) (Variant, error)

Jump to

Keyboard shortcuts

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