refactor: More interface reuse

This commit is contained in:
世界 2024-11-11 15:59:47 +08:00
parent 1015c096bb
commit 355e4e81cc
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
8 changed files with 51 additions and 107 deletions

View file

@ -51,14 +51,14 @@ func (m *defaultInterfaceMonitor) checkUpdate() error {
return err
}
oldInterface := m.defaultInterfaceName
oldIndex := m.defaultInterfaceIndex
m.defaultInterfaceName = link.Attrs().Name
m.defaultInterfaceIndex = link.Attrs().Index
oldInterface := m.defaultInterface.Load()
newInterface, err := m.interfaceFinder.ByIndex(link.Attrs().Index)
if err != nil {
return E.Cause(err, "find updated interface: ", link.Attrs().Name)
}
m.defaultInterface.Store(newInterface)
var event int
if oldInterface != m.defaultInterfaceName || oldIndex != m.defaultInterfaceIndex {
if oldInterface == nil || oldInterface.Name != newInterface.Name || oldInterface.Index != newInterface.Index {
event |= EventInterfaceUpdate
}
if oldVPNEnabled != m.androidVPNEnabled {