Files
mirror-3x-ui/internal/web/controller/client-wireguard-devices.go
T
Sanaei 3f2a2195a8 fix(wireguard): apply a peer change pushed to a node at once
The previous commit applied a device write at once, but only on the panel
that received the request. A node takes the same change as an inbound update
from its master, and that path still flagged the 30 s reconcile: a device
disabled on the master kept its tunnel on the node until the node's next tick.

ReconcileNow is the one place both paths go through. It applies when the core
runs and only flags when it is down, so a device write never starts a core the
tick has not started.

Measured with a real master and node panel (Xray 26.11.9, kernel WireGuard
clients): a device disabled on the master is cut on the node after 5 s instead
of 11-30 s, and a new one connects 7 s after it is added. No unit test reaches
it, a test process is never running; the scenario is the proof.
2026-11-25 00:13:21 +03:30

60 lines
1.7 KiB
Go

package controller
import (
"github.com/gin-gonic/gin"
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
)
func (a *ClientController) wireguardDevices(c *gin.Context) {
devices, err := a.clientService.WireguardDevices(c.Query("email"))
jsonObj(c, devices, err)
}
func (a *ClientController) finishWireguardDeviceWrite(c *gin.Context, err error) {
if err != nil {
jsonObj(c, nil, err)
return
}
// Not left to the 30 s reconcile tick: until then a disabled or deleted device
// kept its tunnel (measured 12-24 s on a running panel).
a.xrayService.ReconcileNow()
notifyClientsChanged()
a.wireguardDevices(c)
}
func (a *ClientController) addWireguardDevice(c *gin.Context) {
var body struct {
Name string `json:"name"`
}
if err := c.ShouldBindJSON(&body); err != nil {
jsonObj(c, nil, err)
return
}
a.finishWireguardDeviceWrite(c, a.clientService.AddWireguardDevice(c.Query("email"), body.Name))
}
func (a *ClientController) updateWireguardDevice(c *gin.Context) {
var patch service.WireguardDevicePatch
if err := c.ShouldBindJSON(&patch); err != nil {
jsonObj(c, nil, err)
return
}
a.finishWireguardDeviceWrite(c, a.clientService.UpdateWireguardDevice(c.Query("email"), c.Param("deviceId"), patch))
}
func (a *ClientController) deleteWireguardDevice(c *gin.Context) {
a.finishWireguardDeviceWrite(c, a.clientService.DeleteWireguardDevice(c.Query("email"), c.Param("deviceId")))
}
func (a *ClientController) setWireguardDeviceLimit(c *gin.Context) {
var body struct {
Limit int `json:"limit"`
}
if err := c.ShouldBindJSON(&body); err != nil {
jsonObj(c, nil, err)
return
}
a.finishWireguardDeviceWrite(c, a.clientService.SetWireguardDeviceLimit(c.Query("email"), body.Limit))
}