osx demo app tweaks

This commit is contained in:
Joseph Henry
2016-07-06 14:09:33 -05:00
parent 9768ba98c2
commit 6a17e0f9d5
9 changed files with 137 additions and 20 deletions

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "489521728.968073"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "74"
endingLineNumber = "74"
landmarkName = "UI_Connect(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View File

@@ -767,6 +767,9 @@
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="txtAddrChanged:" target="XfG-lQ-9wD" id="vpp-Wo-rj8"/>
</connections>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="imQ-Xu-9iD">
<rect key="frame" x="175" y="44" width="50" height="22"/>
@@ -775,6 +778,9 @@
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<action selector="txtPortChanged:" target="XfG-lQ-9wD" id="3zi-Z0-7cx"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ORq-6n-fZV">
<rect key="frame" x="9" y="24" width="104" height="17"/>
@@ -950,6 +956,7 @@
<outlet property="txtAddr" destination="imQ-Xu-9iD" id="FQu-fG-Pg2"/>
<outlet property="txtNWID" destination="7LM-Q0-D7l" id="3QF-tw-Hws"/>
<outlet property="txtPort" destination="imQ-Xu-9iD" id="UrQ-84-slh"/>
<outlet property="txtPortChanged" destination="imQ-Xu-9iD" id="NqB-2s-Og3"/>
<outlet property="txtR" destination="f93-eE-nJ9" id="Sbh-vb-Ycb"/>
<outlet property="txtRX" destination="f93-eE-nJ9" id="aTL-JM-evI"/>
<outlet property="txtRx" destination="f93-eE-nJ9" id="yPZ-sv-Ctq"/>

View File

@@ -19,15 +19,16 @@ void zt_leave_network(const char *nwid);
// Direct Call ZT API
// These functions will provide direct access to ZT-enabled sockets with no hassle
int zts_init_rpc(const char *path, const char *nwid);
int zts_connect(CONNECT_SIG);
int zt_bind(BIND_SIG);
int zt_accept(ACCEPT_SIG);
int zt_listen(LISTEN_SIG);
int zts_bind(BIND_SIG);
int zts_accept(ACCEPT_SIG);
int zts_listen(LISTEN_SIG);
int zts_socket(SOCKET_SIG);
int zt_setsockopt(SETSOCKOPT_SIG);
int zt_getsockopt(GETSOCKOPT_SIG);
int zt_close(CLOSE_SIG);
int zt_getsockname(GETSOCKNAME_SIG);
int zts_setsockopt(SETSOCKOPT_SIG);
int zts_getsockopt(GETSOCKOPT_SIG);
int zts_close(CLOSE_SIG);
int zts_getsockname(GETSOCKNAME_SIG);
#endif /* Example_OSX_Bridging_Header_h */

View File

@@ -23,30 +23,108 @@ class ViewController: NSViewController {
@IBOutlet weak var txtRX: NSScrollView!
@IBOutlet weak var btnSend: NSButton!
var serverPort:Int32 = 4545
var serverAddr:String = "10.147.18.5"
@IBAction func txtAddrChanged(sender: AnyObject) {
if(sender.value != nil) {
serverAddr = sender.value
}
}
@IBAction func txtPortChanged(sender: AnyObject) {
serverPort = sender.intValue!
}
// Join a ZeroTier network
@IBAction func UI_JoinNetwork(sender: AnyObject) {
zt_join_network(txtNWID.stringValue);
}
// Leave a ZeroTier network
@IBAction func UI_LeaveNetwork(sender: AnyObject) {
zt_leave_network(txtNWID.stringValue);
}
// Select an API
var selectedShim:Int32 = 0
@IBAction func UI_SelectAPI(sender: AnyObject) {
selectedShim = sender.intValue // 0 = BSD-style, 1 = SOCKS5 Proxy, etc
}
// Select a protocol
// Protocol { TCP / UDP }
var selectedProtocol:Int32 = 0
@IBAction func UI_SelectProtocol(sender: AnyObject) {
}
switch sender.intValue
{
case 0:
print("Selected TCP (SOCK_STREAM)\n");
selectedProtocol = SOCK_STREAM
case 1:
print("Selected UDP (SOCK_DGRAM)\n");
selectedProtocol = SOCK_DGRAM
default:
break;
} }
// Connect to remote host on ZeroTier virtual network
@IBAction func UI_Connect(sender: AnyObject) {
// TCP
if(selectedProtocol == SOCK_STREAM)
{
let sd = zts_socket(AF_INET, SOCK_STREAM, 0)
var addr = sockaddr_in(sin_len: UInt8(sizeof(sockaddr_in)),
sin_family: UInt8(AF_INET),
sin_port: UInt16(serverPort).bigEndian,
sin_addr: in_addr(s_addr: 0),
sin_zero: (0,0,0,0,0,0,0,0))
inet_pton(AF_INET, serverAddr, &(addr.sin_addr));
let connect_fd = zts_connect(sd, UnsafePointer<sockaddr>([addr]), UInt32(addr.sin_len))
print("connect_fd = \(connect_fd),\(errno)")
if connect_fd < 0 {
let err = errno
print("Error connecting IPv4 socket \(err)")
return
}
}
// UDP
if(selectedProtocol == SOCK_DGRAM)
{
}
}
@IBAction func UI_Bind(sender: AnyObject) {
}
@IBAction func UI_SendData(sender: AnyObject) {
}
/*
// Mode { Client / Server }
@IBOutlet weak var ModeControl: UISegmentedControl!
var selectedMode:UInt16 = 0
@IBAction func ModeControlSelected(sender: AnyObject) {
switch sender.selectedSegmentIndex
{
case 0:
print("Selected client\n");
selectedMode = 0
case 1:
print("Selected server\n");
selectedMode = 1
default:
break;
}
}
*/
var service_thread : NSThread!
@@ -67,7 +145,9 @@ class ViewController: NSViewController {
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
self.service_thread.start()
});
// Do any additional setup after loading the view.
// Set RPC path for this thread
zts_init_rpc("/Users/Joseph/utest3/nc_","e5cd7a9e1c2e194f");
}
override var representedObject: AnyObject? {