mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Update dependencies
This commit is contained in:
parent
90d915ea05
commit
18e5b0963f
20 changed files with 523 additions and 238 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing/common/control"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
"github.com/xtls/xray-core/features/dns"
|
||||
|
@ -18,7 +19,7 @@ type SystemDialer interface {
|
|||
}
|
||||
|
||||
type DefaultSystemDialer struct {
|
||||
controllers []controller
|
||||
controllers []control.Func
|
||||
dns dns.Client
|
||||
obm outbound.Manager
|
||||
}
|
||||
|
@ -81,6 +82,11 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||
|
||||
if sockopt != nil || len(d.controllers) > 0 {
|
||||
dialer.Control = func(network, address string, c syscall.RawConn) error {
|
||||
for _, ctl := range d.controllers {
|
||||
if err := ctl(network, address, c); err != nil {
|
||||
newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
}
|
||||
return c.Control(func(fd uintptr) {
|
||||
if sockopt != nil {
|
||||
if err := applyOutboundSocketOptions(network, address, fd, sockopt); err != nil {
|
||||
|
@ -92,12 +98,6 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, ctl := range d.controllers {
|
||||
if err := ctl(network, address, fd); err != nil {
|
||||
newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ func UseAlternativeSystemDialer(dialer SystemDialer) {
|
|||
// It only works when effective dialer is the default dialer.
|
||||
//
|
||||
// xray:api:beta
|
||||
func RegisterDialerController(ctl func(network, address string, fd uintptr) error) error {
|
||||
func RegisterDialerController(ctl control.Func) error {
|
||||
if ctl == nil {
|
||||
return newError("nil listener controller")
|
||||
}
|
||||
|
|
|
@ -10,21 +10,26 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pires/go-proxyproto"
|
||||
"github.com/sagernet/sing/common/control"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
)
|
||||
|
||||
var effectiveListener = DefaultListener{}
|
||||
|
||||
type controller func(network, address string, fd uintptr) error
|
||||
|
||||
type DefaultListener struct {
|
||||
controllers []controller
|
||||
controllers []control.Func
|
||||
}
|
||||
|
||||
func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []controller) func(network, address string, c syscall.RawConn) error {
|
||||
func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []control.Func) func(network, address string, c syscall.RawConn) error {
|
||||
return func(network, address string, c syscall.RawConn) error {
|
||||
return c.Control(func(fd uintptr) {
|
||||
for _, controller := range controllers {
|
||||
if err := controller(network, address, c); err != nil {
|
||||
newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
if sockopt != nil {
|
||||
if err := applyInboundSocketOptions(network, fd, sockopt); err != nil {
|
||||
newError("failed to apply socket options to incoming connection").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
|
@ -32,12 +37,6 @@ func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []co
|
|||
}
|
||||
|
||||
setReusePort(fd)
|
||||
|
||||
for _, controller := range controllers {
|
||||
if err := controller(network, address, fd); err != nil {
|
||||
newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +116,7 @@ func (dl *DefaultListener) ListenPacket(ctx context.Context, addr net.Addr, sock
|
|||
// The controller can be used to operate on file descriptors before they are put into use.
|
||||
//
|
||||
// xray:api:beta
|
||||
func RegisterListenerController(controller func(network, address string, fd uintptr) error) error {
|
||||
func RegisterListenerController(controller control.Func) error {
|
||||
if controller == nil {
|
||||
return newError("nil listener controller")
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package internet_test
|
|||
import (
|
||||
"context"
|
||||
"net"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/sagernet/sing/common/control"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
)
|
||||
|
@ -12,9 +14,11 @@ import (
|
|||
func TestRegisterListenerController(t *testing.T) {
|
||||
var gotFd uintptr
|
||||
|
||||
common.Must(internet.RegisterListenerController(func(network string, addr string, fd uintptr) error {
|
||||
gotFd = fd
|
||||
return nil
|
||||
common.Must(internet.RegisterListenerController(func(network, address string, conn syscall.RawConn) error {
|
||||
return control.Raw(conn, func(fd uintptr) error {
|
||||
gotFd = fd
|
||||
return nil
|
||||
})
|
||||
}))
|
||||
|
||||
conn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue