mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
Fix URLTest selection and idle connection references
This commit is contained in:
@@ -79,17 +79,25 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var dnsReferences []string
|
||||
for _, dialerOptions := range []option.DialerOptions{options.ControlDialer, options.TunnelDialer} {
|
||||
if dialerOptions.DomainResolver != nil && dialerOptions.DomainResolver.Server != "" {
|
||||
dnsReferences = append(dnsReferences, dialerOptions.DomainResolver.Server)
|
||||
}
|
||||
}
|
||||
return &Inbound{
|
||||
Adapter: inbound.NewAdapter(C.TypeCloudflared, tag),
|
||||
service: service,
|
||||
references: common.FilterNotDefault([]string{options.ControlDialer.Detour, options.TunnelDialer.Detour}),
|
||||
Adapter: inbound.NewAdapter(C.TypeCloudflared, tag),
|
||||
service: service,
|
||||
references: common.FilterNotDefault([]string{options.ControlDialer.Detour, options.TunnelDialer.Detour}),
|
||||
dnsReferences: dnsReferences,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Inbound struct {
|
||||
inbound.Adapter
|
||||
service *cloudflared.Service
|
||||
references []string
|
||||
service *cloudflared.Service
|
||||
references []string
|
||||
dnsReferences []string
|
||||
}
|
||||
|
||||
func (i *Inbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
@@ -259,8 +267,8 @@ func (h *icmpRouterHandler) RouteICMPFlow(source netip.Addr, destination netip.A
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Inbound) References() []string {
|
||||
return i.references
|
||||
func (i *Inbound) References() ([]string, []string) {
|
||||
return i.references, i.dnsReferences
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -127,12 +127,12 @@ func (s *Selector) AttachConnection(closer io.Closer) func() {
|
||||
return s.interruptGroup.Add(closer, true)
|
||||
}
|
||||
|
||||
func (s *Selector) References() []string {
|
||||
func (s *Selector) References() ([]string, []string) {
|
||||
selected := s.selected.Load()
|
||||
if selected == nil {
|
||||
return s.tags[:1]
|
||||
return s.tags[:1], nil
|
||||
}
|
||||
return []string{selected.Tag()}
|
||||
return []string{selected.Tag()}, nil
|
||||
}
|
||||
|
||||
func (s *Selector) SelectOutbound(tag string) bool {
|
||||
|
||||
+77
-51
@@ -106,9 +106,9 @@ func (s *URLTest) All() []string {
|
||||
func (s *URLTest) Selected(network string) adapter.Outbound {
|
||||
var outbound adapter.Outbound
|
||||
if network == N.NetworkUDP {
|
||||
outbound = s.group.selectedOutboundUDP
|
||||
outbound = s.group.selectedOutboundUDP.Load()
|
||||
} else {
|
||||
outbound = s.group.selectedOutboundTCP
|
||||
outbound = s.group.selectedOutboundTCP.Load()
|
||||
}
|
||||
if outbound == nil {
|
||||
outbound, _ = s.group.Select(network)
|
||||
@@ -121,19 +121,21 @@ func (s *URLTest) AttachConnection(closer io.Closer) func() {
|
||||
return s.group.interruptGroup.Add(closer, true)
|
||||
}
|
||||
|
||||
func (s *URLTest) References() []string {
|
||||
func (s *URLTest) References() ([]string, []string) {
|
||||
group := s.group
|
||||
if group == nil {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
var references []string
|
||||
if group.selectedOutboundTCP != nil {
|
||||
references = append(references, group.selectedOutboundTCP.Tag())
|
||||
selectedOutboundTCP := group.selectedOutboundTCP.Load()
|
||||
selectedOutboundUDP := group.selectedOutboundUDP.Load()
|
||||
if selectedOutboundTCP != nil {
|
||||
references = append(references, selectedOutboundTCP.Tag())
|
||||
}
|
||||
if group.selectedOutboundUDP != nil && group.selectedOutboundUDP != group.selectedOutboundTCP {
|
||||
references = append(references, group.selectedOutboundUDP.Tag())
|
||||
if selectedOutboundUDP != nil && selectedOutboundUDP != selectedOutboundTCP {
|
||||
references = append(references, selectedOutboundUDP.Tag())
|
||||
}
|
||||
return references
|
||||
return references, nil
|
||||
}
|
||||
|
||||
func (s *URLTest) URLTest(ctx context.Context) (map[string]uint16, error) {
|
||||
@@ -145,7 +147,9 @@ func (s *URLTest) CheckOutbounds() {
|
||||
}
|
||||
|
||||
func (s *URLTest) PerformUpdateCheck() {
|
||||
s.group.performUpdateCheck()
|
||||
if s.group.performUpdateCheck() {
|
||||
s.group.history.NotifyUpdated()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *URLTest) InterfaceUpdated(ctx context.Context) {
|
||||
@@ -171,9 +175,9 @@ func (s *URLTest) DialContext(ctx context.Context, network string, destination M
|
||||
var outbound adapter.Outbound
|
||||
switch N.NetworkName(network) {
|
||||
case N.NetworkTCP:
|
||||
outbound = s.group.selectedOutboundTCP
|
||||
outbound = s.group.selectedOutboundTCP.Load()
|
||||
case N.NetworkUDP:
|
||||
outbound = s.group.selectedOutboundUDP
|
||||
outbound = s.group.selectedOutboundUDP.Load()
|
||||
default:
|
||||
return nil, E.Extend(N.ErrUnknownNetwork, network)
|
||||
}
|
||||
@@ -188,13 +192,16 @@ func (s *URLTest) DialContext(ctx context.Context, network string, destination M
|
||||
return s.group.interruptGroup.NewConn(conn, interrupt.IsExternalConnectionFromContext(ctx)), nil
|
||||
}
|
||||
s.logger.ErrorContext(ctx, err)
|
||||
s.group.history.DeleteURLTestHistory(outbound.Tag())
|
||||
if !E.IsClosedOrCanceled(err) {
|
||||
s.group.history.DeleteURLTestHistory(RealTag(outbound, N.NetworkName(network)))
|
||||
s.PerformUpdateCheck()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *URLTest) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
s.group.Touch()
|
||||
outbound := s.group.selectedOutboundUDP
|
||||
outbound := s.group.selectedOutboundUDP.Load()
|
||||
if outbound == nil {
|
||||
outbound, _ = s.group.Select(N.NetworkUDP)
|
||||
}
|
||||
@@ -206,7 +213,10 @@ func (s *URLTest) ListenPacket(ctx context.Context, destination M.Socksaddr) (ne
|
||||
return s.group.interruptGroup.NewPacketConn(conn, interrupt.IsExternalConnectionFromContext(ctx)), nil
|
||||
}
|
||||
s.logger.ErrorContext(ctx, err)
|
||||
s.group.history.DeleteURLTestHistory(outbound.Tag())
|
||||
if !E.IsClosedOrCanceled(err) {
|
||||
s.group.history.DeleteURLTestHistory(RealTag(outbound, N.NetworkUDP))
|
||||
s.PerformUpdateCheck()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -223,15 +233,16 @@ type URLTestGroup struct {
|
||||
idleTimeout time.Duration
|
||||
history *urltest.HistoryStorage
|
||||
checking atomic.Bool
|
||||
selectedOutboundTCP adapter.Outbound
|
||||
selectedOutboundUDP adapter.Outbound
|
||||
selectedOutboundTCP common.TypedValue[adapter.Outbound]
|
||||
selectedOutboundUDP common.TypedValue[adapter.Outbound]
|
||||
interruptGroup *interrupt.Group
|
||||
interruptExternalConnections bool
|
||||
access sync.Mutex
|
||||
updateAccess sync.Mutex
|
||||
ticker *time.Ticker
|
||||
close chan struct{}
|
||||
started bool
|
||||
started atomic.Bool
|
||||
closed atomic.Bool
|
||||
lastActive common.TypedValue[time.Time]
|
||||
}
|
||||
|
||||
@@ -272,17 +283,20 @@ func NewURLTestGroup(ctx context.Context, outboundManager adapter.OutboundManage
|
||||
func (g *URLTestGroup) PostStart() {
|
||||
g.access.Lock()
|
||||
defer g.access.Unlock()
|
||||
g.started = true
|
||||
g.started.Store(true)
|
||||
g.lastActive.Store(time.Now())
|
||||
go g.CheckOutbounds(g.ctx, false)
|
||||
}
|
||||
|
||||
func (g *URLTestGroup) Touch() {
|
||||
if !g.started {
|
||||
if !g.started.Load() {
|
||||
return
|
||||
}
|
||||
g.access.Lock()
|
||||
defer g.access.Unlock()
|
||||
if g.closed.Load() {
|
||||
return
|
||||
}
|
||||
if g.ticker != nil {
|
||||
g.lastActive.Store(time.Now())
|
||||
return
|
||||
@@ -296,13 +310,15 @@ func (g *URLTestGroup) Touch() {
|
||||
func (g *URLTestGroup) Close() error {
|
||||
g.access.Lock()
|
||||
defer g.access.Unlock()
|
||||
if g.ticker == nil {
|
||||
if g.closed.Swap(true) {
|
||||
return nil
|
||||
}
|
||||
g.ticker.Stop()
|
||||
g.ticker = nil
|
||||
g.pause.UnregisterCallback(g.pauseCallback)
|
||||
g.pauseCallback = nil
|
||||
if g.ticker != nil {
|
||||
g.ticker.Stop()
|
||||
g.ticker = nil
|
||||
g.pause.UnregisterCallback(g.pauseCallback)
|
||||
g.pauseCallback = nil
|
||||
}
|
||||
close(g.close)
|
||||
return nil
|
||||
}
|
||||
@@ -310,20 +326,17 @@ func (g *URLTestGroup) Close() error {
|
||||
func (g *URLTestGroup) Select(network string) (adapter.Outbound, bool) {
|
||||
var minDelay uint16
|
||||
var minOutbound adapter.Outbound
|
||||
var selectedOutbound adapter.Outbound
|
||||
switch network {
|
||||
case N.NetworkTCP:
|
||||
if g.selectedOutboundTCP != nil {
|
||||
if history := g.history.LoadURLTestHistory(RealTag(g.selectedOutboundTCP, N.NetworkTCP)); history != nil {
|
||||
minOutbound = g.selectedOutboundTCP
|
||||
minDelay = history.Delay
|
||||
}
|
||||
}
|
||||
selectedOutbound = g.selectedOutboundTCP.Load()
|
||||
case N.NetworkUDP:
|
||||
if g.selectedOutboundUDP != nil {
|
||||
if history := g.history.LoadURLTestHistory(RealTag(g.selectedOutboundUDP, N.NetworkUDP)); history != nil {
|
||||
minOutbound = g.selectedOutboundUDP
|
||||
minDelay = history.Delay
|
||||
}
|
||||
selectedOutbound = g.selectedOutboundUDP.Load()
|
||||
}
|
||||
if selectedOutbound != nil {
|
||||
if history := g.history.LoadURLTestHistory(RealTag(selectedOutbound, network)); history != nil {
|
||||
minOutbound = selectedOutbound
|
||||
minDelay = history.Delay
|
||||
}
|
||||
}
|
||||
for _, detour := range g.outbounds {
|
||||
@@ -390,8 +403,9 @@ func (g *URLTestGroup) urlTest(ctx context.Context, force bool) (map[string]uint
|
||||
return make(map[string]uint16), nil
|
||||
}
|
||||
defer g.checking.Store(false)
|
||||
result := URLTestOutbounds(ctx, g.outbound, g.history, g.logger, g.outbounds, g.link, g.interval, force)
|
||||
result := urlTestOutbounds(ctx, g.outbound, g.history, g.logger, g.outbounds, g.link, g.interval, force)
|
||||
g.performUpdateCheck()
|
||||
g.history.NotifyUpdated()
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -410,9 +424,17 @@ type urlTestBatch struct {
|
||||
groups []adapter.OutboundGroup
|
||||
access sync.Mutex
|
||||
result map[string]uint16
|
||||
stored map[string]*adapter.URLTestHistory
|
||||
deleted []string
|
||||
}
|
||||
|
||||
func URLTestOutbounds(ctx context.Context, outboundManager adapter.OutboundManager, history *urltest.HistoryStorage, logger log.Logger, outbounds []adapter.Outbound, link string, interval time.Duration, force bool) map[string]uint16 {
|
||||
result := urlTestOutbounds(ctx, outboundManager, history, logger, outbounds, link, interval, force)
|
||||
history.NotifyUpdated()
|
||||
return result
|
||||
}
|
||||
|
||||
func urlTestOutbounds(ctx context.Context, outboundManager adapter.OutboundManager, history *urltest.HistoryStorage, logger log.Logger, outbounds []adapter.Outbound, link string, interval time.Duration, force bool) map[string]uint16 {
|
||||
b, _ := batch.New(ctx, batch.WithConcurrencyNum[any](10))
|
||||
testBatch := &urlTestBatch{
|
||||
ctx: ctx,
|
||||
@@ -422,9 +444,11 @@ func URLTestOutbounds(ctx context.Context, outboundManager adapter.OutboundManag
|
||||
batch: b,
|
||||
checked: make(map[string]bool),
|
||||
result: make(map[string]uint16),
|
||||
stored: make(map[string]*adapter.URLTestHistory),
|
||||
}
|
||||
testBatch.test(outbounds, link, interval, force)
|
||||
b.Wait()
|
||||
history.UpdateURLTestHistory(testBatch.stored, testBatch.deleted)
|
||||
for _, outboundGroup := range testBatch.groups {
|
||||
groupHistory := history.LoadURLTestHistory(RealTag(outboundGroup, N.NetworkTCP))
|
||||
if groupHistory != nil {
|
||||
@@ -483,14 +507,16 @@ func (b *urlTestBatch) test(outbounds []adapter.Outbound, link string, interval
|
||||
return nil, nil
|
||||
}
|
||||
b.logger.Debug("outbound ", tag, " unavailable: ", testResult.err)
|
||||
b.history.DeleteURLTestHistory(tag)
|
||||
b.access.Lock()
|
||||
b.deleted = append(b.deleted, tag)
|
||||
b.access.Unlock()
|
||||
} else {
|
||||
b.logger.Debug("outbound ", tag, " available: ", testResult.delay, "ms")
|
||||
b.history.StoreURLTestHistory(tag, &adapter.URLTestHistory{
|
||||
b.access.Lock()
|
||||
b.stored[tag] = &adapter.URLTestHistory{
|
||||
Time: time.Now(),
|
||||
Delay: testResult.delay,
|
||||
})
|
||||
b.access.Lock()
|
||||
}
|
||||
b.result[tag] = testResult.delay
|
||||
b.access.Unlock()
|
||||
}
|
||||
@@ -500,31 +526,31 @@ func (b *urlTestBatch) test(outbounds []adapter.Outbound, link string, interval
|
||||
}
|
||||
}
|
||||
|
||||
func (g *URLTestGroup) performUpdateCheck() {
|
||||
func (g *URLTestGroup) performUpdateCheck() bool {
|
||||
g.updateAccess.Lock()
|
||||
defer g.updateAccess.Unlock()
|
||||
var (
|
||||
updated bool
|
||||
selected bool
|
||||
)
|
||||
if outbound, exists := g.Select(N.NetworkTCP); outbound != nil && (g.selectedOutboundTCP == nil || (exists && outbound != g.selectedOutboundTCP)) {
|
||||
if g.selectedOutboundTCP != nil {
|
||||
selectedOutboundTCP := g.selectedOutboundTCP.Load()
|
||||
if outbound, _ := g.Select(N.NetworkTCP); outbound != nil && outbound != selectedOutboundTCP {
|
||||
if selectedOutboundTCP != nil {
|
||||
updated = true
|
||||
}
|
||||
g.selectedOutboundTCP = outbound
|
||||
g.selectedOutboundTCP.Store(outbound)
|
||||
selected = true
|
||||
}
|
||||
if outbound, exists := g.Select(N.NetworkUDP); outbound != nil && (g.selectedOutboundUDP == nil || (exists && outbound != g.selectedOutboundUDP)) {
|
||||
if g.selectedOutboundUDP != nil {
|
||||
selectedOutboundUDP := g.selectedOutboundUDP.Load()
|
||||
if outbound, _ := g.Select(N.NetworkUDP); outbound != nil && outbound != selectedOutboundUDP {
|
||||
if selectedOutboundUDP != nil {
|
||||
updated = true
|
||||
}
|
||||
g.selectedOutboundUDP = outbound
|
||||
g.selectedOutboundUDP.Store(outbound)
|
||||
selected = true
|
||||
}
|
||||
if updated {
|
||||
g.interruptGroup.Interrupt(g.interruptExternalConnections)
|
||||
}
|
||||
if selected {
|
||||
g.history.NotifyUpdated()
|
||||
}
|
||||
return selected
|
||||
}
|
||||
|
||||
+97
-25
@@ -6,7 +6,9 @@ import (
|
||||
"context"
|
||||
"encoding/pem"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/sagernet/cronet-go"
|
||||
_ "github.com/sagernet/cronet-go/all"
|
||||
@@ -33,14 +35,20 @@ func RegisterOutbound(registry *outbound.Registry) {
|
||||
outbound.Register[option.NaiveOutboundOptions](registry, C.TypeNaive, NewOutbound)
|
||||
}
|
||||
|
||||
var _ adapter.OutboundWithMultiplex = (*Outbound)(nil)
|
||||
var (
|
||||
_ adapter.OutboundWithMultiplex = (*Outbound)(nil)
|
||||
_ adapter.IdleConnectionKeeper = (*Outbound)(nil)
|
||||
)
|
||||
|
||||
type Outbound struct {
|
||||
outbound.Adapter
|
||||
ctx context.Context
|
||||
logger logger.ContextLogger
|
||||
client *cronet.NaiveClient
|
||||
uotClient *uot.Client
|
||||
ctx context.Context
|
||||
logger logger.ContextLogger
|
||||
client *cronet.NaiveClient
|
||||
uotClient *uot.Client
|
||||
streamAccess sync.Mutex
|
||||
streams int
|
||||
closeIdle bool
|
||||
}
|
||||
|
||||
func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.NaiveOutboundOptions) (adapter.Outbound, error) {
|
||||
@@ -200,27 +208,26 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var uotClient *uot.Client
|
||||
uotOptions := common.PtrValueOrDefault(options.UDPOverTCP)
|
||||
if uotOptions.Enabled {
|
||||
uotClient = &uot.Client{
|
||||
Dialer: &naiveDialer{client},
|
||||
Version: uotOptions.Version,
|
||||
}
|
||||
}
|
||||
var networks []string
|
||||
if uotClient != nil {
|
||||
if uotOptions.Enabled {
|
||||
networks = []string{N.NetworkTCP, N.NetworkUDP}
|
||||
} else {
|
||||
networks = []string{N.NetworkTCP}
|
||||
}
|
||||
return &Outbound{
|
||||
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeNaive, tag, networks, options.DialerOptions),
|
||||
ctx: ctx,
|
||||
logger: logger,
|
||||
client: client,
|
||||
uotClient: uotClient,
|
||||
}, nil
|
||||
outbound := &Outbound{
|
||||
Adapter: outbound.NewAdapterWithDialerOptions(C.TypeNaive, tag, networks, options.DialerOptions),
|
||||
ctx: ctx,
|
||||
logger: logger,
|
||||
client: client,
|
||||
}
|
||||
if uotOptions.Enabled {
|
||||
outbound.uotClient = &uot.Client{
|
||||
Dialer: (*naiveDialer)(outbound),
|
||||
Version: uotOptions.Version,
|
||||
}
|
||||
}
|
||||
return outbound, nil
|
||||
}
|
||||
|
||||
func (h *Outbound) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
@@ -240,7 +247,7 @@ func (h *Outbound) DialContext(ctx context.Context, network string, destination
|
||||
switch N.NetworkName(network) {
|
||||
case N.NetworkTCP:
|
||||
h.logger.InfoContext(ctx, "outbound connection to ", destination)
|
||||
return h.client.DialEarly(ctx, destination)
|
||||
return h.dialStream(ctx, destination)
|
||||
case N.NetworkUDP:
|
||||
if h.uotClient == nil {
|
||||
return nil, E.New("UDP is not supported unless UDP over TCP is enabled")
|
||||
@@ -267,14 +274,79 @@ func (h *Outbound) InterfaceUpdated(ctx context.Context) {
|
||||
h.client.CloseAllConnections()
|
||||
}
|
||||
|
||||
func (h *Outbound) SetKeepIdleConnections(keep bool) {
|
||||
h.streamAccess.Lock()
|
||||
h.closeIdle = !keep
|
||||
h.streamAccess.Unlock()
|
||||
if !keep {
|
||||
h.CloseIdleConnections()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Outbound) CloseIdleConnections() {
|
||||
h.streamAccess.Lock()
|
||||
defer h.streamAccess.Unlock()
|
||||
if h.streams == 0 {
|
||||
h.client.CloseAllConnections()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Outbound) dialStream(ctx context.Context, destination M.Socksaddr) (net.Conn, error) {
|
||||
h.streamAccess.Lock()
|
||||
h.streams++
|
||||
h.streamAccess.Unlock()
|
||||
keepSession := adapter.KeepSessionFromContext(ctx)
|
||||
conn, err := h.client.DialEarly(ctx, destination)
|
||||
if err != nil {
|
||||
h.releaseStream(keepSession)
|
||||
return nil, err
|
||||
}
|
||||
return &streamConn{NaiveConn: conn, onClose: func() { h.releaseStream(keepSession) }}, nil
|
||||
}
|
||||
|
||||
func (h *Outbound) releaseStream(keepSession bool) {
|
||||
h.streamAccess.Lock()
|
||||
defer h.streamAccess.Unlock()
|
||||
h.streams--
|
||||
if h.closeIdle && !keepSession && h.streams == 0 {
|
||||
h.client.CloseAllConnections()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Outbound) Client() *cronet.NaiveClient {
|
||||
return h.client
|
||||
}
|
||||
|
||||
type naiveDialer struct {
|
||||
*cronet.NaiveClient
|
||||
}
|
||||
type naiveDialer Outbound
|
||||
|
||||
func (d *naiveDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
return d.NaiveClient.DialEarly(ctx, destination)
|
||||
return (*Outbound)(d).dialStream(ctx, destination)
|
||||
}
|
||||
|
||||
func (d *naiveDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
return nil, os.ErrInvalid
|
||||
}
|
||||
|
||||
type streamConn struct {
|
||||
cronet.NaiveConn
|
||||
closeOnce sync.Once
|
||||
onClose func()
|
||||
}
|
||||
|
||||
func (c *streamConn) Close() error {
|
||||
err := c.NaiveConn.Close()
|
||||
c.closeOnce.Do(c.onClose)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *streamConn) Upstream() any {
|
||||
return c.NaiveConn
|
||||
}
|
||||
|
||||
func (c *streamConn) ReaderReplaceable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *streamConn) WriterReplaceable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -230,6 +230,10 @@ func (t *DNSTransport) updateConfiguration(configuration openconnecttransport.Co
|
||||
}
|
||||
}
|
||||
|
||||
func (t *DNSTransport) References() ([]string, []string) {
|
||||
return []string{t.endpointTag}, nil
|
||||
}
|
||||
|
||||
func (t *DNSTransport) Reset() {
|
||||
t.access.RLock()
|
||||
resolvers := t.collectResolversLocked()
|
||||
|
||||
@@ -277,6 +277,10 @@ func (t *DNSTransport) createResolver(server ovpntransport.DNSServer, address ne
|
||||
return dnsTransport.NewHTTPSRaw(t.TransportAdapter, t.logger, t.dialer, destination, http.Header{}, M.SocksaddrFrom(address.Addr(), port), tlsConfig), nil
|
||||
}
|
||||
|
||||
func (t *DNSTransport) References() ([]string, []string) {
|
||||
return []string{t.endpointTag}, nil
|
||||
}
|
||||
|
||||
func (t *DNSTransport) Reset() {
|
||||
t.access.RLock()
|
||||
resolvers := t.collectResolversLocked()
|
||||
|
||||
@@ -148,6 +148,6 @@ func (h *inboundHandler) NewConnectionEx(ctx context.Context, conn net.Conn, sou
|
||||
h.router.RouteConnectionEx(ctx, conn, metadata, onClose)
|
||||
}
|
||||
|
||||
func (h *Inbound) References() []string {
|
||||
return h.references
|
||||
func (h *Inbound) References() ([]string, []string) {
|
||||
return h.references, nil
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ func RegisterCertificateProvider(registry *certificate.Registry) {
|
||||
certificate.Register[option.TailscaleCertificateProviderOptions](registry, C.TypeTailscale, NewCertificateProvider)
|
||||
}
|
||||
|
||||
var _ adapter.CertificateProviderService = (*CertificateProvider)(nil)
|
||||
var (
|
||||
_ adapter.CertificateProviderService = (*CertificateProvider)(nil)
|
||||
_ adapter.Referrer = (*CertificateProvider)(nil)
|
||||
)
|
||||
|
||||
type CertificateProvider struct {
|
||||
certificate.Adapter
|
||||
@@ -63,6 +66,10 @@ func NewCertificateProvider(ctx context.Context, _ log.ContextLogger, tag string
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *CertificateProvider) References() ([]string, []string) {
|
||||
return []string{p.endpointTag}, nil
|
||||
}
|
||||
|
||||
func (p *CertificateProvider) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
if stage != adapter.StartStateStart {
|
||||
return nil
|
||||
|
||||
@@ -112,6 +112,10 @@ func (t *DNSTransport) Start(stage adapter.StartStage, scope *adapter.Scope) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *DNSTransport) References() ([]string, []string) {
|
||||
return []string{t.endpointTag}, nil
|
||||
}
|
||||
|
||||
func (t *DNSTransport) Reset() {
|
||||
t.access.RLock()
|
||||
transports := t.collectResolversLocked()
|
||||
|
||||
@@ -249,11 +249,11 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *Endpoint) References() []string {
|
||||
func (t *Endpoint) References() ([]string, []string) {
|
||||
if t.detour == "" {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
return []string{t.detour}
|
||||
return []string{t.detour}, nil
|
||||
}
|
||||
|
||||
func (t *Endpoint) Start(stage adapter.StartStage, scope *adapter.Scope) error {
|
||||
|
||||
@@ -265,6 +265,6 @@ func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.
|
||||
(*Inbound)(h).NewConnection(ctx, conn, metadata, onClose)
|
||||
}
|
||||
|
||||
func (h *Inbound) References() []string {
|
||||
return h.references
|
||||
func (h *Inbound) References() ([]string, []string) {
|
||||
return h.references, nil
|
||||
}
|
||||
|
||||
@@ -224,6 +224,6 @@ func (h *inboundTransportHandler) NewConnectionEx(ctx context.Context, conn net.
|
||||
(*Inbound)(h).NewConnection(ctx, conn, metadata, onClose)
|
||||
}
|
||||
|
||||
func (h *Inbound) References() []string {
|
||||
return h.references
|
||||
func (h *Inbound) References() ([]string, []string) {
|
||||
return h.references, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user