From 9dd8a223c96307fb8e85f8157f7d3b6974158021 Mon Sep 17 00:00:00 2001 From: Joseph Henry Date: Mon, 20 Jun 2016 12:37:14 -0700 Subject: [PATCH] separated LLAPI and ZT-Sockets API logic --- integrations/Unity3D/Assets/MainScene.unity | Bin 72520 -> 102504 bytes integrations/Unity3D/Assets/MyZeroTier.cs | 0 integrations/Unity3D/Assets/WorldMain.cs | 46 ++- integrations/Unity3D/Assets/ZT.mat | Bin .../Unity3D/Assets/ZerTierLLAPI_Demo.cs | 214 ++++++++++++ integrations/Unity3D/Assets/ZeroTierLLAPI.cs | 175 ++++++++++ .../Unity3D/Assets/ZeroTierSockets.cs | 305 ++++++++++++++++++ .../Unity3D/Assets/ZeroTierSockets_Demo.cs | 246 ++++++++++++++ integrations/Unity3D/Assets/ZeroTierUtils.cs | 29 +- integrations/Unity3D/Assets/smcs.rsp | 0 tests/client.c | 22 +- 11 files changed, 1024 insertions(+), 13 deletions(-) mode change 100644 => 100755 integrations/Unity3D/Assets/MyZeroTier.cs mode change 100644 => 100755 integrations/Unity3D/Assets/WorldMain.cs mode change 100644 => 100755 integrations/Unity3D/Assets/ZT.mat create mode 100755 integrations/Unity3D/Assets/ZerTierLLAPI_Demo.cs create mode 100644 integrations/Unity3D/Assets/ZeroTierLLAPI.cs create mode 100755 integrations/Unity3D/Assets/ZeroTierSockets.cs create mode 100644 integrations/Unity3D/Assets/ZeroTierSockets_Demo.cs mode change 100644 => 100755 integrations/Unity3D/Assets/ZeroTierUtils.cs mode change 100644 => 100755 integrations/Unity3D/Assets/smcs.rsp diff --git a/integrations/Unity3D/Assets/MainScene.unity b/integrations/Unity3D/Assets/MainScene.unity index cf749dce9901624c6ac3792ea61e448efe3b301a..ec9e8299ca7cfca10288e444199ea1e7ad658abe 100644 GIT binary patch delta 13604 zcmbVT3s_V~vhFhsFd`}ng3fA!2^vIH@QFkt3MeQfC`2)dfe}YRVHk%|i7zmkNTNox zRqz>z#*N-6=1#uoy19y)&6Zt1~B&ZL8j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0bZ7Ls+{U<>qNoW!I1 zTvC-FXSs1`W;U}Wf&3d-+7rlkz>;NfA5)0{CGvf~n@ctU1_4H)Y`FWshht6yncgEP z(i4fkN674h<gyOwjgHwT&DLPL-?um}4Q()6$Op2gfu^$Ar$8wa(JnemPWO7V+!y_fF$? z&ZVT}wvbr~9Vbo1axP+lwvd+Ah2pu4%mJA6__cGaayjX_EzA#xevqED7rBT9-Y%q0 zv~tW&eg!)hUBAl|xmJ=DPC-$*ioER<^y;?|N``1c+rM}*NaT`P8FF)5wx7wPzMC^h z3$UQoqzhP@pvUMdjFJs^T3i!0ZK0CEnevo9r9Yd^ziYa{d- z$0`AnR#s4QT>+axDpMHD!J-m*v|iyDDwW4v;8?hcoVqV$ri0R&m)wln zI}q)HN5}zKJIqct+|@pTV~yM8Ve;XarHlv<1ihmS+=HduY(~ASYd)i{Er;U`u$64M zsdsa%xtx?d5EQO*au8U8E8JwS#op2wQv;Zazn%X(YG=%IRJ-}kwL53a((~UbJ z5*}mQ-=9mGsz}REf}*~Pbp0f(42IRx>YJQaSqqVB({hSZUqz=&FL`3@J(26CE)< z&aoQ%9GE|N-Sawg-ce;-tejho=cDBxhxB;b0{F2HTb6uieaH3SDJfi5NtZ(}Td5u;f?j08c= z92_n-M`NeD;pqO02%Wu%%rje&;dU!EO6<_!c5aa9jKN`)M(ogGr!N)PT358X#l@Cb z`~;$U<_$apRN6ZAcr#0%c)^Hc#Eu1^$`p_7G`%+6LcGTv`m+hx9{4AST}5TZTNSw# zJIa@o2i#SZV7_!!|G!$|}{?k&ZQBthJr2?~fG?892bUY!yDQ z;BfkCtael8ufaM`2nW. + * + * -- + * + * 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/ + */ + +using UnityEngine; +using System.Collections; +using UnityEngine.UI; +using System; + +public class WorldMain : MonoBehaviour { + void Start() { + } + + public void API_selection() + { + GameObject go = GameObject.Find ("dropdownAPI"); + Dropdown dd = go.GetComponents () [0]; + Debug.Log("API selected: " + dd.captionText.text); + } + + +} diff --git a/integrations/Unity3D/Assets/ZT.mat b/integrations/Unity3D/Assets/ZT.mat old mode 100644 new mode 100755 diff --git a/integrations/Unity3D/Assets/ZerTierLLAPI_Demo.cs b/integrations/Unity3D/Assets/ZerTierLLAPI_Demo.cs new file mode 100755 index 0000000..70273bc --- /dev/null +++ b/integrations/Unity3D/Assets/ZerTierLLAPI_Demo.cs @@ -0,0 +1,214 @@ +/* + * 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/ + */ + +using UnityEngine; +using System.Collections; +using System.Threading; +using System.Runtime.Serialization.Formatters.Binary; +using System.IO; +using UnityEngine.UI; +using UnityEngine.Networking; + +// Demonstrates the usage of the ZeroTier LLAPI (modeled after the Unity LLAPI) +public class ZeroTierLLAPI_Demo : MonoBehaviour +{ + public float speed = 300f; + + private ZeroTierLLAPI zt; + string nwid = ""; + + int server_connection_socket; // The "connection id" + int host_socket; + + // Demo button methods + public void Join() + { + GameObject go = GameObject.Find ("inputNetworkID"); + InputField input = go.GetComponents () [0]; + Debug.Log ("Joining: " + input.text); + zt.JoinNetwork (input.text); + } + + public void Leave() + { + GameObject go = GameObject.Find ("inputNetworkID"); + InputField input = go.GetComponents () [0]; + Debug.Log ("Leaving: " + input.text); + zt.LeaveNetwork (input.text); + } + + public void Connect() + { + GameObject addr_go = GameObject.Find ("inputServerAddress"); + GameObject port_go = GameObject.Find ("inputServerPort"); + InputField addr = addr_go.GetComponents () [0]; + InputField port = port_go.GetComponents () [0]; + Debug.Log ("Connecting to: " + addr.text + ":" + port.text); + + Thread connectThread = new Thread(() => { + byte error = 0; + server_connection_socket = zt.Connect (0, addr.text, int.Parse (port.text), out error); + Debug.Log ("server_connection_socket = " + server_connection_socket); + Debug.Log ("Connect(): " + error); + }); + connectThread.IsBackground = true; + connectThread.Start(); + } + + public void Bind() + { + GameObject addr_go = GameObject.Find ("inputServerAddress"); + GameObject port_go = GameObject.Find ("inputServerPort"); + InputField addr = addr_go.GetComponents () [0]; + InputField port = port_go.GetComponents () [0]; + Debug.Log ("Binding to: " + addr.text + ":" + port.text); + + Thread connectThread = new Thread(() => { + byte error = 0; + host_socket = zt.AddHost (int.Parse (port.text)); + Debug.Log ("host_socket = " + host_socket); + Debug.Log ("Bind(): " + error); + }); + connectThread.IsBackground = true; + connectThread.Start(); + } + + public void Disconnect() + { + GameObject addr_go = GameObject.Find ("inputServerAddress"); + GameObject port_go = GameObject.Find ("inputServerAddress"); + InputField addr = addr_go.GetComponents () [0]; + InputField port = port_go.GetComponents () [0]; + Debug.Log ("Disconnecting from: " + addr.text + ":" + port.text); + Debug.Log ("Disconnect(): " + zt.Disconnect (server_connection_socket)); + } + + public void SendMessage() + { + //zt_test_network (); + GameObject go = GameObject.Find ("inputMessage"); + InputField msg = go.GetComponents () [0]; + + Thread sendThread = new Thread(() => { + Debug.Log ("Sending Message: " + msg.text); + byte error = 0; + zt.Send (server_connection_socket, msg.text.ToCharArray (), msg.text.ToCharArray ().Length, out error); + Debug.Log ("Send(): " + error); + }); + sendThread.IsBackground = true; + sendThread.Start(); + + } + + void Start() + { + // Set defaults + InputField input; + GameObject go; + go = GameObject.Find ("inputNetworkID"); + input = go.GetComponents () [0]; + input.text = "565799d8f6e1c11a"; + go = GameObject.Find ("inputServerAddress"); + input = go.GetComponents () [0]; + input.text = "172.22.211.245"; + go = GameObject.Find ("inputServerPort"); + input = go.GetComponents () [0]; + input.text = "8887"; + go = GameObject.Find ("inputMessage"); + input = go.GetComponents () [0]; + input.text = "Welcome to the machine"; + + // Create new instance of ZeroTier in separate thread + zt = new ZeroTierLLAPI ("/Users/Joseph/utest2/nc_565799d8f6e1c11a"); + + /* This new instance will communicate via a named pipe, so any + * API calls (ZeroTier.Connect(), ZeroTier.Send(), etc) will be sent to the service + * via this pipe. + */ + } + + // Terminate the ZeroTier service when the application quits + void OnApplicationQuit() { + Debug.Log ("OnApplicationQuit()"); + zt.Terminate (); + } + + // Update is called once per frame + void Update () { + /* + if (text) { + text.text = IsRunning() ? "ZeroTier Status: Online" : "ZeroTier Status: Offline"; + } + */ + + // --- + + int recHostId; + int connectionId; + int channelId; + byte[] recBuffer = new byte[1024]; + int bufferSize = 1024; + int dataSize; + byte error; + NetworkEventType recData = zt.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); + switch (recData) + { + case NetworkEventType.Nothing: + break; + case NetworkEventType.ConnectEvent: + Debug.Log("NetworkEventType.ConnectEvent"); + break; + case NetworkEventType.DataEvent: + Debug.Log("NetworkEventType.DataEvent"); + break; + case NetworkEventType.DisconnectEvent: + Debug.Log("NetworkEventType.DisconnectEvent"); + break; + } + + // --- + + /* + GameObject go = GameObject.Find ("_txtStatusIndicator"); + Text text = go.GetComponents () [0]; + text.text = zt.IsRunning () ? "ZeroTier Service: ONLINE" : "ZeroTier Service: OFFLINE"; + */ + + // Rotate ZTCube when ZT is running + /* + if (zt.IsRunning ()) { + + + go = GameObject.Find ("ZTCube"); + Vector3 rotvec = new Vector3 (10f, 10f, 10f); + go.transform.Rotate (rotvec, speed * Time.deltaTime); + } + GameObject go = GameObject.Find("ZTCube"); + Text text = go.GetComponents ()[0]; + */ + } +} \ No newline at end of file diff --git a/integrations/Unity3D/Assets/ZeroTierLLAPI.cs b/integrations/Unity3D/Assets/ZeroTierLLAPI.cs new file mode 100644 index 0000000..13eb213 --- /dev/null +++ b/integrations/Unity3D/Assets/ZeroTierLLAPI.cs @@ -0,0 +1,175 @@ +/* + * 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/ + */ + +using UnityEngine; +using System.Collections; +using System.Threading; +using System.Net.Sockets; +using System.Runtime.InteropServices; +using System; +using UnityEngine.Networking; + +// Provides a familiar interface which is modeled after the Unity LLAPI +public class ZeroTierLLAPI : ZeroTierNetworkInterface { + + // Initialize the ZeroTier service with a given path + public ZeroTierLLAPI(string path) + { + rpc_path = path; + Init(); + } + + // Creates a ZeroTier Socket and binds on the port provided + // A client instance can now connect to this "host" + public int AddHost(int port) + { + int sockfd = zt_socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified); + if (sockfd < 0) { + return -1; + } + GCHandle sockaddr_ptr = ZeroTierUtils.Generate_unmananged_sockaddr("0.0.0.0" + ":" + port); + IntPtr pSockAddr = sockaddr_ptr.AddrOfPinnedObject (); + int addrlen = Marshal.SizeOf (pSockAddr); + // Set socket to non-blocking for RX polling in Receive() + zt_set_nonblock(sockfd); + return zt_bind (sockfd, pSockAddr, addrlen); + } + + // hostId - host socket ID for this connection + public int Connect(int hostId, string address, int port, out byte error) + { + int sockfd = zt_socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified); + Debug.Log ("sockfd = " + sockfd); + + if (sockfd < 0) { + error = (byte)sockfd; + return -1; + } + GCHandle sockaddr_ptr = ZeroTierUtils.Generate_unmananged_sockaddr(address + ":" + port); + IntPtr pSockAddr = sockaddr_ptr.AddrOfPinnedObject (); + int addrlen = Marshal.SizeOf (pSockAddr); + error = (byte)zt_connect (sockfd, pSockAddr, addrlen); + + // Set socket to non-blocking for RX polling in Receive() + zt_set_nonblock(sockfd); + return sockfd; + } + + // Write data to a ZeroTier socket + public int Send(int fd, char[] buf, int len, out byte error) + { + error = 0; + return Write(fd, buf, len); + } + + // Checks for data to RX + /* + public enum NetworkEventType + { + DataEvent, + ConnectEvent, + DisconnectEvent, + Nothing, + BroadcastEvent + } + */ + public NetworkEventType Receive(out int hostId, out int connectionId, out int channelId, byte[] buffer, int bufferSize, out int receivedSize, out byte error) + { + hostId = 0; + connectionId = 0; + channelId = 0; + receivedSize = 0; + error = 0; + + + // Read() ... + + /* + * If recBuffer is big enough to contain data, data will be copied in the buffer. + * If not, error will contain MessageToLong error and you will need reallocate + * buffer and call this function again. */ + + //for (int i = 0; i < connections.Count; i++) { + + //} + + /* + int res; + res = zt_recv (connectionId, buffer, bufferSize); + + // FIXME: Not quite semantically the same, but close enough for alpha release? + // FIXME: Get notifications of disconnect events? + if (res == -1) { + error = -1; + return NetworkEventType.DisconnectEvent; + } + if(res == 0) { + error = 0; + return NetworkEventType.Nothing; // No data read + } + if (res > 0) { + receivedSize = res; + Marshal.Copy(buffer, buffer, 0, res); + return NetworkEventType.DataEvent; // Data read into buffer + } + */ + + return NetworkEventType.Nothing; + } + + // Shutdown a given connection + public int Disconnect(int fd) + { + return zt_close (fd); + } + + // Test serialization methods, should be removed for production + + public static byte[] RawSerializeEx( object anything ) + { + int rawsize = Marshal.SizeOf( anything ); + byte[] rawdatas = new byte[ rawsize ]; + GCHandle handle = GCHandle.Alloc( rawdatas, GCHandleType.Pinned ); + IntPtr buffer = handle.AddrOfPinnedObject(); + Marshal.StructureToPtr( anything, buffer, false ); + handle.Free(); + return rawdatas; + } + + + public static object RawDeserializeEx( byte[] rawdatas, Type anytype ) + { + int rawsize = Marshal.SizeOf( anytype ); + if( rawsize > rawdatas.Length ) + return null; + GCHandle handle = GCHandle.Alloc( rawdatas, GCHandleType.Pinned ); + IntPtr buffer = handle.AddrOfPinnedObject(); + object retobj = Marshal.PtrToStructure( buffer, anytype ); + handle.Free(); + return retobj; + } +} diff --git a/integrations/Unity3D/Assets/ZeroTierSockets.cs b/integrations/Unity3D/Assets/ZeroTierSockets.cs new file mode 100755 index 0000000..cbc9a41 --- /dev/null +++ b/integrations/Unity3D/Assets/ZeroTierSockets.cs @@ -0,0 +1,305 @@ +/* + * 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/ + */ + +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.Networking; + +using System; +using System.Collections; +using System.Runtime.InteropServices; +using System.Threading; +using System.Net.Sockets; +using System.Net; +using System.IO; +using System.Collections.Generic; + +// Provides a bare-bones interface to ZeroTier-administered sockets +public class ZeroTierNetworkInterface { + + // Apple + #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX + const string DLL_PATH = "ZeroTierSDK_Unity3D_OSX"; + #endif + + #if UNITY_IOS || UNITY_IPHONE + const string DLL_PATH = "ZeroTierSDK_Unity3D_iOS"; + #endif + + // Windows + #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + const string DLL_PATH = "ZeroTierSDK_Unity3D_WIN"; + #endif + + // Linux + #if UNITY_STANDALONE_LINUX + const string DLL_PATH = "ZeroTierSDK_Unity3D_LINUX"; + #endif + + // Android + #if UNITY_ANDROID + const string DLL_PATH = "ZeroTierSDK_Unity3D_ANDROID"; + #endif + + // Interop structures + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)] + public struct sockaddr { + /// u_short->unsigned short + public ushort sa_family; + /// char[14] + [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=14)] + public string sa_data; + } + + // ZeroTier background thread + protected Thread ztThread; + protected List connections = new List (); + protected int MaxPacketSize; + protected string rpc_path = ""; + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void MyDelegate(string str); + + static void CallBackFunction(string str) { + Debug.Log("Native ZT Plugin: " + str); + } + +#region DLL Imports + // ZeroTier service / debug initialization + [DllImport (DLL_PATH)] + public static extern void SetDebugFunction( IntPtr fp ); + [DllImport (DLL_PATH)] + private static extern int unity_start_service(string path); + + // Connection calls + [DllImport (DLL_PATH)] + protected static extern int zt_socket(int family, int type, int protocol); + + [DllImport (DLL_PATH)] + unsafe protected static extern int zt_bind(int sockfd, System.IntPtr addr, int addrlen); + [DllImport (DLL_PATH)] + unsafe protected static extern int zt_connect(int sockfd, System.IntPtr addr, int addrlen); + + [DllImport (DLL_PATH)] + protected static extern int zt_accept(int sockfd); + [DllImport (DLL_PATH)] + protected static extern int zt_listen(int sockfd, int backlog); + [DllImport (DLL_PATH)] + protected static extern int zt_close(int sockfd); + + // RX / TX + [DllImport (DLL_PATH)] + unsafe protected static extern int zt_recv(int sockfd, IntPtr buf, int len); + [DllImport (DLL_PATH)] + unsafe protected static extern int zt_send(int sockfd, IntPtr buf, int len); + [DllImport (DLL_PATH)] + unsafe protected static extern int zt_set_nonblock(int sockfd); + + // ZT Thread controls + [DllImport (DLL_PATH)] + protected static extern bool zt_is_running(); + [DllImport (DLL_PATH)] + protected static extern void zt_terminate(); + + // ZT Network controls + [DllImport (DLL_PATH)] + protected static extern bool zt_join_network(string nwid); + [DllImport (DLL_PATH)] + protected static extern void zt_leave_network(string nwid); +#endregion + + // Thread which starts the ZeroTier service + // The ZeroTier service may spin off a SOCKS5 proxy server + // if -DUSE_SOCKS_PROXY is set when building the bundle + protected void zt_service_thread() + { + MyDelegate callback_delegate = new MyDelegate( CallBackFunction ); + // Convert callback_delegate into a function pointer that can be + // used in unmanaged code. + IntPtr intptr_delegate = + Marshal.GetFunctionPointerForDelegate(callback_delegate); + // Call the API passing along the function pointer. + SetDebugFunction( intptr_delegate ); + Debug.Log ("rpc_path = " + rpc_path); + unity_start_service (rpc_path); + } + + // Start the ZeroTier service + protected void Init() + { + // TODO: Handle exceptions from unmanaged code + ztThread = new Thread(() => { + try { + zt_service_thread(); + } catch(Exception e) { + Debug.Log(e.Message.ToString()); + } + }); + ztThread.IsBackground = true; // Allow the thread to be aborted safely + ztThread.Start(); + } + + // Initialize the ZeroTier service with a given path + public ZeroTierNetworkInterface(string path) + { + rpc_path = path; + Init(); + } + + // Initialize the ZeroTier service + public ZeroTierNetworkInterface() + { + Init(); + } + + // Initialize the ZeroTier service + // Use the GlobalConfig to set things like the max packet size + public ZeroTierNetworkInterface(GlobalConfig gConfig) + { + MaxPacketSize = gConfig.MaxPacketSize; // TODO: Do something with this! + Init(); + } + +#region Network Handling + // Joins a ZeroTier virtual network + public void JoinNetwork(string nwid) + { + zt_join_network(nwid); + } + + // Leaves a ZeroTier virtual network + public void LeaveNetwork(string nwid) + { + zt_leave_network(nwid); + } +#endregion + + // Low-level representations of ZeroTier sockets + // The ZeroTier LLAPI is built on top of these + + // Creates a new ZeroTier-administered socket + public int Socket(int family, int type, int protocol) + { + return zt_socket (family, type, protocol); + } + + // Binds to a specific address + public int Bind(int fd, string addr, int port) + { + GCHandle sockaddr_ptr = ZeroTierUtils.Generate_unmananged_sockaddr(addr + ":" + port); + IntPtr pSockAddr = sockaddr_ptr.AddrOfPinnedObject (); + int addrlen = Marshal.SizeOf (pSockAddr); + return zt_bind (fd, pSockAddr, addrlen); + } + + // Listens for an incoming connection request + public int Listen(int fd, int backlog) + { + return zt_listen(fd, backlog); + } + + // Accepts an incoming connection + public int Accept(int fd) + { + return zt_accept (fd); + } + + // Closes a connection + public int Close(int fd) + { + return Close (fd); + } + + // Connects to a remote host + public int Connect(int fd, string addr, int port) + { + GCHandle sockaddr_ptr = ZeroTierUtils.Generate_unmananged_sockaddr(addr + ":" + port); + IntPtr pSockAddr = sockaddr_ptr.AddrOfPinnedObject (); + int addrlen = Marshal.SizeOf (pSockAddr); + return zt_connect (fd, pSockAddr, addrlen); + } + + + /* + unsafe { + byte *ptr = (byte *)buffer.ToPointer(); + + int offset = 0; + for (int i=0; i. + * + * -- + * + * 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/ + */ + +using UnityEngine; +using System.Collections; +using System.Threading; +using System.Runtime.Serialization.Formatters.Binary; +using System.IO; +using UnityEngine.UI; +using UnityEngine.Networking; + +// Demonstrates the usage of bare-bones ZeroTier-administered sockets +using System.Net.Sockets; +using System.Runtime.InteropServices; +using System; + + +public class ZeroTierSockets_Demo : MonoBehaviour +{ + public float speed = 300f; + + private ZeroTierNetworkInterface zt; + string nwid = ""; + + int connection_socket; // The "connection id" + int host_socket; + + // Demo button methods + public void Join() + { + GameObject go = GameObject.Find ("inputNetworkID"); + InputField input = go.GetComponents () [0]; + Debug.Log ("Joining: " + input.text); + zt.JoinNetwork (input.text); + } + + public void Leave() + { + GameObject go = GameObject.Find ("inputNetworkID"); + InputField input = go.GetComponents () [0]; + Debug.Log ("Leaving: " + input.text); + zt.LeaveNetwork (input.text); + } + + // 1. Create ZeroTier-socket + // 2. Connect to remote host (on ZeroTier network) via socket + public void Connect() + { + GameObject addr_go = GameObject.Find ("inputServerAddress"); + GameObject port_go = GameObject.Find ("inputServerPort"); + InputField addr = addr_go.GetComponents () [0]; + InputField port = port_go.GetComponents () [0]; + Debug.Log ("Connecting to: " + addr.text + ":" + port.text); + + Thread connectThread = new Thread(() => { + + int sockfd = zt.Socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified); + Debug.Log ("sockfd = " + sockfd); + int port_num; + int.TryParse(port.text,out port_num); + zt.Connect (sockfd, addr.text,port_num); + Debug.Log ("connection_socket = " + connection_socket); + }); + connectThread.IsBackground = true; + connectThread.Start(); + } + + public void Bind() + { + GameObject addr_go = GameObject.Find ("inputServerAddress"); + GameObject port_go = GameObject.Find ("inputServerPort"); + InputField addr = addr_go.GetComponents () [0]; + InputField port = port_go.GetComponents () [0]; + Debug.Log ("Binding to: " + addr.text + ":" + port.text); + + Thread connectThread = new Thread(() => { + + // Socket() + int sockfd = zt.Socket ((int)AddressFamily.InterNetwork, (int)SocketType.Stream, (int)ProtocolType.Unspecified); + Debug.Log ("sockfd = " + sockfd); + + // Bind() + int port_num; + int.TryParse(port.text,out port_num); + int bind_res = zt.Bind(connection_socket, "0.0.0.0", port_num); + Debug.Log ("bind_res = " + bind_res); + + // Listen() + int listen_res = zt.Listen(connection_socket, 1); + Debug.Log ("listen_res = " + listen_res); + + // Accept() loop + Debug.Log("entering accept() loop"); + int accept_res = -1; + while(accept_res < 0) + { + //yield return new WaitForSeconds(1); + accept_res = zt.Accept(connection_socket); + Debug.Log ("accept_res = " + accept_res); + + } + }); + connectThread.IsBackground = true; + connectThread.Start(); + } + + public void Disconnect() + { + GameObject addr_go = GameObject.Find ("inputServerAddress"); + GameObject port_go = GameObject.Find ("inputServerAddress"); + InputField addr = addr_go.GetComponents () [0]; + InputField port = port_go.GetComponents () [0]; + Debug.Log ("Disconnecting from: " + addr.text + ":" + port.text); + Debug.Log ("Disconnect(): " + zt.Close (connection_socket)); + } + + public void SendMessage() + { + //zt_test_network (); + /* + GameObject go = GameObject.Find ("inputMessage"); + InputField msg = go.GetComponents () [0]; + + Thread sendThread = new Thread(() => { + Debug.Log ("Sending Message: " + msg.text); + byte error = 0; + zt.Send (server_connection_socket, msg.text.ToCharArray (), msg.text.ToCharArray ().Length, out error); + Debug.Log ("Send(): " + error); + }); + sendThread.IsBackground = true; + sendThread.Start(); + */ + } + + void Start() + { + // Set defaults + InputField input; + GameObject go; + go = GameObject.Find ("inputNetworkID"); + input = go.GetComponents () [0]; + input.text = "565799d8f6e1c11a"; + go = GameObject.Find ("inputServerAddress"); + input = go.GetComponents () [0]; + input.text = "172.22.211.245"; + go = GameObject.Find ("inputServerPort"); + input = go.GetComponents () [0]; + input.text = "8887"; + go = GameObject.Find ("inputMessage"); + input = go.GetComponents () [0]; + input.text = "Welcome to the machine"; + + // Create new instance of ZeroTier in separate thread + zt = new ZeroTierLLAPI ("/Users/Joseph/utest2/nc_565799d8f6e1c11a"); + + /* This new instance will communicate via a named pipe, so any + * API calls (ZeroTier.Connect(), ZeroTier.Send(), etc) will be sent to the service + * via this pipe. + */ + } + + // Terminate the ZeroTier service when the application quits + void OnApplicationQuit() { + Debug.Log ("OnApplicationQuit()"); + zt.Terminate (); + } + + // Update is called once per frame + void Update () { + /* + if (text) { + text.text = IsRunning() ? "ZeroTier Status: Online" : "ZeroTier Status: Offline"; + } + */ + + // --- + /* + int recHostId; + int connectionId; + int channelId; + byte[] recBuffer = new byte[1024]; + int bufferSize = 1024; + int dataSize; + byte error; + NetworkEventType recData = zt.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); + switch (recData) + { + case NetworkEventType.Nothing: + break; + case NetworkEventType.ConnectEvent: + Debug.Log("NetworkEventType.ConnectEvent"); + break; + case NetworkEventType.DataEvent: + Debug.Log("NetworkEventType.DataEvent"); + break; + case NetworkEventType.DisconnectEvent: + Debug.Log("NetworkEventType.DisconnectEvent"); + break; + } + */ + // --- + + /* + GameObject go = GameObject.Find ("_txtStatusIndicator"); + Text text = go.GetComponents () [0]; + text.text = zt.IsRunning () ? "ZeroTier Service: ONLINE" : "ZeroTier Service: OFFLINE"; + */ + + // Rotate ZTCube when ZT is running + /* + if (zt.IsRunning ()) { + + + go = GameObject.Find ("ZTCube"); + Vector3 rotvec = new Vector3 (10f, 10f, 10f); + go.transform.Rotate (rotvec, speed * Time.deltaTime); + } + GameObject go = GameObject.Find("ZTCube"); + Text text = go.GetComponents ()[0]; + */ + } +} \ No newline at end of file diff --git a/integrations/Unity3D/Assets/ZeroTierUtils.cs b/integrations/Unity3D/Assets/ZeroTierUtils.cs old mode 100644 new mode 100755 index a1da79d..033d646 --- a/integrations/Unity3D/Assets/ZeroTierUtils.cs +++ b/integrations/Unity3D/Assets/ZeroTierUtils.cs @@ -1,4 +1,31 @@ -using UnityEngine; +/* + * 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/ + */ + +using UnityEngine; using System.Collections; using System.Net; using System; diff --git a/integrations/Unity3D/Assets/smcs.rsp b/integrations/Unity3D/Assets/smcs.rsp old mode 100644 new mode 100755 diff --git a/tests/client.c b/tests/client.c index 490ff7b..e79a829 100644 --- a/tests/client.c +++ b/tests/client.c @@ -8,23 +8,24 @@ int main(int argc , char *argv[]) { - int sock; + if(argc < 3) { + printf("usage: client \n"); + return 1; + } + + int sock, port = atoi(argv[1]); struct sockaddr_in server; char message[1000] , server_reply[2000]; - //Create socket sock = socket(AF_INET , SOCK_STREAM , 0); - if (sock == -1) - { + if (sock == -1) { printf("Could not create socket"); - } - puts("Socket created"); - - server.sin_addr.s_addr = inet_addr("127.0.0.1"); + } + server.sin_addr.s_addr = inet_addr(argv[1]); server.sin_family = AF_INET; - server.sin_port = htons( 8888 ); + server.sin_port = htons( port ); - //Connect to remote server + printf("connecting...\n"); if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0) { perror("connect failed. Error"); @@ -33,7 +34,6 @@ int main(int argc , char *argv[]) puts("Connected\n"); - //keep communicating with server while(1) { printf("Enter message : ");