diff --git a/src/transport/manager/handle.rs b/src/transport/manager/handle.rs index 8d99666e..36619e51 100644 --- a/src/transport/manager/handle.rs +++ b/src/transport/manager/handle.rs @@ -143,23 +143,21 @@ impl TransportManagerHandle { match iter.next() { None => false, - Some(Protocol::Tcp(_)) => match iter.next() { - Some(Protocol::P2p(_)) => + Some(Protocol::Tcp(_)) => match (iter.next(), iter.next(), iter.next()) { + (Some(Protocol::P2p(_)), None, None) => self.supported_transport.contains(&SupportedTransport::Tcp), #[cfg(feature = "websocket")] - Some(Protocol::Ws(_)) => + (Some(Protocol::Ws(_)), Some(Protocol::P2p(_)), None) => self.supported_transport.contains(&SupportedTransport::WebSocket), #[cfg(feature = "websocket")] - Some(Protocol::Wss(_)) => + (Some(Protocol::Wss(_)), Some(Protocol::P2p(_)), None) => self.supported_transport.contains(&SupportedTransport::WebSocket), _ => false, }, #[cfg(feature = "quic")] - Some(Protocol::Udp(_)) => match ( - iter.next(), - self.supported_transport.contains(&SupportedTransport::Quic), - ) { - (Some(Protocol::QuicV1), true) => true, + Some(Protocol::Udp(_)) => match (iter.next(), iter.next(), iter.next()) { + (Some(Protocol::QuicV1), Some(Protocol::P2p(_)), None) => + self.supported_transport.contains(&SupportedTransport::Quic), _ => false, }, _ => false, @@ -387,6 +385,29 @@ mod tests { assert!(handle.supported_transport(&address)); } + #[tokio::test] + async fn tcp_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + + let address = + "/dns4/google.com/tcp/24928/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + + #[tokio::test] + async fn tcp_non_terminal_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + handle.supported_transport.insert(SupportedTransport::Tcp); + + let address = + "/dns4/google.com/tcp/24928/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy/p2p-circuit" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + #[cfg(feature = "websocket")] #[tokio::test] async fn websocket_supported() { @@ -400,6 +421,107 @@ mod tests { assert!(handle.supported_transport(&address)); } + #[cfg(feature = "websocket")] + #[tokio::test] + async fn websocket_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + + let address = + "/dns4/google.com/tcp/24928/ws/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + + #[cfg(feature = "websocket")] + #[tokio::test] + async fn websocket_non_terminal_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + handle.supported_transport.insert(SupportedTransport::WebSocket); + + let address = + "/dns4/google.com/tcp/24928/ws/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy/p2p-circuit" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + + #[cfg(feature = "websocket")] + #[tokio::test] + async fn wss_supported() { + let (mut handle, _rx) = make_transport_manager_handle(); + handle.supported_transport.insert(SupportedTransport::WebSocket); + + let address = + "/dns4/google.com/tcp/24928/wss/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy" + .parse() + .unwrap(); + assert!(handle.supported_transport(&address)); + } + + #[cfg(feature = "websocket")] + #[tokio::test] + async fn wss_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + + let address = + "/dns4/google.com/tcp/24928/wss/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + + #[cfg(feature = "websocket")] + #[tokio::test] + async fn wss_non_terminal_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + handle.supported_transport.insert(SupportedTransport::WebSocket); + + let address = + "/dns4/google.com/tcp/24928/wss/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy/p2p-circuit" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + + #[cfg(feature = "quic")] + #[tokio::test] + async fn quic_supported() { + let (mut handle, _rx) = make_transport_manager_handle(); + handle.supported_transport.insert(SupportedTransport::Quic); + + let address = + "/dns4/google.com/udp/24928/quic-v1/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy" + .parse() + .unwrap(); + assert!(handle.supported_transport(&address)); + } + + #[cfg(feature = "quic")] + #[tokio::test] + async fn quic_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + + let address = + "/dns4/google.com/udp/24928/quic-v1/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + + #[cfg(feature = "quic")] + #[tokio::test] + async fn quic_non_terminal_unsupported() { + let (mut handle, _rx) = make_transport_manager_handle(); + handle.supported_transport.insert(SupportedTransport::Quic); + + let address = + "/dns4/google.com/udp/24928/quic-v1/p2p/12D3KooWKrUnV42yDR7G6DewmgHtFaVCJWLjQRi2G9t5eJD3BvTy/p2p-circuit" + .parse() + .unwrap(); + assert!(!handle.supported_transport(&address)); + } + #[test] fn transport_not_supported() { let (handle, _rx) = make_transport_manager_handle();