Skip to content
Snippets Groups Projects
Commit 86c8cfb2 authored by cyberta's avatar cyberta
Browse files

Merge branch 'use-cache-dir' into 'main'

use cache-dir for arti storage

See merge request tpo/core/onionmasq!13
parents a8521400 bf027da0
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ mod runtime;
mod socket;
mod tuntap;
use arti_client::{TorClient, TorClientConfig};
use arti_client::TorClient;
use device::VirtualDevice;
use dns::{DnsManager, LockedDnsCookies};
use futures::future::Either;
......@@ -30,7 +30,9 @@ use std::{
use crate::tuntap::AsyncTunTapInterface;
use crate::{parser::Parser, socket::TcpSocket};
const ASYNC_DEVICE_BUFFER_SIZE: usize = 6000; // 1500 × 4
pub use arti_client::{config::TorClientConfigBuilder, TorClientConfig};
const ASYNC_DEVICE_BUFFER_SIZE: usize = 1500 * 4;
pub type IFace =
Arc<Mutex<Interface<'static, VirtualDevice<AsyncDevice<ASYNC_DEVICE_BUFFER_SIZE>>>>>;
......@@ -44,7 +46,11 @@ pub struct OnionTunnel {
}
impl OnionTunnel {
pub async fn create_with_fd(iface_name: &str, fd: i32) -> Result<Self, Error> {
pub async fn create_with_fd(
iface_name: &str,
fd: i32,
arti_config: TorClientConfig,
) -> Result<Self, Error> {
debug!("OnionTunnel create_with_fd {}", &iface_name);
let (adev, pollable_adev) = match AsyncTunTapInterface::new_from_fd(fd) {
Ok(v) => {
......@@ -60,9 +66,8 @@ impl OnionTunnel {
let device = VirtualDevice::new(adev);
let config = TorClientConfig::default();
let rt = OnionTunnelArtiRuntime::new().await;
let arti_builder = TorClient::with_runtime(rt).config(config);
let arti_builder = TorClient::with_runtime(rt).config(arti_config);
let arti = arti_builder.create_unbootstrapped().unwrap();
// routes should already be configured
......@@ -79,7 +84,7 @@ impl OnionTunnel {
})
}
pub async fn new(iface_name: &str) -> Self {
pub async fn new(iface_name: &str, arti_config: TorClientConfig) -> Self {
let tun =
AsyncTunTapInterface::new(iface_name, Medium::Ip).expect("Unable to create TUN iface");
// FIXME(eta): MTU?
......@@ -96,9 +101,8 @@ impl OnionTunnel {
.routes(routes)
.any_ip(true);
let config = TorClientConfig::default();
let rt = OnionTunnelArtiRuntime::new().await;
let arti_builder = TorClient::with_runtime(rt).config(config);
let arti_builder = TorClient::with_runtime(rt).config(arti_config);
let arti = arti_builder.create_unbootstrapped().unwrap();
let iface = iface_builder.finalize();
......
......@@ -13,6 +13,7 @@ tokio = { version = "1", features = ["macros", "rt", "rt-multi-thread"] }
rusqlite = { version = "0.27.0", features = ["bundled"] }
async-std = { version = "1.2", features = ["attributes"] }
openssl = { version = "0.10", features = ["vendored"] }
log = "0.4"
# dependancies specific to Android
[target.'cfg(target_os = "android")'.dependencies]
......@@ -22,7 +23,6 @@ rusqlite = { version = "0.27.0", features = ["bundled"] }
# android logging
android_logger = "0.11"
log = "0.4"
# dependancy to help implementing lockf, for android < 7.0
......@@ -32,4 +32,4 @@ libc = "0.2.112"
[lib]
name = "onionmasq_mobile"
# dylib is for Android
crate-type = ["dylib"]
\ No newline at end of file
crate-type = ["dylib"]
#![allow(non_snake_case)]
#[cfg(target_os = "android")]
use android_logger::Config;
#[cfg(target_os = "android")]
use jni::objects::{JClass, JString};
#[cfg(target_os = "android")]
use jni::JNIEnv;
use log::debug;
use log::Level;
use onion_tunnel::OnionTunnel;
#[cfg(target_os = "android")]
#[no_mangle]
pub extern "C" fn Java_org_torproject_OnionMasq_runProxy(
env: JNIEnv,
_: JClass,
fd: i32,
interface_name: JString,
_cache_dir: JString,
cache_dir: JString,
) {
//TODO: pass cacheDir to arti
debug!("Onionmasq_runProxy");
let rt = tokio::runtime::Runtime::new().expect("failed to create tokio runtime");
let cache_dir = env.get_string(cache_dir).expect("cache_dir is invalid");
let cache_dir = cache_dir.to_string_lossy();
// TODO arti data should probably be put in the datadir, not the cachedir
let config = onion_tunnel::TorClientConfigBuilder::from_directories(
format!("{}/arti-data", cache_dir),
format!("{}/arti-cache", cache_dir),
)
.build()
.unwrap();
rt.block_on(async move {
debug!("creating onion_tunnel...");
......@@ -27,6 +39,7 @@ pub extern "C" fn Java_org_torproject_OnionMasq_runProxy(
.expect("interface_name is invalid")
.to_string_lossy(),
fd,
config,
)
.await
{
......@@ -45,6 +58,7 @@ pub extern "C" fn Java_org_torproject_OnionMasq_runProxy(
});
}
#[cfg(target_os = "android")]
#[no_mangle]
pub extern "C" fn Java_org_torproject_OnionMasq_initLogging(_env: JNIEnv, _: JClass) {
android_logger::init_once(
......@@ -60,6 +74,7 @@ pub extern "C" fn Java_org_torproject_OnionMasq_initLogging(_env: JNIEnv, _: JCl
/// should probably not copy this code.
/// It might be possible to support Android 4.4 and below with the same trick applied to more
/// functions (at least create_epoll1), but this might not be worth the effort.
#[cfg(target_os = "android")]
#[no_mangle]
pub unsafe extern "C" fn lockf(fd: libc::c_int, cmd: libc::c_int, len: libc::off_t) -> libc::c_int {
use libc::*;
......
......@@ -5,7 +5,7 @@ use simple_logger::SimpleLogger;
async fn main() -> anyhow::Result<()> {
SimpleLogger::new().with_utc_timestamps().init().unwrap();
let mut onion_tunnel = OnionTunnel::new("onion0").await;
let mut onion_tunnel = OnionTunnel::new("onion0", Default::default()).await;
tokio::select! {
_ = onion_tunnel.start() => (),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment