mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-26 16:21:39 +00:00
@ -55,7 +55,7 @@ where
|
|||||||
{
|
{
|
||||||
InboundUpgradeApply {
|
InboundUpgradeApply {
|
||||||
inner: InboundUpgradeApplyState::Init {
|
inner: InboundUpgradeApplyState::Init {
|
||||||
future: multistream_select::listener_select_proto(conn, up.protocol_info().into_iter()),
|
future: multistream_select::listener_select_proto(conn, up.protocol_info()),
|
||||||
upgrade: up,
|
upgrade: up,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -354,9 +354,16 @@ mod tests {
|
|||||||
.block_peer(*listener.local_peer_id());
|
.block_peer(*listener.local_peer_id());
|
||||||
|
|
||||||
let (
|
let (
|
||||||
[SwarmEvent::ConnectionClosed { peer_id: closed_dialer_peer, .. }],
|
[SwarmEvent::ConnectionClosed {
|
||||||
[SwarmEvent::ConnectionClosed { peer_id: closed_listener_peer, .. }]
|
peer_id: closed_dialer_peer,
|
||||||
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else {
|
..
|
||||||
|
}],
|
||||||
|
[SwarmEvent::ConnectionClosed {
|
||||||
|
peer_id: closed_listener_peer,
|
||||||
|
..
|
||||||
|
}],
|
||||||
|
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await
|
||||||
|
else {
|
||||||
panic!("unexpected events")
|
panic!("unexpected events")
|
||||||
};
|
};
|
||||||
assert_eq!(closed_dialer_peer, *listener.local_peer_id());
|
assert_eq!(closed_dialer_peer, *listener.local_peer_id());
|
||||||
@ -417,9 +424,22 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (
|
let (
|
||||||
[SwarmEvent::OutgoingConnectionError { error: DialError::Denied { cause: outgoing_cause }, .. }],
|
[SwarmEvent::OutgoingConnectionError {
|
||||||
[_, SwarmEvent::IncomingConnectionError { error: ListenError::Denied { cause: incoming_cause }, .. }],
|
error:
|
||||||
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else {
|
DialError::Denied {
|
||||||
|
cause: outgoing_cause,
|
||||||
|
},
|
||||||
|
..
|
||||||
|
}],
|
||||||
|
[_, SwarmEvent::IncomingConnectionError {
|
||||||
|
error:
|
||||||
|
ListenError::Denied {
|
||||||
|
cause: incoming_cause,
|
||||||
|
},
|
||||||
|
..
|
||||||
|
}],
|
||||||
|
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await
|
||||||
|
else {
|
||||||
panic!("unexpected events")
|
panic!("unexpected events")
|
||||||
};
|
};
|
||||||
assert!(outgoing_cause.downcast::<NotAllowed>().is_ok());
|
assert!(outgoing_cause.downcast::<NotAllowed>().is_ok());
|
||||||
@ -447,9 +467,16 @@ mod tests {
|
|||||||
.list
|
.list
|
||||||
.disallow_peer(*listener.local_peer_id());
|
.disallow_peer(*listener.local_peer_id());
|
||||||
let (
|
let (
|
||||||
[SwarmEvent::ConnectionClosed { peer_id: closed_dialer_peer, .. }],
|
[SwarmEvent::ConnectionClosed {
|
||||||
[SwarmEvent::ConnectionClosed { peer_id: closed_listener_peer, .. }]
|
peer_id: closed_dialer_peer,
|
||||||
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await else {
|
..
|
||||||
|
}],
|
||||||
|
[SwarmEvent::ConnectionClosed {
|
||||||
|
peer_id: closed_listener_peer,
|
||||||
|
..
|
||||||
|
}],
|
||||||
|
) = libp2p_swarm_test::drive(&mut dialer, &mut listener).await
|
||||||
|
else {
|
||||||
panic!("unexpected events")
|
panic!("unexpected events")
|
||||||
};
|
};
|
||||||
assert_eq!(closed_dialer_peer, *listener.local_peer_id());
|
assert_eq!(closed_dialer_peer, *listener.local_peer_id());
|
||||||
|
@ -411,7 +411,7 @@ mod tests {
|
|||||||
assert!(len < (1 << 15));
|
assert!(len < (1 << 15));
|
||||||
let frame = (0..len).map(|n| (n & 0xff) as u8).collect::<Vec<_>>();
|
let frame = (0..len).map(|n| (n & 0xff) as u8).collect::<Vec<_>>();
|
||||||
let mut data = vec![(len & 0x7f) as u8 | 0x80, (len >> 7) as u8];
|
let mut data = vec![(len & 0x7f) as u8 | 0x80, (len >> 7) as u8];
|
||||||
data.extend(frame.clone().into_iter());
|
data.extend(frame.clone());
|
||||||
let mut framed = LengthDelimited::new(Cursor::new(data));
|
let mut framed = LengthDelimited::new(Cursor::new(data));
|
||||||
let recved = futures::executor::block_on(async move { framed.next().await }).unwrap();
|
let recved = futures::executor::block_on(async move { framed.next().await }).unwrap();
|
||||||
assert_eq!(recved.unwrap(), frame);
|
assert_eq!(recved.unwrap(), frame);
|
||||||
|
@ -47,10 +47,9 @@ fn select_proto_basic() {
|
|||||||
|
|
||||||
let client = async_std::task::spawn(async move {
|
let client = async_std::task::spawn(async move {
|
||||||
let protos = vec!["/proto3", "/proto2"];
|
let protos = vec!["/proto3", "/proto2"];
|
||||||
let (proto, mut io) =
|
let (proto, mut io) = dialer_select_proto(client_connection, protos, version)
|
||||||
dialer_select_proto(client_connection, protos.into_iter(), version)
|
.await
|
||||||
.await
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
assert_eq!(proto, "/proto2");
|
assert_eq!(proto, "/proto2");
|
||||||
|
|
||||||
io.write_all(b"ping").await.unwrap();
|
io.write_all(b"ping").await.unwrap();
|
||||||
@ -99,25 +98,21 @@ fn negotiation_failed() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let client =
|
let client = async_std::task::spawn(async move {
|
||||||
async_std::task::spawn(async move {
|
let mut io = match dialer_select_proto(client_connection, dial_protos, version).await {
|
||||||
let mut io =
|
Err(NegotiationError::Failed) => return,
|
||||||
match dialer_select_proto(client_connection, dial_protos.into_iter(), version)
|
Ok((_, io)) => io,
|
||||||
.await
|
Err(_) => panic!(),
|
||||||
{
|
};
|
||||||
Err(NegotiationError::Failed) => return,
|
// The dialer may write a payload that is even sent before it
|
||||||
Ok((_, io)) => io,
|
// got confirmation of the last proposed protocol, when `V1Lazy`
|
||||||
Err(_) => panic!(),
|
// is used.
|
||||||
};
|
io.write_all(&dial_payload).await.unwrap();
|
||||||
// The dialer may write a payload that is even sent before it
|
match io.complete().await {
|
||||||
// got confirmation of the last proposed protocol, when `V1Lazy`
|
Err(NegotiationError::Failed) => {}
|
||||||
// is used.
|
_ => panic!(),
|
||||||
io.write_all(&dial_payload).await.unwrap();
|
}
|
||||||
match io.complete().await {
|
});
|
||||||
Err(NegotiationError::Failed) => {}
|
|
||||||
_ => panic!(),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.await;
|
server.await;
|
||||||
client.await;
|
client.await;
|
||||||
@ -185,10 +180,9 @@ async fn v1_lazy_do_not_wait_for_negotiation_on_poll_close() {
|
|||||||
let client = async_std::task::spawn(async move {
|
let client = async_std::task::spawn(async move {
|
||||||
// Single protocol to allow for lazy (or optimistic) protocol negotiation.
|
// Single protocol to allow for lazy (or optimistic) protocol negotiation.
|
||||||
let protos = vec!["/proto1"];
|
let protos = vec!["/proto1"];
|
||||||
let (proto, mut io) =
|
let (proto, mut io) = dialer_select_proto(client_connection, protos, Version::V1Lazy)
|
||||||
dialer_select_proto(client_connection, protos.into_iter(), Version::V1Lazy)
|
.await
|
||||||
.await
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
assert_eq!(proto, "/proto1");
|
assert_eq!(proto, "/proto1");
|
||||||
|
|
||||||
// client can close the connection even though protocol negotiation is not yet done, i.e.
|
// client can close the connection even though protocol negotiation is not yet done, i.e.
|
||||||
|
@ -858,7 +858,7 @@ fn test_handle_received_subscriptions() {
|
|||||||
// UNSUBSCRIBE - Remove topic from peer_topics for peer.
|
// UNSUBSCRIBE - Remove topic from peer_topics for peer.
|
||||||
// - Remove peer from topic_peers.
|
// - Remove peer from topic_peers.
|
||||||
|
|
||||||
let topics = vec!["topic1", "topic2", "topic3", "topic4"]
|
let topics = ["topic1", "topic2", "topic3", "topic4"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&t| String::from(t))
|
.map(|&t| String::from(t))
|
||||||
.collect();
|
.collect();
|
||||||
@ -1280,7 +1280,7 @@ fn test_handle_graft_is_not_subscribed() {
|
|||||||
#[test]
|
#[test]
|
||||||
// tests multiple topics in a single graft message
|
// tests multiple topics in a single graft message
|
||||||
fn test_handle_graft_multiple_topics() {
|
fn test_handle_graft_multiple_topics() {
|
||||||
let topics: Vec<String> = vec!["topic1", "topic2", "topic3", "topic4"]
|
let topics: Vec<String> = ["topic1", "topic2", "topic3", "topic4"]
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&t| String::from(t))
|
.map(|&t| String::from(t))
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -222,7 +222,7 @@ mod test {
|
|||||||
let t1 = TopicHash::from_raw("t1");
|
let t1 = TopicHash::from_raw("t1");
|
||||||
let t2 = TopicHash::from_raw("t2");
|
let t2 = TopicHash::from_raw("t2");
|
||||||
|
|
||||||
let old = BTreeSet::from_iter(vec![t1.clone()].into_iter());
|
let old = BTreeSet::from_iter(vec![t1.clone()]);
|
||||||
let subscriptions = vec![
|
let subscriptions = vec![
|
||||||
Subscription {
|
Subscription {
|
||||||
action: Unsubscribe,
|
action: Unsubscribe,
|
||||||
|
@ -40,9 +40,10 @@ fn webtransport_server_empty_certhashes() {
|
|||||||
|
|
||||||
// Invalid case, because a MITM attacker may strip certificates of the server.
|
// Invalid case, because a MITM attacker may strip certificates of the server.
|
||||||
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
||||||
handshake_with_certhashes(vec![certhash1, certhash2], vec![]) else {
|
handshake_with_certhashes(vec![certhash1, certhash2], vec![])
|
||||||
panic!("unexpected result");
|
else {
|
||||||
};
|
panic!("unexpected result");
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
|
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
|
||||||
assert_eq!(received, HashSet::new());
|
assert_eq!(received, HashSet::new());
|
||||||
@ -68,9 +69,10 @@ fn webtransport_server_uninit_certhashes() {
|
|||||||
|
|
||||||
// Invalid case, because a MITM attacker may strip certificates of the server.
|
// Invalid case, because a MITM attacker may strip certificates of the server.
|
||||||
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
||||||
handshake_with_certhashes(vec![certhash1, certhash2], None) else {
|
handshake_with_certhashes(vec![certhash1, certhash2], None)
|
||||||
panic!("unexpected result");
|
else {
|
||||||
};
|
panic!("unexpected result");
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
|
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
|
||||||
assert_eq!(received, HashSet::new());
|
assert_eq!(received, HashSet::new());
|
||||||
@ -81,9 +83,10 @@ fn webtransport_different_server_certhashes() {
|
|||||||
let (certhash1, certhash2, certhash3) = certhashes();
|
let (certhash1, certhash2, certhash3) = certhashes();
|
||||||
|
|
||||||
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
||||||
handshake_with_certhashes(vec![certhash1, certhash3], vec![certhash1, certhash2]) else {
|
handshake_with_certhashes(vec![certhash1, certhash3], vec![certhash1, certhash2])
|
||||||
panic!("unexpected result");
|
else {
|
||||||
};
|
panic!("unexpected result");
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(expected, HashSet::from([certhash1, certhash3]));
|
assert_eq!(expected, HashSet::from([certhash1, certhash3]));
|
||||||
assert_eq!(received, HashSet::from([certhash1, certhash2]));
|
assert_eq!(received, HashSet::from([certhash1, certhash2]));
|
||||||
@ -94,9 +97,10 @@ fn webtransport_superset_of_certhashes() {
|
|||||||
let (certhash1, certhash2, _) = certhashes();
|
let (certhash1, certhash2, _) = certhashes();
|
||||||
|
|
||||||
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
let Err(noise::Error::UnknownWebTransportCerthashes(expected, received)) =
|
||||||
handshake_with_certhashes(vec![certhash1, certhash2], vec![certhash1]) else {
|
handshake_with_certhashes(vec![certhash1, certhash2], vec![certhash1])
|
||||||
panic!("unexpected result");
|
else {
|
||||||
};
|
panic!("unexpected result");
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
|
assert_eq!(expected, HashSet::from([certhash1, certhash2]));
|
||||||
assert_eq!(received, HashSet::from([certhash1]));
|
assert_eq!(received, HashSet::from([certhash1]));
|
||||||
|
Reference in New Issue
Block a user