partial implementation of android direct-call API -- still has path problems
This commit is contained in:
@@ -1,8 +1,36 @@
|
||||
package ZeroTier;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
public class SDK {
|
||||
|
||||
// Socket families
|
||||
public int AF_UNIX = 1;
|
||||
public int AF_INET = 2;
|
||||
|
||||
// Socket types
|
||||
public int SOCK_STREAM = 1;
|
||||
public int SOCK_DGRAM = 2;
|
||||
|
||||
// Loads JNI code
|
||||
static { System.loadLibrary("ZeroTierOneJNI"); }
|
||||
|
||||
// ZeroTier service controls
|
||||
public native void startOneService(String homeDir);
|
||||
public native void joinNetwork(String nwid);
|
||||
public native void leaveNetwork(String nwid);
|
||||
public native boolean isRunning();
|
||||
static { System.loadLibrary("ZeroTierOneJNI"); } // Loads JNI code
|
||||
|
||||
// Direct-call API
|
||||
// --- These calls skip the intercept and interface directly via the RPC mechanism ---
|
||||
public native int ztjniSocket(int family, int type, int protocol);
|
||||
public native int ztjniConnect(int fd, String addr, int port);
|
||||
public native int ztjniBind(int fd, String addr, int port);
|
||||
public native int ztjniAccept4(int fd, String addr, int port);
|
||||
public native int ztjniAccept(int fd, String addr, int port, int flags);
|
||||
public native int ztjniListen(int fd, int backlog);
|
||||
//public native int ztjniGetsockopt(int fd, int type, int protocol);
|
||||
//public native int ztjniSetsockopt(int fd, int type, int protocol);
|
||||
//public native int ztjniGetsockname(int fd, int type, int protocol);
|
||||
public native int ztjniClose(int fd);
|
||||
}
|
||||
@@ -2,12 +2,14 @@ package com.example.joseph.example_app;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import ZeroTier.SDK;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.*;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
|
||||
import ZeroTier.SDK;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@@ -16,28 +18,64 @@ public class MainActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
final SDK wrapper = new SDK();
|
||||
final String homeDir = "sdcard/zerotier";
|
||||
final SDK zt = new SDK();
|
||||
final String homeDir = getApplicationContext().getFilesDir() + "/zerotier";
|
||||
|
||||
// Service thread
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
wrapper.startOneService(homeDir); // Calls to JNI code
|
||||
// Calls to JNI code
|
||||
zt.startOneService(homeDir);
|
||||
}
|
||||
}).start();
|
||||
|
||||
// Wait for service before joining network
|
||||
Log.d("SDK-Javaland", "Waiting for service to start...\n");
|
||||
while(!wrapper.isRunning()) {
|
||||
Log.d("SDK-Javaland", "Waiting...\n");
|
||||
Log.d("SDK", "Starting service...\n");
|
||||
while(!zt.isRunning()) { }
|
||||
Log.d("SDK","Joining network...\n");
|
||||
zt.joinNetwork("565799d8f65063e5");
|
||||
|
||||
/*
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//Do something after 100ms
|
||||
}
|
||||
}, 10000);
|
||||
*/
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
Log.d("SDK-Javaland","Joining network...\n");
|
||||
wrapper.joinNetwork("565799d8f65063e5");
|
||||
catch(java.lang.InterruptedException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create ZeroTier socket
|
||||
Log.d("","ztjniSocket()\n");
|
||||
int sock = zt.ztjniSocket(zt.AF_INET, zt.SOCK_STREAM, 0);
|
||||
Log.d("", "ztjniSocket() = " + sock + "\n");
|
||||
|
||||
|
||||
// Construct remote host address
|
||||
//InetAddress addr = InetAddress.getByName("10.144.211.245");
|
||||
//int port = 8080;
|
||||
//SocketAddress sockaddr = new InetSocketAddress(addr, port);
|
||||
|
||||
// Connect to remote host
|
||||
//Log.d("","ztjniConnect()\n");
|
||||
//int err = zt.ztjniConnect(sock, "10.144.211.245", 8080);
|
||||
//Log.d("", "ztjniConnect() = " + err + "\n");
|
||||
|
||||
// Set up example proxy connection to SDK proxy server
|
||||
/*
|
||||
Log.d("ZTSDK-InJavaland", "Setting up connection to SDK proxy server");
|
||||
Socket s = new Socket();
|
||||
SocketAddress proxyAddr = new InetSocketAddress("0.0.0.0", 1337);
|
||||
Proxy proxy = new Proxy(Proxy.Type.SOCKS, proxyAddr);
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
org.gradle.daemon=true
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
|
||||
Reference in New Issue
Block a user