Skip to content

Commit

Permalink
remove tor feature flag and other miscellaneous objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Shourya742 committed Feb 19, 2025
1 parent eeb03b8 commit 7be1bb4
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 167 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ minreq = { version = "2.12.0", features = ["https"] , optional = true}

#Empty default feature set, (helpful to generalise in github actions)
[features]
default = ['tor']
default = []
# The following feature set is in response to the issue described at https://github.com/rust-lang/rust/issues/45599
# Only used for running the integration tests
integration-test = ['dep:flate2','dep:tar','dep:minreq']
# Used for connecting to the Tor socks port
tor = []

10 changes: 3 additions & 7 deletions src/bin/directoryd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ fn main() -> Result<(), DirectoryServerError> {
wallet_name: "random".to_string(), // we can put anything here as it will get updated in the init.
};

#[cfg(feature = "tor")]
let connection_type = if cfg!(feature = "integration-test") {
ConnectionType::CLEARNET
} else {
ConnectionType::TOR
};
#[cfg(not(feature = "integration-test"))]
let connection_type = ConnectionType::TOR;

#[cfg(not(feature = "tor"))]
#[cfg(feature = "integration-test")]
let connection_type = ConnectionType::CLEARNET;

let directory = Arc::new(DirectoryServer::new(
Expand Down
10 changes: 3 additions & 7 deletions src/bin/makerd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ fn main() -> Result<(), MakerError> {
wallet_name: "random".to_string(), // we can put anything here as it will get updated in the init.
};

#[cfg(feature = "tor")]
let connection_type = if cfg!(feature = "integration-test") {
ConnectionType::CLEARNET
} else {
ConnectionType::TOR
};
#[cfg(not(feature = "integration-test"))]
let connection_type = ConnectionType::TOR;

#[cfg(not(feature = "tor"))]
#[cfg(feature = "integration-test")]
let connection_type = ConnectionType::CLEARNET;

let maker = Arc::new(Maker::init(
Expand Down
10 changes: 3 additions & 7 deletions src/bin/taker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,10 @@ fn main() -> Result<(), TakerError> {
wallet_name: "random".to_string(), // we can put anything here as it will get updated in the init.
};

#[cfg(feature = "tor")]
let connection_type = if cfg!(feature = "integration-test") {
ConnectionType::CLEARNET
} else {
ConnectionType::TOR
};
#[cfg(not(feature = "integration-test"))]
let connection_type = ConnectionType::TOR;

#[cfg(not(feature = "tor"))]
#[cfg(feature = "integration-test")]
let connection_type = ConnectionType::CLEARNET;

let mut taker = Taker::init(
Expand Down
4 changes: 2 additions & 2 deletions src/maker/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ impl Default for MakerConfig {
#[cfg(not(feature = "integration-test"))]
fidelity_timelock: 2160, // Approx 15 days of blocks in production
connection_type: {
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
{
ConnectionType::TOR
}
#[cfg(not(feature = "tor"))]
#[cfg(feature = "integration-test")]
{
ConnectionType::CLEARNET
}
Expand Down
6 changes: 2 additions & 4 deletions src/maker/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bitcoin::{Address, Amount};
use super::messages::RpcMsgReq;
use crate::{
maker::{error::MakerError, rpc::messages::RpcMsgResp, Maker},
utill::{get_tor_hostname, read_message, send_message, ConnectionType, HEART_BEAT_INTERVAL},
utill::{read_message, send_message, ConnectionType, HEART_BEAT_INTERVAL},
wallet::{Destination, SendAmount},
};
use std::str::FromStr;
Expand Down Expand Up @@ -105,9 +105,7 @@ fn handle_request(maker: &Arc<Maker>, socket: &mut TcpStream) -> Result<(), Make
if maker.config.connection_type == ConnectionType::CLEARNET {
RpcMsgResp::GetTorAddressResp("Maker is not running on TOR".to_string())
} else {
let hostname = get_tor_hostname(&maker.data_dir.join("tor"))?;

let address = format!("{}:{}", hostname, maker.config.service_port);
let address = format!("{}:{}", maker.config.hostname, maker.config.service_port);

RpcMsgResp::GetTorAddressResp(address)
}
Expand Down
26 changes: 9 additions & 17 deletions src/maker/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::{
io::ErrorKind,
net::{Ipv4Addr, TcpListener, TcpStream},
path::Path,
process::Child,
sync::{
atomic::{AtomicBool, Ordering::Relaxed},
Expand All @@ -20,7 +19,7 @@ use std::{
use bitcoin::{absolute::LockTime, Amount};
use bitcoind::bitcoincore_rpc::RpcApi;

#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
use socks::Socks5Stream;

pub(crate) use super::{api::RPC_PING_INTERVAL, Maker};
Expand All @@ -36,13 +35,13 @@ use crate::{
rpc::start_rpc_server,
},
protocol::messages::{DnsMetadata, DnsRequest, TakerToMakerMessage},
utill::{
check_tor_status, get_tor_hostname, read_message, send_message, ConnectionType,
HEART_BEAT_INTERVAL,
},
utill::{read_message, send_message, ConnectionType, HEART_BEAT_INTERVAL},
wallet::WalletError,
};

#[cfg(not(feature = "integration-test"))]
use crate::utill::check_tor_status;

use crate::maker::error::MakerError;

// Default values for Maker configurations
Expand All @@ -67,19 +66,12 @@ fn network_bootstrap(maker: Arc<Maker>) -> Result<Option<Child>, MakerError> {

(maker_address, dns_address, None)
}
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => {
let maker_hostname = &maker.config.hostname;
let maker_address = format!("{}:{}", maker_hostname, maker.config.service_port);

let dns_address = if cfg!(feature = "integration-test") {
let dns_tor_dir = Path::new("/tmp/coinswap/dns/tor");
let dns_hostname = get_tor_hostname(dns_tor_dir)?;
format!("{}:{}", dns_hostname, 8080)
} else {
maker.config.directory_server_address.clone()
};

let dns_address = maker.config.directory_server_address.clone();
(maker_address, dns_address, None)
}
};
Expand Down Expand Up @@ -120,7 +112,7 @@ fn network_bootstrap(maker: Arc<Maker>) -> Result<Option<Child>, MakerError> {
if i >= trigger_count || i == 0 {
let stream = match maker.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(&dns_address),
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", maker.config.socks_port),
dns_address.as_str(),
Expand Down Expand Up @@ -422,7 +414,7 @@ fn handle_client(maker: Arc<Maker>, stream: &mut TcpStream) -> Result<(), MakerE
pub fn start_maker_server(maker: Arc<Maker>) -> Result<(), MakerError> {
log::info!("Starting Maker Server");
// Initialize network connections.
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
check_tor_status(maker.config.control_port, &maker.config.tor_auth_password)?;
// Setup the wallet with fidelity bond.
let _tor_thread = network_bootstrap(maker.clone())?;
Expand Down
18 changes: 10 additions & 8 deletions src/market/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ use crate::{
market::rpc::start_rpc_server_thread,
protocol::messages::DnsRequest,
utill::{
check_tor_status, get_dns_dir, parse_field, parse_toml, read_message, send_message,
verify_fidelity_checks, ConnectionType, TorError, HEART_BEAT_INTERVAL,
get_dns_dir, parse_field, parse_toml, read_message, send_message, verify_fidelity_checks,
ConnectionType, TorError, HEART_BEAT_INTERVAL,
},
wallet::{RPCConfig, WalletError},
};

#[cfg(not(feature = "integration-test"))]
use crate::utill::check_tor_status;

use std::{
collections::HashMap,
convert::TryFrom,
Expand Down Expand Up @@ -154,11 +157,11 @@ impl Default for DirectoryServer {
control_port: 9051,
tor_auth_password: "".to_string(),
connection_type: {
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
{
ConnectionType::TOR
}
#[cfg(not(feature = "tor"))]
#[cfg(feature = "integration-test")]
{
ConnectionType::CLEARNET
}
Expand Down Expand Up @@ -371,10 +374,9 @@ pub fn start_directory_server(
directory: Arc<DirectoryServer>,
rpc_config: Option<RPCConfig>,
) -> Result<(), DirectoryServerError> {
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
check_tor_status(directory.control_port, &directory.tor_auth_password)?;

#[cfg(feature = "tor")]
let rpc_config = rpc_config.unwrap_or_default();

let rpc_client = bitcoincore_rpc::Client::try_from(&rpc_config)?;
Expand All @@ -389,9 +391,9 @@ pub fn start_directory_server(

match directory.connection_type {
ConnectionType::CLEARNET => {}
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => {
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
{
let network_port = directory.service_port;

Expand Down
44 changes: 15 additions & 29 deletions src/taker/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use std::{
collections::{HashMap, HashSet},
io::BufWriter,
net::TcpStream,
path::{Path, PathBuf},
path::PathBuf,
thread::sleep,
time::{Duration, Instant},
};

use bitcoind::bitcoincore_rpc::RpcApi;

#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
use socks::Socks5Stream;

use bitcoin::{
Expand Down Expand Up @@ -290,7 +290,7 @@ impl Taker {

/// Does the coinswap process
pub fn do_coinswap(&mut self, swap_params: SwapParams) -> Result<(), TakerError> {
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
check_tor_status(self.config.control_port, &self.config.tor_auth_password)?;
self.send_coinswap(swap_params)
}
Expand Down Expand Up @@ -930,7 +930,7 @@ impl Taker {
let address = this_maker.address.to_string();
let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(address)?,
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
address.as_str(),
Expand Down Expand Up @@ -1406,7 +1406,7 @@ impl Taker {

let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(maker_addr_str.clone())?,
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
&*maker_addr_str,
Expand Down Expand Up @@ -1495,7 +1495,7 @@ impl Taker {
let maker_addr_str = maker_address.to_string();
let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(maker_addr_str.clone())?,
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
&*maker_addr_str,
Expand Down Expand Up @@ -1673,7 +1673,7 @@ impl Taker {
let maker_addr_str = maker_address.to_string();
let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(maker_addr_str.clone())?,
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
&*maker_addr_str,
Expand Down Expand Up @@ -2017,29 +2017,15 @@ impl Taker {
self.config.directory_server_address.clone()
}
}
#[cfg(feature = "tor")]
ConnectionType::TOR => {
if cfg!(feature = "integration-test") {
let tor_dir = Path::new("/tmp/coinswap/dns/tor");

let hostname = get_tor_hostname(tor_dir)?;
log::info!("---------------hostname : {:?}", hostname);
format!("{}:{}", hostname, 8080)
} else {
self.config.directory_server_address.clone()
}
}
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => self.config.directory_server_address.clone(),
};

let socks_port = if cfg!(feature = "tor") {
if self.config.connection_type == ConnectionType::CLEARNET {
None
} else {
Some(self.config.socks_port)
}
} else {
None
};
#[cfg(not(feature = "integration-test"))]
let socks_port = Some(self.config.socks_port);

#[cfg(feature = "integration-test")]
let socks_port = None;

log::info!("Fetching addresses from DNS: {}", dns_addr);

Expand Down Expand Up @@ -2104,7 +2090,7 @@ impl Taker {
let address = maker_addr.to_string();
let mut socket = match self.config.connection_type {
ConnectionType::CLEARNET => TcpStream::connect(address)?,
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => Socks5Stream::connect(
format!("127.0.0.1:{}", self.config.socks_port).as_str(),
address.as_str(),
Expand Down
4 changes: 2 additions & 2 deletions src/taker/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ impl Default for TakerConfig {
directory_server_address:
"bhbzkndgad52ojm75w4goii7xsi6ou73fzyvorxas7swg2snlto4c4ad.onion:8080".to_string(),
connection_type: {
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
{
ConnectionType::TOR
}
#[cfg(not(feature = "tor"))]
#[cfg(feature = "integration-test")]
{
ConnectionType::CLEARNET
}
Expand Down
12 changes: 3 additions & 9 deletions src/taker/offers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{

use serde::{Deserialize, Serialize};

#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
use socks::Socks5Stream;

use crate::{
Expand Down Expand Up @@ -200,19 +200,13 @@ pub(crate) fn fetch_offer_from_makers(
Ok(result)
}

#[allow(unused_variables)]
/// Retrieves advertised maker addresses from directory servers based on the specified network.
pub fn fetch_addresses_from_dns(
socks_port: Option<u16>,
dns_addr: String,
connection_type: ConnectionType,
) -> Result<Vec<MakerAddress>, TakerError> {
if !cfg!(feature = "tor") {
assert!(
socks_port.is_none(),
"Cannot use socks port without tor feature"
);
}

loop {
let mut stream = match connection_type {
ConnectionType::CLEARNET => match TcpStream::connect(dns_addr.as_str()) {
Expand All @@ -223,7 +217,7 @@ pub fn fetch_addresses_from_dns(
}
Ok(s) => s,
},
#[cfg(feature = "tor")]
#[cfg(not(feature = "integration-test"))]
ConnectionType::TOR => {
let socket_addrs = format!("127.0.0.1:{}", socks_port.expect("Tor port expected"));
match Socks5Stream::connect(socket_addrs, dns_addr.as_str()) {
Expand Down
Loading

0 comments on commit 7be1bb4

Please sign in to comment.