Skip to content

Commit

Permalink
Add no route event
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Aug 7, 2023
1 parent 688d4da commit 59b8600
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type (
)

const (
EventInterfaceUpdate = 1
EventAndroidVPNUpdate = 2
EventInterfaceUpdate = iota
EventAndroidVPNUpdate
EventNoRoute
)

type NetworkUpdateMonitor interface {
Expand Down
7 changes: 6 additions & 1 deletion monitor_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package tun

import (
"context"
"errors"
"net"
"net/netip"
"sync"
Expand Down Expand Up @@ -84,7 +85,11 @@ func (m *defaultInterfaceMonitor) delayCheckUpdate() error {
if err != nil {
m.networkMonitor.NewError(context.Background(), E.Cause(err, "update interfaces"))
}
return m.checkUpdate()
err = m.checkUpdate()
if errors.Is(err, ErrNoRoute) {
m.emit(EventNoRoute)
}
return err
}

func (m *defaultInterfaceMonitor) updateInterfaces() error {
Expand Down

0 comments on commit 59b8600

Please sign in to comment.