diff --git a/.gitignore b/.gitignore
index 25be1ac..b827dbd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@ integrations/android/example_app/local.properties
integrations/Unity3D/Library
integrations/Unity3D/Temp
integrations/Unity3D/obj
+integrations/Unity3D/Plugins
# Docker test
*.tmp
@@ -26,3 +27,4 @@ zerotierone
# Other
.depend
.buildnum
+build
diff --git a/docs/ios_zt_sdk.md b/docs/ios_zt_sdk.md
index ff7646f..7171ee5 100644
--- a/docs/ios_zt_sdk.md
+++ b/docs/ios_zt_sdk.md
@@ -52,7 +52,7 @@ The following APIs are available for this integration:
**Step 5: Join a network!**
-Simply call `zt_join_network("XXXXXXXXXXXXXXXX")`
+Simply call `zt_join_network("nwid")`
***
**NSStream and SOCKS Proxy:**
diff --git a/docs/osx_unity3d_zt_sdk.md b/docs/osx_unity3d_zt_sdk.md
index e45eb55..6df90f4 100644
--- a/docs/osx_unity3d_zt_sdk.md
+++ b/docs/osx_unity3d_zt_sdk.md
@@ -7,8 +7,6 @@ We want your Unity apps to talk *directly* over a flat, secure, no-config virtua
Our implementation currently intends to be the bare minimum required to get your Unity application to talk over ZeroTier virtual networks. As a result, we've created an API that is very similar to the classic BSD-style sockets API. With this basic API it is possible to construct more abstracted network layers much like Unity's LLAPI and HLAPI.
-Our example project can be found [here]()
-
***
## API
@@ -51,7 +49,7 @@ public class Example
public void example_server()
{
zt = new ZeroTierNetworkInterface (); // Start interface
- zt.Join("565799d8f6e1c11a"); // Join your network
+ zt.Join("8056c2e21c000001"); // Join your network
Thread connectThread = new Thread(() => {
// Create ZeroTier-administered socket
diff --git a/docs/osx_zt_sdk.md b/docs/osx_zt_sdk.md
index 3b9cb29..05cd9b5 100644
--- a/docs/osx_zt_sdk.md
+++ b/docs/osx_zt_sdk.md
@@ -83,7 +83,7 @@ The following APIs are available for this integration:
**Step 5: Join a network!**
-Simply call `zt_join_network("XXXXXXXXXXXXXXXX")`
+Simply call `zt_join_network("nwid")`
***
**NSStream and SOCKS Proxy:**
diff --git a/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/Info.plist b/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/Info.plist
deleted file mode 100644
index b959195..0000000
--- a/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/Info.plist
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
-
- BuildMachineOSBuild
- 15F34
- CFBundleDevelopmentRegion
- en
- CFBundleExecutable
- ZeroTierSDK_Unity3D_OSX
- CFBundleIdentifier
- zerotier.ZeroTierSDK-Unity3D-OSX
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleName
- ZeroTierSDK_Unity3D_OSX
- CFBundlePackageType
- BNDL
- CFBundleShortVersionString
- 1.0
- CFBundleSignature
- ????
- CFBundleSupportedPlatforms
-
- MacOSX
-
- CFBundleVersion
- 1
- DTCompiler
- com.apple.compilers.llvm.clang.1_0
- DTPlatformBuild
- 7D1014
- DTPlatformVersion
- GM
- DTSDKBuild
- 15E60
- DTSDKName
- macosx10.11
- DTXcode
- 0731
- DTXcodeBuild
- 7D1014
- NSHumanReadableCopyright
- Copyright © 2016 ZeroTier Inc. All rights reserved.
-
-
diff --git a/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/MacOS/ZeroTierSDK_Unity3D_OSX b/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/MacOS/ZeroTierSDK_Unity3D_OSX
deleted file mode 100755
index 390d462..0000000
Binary files a/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/MacOS/ZeroTierSDK_Unity3D_OSX and /dev/null differ
diff --git a/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/_CodeSignature/CodeResources b/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/_CodeSignature/CodeResources
deleted file mode 100644
index 0710b40..0000000
--- a/integrations/Unity3D/Assets/Plugins/ZeroTierSDK_Unity3D_OSX.bundle/Contents/_CodeSignature/CodeResources
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-
-
- files
-
- files2
-
- rules
-
- ^Resources/
-
- ^Resources/.*\.lproj/
-
- optional
-
- weight
- 1000
-
- ^Resources/.*\.lproj/locversion.plist$
-
- omit
-
- weight
- 1100
-
- ^version.plist$
-
-
- rules2
-
- .*\.dSYM($|/)
-
- weight
- 11
-
- ^(.*/)?\.DS_Store$
-
- omit
-
- weight
- 2000
-
- ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/
-
- nested
-
- weight
- 10
-
- ^.*
-
- ^Info\.plist$
-
- omit
-
- weight
- 20
-
- ^PkgInfo$
-
- omit
-
- weight
- 20
-
- ^Resources/
-
- weight
- 20
-
- ^Resources/.*\.lproj/
-
- optional
-
- weight
- 1000
-
- ^Resources/.*\.lproj/locversion.plist$
-
- omit
-
- weight
- 1100
-
- ^[^/]+$
-
- nested
-
- weight
- 10
-
- ^embedded\.provisionprofile$
-
- weight
- 20
-
- ^version\.plist$
-
- weight
- 20
-
-
-
-
diff --git a/integrations/Unity3D/Assets/ZeroTierSockets_Demo.cs b/integrations/Unity3D/Assets/ZeroTierSockets_Demo.cs
index c19d951..b4f101a 100644
--- a/integrations/Unity3D/Assets/ZeroTierSockets_Demo.cs
+++ b/integrations/Unity3D/Assets/ZeroTierSockets_Demo.cs
@@ -234,7 +234,7 @@ public class ZeroTierSockets_Demo : MonoBehaviour
input.text = "Welcome to the machine";
// Create new instance of ZeroTier in separate thread
- zt = new ZTSDK (".", "8056c2e21c000001");
+ zt = new ZTSDK ("zerotier/", "8056c2e21c000001");
}
// Terminate the ZeroTier service when the application quits
diff --git a/integrations/android/example_app/app/src/main/java/ZeroTier/ZTAddress.java b/integrations/android/example_app/app/src/main/java/ZeroTier/ZTAddress.java
new file mode 100644
index 0000000..e26612e
--- /dev/null
+++ b/integrations/android/example_app/app/src/main/java/ZeroTier/ZTAddress.java
@@ -0,0 +1,84 @@
+package ZeroTier;
+
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+import java.util.regex.Pattern;
+
+/*
+
+The ZTAddress object is merely a convenience object for moving address information
+across the JNI memory border.
+
+*/
+
+public class ZTAddress
+{
+ // int -> byte array
+ static public byte[] toIPByteArray(long addr){
+ return new byte[]{(byte)addr,(byte)(addr>>>8),(byte)(addr>>>16),(byte)(addr>>>24)};
+ }
+
+ // byte array -> int
+ long toIPInt(String _addr) {
+ long result = 0;
+ for(String part: _addr.split(Pattern.quote("."))) {
+ result = result << 8;
+ result |= Integer.parseInt(part);
+ }
+ return result;
+ }
+
+ public int port;
+ public int Port() {
+ return port;
+ }
+
+ public long _rawAddr;
+ public String Address()
+ {
+ try {
+ return InetAddress.getByAddress(toIPByteArray(_rawAddr)).getHostAddress();
+ } catch (UnknownHostException e) {
+ // should never happen
+ return null;
+ }
+ }
+
+ public String toString() {
+ return Address() + ":" + Port();
+ }
+
+ public ZTAddress()
+ {
+ port = -1;
+ _rawAddr = -1;
+ }
+
+ public ZTAddress(String _addr, int _port)
+ {
+ _rawAddr = toIPInt(_addr);
+ port = _port;
+ }
+
+ public void ZTAddress(InetSocketAddress ins)
+ {
+ port = ins.getPort();
+ _rawAddr = toIPInt(ins.getAddress().getHostAddress());
+ }
+
+ public InetSocketAddress ToInetSocketAddress() throws IllegalArgumentException {
+ InetSocketAddress sock_addr = null;
+ try {
+ sock_addr = new InetSocketAddress(Address(), port);
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ }
+ return sock_addr;
+ }
+
+ public boolean isValid() {
+ return port != -1 && !Address().startsWith("-1.-1.-1.-1/-1");
+ }
+}
\ No newline at end of file
diff --git a/integrations/android/example_app/app/src/main/java/ZeroTier/ZTSDK.java b/integrations/android/example_app/app/src/main/java/ZeroTier/ZTSDK.java
new file mode 100644
index 0000000..7cd32c4
--- /dev/null
+++ b/integrations/android/example_app/app/src/main/java/ZeroTier/ZTSDK.java
@@ -0,0 +1,275 @@
+/*
+ * ZeroTier One - Network Virtualization Everywhere
+ * Copyright (C) 2011-2015 ZeroTier, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * --
+ *
+ * ZeroTier may be used and distributed under the terms of the GPLv3, which
+ * are available at: http://www.gnu.org/licenses/gpl-3.0.html
+ *
+ * If you would like to embed ZeroTier into a commercial application or
+ * redistribute it in a modified binary form, please contact ZeroTier Networks
+ * LLC. Start here: http://www.zerotier.com/
+ */
+package ZeroTier;
+
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.zip.ZipError;
+
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+import android.util.Pair;
+
+public class ZTSDK {
+
+ // Socket families
+ public static int AF_UNIX = 1;
+ public static int AF_INET = 2;
+
+ // Socket types
+ public static int SOCK_STREAM = 1;
+ public static int SOCK_DGRAM = 2;
+
+ // fcntl flags
+ public static int O_APPEND = 1024;
+ public static int O_NONBLOCK = 2048;
+ public static int O_ASYNC = 8192;
+ public static int O_DIRECT = 65536;
+ public static int O_NOATIME = 262144;
+
+ // fcntl cmds
+ public static int F_GETFL = 3;
+ public static int F_SETFL = 4;
+
+ // Loads JNI code
+ static { System.loadLibrary("ZeroTierOneJNI"); }
+
+ // ZeroTier service controls
+ public native void zt_start_service(String homeDir);
+ public void start_service(String homeDir) {
+ zt_start_service(homeDir);
+ }
+
+ public native void zt_join_network(String nwid);
+ public void join_network(String nwid) {
+ zt_join_network(nwid);
+ }
+
+ public native void zt_leave_network(String nwid);
+ public void leave_network(String nwid) {
+ zt_leave_network(nwid);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ------------------------------- get_addresses() ------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native ArrayList zt_get_addresses(String nwid);
+ public ArrayList get_addresses(String nwid) {
+ int err = -1;
+ ArrayList addresses;
+ while (err < 0) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ addresses = zt_get_addresses(nwid);
+ if (addresses.size() > 0) {
+ return addresses;
+ }
+ }
+ return null;
+ }
+
+ public native int zt_get_proxy_port(String nwid);
+ public int get_proxy_port(String nwid) {
+ return zt_get_proxy_port(nwid);
+ }
+
+ public native boolean zt_running();
+ public boolean running() {
+ return zt_running();
+ }
+
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- socket() ---------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_socket(int family, int type, int protocol);
+ public int socket(int family, int type, int protocol) {
+ return zt_socket(family, type, protocol);
+ }
+
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- connect() --------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_connect(int fd, String addr, int port);
+
+ public int connect(int sock, ZTAddress zaddr, String nwid) {
+ return connect(sock, zaddr.Address(), zaddr.Port(), nwid);
+ }
+
+ public int connect(int sock, String addr, int port, String nwid)
+ {
+ int err = -1;
+ ArrayList addresses;
+ while (err < 0) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ addresses = zt_get_addresses(nwid);
+ if (addresses.size() > 0) {
+ if(!addresses.get(0).startsWith("-1.-1.-1.-1/-1")) {
+ err = zt_connect(sock, addr, port);
+ }
+ }
+ }
+ return err;
+ }
+
+ // ------------------------------------------------------------------------------
+ // ------------------------------------ bind() ----------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_bind(int fd, String addr, int port);
+
+ public int bind(int sock, ZTAddress zaddr, String nwid) {
+ return bind(sock, zaddr.Address(), zaddr.Port(), nwid);
+ }
+ public int bind(int sock, String addr, int port, String nwid) {
+ int err = -1;
+ ArrayList addresses;
+ while (err < 0) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ addresses = zt_get_addresses(nwid);
+ if (addresses.size() > 0) {
+ if(!addresses.get(0).startsWith("-1.-1.-1.-1/-1")) {
+ err = zt_bind(sock, addr, port);
+ }
+ }
+ }
+ return err;
+ }
+
+
+ // ------------------------------------------------------------------------------
+ // ---------------------------------- accept4() ---------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_accept4(int fd, String addr, int port);
+ public int accept4(int fd, String addr, int port) {
+ return zt_accept4(fd,addr,port);
+ }
+
+
+ // ------------------------------------------------------------------------------
+ // ---------------------------------- accept() ----------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_accept(int fd, ZeroTier.ZTAddress addr);
+ public int accept(int fd, ZeroTier.ZTAddress addr) {
+ return zt_accept(fd, addr);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- listen() ---------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_listen(int fd, int backlog);
+ public int listen(int fd, int backlog) {
+ return zt_listen(fd,backlog);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- close() ----------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_close(int fd);
+ public int close(int fd) {
+ return close(fd);
+ }
+
+
+ // ------------------------------------------------------------------------------
+ // ------------------------------------ read() ----------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_read(int fd, byte[] buf, int len);
+ public int read(int fd, byte[] buf, int len) {
+ return zt_read(fd, buf, len);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- write() ----------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_write(int fd, byte[] buf, int len);
+ public int write(int fd, byte[] buf, int len) {
+ return zt_write(fd, buf, len);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- sendto() ---------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_sendto(int fd, byte[] buf, int len, int flags, ZeroTier.ZTAddress addr);
+ public int sendto(int fd, byte[] buf, int len, int flags, ZeroTier.ZTAddress addr){
+ return zt_sendto(fd,buf,len,flags,addr);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ----------------------------------- send() -----------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_send(int fd, byte[] buf, int len, int flags);
+ public int send(int fd, byte[] buf, int len, int flags) {
+ return zt_send(fd, buf, len, flags);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ---------------------------------- recvfrom() --------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_recvfrom(int fd, byte[] buf, int len, int flags, ZeroTier.ZTAddress addr);
+ public int recvfrom(int fd, byte[] buf, int len, int flags, ZeroTier.ZTAddress addr){
+ return zt_recvfrom(fd,buf,len,flags,addr);
+ }
+
+ // ------------------------------------------------------------------------------
+ // ---------------------------------- recvfrom() --------------------------------
+ // ------------------------------------------------------------------------------
+
+ public native int zt_fcntl(int sock, int cmd, int flag);
+ public int fcntl(int sock, int cmd, int flag) {
+ return zt_fcntl(sock, F_SETFL, O_NONBLOCK);
+ }
+
+
+
+ //public static native int zt_getsockopt(int fd, int type, int protocol);
+ //public static native int zt_setsockopt(int fd, int type, int protocol);
+ //public static native int zt_getsockname(int fd, int type, int protocol);
+}
\ No newline at end of file
diff --git a/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java b/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java
index ac1cc61..3114421 100644
--- a/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java
+++ b/integrations/android/example_app/app/src/main/java/com/example/joseph/example_app/MainActivity.java
@@ -14,7 +14,7 @@ import java.net.Proxy;
import java.net.Socket;
import java.net.SocketAddress;
-import ZeroTier.SDK;
+import ZeroTier.ZTSDK;
import ZeroTier.ZTAddress;
public class MainActivity extends AppCompatActivity {
@@ -26,7 +26,7 @@ public class MainActivity extends AppCompatActivity {
String nwid = "8056c2e21c000001";
// Set up service
- final SDK zt = new SDK();
+ final ZTSDK zt = new ZTSDK();
final String homeDir = getApplicationContext().getFilesDir() + "/zerotier";
new Thread(new Runnable() {
public void run() {
@@ -43,17 +43,13 @@ public class MainActivity extends AppCompatActivity {
if(mode==1)
{
zt.join_network(nwid);
- int sock = zt.socket(SDK.AF_INET, SDK.SOCK_STREAM, 0);
-
+ int sock = zt.socket(ZTSDK.AF_INET, ZTSDK.SOCK_STREAM, 0);
if((err = zt.bind(sock, "0.0.0.0", 8080, nwid)) < 0)
Log.d("ZTSDK", "bind_err = " + err + "\n");
-
if((err = zt.listen(sock,1)) < 0)
Log.d("ZTSDK", "listen_err = " + err);
-
if((err = zt.accept(sock,null)) < 0)
Log.d("ZTSDK", "accept_err = " + err);
-
Log.d("ZTSDK", "Waiting to accept connection...");
// ...
@@ -64,14 +60,11 @@ public class MainActivity extends AppCompatActivity {
{
Log.d("ZTSDK", "\n\nStarting TCP Echo ZTSDK\n\n");
zt.join_network(nwid);
- int sock = zt.socket(SDK.AF_INET, SDK.SOCK_STREAM, 0);
+ int sock = zt.socket(ZTSDK.AF_INET, ZTSDK.SOCK_STREAM, 0);
String msg = "Welcome to the machine!";
err = zt.connect(sock, "28.206.65.211", 8099, nwid);
-
Log.d("ZTSDK", "err = " + err + "\n");
- //return;
-
// ECHO
while(true)
{
@@ -79,7 +72,6 @@ public class MainActivity extends AppCompatActivity {
if((err = zt.write(sock, msg.getBytes(), msg.length())) > 0) {
Log.d("ZTSDK", "TX: " + msg + " --- " + err + " bytes");
}
-
// RX
byte[] buffer = new byte[32];
Arrays.fill(buffer, (byte)0);
@@ -96,7 +88,7 @@ public class MainActivity extends AppCompatActivity {
if(mode==3)
{
zt.join_network(nwid);
- int sock = zt.socket(SDK.AF_INET, SDK.SOCK_STREAM, 0);
+ int sock = zt.socket(ZTSDK.AF_INET, ZTSDK.SOCK_STREAM, 0);
int proxyPort = zt.get_proxy_port(nwid);
Log.d("ZTSDK", "Setting up connection to SDK proxy server");
@@ -143,7 +135,7 @@ public class MainActivity extends AppCompatActivity {
Log.d("ZTSDK", "\n\nStarting UDP Echo ZTSDK\n\n");
nwid = "8056c2e21c000001";
zt.join_network(nwid);
- int sock = zt.socket(SDK.AF_INET, SDK.SOCK_DGRAM, 0);
+ int sock = zt.socket(ZTSDK.AF_INET, ZTSDK.SOCK_DGRAM, 0);
Log.d("ZTSDK", "binding...");
if((err = zt.bind(sock, bindAddr, nwid)) < 0)
@@ -162,7 +154,7 @@ public class MainActivity extends AppCompatActivity {
String bufStr;
byte[] buffer = new byte[1024];
- zt.fcntl(sock, zt.F_SETFL, zt.O_NONBLOCK);
+ zt.fcntl(sock, ZTSDK.F_SETFL, ZTSDK.O_NONBLOCK);
// ECHO
while(true) {