Close idle connections of unreferenced outbounds and DNS servers

This commit is contained in:
世界
2026-10-02 18:00:09 +08:00
parent d2cf9747d7
commit fd9a076d25
40 changed files with 851 additions and 81 deletions
+15 -4
View File
@@ -26,10 +26,11 @@ func RegisterInbound(registry *inbound.Registry) {
type Inbound struct {
inbound.Adapter
router adapter.Router
logger logger.ContextLogger
listener *listener.Listener
service *shadowtls.Service
router adapter.Router
logger logger.ContextLogger
listener *listener.Listener
service *shadowtls.Service
references []string
}
func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.ShadowTLSInboundOptions) (adapter.Inbound, error) {
@@ -48,6 +49,9 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
handshakeForServerName = make(map[string]shadowtls.HandshakeConfig)
if options.HandshakeForServerName != nil {
for _, entry := range options.HandshakeForServerName.Entries() {
if entry.Value.Detour != "" {
inbound.references = append(inbound.references, entry.Value.Detour)
}
handshakeDialer, err := dialer.New(ctx, entry.Value.DialerOptions, entry.Value.ServerIsDomain())
if err != nil {
return nil, err
@@ -67,6 +71,9 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
if err != nil {
return nil, err
}
if options.Handshake.Detour != "" {
inbound.references = append(inbound.references, options.Handshake.Detour)
}
service, err := shadowtls.NewService(shadowtls.ServiceConfig{
Version: options.Version,
Password: options.Password,
@@ -139,3 +146,7 @@ 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
}