From f41119634afcfbb645aa53351d0ca1762269dfad Mon Sep 17 00:00:00 2001 From: Akilan Date: Thu, 26 Jun 2025 18:17:07 +0100 Subject: [PATCH] added base p2prc instruction~ --- process/src/SpinProcess.rs | 46 ++++++++++++++++++++------------------ process/src/p2prc.rs | 17 ++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/process/src/SpinProcess.rs b/process/src/SpinProcess.rs index dd6f806..a335352 100644 --- a/process/src/SpinProcess.rs +++ b/process/src/SpinProcess.rs @@ -4,6 +4,7 @@ use std::process::Command; use std::fs::{self, File}; use std::io::{self, Write}; use uuid::Uuid; +use crate::p2prc::*; // Struct representing NodeInfo #[derive(Debug)] @@ -72,26 +73,27 @@ fn spin_process(mut process: Process) -> Process { // Main function fn main() { - println!("Starting SpinProcess..."); - - let node_info = NodeInfo { - ipv4: "192.168.1.20".to_string(), - server_port: "9000".to_string(), - }; - - let process = Process { - id: String::new(), - internal_port_no: "".to_string(), - external_address: "".to_string(), - node_id: "Test".to_string(), - task_name: "ExampleTask".to_string(), - command_to_run_script: "./run_script.sh".to_string(), - command_to_kill_script: "./kill_script.sh".to_string(), - status: false, - domain_name: "example.com".to_string(), - }; - - let updated = spin_process(process); - - println!("Final Process: {:?}", updated); + println!("{}", p2prc_map_port_command("3000", "0.0.0.0")); +// println!("Starting SpinProcess..."); +// +// let node_info = NodeInfo { +// ipv4: "192.168.1.20".to_string(), +// server_port: "9000".to_string(), +// }; +// +// let process = Process { +// id: String::new(), +// internal_port_no: "".to_string(), +// external_address: "".to_string(), +// node_id: "Test".to_string(), +// task_name: "ExampleTask".to_string(), +// command_to_run_script: "./run_script.sh".to_string(), +// command_to_kill_script: "./kill_script.sh".to_string(), +// status: false, +// domain_name: "example.com".to_string(), +// }; +// +// let updated = spin_process(process); +// +// println!("Final Process: {:?}", updated); } \ No newline at end of file diff --git a/process/src/p2prc.rs b/process/src/p2prc.rs index e69de29..0bbac46 100644 --- a/process/src/p2prc.rs +++ b/process/src/p2prc.rs @@ -0,0 +1,17 @@ +use std::io::Error; +use std::process::{Command, Output}; + +// Runs p2prc with custom arguments called. +pub fn run_p2prc_command(arguments: &str) -> Result { + Command::new("p2prc") + .arg(arguments) + .output() +} + +// Runs p2prc map port command +pub fn p2prc_map_port_command(local_port_no: &str, address: &str) -> String{ + let output = run_p2prc_command(&*"--ls".to_string()); + let stdout = String::from_utf8_lossy(&output.unwrap().stdout).to_string(); + stdout +} +