fix: sync protocol and discussion stability fixes
This commit is contained in:
parent
9f73dc20da
commit
aa21bd04e1
43 changed files with 7258 additions and 503 deletions
|
|
@ -43,3 +43,50 @@ func TestNewSessionCreatedUniqueIDPerSession(t *testing.T) {
|
|||
t.Fatalf("new_session_created.unique_id reused across sessions: %d", created1.UniqueID)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewSessionCreatedMovesFloorForLaterLowerMessage locks the MTProto rule
|
||||
// that a server-side session must publish a fresh boundary notification when it
|
||||
// later accepts a smaller logical client msg_id. Official clients use this
|
||||
// boundary to decide which requests must be regenerated and resent.
|
||||
func TestNewSessionCreatedMovesFloorForLaterLowerMessage(t *testing.T) {
|
||||
const dc = 2
|
||||
addr, pub, _ := startTestServer(t, Options{DC: dc})
|
||||
conn, auth, cipher := dialHandshake(t, addr, dc, pub)
|
||||
|
||||
freshIDs := proto.NewMessageIDGen(time.Now)
|
||||
firstMsgID := freshIDs.New(proto.MessageFromClient)
|
||||
sendEncryptedWithSeq(t, conn, cipher, auth, firstMsgID, 0, &mt.HTTPWaitRequest{
|
||||
MaxDelay: 0,
|
||||
WaitAfter: 0,
|
||||
MaxWait: 25_000,
|
||||
})
|
||||
first := collectReplies(t, conn, cipher, auth.AuthKey, mt.NewSessionCreatedTypeID)
|
||||
var created1 mt.NewSessionCreated
|
||||
if err := created1.Decode(mustHave(t, first, mt.NewSessionCreatedTypeID, "first new_session_created")); err != nil {
|
||||
t.Fatalf("decode first new_session_created: %v", err)
|
||||
}
|
||||
if created1.FirstMsgID != firstMsgID {
|
||||
t.Fatalf("first boundary = %d, want %d", created1.FirstMsgID, firstMsgID)
|
||||
}
|
||||
|
||||
oldIDs := proto.NewMessageIDGen(func() time.Time { return time.Now().Add(-10 * time.Minute) })
|
||||
lowerMsgID := oldIDs.New(proto.MessageFromClient)
|
||||
outerMsgID := freshIDs.New(proto.MessageFromClient)
|
||||
pingBody := mustEncodeTL(t, &mt.PingRequest{PingID: 99})
|
||||
sendEncrypted(t, conn, cipher, auth, outerMsgID, &proto.MessageContainer{
|
||||
Messages: []proto.Message{{
|
||||
ID: lowerMsgID, SeqNo: 1, Bytes: len(pingBody), Body: pingBody,
|
||||
}},
|
||||
})
|
||||
second := collectReplies(t, conn, cipher, auth.AuthKey, mt.PongTypeID)
|
||||
var created2 mt.NewSessionCreated
|
||||
if err := created2.Decode(mustHave(t, second, mt.NewSessionCreatedTypeID, "lower-boundary new_session_created")); err != nil {
|
||||
t.Fatalf("decode lower-boundary new_session_created: %v", err)
|
||||
}
|
||||
if created2.FirstMsgID != lowerMsgID {
|
||||
t.Fatalf("lower boundary = %d, want %d", created2.FirstMsgID, lowerMsgID)
|
||||
}
|
||||
if created2.UniqueID == created1.UniqueID {
|
||||
t.Fatalf("lower-boundary notification reused unique_id %d", created2.UniqueID)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue