Skip to content

Commit

Permalink
Fix inconsistent naming, host --> address
Browse files Browse the repository at this point in the history
In the context of makers advertising their own addresses on the
directory servers, sometimes it would be called an addresss
e.g. in the structs MakerAddress and OfferAndAddress
and sometimes called host, as in sync_maker_hosts_from_directory_servers()

Fixed this inconsistency by choosing the word address.
  • Loading branch information
chris-belcher committed Feb 15, 2022
1 parent 4b1c89e commit d83dcc8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/directory_servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn network_enum_to_string(network: Network) -> &'static str {
}
}

pub async fn sync_maker_hosts_from_directory_servers(
pub async fn sync_maker_addresses_from_directory_servers(
network: Network,
) -> Result<Vec<MakerAddress>, DirectoryServerError> {
// https://github.com/seanmonstar/reqwest/blob/master/examples/tor_socks.rs
Expand Down Expand Up @@ -59,13 +59,13 @@ pub async fn sync_maker_hosts_from_directory_servers(
maker_addresses.push(MakerAddress::Tor {
address: String::from(csv_chunks[1]),
});
log::debug!(target:"directory_servers", "expiry timestamp = {} hostname = {}",
log::debug!(target:"directory_servers", "expiry timestamp = {} address = {}",
csv_chunks[0], csv_chunks[1]);
}
Ok(maker_addresses)
}

pub async fn post_maker_host_to_directory_servers(
pub async fn post_maker_address_to_directory_servers(
network: Network,
address: &str,
) -> Result<u64, DirectoryServerError> {
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod taker_protocol;
use taker_protocol::TakerConfig;

pub mod offerbook_sync;
use offerbook_sync::{get_advertised_maker_hosts, sync_offerbook_with_hostnames, MakerAddress};
use offerbook_sync::{get_advertised_maker_addresses, sync_offerbook_with_addresses, MakerAddress};

pub mod directory_servers;
pub mod error;
Expand Down Expand Up @@ -511,11 +511,11 @@ pub async fn download_and_display_offers(maker_address: Option<String>) {
address: maker_addr,
}]
} else {
get_advertised_maker_hosts()
get_advertised_maker_addresses()
.await
.expect("unable to sync maker addresses from directory servers")
};
let offers_addresses = sync_offerbook_with_hostnames(maker_addresses.clone()).await;
let offers_addresses = sync_offerbook_with_addresses(maker_addresses.clone()).await;
let mut addresses_offers_map = HashMap::new();
for offer_address in offers_addresses.iter() {
let address_str = match &offer_address.address {
Expand Down
10 changes: 5 additions & 5 deletions src/maker_protocol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//put your onion hostname and port here
const MAKER_ONION_ADDR: &str = "myhiddenservicehostname.onion:6102";
//put your onion address and port here
const MAKER_ONION_ADDR: &str = "myhiddenserviceaddress.onion:6102";
const ABSOLUTE_FEE_SAT: u64 = 1000;
const AMOUNT_RELATIVE_FEE_PPB: u64 = 10_000_000;
const TIME_RELATIVE_FEE_PPB: u64 = 100_000;
Expand Down Expand Up @@ -33,7 +33,7 @@ use crate::contracts::{
calculate_coinswap_fee, find_funding_output, read_hashvalue_from_contract,
read_locktime_from_contract, MAKER_FUNDING_TX_VBYTE_SIZE,
};
use crate::directory_servers::post_maker_host_to_directory_servers;
use crate::directory_servers::post_maker_address_to_directory_servers;
use crate::error::Error;
use crate::messages::{
HashPreimage, MakerHello, MakerToTakerMessage, Offer, PrivateKeyHandover, ProofOfFunding,
Expand Down Expand Up @@ -114,7 +114,7 @@ async fn run(

if NETWORK != Network::Regtest {
log::info!("Adding my address at the directory servers. . .");
post_maker_host_to_directory_servers(NETWORK, MAKER_ONION_ADDR)
post_maker_address_to_directory_servers(NETWORK, MAKER_ONION_ADDR)
.await
.unwrap();
}
Expand Down Expand Up @@ -170,7 +170,7 @@ async fn run(
&& Instant::now().saturating_duration_since(last_directory_servers_refresh)
> directory_servers_refresh_interval {
last_directory_servers_refresh = Instant::now();
let result_expiry_time = post_maker_host_to_directory_servers(
let result_expiry_time = post_maker_address_to_directory_servers(
NETWORK,
MAKER_ONION_ADDR
).await;
Expand Down
14 changes: 7 additions & 7 deletions src/offerbook_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tokio::time::sleep;
use bitcoin::Network;

use crate::directory_servers::{
sync_maker_hosts_from_directory_servers, DirectoryServerError, TOR_ADDR,
sync_maker_addresses_from_directory_servers, DirectoryServerError, TOR_ADDR,
};
use crate::error::Error;
use crate::messages::{GiveOffer, MakerToTakerMessage, Offer, TakerToMakerMessage};
Expand All @@ -31,7 +31,7 @@ pub struct OfferAndAddress {
pub address: MakerAddress,
}

const REGTEST_MAKER_HOSTS: &'static [&'static str] = &[
const REGTEST_MAKER_ADDRESSES: &'static [&'static str] = &[
"localhost:6102",
"localhost:16102",
"localhost:26102",
Expand All @@ -40,7 +40,7 @@ const REGTEST_MAKER_HOSTS: &'static [&'static str] = &[
];

fn get_regtest_maker_addresses() -> Vec<MakerAddress> {
REGTEST_MAKER_HOSTS
REGTEST_MAKER_ADDRESSES
.iter()
.map(|h| MakerAddress::Clearnet {
address: h.to_string(),
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn download_maker_offer(address: MakerAddress) -> Option<OfferAndAddress>
}
}

pub async fn sync_offerbook_with_hostnames(
pub async fn sync_offerbook_with_addresses(
maker_addresses: Vec<MakerAddress>,
) -> Vec<OfferAndAddress> {
let (offers_writer_m, mut offers_reader) = mpsc::channel::<Option<OfferAndAddress>>(100);
Expand All @@ -151,14 +151,14 @@ pub async fn sync_offerbook_with_hostnames(
result
}

pub async fn get_advertised_maker_hosts() -> Result<Vec<MakerAddress>, DirectoryServerError> {
pub async fn get_advertised_maker_addresses() -> Result<Vec<MakerAddress>, DirectoryServerError> {
Ok(if NETWORK == Network::Regtest {
get_regtest_maker_addresses()
} else {
sync_maker_hosts_from_directory_servers(NETWORK).await?
sync_maker_addresses_from_directory_servers(NETWORK).await?
})
}

pub async fn sync_offerbook() -> Result<Vec<OfferAndAddress>, DirectoryServerError> {
Ok(sync_offerbook_with_hostnames(get_advertised_maker_hosts().await?).await)
Ok(sync_offerbook_with_addresses(get_advertised_maker_addresses().await?).await)
}
2 changes: 1 addition & 1 deletion src/taker_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub async fn start_taker(rpc: &Client, wallet: &mut Wallet, config: TakerConfig)
async fn run(rpc: &Client, wallet: &mut Wallet, config: TakerConfig) -> Result<(), Error> {
let offers_addresses = sync_offerbook()
.await
.expect("unable to sync maker hosts from directory servers");
.expect("unable to sync maker addresses from directory servers");
log::info!("<=== Got Offers");
log::debug!("Offers : {:#?}", offers_addresses);
send_coinswap(rpc, wallet, config, &offers_addresses).await?;
Expand Down

0 comments on commit d83dcc8

Please sign in to comment.