Skip to content

Commit e3d9a8e

Browse files
committed
fix: vision on vless encryption
1 parent 1ae050c commit e3d9a8e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

transport/vless/encryption/common.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type CommonConn struct {
2323
PreWrite []byte
2424
GCM *GCM
2525
PeerGCM *GCM
26-
PeerCache []byte
26+
input bytes.Reader // PeerCache
2727
}
2828

2929
func (c *CommonConn) Write(b []byte) (int, error) {
@@ -72,10 +72,8 @@ func (c *CommonConn) Read(b []byte) (int, error) {
7272
xorConn.PeerCTR = NewCTR(c.UnitedKey, serverRandom[16:])
7373
}
7474
}
75-
if len(c.PeerCache) != 0 {
76-
n := copy(b, c.PeerCache)
77-
c.PeerCache = c.PeerCache[n:]
78-
return n, nil
75+
if c.input.Len() > 0 {
76+
return c.input.Read(b)
7977
}
8078
h, l, err := ReadAndDecodeHeader(c.Conn) // l: 17~17000
8179
if err != nil {
@@ -110,7 +108,7 @@ func (c *CommonConn) Read(b []byte) (int, error) {
110108
return 0, err
111109
}
112110
if len(dst) > len(b) {
113-
c.PeerCache = dst[copy(b, dst):]
111+
c.input.Reset(dst[copy(b, dst):])
114112
dst = b // for len(dst)
115113
}
116114
return len(dst), nil

0 commit comments

Comments
 (0)