Set correct simple ack

This commit is contained in:
9seconds
2018-07-09 07:49:28 +03:00
parent 6ea4f3dbc2
commit 71614ee615
2 changed files with 7 additions and 7 deletions
+6 -7
View File
@@ -44,7 +44,7 @@ func (m *MTProtoAbridged) Read() ([]byte, error) {
if _, err := io.CopyN(buf, m.conn, 1); err != nil {
return nil, errors.Annotate(err, "Cannot read message length")
}
msgLength := uint8(buf.Bytes()[0])
msgLength := uint32(buf.Bytes()[0])
buf.Reset()
m.logger.Debugw("Packet first byte",
@@ -59,27 +59,26 @@ func (m *MTProtoAbridged) Read() ([]byte, error) {
msgLength -= mtprotoAbridgedQuickAckLength
}
msgLength32 := uint32(msgLength)
if msgLength == mtprotoAbridgedSmallPacketLength {
if _, err := io.CopyN(buf, m.conn, 3); err != nil {
return nil, errors.Annotate(err, "Cannot read the correct message length")
}
number := utils.Uint24{}
copy(number[:], buf.Bytes())
msgLength32 = utils.FromUint24(number)
msgLength = utils.FromUint24(number)
}
msgLength32 *= 4
msgLength *= 4
m.logger.Debugw("Packet length",
"length", msgLength32,
"length", msgLength,
"simple_ack", m.opts.ReadHacks.SimpleAck,
"quick_ack", m.opts.ReadHacks.QuickAck,
"counter", m.readCounter,
)
buf.Reset()
buf.Grow(int(msgLength32))
if _, err := io.CopyN(buf, m.conn, int64(msgLength32)); err != nil {
buf.Grow(int(msgLength))
if _, err := io.CopyN(buf, m.conn, int64(msgLength)); err != nil {
return nil, errors.Annotate(err, "Cannot read message")
}
+1
View File
@@ -80,6 +80,7 @@ func (m *MTProtoProxy) readSimpleAck(data []byte) ([]byte, error) {
return nil, errors.Errorf("Incorrect data of simple ack: %d", len(data))
}
data = data[8:12]
m.req.Options.WriteHacks.SimpleAck = true
m.logger.Debugw("Read RPC_SIMPLE_ACK",
"counter", m.readCounter,