mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Convert Network to OBJC
This commit is contained in:
parent
7a12d8193b
commit
a0db48571d
7 changed files with 338 additions and 288 deletions
|
@ -15,7 +15,6 @@
|
||||||
932D47371D1CDC9B004BCFE2 /* AboutViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 932D47351D1CDC9B004BCFE2 /* AboutViewController.xib */; };
|
932D47371D1CDC9B004BCFE2 /* AboutViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 932D47351D1CDC9B004BCFE2 /* AboutViewController.xib */; };
|
||||||
932D473A1D220D63004BCFE2 /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 932D47391D220D63004BCFE2 /* LaunchAtLoginController.m */; };
|
932D473A1D220D63004BCFE2 /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 932D47391D220D63004BCFE2 /* LaunchAtLoginController.m */; };
|
||||||
9330F1351CEAB4C400687EC8 /* ServiceCom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9330F1341CEAB4C400687EC8 /* ServiceCom.swift */; };
|
9330F1351CEAB4C400687EC8 /* ServiceCom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9330F1341CEAB4C400687EC8 /* ServiceCom.swift */; };
|
||||||
9330F1371CEBF87200687EC8 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9330F1361CEBF87200687EC8 /* Network.swift */; };
|
|
||||||
9330F13B1CF534E500687EC8 /* NetworkInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9330F13A1CF534E500687EC8 /* NetworkInfoCell.swift */; };
|
9330F13B1CF534E500687EC8 /* NetworkInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9330F13A1CF534E500687EC8 /* NetworkInfoCell.swift */; };
|
||||||
93326BDC1CE7C816005CA2AC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93326BDB1CE7C816005CA2AC /* AppDelegate.swift */; };
|
93326BDC1CE7C816005CA2AC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93326BDB1CE7C816005CA2AC /* AppDelegate.swift */; };
|
||||||
93326BDE1CE7C816005CA2AC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 93326BDD1CE7C816005CA2AC /* Assets.xcassets */; };
|
93326BDE1CE7C816005CA2AC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 93326BDD1CE7C816005CA2AC /* Assets.xcassets */; };
|
||||||
|
@ -25,6 +24,8 @@
|
||||||
93326BEE1CE7DA30005CA2AC /* ShowNetworksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93326BEC1CE7DA30005CA2AC /* ShowNetworksViewController.swift */; };
|
93326BEE1CE7DA30005CA2AC /* ShowNetworksViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93326BEC1CE7DA30005CA2AC /* ShowNetworksViewController.swift */; };
|
||||||
93326BEF1CE7DA30005CA2AC /* ShowNetworksViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93326BED1CE7DA30005CA2AC /* ShowNetworksViewController.xib */; };
|
93326BEF1CE7DA30005CA2AC /* ShowNetworksViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93326BED1CE7DA30005CA2AC /* ShowNetworksViewController.xib */; };
|
||||||
93D1675F1D54191C00330C99 /* NodeStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D1675E1D54191C00330C99 /* NodeStatus.m */; };
|
93D1675F1D54191C00330C99 /* NodeStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D1675E1D54191C00330C99 /* NodeStatus.m */; };
|
||||||
|
93D167621D541BC200330C99 /* ServiceCom.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D167611D541BC200330C99 /* ServiceCom.m */; };
|
||||||
|
93D167661D54308200330C99 /* Network.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D167651D54308200330C99 /* Network.m */; };
|
||||||
93DAFB271D3F0BEE004D5417 /* about.html in Resources */ = {isa = PBXBuildFile; fileRef = 93DAFB261D3F0BEE004D5417 /* about.html */; };
|
93DAFB271D3F0BEE004D5417 /* about.html in Resources */ = {isa = PBXBuildFile; fileRef = 93DAFB261D3F0BEE004D5417 /* about.html */; };
|
||||||
93DAFE4B1CFE53CA00547CC4 /* AuthtokenCopy.m in Sources */ = {isa = PBXBuildFile; fileRef = 93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */; };
|
93DAFE4B1CFE53CA00547CC4 /* AuthtokenCopy.m in Sources */ = {isa = PBXBuildFile; fileRef = 93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
@ -39,7 +40,6 @@
|
||||||
932D47381D220D63004BCFE2 /* LaunchAtLoginController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; sourceTree = "<group>"; };
|
932D47381D220D63004BCFE2 /* LaunchAtLoginController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; sourceTree = "<group>"; };
|
||||||
932D47391D220D63004BCFE2 /* LaunchAtLoginController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = "<group>"; };
|
932D47391D220D63004BCFE2 /* LaunchAtLoginController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = "<group>"; };
|
||||||
9330F1341CEAB4C400687EC8 /* ServiceCom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceCom.swift; sourceTree = "<group>"; };
|
9330F1341CEAB4C400687EC8 /* ServiceCom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceCom.swift; sourceTree = "<group>"; };
|
||||||
9330F1361CEBF87200687EC8 /* Network.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
|
|
||||||
9330F13A1CF534E500687EC8 /* NetworkInfoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkInfoCell.swift; sourceTree = "<group>"; };
|
9330F13A1CF534E500687EC8 /* NetworkInfoCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkInfoCell.swift; sourceTree = "<group>"; };
|
||||||
93326BD81CE7C816005CA2AC /* ZeroTier One.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ZeroTier One.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
93326BD81CE7C816005CA2AC /* ZeroTier One.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ZeroTier One.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
|
@ -52,6 +52,10 @@
|
||||||
93326BED1CE7DA30005CA2AC /* ShowNetworksViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ShowNetworksViewController.xib; sourceTree = "<group>"; };
|
93326BED1CE7DA30005CA2AC /* ShowNetworksViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ShowNetworksViewController.xib; sourceTree = "<group>"; };
|
||||||
93D1675D1D54191C00330C99 /* NodeStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeStatus.h; sourceTree = "<group>"; };
|
93D1675D1D54191C00330C99 /* NodeStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeStatus.h; sourceTree = "<group>"; };
|
||||||
93D1675E1D54191C00330C99 /* NodeStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NodeStatus.m; sourceTree = "<group>"; };
|
93D1675E1D54191C00330C99 /* NodeStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NodeStatus.m; sourceTree = "<group>"; };
|
||||||
|
93D167601D541BC200330C99 /* ServiceCom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceCom.h; sourceTree = "<group>"; };
|
||||||
|
93D167611D541BC200330C99 /* ServiceCom.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ServiceCom.m; sourceTree = "<group>"; };
|
||||||
|
93D167641D54308200330C99 /* Network.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Network.h; sourceTree = "<group>"; };
|
||||||
|
93D167651D54308200330C99 /* Network.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Network.m; sourceTree = "<group>"; };
|
||||||
93DAFB261D3F0BEE004D5417 /* about.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = about.html; sourceTree = "<group>"; };
|
93DAFB261D3F0BEE004D5417 /* about.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = about.html; sourceTree = "<group>"; };
|
||||||
93DAFE491CFE53C900547CC4 /* ZeroTier One-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ZeroTier One-Bridging-Header.h"; sourceTree = "<group>"; };
|
93DAFE491CFE53C900547CC4 /* ZeroTier One-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ZeroTier One-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||||
93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AuthtokenCopy.m; sourceTree = "<group>"; };
|
93DAFE4A1CFE53CA00547CC4 /* AuthtokenCopy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AuthtokenCopy.m; sourceTree = "<group>"; };
|
||||||
|
@ -91,7 +95,6 @@
|
||||||
932D472E1D1CD499004BCFE2 /* ZeroTierIcon.icns */,
|
932D472E1D1CD499004BCFE2 /* ZeroTierIcon.icns */,
|
||||||
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */,
|
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */,
|
||||||
93326BE81CE7D9B9005CA2AC /* JoinNetworkViewController.swift */,
|
93326BE81CE7D9B9005CA2AC /* JoinNetworkViewController.swift */,
|
||||||
9330F1361CEBF87200687EC8 /* Network.swift */,
|
|
||||||
9330F13A1CF534E500687EC8 /* NetworkInfoCell.swift */,
|
9330F13A1CF534E500687EC8 /* NetworkInfoCell.swift */,
|
||||||
93326BEC1CE7DA30005CA2AC /* ShowNetworksViewController.swift */,
|
93326BEC1CE7DA30005CA2AC /* ShowNetworksViewController.swift */,
|
||||||
9330F1341CEAB4C400687EC8 /* ServiceCom.swift */,
|
9330F1341CEAB4C400687EC8 /* ServiceCom.swift */,
|
||||||
|
@ -113,6 +116,10 @@
|
||||||
93DAFB261D3F0BEE004D5417 /* about.html */,
|
93DAFB261D3F0BEE004D5417 /* about.html */,
|
||||||
93D1675D1D54191C00330C99 /* NodeStatus.h */,
|
93D1675D1D54191C00330C99 /* NodeStatus.h */,
|
||||||
93D1675E1D54191C00330C99 /* NodeStatus.m */,
|
93D1675E1D54191C00330C99 /* NodeStatus.m */,
|
||||||
|
93D167601D541BC200330C99 /* ServiceCom.h */,
|
||||||
|
93D167611D541BC200330C99 /* ServiceCom.m */,
|
||||||
|
93D167641D54308200330C99 /* Network.h */,
|
||||||
|
93D167651D54308200330C99 /* Network.m */,
|
||||||
);
|
);
|
||||||
path = "ZeroTier One";
|
path = "ZeroTier One";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -193,7 +200,7 @@
|
||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
9330F1371CEBF87200687EC8 /* Network.swift in Sources */,
|
93D167621D541BC200330C99 /* ServiceCom.m in Sources */,
|
||||||
932D472D1D138B0C004BCFE2 /* NetworkMonitor.swift in Sources */,
|
932D472D1D138B0C004BCFE2 /* NetworkMonitor.swift in Sources */,
|
||||||
932D47321D1CD861004BCFE2 /* PreferencesViewController.swift in Sources */,
|
932D47321D1CD861004BCFE2 /* PreferencesViewController.swift in Sources */,
|
||||||
932D473A1D220D63004BCFE2 /* LaunchAtLoginController.m in Sources */,
|
932D473A1D220D63004BCFE2 /* LaunchAtLoginController.m in Sources */,
|
||||||
|
@ -204,6 +211,7 @@
|
||||||
93326BEE1CE7DA30005CA2AC /* ShowNetworksViewController.swift in Sources */,
|
93326BEE1CE7DA30005CA2AC /* ShowNetworksViewController.swift in Sources */,
|
||||||
93D1675F1D54191C00330C99 /* NodeStatus.m in Sources */,
|
93D1675F1D54191C00330C99 /* NodeStatus.m in Sources */,
|
||||||
932D47361D1CDC9B004BCFE2 /* AboutViewController.swift in Sources */,
|
932D47361D1CDC9B004BCFE2 /* AboutViewController.swift in Sources */,
|
||||||
|
93D167661D54308200330C99 /* Network.m in Sources */,
|
||||||
9330F1351CEAB4C400687EC8 /* ServiceCom.swift in Sources */,
|
9330F1351CEAB4C400687EC8 /* ServiceCom.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
|
52
ZeroTier One/Network.h
Normal file
52
ZeroTier One/Network.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
//
|
||||||
|
// Network.h
|
||||||
|
// ZeroTier One
|
||||||
|
//
|
||||||
|
// Created by Grant Limberg on 8/4/16.
|
||||||
|
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
enum NetworkStatus {
|
||||||
|
REQUESTING_CONFIGURATION,
|
||||||
|
OK,
|
||||||
|
ACCESS_DENIED,
|
||||||
|
NOT_FOUND,
|
||||||
|
PORT_ERROR,
|
||||||
|
CLIENT_TOO_OLD,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum NetworkType {
|
||||||
|
PUBLIC,
|
||||||
|
PRIVATE,
|
||||||
|
};
|
||||||
|
|
||||||
|
@interface Network : NSObject <NSCoding>
|
||||||
|
|
||||||
|
@property (readonly) NSArray<NSString*> *assignedAddresses;
|
||||||
|
@property (readonly) BOOL bridge;
|
||||||
|
@property (readonly) BOOL broadcastEnabled;
|
||||||
|
@property (readonly) BOOL dhcp;
|
||||||
|
@property (readonly) NSString *mac;
|
||||||
|
@property (readonly) int mtu;
|
||||||
|
@property (readonly) int netconfRevision;
|
||||||
|
@property (readonly) NSString *name;
|
||||||
|
@property (readonly) UInt64 nwid;
|
||||||
|
@property (readonly) NSString *portDeviceName;
|
||||||
|
@property (readonly) int portError;
|
||||||
|
@property (readonly) enum NetworkStatus status;
|
||||||
|
@property (readonly) enum NetworkType type;
|
||||||
|
@property (readonly) BOOL allowManaged;
|
||||||
|
@property (readonly) BOOL allowGlobal;
|
||||||
|
@property (readonly) BOOL allowDefault;
|
||||||
|
@property (readonly) BOOL connected; // not persisted. set to YES if loaded via json
|
||||||
|
|
||||||
|
- (id)initWithJsonData:(NSDictionary*)jsonData;
|
||||||
|
- (id)initWithCoder:(NSCoder *)aDecoder;
|
||||||
|
- (void)encodeWithCoder:(NSCoder *)aCoder;
|
||||||
|
+ (BOOL)defaultRouteExists:(NSArray<Network *>*)netList;
|
||||||
|
- (NSString*)statusString;
|
||||||
|
- (NSString*)typeString;
|
||||||
|
|
||||||
|
@end
|
268
ZeroTier One/Network.m
Normal file
268
ZeroTier One/Network.m
Normal file
|
@ -0,0 +1,268 @@
|
||||||
|
//
|
||||||
|
// Network.m
|
||||||
|
// ZeroTier One
|
||||||
|
//
|
||||||
|
// Created by Grant Limberg on 8/4/16.
|
||||||
|
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "Network.h"
|
||||||
|
|
||||||
|
NSString *NetworkAddressesKey = @"addresses";
|
||||||
|
NSString *NetworkBridgeKey = @"bridge";
|
||||||
|
NSString *NetworkBroadcastKey = @"broadcast";
|
||||||
|
NSString *NetworkDhcpKey = @"dhcp";
|
||||||
|
NSString *NetworkMacKey = @"mac";
|
||||||
|
NSString *NetworkMtuKey = @"mtu";
|
||||||
|
NSString *NetworkMulticastKey = @"multicast";
|
||||||
|
NSString *NetworkNameKey = @"name";
|
||||||
|
NSString *NetworkNetconfKey = @"netconf";
|
||||||
|
NSString *NetworkNwidKey = @"nwid";
|
||||||
|
NSString *NetworkPortNameKey = @"port";
|
||||||
|
NSString *NetworkPortErrorKey = @"portError";
|
||||||
|
NSString *NetworkStatusKey = @"status";
|
||||||
|
NSString *NetworkTypeKey = @"type";
|
||||||
|
NSString *NetworkAllowManagedKey = @"allowManaged";
|
||||||
|
NSString *NetworkAllowGlobalKey = @"allowGlobal";
|
||||||
|
NSString *NetworkAllowDefaultKey = @"allowDefault";
|
||||||
|
|
||||||
|
@implementation Network
|
||||||
|
|
||||||
|
- (id)initWithJsonData:(NSDictionary*)jsonData
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if(self) {
|
||||||
|
if([jsonData objectForKey:@"assignedAddresses"]) {
|
||||||
|
_assignedAddresses = (NSArray<NSString*>*)[jsonData objectForKey:@"assignedAddresses"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"bridge"]) {
|
||||||
|
_bridge = [(NSNumber*)[jsonData objectForKey:@"bridge"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"broadcastEnabled"]) {
|
||||||
|
_broadcastEnabled = [(NSNumber*)[jsonData objectForKey:@"broadcastEnabled"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"dhcp"]) {
|
||||||
|
_dhcp = [(NSNumber*)[jsonData objectForKey:@"dhcp"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"mac"]) {
|
||||||
|
_mac = (NSString*)[jsonData objectForKey:@"mac"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"mtu"]) {
|
||||||
|
_mtu = [(NSNumber*)[jsonData objectForKey:@"mtu"] intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"name"]) {
|
||||||
|
_name = (NSString*)[jsonData objectForKey:@"name"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"netconfRevision"]) {
|
||||||
|
_netconfRevision = [(NSNumber*)[jsonData objectForKey:@"netconfRevision"] intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"nwid"]) {
|
||||||
|
NSString *networkid = (NSString*)[jsonData objectForKey:@"nwid"];
|
||||||
|
|
||||||
|
NSScanner *scanner = [NSScanner scannerWithString:networkid];
|
||||||
|
[scanner scanHexLongLong:&_nwid];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"portDeviceName"]) {
|
||||||
|
_portDeviceName = (NSString*)[jsonData objectForKey:@"portDeviceName"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"portError"]) {
|
||||||
|
_portError = [(NSNumber*)[jsonData objectForKey:@"portError"] intValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"allowManaged"]) {
|
||||||
|
_allowManaged = [(NSNumber*)[jsonData objectForKey:@"allowManaged"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"allowGlobal"]) {
|
||||||
|
_allowGlobal = [(NSNumber*)[jsonData objectForKey:@"allowGlobal"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"allowDefault"]) {
|
||||||
|
_allowDefault = [(NSNumber*)[jsonData objectForKey:@"allowDefault"] boolValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"status"]) {
|
||||||
|
NSString *statusStr = (NSString*)[jsonData objectForKey:@"status"];
|
||||||
|
if([statusStr isEqualToString:@"REQUESTING_CONFIGURATION"]) {
|
||||||
|
_status = REQUESTING_CONFIGURATION;
|
||||||
|
}
|
||||||
|
else if([statusStr isEqualToString:@"OK"]) {
|
||||||
|
_status = OK;
|
||||||
|
}
|
||||||
|
else if([statusStr isEqualToString:@"ACCESS_DENIED"]) {
|
||||||
|
_status = ACCESS_DENIED;
|
||||||
|
}
|
||||||
|
else if([statusStr isEqualToString:@"NOT_FOUND"]) {
|
||||||
|
_status = NOT_FOUND;
|
||||||
|
}
|
||||||
|
else if([statusStr isEqualToString:@"PORT_ERROR"]) {
|
||||||
|
_status = PORT_ERROR;
|
||||||
|
}
|
||||||
|
else if([statusStr isEqualToString:@"CLIENT_TOO_OLD"]) {
|
||||||
|
_status = CLIENT_TOO_OLD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if([jsonData objectForKey:@"type"]) {
|
||||||
|
NSString *typeStr = (NSString*)[jsonData objectForKey:@"type"];
|
||||||
|
if([typeStr isEqualToString:@"PRIVATE"]) {
|
||||||
|
_type = PRIVATE;
|
||||||
|
}
|
||||||
|
else if([typeStr isEqualToString:@"PUBLIC"]) {
|
||||||
|
_type = PUBLIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_connected = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
- (id)initWithCoder:(NSCoder *)aDecoder
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if(self) {
|
||||||
|
if([aDecoder containsValueForKey:NetworkAddressesKey]) {
|
||||||
|
_assignedAddresses = (NSArray<NSString*>*)[aDecoder decodeObjectForKey:NetworkAddressesKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkBridgeKey]) {
|
||||||
|
_bridge = [aDecoder decodeBoolForKey:NetworkBridgeKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkBroadcastKey]) {
|
||||||
|
_broadcastEnabled = [aDecoder decodeBoolForKey:NetworkBroadcastKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkDhcpKey]) {
|
||||||
|
_dhcp = [aDecoder decodeBoolForKey:NetworkDhcpKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkMacKey]) {
|
||||||
|
_mac = (NSString*)[aDecoder decodeObjectForKey:NetworkMacKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkMtuKey]) {
|
||||||
|
_mtu = [aDecoder decodeIntegerForKey:NetworkMtuKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkNameKey]) {
|
||||||
|
_name = (NSString*)[aDecoder decodeObjectForKey:NetworkNameKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkNetconfKey]) {
|
||||||
|
_netconfRevision = [aDecoder decodeIntegerForKey:NetworkNetconfKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkNwidKey]) {
|
||||||
|
_nwid = [(NSNumber*)[aDecoder decodeObjectForKey:NetworkNwidKey] unsignedLongLongValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkPortNameKey]) {
|
||||||
|
_portDeviceName = (NSString*)[aDecoder decodeObjectForKey:NetworkPortNameKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkPortErrorKey]) {
|
||||||
|
_portError = [aDecoder decodeIntegerForKey:NetworkPortErrorKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkStatusKey]) {
|
||||||
|
_status = [aDecoder decodeIntegerForKey:NetworkStatusKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkTypeKey]) {
|
||||||
|
_type = [aDecoder decodeIntegerForKey:NetworkTypeKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkAllowManagedKey]) {
|
||||||
|
_allowManaged = [aDecoder decodeBoolForKey:NetworkAllowManagedKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkAllowGlobalKey]) {
|
||||||
|
_allowGlobal = [aDecoder decodeBoolForKey:NetworkAllowGlobalKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
if([aDecoder containsValueForKey:NetworkAllowDefaultKey]) {
|
||||||
|
_allowDefault = [aDecoder decodeBoolForKey:NetworkAllowDefaultKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
_connected = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(NSCoder *)aCoder
|
||||||
|
{
|
||||||
|
[aCoder encodeObject:_assignedAddresses forKey:NetworkAddressesKey];
|
||||||
|
[aCoder encodeBool:_bridge forKey:NetworkBridgeKey];
|
||||||
|
[aCoder encodeBool:_broadcastEnabled forKey:NetworkBroadcastKey];
|
||||||
|
[aCoder encodeBool:_dhcp forKey:NetworkDhcpKey];
|
||||||
|
[aCoder encodeObject:_mac forKey:NetworkMacKey];
|
||||||
|
[aCoder encodeInteger:_mtu forKey:NetworkMtuKey];
|
||||||
|
[aCoder encodeObject:_name forKey:NetworkNameKey];
|
||||||
|
[aCoder encodeInteger:_netconfRevision forKey:NetworkNetconfKey];
|
||||||
|
[aCoder encodeObject:[NSNumber numberWithUnsignedLongLong:_nwid]
|
||||||
|
forKey:NetworkNwidKey];
|
||||||
|
[aCoder encodeObject:_portDeviceName forKey:NetworkPortNameKey];
|
||||||
|
[aCoder encodeInteger:_portError forKey:NetworkPortErrorKey];
|
||||||
|
[aCoder encodeInteger:_status forKey:NetworkStatusKey];
|
||||||
|
[aCoder encodeInteger:_type forKey:NetworkTypeKey];
|
||||||
|
[aCoder encodeBool:_allowManaged forKey:NetworkAllowManagedKey];
|
||||||
|
[aCoder encodeBool:_allowGlobal forKey:NetworkAllowGlobalKey];
|
||||||
|
[aCoder encodeBool:_allowDefault forKey:NetworkAllowDefaultKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (BOOL)defaultRouteExists:(NSArray<Network *>*)netList
|
||||||
|
{
|
||||||
|
for(Network *net in netList) {
|
||||||
|
if (net.allowDefault && net.connected) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)statusString {
|
||||||
|
switch(_status) {
|
||||||
|
case REQUESTING_CONFIGURATION:
|
||||||
|
return @"REQUESTING_CONFIGURATION";
|
||||||
|
case OK:
|
||||||
|
return @"OK";
|
||||||
|
case ACCESS_DENIED:
|
||||||
|
return @"ACCESS_DENIED";
|
||||||
|
case NOT_FOUND:
|
||||||
|
return @"NOT_FOUND";
|
||||||
|
case PORT_ERROR:
|
||||||
|
return @"PORT_ERROR";
|
||||||
|
case CLIENT_TOO_OLD:
|
||||||
|
return @"CLIENT_TOO_OLD";
|
||||||
|
default:
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)typeString {
|
||||||
|
switch(_type) {
|
||||||
|
case PUBLIC:
|
||||||
|
return @"PUBLIC";
|
||||||
|
case PRIVATE:
|
||||||
|
return @"PRIVATE";
|
||||||
|
default:
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -1,279 +0,0 @@
|
||||||
//
|
|
||||||
// Network.swift
|
|
||||||
// ZeroTier One
|
|
||||||
//
|
|
||||||
// Created by Grant Limberg on 5/17/16.
|
|
||||||
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
import Cocoa
|
|
||||||
|
|
||||||
enum NetworkStatus : Int, CustomStringConvertible {
|
|
||||||
case REQUESTING_CONFIGURATION
|
|
||||||
case OK
|
|
||||||
case ACCESS_DENIED
|
|
||||||
case NOT_FOUND
|
|
||||||
case PORT_ERROR
|
|
||||||
case CLIENT_TOO_OLD
|
|
||||||
|
|
||||||
var description: String {
|
|
||||||
switch self {
|
|
||||||
case .REQUESTING_CONFIGURATION: return "REQUESTING_CONFIGURATION"
|
|
||||||
case .OK: return "OK"
|
|
||||||
case .ACCESS_DENIED: return "ACCESS_DENIED"
|
|
||||||
case .NOT_FOUND: return "NOT_FOUND"
|
|
||||||
case .PORT_ERROR: return "PORT_ERROR"
|
|
||||||
case .CLIENT_TOO_OLD: return "CLIENT_TOO_OLD"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum NetworkType: Int, CustomStringConvertible {
|
|
||||||
case PUBLIC
|
|
||||||
case PRIVATE
|
|
||||||
|
|
||||||
var description: String {
|
|
||||||
switch self {
|
|
||||||
case .PUBLIC: return "PUBLIC"
|
|
||||||
case .PRIVATE: return "PRIVATE"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct PropertyKeys {
|
|
||||||
static let addressesKey = "addresses"
|
|
||||||
static let bridgeKey = "bridge"
|
|
||||||
static let broadcastKey = "broadcast"
|
|
||||||
static let dhcpKey = "dhcp"
|
|
||||||
static let macKey = "mac"
|
|
||||||
static let mtuKey = "mtu"
|
|
||||||
static let multicastKey = "multicast"
|
|
||||||
static let nameKey = "name"
|
|
||||||
static let netconfKey = "netconf"
|
|
||||||
static let nwidKey = "nwid"
|
|
||||||
static let portNameKey = "port"
|
|
||||||
static let portErrorKey = "portError"
|
|
||||||
static let statusKey = "status"
|
|
||||||
static let typeKey = "type"
|
|
||||||
static let allowManagedKey = "allowManaged"
|
|
||||||
static let allowGlobalKey = "allowGlobal"
|
|
||||||
static let allowDefaultKey = "allowDefault"
|
|
||||||
}
|
|
||||||
|
|
||||||
class Network: NSObject, NSCoding {
|
|
||||||
var assignedAddresses: [String] = [String]()
|
|
||||||
var bridge: Bool = false
|
|
||||||
var broadcastEnabled: Bool = false
|
|
||||||
var dhcp: Bool = false
|
|
||||||
var mac: String = ""
|
|
||||||
var mtu: Int = 0
|
|
||||||
var name: String = ""
|
|
||||||
var netconfRevision: Int = 232
|
|
||||||
var nwid: UInt64 = 0
|
|
||||||
var portDeviceName: String = ""
|
|
||||||
var portError: Int = 0
|
|
||||||
var status: NetworkStatus = .REQUESTING_CONFIGURATION
|
|
||||||
var type: NetworkType = .PRIVATE
|
|
||||||
var allowManaged: Bool = true
|
|
||||||
var allowGlobal: Bool = false
|
|
||||||
var allowDefault: Bool = false
|
|
||||||
var connected: Bool = false // NOT PERSISTED. Set to true if loaded via JSON
|
|
||||||
|
|
||||||
init(jsonData: [String: AnyObject]) {
|
|
||||||
super.init()
|
|
||||||
|
|
||||||
if let aa = jsonData["assignedAddresses"] as? [String] {
|
|
||||||
for a in aa {
|
|
||||||
assignedAddresses.append(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let b = jsonData["bridge"] as? NSNumber {
|
|
||||||
bridge = b.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let b = jsonData["broadcastEnabled"] as? NSNumber {
|
|
||||||
broadcastEnabled = b.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let d = jsonData["dhcp"] as? NSNumber {
|
|
||||||
dhcp = d.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let m = jsonData["mac"] as? String {
|
|
||||||
mac = m
|
|
||||||
}
|
|
||||||
|
|
||||||
if let m = jsonData["mtu"] as? NSNumber {
|
|
||||||
mtu = m.integerValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let n = jsonData["name"] as? String {
|
|
||||||
name = n
|
|
||||||
}
|
|
||||||
|
|
||||||
if let n = jsonData["netconfRevision"] as? NSNumber {
|
|
||||||
netconfRevision = n.integerValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let n = UInt64((jsonData["nwid"] as! String), radix: 16) {
|
|
||||||
nwid = n
|
|
||||||
}
|
|
||||||
|
|
||||||
if let p = jsonData["portDeviceName"] as? String {
|
|
||||||
portDeviceName = p
|
|
||||||
}
|
|
||||||
|
|
||||||
if let p = jsonData["portError"] as? NSNumber {
|
|
||||||
portError = p.integerValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let a = jsonData["allowManaged"] as? NSNumber {
|
|
||||||
allowManaged = a.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let a = jsonData["allowGlobal"] as? NSNumber {
|
|
||||||
allowGlobal = a.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let a = jsonData["allowDefault"] as? NSNumber {
|
|
||||||
allowDefault = a.boolValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if let statusStr = jsonData["status"] as? String {
|
|
||||||
switch statusStr {
|
|
||||||
case "REQUESTING_CONFIGURATION":
|
|
||||||
status = .REQUESTING_CONFIGURATION
|
|
||||||
case "OK":
|
|
||||||
status = .OK
|
|
||||||
case "ACCESS_DENIED":
|
|
||||||
status = .ACCESS_DENIED
|
|
||||||
case "NOT_FOUND":
|
|
||||||
status = .NOT_FOUND
|
|
||||||
case "PORT_ERROR":
|
|
||||||
status = .PORT_ERROR
|
|
||||||
case "CLIENT_TOO_OLD":
|
|
||||||
status = .CLIENT_TOO_OLD
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let typeStr = jsonData["type"] as? String {
|
|
||||||
switch typeStr {
|
|
||||||
case "PRIVATE":
|
|
||||||
type = .PRIVATE
|
|
||||||
case "PUBLIC":
|
|
||||||
type = .PUBLIC
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it's being initialized via JSON, it's connected
|
|
||||||
connected = true
|
|
||||||
}
|
|
||||||
|
|
||||||
required init?(coder aDecoder: NSCoder) {
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.addressesKey) {
|
|
||||||
let addrs = aDecoder.decodeObjectForKey(PropertyKeys.addressesKey) as! [String]
|
|
||||||
|
|
||||||
for a in addrs {
|
|
||||||
self.assignedAddresses.append(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.bridgeKey) {
|
|
||||||
self.bridge = aDecoder.decodeBoolForKey(PropertyKeys.bridgeKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.broadcastKey) {
|
|
||||||
self.broadcastEnabled = aDecoder.decodeBoolForKey(PropertyKeys.broadcastKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.dhcpKey) {
|
|
||||||
self.dhcp = aDecoder.decodeBoolForKey(PropertyKeys.dhcpKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.macKey) {
|
|
||||||
let mac = aDecoder.decodeObjectForKey(PropertyKeys.macKey) as! String
|
|
||||||
self.mac = mac
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.mtuKey) {
|
|
||||||
self.mtu = aDecoder.decodeIntegerForKey(PropertyKeys.mtuKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.nameKey) {
|
|
||||||
let name = aDecoder.decodeObjectForKey(PropertyKeys.nameKey) as! String
|
|
||||||
|
|
||||||
self.name = name
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.netconfKey) {
|
|
||||||
self.netconfRevision = aDecoder.decodeIntegerForKey(PropertyKeys.netconfKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.nwidKey) {
|
|
||||||
self.nwid = (aDecoder.decodeObjectForKey(PropertyKeys.nwidKey) as! NSNumber).unsignedLongLongValue
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.portNameKey) {
|
|
||||||
self.portDeviceName = aDecoder.decodeObjectForKey(PropertyKeys.portNameKey) as! String
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.portErrorKey) {
|
|
||||||
self.portError = aDecoder.decodeIntegerForKey(PropertyKeys.portErrorKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.statusKey) {
|
|
||||||
self.status = NetworkStatus(rawValue: aDecoder.decodeIntegerForKey(PropertyKeys.statusKey))!
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.typeKey) {
|
|
||||||
self.type = NetworkType(rawValue: aDecoder.decodeIntegerForKey(PropertyKeys.typeKey))!
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.allowManagedKey) {
|
|
||||||
self.allowManaged = aDecoder.decodeBoolForKey(PropertyKeys.allowManagedKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.allowGlobalKey) {
|
|
||||||
self.allowGlobal = aDecoder.decodeBoolForKey(PropertyKeys.allowGlobalKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
if aDecoder.containsValueForKey(PropertyKeys.allowDefaultKey) {
|
|
||||||
self.allowDefault = aDecoder.decodeBoolForKey(PropertyKeys.allowDefaultKey)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeWithCoder(aCoder: NSCoder) {
|
|
||||||
aCoder.encodeObject(self.assignedAddresses, forKey: PropertyKeys.addressesKey)
|
|
||||||
aCoder.encodeBool(self.bridge, forKey: PropertyKeys.bridgeKey)
|
|
||||||
aCoder.encodeBool(self.broadcastEnabled, forKey: PropertyKeys.broadcastKey)
|
|
||||||
aCoder.encodeBool(self.dhcp, forKey: PropertyKeys.dhcpKey)
|
|
||||||
aCoder.encodeObject(self.mac, forKey: PropertyKeys.macKey)
|
|
||||||
aCoder.encodeInteger(self.mtu, forKey: PropertyKeys.mtuKey)
|
|
||||||
aCoder.encodeObject(self.name, forKey: PropertyKeys.nameKey)
|
|
||||||
aCoder.encodeInteger(self.netconfRevision, forKey: PropertyKeys.netconfKey)
|
|
||||||
aCoder.encodeObject(NSNumber(unsignedLongLong: self.nwid), forKey: PropertyKeys.nwidKey)
|
|
||||||
aCoder.encodeObject(self.portDeviceName, forKey: PropertyKeys.portNameKey)
|
|
||||||
aCoder.encodeInteger(self.portError, forKey: PropertyKeys.portErrorKey)
|
|
||||||
aCoder.encodeInteger(self.status.rawValue, forKey: PropertyKeys.statusKey)
|
|
||||||
aCoder.encodeInteger(self.type.rawValue, forKey: PropertyKeys.typeKey)
|
|
||||||
aCoder.encodeBool(self.allowManaged, forKey: PropertyKeys.allowManagedKey)
|
|
||||||
aCoder.encodeBool(self.allowGlobal, forKey: PropertyKeys.allowGlobalKey)
|
|
||||||
aCoder.encodeBool(self.allowDefault, forKey: PropertyKeys.allowDefaultKey)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultRouteExists(netList: [Network]) -> Bool {
|
|
||||||
for net in netList {
|
|
||||||
if net.allowDefault && net.connected {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
|
@ -59,7 +59,7 @@ class NetworkInfoCell: NSTableCellView {
|
||||||
ServiceCom.sharedInstance.joinNetwork(nwid,
|
ServiceCom.sharedInstance.joinNetwork(nwid,
|
||||||
allowManaged: allowManaged.state == NSOnState,
|
allowManaged: allowManaged.state == NSOnState,
|
||||||
allowGlobal: allowGlobal.state == NSOnState,
|
allowGlobal: allowGlobal.state == NSOnState,
|
||||||
allowDefault: !defaultRouteExists(parent.networkList) && (allowDefault.state == NSOnState))
|
allowDefault: !Network.defaultRouteExists(parent.networkList) && (allowDefault.state == NSOnState))
|
||||||
}
|
}
|
||||||
|
|
||||||
func leaveNetwork(nwid: String) {
|
func leaveNetwork(nwid: String) {
|
||||||
|
|
|
@ -74,8 +74,8 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
|
||||||
cell.networkIdField.stringValue = String(network.nwid, radix: 16)
|
cell.networkIdField.stringValue = String(network.nwid, radix: 16)
|
||||||
cell.networkNameField.stringValue = network.name
|
cell.networkNameField.stringValue = network.name
|
||||||
|
|
||||||
cell.statusField.stringValue = network.status.description
|
cell.statusField.stringValue = network.statusString()
|
||||||
cell.typeField.stringValue = network.type.description
|
cell.typeField.stringValue = network.typeString()
|
||||||
cell.macField.stringValue = network.mac
|
cell.macField.stringValue = network.mac
|
||||||
cell.mtuField.stringValue = String(network.mtu)
|
cell.mtuField.stringValue = String(network.mtu)
|
||||||
cell.broadcastField.stringValue = network.broadcastEnabled ? "ENABLED" : "DISABLED"
|
cell.broadcastField.stringValue = network.broadcastEnabled ? "ENABLED" : "DISABLED"
|
||||||
|
@ -92,7 +92,7 @@ class ShowNetworksViewController: NSViewController, NSTableViewDelegate, NSTable
|
||||||
else {
|
else {
|
||||||
cell.allowDefault.state = NSOffState
|
cell.allowDefault.state = NSOffState
|
||||||
|
|
||||||
if defaultRouteExists(networkList) {
|
if Network.defaultRouteExists(networkList) {
|
||||||
cell.allowDefault.enabled = false
|
cell.allowDefault.enabled = false
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -4,4 +4,5 @@
|
||||||
|
|
||||||
#import "AuthtokenCopy.h"
|
#import "AuthtokenCopy.h"
|
||||||
#import "LaunchAtLoginController.h"
|
#import "LaunchAtLoginController.h"
|
||||||
#import "NodeStatus.h"
|
#import "NodeStatus.h"
|
||||||
|
#import "Network.h"
|
Loading…
Add table
Reference in a new issue