Skip to content

Commit

Permalink
Add UpdatesGetStateParams struct and make request to server on reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Mar 22, 2024
1 parent 3f9bfc8 commit a7ed9c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion mtproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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 + "] - <TcpInt> ...")
m.Logger.Debug("packet read error, reconnecting to [" + m.Addr + "] - <TcpInt> ...")
err = m.Reconnect(false)
if err != nil {
m.Logger.Error(errors.Wrap(err, "reconnecting"))
Expand Down

0 comments on commit a7ed9c1

Please sign in to comment.