Documentation ¶
Overview ¶
Package tgtest provides test Telegram server for basic end-to-end tests.
Index ¶
- Constants
- func NewPrivateKey(k *rsa.PrivateKey) exchange.PrivateKey
- type Dispatcher
- func (d *Dispatcher) Fallback(h Handler) *Dispatcher
- func (d *Dispatcher) Handle(id uint32, h Handler) *Dispatcher
- func (d *Dispatcher) HandleFunc(id uint32, h func(server *Server, req *Request) error) *Dispatcher
- func (d *Dispatcher) OnMessage(server *Server, req *Request) error
- func (d *Dispatcher) Result(id uint32, msg bin.Encoder) *Dispatcher
- func (d *Dispatcher) Vector(id uint32, msgs ...bin.Encoder) *Dispatcher
- type Handler
- type HandlerFunc
- type Request
- type Server
- func (s *Server) ForceDisconnect(k Session)
- func (s *Server) Key() exchange.PublicKey
- func (s *Server) Send(ctx context.Context, k Session, t proto.MessageType, message bin.Encoder) error
- func (s *Server) SendAck(ctx context.Context, k Session, ids ...int64) error
- func (s *Server) SendBool(req *Request, r bool) error
- func (s *Server) SendErr(req *Request, e *tgerr.Error) error
- func (s *Server) SendEternalSalt(req *Request) error
- func (s *Server) SendFutureSalts(req *Request, salts ...mt.FutureSalt) error
- func (s *Server) SendGZIP(req *Request, msg bin.Encoder) error
- func (s *Server) SendPong(req *Request, pingID int64) error
- func (s *Server) SendResult(req *Request, msg bin.Encoder) error
- func (s *Server) SendUpdates(ctx context.Context, k Session, updates ...tg.UpdateClass) error
- func (s *Server) SendVector(req *Request, msgs ...bin.Encoder) error
- func (s *Server) Serve(ctx context.Context, l transport.Listener) error
- type ServerOptions
- type Session
Constants ¶
const ( // MessageServerResponse is a message type of RPC calls result. MessageServerResponse = proto.MessageServerResponse // MessageFromServer is a message type of server-side updates. MessageFromServer = proto.MessageFromServer )
Variables ¶
This section is empty.
Functions ¶
func NewPrivateKey ¶
func NewPrivateKey(k *rsa.PrivateKey) exchange.PrivateKey
NewPrivateKey creates new private key from RSA private key.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher is a plain handler to map requests by ID.
func (*Dispatcher) Fallback ¶
func (d *Dispatcher) Fallback(h Handler) *Dispatcher
Fallback sets fallback handler.
func (*Dispatcher) Handle ¶
func (d *Dispatcher) Handle(id uint32, h Handler) *Dispatcher
Handle sets handler for given TypeID.
func (*Dispatcher) HandleFunc ¶
func (d *Dispatcher) HandleFunc(id uint32, h func(server *Server, req *Request) error) *Dispatcher
HandleFunc sets handler for given TypeID.
func (*Dispatcher) OnMessage ¶
func (d *Dispatcher) OnMessage(server *Server, req *Request) error
OnMessage implements Handler
func (*Dispatcher) Result ¶
func (d *Dispatcher) Result(id uint32, msg bin.Encoder) *Dispatcher
Result sets constant result for given TypeID. NB: it uses rpc_result to pack given encoder.
func (*Dispatcher) Vector ¶
func (d *Dispatcher) Vector(id uint32, msgs ...bin.Encoder) *Dispatcher
Vector sets constant Vector result for given TypeID. NB: it uses rpc_result to pack generic vector with given encoders.
type Handler ¶
Handler is a RPC request handler.
func TestTransport ¶
TestTransport is a handler for testing MTProto transport.
func UnpackInvoke ¶
UnpackInvoke is a simple Handler middleware to unpack some Invoke*-like requests. Including:
tg.InvokeWithLayerRequest tg.InitConnectionRequest tg.InvokeWithoutUpdatesRequest
type HandlerFunc ¶
HandlerFunc is functional adapter for Handler.OnMessage method.
type Request ¶
type Request struct { // DC ID from server structure. // Used to make handler less stateful. DC int // Session is a user session. Session Session // MsgID is a message ID of RPC request. MsgID int64 // Buf contains RPC request Buf *bin.Buffer // RequestCtx is a request context. RequestCtx context.Context }
Request represents MTProto RPC request structure.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a MTProto server structure.
func NewServer ¶
func NewServer(key exchange.PrivateKey, handler Handler, opts ServerOptions) *Server
NewServer creates new Server.
func (*Server) ForceDisconnect ¶
ForceDisconnect forcibly disconnect user from server. It deletes MTProto session (session_id), but not auth key.
func (*Server) Send ¶
func (s *Server) Send(ctx context.Context, k Session, t proto.MessageType, message bin.Encoder) error
Send sends given message to user session k. Parameter t denotes MTProto message type. It should be MessageServerResponse or MessageFromServer.
func (*Server) SendBool ¶
SendBool sends RPC answer using given bool as result. Usually used in methods without explicit response.
func (*Server) SendEternalSalt ¶
SendEternalSalt sends response for mt.GetFutureSaltsRequest. It sends an `eternal` salt, which valid until maximum possible date.
func (*Server) SendFutureSalts ¶
func (s *Server) SendFutureSalts(req *Request, salts ...mt.FutureSalt) error
SendFutureSalts sends response for mt.GetFutureSaltsRequest.
func (*Server) SendResult ¶
SendResult sends RPC answer using msg as result.
func (*Server) SendUpdates ¶
SendUpdates sends given updates to user session k.
func (*Server) SendVector ¶
SendVector sends RPC answer using given vector as result.
type ServerOptions ¶
type ServerOptions struct { // DC ID of this server. Default to 2. DC int // Random is random source. Defaults to rand.Reader. Random io.Reader // Logger is instance of zap.Logger. No logs by default. Logger *zap.Logger // Codec constructor. // Defaults to nil (underlying transport server detects protocol automatically). Codec func() transport.Codec // Clock to use. Defaults to clock.System. Clock clock.Clock // MessageID generator. Creates a new proto.MessageIDGen by default. // Clock will be used for creation. MessageID mtproto.MessageIDSource // Types map, used in verbose logging of incoming message. Types *tmap.Map // ReadTimeout is a connection read timeout. ReadTimeout time.Duration // ReadTimeout is a connection write timeout. WriteTimeout time.Duration }
ServerOptions of Server.
type Session ¶
type Session struct { // ID is a Session ID. ID int64 // AuthKey is an attached key. AuthKey crypto.AuthKey }
Session represents connection session.
func (Session) MarshalLogObject ¶
func (s Session) MarshalLogObject(encoder zapcore.ObjectEncoder) error
MarshalLogObject implements zap.ObjectMarshaler.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package cluster contains Telegram multi-DC setup utilities.
|
Package cluster contains Telegram multi-DC setup utilities. |
Package services contains some Telegram services implemented for testing.
|
Package services contains some Telegram services implemented for testing. |
config
Package config contains config service implementation for tgtest server.
|
Package config contains config service implementation for tgtest server. |
file
Package file contains file service implementation for tgtest server.
|
Package file contains file service implementation for tgtest server. |