diff --git a/outbound/wireguard.go b/outbound/wireguard.go index c009b56264..d9d38beb71 100644 --- a/outbound/wireguard.go +++ b/outbound/wireguard.go @@ -210,42 +210,77 @@ func (w *WireGuard) Close() error { } func (w *WireGuard) InterfaceUpdated() { - w.logger.Warn("Hiddify! Wirguard! Interface updated!1") + w.logger.Warn("Hiddify! Wirguard! Interface updated!XXX") + // <-time.After(10 * time.Millisecond) + // if true { + // return + // } + if w.pauseManager.IsNetworkPaused() { + w.logger.Error("Hiddify! Network is paused!... returning") + return + } + <-time.After(50 * time.Millisecond) err := w.device.BindUpdate() + <-time.After(50 * time.Millisecond) // err := fmt.Errorf("Hiddify! downing wireguard interface failed") if err != nil { w.logger.Error("Hiddify! bind update failed", err) - e1 := w.device.Down() - if e1 != nil { - w.logger.Error("Hiddify! downing wireguard interface failed", e1) - } - w.logger.Warn("Hiddify! uping.... wireguard interface") - e2 := w.device.Up() - if e2 != nil { - w.logger.Error("Hiddify! Uping wireguard interface failed", e2) - } else { - w.logger.Warn("Hiddify! OK!Updating wireguard interface") - - } - } else { - w.logger.Warn("Hiddify! OK2!Updating wireguard interface") } + // w.logger.Error("Hiddify! downing...") + // e1 := w.device.Down() + // if e1 != nil { + // w.logger.Error("Hiddify! downing wireguard interface failed", e1) + // } else { + // w.logger.Warn("Hiddify! downing Ok!") + // } + // for i := 0; i < 5; i++ { + // if !w.pauseManager.IsNetworkPaused() { + // break + // } + // if i == 4 { + // w.logger.Error("No network is availble after 4 seconds, stopping wireguard.") + // return + // } + // w.logger.Warn("Network is pause waiting ", i) + // select { + // case <-time.After(1 * time.Second): + // // case <-w.conn.done: + // // return + // } + // } + // <-time.After(100 * time.Millisecond) + // w.logger.Warn("Hiddify! uping.... wireguard interface") + // e2 := w.device.Up() + // if e2 != nil { + // w.logger.Error("Hiddify! Uping wireguard interface failed", e2) + // } else { + // w.logger.Warn("Hiddify! OK!Updating wireguard interface") + + // } + // } else { + // w.logger.Warn("Hiddify! OK2!Updating wireguard interface") + // } return } func (w *WireGuard) onPauseUpdated(event int) { w.logger.Warn("Hiddify! Wirguard! on Pause updated! event=", event) + // <-time.After(1000 * time.Millisecond) switch event { case pause.EventDevicePaused: w.device.Down() - // case EventNetworkPause://hiddify already handled in Interface Updated - // w.device.Down() + case pause.EventNetworkPause: //hiddify already handled in Interface Updated + err := w.device.Down() + w.logger.Warn("Hiddify! Wirguard! downing net! err=", err) + <-time.After(50 * time.Millisecond) case pause.EventDeviceWake: w.device.Up() - // case pause.EventNetworkWake://hiddify already handled in Interface Updated - // w.device.Up() + case pause.EventNetworkWake: //hiddify already handled in Interface Updated + err := w.device.Up() + w.logger.Warn("Hiddify! Wirguard! Uping net! err=", err) + <-time.After(50 * time.Millisecond) } } diff --git a/route/router.go b/route/router.go index 4853780b4a..9f1194bde9 100644 --- a/route/router.go +++ b/route/router.go @@ -327,10 +327,17 @@ func NewRouter( } interfaceMonitor.RegisterCallback(router.notifyNetworkUpdate) router.interfaceMonitor = interfaceMonitor + // go func() { + // <-time.After(10 * time.Second) + // router.notifyNetworkUpdate(3) + // <-time.After(10 * time.Second) + // router.notifyNetworkUpdate(3) + // }() } } else { interfaceMonitor := platformInterface.CreateDefaultInterfaceMonitor(router.logger) interfaceMonitor.RegisterCallback(router.notifyNetworkUpdate) + router.interfaceMonitor = interfaceMonitor } @@ -1180,7 +1187,7 @@ func (r *Router) notifyNetworkUpdate(event int) { return } - _ = r.ResetNetwork() + go r.ResetNetwork() } func (r *Router) ResetNetwork() error {