mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-09 14:10:00 +00:00
Merge pull request #424 from DumAdudus/master
Fix wechat protocol is not working if no obfs string is configured
This commit is contained in:
commit
1d756528a8
18
pkg/obfs/dummy.go
Normal file
18
pkg/obfs/dummy.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package obfs
|
||||||
|
|
||||||
|
type DummyObfuscator struct{}
|
||||||
|
|
||||||
|
func NewDummyObfuscator() *DummyObfuscator {
|
||||||
|
return &DummyObfuscator{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DummyObfuscator) Deobfuscate(in []byte, out []byte) int {
|
||||||
|
if len(out) < len(in) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return copy(out, in)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DummyObfuscator) Obfuscate(in []byte, out []byte) int {
|
||||||
|
return copy(out, in)
|
||||||
|
}
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/HyNetwork/hysteria/pkg/conns/faketcp"
|
"github.com/HyNetwork/hysteria/pkg/conns/faketcp"
|
||||||
"github.com/HyNetwork/hysteria/pkg/conns/udp"
|
"github.com/HyNetwork/hysteria/pkg/conns/udp"
|
||||||
"github.com/HyNetwork/hysteria/pkg/conns/wechat"
|
"github.com/HyNetwork/hysteria/pkg/conns/wechat"
|
||||||
"github.com/HyNetwork/hysteria/pkg/obfs"
|
obfsPkg "github.com/HyNetwork/hysteria/pkg/obfs"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ var DefaultClientTransport = &ClientTransport{
|
|||||||
ResolvePreference: ResolvePreferenceDefault,
|
ResolvePreference: ResolvePreferenceDefault,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfs.Obfuscator) (net.PacketConn, error) {
|
func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfsPkg.Obfuscator) (net.PacketConn, error) {
|
||||||
if len(proto) == 0 || proto == "udp" {
|
if len(proto) == 0 || proto == "udp" {
|
||||||
conn, err := net.ListenUDP("udp", nil)
|
conn, err := net.ListenUDP("udp", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -42,12 +42,10 @@ func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfs
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if obfs != nil {
|
if obfs == nil {
|
||||||
oc := wechat.NewObfsWeChatUDPConn(conn, obfs)
|
obfs = obfsPkg.NewDummyObfuscator()
|
||||||
return oc, nil
|
|
||||||
} else {
|
|
||||||
return conn, nil
|
|
||||||
}
|
}
|
||||||
|
return wechat.NewObfsWeChatUDPConn(conn, obfs), nil
|
||||||
} else if proto == "faketcp" {
|
} else if proto == "faketcp" {
|
||||||
var conn *faketcp.TCPConn
|
var conn *faketcp.TCPConn
|
||||||
conn, err := faketcp.Dial("tcp", server)
|
conn, err := faketcp.Dial("tcp", server)
|
||||||
@ -65,7 +63,7 @@ func (ct *ClientTransport) quicPacketConn(proto string, server string, obfs obfs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ct *ClientTransport) QUICDial(proto string, server string, tlsConfig *tls.Config, quicConfig *quic.Config, obfs obfs.Obfuscator) (quic.Connection, error) {
|
func (ct *ClientTransport) QUICDial(proto string, server string, tlsConfig *tls.Config, quicConfig *quic.Config, obfs obfsPkg.Obfuscator) (quic.Connection, error) {
|
||||||
serverUDPAddr, err := net.ResolveUDPAddr("udp", server)
|
serverUDPAddr, err := net.ResolveUDPAddr("udp", server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/HyNetwork/hysteria/pkg/conns/faketcp"
|
"github.com/HyNetwork/hysteria/pkg/conns/faketcp"
|
||||||
"github.com/HyNetwork/hysteria/pkg/conns/udp"
|
"github.com/HyNetwork/hysteria/pkg/conns/udp"
|
||||||
"github.com/HyNetwork/hysteria/pkg/conns/wechat"
|
"github.com/HyNetwork/hysteria/pkg/conns/wechat"
|
||||||
"github.com/HyNetwork/hysteria/pkg/obfs"
|
obfsPkg "github.com/HyNetwork/hysteria/pkg/obfs"
|
||||||
"github.com/HyNetwork/hysteria/pkg/sockopt"
|
"github.com/HyNetwork/hysteria/pkg/sockopt"
|
||||||
"github.com/HyNetwork/hysteria/pkg/utils"
|
"github.com/HyNetwork/hysteria/pkg/utils"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
@ -76,7 +76,7 @@ var DefaultServerTransport = &ServerTransport{
|
|||||||
ResolvePreference: ResolvePreferenceDefault,
|
ResolvePreference: ResolvePreferenceDefault,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ServerTransport) quicPacketConn(proto string, laddr string, obfs obfs.Obfuscator) (net.PacketConn, error) {
|
func (st *ServerTransport) quicPacketConn(proto string, laddr string, obfs obfsPkg.Obfuscator) (net.PacketConn, error) {
|
||||||
if len(proto) == 0 || proto == "udp" {
|
if len(proto) == 0 || proto == "udp" {
|
||||||
laddrU, err := net.ResolveUDPAddr("udp", laddr)
|
laddrU, err := net.ResolveUDPAddr("udp", laddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -101,12 +101,10 @@ func (st *ServerTransport) quicPacketConn(proto string, laddr string, obfs obfs.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if obfs != nil {
|
if obfs == nil {
|
||||||
oc := wechat.NewObfsWeChatUDPConn(conn, obfs)
|
obfs = obfsPkg.NewDummyObfuscator()
|
||||||
return oc, nil
|
|
||||||
} else {
|
|
||||||
return conn, nil
|
|
||||||
}
|
}
|
||||||
|
return wechat.NewObfsWeChatUDPConn(conn, obfs), nil
|
||||||
} else if proto == "faketcp" {
|
} else if proto == "faketcp" {
|
||||||
conn, err := faketcp.Listen("tcp", laddr)
|
conn, err := faketcp.Listen("tcp", laddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -123,7 +121,7 @@ func (st *ServerTransport) quicPacketConn(proto string, laddr string, obfs obfs.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *ServerTransport) QUICListen(proto string, listen string, tlsConfig *tls.Config, quicConfig *quic.Config, obfs obfs.Obfuscator) (quic.Listener, error) {
|
func (st *ServerTransport) QUICListen(proto string, listen string, tlsConfig *tls.Config, quicConfig *quic.Config, obfs obfsPkg.Obfuscator) (quic.Listener, error) {
|
||||||
pktConn, err := st.quicPacketConn(proto, listen, obfs)
|
pktConn, err := st.quicPacketConn(proto, listen, obfs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user