# The Nexrs dev journal ## Task 1: Getting the machine's local IP address This proved to be harder than I suspected, and naturally with my luck, not very portable. I opted for a Linux-exclusive solution: A combination of `ifconfig` and `grep`. Rust has a nice set of tools for building and executing commands on the local machine. `grep` appears to be having issues, however, so we're gonna execute `ifconfig` and do the string searching/parsing in Rust itself. Well hot damn. Took us a day and a half but we finally got it working. Rust's explicit types are sometimes extremely brutal when my strongest languages are Python and Javascript. We have a function that, through a dirty, ugly method, finds the machine's local IP(v4) address. With that, we'll naively scan other IPs in our range for other Nexrs servers. Easy and bad! Let's go! ## Task 2: Scanning for other servers The idea behind this one is straightforward. Hold the first 3 octets of the IP address constant, and step the last one up one. Attempt to connect on our port. If we connect, send a heartbeat (`0xFF`). If we received a return heartbeat (`0xFE`), add this machine to our list of servers. This SHOULD be straightforward, but this is Rust and me we're talking about, so... Good news! It actually was straightforward. The `attempt_heartbeat()` function simply looks for a server listening on port 1738. If it succeeds, it prints out a confirmation. If it fails, prints out a failure message. E.z. We'll expand this to do some additional checking: * We'll keep sending unicode literals. It's easy. * Confirm that a proper message is received (`"hbc"`) * Later, do some encryption (via TLS, maybe?) For now, we'll work on listening and responding. Then we can finally get a small network going! ## Task 3: Listen, and listen good. Now we set about on the other half of communication: Listening. We're going to explore the `TcpListener` API, and use pattern matching to handle any of the various input messages we might receive.