transport

package
v0.50.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 15 Imported by: 14

Documentation

Overview

Package transport contains different MTProto transport implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Abridged is abridged transport protocol.
	//
	// See https://core.telegram.org/mtproto/mtproto-transports#abridged
	Abridged = NewProtocol(func() Codec { return codec.Abridged{} })

	// Intermediate is intermediate transport protocol.
	//
	// See https://core.telegram.org/mtproto/mtproto-transports#intermediate
	Intermediate = NewProtocol(func() Codec { return codec.Intermediate{} })

	// PaddedIntermediate is padded intermediate transport protocol.
	//
	// See https://core.telegram.org/mtproto/mtproto-transports#padded-intermediate
	PaddedIntermediate = NewProtocol(func() Codec { return codec.PaddedIntermediate{} })

	// Full is full transport protocol.
	//
	// See https://core.telegram.org/mtproto/mtproto-transports#full
	Full = NewProtocol(func() Codec { return &codec.Full{} })
)

Telegram transport protocols.

See https://core.telegram.org/mtproto/mtproto-transports

Functions

func WebsocketListener added in v0.50.0

func WebsocketListener(addr net.Addr) (net.Listener, http.Handler)

WebsocketListener creates new MTProto Websocket listener.

Types

type Codec

type Codec interface {
	// WriteHeader sends protocol tag if needed.
	WriteHeader(w io.Writer) error
	// ReadHeader reads protocol tag if needed.
	ReadHeader(r io.Reader) error
	// Write encode to writer message from given buffer.
	Write(w io.Writer, b *bin.Buffer) error
	// Read fills buffer with received message.
	Read(r io.Reader, b *bin.Buffer) error
}

Codec is MTProto transport protocol encoding abstraction.

type Conn added in v0.12.0

type Conn interface {
	Send(ctx context.Context, b *bin.Buffer) error
	Recv(ctx context.Context, b *bin.Buffer) error
	Close() error
}

Conn is transport connection.

type Listener added in v0.50.0

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

Listener is a simple net.Listener wrapper for listening MTProto transport connections.

func Listen added in v0.50.0

func Listen(listener net.Listener) Listener

Listen creates new Listener using given net.Listener. Transport codec will be detected automatically.

func ListenCodec added in v0.50.0

func ListenCodec(codec func() Codec, listener net.Listener) Listener

ListenCodec creates new Listener using given net.Listener. Listener will always use given Codec constructor.

func (Listener) Accept added in v0.50.0

func (l Listener) Accept() (_ Conn, rErr error)

Accept waits for and returns the next connection to the listener.

func (Listener) Addr added in v0.50.0

func (l Listener) Addr() net.Addr

Addr returns the listener's network address.

func (Listener) Close added in v0.50.0

func (l Listener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

type Protocol added in v0.33.0

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

Protocol is MTProto transport protocol.

See https://core.telegram.org/mtproto/mtproto-transports

func NewProtocol added in v0.33.0

func NewProtocol(getCodec func() Codec) Protocol

NewProtocol creates new transport protocol using user Codec constructor.

See https://core.telegram.org/mtproto/mtproto-transports

func (Protocol) Codec added in v0.33.0

func (p Protocol) Codec() Codec

Codec creates new codec using protocol settings.

func (Protocol) Handshake added in v0.33.0

func (p Protocol) Handshake(conn net.Conn) (Conn, error)

Handshake inits given net.Conn as MTProto connection.

func (Protocol) Pipe added in v0.33.0

func (p Protocol) Pipe() (a, b Conn)

Pipe creates an in-memory MTProto connection.

Jump to

Keyboard shortcuts

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