Fix reset network

This commit is contained in:
世界
2026-05-05 20:19:19 +08:00
parent 4807ee9007
commit 3e5991744d
7 changed files with 25 additions and 19 deletions
+4 -4
View File
@@ -18,10 +18,10 @@ import (
"github.com/gofrs/uuid/v5"
)
func connectionRouter(ctx context.Context, router adapter.Router, trafficManager *trafficontrol.Manager) http.Handler {
func connectionRouter(ctx context.Context, network adapter.NetworkManager, trafficManager *trafficontrol.Manager) http.Handler {
r := chi.NewRouter()
r.Get("/", getConnections(ctx, trafficManager))
r.Delete("/", closeAllConnections(router, trafficManager))
r.Delete("/", closeAllConnections(network, trafficManager))
r.Delete("/{id}", closeConnection(trafficManager))
return r
}
@@ -96,13 +96,13 @@ func closeConnection(trafficManager *trafficontrol.Manager) func(w http.Response
}
}
func closeAllConnections(router adapter.Router, trafficManager *trafficontrol.Manager) func(w http.ResponseWriter, r *http.Request) {
func closeAllConnections(network adapter.NetworkManager, trafficManager *trafficontrol.Manager) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
snapshot := trafficManager.Snapshot()
for _, c := range snapshot.Connections {
c.Close()
}
router.ResetNetwork()
network.ResetNetwork()
render.NoContent(w, r)
}
}
+3 -1
View File
@@ -43,6 +43,7 @@ var _ adapter.ClashServer = (*Server)(nil)
type Server struct {
ctx context.Context
network adapter.NetworkManager
router adapter.Router
dnsRouter adapter.DNSRouter
outbound adapter.OutboundManager
@@ -69,6 +70,7 @@ func NewServer(ctx context.Context, logFactory log.ObservableFactory, options op
chiRouter := chi.NewRouter()
s := &Server{
ctx: ctx,
network: service.FromContext[adapter.NetworkManager](ctx),
router: service.FromContext[adapter.Router](ctx),
dnsRouter: service.FromContext[adapter.DNSRouter](ctx),
outbound: service.FromContext[adapter.OutboundManager](ctx),
@@ -124,7 +126,7 @@ func NewServer(ctx context.Context, logFactory log.ObservableFactory, options op
r.Mount("/configs", configRouter(s, logFactory))
r.Mount("/proxies", proxyRouter(s, s.router))
r.Mount("/rules", ruleRouter(s.router))
r.Mount("/connections", connectionRouter(s.ctx, s.router, trafficManager))
r.Mount("/connections", connectionRouter(s.ctx, s.network, trafficManager))
r.Mount("/providers/proxies", proxyProviderRouter())
r.Mount("/providers/rules", ruleProviderRouter())
r.Mount("/script", scriptRouter())