Compare commits
1 commit
7bc26f6bfb
...
215bc5166b
| Author | SHA1 | Date | |
|---|---|---|---|
| 215bc5166b |
8 changed files with 31 additions and 124 deletions
10
README.md
10
README.md
|
|
@ -53,16 +53,6 @@ Path found, destination <0e1fb61e3b38e332868b331740642f41> is 4 hops away via <1
|
|||
|
||||
For now, UDP ports are allocated to links in order from `42000` to `65535`.
|
||||
|
||||
The graph can also be read from a text file listing edges, using option `-G <path>`. An edge is a space-separated list of two node indices. Separation can be any whitespace character. Example:
|
||||
|
||||
```
|
||||
0 1
|
||||
1 2
|
||||
2 0
|
||||
1 3
|
||||
3 4
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[Support me via LiberaPay](https://liberapay.com/tuxmain/donate)
|
||||
|
|
|
|||
0
mitm.py
0
mitm.py
|
|
@ -1,20 +0,0 @@
|
|||
use std::{
|
||||
io::{BufRead, BufReader},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
pub fn read_graph_file(path: &Path) -> Vec<(usize, usize)> {
|
||||
let file = std::fs::OpenOptions::new().read(true).open(path).unwrap();
|
||||
let reader = BufReader::new(file);
|
||||
let mut edges = Vec::new();
|
||||
for line in reader.lines() {
|
||||
let line = line.unwrap();
|
||||
let mut cols = line.split_whitespace();
|
||||
if let (Some(n1), Some(n2)) = (cols.next(), cols.next()) {
|
||||
if let (Ok(n1), Ok(n2)) = (n1.parse(), n2.parse()) {
|
||||
edges.push((n1, n2));
|
||||
}
|
||||
}
|
||||
}
|
||||
edges
|
||||
}
|
||||
66
src/main.rs
66
src/main.rs
|
|
@ -1,14 +1,14 @@
|
|||
mod graph_generator;
|
||||
mod graph_reader;
|
||||
mod graph_render;
|
||||
mod traffic_generator;
|
||||
mod generator;
|
||||
mod render;
|
||||
mod udp;
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, hash_map::Entry},
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
collections::{hash_map::Entry, HashMap}, io::Write, net::Ipv4Addr, path::{PathBuf, Path}, os::{unix::net::{SocketAddr, UnixStream}, linux::net::SocketAddrExt}
|
||||
};
|
||||
|
||||
use rand::Rng;
|
||||
use reticulum::{encode::Encode, sign::FixedKeys, packet::Packet, TestInf};
|
||||
|
||||
/// Generate configuration for local Reticulum networks
|
||||
#[derive(argp::FromArgs)]
|
||||
struct Cli {
|
||||
|
|
@ -18,9 +18,6 @@ struct Cli {
|
|||
/// Generate graph and create Reticulum configs
|
||||
#[argp(switch, short = 'g', long = "gen")]
|
||||
generate: bool,
|
||||
/// Read graph file instead of generating random (one edge per line, node numbers separated by space)
|
||||
#[argp(option, short = 'G')]
|
||||
graph: Option<String>,
|
||||
/// Number of nodes
|
||||
#[argp(option, short = 'n', default = "5")]
|
||||
nodes: usize,
|
||||
|
|
@ -40,17 +37,13 @@ fn main() {
|
|||
let cli: Cli = argp::parse_args_or_exit(argp::DEFAULT);
|
||||
|
||||
if cli.generate {
|
||||
let edges = if let Some(graph_file) = cli.graph {
|
||||
graph_reader::read_graph_file(Path::new(&graph_file))
|
||||
} else {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
assert!(
|
||||
cli.proba >= 0.0 && cli.proba <= 1.0,
|
||||
"Probability should be between 0 and 1."
|
||||
);
|
||||
graph_generator::generate(cli.nodes, cli.proba, &mut rng)
|
||||
};
|
||||
assert!(
|
||||
cli.proba >= 0.0 && cli.proba <= 1.0,
|
||||
"Probability should be between 0 and 1."
|
||||
);
|
||||
let edges = generator::generate(cli.nodes, cli.proba, &mut rng);
|
||||
|
||||
let mut ports = HashMap::new();
|
||||
let mut port: u16 = 42000;
|
||||
|
|
@ -58,8 +51,7 @@ fn main() {
|
|||
|
||||
#[cfg(feature = "render")]
|
||||
if let Some(out_svg) = &cli.render {
|
||||
let mut rng = rand::thread_rng();
|
||||
graph_render::render_to_svg(cli.nodes, &edges, out_svg, &mut rng);
|
||||
render::render_to_svg(cli.nodes, &edges, out_svg, &mut rng);
|
||||
}
|
||||
|
||||
let dir = PathBuf::from(&cli.dir);
|
||||
|
|
@ -142,6 +134,7 @@ forward_port = {}
|
|||
}
|
||||
|
||||
if cli.run {
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut children = Vec::new();
|
||||
for node in std::fs::read_dir(cli.dir).unwrap() {
|
||||
match node {
|
||||
|
|
@ -158,34 +151,31 @@ forward_port = {}
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(4));
|
||||
traffic_generator::generate_traffic(cli.nodes);
|
||||
|
||||
/*let mut socket = UnixStream::connect_addr(&SocketAddr::from_abstract_name(b"rns/n1").unwrap()).unwrap();
|
||||
let mut socket2 = UnixStream::connect_addr(&SocketAddr::from_abstract_name(b"rns/n2").unwrap()).unwrap();
|
||||
let mut socket = UnixStream::connect_addr(&SocketAddr::from_abstract_name(b"rns/n0").unwrap()).unwrap();
|
||||
let mut socket2 = UnixStream::connect_addr(&SocketAddr::from_abstract_name(b"rns/n1").unwrap()).unwrap();
|
||||
let (identity, secret, sk) = reticulum::identity::Identity::generate(&mut rng);
|
||||
let keys = FixedKeys::new(secret, sk);
|
||||
let dest = reticulum::destination::Destination::single_in(&identity, "synthesis", "idontknow");
|
||||
let announce = dest.announce_rnd(&mut rng, Some(b"hello"), &keys);
|
||||
let announce = dest.announce_rnd(&mut rng, None, &keys);
|
||||
let mut announce_buf = Vec::new();
|
||||
announce_buf.push(b'~');
|
||||
announce.encode(&mut announce_buf);
|
||||
let packet = Packet::<TestInf>::from_announce(announce);
|
||||
//dbg!(&packet);
|
||||
dbg!(&packet);
|
||||
packet.encode(&mut announce_buf);
|
||||
announce_buf.push(b'~');
|
||||
//dbg!(&announce_buf);
|
||||
dbg!(&announce_buf);
|
||||
socket.write_all(&announce_buf).unwrap();
|
||||
socket.flush().unwrap();
|
||||
let dest_out = reticulum::destination::Destination::plain_out("synthesis", "idontknow");
|
||||
let dest_out = reticulum::destination::Destination::plain_out("synthesis", "idonknow");
|
||||
let req = reticulum::path_request::PathRequest::new(dest.hash(), &dest_out, None, None);
|
||||
let mut req_buf = Vec::new();
|
||||
req_buf.push(b'~');
|
||||
Packet::<TestInf>::from_path_request(req).encode(&mut req_buf);
|
||||
req_buf.push(b'~');
|
||||
std::thread::sleep(std::time::Duration::from_secs(4));
|
||||
socket2.write_all(&req_buf).unwrap();*/
|
||||
|
||||
socket2.write_all(&req_buf).unwrap();
|
||||
/*loop {
|
||||
let mut buf = Vec::new();
|
||||
dbg!(socket2.re(&mut buf)).ok();
|
||||
dbg!(buf);
|
||||
}*/
|
||||
for mut child in children {
|
||||
child.wait().ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
use reticulum::{
|
||||
TestInf, destination::Destination, encode::Encode, identity::Identity, packet::Packet,
|
||||
sign::FixedKeys,
|
||||
};
|
||||
use std::{
|
||||
io::Write,
|
||||
os::{
|
||||
linux::net::SocketAddrExt,
|
||||
unix::net::{SocketAddr, UnixStream},
|
||||
},
|
||||
};
|
||||
|
||||
pub fn generate_traffic(nodes: usize) {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let mut sockets: Vec<_> = (0..nodes)
|
||||
.map(|i| {
|
||||
UnixStream::connect_addr(
|
||||
&SocketAddr::from_abstract_name(format!("rns/n{i}").as_bytes()).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
|
||||
let identities: Vec<_> = (0..nodes)
|
||||
.map(|_i| {
|
||||
let (identity, secret, sk) = Identity::generate(&mut rng);
|
||||
(identity, FixedKeys::new(secret, sk))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let destinations: Vec<_> = identities
|
||||
.iter()
|
||||
.map(|(identity, keys)| {
|
||||
(
|
||||
Destination::single_in(&identity, "synthesis", "idontknow"),
|
||||
keys,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
for (((destination, keys), _identity), socket) in destinations
|
||||
.iter()
|
||||
.zip(identities.iter())
|
||||
.zip(sockets.iter_mut())
|
||||
{
|
||||
let announce = destination.announce_rnd(&mut rng, Some(b"hello"), *keys);
|
||||
let mut announce_buf = Vec::new();
|
||||
announce_buf.push(b'~');
|
||||
let packet = Packet::<TestInf>::from_announce(announce);
|
||||
packet.encode(&mut announce_buf);
|
||||
announce_buf.push(b'~');
|
||||
socket.write_all(&announce_buf).unwrap();
|
||||
socket.flush().unwrap();
|
||||
}
|
||||
}
|
||||
3
src/udp.rs
Normal file
3
src/udp.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub struct UdpInterface {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue