Skip to content
Merged
Changes from 1 commit
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
29 changes: 24 additions & 5 deletions src/libp2p/collection/multi_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use super::{
NotificationsOutErr, OverlayNetwork, PeerId, ShutdownCause, SubstreamId,
};

use alloc::{collections::VecDeque, string::ToString as _, sync::Arc};
use alloc::{collections::VecDeque, string::ToString as _, sync::Arc, vec::Vec};
use core::{
hash::Hash,
iter,
Expand Down Expand Up @@ -140,16 +140,35 @@ where
request_response_protocols: Arc<[ConfigRequestResponse]>,
ping_protocol: Arc<str>,
) -> Self {
// We only support one kind of handshake at the moment. Make sure (at compile time) that
// the value provided as parameter is indeed the one expected.
let MultiStreamHandshakeKind::WebRtc { .. } = handshake_kind;
// In the WebRTC handshake, the Noise prologue must be set to `"libp2p-webrtc-noise:"`
// followed with the multihash-encoded fingerprints of the local and remote certificates
// in ascending order.
// See <https://github.com/libp2p/specs/pull/412>.
let noise_prologue = {
let MultiStreamHandshakeKind::WebRtc {
local_tls_certificate_multihash,
remote_tls_certificate_multihash,
} = handshake_kind;
const PREFIX: &[u8] = b"libp2p-webrtc-noise:";
let mut out = Vec::with_capacity(
PREFIX.len()
+ local_tls_certificate_multihash.len()
+ remote_tls_certificate_multihash.len(),
);
out.extend_from_slice(PREFIX);
// Since smoldot always acts as a client (at least right now), we don't need to change
// the order of fingerprints.
out.extend_from_slice(&local_tls_certificate_multihash);
out.extend_from_slice(&remote_tls_certificate_multihash);
out
};

MultiStreamConnectionTask {
connection: MultiStreamConnectionTaskInner::Handshake {
handshake: Some(noise::HandshakeInProgress::new(noise::Config {
key: &noise_key,
is_initiator: true, // TODO: is_initiator?
prologue: &[], // TODO: this prologue isn't correct, WebRTC requires passing certificate fingerprints
prologue: &noise_prologue,
})),
opened_substream: None,
extra_open_substreams: hashbrown::HashMap::with_capacity_and_hasher(
Expand Down