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

Core: don't load seqNo and sessionId on start #44

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:

- name: Run Tests
run: |
MSBuild -p:Configuration=Debug -p:CI=true src/TgSharp.sln
MSBuild -p:Configuration=Debug src/TgSharp.sln

certutil -decode encodedSession.dat src/TgSharp.Tests.NUnit/bin/Debug/session.dat
cp app.config src/TgSharp.Tests.NUnit/bin/Debug/TgSharp.Tests.NUnit.dll.config
Expand Down
7 changes: 0 additions & 7 deletions src/TgSharp.Core/FileSessionStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ public static Session FromBytes (byte [] buffer, ISessionStore store, string ses
using (var reader = new BinaryReader (stream)) {
var id = reader.ReadUInt64 ();
var sequence = reader.ReadInt32 ();

// we do this in CI when running tests so that the they can always use a
// higher sequence than previous run
#if CI
sequence = Session.CurrentTime();
#endif

var salt = reader.ReadUInt64 ();
var lastMessageId = reader.ReadInt64 ();
var timeOffset = reader.ReadInt32 ();
Expand Down
17 changes: 5 additions & 12 deletions src/TgSharp.Core/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using TgSharp.TL;
using TgSharp.Core.MTProto;
using TgSharp.Core.MTProto.Crypto;
using System.Security.Cryptography;

namespace TgSharp.Core
{
Expand Down Expand Up @@ -39,6 +40,10 @@ internal static Session TryLoadOrCreateNew (ISessionStore store, string sessionU
DataCenter = defaultDataCenter,
};
}
session.Sequence = 0;
byte[] randomSessionId = new byte[8];
RandomNumberGenerator.Create().GetNonZeroBytes(randomSessionId);
session.Id = BitConverter.ToUInt64(randomSessionId, 0);
return session;
}

Expand All @@ -55,18 +60,6 @@ public class Session
internal object Lock = new object ();

public int Sequence { get; set; }
#if CI
// see the same CI-wrapped assignment in .FromBytes(), but this one will become useful
// when we generate a new session.dat for CI again
= CurrentTime ();

// this is similar to the unixTime but rooted on the worst year of humanity instead of 1970
internal static int CurrentTime ()
{
return (int)DateTime.UtcNow.Subtract (new DateTime (2020, 1, 1)).TotalSeconds;
}
#endif

public string SessionUserId { get; set; }
internal DataCenter DataCenter { get; set; }
public AuthKey AuthKey { get; set; }
Expand Down
3 changes: 0 additions & 3 deletions src/TgSharp.Core/TgSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(CI)'=='true'">
<DefineConstants>$(DefineConstants);CI</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down