How t3nsor27/file-sync works
file-sync is a terminal-based LAN peer-to-peer synchronizer. The main workflow is: choose a peer, exchange filesystem trees, compare them, then pull the peer’s changes and show transfer progress. Tree construction and hashing, diffing, sync operation handling, and filesystem updates are distinct stages. Peer owns connection lifecycle; Session implements asynchronous packet transport, while wire provides binary primitives. The README documents the broader sync protocol; sampled excerpts do not show all handler wiring, so uncertain call paths are omitted.
Main entry points: main.cpp TUI and sync · peer.cpp Session transport · fstree.cpp Directory tree · wire.cpp Binary primitives
Components 14
UI and orchestration
- TUI and sync
main.cpp - Sync apply
main.cpp - Transfer progress
main.cpp
Filesystem model
- Directory tree
src/fstree.cpp - SHA-256 hashing
src/fstree.cpp - Tree diff
src/fstree.cpp - Tree serialization
src/fstree.cpp
Peer networking
- Peer lifecycle
src/peer.cpp - Session transport
src/peer.cpp
Wire protocol
- Packet framing
src/peer.cpp - Binary primitives
src/wire.cpp
Other components
- Operator
- Local directory
- Remote peer
Connections 21
- Operator → TUI and sync: selects peer
- TUI and sync → Peer lifecycle: starts listener
- TUI and sync → Peer lifecycle: requests connection
- Peer lifecycle → Remote peer: connects TCP
- Remote peer → Peer lifecycle: opens TCP
- Peer lifecycle → Session transport: creates session
- TUI and sync → Directory tree: builds local tree
- Directory tree → Local directory: reads directory
- Directory tree → SHA-256 hashing: hashes files
- TUI and sync → Session transport: exchanges trees
- Session transport → Tree serialization: serializes trees
- Session transport → Packet framing: frames messages
- Packet framing → Binary primitives: encodes fields
- Session transport → Remote peer: sends and receives
- TUI and sync → Tree diff: compares trees
- TUI and sync → Session transport: requests sync
- TUI and sync → Sync apply: handles sync packets
- Sync apply → Local directory: creates and deletes
- Sync apply → Session transport: receives file data
- TUI and sync → Transfer progress: updates status
- TUI and sync → Session transport: sends sync operations