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

feat: allow hostnames where we take addresses #286

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 93 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/floresta-electrum/src/electrum_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,8 @@ mod test {
chain.clone(),
Arc::new(tokio::sync::RwLock::new(Mempool::new())),
None,
);
)
.unwrap();

let node_interface = chain_provider.get_handle();

Expand Down
27 changes: 27 additions & 0 deletions crates/floresta-wire/src/p2p_wire/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::{self};
use std::io;

use floresta_chain::BlockchainError;
Expand Down Expand Up @@ -36,6 +39,8 @@ pub enum WireError {
CompactBlockFiltersError(IteratableFilterStoreError),
#[error("Poisoned lock")]
PoisonedLock,
#[error("We couldn't parse the provided address due to: {0}")]
InvalidAddress(AddrParseError),
}

impl_error_from!(WireError, PeerError, PeerError);
Expand All @@ -45,6 +50,7 @@ impl_error_from!(
IteratableFilterStoreError,
CompactBlockFiltersError
);
impl_error_from!(WireError, AddrParseError, InvalidAddress);

impl From<tokio::sync::mpsc::error::SendError<NodeRequest>> for WireError {
fn from(error: tokio::sync::mpsc::error::SendError<NodeRequest>) -> Self {
Expand All @@ -57,3 +63,24 @@ impl From<io::Error> for WireError {
WireError::Io(err)
}
}

#[derive(Debug, Clone)]
pub enum AddrParseError {
InvalidIpv6,
InvalidIpv4,
InvalidHostname,
InvalidPort,
Inconclusive,
}

impl Display for AddrParseError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
AddrParseError::InvalidIpv6 => write!(f, "Invalid ipv6"),
AddrParseError::InvalidIpv4 => write!(f, "Invalid ipv4"),
AddrParseError::InvalidHostname => write!(f, "Invalid hostname"),
AddrParseError::InvalidPort => write!(f, "Invalid port"),
AddrParseError::Inconclusive => write!(f, "Inconclusive"),
}
}
}
4 changes: 1 addition & 3 deletions crates/floresta-wire/src/p2p_wire/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::net::SocketAddr;
use bitcoin::Network;
use floresta_chain::AssumeUtreexoValue;

use self::address_man::LocalAddress;

#[derive(Debug, Clone)]
/// Configuration for the Utreexo node.
pub struct UtreexoNodeConfig {
Expand All @@ -30,7 +28,7 @@ pub struct UtreexoNodeConfig {
///
/// If you want to connect to a specific peer, you can set this to a string with the
/// format `ip:port`. For example, `localhost:8333`.
pub fixed_peer: Option<LocalAddress>,
pub fixed_peer: Option<String>,
/// Maximum ban score. Defaults to 100.
///
/// If a peer misbehaves, we increase its ban score. If the ban score reaches this value,
Expand Down
Loading