path trickery update, direct-call API bugfix
This commit is contained in:
@@ -1435,6 +1435,7 @@
|
|||||||
"-DSDK",
|
"-DSDK",
|
||||||
"-D__IOS__",
|
"-D__IOS__",
|
||||||
"-DLWIP_DEBUG",
|
"-DLWIP_DEBUG",
|
||||||
|
"-DSDK_BUNDLED",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-iOS";
|
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-iOS";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
@@ -1467,6 +1468,7 @@
|
|||||||
OTHER_CFLAGS = (
|
OTHER_CFLAGS = (
|
||||||
"-DSDK",
|
"-DSDK",
|
||||||
"-D__IOS__",
|
"-D__IOS__",
|
||||||
|
"-DSDK_BUNDLED",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-iOS";
|
PRODUCT_BUNDLE_IDENTIFIER = "zerotier.ZeroTierSDK-iOS";
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
|||||||
@@ -83,5 +83,21 @@
|
|||||||
landmarkType = "5">
|
landmarkType = "5">
|
||||||
</BreakpointContent>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
|
<BreakpointProxy
|
||||||
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
|
<BreakpointContent
|
||||||
|
shouldBeEnabled = "No"
|
||||||
|
ignoreCount = "0"
|
||||||
|
continueAfterRunningActions = "No"
|
||||||
|
filePath = "../../../../src/SDK_XcodeWrapper.cpp"
|
||||||
|
timestampString = "490505377.469632"
|
||||||
|
startingColumnNumber = "9223372036854775807"
|
||||||
|
endingColumnNumber = "9223372036854775807"
|
||||||
|
startingLineNumber = "50"
|
||||||
|
endingLineNumber = "50"
|
||||||
|
landmarkName = "zts_socket(SOCKET_SIG)"
|
||||||
|
landmarkType = "7">
|
||||||
|
</BreakpointContent>
|
||||||
|
</BreakpointProxy>
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
</Bucket>
|
</Bucket>
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ class ViewController: NSViewController {
|
|||||||
@IBOutlet weak var txtTX: NSTextField!
|
@IBOutlet weak var txtTX: NSTextField!
|
||||||
@IBOutlet weak var txtRX: NSTextField!
|
@IBOutlet weak var txtRX: NSTextField!
|
||||||
|
|
||||||
var serverPort:Int32 = 8080
|
var serverPort:Int32 = 5658
|
||||||
var serverAddr:String = "10.147.18.5"
|
var serverAddr:String = "10.9.9.203"
|
||||||
|
|
||||||
var sock:Int32 = -1
|
var sock:Int32 = -1
|
||||||
var accepted_sock:Int32 = -1
|
var accepted_sock:Int32 = -1
|
||||||
@@ -227,11 +227,12 @@ class ViewController: NSViewController {
|
|||||||
|
|
||||||
var service_thread : NSThread!
|
var service_thread : NSThread!
|
||||||
func ztnc_start_service() {
|
func ztnc_start_service() {
|
||||||
let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
|
|
||||||
print("start_service()\n")
|
// If you plan on using SOCKS Proxy
|
||||||
// e5cd7a9e1c3511dd
|
//start_service("/Users/Joseph/utest3")
|
||||||
start_service("/Users/Joseph/utest3")
|
|
||||||
//start_service(path[0])
|
// If you plan on using direct calls via RPC
|
||||||
|
start_service_and_rpc("/Users/Joseph/utest3","565799d8f65063e5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -241,15 +242,13 @@ class ViewController: NSViewController {
|
|||||||
// Set initial UI values for demo
|
// Set initial UI values for demo
|
||||||
txtAddr.stringValue = serverAddr
|
txtAddr.stringValue = serverAddr
|
||||||
txtPort.intValue = serverPort
|
txtPort.intValue = serverPort
|
||||||
|
txtNWID.stringValue = "565799d8f65063e5"
|
||||||
|
|
||||||
// ZeroTier Service thread
|
// ZeroTier Service thread
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
|
||||||
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
|
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
|
||||||
self.service_thread.start()
|
self.service_thread.start()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set RPC path for this thread
|
|
||||||
zts_init_rpc("/Users/Joseph/utest3/nc_","e5cd7a9e1c2e194f");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override var representedObject: AnyObject? {
|
override var representedObject: AnyObject? {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment identifier="iOS"/>
|
<deployment identifier="iOS"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
</textField>
|
</textField>
|
||||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Protocol" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fn2-mn-MjK">
|
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Protocol" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fn2-mn-MjK">
|
||||||
<rect key="frame" x="20" y="147" width="64" height="21"/>
|
<rect key="frame" x="20" y="171" width="64" height="21"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
@@ -63,21 +63,21 @@
|
|||||||
<textInputTraits key="textInputTraits"/>
|
<textInputTraits key="textInputTraits"/>
|
||||||
</textField>
|
</textField>
|
||||||
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="mgD-Qw-uwg">
|
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="mgD-Qw-uwg">
|
||||||
<rect key="frame" x="20" y="96" width="121" height="29"/>
|
<rect key="frame" x="38" y="133" width="121" height="29"/>
|
||||||
<segments>
|
<segments>
|
||||||
<segment title="First"/>
|
<segment title="First"/>
|
||||||
<segment title="Second"/>
|
<segment title="Second"/>
|
||||||
</segments>
|
</segments>
|
||||||
</segmentedControl>
|
</segmentedControl>
|
||||||
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="vwT-sy-CRY">
|
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="vwT-sy-CRY">
|
||||||
<rect key="frame" x="20" y="176" width="121" height="29"/>
|
<rect key="frame" x="38" y="200" width="121" height="29"/>
|
||||||
<segments>
|
<segments>
|
||||||
<segment title="First"/>
|
<segment title="First"/>
|
||||||
<segment title="Second"/>
|
<segment title="Second"/>
|
||||||
</segments>
|
</segments>
|
||||||
</segmentedControl>
|
</segmentedControl>
|
||||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="API" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bOi-uD-nTW">
|
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="API" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bOi-uD-nTW">
|
||||||
<rect key="frame" x="20" y="67" width="26" height="21"/>
|
<rect key="frame" x="20" y="104" width="26" height="21"/>
|
||||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||||
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
@@ -118,6 +118,27 @@
|
|||||||
<rect key="frame" x="20" y="492" width="45" height="30"/>
|
<rect key="frame" x="20" y="492" width="45" height="30"/>
|
||||||
<state key="normal" title="write()"/>
|
<state key="normal" title="write()"/>
|
||||||
</button>
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IXS-rJ-KKM">
|
||||||
|
<rect key="frame" x="141" y="55" width="90" height="30"/>
|
||||||
|
<state key="normal" title="Join Network"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="UI_JoinNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="kem-tf-1h1"/>
|
||||||
|
<action selector="btnJoinNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="LSj-sJ-YEs"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="nwid" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="TvY-qZ-Zjm">
|
||||||
|
<rect key="frame" x="20" y="55" width="97" height="30"/>
|
||||||
|
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||||
|
<textInputTraits key="textInputTraits"/>
|
||||||
|
</textField>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fU2-IH-aMf">
|
||||||
|
<rect key="frame" x="141" y="83" width="102" height="30"/>
|
||||||
|
<state key="normal" title="Leave Network"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="UI_LeaveNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="7Pg-IK-dMo"/>
|
||||||
|
<action selector="btnLeaveNetwork:" destination="BYZ-38-t0r" eventType="touchUpInside" id="hmg-2Y-GCl"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
</subviews>
|
</subviews>
|
||||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||||
<variation key="default">
|
<variation key="default">
|
||||||
@@ -128,6 +149,11 @@
|
|||||||
</mask>
|
</mask>
|
||||||
</variation>
|
</variation>
|
||||||
</view>
|
</view>
|
||||||
|
<connections>
|
||||||
|
<outlet property="btnJoinNetwork" destination="IXS-rJ-KKM" id="C88-pL-2CT"/>
|
||||||
|
<outlet property="btnLeaveNetwork" destination="fU2-IH-aMf" id="YwN-GB-2tc"/>
|
||||||
|
<outlet property="txtNWID" destination="TvY-qZ-Zjm" id="1Jc-3U-PIE"/>
|
||||||
|
</connections>
|
||||||
</viewController>
|
</viewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
|||||||
@@ -10,13 +10,22 @@ import UIKit
|
|||||||
|
|
||||||
class ViewController: UIViewController {
|
class ViewController: UIViewController {
|
||||||
|
|
||||||
|
@IBOutlet weak var txtNWID: UITextField!
|
||||||
|
|
||||||
|
@IBOutlet weak var btnJoinNetwork: UIButton!
|
||||||
|
@IBAction func UI_JoinNetwork(sender: AnyObject) {
|
||||||
|
zt_join_network("565799d8f65063e5")
|
||||||
|
}
|
||||||
|
|
||||||
|
@IBOutlet weak var btnLeaveNetwork: UIButton!
|
||||||
|
@IBAction func UI_LeaveNetwork(sender: AnyObject) {
|
||||||
|
zt_leave_network("565799d8f65063e5")
|
||||||
|
}
|
||||||
|
|
||||||
var service_thread : NSThread!
|
var service_thread : NSThread!
|
||||||
func ztnc_start_service() {
|
func ztnc_start_service() {
|
||||||
let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
|
let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
|
||||||
print("start_service()\n")
|
start_service(path[0])
|
||||||
// e5cd7a9e1c3511dd
|
|
||||||
start_service("/Users/Joseph/utest3")
|
|
||||||
//start_service(path[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
@@ -27,10 +36,7 @@ class ViewController: UIViewController {
|
|||||||
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
|
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
|
||||||
self.service_thread.start()
|
self.service_thread.start()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set RPC path for this thread
|
|
||||||
zts_init_rpc("/Users/Joseph/utest3/nc_","e5cd7a9e1c2e194f");
|
|
||||||
|
|
||||||
// Do any additional setup after loading the view, typically from a nib.
|
// Do any additional setup after loading the view, typically from a nib.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +44,5 @@ class ViewController: UIViewController {
|
|||||||
super.didReceiveMemoryWarning()
|
super.didReceiveMemoryWarning()
|
||||||
// Dispose of any resources that can be recreated.
|
// Dispose of any resources that can be recreated.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
// Implementations located in src/SDK_XcodeWrapper.cpp
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef Example_OSX_Bridging_Header_h
|
#ifndef Example_OSX_Bridging_Header_h
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
int start_intercept();
|
int start_intercept();
|
||||||
void start_service(const char * path);
|
void start_service(const char * path);
|
||||||
|
void start_service_and_rpc(const char * path, const char * nwid);
|
||||||
void join_network(const char * nwid);
|
void join_network(const char * nwid);
|
||||||
void disable_intercept();
|
void disable_intercept();
|
||||||
void enable_intercept();
|
void enable_intercept();
|
||||||
@@ -30,7 +31,6 @@ int zts_getsockopt(GETSOCKOPT_SIG);
|
|||||||
int zts_close(CLOSE_SIG);
|
int zts_close(CLOSE_SIG);
|
||||||
int zts_getsockname(GETSOCKNAME_SIG);
|
int zts_getsockname(GETSOCKNAME_SIG);
|
||||||
|
|
||||||
|
|
||||||
#endif /* Example_OSX_Bridging_Header_h */
|
#endif /* Example_OSX_Bridging_Header_h */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -139,19 +139,19 @@ int rpc_join(char * sockname)
|
|||||||
strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)-1);
|
strncpy(addr.sun_path, sockname, sizeof(addr.sun_path)-1);
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(SDK_INTERCEPT)
|
||||||
if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
|
|
||||||
#else
|
|
||||||
if((sock = realsocket(AF_UNIX, SOCK_STREAM, 0)) < 0){
|
if((sock = realsocket(AF_UNIX, SOCK_STREAM, 0)) < 0){
|
||||||
|
#else
|
||||||
|
if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0){
|
||||||
#endif
|
#endif
|
||||||
LOGV(stderr, "Error while creating RPC socket\n");
|
LOGV(stderr, "Error while creating RPC socket\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while((conn_err != 0) && (attempts < SERVICE_CONNECT_ATTEMPTS)){
|
while((conn_err != 0) && (attempts < SERVICE_CONNECT_ATTEMPTS)){
|
||||||
#if defined(__ANDROID__)
|
#if defined(SDK_INTERCEPT)
|
||||||
if((conn_err = connect(sock, (struct sockaddr*)&addr, sizeof(addr))) != 0) {
|
|
||||||
#else
|
|
||||||
if((conn_err = realconnect(sock, (struct sockaddr*)&addr, sizeof(addr))) != 0) {
|
if((conn_err = realconnect(sock, (struct sockaddr*)&addr, sizeof(addr))) != 0) {
|
||||||
|
#else
|
||||||
|
if((conn_err = connect(sock, (struct sockaddr*)&addr, sizeof(addr))) != 0) {
|
||||||
#endif
|
#endif
|
||||||
LOGV("Error while connecting to RPC socket. Re-attempting...\n");
|
LOGV("Error while connecting to RPC socket. Re-attempting...\n");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|||||||
@@ -42,12 +42,11 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "service/OneService.hpp"
|
#include "OneService.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
#include "OSUtils.hpp"
|
#include "OSUtils.hpp"
|
||||||
|
|
||||||
#include "SDK.h"
|
#include "SDK.h"
|
||||||
|
|
||||||
#include "SDK_Debug.h"
|
#include "SDK_Debug.h"
|
||||||
#include "SDK_ServiceSetup.hpp"
|
#include "SDK_ServiceSetup.hpp"
|
||||||
|
|
||||||
@@ -56,7 +55,10 @@ pthread_t intercept_thread;
|
|||||||
int * intercept_thread_id;
|
int * intercept_thread_id;
|
||||||
pthread_key_t thr_id_key;
|
pthread_key_t thr_id_key;
|
||||||
static ZeroTier::OneService *volatile zt1Service;
|
static ZeroTier::OneService *volatile zt1Service;
|
||||||
std::string homeDir;
|
|
||||||
|
std::string localHomeDir; // Local shortened path
|
||||||
|
std::string givenHomeDir; // What the user/application provides as a suggestion
|
||||||
|
std::string homeDir; // The resultant platform-specific dir we *must* use internally
|
||||||
std::string netDir;
|
std::string netDir;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -145,20 +147,24 @@ void zt_init_rpc(const char * path, const char * nwid);
|
|||||||
/*
|
/*
|
||||||
* Starts a service thread and performs basic setup tasks
|
* Starts a service thread and performs basic setup tasks
|
||||||
*/
|
*/
|
||||||
void init_service(int key, const char * path)
|
void init_service(int key, const char * path) {
|
||||||
{
|
givenHomeDir = path;
|
||||||
homeDir = path;
|
|
||||||
pthread_key_create(&thr_id_key, NULL);
|
pthread_key_create(&thr_id_key, NULL);
|
||||||
intercept_thread_id = (int*)malloc(sizeof(int));
|
intercept_thread_id = (int*)malloc(sizeof(int));
|
||||||
*intercept_thread_id = key;
|
*intercept_thread_id = key;
|
||||||
pthread_create(&intercept_thread, NULL, startOneService, (void *)(intercept_thread_id));
|
pthread_create(&intercept_thread, NULL, startOneService, (void *)(intercept_thread_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_service_and_rpc(int key, const char * path, const char * nwid)
|
||||||
|
{
|
||||||
|
init_service(key, path);
|
||||||
|
zt_init_rpc(path, nwid);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enables or disables intercept for current thread using key in thread-local storage
|
* Enables or disables intercept for current thread using key in thread-local storage
|
||||||
*/
|
*/
|
||||||
void set_intercept_status(int mode)
|
void set_intercept_status(int mode) {
|
||||||
{
|
|
||||||
fprintf(stderr, "set_intercept_status(mode=%d): tid = %d\n", mode, pthread_mach_thread_np(pthread_self()));
|
fprintf(stderr, "set_intercept_status(mode=%d): tid = %d\n", mode, pthread_mach_thread_np(pthread_self()));
|
||||||
pthread_key_create(&thr_id_key, NULL);
|
pthread_key_create(&thr_id_key, NULL);
|
||||||
intercept_thread_id = (int*)malloc(sizeof(int));
|
intercept_thread_id = (int*)malloc(sizeof(int));
|
||||||
@@ -192,28 +198,30 @@ void zt_init_rpc(const char * path, const char * nwid);
|
|||||||
// homeDir according to platform and build type
|
// homeDir according to platform and build type
|
||||||
if(!homeDir.length())
|
if(!homeDir.length())
|
||||||
{
|
{
|
||||||
#if defined(__UNITY_3D__)
|
|
||||||
int MAX_DIR_SZ = 256;
|
|
||||||
char current_dir[MAX_DIR_SZ];
|
|
||||||
getcwd(current_dir, MAX_DIR_SZ);
|
|
||||||
chdir(service_path.c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__UNITY_3D__) && !defined(__ANDROID__) && !defined(__IOS__)
|
#if defined(__UNITY_3D__) && !defined(__ANDROID__) && !defined(__IOS__)
|
||||||
// Unity3D on a non-mobile platform
|
// Unity3D on a non-mobile platform
|
||||||
homeDir = current_dir; // homeDir shall be current dir
|
homeDir = current_dir; // homeDir shall be current dir
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
|
||||||
#include "TargetConditionals.h"
|
|
||||||
#if TARGET_IPHONE_SIMULATOR
|
|
||||||
// homeDir = "dont/run/this/in/the/simulator";
|
|
||||||
#elif TARGET_OS_IPHONE
|
|
||||||
homeDir = "ZeroTier/One";
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__UNITY_3D__)
|
||||||
|
int MAX_DIR_SZ = 256;
|
||||||
|
char current_dir[MAX_DIR_SZ];
|
||||||
|
getcwd(current_dir, MAX_DIR_SZ);
|
||||||
|
chdir(service_path.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include "TargetConditionals.h"
|
||||||
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
|
// homeDir = "dont/run/this/in/the/simulator/it/wont/work";
|
||||||
|
#elif TARGET_OS_IPHONE
|
||||||
|
localHomeDir = "ZeroTier/One";
|
||||||
|
std::string del = givenHomeDir.length() && givenHomeDir[givenHomeDir.length()-1]!='/' ? "/" : "";
|
||||||
|
homeDir = givenHomeDir + del + localHomeDir;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
/* NOTE: Since on Android devices the sdcard is formatted as fat32, we can't use this
|
/* NOTE: Since on Android devices the sdcard is formatted as fat32, we can't use this
|
||||||
location to set up the RPC unix domain socket. Rather we must use the application's
|
location to set up the RPC unix domain socket. Rather we must use the application's
|
||||||
@@ -223,13 +231,16 @@ void zt_init_rpc(const char * path, const char * nwid);
|
|||||||
//join_network("565799d8f65063e5");
|
//join_network("565799d8f65063e5");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LOGV("homeDir = %s", homeDir.c_str());
|
#if defined(__APPLE__) && !defined(__IOS__)
|
||||||
|
homeDir = givenHomeDir;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
LOGV("homeDir = %s", givenHomeDir.c_str());
|
||||||
// Where network .conf files will be stored
|
// Where network .conf files will be stored
|
||||||
netDir = homeDir + "/networks.d";
|
netDir = homeDir + "/networks.d";
|
||||||
|
|
||||||
zt1Service = (ZeroTier::OneService *)0;
|
zt1Service = (ZeroTier::OneService *)0;
|
||||||
LOGV("Starting ZT service...\n");
|
|
||||||
|
|
||||||
|
// Construct path for network config and supporting service files
|
||||||
if (!homeDir.length()) {
|
if (!homeDir.length()) {
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
return;
|
return;
|
||||||
@@ -254,6 +265,18 @@ void zt_init_rpc(const char * path, const char * nwid);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__IOS__)
|
||||||
|
// Go to the app's data directory so we can shorten the sun_path we bind to
|
||||||
|
int MAX_DIR_SZ = 256;
|
||||||
|
char current_dir[MAX_DIR_SZ];
|
||||||
|
getcwd(current_dir, MAX_DIR_SZ);
|
||||||
|
std::string targetDir = homeDir + "/../../";
|
||||||
|
chdir(targetDir.c_str());
|
||||||
|
homeDir = localHomeDir;
|
||||||
|
#endif
|
||||||
|
|
||||||
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
//chdir(current_dir); // Return to previous current working directory (at the request of Unity3D)
|
||||||
//Debug(homeDir.c_str());
|
//Debug(homeDir.c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ extern std::string homeDir;
|
|||||||
#else
|
#else
|
||||||
void *startOneService(void *thread_id);
|
void *startOneService(void *thread_id);
|
||||||
void init_service(int key, const char * path);
|
void init_service(int key, const char * path);
|
||||||
|
void init_service_and_rpc(int key, const char * path, const char * nwid);
|
||||||
void init_intercept(int key);
|
void init_intercept(int key);
|
||||||
#endif
|
#endif
|
||||||
void set_intercept_status(int mode);
|
void set_intercept_status(int mode);
|
||||||
|
|||||||
@@ -92,24 +92,28 @@ int (*realclose)(CLOSE_SIG);
|
|||||||
void zt_init_rpc(const char *path, const char *nwid)
|
void zt_init_rpc(const char *path, const char *nwid)
|
||||||
{
|
{
|
||||||
dwr(MSG_DEBUG, "zt_init_rpc\n");
|
dwr(MSG_DEBUG, "zt_init_rpc\n");
|
||||||
// Just double check we have
|
#if !defined(__IOS__)
|
||||||
if(!realconnect) {
|
// Since we don't use function interposition in iOS
|
||||||
load_symbols_rpc();
|
if(!realconnect) {
|
||||||
}
|
load_symbols_rpc();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// If no path, construct one or get it fron system env vars
|
||||||
if(!api_netpath) {
|
if(!api_netpath) {
|
||||||
#if defined(SDK_BUNDLED)
|
#if defined(SDK_BUNDLED)
|
||||||
// Get the path/nwid from the user application
|
// Get the path/nwid from the user application
|
||||||
// netpath = [path + "/nc_" + nwid]
|
// netpath = [path + "/nc_" + nwid]
|
||||||
char *fullpath = malloc(strlen(path)+strlen(nwid)+1);
|
char *fullpath = malloc(strlen(path)+strlen(nwid)+1+4);
|
||||||
if(fullpath) {
|
if(fullpath) {
|
||||||
strcpy(fullpath, path);
|
strcpy(fullpath, path);
|
||||||
|
strcat(fullpath, "/nc_");
|
||||||
strcat(fullpath, nwid);
|
strcat(fullpath, nwid);
|
||||||
//api_netpath = fullpath;
|
api_netpath = fullpath;
|
||||||
api_netpath = "/data/data/com.example.joseph.example_app/files/zerotier/nc_565799d8f65063e5";
|
//api_netpath = "/data/data/com.example.joseph.example_app/files/zerotier/nc_565799d8f65063e5";
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Get path/nwid from environment variables
|
// Get path/nwid from environment variables
|
||||||
|
// This is used when you're dynamically-linking our library into your application at runtime
|
||||||
if (!api_netpath) {
|
if (!api_netpath) {
|
||||||
api_netpath = getenv("ZT_NC_NETWORK");
|
api_netpath = getenv("ZT_NC_NETWORK");
|
||||||
dwr(MSG_DEBUG, "$ZT_NC_NETWORK = %s\n", api_netpath);
|
dwr(MSG_DEBUG, "$ZT_NC_NETWORK = %s\n", api_netpath);
|
||||||
@@ -370,7 +374,7 @@ int (*realclose)(CLOSE_SIG);
|
|||||||
printf("path = %s\n", api_netpath);
|
printf("path = %s\n", api_netpath);
|
||||||
LOGV("path = %s\n", api_netpath);
|
LOGV("path = %s\n", api_netpath);
|
||||||
int err = rpc_send_command(api_netpath, RPC_SOCKET, -1, &rpc_st, sizeof(struct socket_st));
|
int err = rpc_send_command(api_netpath, RPC_SOCKET, -1, &rpc_st, sizeof(struct socket_st));
|
||||||
LOGV("socket() = %s\n", err);
|
//LOGV("socket() = %d\n", err);
|
||||||
dwr(MSG_DEBUG," socket() = %d\n", err);
|
dwr(MSG_DEBUG," socket() = %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,17 @@
|
|||||||
#include "SDK_ServiceSetup.hpp"
|
#include "SDK_ServiceSetup.hpp"
|
||||||
|
|
||||||
// Starts a ZeroTier service at the specified path
|
// Starts a ZeroTier service at the specified path
|
||||||
|
// This will only support SOCKS5 Proxy
|
||||||
extern "C" void start_service(const char * path) {
|
extern "C" void start_service(const char * path) {
|
||||||
init_service(INTERCEPT_DISABLED, path);
|
init_service(INTERCEPT_DISABLED, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starts a ZeroTier service at the specified path and initializes the RPC mechanism
|
||||||
|
// This will allow direct API calls
|
||||||
|
extern "C" void start_service_and_rpc(const char * path, const char * nwid) {
|
||||||
|
init_service_and_rpc(INTERCEPT_DISABLED, path, nwid);
|
||||||
|
}
|
||||||
|
|
||||||
// Joins a ZeroTier virtual network
|
// Joins a ZeroTier virtual network
|
||||||
extern "C" void zt_join_network(const char * nwid){
|
extern "C" void zt_join_network(const char * nwid){
|
||||||
join_network(nwid);
|
join_network(nwid);
|
||||||
@@ -32,9 +39,13 @@ extern "C" void zt_leave_network(const char * nwid){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Explicit ZT API wrappers
|
// Explicit ZT API wrappers
|
||||||
extern "C" void zts_init_rpc(const char *path, const char *nwid) {
|
#if !defined(__IOS__)
|
||||||
zt_init_rpc(path, nwid);
|
// This isn't available for iOS since function interposition isn't as reliable
|
||||||
}
|
extern "C" void zts_init_rpc(const char *path, const char *nwid) {
|
||||||
|
zt_init_rpc(path, nwid);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" int zts_socket(SOCKET_SIG) {
|
extern "C" int zts_socket(SOCKET_SIG) {
|
||||||
return zt_socket(socket_family, socket_type, protocol);
|
return zt_socket(socket_family, socket_type, protocol);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user