transport

package
v0.42.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: MIT Imports: 9 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

This section is empty.

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 Handler

type Handler func(ctx context.Context, conn Conn) error

Handler is MTProto server connection handler.

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 a in-memory MTProto connection.

type Server

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

Server is a simple MTProto server.

func NewCustomServer

func NewCustomServer(c func() Codec, listener net.Listener) *Server

NewCustomServer creates new MTProto server with custom transport codec.

func NewFullServer added in v0.12.0

func NewFullServer(listener net.Listener) *Server

NewFullServer creates new MTProto server with Full transport codec.

func NewIntermediateServer

func NewIntermediateServer(listener net.Listener) *Server

NewIntermediateServer creates new MTProto server with Intermediate transport codec.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns server address.

func (*Server) Close

func (s *Server) Close() error

Close stops server and closes given listener.

func (*Server) Serve

func (s *Server) Serve(serveCtx context.Context, handler Handler) error

Serve runs server using given listener.

Jump to

Keyboard shortcuts

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