| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package client
-
- import (
- "context"
- "net"
-
- "github.com/9seconds/mtg/antireplay"
- "github.com/9seconds/mtg/config"
- "github.com/9seconds/mtg/mtproto"
- "github.com/9seconds/mtg/wrappers"
- )
-
- // MiddleInit initializes client connection for proxy which has to
- // support promoted channels, connect to Telegram middle proxies etc.
- func MiddleInit(ctx context.Context, cancel context.CancelFunc, socket net.Conn,
- connID string, antiReplayCache antireplay.Cache,
- conf *config.Config) (wrappers.Wrap, *mtproto.ConnectionOpts, error) {
- conn, opts, err := DirectInit(ctx, cancel, socket, connID, antiReplayCache, conf)
- if err != nil {
- return nil, nil, err
- }
- connStream := conn.(wrappers.StreamReadWriteCloser)
-
- var newConn wrappers.PacketReadWriteCloser
- switch opts.ConnectionType {
- case mtproto.ConnectionTypeAbridged:
- newConn = wrappers.NewMTProtoAbridged(connStream, opts)
- case mtproto.ConnectionTypeIntermediate:
- newConn = wrappers.NewMTProtoIntermediate(connStream, opts)
- case mtproto.ConnectionTypeSecure:
- newConn = wrappers.NewMTProtoIntermediateSecure(connStream, opts)
- default:
- panic("Unknown connection type")
- }
-
- opts.ConnectionProto = mtproto.ConnectionProtocolIPv4
- if socket.LocalAddr().(*net.TCPAddr).IP.To4() == nil {
- opts.ConnectionProto = mtproto.ConnectionProtocolIPv6
- }
-
- return newConn, opts, err
- }
|