Inheritance: IDisposable
Example #1
0
		public static async Task<Step3_Response> DoAuthentication(TcpTransport transport)
		{
			var sender = new MtProtoPlainSender(transport);
			var step1 = new Step1_PQRequest();

			await sender.Send(step1.ToBytes());
			var step1Response = step1.FromBytes(await sender.Recieve());

			var step2 = new Step2_DHExchange();
			await sender.Send(step2.ToBytes(
				step1Response.Nonce,
				step1Response.ServerNonce,
				step1Response.Fingerprints,
				step1Response.Pq));

			var step2Response = step2.FromBytes(await sender.Recieve());

			var step3 = new Step3_CompleteDHExchange();
			await sender.Send(step3.ToBytes(
				step2Response.Nonce,
				step2Response.ServerNonce,
				step2Response.NewNonce,
				step2Response.EncryptedAnswer));

			var step3Response = step3.FromBytes(await sender.Recieve());

			return step3Response;
		}
Example #2
0
        private async Task ReconnectToDc(int dcId)
        {
            if (dcOptions == null || !dcOptions.Any())
                throw new InvalidOperationException($"Can't reconnect. Establish initial connection first.");

            var dc = dcOptions.Cast<DcOptionConstructor>().First(d => d.id == dcId);

            _transport = new TcpTransport(dc.ip_address, dc.port);
            _session.ServerAddress = dc.ip_address;
            _session.Port = dc.port;

            await Connect(true);
        }
		public async Task AuthenticationWorks()
		{
			using (var transport = new TcpTransport())
			{
				var authKey = await Authenticator.DoAuthentication(transport);

				Assert.IsNotNull(authKey.AuthKey.Data);
			}
		}
Example #4
0
 public MtProtoPlainSender(TcpTransport transport)
 {
     _transport = transport;
     random = new Random();
 }
Example #5
0
 public MtProtoSender(TcpTransport transport, Session session)
 {
     this.transport = transport;
     this.session   = session;
 }
 public MtProtoPlainSender(TcpTransport transport)
 {
     this.transport = transport;
     random         = new Random();
 }
Example #7
0
 public void ChangeTransport(TcpTransport transport)
 {
     _transport = transport;
 }
Example #8
0
 public MtProtoSender(TcpTransport transport, Session session)
 {
     _transport = transport;
     _session   = session;
 }
Example #9
0
		public void ChangeTransport(TcpTransport transport)
		{
			_transport = transport;
		}
Example #10
0
		public MtProtoSender(TcpTransport transport, Session session)
		{
			_transport = transport;
			_session = session;
		}
        bool HandleRpcResult(ulong messageId, int sequence, BinaryReader messageReader, MTProtoRequest request)
        {
            uint  code      = messageReader.ReadUInt32();
            ulong requestId = messageReader.ReadUInt64();

            if (requestId == (ulong)request.MessageId)
            {
                request.ConfirmReceived = true;
            }

            //throw new NotImplementedException();

            /*
             * lock (runningRequests)
             * {
             *      if (!runningRequests.ContainsKey(requestId))
             *      {
             *              logger.warning("rpc response on unknown request: {0}", requestId);
             *              messageReader.BaseStream.Position -= 12;
             *              return false;
             *      }
             *
             *      request = runningRequests[requestId];
             *      runningRequests.Remove(requestId);
             * }
             */

            uint innerCode = messageReader.ReadUInt32();

            if (innerCode == 0x2144ca19)
            {             // rpc_error
                int    errorCode    = messageReader.ReadInt32();
                string errorMessage = Serializers.String.Read(messageReader);

                if (errorMessage.StartsWith("FLOOD_WAIT_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var seconds      = int.Parse(resultString);
                    Debug.WriteLine($"Should wait {seconds} sec.");
                    Thread.Sleep(1000 * seconds);
                }
                else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
                {
                    var resultString = Regex.Match(errorMessage, @"\d+").Value;
                    var dcIdx        = int.Parse(resultString);
                    TcpTransport.UpdateDC(dcIdx);
                }
                else if (errorMessage.StartsWith("FILE_MIGRATE_"))
                {
                    // no need to worry! file is in another dc
                }
                else if (errorMessage.StartsWith("CHANNEL_INVALID"))
                {
                    // no need to worry! just skip this message
                }
                else
                {
                    throw new InvalidOperationException(errorMessage);
                }
            }
            else if (innerCode == 0x3072cfa1)
            {
                // gzip_packed
                byte[] packedData = Serializers.Bytes.Read(messageReader);
                using (MemoryStream packedStream = new MemoryStream(packedData, false))
                    using (GZipStream zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
                        using (BinaryReader compressedReader = new BinaryReader(zipStream))
                        {
                            request.OnResponse(compressedReader);
                        }
            }
            else
            {
                messageReader.BaseStream.Position -= 4;

                request.OnResponse(messageReader);
            }

            return(false);
        }
Example #12
-1
        public TelegramClient(ISessionStore store, string sessionUserId)
		{
			if (_apiId == 0)
				throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");

			if (string.IsNullOrEmpty(_apiHash))
				throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");

			_transport = new TcpTransport();
			_session = Session.TryLoadOrCreateNew(store, sessionUserId);
		}
Example #13
-1
		public TelegramClient(ISessionStore store, string sessionUserId)
		{
			_transport = new TcpTransport();
			_session = Session.TryLoadOrCreateNew(store, sessionUserId);
		}