Fix wechat protocol is not working if no obfs string is configured

This commit is contained in:
Brian Ma 2022-09-01 17:46:19 +08:00
parent f7de18fd43
commit f22705be2c
4 changed files with 30 additions and 14 deletions

View File

@ -25,10 +25,13 @@ type ObfsWeChatUDPConn struct {
sn uint32
}
func NewObfsWeChatUDPConn(orig *net.UDPConn, obfs obfs.Obfuscator) *ObfsWeChatUDPConn {
func NewObfsWeChatUDPConn(orig *net.UDPConn, obfs_ obfs.Obfuscator) *ObfsWeChatUDPConn {
if obfs_ == nil {
obfs_ = obfs.NewDummyObfuscator()
}
return &ObfsWeChatUDPConn{
orig: orig,
obfs: obfs,
obfs: obfs_,
readBuf: make([]byte, udpBufferSize),
writeBuf: make([]byte, udpBufferSize),
sn: rand.Uint32() & 0xFFFF,

21
pkg/obfs/dummy.go Normal file
View File

@ -0,0 +1,21 @@
package obfs
type DummyObfuscator struct{}
func NewDummyObfuscator() *DummyObfuscator {
return &DummyObfuscator{}
}
func (x *DummyObfuscator) Deobfuscate(in []byte, out []byte) int {
pLen := len(in)
if pLen <= 0 || len(out) < pLen {
// Invalid
return 0
}
copy(out, in)
return pLen
}
func (x *DummyObfuscator) Obfuscate(in []byte, out []byte) int {
return copy(out, in)
}

View File

@ -42,12 +42,8 @@ func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfs
if err != nil {
return nil, err
}
if obfs != nil {
oc := wechat.NewObfsWeChatUDPConn(conn, obfs)
return oc, nil
} else {
return conn, nil
}
oc := wechat.NewObfsWeChatUDPConn(conn, obfs)
return oc, nil
} else if proto == "faketcp" {
var conn *faketcp.TCPConn
conn, err := faketcp.Dial("tcp", server)

View File

@ -101,12 +101,8 @@ func (st *ServerTransport) quicPacketConn(proto string, laddr string, obfs obfs.
if err != nil {
return nil, err
}
if obfs != nil {
oc := wechat.NewObfsWeChatUDPConn(conn, obfs)
return oc, nil
} else {
return conn, nil
}
oc := wechat.NewObfsWeChatUDPConn(conn, obfs)
return oc, nil
} else if proto == "faketcp" {
conn, err := faketcp.Listen("tcp", laddr)
if err != nil {