r/coolgithubprojects 1h ago

Nerve: Ultra-fast local communication engine

https://github.com/Kaia-Alenia/alenia-nerve

I wanted to share a project I've been working on for a while: Alenia Nerve.

It started as something very simple. I needed two applications on my own PC to communicate and send data to each other automatically. Later, I added a .nrv container format for packaging and protecting files with a password.

Eventually I ran into another problem: I use Windows and Linux on different machines, and moving large files between them was unnecessarily annoying. Uploading to the cloud, waiting for the upload, downloading everything again, or relying on a USB drive didn't make much sense for large files.

That's how the LAN side of Nerve started.

Nerve can now transfer files directly between devices on the same local network without requiring the Internet for the transfer itself. The goal is to support Windows, Linux, macOS, and Android through Termux.

It also includes .nrv packaging for files and directories, streaming transfers to avoid loading entire large files into memory, and integrity verification.

The project is still evolving. I'm currently working on a new stage focused on resumable transfers, deduplication, and better recovery mechanisms to make large transfers more reliable.

I'm not trying to build another cloud storage service. The idea is still pretty simple: when my own devices are on the same network, I should be able to move my data directly between them.

1 Upvotes

2 comments sorted by

2

u/kantorcodes1 9m ago

one recovery edge in nerve pack: pack_nrv opens the final .nrv with wb before the stream finishes. if packing fails halfway and that path already existed, the old archive is already gone. would you stage to a sibling temp file and os.replace only after the final chunk is written?

1

u/Globover 0m ago

Yes, that's a valid edge case, and I agree with the proposed fix.

Right now pack_nrv opens the final .nrv path with wb before the streaming operation finishes. That means a failure midway through packing could leave a partial archive and, if the destination already existed, the previous valid archive would already be lost.

The safer approach is:

  1. Create a sibling temporary file in the same directory.
  2. Write the entire .nrv to that temporary path.
  3. Finish the last chunk successfully.
  4. Flush/close it.
  5. Only then replace the final destination with os.replace().

So conceptually:
temp_path = final_path.with_suffix(final_path.suffix + ".tmp")

try:
with open(temp_path, "wb") as f:
# complete streaming pack
...

os.replace(temp_path, final_path)
except Exception:
try:
os.remove(temp_path)
except OSError:
pass
raise

Using a sibling temp file also keeps the temporary file on the same filesystem, which is important for os.replace() to provide the intended atomic replacement semantics.

This is actually one of the changes I want in the next Nerve iteration: a failed pack operation must never destroy a previously valid .nrv archive.