From d15966c76c5ad14de4f9d8a55b8cd6b56592a335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Fri, 16 Oct 2026 13:12:52 +0800 Subject: [PATCH] Fixes: Regard int() as int32() by default, which should be a coding standard (#7155) https://github.com/XTLS/Xray-core/pull/7155#issuecomment-6208455069 Fixes https://github.com/XTLS/Xray-core/pull/7148#issuecomment-6173633056 --------- Co-authored-by: Denis Orlov Co-authored-by: Milomilo777 <117558067+Milomilo777@users.noreply.github.com> --- app/observatory/burst/healthping_result.go | 2 +- proxy/shadowsocks_2022/packet.go | 2 +- proxy/shadowsocks_2022/replay.go | 4 ++-- proxy/shadowsocks_2022/stream.go | 4 ++-- transport/internet/xdrive/drive.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/observatory/burst/healthping_result.go b/app/observatory/burst/healthping_result.go index 4759c5e32..6ba5720d9 100644 --- a/app/observatory/burst/healthping_result.go +++ b/app/observatory/burst/healthping_result.go @@ -109,7 +109,7 @@ func (h *HealthPingRTTS) getStatistics() *HealthPingStats { stats.Min = 0 return stats } - stats.Average = time.Duration(int(sum) / cnt) + stats.Average = sum / time.Duration(cnt) var std float64 if cnt < 2 { // no enough data for standard deviation, we assume it's half of the average rtt diff --git a/proxy/shadowsocks_2022/packet.go b/proxy/shadowsocks_2022/packet.go index f81754575..310d3d7bd 100644 --- a/proxy/shadowsocks_2022/packet.go +++ b/proxy/shadowsocks_2022/packet.go @@ -153,7 +153,7 @@ func parsePlainUDPPacket(sessionID, packetID uint64, bodyPlain []byte) (DecodedU return DecodedUDPPacket{}, ErrBadHeaderType } epoch := binary.BigEndian.Uint64(bodyPlain[1:9]) - diff := int(math.Abs(float64(time.Now().Unix() - int64(epoch)))) + diff := math.Abs(float64(time.Now().Unix() - int64(epoch))) if diff > 30 { return DecodedUDPPacket{}, ErrBadTimestamp } diff --git a/proxy/shadowsocks_2022/replay.go b/proxy/shadowsocks_2022/replay.go index 241eb053c..056acbb2f 100644 --- a/proxy/shadowsocks_2022/replay.go +++ b/proxy/shadowsocks_2022/replay.go @@ -49,12 +49,12 @@ func (f *SlidingWindow) Add(counter uint64) { if counter > f.last { lastBlockIndex := f.last >> swBlockBitLog - diff := int(blockIndex - lastBlockIndex) + diff := blockIndex - lastBlockIndex if diff > swRingBlocks { diff = swRingBlocks } - for i := 0; i < diff; i++ { + for i := 0; i < int(diff); i++ { lastBlockIndex = (lastBlockIndex + 1) & swBlockMask f.ring[lastBlockIndex] = 0 } diff --git a/proxy/shadowsocks_2022/stream.go b/proxy/shadowsocks_2022/stream.go index 4de3b3605..14941636b 100644 --- a/proxy/shadowsocks_2022/stream.go +++ b/proxy/shadowsocks_2022/stream.go @@ -254,7 +254,7 @@ func ReadClientRequestHeaderWithFixed(reader *StreamReader, fixedChunk []byte) ( } epoch := binary.BigEndian.Uint64(plainFixed[1:9]) - diff := int(math.Abs(float64(time.Now().Unix() - int64(epoch)))) + diff := math.Abs(float64(time.Now().Unix() - int64(epoch))) if diff > 30 { return nil, ErrBadTimestamp } @@ -431,7 +431,7 @@ func ReadTCPResponse(r io.Reader, method *CipherMethod, psk []byte, clientSalt [ } serverEpoch := binary.BigEndian.Uint64(decryptedFixed[1:9]) - diff := int(math.Abs(float64(time.Now().Unix() - int64(serverEpoch)))) + diff := math.Abs(float64(time.Now().Unix() - int64(serverEpoch))) if diff > 30 { return nil, ErrBadTimestamp } diff --git a/transport/internet/xdrive/drive.go b/transport/internet/xdrive/drive.go index 43f34e2f4..d5da0cfb4 100644 --- a/transport/internet/xdrive/drive.go +++ b/transport/internet/xdrive/drive.go @@ -153,7 +153,7 @@ func jitter(backoff time.Duration) time.Duration { if half <= 0 { return backoff } - return half + time.Duration(dice.Roll(int(half))) + return half + time.Duration(dice.RollInt63n(int64(half))) } func rateLimited(payload []byte) bool {