Skip to content
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

fix(torii-relay): remove tls for ws #2361

Merged
merged 1 commit into from
Aug 29, 2024
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
15 changes: 3 additions & 12 deletions crates/torii/libp2p/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::io::Read;
use std::net::Ipv4Addr;
use std::path::Path;
use std::str::FromStr;
Expand Down Expand Up @@ -95,21 +94,13 @@ impl<P: Provider + Sync> Relay<P> {
})
.expect("Failed to create WebRTC transport")
.with_other_transport(|key| {
let mut transport = websocket::WsConfig::new(
let transport = websocket::WsConfig::new(
dns::tokio::Transport::system(tcp::tokio::Transport::new(
tcp::Config::default(),
))
.unwrap(),
);

let rcgen_cert =
rcgen::generate_simple_self_signed(vec!["localhost".to_string()]).unwrap();
let priv_key = websocket::tls::PrivateKey::new(rcgen_cert.key_pair.serialize_der());
let bytes: Result<Vec<_>, _> = rcgen_cert.cert.der().bytes().collect();
let cert = websocket::tls::Certificate::new(bytes.unwrap());
transport
.set_tls_config(websocket::tls::Config::new(priv_key, vec![cert]).unwrap());

transport
.upgrade(Version::V1)
.authenticate(noise::Config::new(key).unwrap())
Expand Down Expand Up @@ -168,10 +159,10 @@ impl<P: Provider + Sync> Relay<P> {
.with(Protocol::WebRTCDirect);
swarm.listen_on(listen_addr_webrtc.clone())?;

// WSS
// WS
let listen_addr_wss = Multiaddr::from(Ipv4Addr::UNSPECIFIED)
.with(Protocol::Tcp(port_websocket))
.with(Protocol::Wss("/".to_string().into()));
.with(Protocol::Ws("/".to_string().into()));
swarm.listen_on(listen_addr_wss.clone())?;

// Clients will send their messages to the "message" topic
Expand Down
Loading