From 8b9331ddf2250225882f01b62d8bb64f23886bf0 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Fri, 9 Sep 2016 12:02:27 -0700 Subject: [PATCH] updated ios/osx API docs/examples --- docs/ios_zt_sdk.md | 59 ++++++++------------ docs/osx_zt_sdk.md | 53 +++++++----------- integrations/apple/example_app/OSX/README.md | 53 +++++++----------- integrations/apple/example_app/iOS/README.md | 59 ++++++++------------ 4 files changed, 84 insertions(+), 140 deletions(-) diff --git a/docs/ios_zt_sdk.md b/docs/ios_zt_sdk.md index 7171ee5..1407e79 100644 --- a/docs/ios_zt_sdk.md +++ b/docs/ios_zt_sdk.md @@ -19,28 +19,36 @@ This short tutorial will show you how to enable ZeroTier functionality for your - Add `src` directory to *Build Settings -> Header Search Paths* - Add `build/ios_app_framework/Release-iphoneos/` to *Build Settings -> Framework Search Paths* - Add `ZeroTierSDK.frameworkiOS` to *General->Embedded Binaries* -- Add `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project: +- Add `src/ZTSDK.swift`, `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project: - Set `src/SDK_Apple-Bridging-Header.h` as your bridging-header in *Build Settings -> Objective-C Bridging-header* **Step 3: Start the ZeroTier service** Now find a place in your code to set up the ZeroTier service thread: -``` -var service_thread : NSThread! -func zt_start_service() { - let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) - start_service(path[0]) -} -``` - -and then start it: +`Start the service: ``` -dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { - self.service_thread = NSThread(target:self, selector:"zt_start_service", object:nil) - self.service_thread.start() -}); + zt.start_service(nil); + zt.join_network(nwid); +``` + +Listen for incoming connections: + +``` + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let bind_err = zt.bind(sock, ztaddr) + zt_listen(sock, 1); + accepted_sock = zt.accept(sock, ztaddr) +``` + +Or, establish a connection: + +``` + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let connect_err = zt.connect(sock, ztaddr) ``` **Step 4: Pick an API** @@ -48,25 +56,4 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { The following APIs are available for this integration: - `Direct Call`: Consult [src/SDK_Apple-Bridging-Header.h](../../../../src/SDK_Apple-Bridging-Header.h). - `Hook of BSD-like sockets`: Use BSD-like sockets as you normally would. This likely won't work for calls used by a third-party library. -- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. - -**Step 5: Join a network!** - -Simply call `zt_join_network("nwid")` - -*** -**NSStream and SOCKS Proxy:** - -As an example, here's how one would configure a NSStream object to redirect all network activity to the ZeroTier SOCKS proxy server: - -``` -// BEGIN proxy configuration -let myDict:NSDictionary = [NSStreamSOCKSProxyHostKey : "0.0.0.0", - NSStreamSOCKSProxyPortKey : 1337, - NSStreamSOCKSProxyVersionKey : NSStreamSOCKSProxyVersion5] - -inputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -outputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -// END proxy configuration -``` - +- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. An example of how to use the proxy can be found in the example iOS/OSX projects. diff --git a/docs/osx_zt_sdk.md b/docs/osx_zt_sdk.md index 05cd9b5..28cd7e9 100644 --- a/docs/osx_zt_sdk.md +++ b/docs/osx_zt_sdk.md @@ -50,28 +50,34 @@ Run application - Add `src` directory to *Build Settings -> Header Search Paths* - Add `build/osx_app_framework/Release/` to *Build Settings -> Framework Search Paths* - Add `ZeroTierSDK.frameworkOSX` to *General->Embedded Binaries* -- Add `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project: +- Add `src/ZTSDK.swift`, `src/SDK_XcodeWrapper.cpp`, and `src/SDK_XcodeWrapper.hpp` to your project: - Set `src/SDK_Apple-Bridging-Header.h` as your bridging-header in *Build Settings -> Objective-C Bridging-header* **Step 3: Start the ZeroTier service** -Set up the ZeroTier service thread: +Start the service: ``` -var service_thread : NSThread! -func zt_start_service() { - let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) - start_service(".") // "." path will tell ZeroTier to write its config data to the same directory as the binary -} + zt.start_service("."); + zt.join_network(nwid); ``` -and then start it: +Listen for incoming connections: ``` -dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { - self.service_thread = NSThread(target:self, selector:"zt_start_service", object:nil) - self.service_thread.start() -}); + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let bind_err = zt.bind(sock, ztaddr) + zt_listen(sock, 1); + accepted_sock = zt.accept(sock, ztaddr) +``` + +Or, establish a connection: + +``` + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let connect_err = zt.connect(sock, ztaddr) ``` **Step 4: Pick an API** @@ -79,25 +85,4 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { The following APIs are available for this integration: - `Direct Call`: Consult [src/SDK_Apple-Bridging-Header.h](../../../../src/SDK_Apple-Bridging-Header.h). - `Hook of BSD-like sockets`: Use BSD-like sockets as you normally would. -- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. - -**Step 5: Join a network!** - -Simply call `zt_join_network("nwid")` - -*** -**NSStream and SOCKS Proxy:** - -As an example, here's how one would configure a NSStream object to redirect all network activity to the ZeroTier SOCKS proxy server: - -``` -// BEGIN proxy configuration -let myDict:NSDictionary = [NSStreamSOCKSProxyHostKey : "0.0.0.0", - NSStreamSOCKSProxyPortKey : 1337, - NSStreamSOCKSProxyVersionKey : NSStreamSOCKSProxyVersion5] - -inputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -outputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -// END proxy configuration -``` - +- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. An example of how to use the proxy can be found in the example iOS/OSX projects. \ No newline at end of file diff --git a/integrations/apple/example_app/OSX/README.md b/integrations/apple/example_app/OSX/README.md index 05cd9b5..28cd7e9 100644 --- a/integrations/apple/example_app/OSX/README.md +++ b/integrations/apple/example_app/OSX/README.md @@ -50,28 +50,34 @@ Run application - Add `src` directory to *Build Settings -> Header Search Paths* - Add `build/osx_app_framework/Release/` to *Build Settings -> Framework Search Paths* - Add `ZeroTierSDK.frameworkOSX` to *General->Embedded Binaries* -- Add `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project: +- Add `src/ZTSDK.swift`, `src/SDK_XcodeWrapper.cpp`, and `src/SDK_XcodeWrapper.hpp` to your project: - Set `src/SDK_Apple-Bridging-Header.h` as your bridging-header in *Build Settings -> Objective-C Bridging-header* **Step 3: Start the ZeroTier service** -Set up the ZeroTier service thread: +Start the service: ``` -var service_thread : NSThread! -func zt_start_service() { - let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) - start_service(".") // "." path will tell ZeroTier to write its config data to the same directory as the binary -} + zt.start_service("."); + zt.join_network(nwid); ``` -and then start it: +Listen for incoming connections: ``` -dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { - self.service_thread = NSThread(target:self, selector:"zt_start_service", object:nil) - self.service_thread.start() -}); + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let bind_err = zt.bind(sock, ztaddr) + zt_listen(sock, 1); + accepted_sock = zt.accept(sock, ztaddr) +``` + +Or, establish a connection: + +``` + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let connect_err = zt.connect(sock, ztaddr) ``` **Step 4: Pick an API** @@ -79,25 +85,4 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { The following APIs are available for this integration: - `Direct Call`: Consult [src/SDK_Apple-Bridging-Header.h](../../../../src/SDK_Apple-Bridging-Header.h). - `Hook of BSD-like sockets`: Use BSD-like sockets as you normally would. -- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. - -**Step 5: Join a network!** - -Simply call `zt_join_network("nwid")` - -*** -**NSStream and SOCKS Proxy:** - -As an example, here's how one would configure a NSStream object to redirect all network activity to the ZeroTier SOCKS proxy server: - -``` -// BEGIN proxy configuration -let myDict:NSDictionary = [NSStreamSOCKSProxyHostKey : "0.0.0.0", - NSStreamSOCKSProxyPortKey : 1337, - NSStreamSOCKSProxyVersionKey : NSStreamSOCKSProxyVersion5] - -inputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -outputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -// END proxy configuration -``` - +- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. An example of how to use the proxy can be found in the example iOS/OSX projects. \ No newline at end of file diff --git a/integrations/apple/example_app/iOS/README.md b/integrations/apple/example_app/iOS/README.md index 7171ee5..1407e79 100644 --- a/integrations/apple/example_app/iOS/README.md +++ b/integrations/apple/example_app/iOS/README.md @@ -19,28 +19,36 @@ This short tutorial will show you how to enable ZeroTier functionality for your - Add `src` directory to *Build Settings -> Header Search Paths* - Add `build/ios_app_framework/Release-iphoneos/` to *Build Settings -> Framework Search Paths* - Add `ZeroTierSDK.frameworkiOS` to *General->Embedded Binaries* -- Add `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project: +- Add `src/ZTSDK.swift`, `src/SDK_XcodeWrapper.cpp` and `src/SDK_XcodeWrapper.hpp` to your project: - Set `src/SDK_Apple-Bridging-Header.h` as your bridging-header in *Build Settings -> Objective-C Bridging-header* **Step 3: Start the ZeroTier service** Now find a place in your code to set up the ZeroTier service thread: -``` -var service_thread : NSThread! -func zt_start_service() { - let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) - start_service(path[0]) -} -``` - -and then start it: +`Start the service: ``` -dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { - self.service_thread = NSThread(target:self, selector:"zt_start_service", object:nil) - self.service_thread.start() -}); + zt.start_service(nil); + zt.join_network(nwid); +``` + +Listen for incoming connections: + +``` + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let bind_err = zt.bind(sock, ztaddr) + zt_listen(sock, 1); + accepted_sock = zt.accept(sock, ztaddr) +``` + +Or, establish a connection: + +``` + let sock: Int32 = zt.socket(AF_INET, SOCK_STREAM, 0) + let ztaddr: ZTAddress = ZTAddress(AF_INET, serverAddr, Int16(serverPort)) + let connect_err = zt.connect(sock, ztaddr) ``` **Step 4: Pick an API** @@ -48,25 +56,4 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { The following APIs are available for this integration: - `Direct Call`: Consult [src/SDK_Apple-Bridging-Header.h](../../../../src/SDK_Apple-Bridging-Header.h). - `Hook of BSD-like sockets`: Use BSD-like sockets as you normally would. This likely won't work for calls used by a third-party library. -- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. - -**Step 5: Join a network!** - -Simply call `zt_join_network("nwid")` - -*** -**NSStream and SOCKS Proxy:** - -As an example, here's how one would configure a NSStream object to redirect all network activity to the ZeroTier SOCKS proxy server: - -``` -// BEGIN proxy configuration -let myDict:NSDictionary = [NSStreamSOCKSProxyHostKey : "0.0.0.0", - NSStreamSOCKSProxyPortKey : 1337, - NSStreamSOCKSProxyVersionKey : NSStreamSOCKSProxyVersion5] - -inputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -outputStream!.setProperty(myDict, forKey: NSStreamSOCKSProxyConfigurationKey) -// END proxy configuration -``` - +- `Proxy of NSStream`: Create NSStream. Configure stream for SOCKS5 Proxy (127.0.0.1:PORT). Start Proxy. Use stream. An example of how to use the proxy can be found in the example iOS/OSX projects.