diff --git a/NEKit.xcodeproj/project.pbxproj b/NEKit.xcodeproj/project.pbxproj index 15c329dd1..f7eff27e8 100644 --- a/NEKit.xcodeproj/project.pbxproj +++ b/NEKit.xcodeproj/project.pbxproj @@ -74,6 +74,29 @@ 36A718EB1D5AF84400DC35F5 /* tun2socks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A718EA1D5AF84400DC35F5 /* tun2socks.framework */; }; 36A719421D5B231100DC35F5 /* lwip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A719411D5B231100DC35F5 /* lwip.framework */; }; 36A719451D5B25EF00DC35F5 /* lwip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A719441D5B25EF00DC35F5 /* lwip.framework */; }; + 36A7199B1D5EEB4900DC35F5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36A7199A1D5EEB4900DC35F5 /* AppDelegate.swift */; }; + 36A7199D1D5EEB4900DC35F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36A7199C1D5EEB4900DC35F5 /* Assets.xcassets */; }; + 36A719A01D5EEB4900DC35F5 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 36A7199E1D5EEB4900DC35F5 /* MainMenu.xib */; }; + 36A719A51D5EEB5900DC35F5 /* lwip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A719411D5B231100DC35F5 /* lwip.framework */; }; + 36A719A61D5EEB5900DC35F5 /* lwip.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36A719411D5B231100DC35F5 /* lwip.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719A71D5EEB5900DC35F5 /* tun2socks.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36A718E81D5AF82B00DC35F5 /* tun2socks.framework */; }; + 36A719A81D5EEB5900DC35F5 /* tun2socks.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36A718E81D5AF82B00DC35F5 /* tun2socks.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719A91D5EEB5900DC35F5 /* CocoaAsyncSocket.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1624B1CDDA26600F24C97 /* CocoaAsyncSocket.framework */; }; + 36A719AA1D5EEB5900DC35F5 /* CocoaAsyncSocket.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1624B1CDDA26600F24C97 /* CocoaAsyncSocket.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719AB1D5EEB5900DC35F5 /* CocoaLumberjack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1624C1CDDA26600F24C97 /* CocoaLumberjack.framework */; }; + 36A719AC1D5EEB5900DC35F5 /* CocoaLumberjack.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1624C1CDDA26600F24C97 /* CocoaLumberjack.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719AD1D5EEB5900DC35F5 /* CocoaLumberjackSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1624D1CDDA26600F24C97 /* CocoaLumberjackSwift.framework */; }; + 36A719AE1D5EEB5900DC35F5 /* CocoaLumberjackSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1624D1CDDA26600F24C97 /* CocoaLumberjackSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719AF1D5EEB5900DC35F5 /* CommonCrypto.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3664F0B31CE194ED008BA6D8 /* CommonCrypto.framework */; }; + 36A719B01D5EEB5900DC35F5 /* CommonCrypto.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3664F0B31CE194ED008BA6D8 /* CommonCrypto.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719B11D5EEB5900DC35F5 /* MMDB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1625D1CDDAD6E00F24C97 /* MMDB.framework */; }; + 36A719B21D5EEB5900DC35F5 /* MMDB.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36B1625D1CDDAD6E00F24C97 /* MMDB.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719B31D5EEB5900DC35F5 /* Sodium.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3664F0B91CE21A60008BA6D8 /* Sodium.framework */; }; + 36A719B41D5EEB5900DC35F5 /* Sodium.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3664F0B91CE21A60008BA6D8 /* Sodium.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719B51D5EEB5900DC35F5 /* Yaml.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 366EB5BA1CDE328F00E0E942 /* Yaml.framework */; }; + 36A719B61D5EEB5900DC35F5 /* Yaml.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 366EB5BA1CDE328F00E0E942 /* Yaml.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 36A719B71D5EEB5900DC35F5 /* NEKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36463A301CDCD5EB0040579C /* NEKit.framework */; }; + 36A719B81D5EEB5900DC35F5 /* NEKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36463A301CDCD5EB0040579C /* NEKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 36B1620F1CDDA0E000F24C97 /* CountryRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B1620C1CDDA0E000F24C97 /* CountryRule.swift */; }; 36B162101CDDA0E000F24C97 /* Rule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B1620D1CDDA0E000F24C97 /* Rule.swift */; }; 36B162111CDDA0E000F24C97 /* RuleManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B1620E1CDDA0E000F24C97 /* RuleManager.swift */; }; @@ -181,6 +204,16 @@ 36E44A021CF2ED4800185DBF /* TUNInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E44A011CF2ED4800185DBF /* TUNInterface.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 36A719B91D5EEB5900DC35F5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 36463A271CDCD5EB0040579C /* Project object */; + proxyType = 1; + remoteGlobalIDString = 36463A2F1CDCD5EB0040579C; + remoteInfo = "NEKit-macOS"; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXCopyFilesBuildPhase section */ 36A503F61CF5AC5800D1FC78 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; @@ -200,6 +233,26 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 36A719BB1D5EEB5900DC35F5 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 36A719AA1D5EEB5900DC35F5 /* CocoaAsyncSocket.framework in Embed Frameworks */, + 36A719A61D5EEB5900DC35F5 /* lwip.framework in Embed Frameworks */, + 36A719B61D5EEB5900DC35F5 /* Yaml.framework in Embed Frameworks */, + 36A719AC1D5EEB5900DC35F5 /* CocoaLumberjack.framework in Embed Frameworks */, + 36A719B81D5EEB5900DC35F5 /* NEKit.framework in Embed Frameworks */, + 36A719A81D5EEB5900DC35F5 /* tun2socks.framework in Embed Frameworks */, + 36A719B01D5EEB5900DC35F5 /* CommonCrypto.framework in Embed Frameworks */, + 36A719B41D5EEB5900DC35F5 /* Sodium.framework in Embed Frameworks */, + 36A719AE1D5EEB5900DC35F5 /* CocoaLumberjackSwift.framework in Embed Frameworks */, + 36A719B21D5EEB5900DC35F5 /* MMDB.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ @@ -260,6 +313,11 @@ 36A718EA1D5AF84400DC35F5 /* tun2socks.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = tun2socks.framework; path = Carthage/Build/iOS/tun2socks.framework; sourceTree = ""; }; 36A719411D5B231100DC35F5 /* lwip.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = lwip.framework; path = Carthage/Build/Mac/lwip.framework; sourceTree = ""; }; 36A719441D5B25EF00DC35F5 /* lwip.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = lwip.framework; path = Carthage/Build/iOS/lwip.framework; sourceTree = ""; }; + 36A719981D5EEB4900DC35F5 /* NEKitDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NEKitDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 36A7199A1D5EEB4900DC35F5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 36A7199C1D5EEB4900DC35F5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 36A7199F1D5EEB4900DC35F5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 36A719A11D5EEB4900DC35F5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 36B1620C1CDDA0E000F24C97 /* CountryRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryRule.swift; sourceTree = ""; }; 36B1620D1CDDA0E000F24C97 /* Rule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Rule.swift; sourceTree = ""; }; 36B1620E1CDDA0E000F24C97 /* RuleManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RuleManager.swift; sourceTree = ""; }; @@ -330,6 +388,23 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 36A719951D5EEB4900DC35F5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 36A719A91D5EEB5900DC35F5 /* CocoaAsyncSocket.framework in Frameworks */, + 36A719A51D5EEB5900DC35F5 /* lwip.framework in Frameworks */, + 36A719B51D5EEB5900DC35F5 /* Yaml.framework in Frameworks */, + 36A719AB1D5EEB5900DC35F5 /* CocoaLumberjack.framework in Frameworks */, + 36A719B71D5EEB5900DC35F5 /* NEKit.framework in Frameworks */, + 36A719A71D5EEB5900DC35F5 /* tun2socks.framework in Frameworks */, + 36A719AF1D5EEB5900DC35F5 /* CommonCrypto.framework in Frameworks */, + 36A719B31D5EEB5900DC35F5 /* Sodium.framework in Frameworks */, + 36A719AD1D5EEB5900DC35F5 /* CocoaLumberjackSwift.framework in Frameworks */, + 36A719B11D5EEB5900DC35F5 /* MMDB.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 36C48D491CF88DED0071804F /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -388,6 +463,7 @@ 36A719431D5B234500DC35F5 /* Carthage */, 36C48D4E1CF88DED0071804F /* NEKit-iOS */, 368225B91D12484D00E7B495 /* NEKit-macOS */, + 36A719991D5EEB4900DC35F5 /* NEKitDemo */, 36463A311CDCD5EB0040579C /* Products */, 36463A321CDCD5EB0040579C /* src */, 3664F0C61CE37763008BA6D8 /* .swiftlint.yml */, @@ -403,6 +479,7 @@ children = ( 36463A301CDCD5EB0040579C /* NEKit.framework */, 36C48D4D1CF88DED0071804F /* NEKit.framework */, + 36A719981D5EEB4900DC35F5 /* NEKitDemo.app */, ); name = Products; sourceTree = ""; @@ -479,6 +556,17 @@ name = Carthage; sourceTree = ""; }; + 36A719991D5EEB4900DC35F5 /* NEKitDemo */ = { + isa = PBXGroup; + children = ( + 36A7199A1D5EEB4900DC35F5 /* AppDelegate.swift */, + 36A7199C1D5EEB4900DC35F5 /* Assets.xcassets */, + 36A7199E1D5EEB4900DC35F5 /* MainMenu.xib */, + 36A719A11D5EEB4900DC35F5 /* Info.plist */, + ); + path = NEKitDemo; + sourceTree = ""; + }; 36B1620B1CDDA0E000F24C97 /* Rule */ = { isa = PBXGroup; children = ( @@ -694,6 +782,25 @@ productReference = 36463A301CDCD5EB0040579C /* NEKit.framework */; productType = "com.apple.product-type.framework"; }; + 36A719971D5EEB4900DC35F5 /* NEKitDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 36A719A41D5EEB4900DC35F5 /* Build configuration list for PBXNativeTarget "NEKitDemo" */; + buildPhases = ( + 36A719941D5EEB4900DC35F5 /* Sources */, + 36A719951D5EEB4900DC35F5 /* Frameworks */, + 36A719961D5EEB4900DC35F5 /* Resources */, + 36A719BB1D5EEB5900DC35F5 /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 36A719BA1D5EEB5900DC35F5 /* PBXTargetDependency */, + ); + name = NEKitDemo; + productName = NEKitDemo; + productReference = 36A719981D5EEB4900DC35F5 /* NEKitDemo.app */; + productType = "com.apple.product-type.application"; + }; 36C48D4C1CF88DED0071804F /* NEKit-iOS */ = { isa = PBXNativeTarget; buildConfigurationList = 36C48D521CF88DED0071804F /* Build configuration list for PBXNativeTarget "NEKit-iOS" */; @@ -727,7 +834,9 @@ TargetAttributes = { 36463A2F1CDCD5EB0040579C = { CreatedOnToolsVersion = 7.3; - DevelopmentTeam = H5443445N6; + }; + 36A719971D5EEB4900DC35F5 = { + CreatedOnToolsVersion = 7.3.1; }; 36C48D4C1CF88DED0071804F = { CreatedOnToolsVersion = 7.3.1; @@ -749,6 +858,7 @@ targets = ( 36463A2F1CDCD5EB0040579C /* NEKit-macOS */, 36C48D4C1CF88DED0071804F /* NEKit-iOS */, + 36A719971D5EEB4900DC35F5 /* NEKitDemo */, ); }; /* End PBXProject section */ @@ -761,6 +871,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 36A719961D5EEB4900DC35F5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 36A7199D1D5EEB4900DC35F5 /* Assets.xcassets in Resources */, + 36A719A01D5EEB4900DC35F5 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 36C48D4B1CF88DED0071804F /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -926,6 +1045,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 36A719941D5EEB4900DC35F5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 36A7199B1D5EEB4900DC35F5 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 36C48D481CF88DED0071804F /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1011,6 +1138,25 @@ }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 36A719BA1D5EEB5900DC35F5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 36463A2F1CDCD5EB0040579C /* NEKit-macOS */; + targetProxy = 36A719B91D5EEB5900DC35F5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 36A7199E1D5EEB4900DC35F5 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 36A7199F1D5EEB4900DC35F5 /* Base */, + ); + name = MainMenu.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 36463A421CDCD5EB0040579C /* Debug */ = { isa = XCBuildConfiguration; @@ -1184,6 +1330,42 @@ }; name = Release; }; + 36A719A21D5EEB4900DC35F5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + COMBINE_HIDPI_IMAGES = YES; + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/Mac", + ); + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + INFOPLIST_FILE = NEKitDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.osx.NEKitDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 36A719A31D5EEB4900DC35F5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + COMBINE_HIDPI_IMAGES = YES; + EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/Mac", + ); + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + INFOPLIST_FILE = NEKitDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.osx.NEKitDemo; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; 36C48D531CF88DED0071804F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -1266,6 +1448,14 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 36A719A41D5EEB4900DC35F5 /* Build configuration list for PBXNativeTarget "NEKitDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 36A719A21D5EEB4900DC35F5 /* Debug */, + 36A719A31D5EEB4900DC35F5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; 36C48D521CF88DED0071804F /* Build configuration list for PBXNativeTarget "NEKit-iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/NEKitDemo/AppDelegate.swift b/NEKitDemo/AppDelegate.swift new file mode 100644 index 000000000..6e40f76a8 --- /dev/null +++ b/NEKitDemo/AppDelegate.swift @@ -0,0 +1,26 @@ +import Cocoa +import NEKit + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + @IBOutlet weak var window: NSWindow! + var proxy: GCDHTTPProxyServer? + + func applicationDidFinishLaunching(aNotification: NSNotification) { + let config = Configuration() + let filepath = (NSHomeDirectory() as NSString).stringByAppendingPathComponent(".NEKit_demo.yaml") + // swiftlint:disable force_try + try! config.load(fromConfigFile: filepath) + RuleManager.currentManager = config.ruleManager + proxy = GCDHTTPProxyServer(address: IPv4Address(fromString: "127.0.0.1"), port: Port(port: UInt16(config.proxyPort!))) + // swiftlint:disable force_try + try! proxy!.start() + } + + func applicationWillTerminate(aNotification: NSNotification) { + proxy?.stop() + } + + +} diff --git a/NEKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/NEKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..2db2b1c7c --- /dev/null +++ b/NEKitDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/NEKitDemo/Base.lproj/MainMenu.xib b/NEKitDemo/Base.lproj/MainMenu.xib new file mode 100644 index 000000000..1ba7c1bbb --- /dev/null +++ b/NEKitDemo/Base.lproj/MainMenu.xib @@ -0,0 +1,680 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NEKitDemo/Info.plist b/NEKitDemo/Info.plist new file mode 100644 index 000000000..027433e73 --- /dev/null +++ b/NEKitDemo/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2016 Zhuhao Wang. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/src/Socket/AdapterSocket/AdapterSocket.swift b/src/Socket/AdapterSocket/AdapterSocket.swift index 18900310f..f9fa0e784 100644 --- a/src/Socket/AdapterSocket/AdapterSocket.swift +++ b/src/Socket/AdapterSocket/AdapterSocket.swift @@ -34,6 +34,56 @@ class AdapterSocket: NSObject, SocketProtocol, RawTCPSocketDelegate { /// The current connection status of the socket. var state: SocketStatus = .Invalid + /// If the socket is disconnected. + var isDisconnected: Bool { + return state == .Closed || state == .Invalid + } + + /** + Read data from the socket. + + - parameter tag: The tag identifying the data in the callback delegate method. + - warning: This should only be called after the last read is finished, i.e., `delegate?.didReadData()` is called. + */ + func readDataWithTag(tag: Int) { + socket.readDataWithTag(tag) + } + + /** + Send data to remote. + + - parameter data: Data to send. + - parameter tag: The tag identifying the data in the callback delegate method. + - warning: This should only be called after the last write is finished, i.e., `delegate?.didWriteData()` is called. + */ + func writeData(data: NSData, withTag tag: Int) { + socket.writeData(data, withTag: tag) + } + + // func readDataToLength(length: Int, withTag tag: Int) { + // socket.readDataToLength(length, withTag: tag) + // } + // + // func readDataToData(data: NSData, withTag tag: Int) { + // socket.readDataToData(data, withTag: tag) + // } + + /** + Disconnect the socket elegantly. + */ + func disconnect() { + state = .Disconnecting + socket.disconnect() + } + + /** + Disconnect the socket immediately. + */ + func forceDisconnect() { + state = .Disconnecting + socket.forceDisconnect() + } + // MARK: RawTCPSocketDelegate Protocol Implemention /** diff --git a/src/Socket/AdapterSocket/ShadowsocksAdapter.swift b/src/Socket/AdapterSocket/ShadowsocksAdapter.swift index a16be6bb0..d988b5994 100644 --- a/src/Socket/AdapterSocket/ShadowsocksAdapter.swift +++ b/src/Socket/AdapterSocket/ShadowsocksAdapter.swift @@ -91,37 +91,39 @@ class ShadowsocksAdapter: AdapterSocket { super.writeData(data, withTag: tag) } - func readDataWithTag(tag: Int) { + override func readDataWithTag(tag: Int) { if readIV == nil && !readingIV { readingIV = true - socket.readDataToLength(ivLength, withTag: ShadowsocksTag.InitialVector.rawValue) nextReadTag = tag + socket.readDataToLength(ivLength, withTag: ShadowsocksTag.InitialVector.rawValue) } else { super.readDataWithTag(tag) } } - func writeData(data: NSData, withTag tag: Int) { + override func writeData(data: NSData, withTag tag: Int) { writeRawData(encryptData(data), withTag: tag) } override func didReadData(data: NSData, withTag tag: Int, from socket: RawTCPSocketProtocol) { - super.didReadData(decryptData(data), withTag: tag, from: socket) if tag == ShadowsocksTag.InitialVector.rawValue { readIV = data readingIV = false + super.didReadData(data, withTag: tag, from: socket) super.readDataWithTag(nextReadTag) } else { - delegate?.didReadData(decryptData(data), withTag: tag, from: self) + let readData = decryptData(data) + super.didReadData(readData, withTag: tag, from: socket) + delegate?.didReadData(readData, withTag: tag, from: self) } } override func didWriteData(data: NSData?, withTag tag: Int, from socket: RawTCPSocketProtocol) { - super.didWriteData(data, withTag: tag, from: socket) + super.didWriteData(nil, withTag: tag, from: socket) if tag == ShadowsocksTag.Connect.rawValue { delegate?.readyToForward(self) } else { - delegate?.didWriteData(data, withTag: tag, from: self) + delegate?.didWriteData(nil, withTag: tag, from: self) } } diff --git a/src/Socket/AdapterSocket/SpeedAdapter.swift b/src/Socket/AdapterSocket/SpeedAdapter.swift index 3a2175d4a..f14e1d633 100644 --- a/src/Socket/AdapterSocket/SpeedAdapter.swift +++ b/src/Socket/AdapterSocket/SpeedAdapter.swift @@ -29,7 +29,7 @@ class SpeedAdapter: AdapterSocket, SocketDelegate { } } - func disconnect() { + override func disconnect() { _shouldConnect = false pendingCount = 0 for (adapter, _) in adapters { @@ -40,7 +40,7 @@ class SpeedAdapter: AdapterSocket, SocketDelegate { } } - func forceDisconnect() { + override func forceDisconnect() { _shouldConnect = false pendingCount = 0 for (adapter, _) in adapters { @@ -88,4 +88,5 @@ class SpeedAdapter: AdapterSocket, SocketDelegate { func didWriteData(data: NSData?, withTag: Int, from: SocketProtocol) {} func didReadData(data: NSData, withTag: Int, from: SocketProtocol) {} func updateAdapter(newAdapter: AdapterSocket) {} + func didReceiveRequest(request: ConnectRequest, from: ProxySocket) {} } diff --git a/src/Socket/ProxySocket/ProxySocket.swift b/src/Socket/ProxySocket/ProxySocket.swift index d0ef1ad87..8d04a6d77 100644 --- a/src/Socket/ProxySocket/ProxySocket.swift +++ b/src/Socket/ProxySocket/ProxySocket.swift @@ -5,6 +5,11 @@ class ProxySocket: NSObject, SocketProtocol, RawTCPSocketDelegate { /// Received `ConnectRequest`. var request: ConnectRequest? + /// If the socket is disconnected. + var isDisconnected: Bool { + return state == .Closed || state == .Invalid + } + /** Init a `ProxySocket` with a raw TCP socket. @@ -36,10 +41,46 @@ class ProxySocket: NSObject, SocketProtocol, RawTCPSocketDelegate { - parameter tag: The tag identifying the data in the callback delegate method. - warning: This should only be called after the last read is finished, i.e., `delegate?.didReadData()` is called. */ - func readDataWithTag(tag: Int = SocketTag.Forward) { + func readDataWithTag(tag: Int) { socket.readDataWithTag(tag) } + /** + Send data to remote. + + - parameter data: Data to send. + - parameter tag: The tag identifying the data in the callback delegate method. + - warning: This should only be called after the last write is finished, i.e., `delegate?.didWriteData()` is called. + */ + func writeData(data: NSData, withTag tag: Int) { + socket.writeData(data, withTag: tag) + } + + // func readDataToLength(length: Int, withTag tag: Int) { + // socket.readDataToLength(length, withTag: tag) + // } + // + // func readDataToData(data: NSData, withTag tag: Int) { + // socket.readDataToData(data, withTag: tag) + // } + + /** + Disconnect the socket elegantly. + */ + func disconnect() { + state = .Disconnecting + socket.disconnect() + } + + /** + Disconnect the socket immediately. + */ + func forceDisconnect() { + state = .Disconnecting + socket.forceDisconnect() + } + + // MARK: SocketProtocol Implemention /// The underlying TCP socket transmitting data. @@ -98,4 +139,6 @@ class ProxySocket: NSObject, SocketProtocol, RawTCPSocketDelegate { func didConnect(socket: RawTCPSocketProtocol) { } + + } diff --git a/src/Socket/SocketProtocol.swift b/src/Socket/SocketProtocol.swift index eaed6df85..6f8e77395 100644 --- a/src/Socket/SocketProtocol.swift +++ b/src/Socket/SocketProtocol.swift @@ -43,58 +43,36 @@ protocol SocketProtocol: class { /// The current connection status of the socket. var state: SocketStatus { get set } -} -extension SocketProtocol { /// If the socket is disconnected. - var isDisconnected: Bool { - return state == .Closed || state == .Invalid - } + var isDisconnected: Bool { get } /** - Send data to remote. + Read data from the socket. - - parameter data: Data to send. - - parameter tag: The tag identifying the data in the callback delegate method. - - warning: This should only be called after the last write is finished, i.e., `delegate?.didWriteData()` is called. + - parameter tag: The tag identifying the data in the callback delegate method. + - warning: This should only be called after the last read is finished, i.e., `delegate?.didReadData()` is called. */ - func writeData(data: NSData, withTag tag: Int = 0) { - socket.writeData(data, withTag: tag) - } - -// func readDataToLength(length: Int, withTag tag: Int) { -// socket.readDataToLength(length, withTag: tag) -// } -// -// func readDataToData(data: NSData, withTag tag: Int) { -// socket.readDataToData(data, withTag: tag) -// } + func readDataWithTag(tag: Int) /** - Read data from the socket. + Send data to remote. - - parameter tag: The tag identifying the data in the callback delegate method. - - warning: This should only be called after the last read is finished, i.e., `delegate?.didReadData()` is called. + - parameter data: Data to send. + - parameter tag: The tag identifying the data in the callback delegate method. + - warning: This should only be called after the last write is finished, i.e., `delegate?.didWriteData()` is called. */ - func readDataWithTag(tag: Int = SocketTag.Forward) { - socket.readDataWithTag(tag) - } + func writeData(data: NSData, withTag tag: Int) /** Disconnect the socket elegantly. */ - func disconnect() { - state = .Disconnecting - socket.disconnect() - } + func disconnect() /** Disconnect the socket immediately. */ - func forceDisconnect() { - state = .Disconnecting - socket.forceDisconnect() - } + func forceDisconnect() } /// The delegate protocol to handle the events from a socket. @@ -155,9 +133,3 @@ protocol SocketDelegate : class { */ func updateAdapter(newAdapter: AdapterSocket) } - -extension SocketDelegate { - func didReceiveRequest(request: ConnectRequest, from: ProxySocket) {} - - func didConnect(adapterSocket: AdapterSocket, withResponse: ConnectResponse) {} -}