Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes for i2pd for android #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
# CMAKE_ANDROID_STANDALONE_TOOLCHAIN (and likely other cross compilation
# android variables) was only introduced in v3.7
cmake_minimum_required (VERSION 3.7)
add_definitions(-DANDROID) # for i2pd
else()
cmake_minimum_required (VERSION 3.5)
endif()
Expand Down Expand Up @@ -39,23 +40,10 @@ add_definitions(-DBOOST_COROUTINE_NO_DEPRECATION_WARNING)
# https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/using.html#boost_asio.using.optional_separate_compilation
add_definitions(-DBOOST_ASIO_SEPARATE_COMPILATION)

################################################################################

set(GOROOT "${CMAKE_BINARY_DIR}/golang")
externalproject_add(golang
URL https://dl.google.com/go/go1.11.2.linux-amd64.tar.gz
URL_MD5 5630231012b6d02b821af51f04c2776c
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
SOURCE_DIR ${GOROOT}
)

################################################################################
option(ASIO_IPFS_WITH_EXAMPLE_BINARIES "" OFF)

add_subdirectory(./modules/asio-ipfs)
add_subdirectory(./modules/obfs4proxy)
add_subdirectory(./src/ouiservice/i2p)

################################################################################
Expand Down Expand Up @@ -162,12 +150,8 @@ file(GLOB client_sources
"./src/ouiservice.cpp"
"./src/ssl/ca_certificate.cpp"
"./src/ssl/dummy_certificate.cpp"
"./src/ouiservice/pt-obfs2.cpp"
"./src/ouiservice/pt-obfs3.cpp"
"./src/ouiservice/pt-obfs4.cpp"
"./src/ouiservice/tcp.cpp"
"./src/ouiservice/tls.cpp"
"./src/ouiservice/pluggable-transports/*.cpp"
"./src/logger.cpp"
"./src/cache/*.cpp"
"./src/bittorrent/*.cpp"
Expand Down Expand Up @@ -214,12 +198,8 @@ if (WITH_INJECTOR)
"./src/connect_to_host.cpp"
"./src/cache_control.cpp"
"./src/ouiservice.cpp"
"./src/ouiservice/pt-obfs2.cpp"
"./src/ouiservice/pt-obfs3.cpp"
"./src/ouiservice/pt-obfs4.cpp"
"./src/ouiservice/tcp.cpp"
"./src/ouiservice/tls.cpp"
"./src/ouiservice/pluggable-transports/*.cpp"
"./src/ssl/ca_certificate.cpp"
"./src/logger.cpp"
"./src/cache/*.cpp"
Expand Down
2 changes: 2 additions & 0 deletions android/browser/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
</manifest>
2 changes: 0 additions & 2 deletions android/ouinet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ android {
sourceSets {
main {
jniLibs.srcDirs = ["$libdir"]
assets.srcDirs = ["$assetsdir"]
}

}
buildTypes {
release {
Expand Down
48 changes: 4 additions & 44 deletions android/ouinet/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <condition_variable>

#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

#include "debug.h"
Expand All @@ -36,40 +35,13 @@ ouinet::asio::io_service g_ios;
thread g_client_thread;
bool g_crypto_initialized = false;

void start_client_thread(const vector<string>& args, const vector<string>& extra_path)
void start_client_thread(const vector<string>& args)
{
if (g_crypto_initialized) {
ouinet::util::crypto_init();
g_crypto_initialized = true;
}

char* old_path_c = getenv("PATH");
if (old_path_c) {
std::string old_path(old_path_c);
std::set<std::string> old_path_entries;
size_t index = 0;
while (true) {
size_t pos = old_path.find(':', index);
if (pos == std::string::npos) {
old_path_entries.insert(old_path.substr(index));
break;
} else {
old_path_entries.insert(old_path.substr(index, pos - index));
index = pos;
}
}

std::string new_path;
for (size_t i = 0; i < extra_path.size(); i++) {
if (!old_path_entries.count(extra_path[i])) {
new_path += extra_path[i];
new_path += ":";
}
}
new_path += old_path;
setenv("PATH", new_path.c_str(), 1);
}

if (g_client_thread.get_id() != thread::id()) return;

g_client_thread = thread([=] {
Expand Down Expand Up @@ -112,10 +84,10 @@ JNIEXPORT void JNICALL
Java_ie_equalit_ouinet_Ouinet_nStartClient(
JNIEnv* env,
jobject /* this */,
jobjectArray jargs,
jobjectArray jpath)
jobjectArray jargs)
{
size_t argn = env->GetArrayLength(jargs);

vector<string> args;
args.reserve(argn);

Expand All @@ -126,19 +98,7 @@ Java_ie_equalit_ouinet_Ouinet_nStartClient(
env->ReleaseStringUTFChars(jstr, arg);
}


size_t pathn = env->GetArrayLength(jpath);
vector<string> path;
path.reserve(pathn);

for (size_t i = 0; i < pathn; ++i) {
jstring jstr = (jstring) env->GetObjectArrayElement(jpath, i);
const char* dir = env->GetStringUTFChars(jstr, 0);
path.push_back(dir);
env->ReleaseStringUTFChars(jstr, dir);
}

start_client_thread(args, path);
start_client_thread(args);
}

extern "C"
Expand Down
67 changes: 28 additions & 39 deletions android/ouinet/src/main/java/ie/equalit/ouinet/Ouinet.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Ouinet {
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "8080");
}
private static final String TAG = "Ouinet";

private Context _ctx;
private WifiManager.MulticastLock _lock = null;

Expand All @@ -41,9 +41,7 @@ public static class Config {
public Ouinet(Context ctx, Config conf) {
_ctx = ctx;

List<String> args = new ArrayList<String>();
List<String> path = new ArrayList<String>();

Vector<String> args = new Vector<String>();

new File(dir()).mkdirs();

Expand All @@ -52,13 +50,14 @@ public Ouinet(Context ctx, Config conf) {
// repository and fails if this conf file isn't there.
new File(dir() + "/ouinet-client.conf").createNewFile();
} catch (IOException e) {
Log.d(TAG, "Exception thrown while creating ouinet config file: ", e);
Log.d("Ouinet",
"Exception thrown while creating ouinet config file: " + e);
}

args.add("ouinet-client"); // App name
args.add("--repo=" + dir());
args.add("--listen-on-tcp=127.0.0.1:8080");
args.add("--front-end-ep=0.0.0.0:8081");
args.addElement("ouinet-client"); // App name
args.addElement("--repo=" + dir());
args.addElement("--listen-on-tcp=127.0.0.1:8080");
args.addElement("--front-end-ep=0.0.0.0:8081");

maybeAdd(args, "--injector-ep", conf.injector_endpoint);
maybeAdd(args, "--injector-credentials", conf.injector_credentials);
Expand All @@ -77,7 +76,7 @@ public Ouinet(Context ctx, Config conf) {
String asset = conf.tls_ca_cert_store_path.substring(assetPrefix.length());
ca_cert_path = dir() + "/assets/" + asset;

if (copyAssetToFile(asset, ca_cert_path)) {
if (copyAssetToFile(ctx, asset, ca_cert_path)) {
maybeAdd(args, "--tls-ca-cert-store-path", ca_cert_path);
}
}
Expand All @@ -90,57 +89,40 @@ public Ouinet(Context ctx, Config conf) {
if (conf.injector_tls_cert != null) {
String cert_path = dir() + "/injector-tls-cert.pem";
writeToFile(cert_path, conf.injector_tls_cert.getBytes());
args.add("--injector-tls-cert-file=" + cert_path);
args.addElement("--injector-tls-cert-file=" + cert_path);
}
} catch (IOException e) {
Log.d(TAG, "Exception thrown while creating injector's cert file: ", e);
}

String objfs4proxy_path = dir() + "/objfs4proxy";
if (copyExecutableToFile("obfs4proxy", objfs4proxy_path)) {
Log.d(TAG, "objfs4proxy copied to " + objfs4proxy_path);
path.add(dir());
} else {
Log.d(TAG, "objfs4proxy not copied");
Log.d("Ouinet",
"Exception thrown while creating injector's cert file: " + e);
e.printStackTrace();
}

nStartClient(args.toArray(new String[0]), path.toArray(new String[0]));
nStartClient(listToArray(args));
}

public String pathToCARootCert()
{
return nPathToCARootCert();
}

public boolean copyAssetToFile(String asset, String path)
public boolean copyAssetToFile(Context ctx, String asset, String path)
{
try {
java.io.InputStream stream = _ctx.getAssets().open(asset);
java.io.InputStream stream = ctx.getAssets().open(asset);
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
writeToFile(path, buffer);
} catch (IOException e) {
Log.d(TAG, "Failed to write asset \"" + asset + "\" to file \"" + path + "\"", e);
Log.d("Ouinet", "Failed to write asset \"" + asset + "\" to file \"" + path + "\"");
e.printStackTrace();
return false;
}

return true;
}

public boolean copyExecutableToFile(String asset, String path) {
if (!copyAssetToFile(asset, path)) {
return false;
}
File executable = new File(path);
if (!executable.setExecutable(true)) {
Log.d(TAG, "Failed to set executable for file: " + path);
return false;
}
return true;
}

// If this succeeds, we should be able to do UDP multicasts
// from inside ouinet (currently know to be needed by IPFS' mDNS
// but that's not essential for WAN).
Expand Down Expand Up @@ -188,9 +170,16 @@ public void setCredentialsFor(String injector, String credentials) {
}

//----------------------------------------------------------------
private void maybeAdd(List<String> args, String key, String value) {
private String[] listToArray(List<String> list) {
String[] ret = new String[list.size()];
int i = 0;
for (String s : list) { ret[i] = s; i += 1; }
return ret;
}

private void maybeAdd(Vector<String> args, String key, String value) {
if (value == null || value.isEmpty()) return;
args.add(key + "=" + value);
args.addElement(key + "=" + value);
}

private void writeToFile(String path, byte[] bytes) throws IOException {
Expand All @@ -217,7 +206,7 @@ private String dir() {
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
private native void nStartClient(String[] args, String[] path);
private native void nStartClient(String[] args);

private native void nStopClient();
private native void nSetInjectorEP(String endpoint);
Expand Down
2 changes: 1 addition & 1 deletion modules/asio-ipfs
62 changes: 0 additions & 62 deletions modules/obfs4proxy/CMakeLists.txt

This file was deleted.

Loading