relay: sender: receiver: change standart ips
This commit is contained in:
parent
79c9741522
commit
affedf3f3b
5 changed files with 19 additions and 15 deletions
|
|
@ -82,7 +82,7 @@ impl Args {
|
||||||
match &self.command {
|
match &self.command {
|
||||||
Some(Commands::Send { relay, file }) => {
|
Some(Commands::Send { relay, file }) => {
|
||||||
let _ = match sender::send_info(
|
let _ = match sender::send_info(
|
||||||
relay.as_deref().unwrap_or("http://0.0.0.0:8080"),
|
relay.as_deref().unwrap_or("http://0.0.0.0:8000"),
|
||||||
file.as_deref().unwrap_or("test.txt"),
|
file.as_deref().unwrap_or("test.txt"),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
@ -101,19 +101,19 @@ impl Args {
|
||||||
name,
|
name,
|
||||||
}) => {
|
}) => {
|
||||||
let response = receiver::download_info(
|
let response = receiver::download_info(
|
||||||
relay.as_deref().unwrap_or("http://0.0.0.0:8080"),
|
relay.as_deref().unwrap_or("http://0.0.0.0:8000"),
|
||||||
name.as_deref().unwrap_or("None"),
|
name.as_deref().unwrap_or("None"),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
match response {
|
match response {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
debug!("The response is: {:#?}", res);
|
debug!("The response is: {:#?}", res);
|
||||||
let reachable = receiver::ping_sender(&res.ip).await;
|
let reachable = receiver::ping_sender(&res.body.ip).await;
|
||||||
match reachable {
|
match reachable {
|
||||||
Ok(_) => match receiver::download_file(&res, overwrite).await {
|
Ok(_) => match receiver::download_file(&res, overwrite).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Download complete");
|
info!("Download complete");
|
||||||
let _ = match receiver::signal_success(&res.ip).await {
|
let _ = match receiver::signal_success(&res.body.ip).await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use tracing::{debug, error, info};
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
pub async fn download_info(relay: &str, filename: &str) -> Result<TransferInfoRequest> {
|
pub async fn download_info(relay: &str, filename: &str) -> Result<TransferInfoRequest> {
|
||||||
match reqwest::get(format!("{}/download/{}", relay.to_string(), filename)).await {
|
match reqwest::get(format!("{}/download/{}", relay, filename)).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
let json = resp.json::<TransferInfoRequest>().await?;
|
let json = resp.json::<TransferInfoRequest>().await?;
|
||||||
debug!("Json Response: {:#?}", json);
|
debug!("Json Response: {:#?}", json);
|
||||||
|
|
@ -36,11 +36,15 @@ pub async fn download_file(transfer_info: &TransferInfoRequest, overwrite: &bool
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let resp = reqwest::get(format!("http://{}:1300/download_file", &transfer_info.ip)).await?;
|
let resp = reqwest::get(format!(
|
||||||
|
"http://{}:8100/download_file",
|
||||||
|
&transfer_info.body.ip
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
if !resp.status().is_success() {
|
if !resp.status().is_success() {
|
||||||
return Err(Box::new(std::io::Error::new(
|
return Err(Box::new(std::io::Error::new(
|
||||||
std::io::ErrorKind::Other,
|
std::io::ErrorKind::Other,
|
||||||
format!("Failed to download file from {}", &transfer_info.ip),
|
format!("Failed to download file from {}", &transfer_info.body.ip),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let mut dest = File::create(&transfer_info.body.files)?;
|
let mut dest = File::create(&transfer_info.body.files)?;
|
||||||
|
|
@ -52,7 +56,7 @@ pub async fn download_file(transfer_info: &TransferInfoRequest, overwrite: &bool
|
||||||
|
|
||||||
pub async fn ping_sender(sender: &String) -> Result<bool> {
|
pub async fn ping_sender(sender: &String) -> Result<bool> {
|
||||||
debug!("Pinging Sender on {:#?}", sender);
|
debug!("Pinging Sender on {:#?}", sender);
|
||||||
match reqwest::get(format!("http://{}:1300/ping", sender)).await {
|
match reqwest::get(format!("http://{}:8100/ping", sender)).await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
debug!("Sender directly reachable");
|
debug!("Sender directly reachable");
|
||||||
debug!("Response is: {:#?}", resp);
|
debug!("Response is: {:#?}", resp);
|
||||||
|
|
@ -69,7 +73,7 @@ pub async fn signal_success(sender: &String) -> Result<()> {
|
||||||
debug!("Signaling shutdown to {:#?}", sender);
|
debug!("Signaling shutdown to {:#?}", sender);
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
let _ = client
|
let _ = client
|
||||||
.post(format!("http://{}:1300/shutdown", sender))
|
.post(format!("http://{}:8100/shutdown", sender))
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ pub async fn start_server(port: Option<&i32>, listen_addr: Option<&String>) {
|
||||||
};
|
};
|
||||||
let app_port = match port {
|
let app_port = match port {
|
||||||
Some(port) => port.to_string(),
|
Some(port) => port.to_string(),
|
||||||
None => env::var("APP_PORT").unwrap_or("1323".to_string()),
|
None => env::var("APP_PORT").unwrap_or("8000".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("Server configured to accept connections on host {app_host}...");
|
debug!("Server configured to accept connections on host {app_host}...");
|
||||||
|
|
@ -86,12 +86,12 @@ async fn download_info(
|
||||||
(
|
(
|
||||||
StatusCode::NOT_FOUND,
|
StatusCode::NOT_FOUND,
|
||||||
Json(TransferInfoRequest {
|
Json(TransferInfoRequest {
|
||||||
ip: "".to_string(),
|
|
||||||
name: "".to_string(),
|
name: "".to_string(),
|
||||||
message: "error".to_string(),
|
message: "error".to_string(),
|
||||||
body: TransferInfoBody {
|
body: TransferInfoBody {
|
||||||
keyword: "".to_string(),
|
keyword: "".to_string(),
|
||||||
files: "".to_string(),
|
files: "".to_string(),
|
||||||
|
ip: "".to_string(),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
@ -107,12 +107,12 @@ async fn upload_info(
|
||||||
debug!("Got upload request from {}", addr.ip().to_string());
|
debug!("Got upload request from {}", addr.ip().to_string());
|
||||||
let mut data = shared_state.data.lock().unwrap();
|
let mut data = shared_state.data.lock().unwrap();
|
||||||
let t_request = TransferInfoRequest {
|
let t_request = TransferInfoRequest {
|
||||||
ip: addr.ip().to_string(),
|
|
||||||
name: generate_random_name(),
|
name: generate_random_name(),
|
||||||
message: "created".to_string(),
|
message: "created".to_string(),
|
||||||
body: TransferInfoBody {
|
body: TransferInfoBody {
|
||||||
keyword: payload.keyword,
|
keyword: payload.keyword,
|
||||||
files: payload.files,
|
files: payload.files,
|
||||||
|
ip: payload.ip,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
data.push(t_request.clone());
|
data.push(t_request.clone());
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ lazy_static! {
|
||||||
pub async fn serf_file(path: &String) {
|
pub async fn serf_file(path: &String) {
|
||||||
debug!("Sender starting...");
|
debug!("Sender starting...");
|
||||||
let app_host = "0.0.0.0".to_string();
|
let app_host = "0.0.0.0".to_string();
|
||||||
let app_port = "1300".to_string();
|
let app_port = "8100".to_string();
|
||||||
debug!("Server configured to accept connections on host {app_host}...");
|
debug!("Server configured to accept connections on host {app_host}...");
|
||||||
debug!("Server configured to listen connections on port {app_port}...");
|
debug!("Server configured to listen connections on port {app_port}...");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct TransferInfoRequest {
|
pub struct TransferInfoRequest {
|
||||||
pub ip: String,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub body: TransferInfoBody,
|
pub body: TransferInfoBody,
|
||||||
|
|
@ -12,17 +11,18 @@ pub struct TransferInfoRequest {
|
||||||
pub struct TransferInfoBody {
|
pub struct TransferInfoBody {
|
||||||
pub keyword: String,
|
pub keyword: String,
|
||||||
pub files: String,
|
pub files: String,
|
||||||
|
pub ip: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TransferInfoRequest {
|
impl TransferInfoRequest {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
ip: "".to_string(),
|
|
||||||
name: "".to_string(),
|
name: "".to_string(),
|
||||||
message: "".to_string(),
|
message: "".to_string(),
|
||||||
body: TransferInfoBody {
|
body: TransferInfoBody {
|
||||||
keyword: "".to_string(),
|
keyword: "".to_string(),
|
||||||
files: "".to_string(),
|
files: "".to_string(),
|
||||||
|
ip: "".to_string(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue