Compare commits
8 Commits
517052f28b
...
42d0557612
Author | SHA1 | Date |
---|---|---|
_ | 42d0557612 | |
_ | 494c44fbcf | |
_ | f47fb4f1ba | |
_ | 4955119074 | |
_ | fd4062416e | |
_ | 258cab8e4d | |
_ | d0b15c8397 | |
_ | c1992fd562 |
|
@ -45,7 +45,7 @@ checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01"
|
|||
|
||||
[[package]]
|
||||
name = "lookaround"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"mac_address",
|
||||
"rand",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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_
|
|
@ -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.
|
31
src/main.rs
31
src/main.rs
|
@ -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 (¶ms.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 (¶ms.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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue