Skip to content

Commit

Permalink
Merge pull request #362 from Wukong247/2025-01-02-master-build-fix
Browse files Browse the repository at this point in the history
master build fix and few more docs
  • Loading branch information
Shourya742 authored Jan 2, 2025
2 parents 66bcc2e + 5d8c702 commit ee050ee
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate bitcoind;
pub mod error;
pub mod maker;
pub mod market;
pub(crate) mod protocol;
pub mod protocol;
pub mod taker;
#[cfg(feature = "tor")]
pub mod tor;
Expand Down
12 changes: 12 additions & 0 deletions src/market/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub enum DirectoryServerError {
///
/// This variant wraps a [`WalletError`] to capture issues arising during wallet-related operations.
Wallet(WalletError),
/// Represents an error caused by a corrupted address file read.
AddressFileCorrupted(String),
}

Expand Down Expand Up @@ -126,6 +127,7 @@ pub struct DirectoryServer {
pub data_dir: PathBuf,
/// Shutdown flag to stop the directory server
pub shutdown: AtomicBool,
/// A collection of maker addresses received from the Dns Server.
pub addresses: Arc<RwLock<HashMap<OutPoint, String>>>,
}

Expand Down Expand Up @@ -329,6 +331,16 @@ pub fn read_addresses_from_file(
.collect::<Result<HashMap<_, _>, DirectoryServerError>>()
}

/// Initializes and starts the Directory Server with the provided configuration.
///
/// This function configures the Directory Server based on the specified `directory` and optional `rpc_config`.
/// It handles both Clearnet and Tor connections (if the `tor` feature is enabled) and performs the following tasks:
///
/// - Sets up the Directory Server for the appropriate connection type.
/// - Spawns threads for handling RPC requests and writing address data to disk.
/// - Monitors and manages incoming TCP connections.
/// - Handles shutdown signals gracefully, ensuring all threads are terminated and resources are cleaned up.
///
pub fn start_directory_server(
directory: Arc<DirectoryServer>,
rpc_config: Option<RPCConfig>,
Expand Down
2 changes: 1 addition & 1 deletion src/market/rpc/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ pub enum RpcMsgReq {
#[derive(Serialize, Deserialize, Debug)]
pub enum RpcMsgResp {
/// ListAddressesResp RPC message response variant
ListAddressesResp(BTreeSet<String>),
ListAddressesResp(BTreeSet<(OutPoint, String)>),
}
2 changes: 1 addition & 1 deletion src/market/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn handle_request(
Ok(())
}

pub(crate) fn start_rpc_server_thread(
pub fn start_rpc_server_thread(
directory: Arc<DirectoryServer>,
) -> Result<(), DirectoryServerError> {
let rpc_port = directory.rpc_port;
Expand Down
17 changes: 14 additions & 3 deletions src/protocol/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub(crate) struct MakerHello {

/// Contains proof data related to fidelity bond.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub(crate) struct FidelityProof {
pub struct FidelityProof {
pub(crate) bond: FidelityBond,
pub(crate) cert_hash: Hash,
pub(crate) cert_sig: bitcoin::secp256k1::ecdsa::Signature,
Expand Down Expand Up @@ -316,23 +316,34 @@ impl Display for MakerToTakerMessage {
}
}

/// Metadata shared by the maker with the Directory Server for verifying authenticity.
#[derive(Serialize, Deserialize, Debug)]
pub struct DnsMetadata {
/// The maker's URL.
pub url: String,
/// Proof of the maker's fidelity bond funding.
pub proof: FidelityProof,
}

// Structured requests and responses using serde.
/// Enum representing DNS request message types.
///
/// These requests and responses are structured using Serde for serialization and deserialization.
#[derive(Serialize, Deserialize, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum DnsRequest {
/// A request sent by the maker to register itself with the DNS server and authenticate.
Post {
/// Metadata containing the maker's URL and fidelity proof.
metadata: DnsMetadata,
},
/// A request sent by the taker to fetch all valid maker addresses from the DNS server.
Get,
/// Dummy data used for integration tests.
#[cfg(feature = "integration-test")]
Dummy {
/// A dummy URL for testing.
url: String,
vout: u32, // represents a specific vout value of the OutPoint(deadbeefcafebabefeedc0ffee123456789abcdeffedcba9876543210ffeeddcc:vout)
/// A dummy `vout` value, representing a specific output index of an OutPoint.
vout: u32,
},
}
2 changes: 2 additions & 0 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pub mod error;
pub(crate) mod messages;

pub(crate) use contract::Hash160;

pub use messages::{DnsMetadata, DnsRequest};
1 change: 1 addition & 0 deletions src/utill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use log4rs::{
config::{Appender, Logger, Root},
Config,
};
use serde::{Deserialize, Serialize};
use std::{
env, fmt,
io::{BufReader, BufWriter, ErrorKind, Read},
Expand Down
4 changes: 2 additions & 2 deletions tests/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{io::Write, net::TcpStream, process::Command, thread, time::Duration};

mod test_framework;

use coinswap::{protocol::messages::DnsRequest, utill::ConnectionType};
use coinswap::protocol::DnsRequest;
use test_framework::{init_bitcoind, start_dns};

fn send_addresses(addresses: &[(&str, u32)]) {
Expand Down Expand Up @@ -46,7 +46,7 @@ fn verify_addresses(addresses: &[(&str, u32)]) {
);
assert_eq!(
addresses_output
.match_indices(&format!("vout: {}", index.to_string()))
.match_indices(&format!("vout: {}", index))
.count(),
1,
"OP index {} not found",
Expand Down

0 comments on commit ee050ee

Please sign in to comment.