mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 21:33:57 -07:00
misc bug fixes related to default routes
This commit is contained in:
parent
1756e8b0f2
commit
3fc11e2278
6 changed files with 57 additions and 33 deletions
|
@ -70,29 +70,33 @@ class NetworkMonitor: NSObject {
|
|||
var networks = self.savedNetworks
|
||||
|
||||
for nw in receivedNetworks {
|
||||
let index = findNetworkWithID(nw.nwid)
|
||||
let index = findSavedNetworkWithID(nw.nwid)
|
||||
|
||||
if index != NSNotFound {
|
||||
networks[index] = nw
|
||||
}
|
||||
networks.sortInPlace({ (left, right) -> Bool in
|
||||
if left.nwid < right.nwid {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
objc_sync_enter(allNetworks)
|
||||
allNetworks = networks
|
||||
objc_sync_exit(allNetworks)
|
||||
|
||||
saveNetworks()
|
||||
|
||||
let nc = NSNotificationCenter.defaultCenter()
|
||||
|
||||
nc.postNotificationName(networkUpdateKey, object: nil, userInfo: ["networks": networks])
|
||||
else {
|
||||
networks.append(nw)
|
||||
}
|
||||
}
|
||||
|
||||
networks.sortInPlace({ (left, right) -> Bool in
|
||||
if left.nwid < right.nwid {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
objc_sync_enter(allNetworks)
|
||||
allNetworks = networks
|
||||
objc_sync_exit(allNetworks)
|
||||
|
||||
saveNetworks()
|
||||
|
||||
let nc = NSNotificationCenter.defaultCenter()
|
||||
|
||||
nc.postNotificationName(networkUpdateKey, object: nil, userInfo: ["networks": networks])
|
||||
}
|
||||
|
||||
private func findNetworkWithID(nwid: UInt64) -> Int {
|
||||
|
@ -106,6 +110,17 @@ class NetworkMonitor: NSObject {
|
|||
return NSNotFound
|
||||
}
|
||||
|
||||
private func findSavedNetworkWithID(nwid: UInt64) -> Int {
|
||||
for (index, element) in savedNetworks.enumerate() {
|
||||
|
||||
if element.nwid == nwid {
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
return NSNotFound
|
||||
}
|
||||
|
||||
private func saveNetworks() {
|
||||
let file = dataFile()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue