Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI and unstable transport #41

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

aarani
Copy link

@aarani aarani commented May 12, 2021

Recently CI has been extremely buggy and unreliable, during extensive testing TCP Transport is identified as the culprit.
Errors like

System.InvalidOperationException : Couldn't read the packet length (was 0, expected 4)

that would happen because of force disconnections right after the first encrypted write.
For this reason and because the transport layer was long overdue for a rewrite we changed the transport to an asynchronous websocket transport + aes-ctr obfuscation

@omerjacobi
Copy link

@aarani do you know why the CI for windows still fails?

@aarani
Copy link
Author

aarani commented May 13, 2021

@aarani do you know why the CI for windows still fails?

nblockchain's CI sercrets needs an update, for checking out the actual CI result check the results on my fork.

@studasd
Copy link

studasd commented May 13, 2021

@aarani
New transport will work through proxy?

@aarani
Copy link
Author

aarani commented May 13, 2021

yeah, It's not implemented but with a simple code change you can use proxies.

@aarani aarani changed the title [WIP] Core,TL,Gen: Transport layer rewrite and bugfixes [DO NOT MERGE] Core,TL,Gen: Transport layer rewrite and bugfixes May 13, 2021
738a849 moves loading of "NumberToSendMessage" property
to SendMessage test even though there are 3 other tests
that use that variable thereby breaking all 3 tests
because of NumberToSendMessage being null.

This commit moves the load process back to init phase so
all 4 tests can use NumberToSendMessage.
@knocte
Copy link
Member

knocte commented May 18, 2021

Based on @Laiteux's testing, this commit might cause issues in .NET/.NET Core. These platforms are unsupported by us cause TgSharp is a .NET Framework library but I think it makes sense to fix it before merge

We can fix it later when we migrate to .NETCore/.NET5.

@Laiteux
Copy link

Laiteux commented May 18, 2021

That means I won't be able to keep using TgSharp anymore, since all my projects are .NET 5 or at least .NET Core 3.1. Honestly, who uses .NET Framework anymore...

Or then a second option would be to keep the TcpTransport and let the user decide what he wanna use, but that would introduce more complexity than anything else.

@knocte
Copy link
Member

knocte commented May 18, 2021

I won't be able to keep using TgSharp anymore

I said we will migrate, but no need to do it in this PR. The smallest this PR is the better, and the earlier we can start merging other PRs. We don't want this PR to become a monster.

@aarani
Copy link
Author

aarani commented May 18, 2021

Based on @Laiteux's testing, this commit might cause issues in .NET/.NET Core. These platforms are unsupported by us cause TgSharp is a .NET Framework library but I think it makes sense to fix it before merge

We can fix it later when we migrate to .NETCore/.NET5.

I agree! it's not our bug either, so we either have to try to fix our dependency and PR it or just use another websocket library which we can figure out after this gets merged

@aarani
Copy link
Author

aarani commented May 18, 2021

That means I won't be able to keep using TgSharp anymore, since all my projects are .NET 5 or at least .NET Core 3.1. Honestly, who uses .NET Framework anymore...

Or then a second option would be to keep the TcpTransport and let the user decide what he wanna use, but that would introduce more complexity than anything else.

It's just for this PR not permanent.

@Laiteux
Copy link

Laiteux commented May 19, 2021

This will fix the retry logic:

@@ -136,19 +128,20 @@ namespace TgSharp.Core.Network
             await client.SendInstant(finalInit);
         }

-        public async Task ConnectAsync(int retryCount = 5)
+        public async Task ConnectAsync(int retryCount = 0)
         {
-            while (retryCount-- != 0)
+            while (retryCount-- != -1)
             {
                 try
                 {
                     await InitializeClient();
                     break;
                 }
-                catch (Exception ex)
+                catch
                 {
-                    if (retryCount == 1)
-                        throw ex;
+                    if (retryCount == -1)
+                        throw;
+
                     await Task.Delay(1000);
                 }
             }

I don't have access to this repo therefore I can't do the changes myself for now.

@aarani aarani force-pushed the rewritten-transport branch 2 times, most recently from f98b0d4 to 7326527 Compare May 19, 2021 08:46
As long as we create a new sessionId for every connection,
(by randomizing the sessionId) seqNo can start from 0
and we don't have to save it. This prevents errors
like code=32 that are caused by wrong seqNo from happening.

This commit also removes the previous workaround that was
used on CI to prevent these errors cause they are no longer
necessary.
@knocte
Copy link
Member

knocte commented May 19, 2021

CI is broken now in your branch.

@aarani
Copy link
Author

aarani commented May 19, 2021

CI is broken now in your branch.

because my session is now broken

@knocte
Copy link
Member

knocte commented May 20, 2021

because my session is now broken

Let's fix that before you change the retryCount.

@omerjacobi
Copy link

any update on this PR?

 - add response type as generic

namespace TgSharp.Core.Network
{
public class Message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarani nit, should this be internal too?


uint code = messageReader.ReadUInt32();
ulong badMsgId = messageReader.ReadUInt64();
_ = messageReader.ReadUInt32();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in HandlePong, you have put a comment explaining why this is ignored (_), can you put a comment here too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all those comments are mostly old I just ignored some of the unused variables

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's easy to figure out from looking at the spec again for a minute?

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do all TgSharp consumers need this bindingRedirect now?

Copy link
Author

@aarani aarani May 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know to be honest, I don't think so though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is the case, this is a big annoyance... I wonder if we can fix it

  - Upgrade .NET to 4.7.2 to use .NET Standard dependency
    Reason:
      https://docs.microsoft.com/en-us/dotnet/standard/net-standard
  - Uses obfuscated WebSocket transport instead of TCP
  - Adds asynchronous response handling
@knocte
Copy link
Member

knocte commented May 26, 2021

Last but not least, I'm having trouble finding the MS docs where it recommends to use underscores in method names.

@aarani
Copy link
Author

aarani commented May 26, 2021

Last but not least, I'm having trouble finding the MS docs where it recommends to use underscores in method names.

which methods are you talking about ?

@aarani
Copy link
Author

aarani commented May 26, 2021

Last but not least, I'm having trouble finding the MS docs where it recommends to use underscores in method names.

I can't find the original documentation for it, but event handler name Object_EventName is a fairly old convention.

https://docs.microsoft.com/en-us/dotnet/desktop/winforms/event-handlers-overview-windows-forms?view=netframeworkdesktop-4.8

also VS creates event handlers with this same exact naming scheme

@omerjacobi
Copy link

any update?

@Laiteux
Copy link

Laiteux commented Sep 8, 2022

any update?

Nope, and there will never be. Because knocte always had a urge to control every single misplaced comma or underscore despite wanting to take the lead on open-source projects. Hopefully one day he understands you can't have a desire to lead people and a compulsive behavior to "optimize" everyone's code. I would have loved too as well, sadly you'll never see this PR being merged, mainly for that reason. Everyone eventually got tired and that's it, that's why this project is dead. Props to @aarani for his crazy work on everything else and from the very beginning, without that dude I probably wouldn't even be earning a living the way I'm doing it today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants