Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Connection problem with emirati number #935

Closed
solarin opened this issue Apr 9, 2020 · 18 comments
Closed

Connection problem with emirati number #935

solarin opened this issue Apr 9, 2020 · 18 comments

Comments

@solarin
Copy link
Contributor

solarin commented Apr 9, 2020

i can't manage to connect with my Emiratis telephone numbers.
i tried 2 numbers, both same problem, same exception.

System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
at System.IO.BinaryReader.ReadInt64()
at TLSharp.Core.Network.MtProtoPlainSender.d__6.MoveNext() in source\repos\TLSharp\TLSharp.Core\Network\MtProtoPlainSender.cs:line 51
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at TLSharp.Core.Auth.Authenticator.<DoAuthentication>d__0.MoveNext() in source\repos\TLSharp\TLSharp.Core\Auth\Authenticator.cs:line 39 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at TLSharp.Core.TelegramClient.d__13.MoveNext() in source\repos\TLSharp\TLSharp.Core\TelegramClient.cs:line 87
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at TLSharp.Core.TelegramClient.d__14.MoveNext() in source\repos\TLSharp\TLSharp.Core\TelegramClient.cs:line 150
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at TLSharp.Core.TelegramClient.d__15.MoveNext() in source\repos\TLSharp\TLSharp.Core\TelegramClient.cs:line 182
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at TLSharp.Core.TelegramClient.d__18.MoveNext() in source\repos\TLSharp\TLSharp.Core\TelegramClient.cs:line 213
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at test_console.Program.d__2.MoveNext() in source\repos\test-console\test-console\Program.cs:line 30

@solarin
Copy link
Contributor Author

solarin commented Apr 9, 2020

looks like that the big problem is happening with the DC 149.154.165.120

in fact, if i start the software with this default ip address, the migration to a new DC is not requested and the library immediately fails with the above exception

@aarani please help bro! thanks

@knocte
Copy link
Collaborator

knocte commented Apr 9, 2020

@solarin can you test this PR: #919 maybe it fixes this problem

@solarin
Copy link
Contributor Author

solarin commented Apr 9, 2020

@solarin can you test this PR: #919 maybe it fixes this problem

i don't know if it's because i am new to github or because the source repository was deleted, but i can't find it

@knocte
Copy link
Collaborator

knocte commented Apr 9, 2020

you could click on the diff and extract it as a patch

@solarin
Copy link
Contributor Author

solarin commented Apr 9, 2020

you could click on the diff and extract it as a patch

no luck, i have been trying for more than 1 hour, i am not able to download this thing. i give up. if @aarani is so kind to send me a copy, i'll be happy to try.

i even checked "see the repo at this time": https://github.com/sochix/TLSharp/tree/2d9aa26ba22702e64b356e98a1600c189482ce27
but then it can't be downloaded... do you know how to do it?

@knocte
Copy link
Collaborator

knocte commented Apr 9, 2020

Download this with curl or wget: https://github.com/sochix/TLSharp/commit/2d9aa26ba22702e64b356e98a1600c189482ce27.patch then apply it to your tree

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

error: TLSharp.Core/Network/TLClient.cs: already exists in working directory
error: patch failed: TLSharp.Core/Network/TcpTransport.cs:1
error: TLSharp.Core/Network/TcpTransport.cs: patch does not apply
error: patch failed: TLSharp.Core/TLSharp.Core.csproj:9
error: TLSharp.Core/TLSharp.Core.csproj: patch does not apply
error: patch failed: TLSharp.Core/packages.config:2
error: TLSharp.Core/packages.config: patch does not apply
error: patch failed: TLSharp.Tests.NUnit/TLSharp.Tests.NUnit.csproj:7
error: TLSharp.Tests.NUnit/TLSharp.Tests.NUnit.csproj: patch does not apply
error: patch failed: TLSharp.Tests.VS/TLSharp.Tests.VS.csproj:8
error: TLSharp.Tests.VS/TLSharp.Tests.VS.csproj: patch does not apply
error: patch failed: TLSharp.Tests/TLSharp.Tests.csproj:9
error: TLSharp.Tests/TLSharp.Tests.csproj: patch does not apply
error: patch failed: TeleSharp.Generator/App.config:1
error: TeleSharp.Generator/App.config: patch does not apply
error: patch failed: TeleSharp.Generator/TeleSharp.Generator.csproj:9
error: TeleSharp.Generator/TeleSharp.Generator.csproj: patch does not apply
error: patch failed: TeleSharp.TL/TeleSharp.TL.csproj:9
error: TeleSharp.TL/TeleSharp.TL.csproj: patch does not apply

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

