Browse Source

Add binary

interface-2
Lev 3 years ago
parent
commit
1caa0324cf
  1. 5
      Cargo.toml
  2. 8
      src/bin/worker.rs
  3. 3
      src/interfaces/ip.rs
  4. 7
      src/ironforce.rs
  5. 4
      src/lib.rs

5
Cargo.toml

@ -25,3 +25,8 @@ spin = "0.9.2"
[profile.dev.package.num-bigint-dig]
opt-level = 3
[[bin]]
name = "worker"
src = "src/worker.rs"
required-features = ["std"]

8
src/bin/worker.rs

@ -0,0 +1,8 @@
use ironforce::IronForce;
use ironforce::res::IFResult;
fn main() -> IFResult<()> {
let ironforce = IronForce::new();
let (thread, _) = ironforce.launch_main_loop(500);
thread.join().unwrap()
}

3
src/interfaces/ip.rs

@ -3,7 +3,6 @@ use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
use core::ops::RangeInclusive;
#[cfg(test)]
use core::str::FromStr;
use core::time::Duration;
use rayon::prelude::*;
@ -201,7 +200,7 @@ impl Interface for IPInterface {
));
}
// We do a peer exchange every 30 iterations
if self.main_loop_iterations % 30 == 0 {
if self.main_loop_iterations % 30 == 0 && !self.connections.is_empty() {
let connection_index =
(self.main_loop_iterations / 30) as usize % self.connections.len();
IPInterface::request_peers(&mut self.connections[connection_index])?;

7
src/ironforce.rs

@ -83,7 +83,7 @@ impl IronForce {
has_background_worker: false,
processed_messages: vec![],
tunnel_counters: Default::default(),
auto_save: false,
auto_save: true,
}
}
@ -353,6 +353,11 @@ impl IronForce {
})
}
#[cfg(feature = "std")]
pub fn from_file(filename: alloc::string::String) -> IFResult<Self> {
Self::from_serialization_data(serde_json::from_str(std::fs::read_to_string(filename)?.as_str())?)
}
#[cfg(feature = "std")]
pub fn save_to_file(&self, filename: Option<alloc::string::String>) -> IFResult<()> {
std::fs::write(

4
src/lib.rs

@ -22,8 +22,8 @@ pub mod interfaces;
pub mod res;
mod tunnel;
#[cfg(std)]
use crate::interfaces::ip;
pub use ironforce::IronForce;
#[cfg(test)]
mod tests {

Loading…
Cancel
Save