refactor: rework limiter, traffic accounting, and logging (nlog)

This commit is contained in:
xboard
2026-03-23 23:01:13 +08:00
parent 4676caac96
commit 3f1234a05c
20 changed files with 1721 additions and 1333 deletions
+17 -1
View File
@@ -118,10 +118,26 @@ type NodeConfig struct {
// Multiplex
Multiplex *MultiplexConfig `json:"multiplex,omitempty"`
// Proxy Protocol
// Proxy Protocol (supports both top-level and networkSettings for compatibility)
AcceptProxyProtocol bool `json:"accept_proxy_protocol,omitempty"`
}
// GetProxyProtocol returns true if AcceptProxyProtocol is set either at node level
// or in networkSettings (for panel compatibility).
func (nc *NodeConfig) GetProxyProtocol() bool {
if nc.AcceptProxyProtocol {
return true
}
if nc.NetworkSettings != nil {
if v, ok := nc.NetworkSettings["acceptProxyProtocol"]; ok {
if b, ok := v.(bool); ok {
return b
}
}
}
return false
}
type MultiplexConfig struct {
Enabled bool `json:"enabled"`
Protocol string `json:"protocol"`
+18 -4
View File
@@ -185,12 +185,10 @@ func (w *WSClient) connect(ctx context.Context) error {
// Process it and continue
w.connected.Store(true)
w.notifyStatus(true)
slog.Info("ws connected (implicit auth)")
w.handleMessage(firstMsg)
} else {
w.connected.Store(true)
w.notifyStatus(true)
slog.Info("ws connected and authenticated")
}
// Ping interval: send pong responses to server pings.
@@ -314,19 +312,27 @@ func (w *WSClient) handleDataEvent(msg wsMessage) {
case WSEventSyncConfig:
slog.Debug("ws sync config event received")
var p syncConfigPayload
if err := decodeData(msg.Data, &p); err != nil && p.Config.Protocol != "" {
if err := decodeData(msg.Data, &p); err != nil {
slog.Warn("ws: cannot decode config payload", "error", err)
return
}
if p.Config.Protocol == "" {
slog.Warn("ws: config payload missing protocol")
return
}
event.Config = &p.Config
case WSEventSyncUsers:
slog.Debug("ws sync users event received")
var p syncUsersPayload
if err := decodeData(msg.Data, &p); err != nil && len(p.Users) > 0 {
if err := decodeData(msg.Data, &p); err != nil {
slog.Warn("ws: cannot decode users payload", "error", err)
return
}
if len(p.Users) == 0 {
slog.Warn("ws: users payload empty")
return
}
event.Users = p.Users
case WSEventSyncUserDelta:
@@ -336,6 +342,14 @@ func (w *WSClient) handleDataEvent(msg wsMessage) {
slog.Warn("ws: cannot decode user delta payload", "error", err)
return
}
if p.Action == "" {
slog.Warn("ws: user delta payload missing action")
return
}
if len(p.Users) == 0 {
slog.Warn("ws: user delta payload has no users")
return
}
event.DeltaAction = p.Action
event.DeltaUsers = p.Users
}