mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-06 22:05:20 +03:00
Fix inconsistent URLTest results
This commit is contained in:
@@ -27,6 +27,11 @@ type OutboundWithPreferredRoutes interface {
|
|||||||
PreferredAddress(address netip.Addr) bool
|
PreferredAddress(address netip.Addr) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OutboundWithMultiplex interface {
|
||||||
|
Outbound
|
||||||
|
MultiplexEnabled() bool
|
||||||
|
}
|
||||||
|
|
||||||
type DirectRouteOutbound interface {
|
type DirectRouteOutbound interface {
|
||||||
Outbound
|
Outbound
|
||||||
NewDirectRouteConnection(metadata InboundContext, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error)
|
NewDirectRouteConnection(metadata InboundContext, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/sagernet/sing-box/adapter"
|
"github.com/sagernet/sing-box/adapter"
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing/common"
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
"github.com/sagernet/sing/common/ntp"
|
"github.com/sagernet/sing/common/ntp"
|
||||||
@@ -72,7 +73,18 @@ func (s *HistoryStorage) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func URLTest(ctx context.Context, link string, detour N.Dialer) (t uint16, err error) {
|
func URLTest(ctx context.Context, link string, detour N.Dialer) (uint16, error) {
|
||||||
|
multiplexOutbound, isMultiplexOutbound := common.Cast[adapter.OutboundWithMultiplex](detour)
|
||||||
|
if isMultiplexOutbound && multiplexOutbound.MultiplexEnabled() {
|
||||||
|
_, err := urlTest(ctx, link, detour)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return urlTest(ctx, link, detour)
|
||||||
|
}
|
||||||
|
|
||||||
|
func urlTest(ctx context.Context, link string, detour N.Dialer) (t uint16, err error) {
|
||||||
if link == "" {
|
if link == "" {
|
||||||
link = "https://www.gstatic.com/generate_204"
|
link = "https://www.gstatic.com/generate_204"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ func RegisterOutbound(registry *outbound.Registry) {
|
|||||||
outbound.Register[option.ShadowsocksOutboundOptions](registry, C.TypeShadowsocks, NewOutbound)
|
outbound.Register[option.ShadowsocksOutboundOptions](registry, C.TypeShadowsocks, NewOutbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ adapter.OutboundWithMultiplex = (*Outbound)(nil)
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
outbound.Adapter
|
outbound.Adapter
|
||||||
logger logger.ContextLogger
|
logger logger.ContextLogger
|
||||||
@@ -124,6 +126,10 @@ func (h *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Outbound) MultiplexEnabled() bool {
|
||||||
|
return h.multiplexDialer != nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Outbound) InterfaceUpdated() {
|
func (h *Outbound) InterfaceUpdated() {
|
||||||
if h.multiplexDialer != nil {
|
if h.multiplexDialer != nil {
|
||||||
h.multiplexDialer.Reset()
|
h.multiplexDialer.Reset()
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ func RegisterOutbound(registry *outbound.Registry) {
|
|||||||
outbound.Register[option.TrojanOutboundOptions](registry, C.TypeTrojan, NewOutbound)
|
outbound.Register[option.TrojanOutboundOptions](registry, C.TypeTrojan, NewOutbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ adapter.OutboundWithMultiplex = (*Outbound)(nil)
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
outbound.Adapter
|
outbound.Adapter
|
||||||
logger logger.ContextLogger
|
logger logger.ContextLogger
|
||||||
@@ -107,6 +109,10 @@ func (h *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Outbound) MultiplexEnabled() bool {
|
||||||
|
return h.multiplexDialer != nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Outbound) InterfaceUpdated() {
|
func (h *Outbound) InterfaceUpdated() {
|
||||||
if h.transport != nil {
|
if h.transport != nil {
|
||||||
h.transport.Close()
|
h.transport.Close()
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ func RegisterOutbound(registry *outbound.Registry) {
|
|||||||
outbound.Register[option.VLESSOutboundOptions](registry, C.TypeVLESS, NewOutbound)
|
outbound.Register[option.VLESSOutboundOptions](registry, C.TypeVLESS, NewOutbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ adapter.OutboundWithMultiplex = (*Outbound)(nil)
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
outbound.Adapter
|
outbound.Adapter
|
||||||
logger logger.ContextLogger
|
logger logger.ContextLogger
|
||||||
@@ -127,6 +129,10 @@ func (h *Outbound) ListenPacket(ctx context.Context, destination M.Socksaddr) (n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Outbound) MultiplexEnabled() bool {
|
||||||
|
return h.multiplexDialer != nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Outbound) InterfaceUpdated() {
|
func (h *Outbound) InterfaceUpdated() {
|
||||||
if h.transport != nil {
|
if h.transport != nil {
|
||||||
h.transport.Close()
|
h.transport.Close()
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ func RegisterOutbound(registry *outbound.Registry) {
|
|||||||
outbound.Register[option.VMessOutboundOptions](registry, C.TypeVMess, NewOutbound)
|
outbound.Register[option.VMessOutboundOptions](registry, C.TypeVMess, NewOutbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ adapter.OutboundWithMultiplex = (*Outbound)(nil)
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
outbound.Adapter
|
outbound.Adapter
|
||||||
logger logger.ContextLogger
|
logger logger.ContextLogger
|
||||||
@@ -105,6 +107,10 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
|
|||||||
return outbound, nil
|
return outbound, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Outbound) MultiplexEnabled() bool {
|
||||||
|
return h.multiplexDialer != nil
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Outbound) InterfaceUpdated() {
|
func (h *Outbound) InterfaceUpdated() {
|
||||||
if h.transport != nil {
|
if h.transport != nil {
|
||||||
h.transport.Close()
|
h.transport.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user