Compare commits

..

No commits in common. "42d0557612bcc102aa6b74be3b19f2028b7a9a47" and "517052f28bcb9a0c1be2420606e3e01a0c080a0c" have entirely different histories.

6 changed files with 16 additions and 56 deletions

2
Cargo.lock generated
View File

@ -45,7 +45,7 @@ checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01"
[[package]]
name = "lookaround"
version = "0.1.2"
version = "0.1.0"
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.2"
version = "0.1.1"
[dependencies]
mac_address = "1.1.2"

View File

@ -77,5 +77,3 @@ 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.

View File

@ -1,5 +0,0 @@
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_

View File

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