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 eb2de00
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions outbound/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,49 @@ 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")
// 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)
// if err != nil {
// w.logger.Error("Hiddify! bind update failed", err)
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!")
}
// if w.pauseManager.IsNetworkPaused() {
// w.logger.Error("Hiddify! Network is paused!... returning")
// return
// }
for i := 0; i < 5; i++ {
if !w.pauseManager.IsNetworkPaused() {
break
}
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 i == 4 {
w.logger.Errorf("No network is availble after 4 seconds, stopping wireguard.")

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-386, freebsd, 386)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64, linux, mips64)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv7, linux, arm, 7)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-arm64, freebsd, arm64)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-arm64, linux, arm64)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-386, linux, 386)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64, freebsd, amd64, v1)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv5, linux, arm, 5)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64, linux, amd64, v1)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv6, linux, arm, 6)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mipsel-softfloat, linux, mipsle, softfloat)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64el, linux, mips64le)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (darwin-arm64, darwin, arm64)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64, darwin, amd64, v1)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64-v3, linux, amd64, v3)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips-hardfloat, linux, mips, hardfloat)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64-v3, darwin, amd64, v3)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64-v3, freebsd, amd64, v3)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)

Check failure on line 235 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.20)

w.logger.Errorf undefined (type "github.com/sagernet/sing-box/log".ContextLogger has no field or method Errorf)
return
}
w.logger.Warn("Network is pause waiting ", i)
select {
case <-time.After(1 * time.Second):
case <-w.done:

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-386, freebsd, 386)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64, linux, mips64)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv7, linux, arm, 7)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-arm64, freebsd, arm64)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-arm64, linux, arm64)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-386, linux, 386)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64, freebsd, amd64, v1)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv5, linux, arm, 5)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64, linux, amd64, v1)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-armv6, linux, arm, 6)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mipsel-softfloat, linux, mipsle, softfloat)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips64el, linux, mips64le)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (darwin-arm64, darwin, arm64)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64, darwin, amd64, v1)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-amd64-v3, linux, amd64, v3)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (linux-mips-hardfloat, linux, mips, hardfloat)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (darwin-amd64-v3, darwin, amd64, v3)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / cross (freebsd-amd64-v3, freebsd, amd64, v3)

w.done undefined (type *WireGuard has no field or method done)

Check failure on line 241 in outbound/wireguard.go

View workflow job for this annotation

GitHub Actions / Debug build (Go 1.20)

w.done undefined (type *WireGuard has no field or method done)
return
}
}
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! OK2!Updating wireguard interface")
w.logger.Warn("Hiddify! OK!Updating wireguard interface")

}
// } else {
// w.logger.Warn("Hiddify! OK2!Updating wireguard interface")
// }
return
}

Expand All @@ -240,12 +262,15 @@ 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
err := w.device.Up()
w.logger.Warn("Hiddify! Wirguard! Uping net! err=", err)
}
}

Expand Down

0 comments on commit eb2de00

Please sign in to comment.