mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-27 20:15:38 +08:00
89c723e3e4
Refactor Authenticator interface to struct & Update smux & Update gVisor to 20231204.0 & Update quic-go to v0.40.1 & Update wireguard-go & Add GSO support for TUN/WireGuard & Fix router pre-start & Fix bind forwarder to interface for systems stack
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package inbound
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"os"
|
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
"github.com/sagernet/sing-box/common/uot"
|
|
C "github.com/sagernet/sing-box/constant"
|
|
"github.com/sagernet/sing-box/log"
|
|
"github.com/sagernet/sing-box/option"
|
|
"github.com/sagernet/sing/common/auth"
|
|
N "github.com/sagernet/sing/common/network"
|
|
"github.com/sagernet/sing/protocol/socks"
|
|
)
|
|
|
|
var (
|
|
_ adapter.Inbound = (*Socks)(nil)
|
|
_ adapter.InjectableInbound = (*Socks)(nil)
|
|
)
|
|
|
|
type Socks struct {
|
|
myInboundAdapter
|
|
authenticator *auth.Authenticator
|
|
}
|
|
|
|
func NewSocks(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.SocksInboundOptions) *Socks {
|
|
inbound := &Socks{
|
|
myInboundAdapter{
|
|
protocol: C.TypeSOCKS,
|
|
network: []string{N.NetworkTCP},
|
|
ctx: ctx,
|
|
router: uot.NewRouter(router, logger),
|
|
logger: logger,
|
|
tag: tag,
|
|
listenOptions: options.ListenOptions,
|
|
},
|
|
auth.NewAuthenticator(options.Users),
|
|
}
|
|
inbound.connHandler = inbound
|
|
return inbound
|
|
}
|
|
|
|
func (h *Socks) NewConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext) error {
|
|
return socks.HandleConnection(ctx, conn, h.authenticator, h.upstreamUserHandler(metadata), adapter.UpstreamMetadata(metadata))
|
|
}
|
|
|
|
func (h *Socks) NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext) error {
|
|
return os.ErrInvalid
|
|
}
|