From a7ed9c1708b073a94955a8225092d87df1f588a6 Mon Sep 17 00:00:00 2001 From: AmarnathCJD Date: Fri, 22 Mar 2024 20:28:22 +0530 Subject: [PATCH] Add UpdatesGetStateParams struct and make request to server on reconnect --- internal/utils/utils.go | 6 ++++++ mtproto.go | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 2fe9279b..cf195675 100755 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -30,6 +30,12 @@ func (*PingParams) CRC() uint32 { return 0x7abe77ec } +type UpdatesGetStateParams struct{} + +func (*UpdatesGetStateParams) CRC() uint32 { + return 0xedd4882a +} + func GenerateMessageId(prevID int64, offset int64) int64 { const billion = 1000 * 1000 * 1000 unixnano := time.Now().UnixNano() + (offset * billion) diff --git a/mtproto.go b/mtproto.go index 7ae6684c..cdb5b7e1 100755 --- a/mtproto.go +++ b/mtproto.go @@ -388,6 +388,8 @@ func (m *MTProto) Reconnect(WithLogs bool) error { m.InvokeRequestWithoutUpdate(&utils.PingParams{ PingID: 123456789, }) + + m.MakeRequest(&utils.UpdatesGetStateParams{}) // to ask the server to send the updates return errors.Wrap(err, "recreating connection") } @@ -423,7 +425,7 @@ func (m *MTProto) startReadingResponses(ctx context.Context) { m.Logger.Error(errors.Wrap(err, "reconnecting")) } } else if strings.Contains(err.Error(), "required to reconnect!") { // network is not stable - m.Logger.Debug("unstable connection, reconnecting to [" + m.Addr + "] - ...") + m.Logger.Debug("packet read error, reconnecting to [" + m.Addr + "] - ...") err = m.Reconnect(false) if err != nil { m.Logger.Error(errors.Wrap(err, "reconnecting"))