mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-16 09:19:51 +00:00
feat: remove separate udp-hop protocol, auto detect by address format
This commit is contained in:
parent
a5985c5b6f
commit
e329e8a2e9
@ -32,7 +32,6 @@ import (
|
|||||||
var clientPacketConnFuncFactoryMap = map[string]pktconns.ClientPacketConnFuncFactory{
|
var clientPacketConnFuncFactoryMap = map[string]pktconns.ClientPacketConnFuncFactory{
|
||||||
"": pktconns.NewClientUDPConnFunc,
|
"": pktconns.NewClientUDPConnFunc,
|
||||||
"udp": pktconns.NewClientUDPConnFunc,
|
"udp": pktconns.NewClientUDPConnFunc,
|
||||||
"udp-hop": pktconns.NewClientUDPHopConnFunc,
|
|
||||||
"wechat": pktconns.NewClientWeChatConnFunc,
|
"wechat": pktconns.NewClientWeChatConnFunc,
|
||||||
"wechat-video": pktconns.NewClientWeChatConnFunc,
|
"wechat-video": pktconns.NewClientWeChatConnFunc,
|
||||||
"faketcp": pktconns.NewClientFakeTCPConnFunc,
|
"faketcp": pktconns.NewClientFakeTCPConnFunc,
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
var serverPacketConnFuncFactoryMap = map[string]pktconns.ServerPacketConnFuncFactory{
|
var serverPacketConnFuncFactoryMap = map[string]pktconns.ServerPacketConnFuncFactory{
|
||||||
"": pktconns.NewServerUDPConnFunc,
|
"": pktconns.NewServerUDPConnFunc,
|
||||||
"udp": pktconns.NewServerUDPConnFunc,
|
"udp": pktconns.NewServerUDPConnFunc,
|
||||||
"udp-hop": pktconns.NewServerUDPHopConnFunc,
|
|
||||||
"wechat": pktconns.NewServerWeChatConnFunc,
|
"wechat": pktconns.NewServerWeChatConnFunc,
|
||||||
"wechat-video": pktconns.NewServerWeChatConnFunc,
|
"wechat-video": pktconns.NewServerWeChatConnFunc,
|
||||||
"faketcp": pktconns.NewServerFakeTCPConnFunc,
|
"faketcp": pktconns.NewServerFakeTCPConnFunc,
|
||||||
|
@ -2,6 +2,7 @@ package pktconns
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/HyNetwork/hysteria/pkg/transport/pktconns/udphop"
|
"github.com/HyNetwork/hysteria/pkg/transport/pktconns/udphop"
|
||||||
|
|
||||||
@ -24,6 +25,9 @@ type (
|
|||||||
func NewClientUDPConnFunc(obfsPassword string) ClientPacketConnFunc {
|
func NewClientUDPConnFunc(obfsPassword string) ClientPacketConnFunc {
|
||||||
if obfsPassword == "" {
|
if obfsPassword == "" {
|
||||||
return func(server string) (net.PacketConn, net.Addr, error) {
|
return func(server string) (net.PacketConn, net.Addr, error) {
|
||||||
|
if isAddrPortHopping(server) {
|
||||||
|
return udphop.NewObfsUDPHopClientPacketConn(server, nil)
|
||||||
|
}
|
||||||
sAddr, err := net.ResolveUDPAddr("udp", server)
|
sAddr, err := net.ResolveUDPAddr("udp", server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -33,6 +37,10 @@ func NewClientUDPConnFunc(obfsPassword string) ClientPacketConnFunc {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return func(server string) (net.PacketConn, net.Addr, error) {
|
return func(server string) (net.PacketConn, net.Addr, error) {
|
||||||
|
if isAddrPortHopping(server) {
|
||||||
|
ob := obfs.NewXPlusObfuscator([]byte(obfsPassword))
|
||||||
|
return udphop.NewObfsUDPHopClientPacketConn(server, ob)
|
||||||
|
}
|
||||||
sAddr, err := net.ResolveUDPAddr("udp", server)
|
sAddr, err := net.ResolveUDPAddr("udp", server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -47,19 +55,6 @@ func NewClientUDPConnFunc(obfsPassword string) ClientPacketConnFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientUDPHopConnFunc(obfsPassword string) ClientPacketConnFunc {
|
|
||||||
if obfsPassword == "" {
|
|
||||||
return func(server string) (net.PacketConn, net.Addr, error) {
|
|
||||||
return udphop.NewObfsUDPHopClientPacketConn(server, nil)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return func(server string) (net.PacketConn, net.Addr, error) {
|
|
||||||
ob := obfs.NewXPlusObfuscator([]byte(obfsPassword))
|
|
||||||
return udphop.NewObfsUDPHopClientPacketConn(server, ob)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewClientWeChatConnFunc(obfsPassword string) ClientPacketConnFunc {
|
func NewClientWeChatConnFunc(obfsPassword string) ClientPacketConnFunc {
|
||||||
if obfsPassword == "" {
|
if obfsPassword == "" {
|
||||||
return func(server string) (net.PacketConn, net.Addr, error) {
|
return func(server string) (net.PacketConn, net.Addr, error) {
|
||||||
@ -118,6 +113,9 @@ func NewClientFakeTCPConnFunc(obfsPassword string) ClientPacketConnFunc {
|
|||||||
func NewServerUDPConnFunc(obfsPassword string) ServerPacketConnFunc {
|
func NewServerUDPConnFunc(obfsPassword string) ServerPacketConnFunc {
|
||||||
if obfsPassword == "" {
|
if obfsPassword == "" {
|
||||||
return func(listen string) (net.PacketConn, error) {
|
return func(listen string) (net.PacketConn, error) {
|
||||||
|
if isAddrPortHopping(listen) {
|
||||||
|
return udphop.NewObfsUDPHopServerPacketConn(listen, nil)
|
||||||
|
}
|
||||||
laddrU, err := net.ResolveUDPAddr("udp", listen)
|
laddrU, err := net.ResolveUDPAddr("udp", listen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -126,6 +124,10 @@ func NewServerUDPConnFunc(obfsPassword string) ServerPacketConnFunc {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return func(listen string) (net.PacketConn, error) {
|
return func(listen string) (net.PacketConn, error) {
|
||||||
|
if isAddrPortHopping(listen) {
|
||||||
|
ob := obfs.NewXPlusObfuscator([]byte(obfsPassword))
|
||||||
|
return udphop.NewObfsUDPHopServerPacketConn(listen, ob)
|
||||||
|
}
|
||||||
ob := obfs.NewXPlusObfuscator([]byte(obfsPassword))
|
ob := obfs.NewXPlusObfuscator([]byte(obfsPassword))
|
||||||
laddrU, err := net.ResolveUDPAddr("udp", listen)
|
laddrU, err := net.ResolveUDPAddr("udp", listen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -140,19 +142,6 @@ func NewServerUDPConnFunc(obfsPassword string) ServerPacketConnFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServerUDPHopConnFunc(obfsPassword string) ServerPacketConnFunc {
|
|
||||||
if obfsPassword == "" {
|
|
||||||
return func(listen string) (net.PacketConn, error) {
|
|
||||||
return udphop.NewObfsUDPHopServerPacketConn(listen, nil)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return func(listen string) (net.PacketConn, error) {
|
|
||||||
ob := obfs.NewXPlusObfuscator([]byte(obfsPassword))
|
|
||||||
return udphop.NewObfsUDPHopServerPacketConn(listen, ob)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewServerWeChatConnFunc(obfsPassword string) ServerPacketConnFunc {
|
func NewServerWeChatConnFunc(obfsPassword string) ServerPacketConnFunc {
|
||||||
if obfsPassword == "" {
|
if obfsPassword == "" {
|
||||||
return func(listen string) (net.PacketConn, error) {
|
return func(listen string) (net.PacketConn, error) {
|
||||||
@ -198,3 +187,8 @@ func NewServerFakeTCPConnFunc(obfsPassword string) ServerPacketConnFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isAddrPortHopping(addr string) bool {
|
||||||
|
_, portStr, err := net.SplitHostPort(addr)
|
||||||
|
return err == nil && strings.Contains(portStr, ",")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user