mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
put buffer into client session as allocation optimization
This commit is contained in:
parent
a89ff38fe6
commit
09b601528b
@ -39,6 +39,8 @@ type ClientSession struct {
|
|||||||
responseBodyIV [16]byte
|
responseBodyIV [16]byte
|
||||||
responseReader io.Reader
|
responseReader io.Reader
|
||||||
responseHeader byte
|
responseHeader byte
|
||||||
|
|
||||||
|
buffer [33]byte // 16 + 16 + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var clientSessionPool = sync.Pool{
|
var clientSessionPool = sync.Pool{
|
||||||
@ -47,10 +49,11 @@ var clientSessionPool = sync.Pool{
|
|||||||
|
|
||||||
// NewClientSession creates a new ClientSession.
|
// NewClientSession creates a new ClientSession.
|
||||||
func NewClientSession(idHash protocol.IDHash) *ClientSession {
|
func NewClientSession(idHash protocol.IDHash) *ClientSession {
|
||||||
randomBytes := make([]byte, 33) // 16 + 16 + 1
|
session := clientSessionPool.Get().(*ClientSession)
|
||||||
|
|
||||||
|
randomBytes := session.buffer[:]
|
||||||
common.Must2(rand.Read(randomBytes))
|
common.Must2(rand.Read(randomBytes))
|
||||||
|
|
||||||
session := clientSessionPool.Get().(*ClientSession)
|
|
||||||
copy(session.requestBodyKey[:], randomBytes[:16])
|
copy(session.requestBodyKey[:], randomBytes[:16])
|
||||||
copy(session.requestBodyIV[:], randomBytes[16:32])
|
copy(session.requestBodyIV[:], randomBytes[16:32])
|
||||||
session.responseHeader = randomBytes[32]
|
session.responseHeader = randomBytes[32]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user