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

feat!: add tcp bypass settings for tor in wallet_ffi #3615

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 27 additions & 8 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,8 @@ pub unsafe extern "C" fn transport_tcp_create(
/// `control_server_address` - The pointer to a char array
/// `tor_cookie` - The pointer to a ByteVector containing the contents of the tor cookie file, can be null
/// `tor_port` - The tor port
/// `socks_username` - The pointer to a char array containing the socks username, can be null
/// `tor_proxy_bypass_for_outbound` - Whether tor will use a direct tcp connection for a given bypass address instead of
/// the tor proxy if tcp is available, if not it has no effect
/// `socks_password` - The pointer to a char array containing the socks password, can be null
/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions
/// as an out parameter.
Expand All @@ -2592,6 +2593,7 @@ pub unsafe extern "C" fn transport_tor_create(
control_server_address: *const c_char,
tor_cookie: *const ByteVector,
tor_port: c_ushort,
tor_proxy_bypass_for_outbound: bool,
socks_username: *const c_char,
socks_password: *const c_char,
error_out: *mut c_int,
Expand Down Expand Up @@ -2665,8 +2667,7 @@ pub unsafe extern "C" fn transport_tor_create(
socks_address_override: None,
socks_auth: authentication,
tor_proxy_bypass_addresses: vec![],
// Prefer performance
tor_proxy_bypass_for_outbound_tcp: true,
tor_proxy_bypass_for_outbound_tcp: tor_proxy_bypass_for_outbound,
};
let transport = TariTransportType::Tor(tor_config);

Expand Down Expand Up @@ -5975,6 +5976,7 @@ mod test {
let transport = transport_memory_create();
let _address = transport_memory_get_address(transport, error_ptr);
assert_eq!(error, 0);
transport_type_destroy(transport);
}
}

Expand All @@ -5985,8 +5987,9 @@ mod test {
let error_ptr = &mut error as *mut c_int;
let address_listener = CString::new("/ip4/127.0.0.1/tcp/0").unwrap();
let address_listener_str: *const c_char = CString::into_raw(address_listener) as *const c_char;
let _transport = transport_tcp_create(address_listener_str, error_ptr);
let transport = transport_tcp_create(address_listener_str, error_ptr);
assert_eq!(error, 0);
transport_type_destroy(transport);
}
}

Expand All @@ -5996,16 +5999,32 @@ mod test {
let mut error = 0;
let error_ptr = &mut error as *mut c_int;
let address_control = CString::new("/ip4/127.0.0.1/tcp/8080").unwrap();
let mut bypass = false;
let address_control_str: *const c_char = CString::into_raw(address_control) as *const c_char;
let _transport = transport_tor_create(
let mut transport = transport_tor_create(
address_control_str,
ptr::null_mut(),
ptr::null(),
8080,
bypass,
ptr::null(),
ptr::null(),
error_ptr,
);
assert_eq!(error, 0);
transport_type_destroy(transport);

bypass = true;
transport = transport_tor_create(
address_control_str,
ptr::null(),
8080,
ptr::null_mut(),
ptr::null_mut(),
bypass,
ptr::null(),
ptr::null(),
error_ptr,
);
assert_eq!(error, 0);
transport_type_destroy(transport);
}
}

Expand Down
1 change: 1 addition & 0 deletions base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct TariTransportType *transport_tor_create(
const char *control_server_address,
struct ByteVector *tor_cookie,
unsigned short tor_port,
bool tor_proxy_bypass_for_outbound,
const char *socks_username,
const char *socks_password,
int *error_out);
Expand Down
1 change: 1 addition & 0 deletions comms/dht/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/// This macro unlocks a Mutex or RwLock. If the lock is
/// poisoned (i.e. panic while unlocked) the last value
/// before the panic is used.
#[allow(unused_macros)]
macro_rules! acquire_lock {
($e:expr, $m:ident) => {
match $e.$m() {
Expand Down
1 change: 1 addition & 0 deletions comms/src/tor/hidden_service/proxy_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn is_tcp_address(addr: &Multiaddr) -> bool {
let protocol = iter.next();
matches!(protocol, Some(Tcp(_)))
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/helpers/ffi/ffiInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class InterfaceFFI {
this.string,
this.ptr,
this.ushort,
this.bool,
this.string,
this.string,
this.intPtr,
Expand Down Expand Up @@ -608,6 +609,7 @@ class InterfaceFFI {
control_server_address,
tor_cookie,
tor_port,
true,
socks_username,
socks_password,
error
Expand Down