mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-07 09:53:58 +08:00
Fix: chunk size limit in tls obfs (#54)
* Fix: add chunkSize limit in TLSObfs * Chore: add length var for len(b)
This commit is contained in:
parent
3a527cdf0f
commit
27cdef3086
@ -14,6 +14,10 @@ func init() {
|
|||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
chunkSize = 1 << 14 // 2 ** 14 == 16 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
var bufPool = sync.Pool{New: func() interface{} { return make([]byte, 2048) }}
|
var bufPool = sync.Pool{New: func() interface{} { return make([]byte, 2048) }}
|
||||||
|
|
||||||
// TLSObfs is shadowsocks tls simple-obfs implementation
|
// TLSObfs is shadowsocks tls simple-obfs implementation
|
||||||
@ -75,8 +79,23 @@ func (to *TLSObfs) Read(b []byte) (int, error) {
|
|||||||
// type + ver = 3
|
// type + ver = 3
|
||||||
return to.read(b, 3)
|
return to.read(b, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (to *TLSObfs) Write(b []byte) (int, error) {
|
func (to *TLSObfs) Write(b []byte) (int, error) {
|
||||||
|
length := len(b)
|
||||||
|
for i := 0; i < length; i += chunkSize {
|
||||||
|
end := i + chunkSize
|
||||||
|
if end > length {
|
||||||
|
end = length
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := to.write(b[i:end])
|
||||||
|
if err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return length, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (to *TLSObfs) write(b []byte) (int, error) {
|
||||||
if to.firstRequest {
|
if to.firstRequest {
|
||||||
helloMsg := makeClientHelloMsg(b, to.server)
|
helloMsg := makeClientHelloMsg(b, to.server)
|
||||||
_, err := to.Conn.Write(helloMsg)
|
_, err := to.Conn.Write(helloMsg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user