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

DNS: Send ACK to Maker after successful address posting #414

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
32 changes: 31 additions & 1 deletion src/maker/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::{
handlers::handle_message,
rpc::start_rpc_server,
},
protocol::messages::{DnsMetadata, DnsRequest, TakerToMakerMessage},
protocol::messages::{DnsMetadata, DnsRequest, DnsResponse, TakerToMakerMessage},
utill::{get_tor_hostname, read_message, send_message, ConnectionType, HEART_BEAT_INTERVAL},
wallet::WalletError,
};
Expand Down Expand Up @@ -207,6 +207,36 @@ fn network_bootstrap(maker: Arc<Maker>) -> Result<Option<Child>, MakerError> {
maker_port,
dns_address
);

match read_message(&mut stream) {
Ok(dns_msg_bytes) => {
match serde_cbor::from_slice::<DnsResponse>(&dns_msg_bytes) {
Ok(dns_msg) => match dns_msg {
DnsResponse::Ack => {
log::info!("[{}] <=== {}", maker.config.network_port, dns_msg);
}
DnsResponse::Nack(reason) => {
log::error!("{}", reason);
}
},
Err(e) => {
log::warn!("CBOR deserialization failed: {}", e);
}
}
}
Err(e) => {
if let NetError::IO(e) = e {
if e.kind() == ErrorKind::UnexpectedEof {
log::info!("[{}] Connection ended.", maker.config.network_port);
break;
} else {
// For any other errors, report them
log::error!("[{}] Net Error: {}", maker.config.network_port, e);
continue;
}
}
}
}
// Reset counter when success
i = 0;
}
Expand Down
26 changes: 24 additions & 2 deletions src/market/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bitcoind::bitcoincore_rpc::{self, Client, RpcApi};

use crate::{
market::rpc::start_rpc_server_thread,
protocol::messages::DnsRequest,
protocol::messages::{DnsRequest, DnsResponse},
utill::{
get_dns_dir, parse_field, parse_toml, read_message, send_message, verify_fidelity_checks,
ConnectionType, HEART_BEAT_INTERVAL,
Expand Down Expand Up @@ -484,14 +484,36 @@ fn handle_client(
"Fidelity verification success from {}. Adding/updating to address data.",
metadata.url
);
directory.updated_address_map((metadata.url, metadata.proof.bond.outpoint))?;

match directory
.updated_address_map((metadata.url.clone(), metadata.proof.bond.outpoint))
{
Ok(_) => {
log::info!("Maker posting request successful from {}", metadata.url);
send_message(stream, &DnsResponse::Ack)?;
}
Err(e) => {
log::warn!("Maker posting request failed from {}", metadata.url);
send_message(
stream,
&DnsResponse::Nack(format!(
"Maker posting request failed: {:?}",
e
)),
)?;
}
}
}
Err(e) => {
log::error!(
"Potentially suspicious maker detected: {:?} | {:?}",
metadata.url,
e
);
send_message(
stream,
&DnsResponse::Nack(format!("Fidelity verification failed {:?}", e)),
)?;
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/protocol/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ impl Display for MakerToTakerMessage {
}
}

/// All messages sent from DNS to Maker
#[derive(Debug, Serialize, Deserialize)]
pub enum DnsResponse {
/// Posting request by Maker was accepted by DNS.
Ack,
/// Posting request by Maker was rejected by DNS.
Nack(String),
}

impl Display for DnsResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Ack => write!(f, "Ack"),
Self::Nack(s) => write!(f, "{}", s.as_str()),
}
}
}

/// Metadata shared by the maker with the Directory Server for verifying authenticity.
#[derive(Serialize, Deserialize, Debug)]
#[allow(private_interfaces)]
Expand Down
Loading