async Task<TgConnection> EstablishForkConnection(TgConnection srcConn, int dcId) { var ep = DcInfoKeeper.FindEndpoint(dcId); var connectInfo = ConnectInfo.FromInfo(srcConn.Session.Get().ApiId, ep); var dstConn = await TgConnectionEstablisher.EstablishConnection(connectInfo, _callMiddlewareChain, _connHandler); await TryExportAuth(srcConn, dstConn); return dstConn; }
public static async Task <TgConnection> EstablishConnection( ILogger logger, ConnectInfo connectInfo, TgCallMiddlewareChain callMiddlewareChain, TcpClientConnectionHandler?connHandler = null ) { var endpoint = connectInfo.Endpoint; Helpers.Assert(endpoint != null, "endpoint == null"); var tcpClient = await CreateTcpClient(endpoint !, connHandler).ConfigureAwait(false); var tcpTransport = new TcpTransport(tcpClient); if (connectInfo.NeedsInAuth) { var mtPlainTransport = new MtProtoPlainTransport(tcpTransport); var result = await Authenticator.DoAuthentication(mtPlainTransport).ConfigureAwait(false); connectInfo.SetAuth(result); } var session = connectInfo.ToSession().AsVar(); var mtCipherTransport = new MtProtoCipherTransport(tcpTransport, session); var transport = new TgCustomizedTransport(new TgTransport(logger, mtCipherTransport, session), callMiddlewareChain); // TODO: separate Config var config = new GetConfig(); var request = new InitConnection <GetConfig, Config>( apiId: session.Get().ApiId, appVersion: "1.0.0", deviceModel: "PC", langCode: "en", query: config, systemVersion: "Win 10.0", systemLangCode: "en", langPack: "tdesktop", proxy: null, @params: null ); var invokeWithLayer = new InvokeWithLayer <InitConnection <GetConfig, Config>, Config>( layer: SchemeInfo.LayerVersion, query: request ); var cfg = await transport.Call(invokeWithLayer).ConfigureAwait(false); DcInfoKeeper.Update(cfg); return(new TgConnection(session, transport, cfg)); }