This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: add WebRTC transport #12529
Open
melekes
wants to merge
79
commits into
paritytech:master
Choose a base branch
from
melekes:anton/webrtc-transport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add WebRTC transport #12529
Changes from 17 commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
81bdbdf
upgrade libp2p to 0.50.0
melekes 21cf90c
on_swarm_event and on_connection_handler_event
melekes 8a227e4
replace `Swarm::new` with `Swarm::with_threadpool_executor`
melekes 8a97a52
on_swarm_event and on_connection_handler_event part 2
melekes e9b731b
on_swarm_event and on_connection_handler_event part 3
melekes d27d73a
on_swarm_event and on_connection_handler_event part 4
melekes 672cac2
update libp2p
melekes 41ab633
Merge branch 'master' into anton/upgrade-libp2p-to-0.50.0
melekes 2fa1b2b
libp2p 0.50.0
melekes b3c33b5
rename OutboundQueryCompleted to OutboundQueryProgressed
melekes 20437d7
remove unused var
melekes dbb7bec
accumulate outbound_query_records until query is finished
melekes f793dad
client: add WebRTC transport
melekes 1e6f631
put webrtc certificate within base, not network config directory
melekes 27ef639
Merge branch 'master' into anton/webrtc-transport
melekes a955481
fixes after the merge
melekes 82fd633
fix docs
melekes c6eb8c8
better vars names in tests
melekes f964453
Merge branch 'master' into anton/webrtc-transport
melekes 0db37d0
always give preference to tcp transport
melekes b7070e0
Merge branch 'master' into anton/webrtc-transport
melekes 05238ab
Merge branch 'master' into anton/webrtc-transport
melekes 2f404a4
use udp protocol, not tcp for webrtc
melekes 05fb813
copy warp-sync zombienet test
melekes ce05840
rename test files
melekes f929b72
update test name
melekes 7781776
remove generate-warp-sync-database from webrtc test
melekes 1e153d2
change listen addr in zombienet tests
melekes dcd00f4
Apply suggestions from code review
melekes 1c7a375
bump zombienet version
melekes 727b487
Merge branch 'master' into anton/webrtc-transport
melekes b549d2b
Update zombienet version.
pepoviola 35b971a
Merge branch 'master' into anton/webrtc-transport
melekes 6e9c7ea
Update zombienet/0004-webrtc/test-webrtc.toml
pepoviola 4516910
Update zombienet/0004-webrtc/test-webrtc.toml
pepoviola 41fc433
Update zombienet/0004-webrtc/test-webrtc.toml
pepoviola 722ccad
Update .gitlab-ci.yml
pepoviola be72387
bump version of zombienet and update snaps links (#13359)
pepoviola 22c1a15
Merge branch 'master' into anton/webrtc-transport
melekes c596bb4
Merge branch 'master' into anton/webrtc-transport
melekes 2d35bec
bump zombienet version
melekes a63e5d6
remove unneeded lines from zombienet test
melekes 407ce5a
add missing features
melekes a26fabb
Merge branch 'master' into anton/webrtc-transport
melekes f2ca191
enable logging for bob
melekes 52be5fd
add `--webrtc-certificate-raw` flag for zombienet
melekes b10a5cb
Merge branch 'master' into anton/webrtc-transport
melekes b4b92bf
zombienet: set p2p_cert_hash
melekes a9f2bd7
set p2p_cert_hash for alice
melekes 0764cc9
Merge branch 'master' into anton/webrtc-transport
melekes 1282e57
try to fix unsupported address error
melekes 45c3d64
Merge branch 'master' into anton/webrtc-transport
melekes e4003ef
remove leftovers from merge
melekes 342be2a
add missing dev dep
melekes 2b37e04
rename /webrtc to /webrtc-direct
melekes 8347be8
Merge branch 'master' into anton/webrtc-transport
melekes 62a4658
Revert "rename /webrtc to /webrtc-direct"
melekes a518c81
Revert "Revert "rename /webrtc to /webrtc-direct""
melekes 35ef2e8
disable webrtc for non-validators
melekes ae89a63
add logging to all nodes
melekes ef632a1
Merge branch 'master' into anton/webrtc-transport
melekes 656faf7
trace webrtc package
melekes baf5b8f
Merge branch 'master' into anton/webrtc-transport
melekes 424e319
fixes after merge
melekes e24baa9
fix protocol name
melekes 6025ea4
use libp2p-webrtc dep in CLI
melekes 09efa75
Merge branch 'master' into anton/webrtc-transport
melekes f0f7075
remove webrtc_sctp trace from dave's log
melekes 142b884
bump regex to resolve polkadot companion CI job
melekes 01ba6d2
more logging
melekes 7d4e8e2
set mode to server by default
melekes ff958f8
Revert "bump regex to resolve polkadot companion CI job"
melekes 27ef6c9
Revert "set mode to server by default"
melekes 634ed48
Merge branch 'master' into anton/webrtc-transport
melekes 2647ae6
reduce logging
melekes fb2caf8
Merge branch 'master' into anton/webrtc-transport
melekes c650ae8
Merge branch 'master' into anton/webrtc-transport
melekes 20d33ad
Merge branch 'master' into anton/webrtc-transport
melekes 7d8623a
more logging for dave
melekes 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,121 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2017-2022 Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
|
|
||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use clap::Args; | ||
| use sc_network::config::WebRTCConfig; | ||
| use std::path::PathBuf; | ||
|
|
||
| use crate::error; | ||
|
|
||
| /// The file name of the WebRTC's certificate inside the chain-specific | ||
| /// network config directory. | ||
| const WEBRTC_CERTIFICATE_FILENAME: &str = "webrtc_certificate"; | ||
|
|
||
| /// Parameters used to create the `WebRTCConfig`, which determines the certificate used | ||
| /// for libp2p WebRTC transport. | ||
| #[derive(Debug, Clone, Args)] | ||
| pub struct WebRTCCertificateParams { | ||
| /// The file from which to read the node's WebRTC certificate to use for libp2p networking. | ||
| /// | ||
| /// The contents of the file are parsed as follows: | ||
| /// | ||
| /// The file must contain an ASCII PEM encoded | ||
| /// `webrtc::peer_connection::certificate::RTCCertificate`. | ||
| /// | ||
| /// If the file does not exist, it is created with a newly generated certificate. | ||
| #[clap(long, value_name = "FILE")] | ||
| pub webrtc_certificate_file: Option<PathBuf>, | ||
|
|
||
| /// When set to `true`, a new WebRTC certificate will be created each time you start a node. | ||
| /// | ||
| /// The certificate won't be stored on disk. Use this option only if you DON'T want to preserve | ||
| /// node's WebRTC identity between (re)starts. | ||
| /// | ||
| /// This option takes precedence over `--webrtc-certificate-file` option. | ||
| #[arg(long, value_name = "EPHEMERAL")] | ||
| pub webrtc_certificate_ephemeral: Option<bool>, | ||
| } | ||
|
|
||
| impl WebRTCCertificateParams { | ||
| /// Create a `WebRTCConfig` from the given [`WebRTCCertificateParams`] in the context | ||
| /// of an optional base config storage directory. | ||
| pub fn webrtc_certificate(&self, config_dir: &PathBuf) -> error::Result<WebRTCConfig> { | ||
| if let Some(true) = self.webrtc_certificate_ephemeral { | ||
| return Ok(WebRTCConfig::Ephemeral) | ||
| } | ||
|
|
||
| let filename = self | ||
| .webrtc_certificate_file | ||
| .clone() | ||
| .unwrap_or_else(|| config_dir.join(WEBRTC_CERTIFICATE_FILENAME)); | ||
|
|
||
| Ok(WebRTCConfig::File(filename)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use libp2p::webrtc::tokio::Certificate as WebRTCCertificate; | ||
| use rand::thread_rng; | ||
| use std::fs; | ||
|
|
||
| #[test] | ||
| fn test_webrtc_certificate_file() { | ||
| fn load_cert_and_assert_eq(file: PathBuf, cert: WebRTCCertificate) { | ||
| let params = WebRTCCertificateParams { | ||
| webrtc_certificate_file: Some(file), | ||
| webrtc_certificate_ephemeral: None, | ||
| }; | ||
|
|
||
| let loaded_cert = params | ||
| .webrtc_certificate(&PathBuf::from("not-used")) | ||
| .expect("Creates certificate config") | ||
| .into_certificate() | ||
| .expect("Creates certificate"); | ||
|
|
||
| assert_eq!(cert, loaded_cert, "expected the same certificate"); | ||
| } | ||
|
|
||
| let tmp = tempfile::Builder::new().prefix("alice").tempdir().expect("Creates tempfile"); | ||
| let file = tmp.path().join("mycertificate").to_path_buf(); | ||
|
|
||
| let cert = WebRTCCertificate::generate(&mut thread_rng()).expect("Generates certificate"); | ||
|
|
||
| fs::write(&file, cert.serialize_pem().as_bytes()).expect("Writes certificate"); | ||
| load_cert_and_assert_eq(file.clone(), cert); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_webrtc_certificate_ephemeral() { | ||
| let filepath = PathBuf::from("not-used"); | ||
| let params = WebRTCCertificateParams { | ||
| webrtc_certificate_file: Some(filepath.clone()), | ||
| webrtc_certificate_ephemeral: Some(true), | ||
| }; | ||
|
|
||
| let _loaded_cert = params | ||
| .webrtc_certificate(&filepath) | ||
melekes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .expect("Creates certificate config") | ||
| .into_certificate() | ||
| .expect("Creates certificate"); | ||
|
|
||
| assert!(!filepath.exists(), "Does not create a file"); | ||
| assert!(!filepath.join(WEBRTC_CERTIFICATE_FILENAME).exists(), "Does not create a file"); | ||
| } | ||
| } | ||
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
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.