Skip to content
Merged
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
140 changes: 131 additions & 9 deletions src/transport/manager/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
Expand Down
Loading