Skip to content

Commit

Permalink
revert Box<dyn Error> to String conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Jul 8, 2023
1 parent 3f3f745 commit 7d679c8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
5 changes: 3 additions & 2 deletions protocols/upnp/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
borrow::Borrow,
collections::HashMap,
error::Error,
hash::{Hash, Hasher},
net::{Ipv4Addr, SocketAddrV4},
pin::Pin,
Expand Down Expand Up @@ -90,11 +91,11 @@ enum Event {
/// Port was successfully mapped.
Mapped(Mapping),
/// There was a failure mapping port.
MapFailure(Mapping, String),
MapFailure(Mapping, Box<dyn Error + Send + Sync + 'static>),
/// Port was successfully removed.
Removed(Mapping),
/// There was a failure removing the mapping port.
RemovalFailure(Mapping, String),
RemovalFailure(Mapping, Box<dyn Error + Send + Sync + 'static>),
}

/// Mapping of a Protocol and Port on the gateway.
Expand Down
8 changes: 6 additions & 2 deletions protocols/upnp/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@ pub trait Gateway: Sized + Send + Sync {
protocol: Protocol,
addr: SocketAddrV4,
duration: Duration,
) -> Result<(), String>;
) -> Result<(), Box<dyn Error + Send + Sync + 'static>>;

/// Remove port mapping on the gateway.
async fn remove_port(_: Arc<Self>, protocol: Protocol, port: u16) -> Result<(), String>;
async fn remove_port(
_: Arc<Self>,
protocol: Protocol,
port: u16,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>>;

// /// Spawn a future on the executor.
fn spawn<F>(f: F)
Expand Down
12 changes: 8 additions & 4 deletions protocols/upnp/src/gateway/async_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl super::Gateway for Gateway {
protocol: Protocol,
addr: SocketAddrV4,
duration: Duration,
) -> Result<(), String> {
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
Expand All @@ -67,18 +67,22 @@ impl super::Gateway for Gateway {
"rust-libp2p mapping",
)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}

async fn remove_port(gateway: Arc<Self>, protocol: Protocol, port: u16) -> Result<(), String> {
async fn remove_port(
gateway: Arc<Self>,
protocol: Protocol,
port: u16,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
};
gateway
.remove_port(protocol, port)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}
fn spawn<F>(f: F)
where
Expand Down
12 changes: 8 additions & 4 deletions protocols/upnp/src/gateway/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl super::Gateway for Gateway {
protocol: Protocol,
addr: SocketAddrV4,
duration: Duration,
) -> Result<(), String> {
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
Expand All @@ -67,18 +67,22 @@ impl super::Gateway for Gateway {
"rust-libp2p mapping",
)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}

async fn remove_port(gateway: Arc<Self>, protocol: Protocol, port: u16) -> Result<(), String> {
async fn remove_port(
gateway: Arc<Self>,
protocol: Protocol,
port: u16,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
};
gateway
.remove_port(protocol, port)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}

fn spawn<F>(f: F)
Expand Down

0 comments on commit 7d679c8

Please sign in to comment.