fix(sender,receiver): fixed bug with sender and receiver trying to connect to https with http address
to fix this bug i had to change the way a user can support a relay address. the user can no longer provide the address in the form "0.0.0.0:8000" instead he has to use "ws://0.0.0.0:8000" or "wss://0.0.0.0:8000" the switch between ws/http or wss/https is handle by the program
This commit is contained in:
parent
d098ea41f6
commit
42e4a63a6a
7 changed files with 25 additions and 13 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -406,7 +406,7 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "caesar-transfer-iu"
|
name = "caesar-transfer-iu"
|
||||||
version = "0.2.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-gcm",
|
"aes-gcm",
|
||||||
"axum 0.7.5",
|
"axum 0.7.5",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "caesar-transfer-iu"
|
name = "caesar-transfer-iu"
|
||||||
version = "0.2.0"
|
version = "0.3.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "src/build.rs"
|
build = "src/build.rs"
|
||||||
authors = ["Manuel Keidel", "Patryk Hegenberg", "Krzysztof Stankiewicz"]
|
authors = ["Manuel Keidel", "Patryk Hegenberg", "Krzysztof Stankiewicz"]
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use crate::relay::transfer::TransferResponse;
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
pub async fn download_info(relay: &str, name: &str) -> Result<TransferResponse> {
|
pub async fn download_info(relay: &str, name: &str) -> Result<TransferResponse> {
|
||||||
let url = String::from("http://") + relay;
|
let url = String::from(relay);
|
||||||
let hashed_name = Sha256::digest(name.as_bytes());
|
let hashed_name = Sha256::digest(name.as_bytes());
|
||||||
let hashed_string = hex::encode(hashed_name);
|
let hashed_string = hex::encode(hashed_name);
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ pub async fn download_info(relay: &str, name: &str) -> Result<TransferResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn download_success(relay: &str, name: &str) -> Result<()> {
|
pub async fn download_success(relay: &str, name: &str) -> Result<()> {
|
||||||
let url = String::from("http://") + relay;
|
let url = String::from(relay);
|
||||||
let hashed_name = Sha256::digest(name.as_bytes());
|
let hashed_name = Sha256::digest(name.as_bytes());
|
||||||
let hashed_string = hex::encode(hashed_name);
|
let hashed_string = hex::encode(hashed_name);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod http_client;
|
pub mod http_client;
|
||||||
|
|
||||||
use crate::receiver::client as receiver;
|
use crate::{receiver::client as receiver, sender::util::replace_protocol};
|
||||||
|
|
||||||
use tokio_tungstenite::{
|
use tokio_tungstenite::{
|
||||||
connect_async,
|
connect_async,
|
||||||
|
|
@ -47,9 +47,12 @@ use tokio_tungstenite::{
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
pub async fn start_receiver(relay: &str, name: &str) {
|
pub async fn start_receiver(relay: &str, name: &str) {
|
||||||
let res = http_client::download_info(relay, name).await.unwrap();
|
let http_url = replace_protocol(relay);
|
||||||
|
let res = http_client::download_info(http_url.as_str(), name)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
debug!("Got room_id from Server: {:?}", res);
|
debug!("Got room_id from Server: {:?}", res);
|
||||||
let res_ip = res.ip + ":9000";
|
let res_ip = String::from("ws://") + res.ip.as_str() + ":9000";
|
||||||
|
|
||||||
if let Err(local_err) = start_ws_com(res_ip.as_str(), res.local_room_id.as_str()).await {
|
if let Err(local_err) = start_ws_com(res_ip.as_str(), res.local_room_id.as_str()).await {
|
||||||
debug!("Failed to connect local: {local_err}");
|
debug!("Failed to connect local: {local_err}");
|
||||||
|
|
@ -57,7 +60,7 @@ pub async fn start_receiver(relay: &str, name: &str) {
|
||||||
debug!("Failed to connect remote: {relay_err}");
|
debug!("Failed to connect remote: {relay_err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let success = http_client::download_success(relay, name).await;
|
let success = http_client::download_success(http_url.as_str(), name).await;
|
||||||
match success {
|
match success {
|
||||||
Ok(()) => debug!("Success"),
|
Ok(()) => debug!("Success"),
|
||||||
Err(e) => error!("Error: {e:?}"),
|
Err(e) => error!("Error: {e:?}"),
|
||||||
|
|
@ -72,7 +75,7 @@ pub async fn start_receiver(relay: &str, name: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_ws_com(relay: &str, name: &str) -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn start_ws_com(relay: &str, name: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let url = String::from("ws://") + relay + "/ws";
|
let url = String::from(relay) + "/ws";
|
||||||
let Ok(mut request) = url.into_client_request() else {
|
let Ok(mut request) = url.into_client_request() else {
|
||||||
println!("Error: Failed to create request.");
|
println!("Error: Failed to create request.");
|
||||||
return Err("Failed to create request".into());
|
return Err("Failed to create request".into());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::sender::http_client::send_info;
|
use crate::sender::http_client::send_info;
|
||||||
use crate::sender::util::hash_random_name;
|
use crate::sender::util::{hash_random_name, replace_protocol};
|
||||||
use crate::shared::{
|
use crate::shared::{
|
||||||
packets::{
|
packets::{
|
||||||
list_packet, packet::Value, ChunkPacket, HandshakePacket, HandshakeResponsePacket,
|
list_packet, packet::Value, ChunkPacket, HandshakePacket, HandshakeResponsePacket,
|
||||||
|
|
@ -135,7 +135,7 @@ fn on_create_room(
|
||||||
|
|
||||||
let send_url = url.to_string();
|
let send_url = url.to_string();
|
||||||
let h_name = hash_name.to_string();
|
let h_name = hash_name.to_string();
|
||||||
let server_url = String::from("http://") + relay.as_str();
|
let server_url = replace_protocol(relay.as_str());
|
||||||
let res = std::thread::spawn(move || {
|
let res = std::thread::spawn(move || {
|
||||||
tokio::runtime::Builder::new_current_thread()
|
tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ pub async fn start_sender(relay: Arc<String>, files: Arc<Vec<String>>) {
|
||||||
});
|
});
|
||||||
let local_thread = task::spawn(async move {
|
let local_thread = task::spawn(async move {
|
||||||
connect_to_server(
|
connect_to_server(
|
||||||
Arc::new(String::from("0.0.0.0:9000")),
|
Arc::new(String::from("ws://0.0.0.0:9000")),
|
||||||
local_files.clone(),
|
local_files.clone(),
|
||||||
Some(local_room_id),
|
Some(local_room_id),
|
||||||
local_relay.clone(),
|
local_relay.clone(),
|
||||||
|
|
@ -146,7 +146,7 @@ async fn connect_to_server(
|
||||||
tx: mpsc::Sender<()>,
|
tx: mpsc::Sender<()>,
|
||||||
is_local: bool,
|
is_local: bool,
|
||||||
) {
|
) {
|
||||||
let url = format!("ws://{}/ws", relay);
|
let url = format!("{}/ws", relay);
|
||||||
let message_relay = format!("{}", message_server);
|
let message_relay = format!("{}", message_server);
|
||||||
let transfer_name = format!("{}", transfer_name);
|
let transfer_name = format!("{}", transfer_name);
|
||||||
match url.clone().into_client_request() {
|
match url.clone().into_client_request() {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,15 @@ pub fn hash_random_name(name: String) -> String {
|
||||||
hex::encode(hashed_name)
|
hex::encode(hashed_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn replace_protocol(address: &str) -> String {
|
||||||
|
let mut result = address.to_string();
|
||||||
|
result = result.replace("ws://", "http://");
|
||||||
|
|
||||||
|
result = result.replace("wss://", "https://");
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue