Skip to content

Commit

Permalink
Do not unpack first packets twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Dec 19, 2024
1 parent 418c0e4 commit 98988b0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions service/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,14 @@ func (a *association) HandlePacket(pkt []byte, lazySlice slicepool.LazySlice) {
return onet.NewConnectionError("ERR_CIPHER", "Failed to unpack data from client", err)
}

unpackStart := time.Now()
textData, err = shadowsocks.Unpack(nil, pkt, a.cryptoKey)
timeToCipher := time.Since(unpackStart)
a.ssm.AddCipherSearch(err == nil, timeToCipher)
if textData == nil {
// This is a subsequent packet. First packets are already decrypted as part of the
// initial access key search.
unpackStart := time.Now()
textData, err = shadowsocks.Unpack(nil, pkt, a.cryptoKey)
timeToCipher := time.Since(unpackStart)
a.ssm.AddCipherSearch(err == nil, timeToCipher)
}

if err != nil {
return onet.NewConnectionError("ERR_CIPHER", "Failed to unpack data from client", err)
Expand Down

0 comments on commit 98988b0

Please sign in to comment.