by the way, this problem seems to be connected with DataCenter number 5. maybe also others, i don't know. dc4 is working fine

@knocte
Copy link
Collaborator

knocte commented Apr 10, 2020

error: TeleSharp.TL/TeleSharp.TL.csproj: patch does not apply

How are you applying the patch? git am or the patch command?

Anyway, regardless of this, what happens is that the 2d9aa26 commit needs to be applied into a previous commit, not current master. So, first, checkout this commit in your local clone: f24da2c, and after that, apply the patch.

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

git apply
ok let me see

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

same exception

Furthermore, there is a new bug in this code

   public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null)
        {
            //if (handler == null)
            //{
            var ipAddress = IPAddress.Parse(address);
            tcpClient = new TLClient(ipAddress, port, ReceiveMessage);
            tcpClient.ConnectAsync();
            //}
            //else
            //    tcpClient = handler(address, port);
        }

the call ConnectAsync might not end before someone calls send on the TcpTransport, causing an exception.

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

everything works if telegram migrates the communication to DC4. With other datacenters it doesn't work.
how is it possible that other data centers use a different protcol?

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

i think i understood why this is happening :D

let me see

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

image
because some data centers only accept media!

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

yes, filtering the MediaOnly also fixes the problem, but ReconnectToDcAsync should also be fixed because it creates a TcpTransport, then it calls ConnectAsync which basically reloads the session with the old datacenter address and recreates a new TcpTransport.

my proposed solution is that ReconnectToDcAsync does not recreate a TcpTransport, but saves the session after updating the new datacenter. then everything stays as it is.

this is compatible with #939 and/or #937

please @knocte check asap and let's address this boring issue. we need either #939 or #937 for this fix

@knocte
Copy link
Collaborator

knocte commented Apr 10, 2020

#939? you mean #931 right?

@knocte
Copy link
Collaborator

knocte commented Apr 10, 2020

my proposed solution is that ReconnectToDcAsync does not recreate a TcpTransport, but saves the session after updating the new datacenter. then everything stays as it is.

Not sure what you mean by this. When explaining changes to the code, it's better to post a diff than using prose.

filtering the MediaOnly also fixes the problem

You mean this change?:

@@ -111,17 +111,16 @@ namespace TLSharp.Core
             {
                 TLRequestExportAuthorization exportAuthorization = new TLRequestExportAuthorization() { DcId = dcId };
                 exported = await SendRequestAsync<TLExportedAuthorization>(exportAuthorization, token).ConfigureAwait(false);
             }
 
-            IEnumerable<TLDcOption> dcs;
+            IEnumerable<TLDcOption> dcs =
+                dcOptions.Where (d => d.Id == dcId && !d.MediaOnly);
             if (dcIpVersion == DataCenterIPVersion.OnlyIPv6)
-                dcs = dcOptions.Where(d => d.Id == dcId && d.Ipv6); // selects only ipv6 addresses 	
+                dcs = dcs.Where(d => d.Id == dcId && d.Ipv6);
             else if (dcIpVersion == DataCenterIPVersion.OnlyIPv4)
-                dcs = dcOptions.Where(d => d.Id == dcId && !d.Ipv6); // selects only ipv4 addresses
-            else
-                dcs = dcOptions.Where(d => d.Id == dcId); // any
+                dcs = dcs.Where(d => d.Id == dcId && !d.Ipv6);
 
             TLDcOption dc;
             if (dcIpVersion != DataCenterIPVersion.Default)
             {
                 if (!dcs.Any())

@solarin
Copy link
Contributor Author

solarin commented Apr 10, 2020

i just added

dcs = dcs.Where(d => !d.MediaOnly)

after all the if-else

but there is also the ReconnectToDcAsync to change. i'll make a pr later. if i am still alive. debugging this thing is more difficult than my project :D

@knocte knocte closed this as completed in 9a6e391 Apr 11, 2020
knocte pushed a commit to nblockchain/TgSharp that referenced this issue Apr 11, 2020
Fixes sochix#935

(This commit was brought from TLSharp [1] version 0.1.0.554.)

[1] sochix@9a6e391
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants