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

Fix domain/port discernment for transfers routed through epicbox #90

Merged
merged 7 commits into from
Aug 17, 2023
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
47 changes: 14 additions & 33 deletions impls/src/adapters/epicbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use crate::libwallet::message::EncryptedMessage;
use crate::util::secp::key::PublicKey;

use crate::libwallet::wallet_lock;
use crate::libwallet::{
address, Address, AddressType, EpicboxAddress, TxProof, DEFAULT_EPICBOX_PORT_443,
DEFAULT_EPICBOX_PORT_80,
};
use crate::libwallet::{address, Address, EpicboxAddress, TxProof};
use crate::libwallet::{NodeClient, WalletInst, WalletLCProvider};

use crate::Error;
Expand Down Expand Up @@ -155,16 +152,8 @@ impl EpicboxListenChannel {
let url = {
let cloned_address = address.clone();
match epicbox_config.epicbox_protocol_unsecure.unwrap_or(false) {
true => format!(
"ws://{}:{}",
cloned_address.domain,
cloned_address.port.unwrap_or(DEFAULT_EPICBOX_PORT_80)
),
false => format!(
"wss://{}:{}",
cloned_address.domain,
cloned_address.port.unwrap_or(DEFAULT_EPICBOX_PORT_443)
),
true => format!("ws://{}:{}", cloned_address.domain, cloned_address.port),
false => format!("wss://{}:{}", cloned_address.domain, cloned_address.port),
}
};
let (tx, _rx): (Sender<bool>, Receiver<bool>) = channel();
Expand Down Expand Up @@ -293,16 +282,8 @@ where
let url = {
let cloned_address = address.clone();
match config.epicbox_protocol_unsecure.unwrap_or(false) {
true => format!(
"ws://{}:{}",
cloned_address.domain,
cloned_address.port.unwrap_or(DEFAULT_EPICBOX_PORT_80)
),
false => format!(
"wss://{}:{}",
cloned_address.domain,
cloned_address.port.unwrap_or(DEFAULT_EPICBOX_PORT_443)
),
true => format!("ws://{}:{}", cloned_address.domain, cloned_address.port),
false => format!("wss://{}:{}", cloned_address.domain, cloned_address.port),
}
};
debug!("Connecting to the epicbox server at {} ..", url.clone());
Expand Down Expand Up @@ -385,10 +366,9 @@ impl Publisher for EpicboxPublisher {
fn post_slate(
&self,
slate: &VersionedSlate,
to: &dyn Address,
to: &EpicboxAddress,
close_connection: bool,
) -> Result<(), Error> {
let to = EpicboxAddress::from_str(&to.to_string())?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the important removal, where regex parsing was happening twice.

self.broker
.post_slate(slate, &to, &self.address, &self.secret_key)?;
if close_connection {
Expand Down Expand Up @@ -525,7 +505,7 @@ where
}
}
pub trait SubscriptionHandler: Send {
fn on_slate(&self, from: &dyn Address, slate: &VersionedSlate, proof: Option<&mut TxProof>);
fn on_slate(&self, from: &EpicboxAddress, slate: &VersionedSlate, proof: Option<&mut TxProof>);
fn on_close(&self, result: CloseReason);
}

Expand All @@ -536,7 +516,12 @@ where
C: NodeClient + 'static,
K: Keychain + 'static,
{
fn on_slate(&self, from: &dyn Address, slate: &VersionedSlate, tx_proof: Option<&mut TxProof>) {
fn on_slate(
&self,
from: &EpicboxAddress,
slate: &VersionedSlate,
tx_proof: Option<&mut TxProof>,
) {
let version = slate.version();
let mut slate: Slate = slate.clone().into();

Expand All @@ -556,10 +541,6 @@ where
);
};

if from.address_type() == AddressType::Epicbox {
EpicboxAddress::from_str(&from.to_string()).expect("invalid epicbox address");
}

let result = self
.process_incoming_slate(Some(from.to_string()), &mut slate, tx_proof)
.and_then(|is_finalized| {
Expand Down Expand Up @@ -627,7 +608,7 @@ pub trait Publisher: Send {
fn post_slate(
&self,
slate: &VersionedSlate,
to: &dyn Address,
to: &EpicboxAddress,
close_connection: bool,
) -> Result<(), Error>;
}
Expand Down
14 changes: 5 additions & 9 deletions libwallet/src/epicbox_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub enum AddressType {
pub struct EpicboxAddress {
pub public_key: String,
pub domain: String,
pub port: Option<u16>,
pub port: u16,
}

pub trait Address: Debug + Display {
Expand All @@ -58,7 +58,7 @@ impl EpicboxAddress {
Self {
public_key: public_key.to_base58_check(version_bytes()),
domain: domain.unwrap_or(DEFAULT_EPICBOX_DOMAIN.to_string()),
port,
port: port.unwrap_or(DEFAULT_EPICBOX_PORT_443),
}
}

Expand Down Expand Up @@ -100,13 +100,9 @@ impl Address for EpicboxAddress {
impl Display for EpicboxAddress {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.public_key)?;
if self.domain != DEFAULT_EPICBOX_DOMAIN
|| (self.port.is_some() && self.port.unwrap() != DEFAULT_EPICBOX_PORT_443)
{
write!(f, "@{}", self.domain)?;
if self.port.is_some() && self.port.unwrap() != DEFAULT_EPICBOX_PORT_443 {
write!(f, ":{}", self.port.unwrap())?;
}
write!(f, "@{}", self.domain)?;
if self.port != DEFAULT_EPICBOX_PORT_443 {
write!(f, ":{}", self.port)?;
}
Ok(())
}
Expand Down