Flattened examples directory
This commit is contained in:
36
examples/scala/ExampleApp.scala
Normal file
36
examples/scala/ExampleApp.scala
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
import zerotier.ZeroTier
|
||||
|
||||
object ExampleApp extends App {
|
||||
// load libzt.dylib or libzt.so
|
||||
System.loadLibrary("zt")
|
||||
val libzt = new ZeroTier
|
||||
libzt.startjoin("/Users/joseph/op/zt/libzt/ztjni", 0xa09acf0232a930f7L)
|
||||
val fd = libzt.socket(2, 1, 0)
|
||||
println(s"libzt.socket(): $fd")
|
||||
}
|
||||
18
examples/scala/Makefile
Normal file
18
examples/scala/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
OSTYPE=$(shell uname -s | tr '[A-Z]' '[a-z]')
|
||||
BUILD=build/$(OSTYPE)
|
||||
|
||||
ifeq ($(OSTYPE),darwin)
|
||||
SHARED_LIB=libzt.dylib
|
||||
endif
|
||||
ifeq ($(OSTYPE),linux)
|
||||
SHARED_LIB=libzt.so
|
||||
endif
|
||||
|
||||
example_scala_app:
|
||||
scalac *.scala
|
||||
|
||||
copy_dynamic_lib:
|
||||
cp ../../../$(BUILD)/$(SHARED_LIB) .
|
||||
|
||||
clean:
|
||||
-find . -type f \( -name '*.class' \) -delete
|
||||
14
examples/scala/README.md
Normal file
14
examples/scala/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
## ZeroTier with Scala via JNI
|
||||
***
|
||||
|
||||
To get this example project to work, do the following:
|
||||
|
||||
- From libzt main directory, build shared library: `make shared_jni_lib`
|
||||
- Copy the resultant dynamic library (`*.so` or `*.dylib`) from `build/` to this current directory
|
||||
- Change to this directory and `make example_scala_app`
|
||||
- Run: `scala -Djava.library.path=$(pwd) -cp "." ExampleApp`
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
Upon execution, it will load the libzt dynamic library via the `loadLibrary` method and begin generating an identity.
|
||||
76
examples/scala/libzt.scala
Normal file
76
examples/scala/libzt.scala
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* ZeroTier SDK - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
package zerotier;
|
||||
|
||||
class ZeroTier {
|
||||
|
||||
// socket families
|
||||
// socket types
|
||||
// basic service controls
|
||||
@native def start(path: String, blocking: Boolean): Int
|
||||
@native def startjoin(path: String, nwid: Long): Int
|
||||
@native def stop(): Unit
|
||||
@native def running(): Int
|
||||
@native def join(nwid: Long): Unit
|
||||
@native def leave(nwid: Long): Unit
|
||||
// advanced service controls
|
||||
//@native def get_path(): Unit
|
||||
@native def get_node_id(): Long
|
||||
//@native def get_6plane_addr(): Unit
|
||||
//@native def get_rfc4193_addr(): Unit
|
||||
// socket API
|
||||
@native def socket(socket_family: Int, socket_type: Int, protocol: Int): Int
|
||||
@native def connect(fd: Int, addr: String, port: Int): Int
|
||||
@native def bind(fd: Int, addr: String, port: Int): Int
|
||||
@native def listen(fd: Int, backlog: Int): Int
|
||||
@native def accept(fd: Int, addr: Object, addrlen: Int): Int
|
||||
@native def accept4(fd: Int, addr: Object, addrlen: Int, flags: Int): Int
|
||||
@native def close(fd: Int): Int
|
||||
@native def setsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int
|
||||
@native def getsockopt(fd: Int, level: Int, optname: Int, optval: Object, optlen: Int): Int
|
||||
@native def read(fd: Int, buf: Object, len: Int): Int
|
||||
@native def write(fd: Int, buf: Object, len: Int): Int
|
||||
@native def send(fd: Int, buf: Object, len: Int, flags: Int): Int
|
||||
@native def sendto(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int
|
||||
@native def sendmsg(fd: Int, msg: Object, flags: Int): Int
|
||||
@native def recv(fd: Int, buf: Object, len: Int, flags: Int): Int
|
||||
@native def recvfrom(fd: Int, buf: Object, len: Int, addr: Object, addrlen: Int): Int
|
||||
@native def recvmsg(fd: Int, msg: Object, flags: Int): Int
|
||||
@native def shutdown(fd: Int, how: Int): Int
|
||||
//@native def getsockname(): Int
|
||||
//@native def getpeername(): Int
|
||||
//@native def gethostname(): Int
|
||||
//@native def sethostname(): Int
|
||||
//@native def gethostbyname(): Object
|
||||
//@native def poll(): Int
|
||||
//@native def select(): Int
|
||||
@native def fcntl(fd: Int, cmd: Int, flags: Int): Int
|
||||
@native def ioctl(fd: Int, request: Long, argp: Object): Int
|
||||
// stack controls
|
||||
//@native def add_dns(): Int
|
||||
//@native def del_dns(): Int
|
||||
}
|
||||
Reference in New Issue
Block a user