mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-20 00:50:06 +08:00
chore: tradition shadowsocks server could handle smux
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 1s
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 1s
This commit is contained in:
parent
5830afcbde
commit
e23f40a56b
@ -8,6 +8,7 @@ import (
|
|||||||
N "github.com/metacubex/mihomo/common/net"
|
N "github.com/metacubex/mihomo/common/net"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
LC "github.com/metacubex/mihomo/listener/config"
|
LC "github.com/metacubex/mihomo/listener/config"
|
||||||
|
"github.com/metacubex/mihomo/listener/sing"
|
||||||
"github.com/metacubex/mihomo/transport/shadowsocks/core"
|
"github.com/metacubex/mihomo/transport/shadowsocks/core"
|
||||||
"github.com/metacubex/mihomo/transport/socks5"
|
"github.com/metacubex/mihomo/transport/socks5"
|
||||||
)
|
)
|
||||||
@ -18,6 +19,7 @@ type Listener struct {
|
|||||||
listeners []net.Listener
|
listeners []net.Listener
|
||||||
udpListeners []*UDPListener
|
udpListeners []*UDPListener
|
||||||
pickCipher core.Cipher
|
pickCipher core.Cipher
|
||||||
|
handler *sing.ListenerHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
var _listener *Listener
|
var _listener *Listener
|
||||||
@ -28,7 +30,17 @@ func New(config LC.ShadowsocksServer, tunnel C.Tunnel, additions ...inbound.Addi
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sl := &Listener{false, config, nil, nil, pickCipher}
|
h, err := sing.NewListenerHandler(sing.ListenerConfig{
|
||||||
|
Tunnel: tunnel,
|
||||||
|
Type: C.SHADOWSOCKS,
|
||||||
|
Additions: additions,
|
||||||
|
MuxOption: config.MuxOption,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sl := &Listener{false, config, nil, nil, pickCipher, h}
|
||||||
_listener = sl
|
_listener = sl
|
||||||
|
|
||||||
for _, addr := range strings.Split(config.Listen, ",") {
|
for _, addr := range strings.Split(config.Listen, ",") {
|
||||||
@ -107,7 +119,8 @@ func (l *Listener) HandleConn(conn net.Conn, tunnel C.Tunnel, additions ...inbou
|
|||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tunnel.HandleTCPConn(inbound.NewSocket(target, conn, C.SHADOWSOCKS, additions...))
|
l.handler.HandleSocket(target, conn, additions...)
|
||||||
|
//tunnel.HandleTCPConn(inbound.NewSocket(target, conn, C.SHADOWSOCKS, additions...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleShadowSocks(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) bool {
|
func HandleShadowSocks(conn net.Conn, tunnel C.Tunnel, additions ...inbound.Addition) bool {
|
||||||
|
|||||||
@ -136,8 +136,8 @@ func (h *ListenerHandler) NewConnection(ctx context.Context, conn net.Conn, meta
|
|||||||
cMetadata.RawDstAddr = metadata.Destination.Unwrap().TCPAddr()
|
cMetadata.RawDstAddr = metadata.Destination.Unwrap().TCPAddr()
|
||||||
}
|
}
|
||||||
inbound.ApplyAdditions(cMetadata, inbound.WithDstAddr(metadata.Destination), inbound.WithSrcAddr(metadata.Source), inbound.WithInAddr(conn.LocalAddr()))
|
inbound.ApplyAdditions(cMetadata, inbound.WithDstAddr(metadata.Destination), inbound.WithSrcAddr(metadata.Source), inbound.WithInAddr(conn.LocalAddr()))
|
||||||
inbound.ApplyAdditions(cMetadata, getAdditions(ctx)...)
|
|
||||||
inbound.ApplyAdditions(cMetadata, h.Additions...)
|
inbound.ApplyAdditions(cMetadata, h.Additions...)
|
||||||
|
inbound.ApplyAdditions(cMetadata, getAdditions(ctx)...)
|
||||||
|
|
||||||
h.Tunnel.HandleTCPConn(conn, cMetadata) // this goroutine must exit after conn unused
|
h.Tunnel.HandleTCPConn(conn, cMetadata) // this goroutine must exit after conn unused
|
||||||
return nil
|
return nil
|
||||||
@ -198,8 +198,8 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network.
|
|||||||
cMetadata.RawDstAddr = dest.Unwrap().UDPAddr()
|
cMetadata.RawDstAddr = dest.Unwrap().UDPAddr()
|
||||||
}
|
}
|
||||||
inbound.ApplyAdditions(cMetadata, inbound.WithDstAddr(dest), inbound.WithSrcAddr(metadata.Source), inbound.WithInAddr(conn.LocalAddr()))
|
inbound.ApplyAdditions(cMetadata, inbound.WithDstAddr(dest), inbound.WithSrcAddr(metadata.Source), inbound.WithInAddr(conn.LocalAddr()))
|
||||||
inbound.ApplyAdditions(cMetadata, getAdditions(ctx)...)
|
|
||||||
inbound.ApplyAdditions(cMetadata, h.Additions...)
|
inbound.ApplyAdditions(cMetadata, h.Additions...)
|
||||||
|
inbound.ApplyAdditions(cMetadata, getAdditions(ctx)...)
|
||||||
|
|
||||||
h.Tunnel.HandleUDPPacket(cPacket, cMetadata)
|
h.Tunnel.HandleUDPPacket(cPacket, cMetadata)
|
||||||
}
|
}
|
||||||
|
|||||||
24
listener/sing/util.go
Normal file
24
listener/sing/util.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package sing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/metacubex/mihomo/adapter/inbound"
|
||||||
|
"github.com/metacubex/mihomo/transport/socks5"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandleSocket like inbound.NewSocket combine with Tunnel.HandleTCPConn but also handel specialFqdn
|
||||||
|
func (h *ListenerHandler) HandleSocket(target socks5.Addr, conn net.Conn, _additions ...inbound.Addition) {
|
||||||
|
conn, metadata := inbound.NewSocket(target, conn, h.Type, h.Additions...)
|
||||||
|
if h.IsSpecialFqdn(metadata.Host) {
|
||||||
|
_ = h.ParseSpecialFqdn(
|
||||||
|
WithAdditions(context.Background(), _additions...),
|
||||||
|
conn,
|
||||||
|
ConvertMetadata(metadata),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
inbound.ApplyAdditions(metadata, _additions...)
|
||||||
|
h.Tunnel.HandleTCPConn(conn, metadata)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package tuic
|
package tuic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
@ -93,23 +92,14 @@ func New(config LC.TuicServer, tunnel C.Tunnel, additions ...inbound.Addition) (
|
|||||||
quicConfig.MaxDatagramFrameSize = int64(maxDatagramFrameSize)
|
quicConfig.MaxDatagramFrameSize = int64(maxDatagramFrameSize)
|
||||||
|
|
||||||
handleTcpFn := func(conn net.Conn, addr socks5.Addr, _additions ...inbound.Addition) error {
|
handleTcpFn := func(conn net.Conn, addr socks5.Addr, _additions ...inbound.Addition) error {
|
||||||
newAdditions := additions
|
//newAdditions := additions
|
||||||
if len(_additions) > 0 {
|
//if len(_additions) > 0 {
|
||||||
newAdditions = slices.Clone(additions)
|
// newAdditions = slices.Clone(additions)
|
||||||
newAdditions = append(newAdditions, _additions...)
|
// newAdditions = append(newAdditions, _additions...)
|
||||||
}
|
//}
|
||||||
conn, metadata := inbound.NewSocket(addr, conn, C.TUIC, newAdditions...)
|
//conn, metadata := inbound.NewSocket(addr, conn, C.TUIC, newAdditions...)
|
||||||
if h.IsSpecialFqdn(metadata.Host) {
|
//go tunnel.HandleTCPConn(conn, metadata)
|
||||||
go func() { // ParseSpecialFqdn will block, so open a new goroutine
|
go h.HandleSocket(addr, conn, _additions...) // h.HandleSocket will block, so open a new goroutine
|
||||||
_ = h.ParseSpecialFqdn(
|
|
||||||
sing.WithAdditions(context.Background(), newAdditions...),
|
|
||||||
conn,
|
|
||||||
sing.ConvertMetadata(metadata),
|
|
||||||
)
|
|
||||||
}()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
go tunnel.HandleTCPConn(conn, metadata)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
handleUdpFn := func(addr socks5.Addr, packet C.UDPPacket, _additions ...inbound.Addition) error {
|
handleUdpFn := func(addr socks5.Addr, packet C.UDPPacket, _additions ...inbound.Addition) error {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user