-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Libp2p quic second attempt #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7431703
Add libp2p-quic.
dvc94ch 7c65806
Disable build on wasm.
dvc94ch eb3bc68
Update to v0.6.0
dvc94ch f6c32fe
Merge remote-tracking branch 'upstream/master' into libp2p-quic
dvc94ch a762d14
Update to latest libp2p-quic.
dvc94ch 4a69421
Update imports.
dvc94ch a93cf96
Merge branch 'master' into libp2p-quic
dvc94ch a1c06ae
Merge branch 'master' into libp2p-quic
dvc94ch 65e3623
Review fixes
kpp 1eface6
Don't require critical libp2p ext
kpp f760494
Use std HashMap instead of fnv's
kpp 9a88cf2
Remove ToLibp2p to_keypair
kpp 35ac0fb
Move iovs init into a separate function
kpp d665212
Use mem::replace to unbind recv_buf
kpp ee7a7f5
Update transports/quic/src/endpoint.rs
dvc94ch aee258c
Merge master (#18)
kpp 314e1c5
Merge branch 'master' into libp2p-quic
dvc94ch 9b36bc1
Update transports/quic/src/transport.rs
dvc94ch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| [package] | ||
| name = "libp2p-quic" | ||
| version = "0.6.0" | ||
| authors = ["David Craven <[email protected]>", "Parity Technologies <[email protected]>"] | ||
| edition = "2018" | ||
| description = "TLS and Noise based QUIC transport implementation for libp2p" | ||
| repository = "https://github.com/libp2p/rust-libp2p" | ||
| license = "MIT" | ||
|
|
||
| [features] | ||
| noise = ["quinn-noise", "ed25519-dalek"] | ||
| tls = ["barebones-x509", "quinn-proto/tls-rustls", "rcgen", "ring", "rustls", "untrusted", "webpki", "yasna"] | ||
|
|
||
| [dependencies] | ||
| async-global-executor = "2.0.2" | ||
| async-io = "1.6.0" | ||
| barebones-x509 = { version = "0.5.0", optional = true, features = ["webpki", "rustls", "std"] } | ||
| bytes = "1.0.1" | ||
| ed25519-dalek = { version = "1.0.1", optional = true } | ||
| futures = "0.3.15" | ||
| if-watch = "0.2.2" | ||
| libp2p-core = { version = "0.30.0", path = "../../core" } | ||
| multihash = { version = "0.14.0", default-features = false } | ||
| parking_lot = "0.11.1" | ||
| quinn-noise = { version = "0.3.0", optional = true } | ||
| quinn-proto = { version = "0.7.3", default-features = false } | ||
| rcgen = { version = "0.8.11", optional = true } | ||
| ring = { version = "0.16.20", optional = true } | ||
| rustls = { version = "0.19.1", optional = true, features = ["dangerous_configuration"] } | ||
| thiserror = "1.0.26" | ||
| tracing = "0.1.26" | ||
| udp-socket = "0.1.5" | ||
| untrusted = { version = "0.7.1", optional = true } | ||
| webpki = { version = "0.21.4", optional = true, features = ["std"] } | ||
| yasna = { version = "0.4.0", optional = true } | ||
|
|
||
| [dev-dependencies] | ||
| anyhow = "1.0.41" | ||
| async-std = { version = "1.9.0", features = ["attributes"] } | ||
| async-trait = "0.1.50" | ||
| libp2p = { version = "0.40.0", default-features = false, features = ["request-response"], path = "../.." } | ||
| log-panics = "2.0.0" | ||
| rand = "0.8.4" | ||
| rand_core = "0.5.1" | ||
| tracing-subscriber = "0.2.19" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| use libp2p_core::PeerId; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the sake of consistency, would you mind including license headers here? |
||
| use quinn_proto::crypto::Session; | ||
| use quinn_proto::TransportConfig; | ||
| use std::sync::Arc; | ||
|
|
||
| pub struct CryptoConfig<C: Crypto> { | ||
| pub keypair: C::Keypair, | ||
| pub psk: Option<[u8; 32]>, | ||
| pub keylogger: Option<C::Keylogger>, | ||
| pub transport: Arc<TransportConfig>, | ||
| } | ||
|
|
||
| #[cfg(feature = "noise")] | ||
| trait CloneKeypair { | ||
| fn clone_keypair(&self) -> Self; | ||
| } | ||
|
|
||
| #[cfg(feature = "noise")] | ||
| impl CloneKeypair for ed25519_dalek::Keypair { | ||
| fn clone_keypair(&self) -> Self { | ||
| ed25519_dalek::Keypair::from_bytes(&self.to_bytes()).expect("serde works") | ||
| } | ||
| } | ||
|
|
||
| pub trait ToLibp2p { | ||
| fn to_public(&self) -> libp2p_core::identity::PublicKey; | ||
| fn to_peer_id(&self) -> PeerId { | ||
| self.to_public().to_peer_id() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "noise")] | ||
| impl ToLibp2p for ed25519_dalek::Keypair { | ||
| fn to_public(&self) -> libp2p_core::identity::PublicKey { | ||
| self.public.to_public() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "noise")] | ||
| impl ToLibp2p for ed25519_dalek::PublicKey { | ||
| fn to_public(&self) -> libp2p_core::identity::PublicKey { | ||
| let public_key = self.to_bytes(); | ||
| let public_key = | ||
| libp2p_core::identity::ed25519::PublicKey::decode(&public_key[..]).unwrap(); | ||
| libp2p_core::identity::PublicKey::Ed25519(public_key) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "tls")] | ||
| impl ToLibp2p for libp2p_core::identity::Keypair { | ||
| fn to_public(&self) -> libp2p_core::identity::PublicKey { | ||
| self.public() | ||
| } | ||
| } | ||
|
|
||
| pub trait Crypto: std::fmt::Debug + Clone + 'static { | ||
| type Session: Session + Unpin; | ||
| type Keylogger: Send + Sync; | ||
| type Keypair: Send + Sync + ToLibp2p; | ||
| type PublicKey: Send + std::fmt::Debug + PartialEq<Self::PublicKey>; | ||
|
|
||
| fn new_server_config( | ||
| config: &Arc<CryptoConfig<Self>>, | ||
| ) -> <Self::Session as Session>::ServerConfig; | ||
| fn new_client_config( | ||
| config: &Arc<CryptoConfig<Self>>, | ||
| remote_public: Self::PublicKey, | ||
| ) -> <Self::Session as Session>::ClientConfig; | ||
| fn supported_quic_versions() -> Vec<u32>; | ||
| fn default_quic_version() -> u32; | ||
| fn peer_id(session: &Self::Session) -> Option<PeerId>; | ||
| fn extract_public_key(generic_key: libp2p_core::PublicKey) -> Option<Self::PublicKey>; | ||
| fn keylogger() -> Self::Keylogger; | ||
| } | ||
|
|
||
| #[cfg(feature = "noise")] | ||
| #[derive(Clone, Copy, Debug)] | ||
| pub struct NoiseCrypto; | ||
|
|
||
| #[cfg(feature = "noise")] | ||
| impl Crypto for NoiseCrypto { | ||
| type Session = quinn_noise::NoiseSession; | ||
| type Keylogger = Arc<dyn quinn_noise::KeyLog>; | ||
| type Keypair = ed25519_dalek::Keypair; | ||
| type PublicKey = ed25519_dalek::PublicKey; | ||
|
|
||
| fn new_server_config( | ||
| config: &Arc<CryptoConfig<Self>>, | ||
| ) -> <Self::Session as Session>::ServerConfig { | ||
| Arc::new( | ||
| quinn_noise::NoiseServerConfig { | ||
| keypair: config.keypair.clone_keypair(), | ||
| psk: config.psk, | ||
| keylogger: config.keylogger.clone(), | ||
| supported_protocols: vec![b"libp2p".to_vec()], | ||
| } | ||
| .into(), | ||
| ) | ||
| } | ||
|
|
||
| fn new_client_config( | ||
| config: &Arc<CryptoConfig<Self>>, | ||
| remote_public_key: Self::PublicKey, | ||
| ) -> <Self::Session as Session>::ClientConfig { | ||
| quinn_noise::NoiseClientConfig { | ||
| keypair: config.keypair.clone_keypair(), | ||
| psk: config.psk, | ||
| alpn: b"libp2p".to_vec(), | ||
| remote_public_key, | ||
| keylogger: config.keylogger.clone(), | ||
| } | ||
| .into() | ||
| } | ||
|
|
||
| fn supported_quic_versions() -> Vec<u32> { | ||
| quinn_noise::SUPPORTED_QUIC_VERSIONS.to_vec() | ||
| } | ||
|
|
||
| fn default_quic_version() -> u32 { | ||
| quinn_noise::DEFAULT_QUIC_VERSION | ||
| } | ||
|
|
||
| fn peer_id(session: &Self::Session) -> Option<PeerId> { | ||
| Some(session.peer_identity()?.to_peer_id()) | ||
| } | ||
|
|
||
| fn extract_public_key(generic_key: libp2p_core::PublicKey) -> Option<Self::PublicKey> { | ||
| let public_key = if let libp2p_core::PublicKey::Ed25519(public_key) = generic_key { | ||
| public_key.encode() | ||
| } else { | ||
| return None; | ||
| }; | ||
| Self::PublicKey::from_bytes(&public_key).ok() | ||
| } | ||
|
|
||
| fn keylogger() -> Self::Keylogger { | ||
| Arc::new(quinn_noise::KeyLogFile::new()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "tls")] | ||
| #[derive(Clone, Copy, Debug)] | ||
| pub struct TlsCrypto; | ||
|
|
||
| #[cfg(feature = "tls")] | ||
| impl Crypto for TlsCrypto { | ||
| type Session = quinn_proto::crypto::rustls::TlsSession; | ||
| type Keylogger = Arc<dyn rustls::KeyLog>; | ||
| type Keypair = libp2p_core::identity::Keypair; | ||
| type PublicKey = libp2p_core::identity::PublicKey; | ||
|
|
||
| fn new_server_config( | ||
| config: &Arc<CryptoConfig<Self>>, | ||
| ) -> <Self::Session as Session>::ServerConfig { | ||
| assert!(config.psk.is_none(), "invalid config"); | ||
| let mut server = crate::tls::make_server_config(&config.keypair).expect("invalid config"); | ||
| if let Some(key_log) = config.keylogger.clone() { | ||
| server.key_log = key_log; | ||
| } | ||
| Arc::new(server) | ||
| } | ||
|
|
||
| fn new_client_config( | ||
| config: &Arc<CryptoConfig<Self>>, | ||
| remote_public: Self::PublicKey, | ||
| ) -> <Self::Session as Session>::ClientConfig { | ||
| assert!(config.psk.is_none(), "invalid config"); | ||
| let mut client = | ||
| crate::tls::make_client_config(&config.keypair, remote_public.to_peer_id()) | ||
| .expect("invalid config"); | ||
| if let Some(key_log) = config.keylogger.clone() { | ||
| client.key_log = key_log; | ||
| } | ||
| Arc::new(client) | ||
| } | ||
|
|
||
| fn supported_quic_versions() -> Vec<u32> { | ||
| quinn_proto::DEFAULT_SUPPORTED_VERSIONS.to_vec() | ||
| } | ||
|
|
||
| fn default_quic_version() -> u32 { | ||
| quinn_proto::DEFAULT_SUPPORTED_VERSIONS[0] | ||
| } | ||
|
|
||
| fn peer_id(session: &Self::Session) -> Option<PeerId> { | ||
| let certificate = session.get_peer_certificates()?.into_iter().next()?; | ||
| Some(crate::tls::extract_peerid_or_panic( | ||
| quinn_proto::Certificate::from(certificate).as_der(), | ||
| )) | ||
| } | ||
|
|
||
| fn extract_public_key(generic_key: libp2p_core::PublicKey) -> Option<Self::PublicKey> { | ||
| Some(generic_key) | ||
| } | ||
|
|
||
| fn keylogger() -> Self::Keylogger { | ||
| Arc::new(rustls::KeyLogFile::new()) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.