Skip to content

Commit d7d113a

Browse files
Inform the user that (and why) Tor is forced-on (GUI). Don't ask the user about listening on TCP/Onion if the environment doesn't support it (TUI questionnaire)
1 parent eb261a0 commit d7d113a

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

src-gui/src/renderer/components/pages/help/SettingsBox.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { getNetwork } from "store/config";
6666
import { currencySymbol } from "utils/formatUtils";
6767
import InfoBox from "renderer/components/pages/swap/swap/components/InfoBox";
6868
import { isValidMultiAddressWithPeerId } from "utils/parseUtils";
69-
import { getNodeStatus } from "renderer/rpc";
69+
import { getNodeStatus, getTorForcedExcuse } from "renderer/rpc";
7070
import { setStatus } from "store/features/nodesSlice";
7171
import MoneroAddressTextField from "renderer/components/inputs/MoneroAddressTextField";
7272
import BitcoinAddressTextField from "renderer/components/inputs/BitcoinAddressTextField";
@@ -704,24 +704,32 @@ function NodeTable({
704704
);
705705
}
706706

707+
const torForced = await getTorForcedExcuse();
707708
export function TorSettings() {
708709
const dispatch = useAppDispatch();
709710
const torEnabled = useSettings((settings) => settings.enableTor);
710711
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) =>
711712
dispatch(setTorEnabled(event.target.checked));
712-
const status = (state: boolean) => (state === true ? "enabled" : "disabled");
713713

714714
return (
715715
<TableRow>
716716
<TableCell>
717717
<SettingLabel
718718
label="Use Tor"
719-
tooltip="Route network traffic through Tor to hide your IP address from the maker."
719+
tooltip={
720+
"Route network traffic through Tor to hide your IP address from the maker. " +
721+
torForced
722+
}
720723
/>
721724
</TableCell>
722725

723726
<TableCell>
724-
<Switch checked={torEnabled} onChange={handleChange} color="primary" />
727+
<Switch
728+
disabled={torForced}
729+
checked={torEnabled || torForced}
730+
onChange={handleChange}
731+
color="primary"
732+
/>
725733
</TableCell>
726734
</TableRow>
727735
);
@@ -740,7 +748,8 @@ function MoneroTorSettings() {
740748
dispatch(setEnableMoneroTor(event.target.checked));
741749

742750
// Hide this setting if Tor is disabled entirely
743-
if (!torEnabled) {
751+
// Hide this setting if it's superseded by the global Tor connection
752+
if (!torEnabled || torForced) {
744753
return null;
745754
}
746755

src-gui/src/renderer/rpc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ export async function checkContextStatus(): Promise<ContextStatus> {
304304
return await invokeNoArgs<ContextStatus>("get_context_status");
305305
}
306306

307+
export async function getTorForcedExcuse(): Promise<string> {
308+
return await invokeNoArgs<string>("get_tor_forced_excuse");
309+
}
310+
307311
export async function getLogsOfSwap(
308312
swapId: string,
309313
redact: boolean,

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tauri-build = { version = "2.*", features = ["config-json5"] }
1515
[dependencies]
1616
monero-rpc-pool = { path = "../monero-rpc-pool" }
1717
swap = { path = "../swap", features = [ "tauri" ] }
18+
swap-tor = { path = "../swap-tor" }
1819
dfx-swiss-sdk = { workspace = true }
1920

2021
anyhow = "1"

src-tauri/src/commands.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ macro_rules! generate_command_handlers {
6969
get_restore_height,
7070
dfx_authenticate,
7171
change_monero_node,
72-
get_context_status
72+
get_context_status,
73+
get_tor_forced_excuse,
7374
]
7475
};
7576
}
@@ -197,6 +198,13 @@ pub async fn get_context_status(state: tauri::State<'_, State>) -> Result<Contex
197198
Ok(state.context().status().await)
198199
}
199200

201+
#[tauri::command]
202+
pub async fn get_tor_forced_excuse(_: tauri::State<'_, State>) -> Result<String, String> {
203+
Ok(swap_tor::TOR_ENVIRONMENT
204+
.map(|ste| ste.excuse())
205+
.unwrap_or(String::new()))
206+
}
207+
200208
#[tauri::command]
201209
pub async fn resolve_approval_request(
202210
args: ResolveApprovalArgs,

swap-env/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rust_decimal = { workspace = true }
1515
serde = { workspace = true }
1616
swap-fs = { path = "../swap-fs" }
1717
swap-serde = { path = "../swap-serde" }
18+
swap-tor = { path = "../swap-tor" }
1819
terminal_size = "0.4"
1920
thiserror = { workspace = true }
2021
time = "0.3"

swap-env/src/prompt.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ pub fn bitcoin_confirmation_target(default_target: u16) -> Result<u16> {
3838

3939
/// Prompt user for listen addresses
4040
pub fn listen_addresses(default_listen_address: &Multiaddr) -> Result<Vec<Multiaddr>> {
41+
if !swap_tor::TOR_ENVIRONMENT
42+
.map(|ste| ste.can_listen_tcp())
43+
.unwrap_or(true)
44+
{
45+
return Ok(vec![]);
46+
}
47+
4148
let listen_addresses = Input::with_theme(&ColorfulTheme::default())
4249
.with_prompt("Enter multiaddresses (comma separated) on which asb should list for peer-to-peer communications or hit return to use default")
4350
.default(format!("{}", default_listen_address))
@@ -131,6 +138,13 @@ pub fn monero_daemon_url() -> Result<Option<Url>> {
131138

132139
/// Prompt user for Tor hidden service registration
133140
pub fn tor_hidden_service() -> Result<bool> {
141+
if !swap_tor::TOR_ENVIRONMENT
142+
.map(|ste| ste.can_listen_onion())
143+
.unwrap_or(true)
144+
{
145+
return Ok(false);
146+
}
147+
134148
print_info_box([
135149
"Your ASB needs to be reachable from the outside world to provide quotes to takers.",
136150
"Your ASB can run a hidden service for itself. It'll be reachable at an .onion address.",

swap-tor/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,23 @@ impl SpecialTorEnvironment {
203203
)),
204204
}
205205
}
206+
207+
/// `true` if listening on an address like `/ip4/0.0.0.0/tcp/9939` is possible in this environment
208+
pub fn can_listen_tcp(self) -> bool {
209+
match self {
210+
Self::Whonix | Self::Tails => false,
211+
}
212+
}
213+
214+
/// `true` if listening on an address like `/onion3/whatever` is possible in this environment
215+
pub fn can_listen_onion(self) -> bool {
216+
match self {
217+
Self::Whonix | Self::Tails => false,
218+
}
219+
}
220+
221+
/// Explain to the user why Tor is always on
222+
pub fn excuse(self) -> String {
223+
format!("Under {self:?}, the app always uses the global Tor connection.")
224+
}
206225
}

0 commit comments

Comments
 (0)