-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
handle_bad_msg.go
68 lines (58 loc) · 1.52 KB
/
handle_bad_msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package mtproto
import (
"fmt"
"golang.org/x/xerrors"
"github.com/gotd/td/bin"
"github.com/gotd/td/internal/mt"
)
type badMessageError struct {
Code int
NewSalt int64
}
const (
codeMessageIDTooLow = 16
codeMessageIDTooHigh = 17
codeIncorrectServerSalt = 48
)
func (c badMessageError) Error() string {
description := map[int]string{
codeMessageIDTooLow: "msg_id too low",
codeMessageIDTooHigh: "msg_id too high",
codeIncorrectServerSalt: "incorrect server salt",
18: "incorrect two lower order msg_id bits",
19: "container msg_id is the same as msg_id of a previously received message",
20: "message too old",
32: "msg_seqno too low",
33: "msg_seqno too high",
34: "even msg_seqno expected, but odd received",
35: "odd msg_seqno expected, but even received",
}[c.Code]
if description == "" {
return fmt.Sprintf("bad msg error code %d", c.Code)
}
return description
}
func (c *Conn) handleBadMsg(b *bin.Buffer) error {
id, err := b.PeekID()
if err != nil {
return err
}
switch id {
case mt.BadMsgNotificationTypeID:
var bad mt.BadMsgNotification
if err := bad.Decode(b); err != nil {
return err
}
c.rpc.NotifyError(bad.BadMsgID, &badMessageError{Code: bad.ErrorCode})
return nil
case mt.BadServerSaltTypeID:
var bad mt.BadServerSalt
if err := bad.Decode(b); err != nil {
return err
}
c.rpc.NotifyError(bad.BadMsgID, &badMessageError{Code: bad.ErrorCode, NewSalt: bad.NewServerSalt})
return nil
default:
return xerrors.Errorf("unknown type id 0x%d", id)
}
}