diff --git a/protocols/upnp/src/behaviour.rs b/protocols/upnp/src/behaviour.rs index adfa60f6e94..035561689f6 100644 --- a/protocols/upnp/src/behaviour.rs +++ b/protocols/upnp/src/behaviour.rs @@ -23,6 +23,7 @@ use std::{ borrow::Borrow, collections::HashMap, + error::Error, hash::{Hash, Hasher}, net::{Ipv4Addr, SocketAddrV4}, pin::Pin, @@ -90,11 +91,11 @@ enum Event { /// Port was successfully mapped. Mapped(Mapping), /// There was a failure mapping port. - MapFailure(Mapping, String), + MapFailure(Mapping, Box), /// Port was successfully removed. Removed(Mapping), /// There was a failure removing the mapping port. - RemovalFailure(Mapping, String), + RemovalFailure(Mapping, Box), } /// Mapping of a Protocol and Port on the gateway. diff --git a/protocols/upnp/src/gateway.rs b/protocols/upnp/src/gateway.rs index 4ad8cf665d9..3d8155e123b 100644 --- a/protocols/upnp/src/gateway.rs +++ b/protocols/upnp/src/gateway.rs @@ -64,10 +64,14 @@ pub trait Gateway: Sized + Send + Sync { protocol: Protocol, addr: SocketAddrV4, duration: Duration, - ) -> Result<(), String>; + ) -> Result<(), Box>; /// Remove port mapping on the gateway. - async fn remove_port(_: Arc, protocol: Protocol, port: u16) -> Result<(), String>; + async fn remove_port( + _: Arc, + protocol: Protocol, + port: u16, + ) -> Result<(), Box>; // /// Spawn a future on the executor. fn spawn(f: F) diff --git a/protocols/upnp/src/gateway/async_std.rs b/protocols/upnp/src/gateway/async_std.rs index 351c196a0fe..7b199c67579 100644 --- a/protocols/upnp/src/gateway/async_std.rs +++ b/protocols/upnp/src/gateway/async_std.rs @@ -53,7 +53,7 @@ impl super::Gateway for Gateway { protocol: Protocol, addr: SocketAddrV4, duration: Duration, - ) -> Result<(), String> { + ) -> Result<(), Box> { let protocol = match protocol { Protocol::Tcp => PortMappingProtocol::TCP, Protocol::Udp => PortMappingProtocol::UDP, @@ -67,10 +67,14 @@ 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, protocol: Protocol, port: u16) -> Result<(), String> { + async fn remove_port( + gateway: Arc, + protocol: Protocol, + port: u16, + ) -> Result<(), Box> { let protocol = match protocol { Protocol::Tcp => PortMappingProtocol::TCP, Protocol::Udp => PortMappingProtocol::UDP, @@ -78,7 +82,7 @@ impl super::Gateway for Gateway { gateway .remove_port(protocol, port) .await - .map_err(|err| err.to_string()) + .map_err(|err| err.into()) } fn spawn(f: F) where diff --git a/protocols/upnp/src/gateway/tokio.rs b/protocols/upnp/src/gateway/tokio.rs index 2c035566b03..febc691c85d 100644 --- a/protocols/upnp/src/gateway/tokio.rs +++ b/protocols/upnp/src/gateway/tokio.rs @@ -53,7 +53,7 @@ impl super::Gateway for Gateway { protocol: Protocol, addr: SocketAddrV4, duration: Duration, - ) -> Result<(), String> { + ) -> Result<(), Box> { let protocol = match protocol { Protocol::Tcp => PortMappingProtocol::TCP, Protocol::Udp => PortMappingProtocol::UDP, @@ -67,10 +67,14 @@ 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, protocol: Protocol, port: u16) -> Result<(), String> { + async fn remove_port( + gateway: Arc, + protocol: Protocol, + port: u16, + ) -> Result<(), Box> { let protocol = match protocol { Protocol::Tcp => PortMappingProtocol::TCP, Protocol::Udp => PortMappingProtocol::UDP, @@ -78,7 +82,7 @@ impl super::Gateway for Gateway { gateway .remove_port(protocol, port) .await - .map_err(|err| err.to_string()) + .map_err(|err| err.into()) } fn spawn(f: F)