perf: sync protocol and core hardening updates

This commit is contained in:
A 2026-07-11 19:48:26 +08:00
parent 152fed3b87
commit 4390ebf5a9
283 changed files with 29231 additions and 2295 deletions

View file

@ -16,8 +16,21 @@ const (
sessionIDKey
userIDKey
invokeWithoutUpdatesKey
inboundRPCBytesKey
)
func withInboundRPCBytes(ctx context.Context, n int) context.Context {
if n < 0 {
n = 0
}
return context.WithValue(ctx, inboundRPCBytesKey, n)
}
func inboundRPCBytesFrom(ctx context.Context) int {
v, _ := ctx.Value(inboundRPCBytesKey).(int)
return v
}
const currentClientLayer = 227
var androidSDKVersionRE = regexp.MustCompile(`\bsdk\s+\d+\b`)
@ -153,6 +166,16 @@ func AuthKeyIDFrom(ctx context.Context) ([8]byte, bool) {
return v, ok
}
// rawAuthKeyIDForOrigin 返回用于 update/outbox 当前 session 排除的物理 raw key。
// 单测/非 edge 调用若没有注入 raw key,才回退业务 key;生产 Router context 两者都有。
func rawAuthKeyIDForOrigin(ctx context.Context) [8]byte {
if id, ok := RawAuthKeyIDFrom(ctx); ok {
return id
}
id, _ := AuthKeyIDFrom(ctx)
return id
}
// WithSessionID 在 ctx 注入调用方的 MTProto session_id。
func WithSessionID(ctx context.Context, id int64) context.Context {
return context.WithValue(ctx, sessionIDKey, id)