initial jni wrapper stuff

pull/869/head
jeff 5 years ago
parent 6dc350a8f3
commit 313898999d

@ -33,20 +33,16 @@ import android.widget.TextView;
public class LokiNetActivity extends Activity {
private static final String TAG = "lokinet-activity";
private TextView textView;
private static final String DefaultBootstrapURL = "https://i2p.rocks/bootstrap.signed";
private static final String DefaultBootstrapURL = "https://seed.lokinet.org/bootstrap.signed";
private AsyncBootstrap bootstrapper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// copy assets
//String conf = copyFileAsset("daemon.ini");
textView = new TextView(this);
setContentView(textView);
Lokinet_JNI.loadLibraries();
System.loadLibrary("lokinetandroid");
}

@ -5,4 +5,5 @@ import android.net.VpnService;
public class LokinetService extends VpnService
{
}

@ -1,44 +0,0 @@
package network.loki.lokinet;
public class Lokinet_JNI {
public static final String STATUS_OK = "ok";
public static native String getABICompiledWith();
/**
* returns error info if failed
* returns "ok" if daemon initialized and started okay
*/
public static native String startLokinet(String config);
/**
* stop daemon if running
*/
public static native void stopLokinet();
/** get interface address we want */
public static native String getIfAddr();
/** get interface address range we want */
public static native int getIfRange();
/**
* change network status
*/
public static native void onNetworkStateChanged(boolean isConnected);
/**
* set vpn network interface fd pair
* @param rfd the file descriptor of read end
* @param wfd the file descriptor of the write end
*/
public static native void setVPNFileDescriptor(int rfd, int wfd);
/**
* load jni libraries
*/
public static void loadLibraries() {
System.loadLibrary("lokinetandroid");
}
}

@ -39,10 +39,10 @@ struct AndroidMain
{
if(m_impl || m_thread)
return true;
m_impl = llarp_main_init(configFile.c_str(), true);
m_impl = llarp_main_default_init();
if(m_impl == nullptr)
return false;
if(llarp_main_setup(m_impl, false))
if(llarp_main_setup(m_impl))
{
llarp_main_free(m_impl);
m_impl = nullptr;
@ -63,7 +63,8 @@ struct AndroidMain
void
Run()
{
if(llarp_main_run(m_impl))
llarp_main_runtime_opts opts;
if(llarp_main_run(m_impl, opts))
{
// on error
llarp::LogError("daemon run fail");
@ -74,50 +75,6 @@ struct AndroidMain
}
}
const char*
GetIfAddr()
{
std::string addr;
if(m_impl)
{
auto* ctx = llarp_main_get_context(m_impl);
if(!ctx)
return "";
ctx->router->hiddenServiceContext().ForEachService(
[&addr](const std::string&,
const llarp::service::Endpoint_ptr& ep) -> bool {
if(addr.empty())
{
if(ep->HasIfAddr())
{
// TODO: v4
const auto ip = ep->GetIfAddr();
if(ip.h)
{
addr = ip.ToString();
return false;
}
}
}
return true;
});
}
return addr.c_str();
}
int
GetIfRange() const
{
if(m_impl)
{
auto* ctx = llarp_main_get_context(m_impl);
if(!ctx)
return -1;
}
return -1;
}
void
SetVPN_FD(int rfd, int wfd)
{
@ -200,19 +157,13 @@ extern "C"
JNIEXPORT jstring JNICALL
Java_network_loki_lokinet_Lokinet_1JNI_getIfAddr(JNIEnv* env, jclass)
{
if(daemon_ptr)
return env->NewStringUTF(daemon_ptr->GetIfAddr());
else
return env->NewStringUTF("");
return env->NewStringUTF("");
}
JNIEXPORT jint JNICALL
Java_network_loki_lokinet_Lokinet_1JNI_getIfRange(JNIEnv*, jclass)
{
if(daemon_ptr)
return daemon_ptr->GetIfRange();
else
return -1;
return -1;
}
JNIEXPORT void JNICALL

Loading…
Cancel
Save