Compare commits
No commits in common. "42d0557612bcc102aa6b74be3b19f2028b7a9a47" and "517052f28bcb9a0c1be2420606e3e01a0c080a0c" have entirely different histories.
42d0557612
...
517052f28b
|
@ -45,7 +45,7 @@ checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lookaround"
|
name = "lookaround"
|
||||||
version = "0.1.2"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"mac_address",
|
"mac_address",
|
||||||
"rand",
|
"rand",
|
||||||
|
|
|
@ -9,7 +9,7 @@ license = "AGPL-3.0"
|
||||||
name = "lookaround"
|
name = "lookaround"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://six-five-six-four.com/git/reactor/lookaround"
|
repository = "https://six-five-six-four.com/git/reactor/lookaround"
|
||||||
version = "0.1.2"
|
version = "0.1.1"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mac_address = "1.1.2"
|
mac_address = "1.1.2"
|
||||||
|
|
|
@ -77,5 +77,3 @@ Use the [kazupon Git commit message convention](https://github.com/kazupon/git-c
|
||||||
|
|
||||||
## This Git repo
|
## This Git repo
|
||||||
This repo's upstream is https://six-five-six-four.com/git/reactor/lookaround.
|
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
5
ideas.md
|
@ -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_
|
|
30
issues.md
30
issues.md
|
@ -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.
|
|
31
src/main.rs
31
src/main.rs
|
@ -76,26 +76,23 @@ fn main () -> Result <(), AppError> {
|
||||||
Err(e) => println!("{:?}", e),
|
Err(e) => println!("{:?}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
let subcommand: Option <String> = args.next ();
|
match args.next ().as_ref ().map (|s| &s[..]) {
|
||||||
|
|
||||||
let mut common_params = CommonParams::default ();
|
|
||||||
|
|
||||||
match subcommand.as_ref ().map (|x| &x[..]) {
|
|
||||||
None => return Err (CliArgError::MissingSubcommand.into ()),
|
None => return Err (CliArgError::MissingSubcommand.into ()),
|
||||||
Some ("client") => client (&common_params)?,
|
Some ("client") => client ()?,
|
||||||
Some ("server") => server (&common_params)?,
|
Some ("server") => server ()?,
|
||||||
Some (x) => return Err (CliArgError::UnknownSubcommand (x.to_string ()).into ()),
|
Some (x) => return Err (CliArgError::UnknownSubcommand (x.to_string ()).into ()),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn client (common_params: &CommonParams) -> Result <(), AppError> {
|
fn client () -> Result <(), AppError> {
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
|
||||||
|
let params = CommonParams::default ();
|
||||||
let socket = UdpSocket::bind ("0.0.0.0:0")?;
|
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 (¶ms.multicast_addr, &([0u8, 0, 0, 0].into ()))?;
|
||||||
socket.set_read_timeout (Some (Duration::from_millis (1_000)))?;
|
socket.set_read_timeout (Some (Duration::from_millis (1_000)))?;
|
||||||
|
|
||||||
let mut idem_id = [0u8; 8];
|
let mut idem_id = [0u8; 8];
|
||||||
|
@ -107,7 +104,7 @@ fn client (common_params: &CommonParams) -> Result <(), AppError> {
|
||||||
}.to_vec ()?;
|
}.to_vec ()?;
|
||||||
|
|
||||||
for _ in 0..10 {
|
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));
|
std::thread::sleep (Duration::from_millis (100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,16 +123,16 @@ fn client (common_params: &CommonParams) -> Result <(), AppError> {
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
peers.insert (remote_addr, peer_mac_addr);
|
peers.insert (peer_mac_addr, remote_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut peers: Vec <_> = peers.into_iter ().collect ();
|
let mut peers: Vec <_> = peers.into_iter ().collect ();
|
||||||
peers.sort ();
|
peers.sort ();
|
||||||
|
|
||||||
println! ("Found {} peers:", peers.len ());
|
println! ("Found {} peers:", peers.len ());
|
||||||
for (ip, mac) in &peers {
|
for (mac, ip) in &peers {
|
||||||
match mac {
|
match mac {
|
||||||
Some (mac) => println! ("{} = {}", MacAddress::new (*mac), ip.ip ()),
|
Some (mac) => println! ("{} = {}", MacAddress::new (*mac), ip),
|
||||||
None => println! ("<Unknown> = {}", ip),
|
None => println! ("<Unknown> = {}", ip),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,16 +140,16 @@ fn client (common_params: &CommonParams) -> Result <(), AppError> {
|
||||||
Ok (())
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server (common_params: &CommonParams) -> Result <(), AppError>
|
fn server () -> Result <(), AppError> {
|
||||||
{
|
|
||||||
let our_mac = get_mac_address ()?.map (|x| x.bytes ());
|
let our_mac = get_mac_address ()?.map (|x| x.bytes ());
|
||||||
if our_mac.is_none () {
|
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");
|
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 (¶ms.multicast_addr, &([0u8, 0, 0, 0].into ())).unwrap ();
|
||||||
|
|
||||||
let mut recent_idem_ids = Vec::with_capacity (32);
|
let mut recent_idem_ids = Vec::with_capacity (32);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue