Compare commits

...

8 Commits

Author SHA1 Message Date
_ 42d0557612 release: bump to 0.1.2 2021-12-06 21:21:12 -06:00
_ 494c44fbcf ♻️ refactor: pass address / port params to subcommands
Needed to land CLI arg changes eventually
2021-12-06 21:21:12 -06:00
_ f47fb4f1ba 🐛 bug: flip hashmap key and value so peers are de-duped by IP instead of claimed MAC. 2021-12-06 21:21:12 -06:00
_ 4955119074 📝 add issue for CLI args 2021-12-06 21:21:12 -06:00
_ fd4062416e 💄 hide port from output since it's alwasy 9040 2021-12-06 21:21:12 -06:00
_ 258cab8e4d 📝 brainstorming 2021-12-06 21:21:12 -06:00
_ d0b15c8397 📝 document issue I noticed at work 2021-12-06 21:21:12 -06:00
_ c1992fd562 🐛 bug: forgot to check in Cargo.lock after the version bump 2021-12-06 21:21:12 -06:00
6 changed files with 56 additions and 16 deletions

2
Cargo.lock generated
View File

@ -45,7 +45,7 @@ checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01"
[[package]]
name = "lookaround"
version = "0.1.0"
version = "0.1.2"
dependencies = [
"mac_address",
"rand",

View File

@ -9,7 +9,7 @@ license = "AGPL-3.0"
name = "lookaround"
readme = "README.md"
repository = "https://six-five-six-four.com/git/reactor/lookaround"
version = "0.1.1"
version = "0.1.2"
[dependencies]
mac_address = "1.1.2"

View File

@ -77,3 +77,5 @@ Use the [kazupon Git commit message convention](https://github.com/kazupon/git-c
## This Git repo
This repo's upstream is https://six-five-six-four.com/git/reactor/lookaround.
I don't use GitHub issues, so issues are in issues.md in the repo.

5
ideas.md Normal file
View File

@ -0,0 +1,5 @@
Cool ideas that can be done but probably won't be.
- Command for shell substituting IPs into commands
- Arbitrary TCP forwarding of (stdin? stdout? TCP?)
- Netcat replacement "Just send a file" _including filename_

30
issues.md Normal file
View File

@ -0,0 +1,30 @@
**Issues**
Just doing ULIDs cause `rusty_ulid` makes it easy.
# 01FP9843V1J3H9JMHXFPJSV2QJ
Have to disable VirtualBox virtual interface thingy to make it work.
Might also misbehave on systems with both Ethernet and WiFi connections.
I think this is because the `UdpSocket`, when I tell it to bind to
`0.0.0.0`, doesn't actually bind to all interfaces, it picks an interface
and binds to it.
I don't have any systems at home to replicate this on. And if I have
to poll multiple sockets, I'll probably just drag in Tokio even
though I was hoping not to use it - It's nicer than threading.
I don't think Tokio has a way to iterate over network interfaces
and get their IPs, so I might have to find another dependency
for that. I think on Linux I can get it from `/sys/class/net` but
I can't remember the trick for that. I think last time I did this
(for that work project) I just punted to Qt.
# 01FP9A272Q94Y08MAKX7BFT11M
Need CLI args
I don't know if this multicast addr and this port are unused.
Having CLI args lets us work around other apps.

View File

@ -76,23 +76,26 @@ fn main () -> Result <(), AppError> {
Err(e) => println!("{:?}", e),
}
match args.next ().as_ref ().map (|s| &s[..]) {
let subcommand: Option <String> = args.next ();
let mut common_params = CommonParams::default ();
match subcommand.as_ref ().map (|x| &x[..]) {
None => return Err (CliArgError::MissingSubcommand.into ()),
Some ("client") => client ()?,
Some ("server") => server ()?,
Some ("client") => client (&common_params)?,
Some ("server") => server (&common_params)?,
Some (x) => return Err (CliArgError::UnknownSubcommand (x.to_string ()).into ()),
}
Ok (())
}
fn client () -> Result <(), AppError> {
fn client (common_params: &CommonParams) -> Result <(), AppError> {
use rand::RngCore;
let params = CommonParams::default ();
let socket = UdpSocket::bind ("0.0.0.0:0")?;
socket.join_multicast_v4 (&params.multicast_addr, &([0u8, 0, 0, 0].into ()))?;
socket.join_multicast_v4 (&common_params.multicast_addr, &([0u8, 0, 0, 0].into ()))?;
socket.set_read_timeout (Some (Duration::from_millis (1_000)))?;
let mut idem_id = [0u8; 8];
@ -104,7 +107,7 @@ fn client () -> Result <(), AppError> {
}.to_vec ()?;
for _ in 0..10 {
socket.send_to (&msg, (params.multicast_addr, params.server_port))?;
socket.send_to (&msg, (common_params.multicast_addr, common_params.server_port))?;
std::thread::sleep (Duration::from_millis (100));
}
@ -123,16 +126,16 @@ fn client () -> Result <(), AppError> {
_ => continue,
};
peers.insert (peer_mac_addr, remote_addr);
peers.insert (remote_addr, peer_mac_addr);
}
let mut peers: Vec <_> = peers.into_iter ().collect ();
peers.sort ();
println! ("Found {} peers:", peers.len ());
for (mac, ip) in &peers {
for (ip, mac) in &peers {
match mac {
Some (mac) => println! ("{} = {}", MacAddress::new (*mac), ip),
Some (mac) => println! ("{} = {}", MacAddress::new (*mac), ip.ip ()),
None => println! ("<Unknown> = {}", ip),
}
}
@ -140,16 +143,16 @@ fn client () -> Result <(), AppError> {
Ok (())
}
fn server () -> Result <(), AppError> {
fn server (common_params: &CommonParams) -> Result <(), AppError>
{
let our_mac = get_mac_address ()?.map (|x| x.bytes ());
if our_mac.is_none () {
println! ("Warning: Can't find our own MAC address. We won't be able to respond to MAC-specific lookaround requests");
}
let params = CommonParams::default ();
let socket = UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, params.server_port)).unwrap ();
let socket = UdpSocket::bind (SocketAddrV4::new (Ipv4Addr::UNSPECIFIED, common_params.server_port)).unwrap ();
socket.join_multicast_v4 (&params.multicast_addr, &([0u8, 0, 0, 0].into ())).unwrap ();
socket.join_multicast_v4 (&common_params.multicast_addr, &([0u8, 0, 0, 0].into ())).unwrap ();
let mut recent_idem_ids = Vec::with_capacity (32);