pSync guide
The full reference. For an overview, see the README. Peer-to-peer file sync between your own devices on the local network: no cloud, no server, no accounts. Android first, with a Windows app to follow; both in Kotlin.
No libraries. The app uses only the Kotlin stdlib plus the JDK / Android framework: no AndroidX, Compose, coroutines or kotlinx-serialization. The tests use a tiny built-in harness instead of JUnit. The release APK is ~110 KB.
Modules
| Module | What | Depends on |
|---|---|---|
core | Sync engine: index, versioning, merge, rules, crypto, protocol, discovery | Kotlin stdlib + JDK |
android | Android app: SAF storage, foreground service, framework UI | core + Android framework |
windows (next) | Desktop app reusing core as-is | core + JDK |
How sync works
Index and versions. Each device keeps an index per folder with a SHA-256 hash and a version vector for every file (deletions are kept as tombstones). A scan finds changes cheaply by size and mtime, and only hashes files that changed. Files modified in the last 2 s are skipped until they settle.
Sessions. Two devices open one encrypted TCP connection, exchange their folder lists, and then each side pulls what it's missing. The protocol is symmetric, so both sides run the same code.
Deciding what to do with each remote entry, by comparing version vectors:
- remote is newer → download (or delete, for a tombstone)
- local is newer or equal → nothing to do
- concurrent (edited on both devices) → conflict resolution:
- same content on both → just merge the vectors
- deleted on one side, edited on the other → the edit wins
- text files ≤ 1 MB → 3-way line merge (Myers diff + diff3) against the last common version. Each device keeps small text versions as merge bases.
- binary files, or edits to the same lines → keep both: the newer edit keeps the name, the other becomes
name.conflict-<device>-<time>.ext
Resolution is deterministic, so both devices reach the same content and the same version without another round of conflicts.
Safety nets
- Downloads go to app-private staging and are hash-verified before they touch your folder.
- Before overwriting or deleting, the engine checks the local file is still what the index says. If it changed mid-sync, the file is skipped until the next round.
- Overwritten and deleted files are copied to a per-folder version archive (default: last 5 per file).
- If a folder becomes unavailable (permission revoked, drive unplugged), the scan fails instead of marking every file deleted.
- Changing a folder's location resets its index rather than propagating deletions.
Rules per folder
- Folder ID: devices sync folders that share the same ID. The location can differ per device.
- Direction:
- two-way
- send only
- receive only
- move to peers: a file is deleted locally once a peer confirms it stored that exact version, e.g. moving phone photos to the PC
- Include / exclude patterns, gitignore style:
*.jpgmatches by file namedocs/**/*.mdmatches a pathcache/matches a directory anywhere/build/matches only at the folder root
- Max file size, versions to keep, and which paired devices may sync the folder.
Security
- Every device has an EC P-256 identity key; its device ID is derived from the public key.
- Handshake (SIGMA-style): ephemeral ECDH, HKDF-SHA256 session keys, then each side signs the transcript with its identity key. After that, every frame is AES-256-GCM.
- Pairing: both screens show a 6-digit code derived from the handshake transcript. If the codes match there is no man in the middle; the user confirms on both devices and the peer's key is pinned. Unpaired devices can't sync.
- Discovery beacons (UDP broadcast) are only hints. They are never trusted.
Network
| Port | Use |
|---|---|
| UDP 47430 | discovery beacons (broadcast) |
| TCP 47431 | sync connections (falls back to a random port if busy) |
If discovery is blocked (guest Wi-Fi, client isolation, VPN), use Connect by address in the app.
Android notes
- Folders are picked with the system folder picker (SAF), so no "All files access" is needed, which keeps the app Play-friendly.
- Sync runs in a
dataSyncforeground service. It rescans every minute, syncs when something changed, does a full sync every 15 minutes, and syncs right away when a paired device appears. - Android 15 limits
dataSyncservices to about 6 h per day. When that limit is hit the service stops itself and logs it; opening the app restarts it.
Build
Open the project in Android Studio, or:
./gradlew :core:runTests # core tests (built-in harness, no JUnit)
./gradlew :android:assembleDebug # APK in android/build/outputs/apk/debug/
Requires JDK 17+ and Android SDK 35.
Known limitations / roadmap
- Windows app (desktop UI,
LocalFileSystem, tray). The core is ready for it. - Renames are seen as delete + add. Planned: reuse local content with the same hash instead of re-downloading.
- No resume for interrupted large transfers; a file restarts from zero.
- Empty directories aren't synced.
- Case-only renames and case clashes between Android (case-sensitive) and Windows (case-insensitive).
- UI to browse and restore files from the version archive.
- The scanner rereads the full SAF tree each pass. Very large trees (100k+ files) need a smarter change feed.