chore: shadowsocks listener support the "udp" setting

This commit is contained in:
wwqgtxx 2023-03-21 12:40:36 +08:00
parent 154fbb34ea
commit 0336435ebc
6 changed files with 44 additions and 36 deletions

View File

@ -9,6 +9,7 @@ type ShadowsocksServer struct {
Listen string Listen string
Password string Password string
Cipher string Cipher string
Udp bool
} }
func (t ShadowsocksServer) String() string { func (t ShadowsocksServer) String() string {

View File

@ -11,6 +11,7 @@ type ShadowSocksOption struct {
BaseOption BaseOption
Password string `inbound:"password"` Password string `inbound:"password"`
Cipher string `inbound:"cipher"` Cipher string `inbound:"cipher"`
UDP bool `inbound:"udp,omitempty"`
} }
func (o ShadowSocksOption) Equal(config C.InboundConfig) bool { func (o ShadowSocksOption) Equal(config C.InboundConfig) bool {
@ -37,6 +38,7 @@ func NewShadowSocks(options *ShadowSocksOption) (*ShadowSocks, error) {
Listen: base.RawAddress(), Listen: base.RawAddress(),
Password: options.Password, Password: options.Password,
Cipher: options.Cipher, Cipher: options.Cipher,
Udp: options.UDP,
}, },
}, nil }, nil
} }

View File

@ -271,6 +271,7 @@ func ReCreateShadowSocks(shadowSocksConfig string, tcpIn chan<- C.ConnContext, u
Listen: addr, Listen: addr,
Password: password, Password: password,
Cipher: cipher, Cipher: cipher,
Udp: true,
} }
} }

View File

@ -73,7 +73,7 @@ func ParseListener(mapping map[string]any) (C.InboundListener, error) {
} }
listener, err = IN.NewTun(tunOption) listener, err = IN.NewTun(tunOption)
case "shadowsocks": case "shadowsocks":
shadowsocksOption := &IN.ShadowSocksOption{} shadowsocksOption := &IN.ShadowSocksOption{UDP: true}
err = decoder.Decode(mapping, shadowsocksOption) err = decoder.Decode(mapping, shadowsocksOption)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -33,12 +33,14 @@ func New(config LC.ShadowsocksServer, tcpIn chan<- C.ConnContext, udpIn chan<- C
for _, addr := range strings.Split(config.Listen, ",") { for _, addr := range strings.Split(config.Listen, ",") {
addr := addr addr := addr
if config.Udp {
//UDP //UDP
ul, err := NewUDP(addr, pickCipher, udpIn) ul, err := NewUDP(addr, pickCipher, udpIn)
if err != nil { if err != nil {
return nil, err return nil, err
} }
sl.udpListeners = append(sl.udpListeners, ul) sl.udpListeners = append(sl.udpListeners, ul)
}
//TCP //TCP
l, err := inbound.Listen("tcp", addr) l, err := inbound.Listen("tcp", addr)

View File

@ -76,6 +76,7 @@ func New(config LC.ShadowsocksServer, tcpIn chan<- C.ConnContext, udpIn chan<- C
for _, addr := range strings.Split(config.Listen, ",") { for _, addr := range strings.Split(config.Listen, ",") {
addr := addr addr := addr
if config.Udp {
//UDP //UDP
ul, err := net.ListenPacket("udp", addr) ul, err := net.ListenPacket("udp", addr)
if err != nil { if err != nil {
@ -107,6 +108,7 @@ func New(config LC.ShadowsocksServer, tcpIn chan<- C.ConnContext, udpIn chan<- C
}) })
} }
}() }()
}
//TCP //TCP
l, err := inbound.Listen("tcp", addr) l, err := inbound.Listen("tcp", addr)