Skip to content

Commit eae9981

Browse files
committed
Core: remove seqNo and sessionId from session file
This commit randomizes SeqNo and SessionID on start this prevents some errors (code=32) also removes the previous workaround that was used on CI to prevent these errors.
1 parent 3151c23 commit eae9981

2 files changed

Lines changed: 2 additions & 26 deletions

File tree

src/TgSharp.Core/FileSessionStore.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ public static Session FromBytes (byte [] buffer, ISessionStore store, string ses
5252
{
5353
using (var stream = new MemoryStream (buffer))
5454
using (var reader = new BinaryReader (stream)) {
55-
var id = reader.ReadUInt64 ();
56-
var sequence = reader.ReadInt32 ();
57-
58-
// we do this in CI when running tests so that the they can always use a
59-
// higher sequence than previous run
60-
#if CI
61-
sequence = Session.CurrentTime();
62-
#endif
63-
6455
var salt = reader.ReadUInt64 ();
6556
var lastMessageId = reader.ReadInt64 ();
6657
var timeOffset = reader.ReadInt32 ();
@@ -80,9 +71,7 @@ public static Session FromBytes (byte [] buffer, ISessionStore store, string ses
8071

8172
return new Session () {
8273
AuthKey = new AuthKey (authData),
83-
Id = id,
8474
Salt = salt,
85-
Sequence = sequence,
8675
LastMessageId = lastMessageId,
8776
TimeOffset = timeOffset,
8877
SessionExpires = sessionExpires,
@@ -97,8 +86,6 @@ internal byte [] ToBytes (Session session)
9786
{
9887
using (var stream = new MemoryStream ())
9988
using (var writer = new BinaryWriter (stream)) {
100-
writer.Write (session.Id);
101-
writer.Write (session.Sequence);
10289
writer.Write (session.Salt);
10390
writer.Write (session.LastMessageId);
10491
writer.Write (session.TimeOffset);

src/TgSharp.Core/Session.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,12 @@ public class Session
5454
{
5555
internal object Lock = new object ();
5656

57-
public int Sequence { get; set; }
58-
#if CI
59-
// see the same CI-wrapped assignment in .FromBytes(), but this one will become useful
60-
// when we generate a new session.dat for CI again
61-
= CurrentTime ();
62-
63-
// this is similar to the unixTime but rooted on the worst year of humanity instead of 1970
64-
internal static int CurrentTime ()
65-
{
66-
return (int)DateTime.UtcNow.Subtract (new DateTime (2020, 1, 1)).TotalSeconds;
67-
}
68-
#endif
57+
public int Sequence { get; set; } = 0;
6958

7059
public string SessionUserId { get; set; }
7160
internal DataCenter DataCenter { get; set; }
7261
public AuthKey AuthKey { get; set; }
73-
public ulong Id { get; set; }
62+
public ulong Id { get; set; } = Utils.Helpers.GenerateRandomUlong();
7463
public ulong Salt { get; set; }
7564
public int TimeOffset { get; set; }
7665
public long LastMessageId { get; set; }

0 commit comments

Comments
 (0)