fix: add status field to service list/detail APIs, unify observeStats retry pattern, fix router bugs

- api: add fillServiceStatus helper and call it from getServiceList/getService
  so status field appears in service list and detail API responses
- observeStats: unify retry pattern across all 9 handlers (http, http2, masque,
  relay, router, socks4, socks5, tungo, tunnel) — buffer events on failure,
  continue to skip fresh collection, clear on success; fix event-loss bug
  where interim events were dropped during retry cycles
- handler/router: check WriteTo/Write return errors in associate.go and
  entrypoint.go; fix DelConnector and ConnectorPool.Del using RLock instead
  of Lock (write under read lock); remove unused fields t and cancel
This commit is contained in:
ginuerzh
2026-06-03 22:12:08 +08:00
parent 785d52da31
commit 95874c53f5
14 changed files with 150 additions and 103 deletions
+4 -13
View File
@@ -1,10 +1,8 @@
package router
import (
"context"
"io"
"sync"
"time"
"github.com/go-gost/core/logger"
"github.com/go-gost/relay"
@@ -76,7 +74,6 @@ type Router struct {
node string
id relay.TunnelID
connectors map[string][]*Connector
t time.Time
close chan struct{}
mu sync.RWMutex
}
@@ -86,7 +83,6 @@ func NewRouter(node string, rid relay.TunnelID) *Router {
node: node,
id: rid,
connectors: make(map[string][]*Connector),
t: time.Now(),
close: make(chan struct{}),
}
return r
@@ -139,8 +135,8 @@ func (r *Router) GetConnector(host string) *Connector {
}
func (r *Router) DelConnector(host string, cid relay.ConnectorID) {
r.mu.RLock()
defer r.mu.RUnlock()
r.mu.Lock()
defer r.mu.Unlock()
connectors := r.connectors[host]
for i, c := range connectors {
@@ -174,7 +170,6 @@ type ConnectorPool struct {
node string
routers map[relay.TunnelID]*Router
mu sync.RWMutex
cancel context.CancelFunc
}
func NewConnectorPool(node string) *ConnectorPool {
@@ -219,8 +214,8 @@ func (p *ConnectorPool) Del(rid relay.TunnelID, host string, cid relay.Connector
return
}
p.mu.RLock()
defer p.mu.RUnlock()
p.mu.Lock()
defer p.mu.Unlock()
r := p.routers[rid]
if r == nil {
@@ -235,10 +230,6 @@ func (p *ConnectorPool) Close() error {
return nil
}
if p.cancel != nil {
p.cancel()
}
p.mu.Lock()
defer p.mu.Unlock()