Updated example Android project and JNI layer
This commit is contained in:
@@ -56,8 +56,8 @@ public class ZeroTier {
|
|||||||
public native boolean get_address_at_index(long nwid, int index, ZTSocketAddress addr);
|
public native boolean get_address_at_index(long nwid, int index, ZTSocketAddress addr);
|
||||||
public native boolean has_address(long nwid);
|
public native boolean has_address(long nwid);
|
||||||
public native boolean get_address(long nwid, int address_family, ZTSocketAddress addr);
|
public native boolean get_address(long nwid, int address_family, ZTSocketAddress addr);
|
||||||
public native void get_6plane_addr();
|
public native void get_6plane_addr(long nwid, long nodeId, ZTSocketAddress addr);
|
||||||
public native void get_rfc4193_addr();
|
public native void get_rfc4193_addr(long nwid, long nodeId, ZTSocketAddress addr);
|
||||||
|
|
||||||
public native int socket(int family, int type, int protocol);
|
public native int socket(int family, int type, int protocol);
|
||||||
public native int connect(int fd, ZTSocketAddress addr);
|
public native int connect(int fd, ZTSocketAddress addr);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
final String path = getApplicationContext().getFilesDir() + "/zerotier";
|
final String path = getApplicationContext().getFilesDir() + "/zerotier";
|
||||||
long nwid = 0xac9afb026544b071L;
|
long nwid = 0xac9afb023544b071L;
|
||||||
|
|
||||||
// Test modes
|
// Test modes
|
||||||
boolean blocking_start_call = true;
|
boolean blocking_start_call = true;
|
||||||
@@ -50,7 +50,24 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (blocking_start_call) {
|
if (blocking_start_call) {
|
||||||
libzt.startjoin(path, nwid);
|
libzt.startjoin(path, nwid);
|
||||||
}
|
}
|
||||||
System.out.println("Complete");
|
System.out.println("ZT service ready.");
|
||||||
|
|
||||||
|
// Device/Node address info
|
||||||
|
System.out.println("path=" + libzt.get_path());
|
||||||
|
long nodeId = libzt.get_node_id();
|
||||||
|
System.out.println("nodeId=" + Long.toHexString(nodeId));
|
||||||
|
int numAddresses = libzt.get_num_assigned_addresses(nwid);
|
||||||
|
System.out.println("this node has (" + numAddresses + ") assigned addresses on network " + Long.toHexString(nwid));
|
||||||
|
for (int i=0; i<numAddresses; i++) {
|
||||||
|
libzt.get_address_at_index(nwid, i, sockname);
|
||||||
|
//System.out.println("address[" + i + "] = " + sockname.toString()); // ip:port
|
||||||
|
System.out.println("address[" + i + "] = " + sockname.toCIDR());
|
||||||
|
}
|
||||||
|
|
||||||
|
libzt.get_6plane_addr(nwid, nodeId, sockname);
|
||||||
|
System.out.println("6PLANE address = " + sockname.toCIDR());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ExampleApp {
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
String path = "/Users/joseph/op/zt/libzt/ztjni"; // Where node's config files are stored
|
String path = "/Users/joseph/op/zt/libzt/ztjni"; // Where node's config files are stored
|
||||||
long nwid = 0xf0b9acf0833f4b071L;
|
long nwid = 0xa09acf0233e4b070L;
|
||||||
|
|
||||||
// Test modes
|
// Test modes
|
||||||
boolean blocking_start_call = true;
|
boolean blocking_start_call = true;
|
||||||
@@ -105,18 +105,20 @@ public class ExampleApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("ZT service ready.");
|
System.out.println("ZT service ready.");
|
||||||
|
// Device/Node address info
|
||||||
// Device/Node address info
|
System.out.println("path=" + libzt.get_path());
|
||||||
System.out.println("path=" + libzt.get_path());
|
long nodeId = libzt.get_node_id();
|
||||||
System.out.println("nodeId=" + Long.toHexString(libzt.get_node_id()));
|
System.out.println("nodeId=" + Long.toHexString(nodeId));
|
||||||
int numAddresses = libzt.get_num_assigned_addresses(nwid);
|
int numAddresses = libzt.get_num_assigned_addresses(nwid);
|
||||||
System.out.println("this node has (" + numAddresses + ") assigned addresses on network " + Long.toHexString(nwid));
|
System.out.println("this node has (" + numAddresses + ") assigned addresses on network " + Long.toHexString(nwid));
|
||||||
for (int i=0; i<numAddresses; i++) {
|
for (int i=0; i<numAddresses; i++) {
|
||||||
libzt.get_address_at_index(nwid, i, sockname);
|
libzt.get_address_at_index(nwid, i, sockname);
|
||||||
//System.out.println("address[" + i + "] = " + sockname.toString()); // ip:port
|
//System.out.println("address[" + i + "] = " + sockname.toString()); // ip:port
|
||||||
System.out.println("address[" + i + "] = " + sockname.toCIDR());
|
System.out.println("address[" + i + "] = " + sockname.toCIDR());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
libzt.get_6plane_addr(nwid, nodeId, sockname);
|
||||||
|
System.out.println("6PLANE address = " + sockname.toCIDR());
|
||||||
|
|
||||||
// Idle loop test
|
// Idle loop test
|
||||||
while(idle) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } }
|
while(idle) { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } }
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ public class ZeroTier {
|
|||||||
public native boolean get_address_at_index(long nwid, int index, ZTSocketAddress addr);
|
public native boolean get_address_at_index(long nwid, int index, ZTSocketAddress addr);
|
||||||
public native boolean has_address(long nwid);
|
public native boolean has_address(long nwid);
|
||||||
public native boolean get_address(long nwid, int address_family, ZTSocketAddress addr);
|
public native boolean get_address(long nwid, int address_family, ZTSocketAddress addr);
|
||||||
public native void get_6plane_addr();
|
public native void get_6plane_addr(long nwid, long nodeId, ZTSocketAddress addr);
|
||||||
public native void get_rfc4193_addr();
|
public native void get_rfc4193_addr(long nwid, long nodeId, ZTSocketAddress addr);
|
||||||
|
|
||||||
public native int socket(int family, int type, int protocol);
|
public native int socket(int family, int type, int protocol);
|
||||||
public native int connect(int fd, ZTSocketAddress addr);
|
public native int connect(int fd, ZTSocketAddress addr);
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ namespace ZeroTier {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_get_6plane_addr(
|
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_get_16plane_1addr(
|
||||||
JNIEnv *env, jobject thisObj, jlong nwid, jlong nodeId, jobject addr)
|
JNIEnv *env, jobject thisObj, jlong nwid, jlong nodeId, jobject addr)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
@@ -160,7 +160,7 @@ namespace ZeroTier {
|
|||||||
ss2zta(env, &ss, addr);
|
ss2zta(env, &ss, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_get_rfc4193_addr(
|
JNIEXPORT void JNICALL Java_zerotier_ZeroTier_get_1rfc4193_1addr(
|
||||||
JNIEnv *env, jobject thisObj, jlong nwid, jlong nodeId, jobject addr)
|
JNIEnv *env, jobject thisObj, jlong nwid, jlong nodeId, jobject addr)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage ss;
|
struct sockaddr_storage ss;
|
||||||
@@ -168,7 +168,7 @@ namespace ZeroTier {
|
|||||||
ss2zta(env, &ss, addr);
|
ss2zta(env, &ss, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL Java_zerotier_ZeroTier_get_peer_count(
|
JNIEXPORT jlong JNICALL Java_zerotier_ZeroTier_get_1peer_1count(
|
||||||
JNIEnv *env, jobject thisObj)
|
JNIEnv *env, jobject thisObj)
|
||||||
{
|
{
|
||||||
return zts_get_peer_count();
|
return zts_get_peer_count();
|
||||||
|
|||||||
Reference in New Issue
Block a user