Skip to content

Commit

Permalink
make network up after it is availble
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 22, 2024
1 parent 8b10558 commit 48890c2
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions outbound/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,53 @@ func (w *WireGuard) Close() error {
}

func (w *WireGuard) InterfaceUpdated() {
w.logger.Warn("Hiddify! Wirguard! Interface updated!1")
err := w.device.BindUpdate()
// err := fmt.Errorf("Hiddify! downing wireguard interface failed")
w.logger.Warn("Hiddify! Wirguard! Interface updated!XXX")
// if true {
// return
// }
// err := w.device.BindUpdate()
// // 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")

}
// if err != nil {
// w.logger.Error("Hiddify! bind update failed", err)
if w.pauseManager.IsNetworkPaused() {
w.logger.Error("Hiddify! Network is paused!... returning")
return
}
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! OK2!Updating wireguard interface")
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
}

Expand All @@ -240,12 +266,16 @@ func (w *WireGuard) onPauseUpdated(event int) {

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)

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
<-time.After(100 * time.Millisecond)
err := w.device.Up()
w.logger.Warn("Hiddify! Wirguard! Uping net! err=", err)
}
}

Expand Down

0 comments on commit 48890c2

Please sign in to comment.