hsync-common 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. hsync_common-1.0.1/LICENSE +29 -0
  2. hsync_common-1.0.1/PKG-INFO +162 -0
  3. hsync_common-1.0.1/README.md +131 -0
  4. hsync_common-1.0.1/hsync_common/__init__.py +9 -0
  5. hsync_common-1.0.1/hsync_common/clock.py +479 -0
  6. hsync_common-1.0.1/hsync_common/compression.py +405 -0
  7. hsync_common-1.0.1/hsync_common/constants.py +317 -0
  8. hsync_common-1.0.1/hsync_common/delta/__init__.py +44 -0
  9. hsync_common-1.0.1/hsync_common/delta/decision.py +85 -0
  10. hsync_common-1.0.1/hsync_common/delta/rolling_checksum.py +380 -0
  11. hsync_common-1.0.1/hsync_common/endpoint.py +264 -0
  12. hsync_common-1.0.1/hsync_common/env.py +51 -0
  13. hsync_common-1.0.1/hsync_common/exceptions.py +57 -0
  14. hsync_common-1.0.1/hsync_common/format.py +95 -0
  15. hsync_common-1.0.1/hsync_common/hashing.py +124 -0
  16. hsync_common-1.0.1/hsync_common/ignore.py +255 -0
  17. hsync_common-1.0.1/hsync_common/labels.py +289 -0
  18. hsync_common-1.0.1/hsync_common/logger.py +259 -0
  19. hsync_common-1.0.1/hsync_common/models/__init__.py +61 -0
  20. hsync_common-1.0.1/hsync_common/models/_store_base.py +180 -0
  21. hsync_common-1.0.1/hsync_common/models/_util.py +191 -0
  22. hsync_common-1.0.1/hsync_common/models/delta.py +312 -0
  23. hsync_common-1.0.1/hsync_common/models/dir.py +127 -0
  24. hsync_common-1.0.1/hsync_common/models/event.py +149 -0
  25. hsync_common-1.0.1/hsync_common/models/file.py +347 -0
  26. hsync_common-1.0.1/hsync_common/models/folder.py +187 -0
  27. hsync_common-1.0.1/hsync_common/models/sqlstore.py +474 -0
  28. hsync_common-1.0.1/hsync_common/models/symlink.py +133 -0
  29. hsync_common-1.0.1/hsync_common/models/sync_action.py +126 -0
  30. hsync_common-1.0.1/hsync_common/models/tombstone.py +189 -0
  31. hsync_common-1.0.1/hsync_common/models/tombstone_store.py +203 -0
  32. hsync_common-1.0.1/hsync_common/models/version.py +356 -0
  33. hsync_common-1.0.1/hsync_common/models/version_store.py +146 -0
  34. hsync_common-1.0.1/hsync_common/path_validation.py +681 -0
  35. hsync_common-1.0.1/hsync_common/permissions.py +111 -0
  36. hsync_common-1.0.1/hsync_common/protocol/__init__.py +99 -0
  37. hsync_common-1.0.1/hsync_common/protocol/bootnode.py +751 -0
  38. hsync_common-1.0.1/hsync_common/protocol/capabilities.py +215 -0
  39. hsync_common-1.0.1/hsync_common/protocol/events.py +168 -0
  40. hsync_common-1.0.1/hsync_common/protocol/fixtures/bootnode-ack.json +7 -0
  41. hsync_common-1.0.1/hsync_common/protocol/fixtures/bootnode-fingerprint.json +57 -0
  42. hsync_common-1.0.1/hsync_common/protocol/fixtures/bootnode-query.json +7 -0
  43. hsync_common-1.0.1/hsync_common/protocol/fixtures/bootnode-register.json +19 -0
  44. hsync_common-1.0.1/hsync_common/protocol/fixtures/bootnode-response.json +29 -0
  45. hsync_common-1.0.1/hsync_common/protocol/fixtures/causal-resolution-scenarios.json +274 -0
  46. hsync_common-1.0.1/hsync_common/protocol/fixtures/causal-tombstone-scenarios.json +152 -0
  47. hsync_common-1.0.1/hsync_common/protocol/fixtures/delta-apply-metadata.json +1549 -0
  48. hsync_common-1.0.1/hsync_common/protocol/fixtures/delta-instructions.json +1546 -0
  49. hsync_common-1.0.1/hsync_common/protocol/fixtures/delta-signatures.json +1800 -0
  50. hsync_common-1.0.1/hsync_common/protocol/fixtures/ntp-targets-scenarios.json +69 -0
  51. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-bootnode-trust-scenarios.json +123 -0
  52. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-election-scenarios.json +180 -0
  53. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-pairing-scenarios.json +80 -0
  54. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-sources-request.json +9 -0
  55. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-sources-response.json +17 -0
  56. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-txt-record.json +16 -0
  57. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-txt-seeder-record.json +12 -0
  58. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-auth-failed.json +6 -0
  59. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-auth-ok.json +9 -0
  60. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-auth-required.json +8 -0
  61. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-auth.json +10 -0
  62. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-hello-master.json +8 -0
  63. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-hello-slave.json +9 -0
  64. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-ack-ok.json +6 -0
  65. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-ack-rejected.json +7 -0
  66. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-ack-resync.json +6 -0
  67. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-delta-delete.json +13 -0
  68. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-delta-upsert.json +14 -0
  69. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-empty-snapshot.json +8 -0
  70. hsync_common-1.0.1/hsync_common/protocol/fixtures/p2p-wss-inventory-snapshot.json +14 -0
  71. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-auth-error.json +7 -0
  72. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-auth-ok.json +9 -0
  73. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-auth-request.json +9 -0
  74. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-file-event.json +24 -0
  75. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-ping.json +3 -0
  76. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-pong.json +3 -0
  77. hsync_common-1.0.1/hsync_common/protocol/fixtures/ws-presence.json +5 -0
  78. hsync_common-1.0.1/hsync_common/protocol/fixtures.py +778 -0
  79. hsync_common-1.0.1/hsync_common/protocol/handshake.py +336 -0
  80. hsync_common-1.0.1/hsync_common/protocol/p2p/sources-schema.json +164 -0
  81. hsync_common-1.0.1/hsync_common/protocol/p2p/txt-schema.json +99 -0
  82. hsync_common-1.0.1/hsync_common/protocol/p2p/wss-schema.json +743 -0
  83. hsync_common-1.0.1/hsync_common/protocol/p2p.py +126 -0
  84. hsync_common-1.0.1/hsync_common/protocol/pairing.py +214 -0
  85. hsync_common-1.0.1/hsync_common/protocol/peer_download.py +522 -0
  86. hsync_common-1.0.1/hsync_common/protocol/rest/openapi.json +2106 -0
  87. hsync_common-1.0.1/hsync_common/protocol/rest.py +157 -0
  88. hsync_common-1.0.1/hsync_common/protocol/schemas.py +814 -0
  89. hsync_common-1.0.1/hsync_common/protocol/tls_trust.py +107 -0
  90. hsync_common-1.0.1/hsync_common/protocol/ws/ws-schema.json +424 -0
  91. hsync_common-1.0.1/hsync_common/ratelimit.py +146 -0
  92. hsync_common-1.0.1/hsync_common/runtime.py +300 -0
  93. hsync_common-1.0.1/hsync_common/ssl_utils.py +182 -0
  94. hsync_common-1.0.1/hsync_common/text.py +64 -0
  95. hsync_common-1.0.1/hsync_common/time_utils.py +154 -0
  96. hsync_common-1.0.1/hsync_common/upnp.py +462 -0
  97. hsync_common-1.0.1/pyproject.toml +72 -0
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Alberto Basso
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: hsync-common
3
+ Version: 1.0.1
4
+ Summary: HSYNC Common - shared models, constants, and compression utilities
5
+ License-Expression: BSD-3-Clause
6
+ License-File: LICENSE
7
+ Keywords: hsync,synchronization,delta-transfer,peer-to-peer,protocol
8
+ Author: Alberto Basso
9
+ Author-email: 17047798+albertsdk@users.noreply.github.com
10
+ Requires-Python: >=3.12,<3.15
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: System :: Networking
19
+ Requires-Dist: aiofiles (>=25.1.0,<26.0.0)
20
+ Requires-Dist: cryptography (>=50.0.2,<51.0.0)
21
+ Requires-Dist: loguru (>=0.7.3,<0.8.0)
22
+ Requires-Dist: pathspec (>=1.1.1,<2.0)
23
+ Requires-Dist: python-dotenv (>=1.2.4,<2.0.0)
24
+ Requires-Dist: zstandard (>=0.25.0,<0.26.0)
25
+ Project-URL: Documentation, https://github.com/albertsdk/hsync-common/blob/main/docs/README.md
26
+ Project-URL: Homepage, https://github.com/albertsdk/hsync-common
27
+ Project-URL: Issues, https://github.com/albertsdk/hsync-common/issues
28
+ Project-URL: Repository, https://github.com/albertsdk/hsync-common
29
+ Description-Content-Type: text/markdown
30
+
31
+ <p align="center">
32
+ <img src="docs/assets/hsync-logo-horizontal.svg" alt="HSYNC logo" width="300">
33
+ </p>
34
+
35
+ # HSYNC Common Library
36
+
37
+ **hsync-common** is the shared foundation that all other HSYNC projects build
38
+ upon — data formats, compression, file exclusion rules, and security utilities.
39
+ You don't install or run it directly; it's a library used by the client, server and
40
+ desktop application.
41
+
42
+ > New to HSYNC? Start with the [HSYNC Ecosystem](https://github.com/albertsdk/hsync/blob/main/README.md) for an overview of the platform before using the library.
43
+
44
+ It is also the **single source of truth for the open, versioned wire protocol**:
45
+ the shared models, JSON-Schema builders and committed fixtures live here
46
+ (`hsync_common.protocol`, `docs/protocol.md`, `docs/p2p-protocol.md`), so every
47
+ implementation speaks the same contract. The library sends no telemetry or
48
+ analytics anywhere.
49
+
50
+ > 👉 **Operational Advisory:** As with any data-management software, integrators are strongly advised to validate the library's behavior against their own data and to maintain validated, independent backups in the applications built on top of it.
51
+
52
+ ---
53
+
54
+ [![License: BSD 3-Clause](https://img.shields.io/badge/License-BSD_3--Clause-brightgreen.svg)](LICENSE)
55
+ [![CI](https://github.com/albertsdk/hsync-common/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/albertsdk/hsync-common/actions/workflows/ci.yml)
56
+ [![Release](https://img.shields.io/github/v/release/albertsdk/hsync-common)](https://github.com/albertsdk/hsync-common/releases/latest)
57
+ [![PyPI](https://img.shields.io/pypi/v/hsync-common)](https://pypi.org/project/hsync-common/)
58
+ [![Python 3.12+](https://img.shields.io/badge/Python-3.12+-blue.svg)](https://www.python.org/)
59
+
60
+ **Quick navigation:**
61
+ - **Want to contribute?** See [Contributing](CONTRIBUTING.md)
62
+ - **Looking for detailed documentation?** Navigate to [docs/README.md](docs/README.md)
63
+
64
+ ---
65
+
66
+ ## Key modules
67
+
68
+ | Module | Purpose |
69
+ |--------|---------|
70
+ | `hsync_common.models` | Unified `File`, `Dir`, `Symlink`, `Event`, `SyncAction`, `TombstoneStore`, delta transfer models |
71
+ | `hsync_common.protocol` | Versioned wire protocol: versions, capabilities, WS auth, LAN election, pairing, JSON-Schema builders, fixtures |
72
+ | `hsync_common.delta` | Rsync-style delta transfer algorithm: rolling checksum, block matching, decision heuristics |
73
+ | `hsync_common.hashing` | SHA-256 computation, adaptive chunk sizing, hex digest validation |
74
+ | `hsync_common.compression` | Zstandard helpers, `PRECOMPRESSED_EXTENSIONS`, `should_compress` |
75
+ | `hsync_common.permissions` | Octal permission SSOT, remote permission sanitization |
76
+ | `hsync_common.ignore` | `.hsyncignore` gitignore-style matcher (`IgnoreMatcher`) |
77
+ | `hsync_common.path_validation` | Path safety helpers, remote-path validators |
78
+ | `hsync_common.constants` | Shared constants (`HSYNCKEEP_FILENAME`, `HSYNCIGNORE_FILENAME`, `HSYNCFOLDER_FILENAME`, …) |
79
+ | `hsync_common.ssl_utils` | Shared SSL primitives, cert fingerprinting |
80
+ | `hsync_common.logger` | `BaseInterceptHandler`, log rotation helpers |
81
+ | `hsync_common.clock` | NTP-style clock offset computation |
82
+ | `hsync_common.format` | Human-readable bytes/duration formatting |
83
+ | `hsync_common.env` | Environment-variable parsing helpers |
84
+ | `hsync_common.text` | Text utilities (e.g. `escape_loguru_markup`) |
85
+ | `hsync_common.labels` | `ActionLabel` enum, log-label colorization, two-level origin rule (`[LOCAL …]` / `[REMOTE …]`) |
86
+ | `hsync_common.runtime` | Container runtime detection (Docker, Podman, Kubernetes), TTY detection, cgroup resource limits |
87
+ | `hsync_common.exceptions` | `HSyncError` base class |
88
+ | `hsync_common.time_utils` | Timestamp formatting/parsing SSOT |
89
+
90
+ ## Benchmarks
91
+
92
+ Hot-path micro-benchmarks live in [`bench/`](bench/) — L1 only (pure in-process
93
+ measurement), because the library has no process or transport of its own. Five
94
+ scripts cover hashing, compression, delta transfer, `.hsyncignore` matching and
95
+ model serialization; each accepts `--count N` and `--json-out FILE`.
96
+
97
+ ```bash
98
+ cd hsync-common && .venv/bin/python bench/bench_hashing.py --count 2000
99
+ ```
100
+
101
+ See [`bench/README.md`](bench/README.md) for the scope of each script, the
102
+ shared helpers and the measurement methodology.
103
+
104
+ ## Documentation
105
+
106
+ | Document | What it covers |
107
+ | -------- | -------------- |
108
+ | [Usage](docs/usage.md) | How to integrate hsync-common as a dependency |
109
+ | [Models](docs/models.md) | Shared data models reference |
110
+ | [Utilities](docs/utilities.md) | Cross-cutting utilities guide |
111
+ | [Protocol](docs/protocol.md) | Versioned wire protocol reference |
112
+ | [Ignore file](docs/ignore-file.md) | `.hsyncignore` syntax, `IgnoreMatcher` layers, and API |
113
+ | [Android Mirroring](docs/android-mirroring.md) | How Python models are mirrored in Kotlin |
114
+ | [Internal Architecture](docs/internal/architecture.md) | Shared models, utilities, and how they fit the HSYNC ecosystem |
115
+ | [Architecture Decision Records](docs/internal/adr/README.md) | Why the stable, cross-project decisions were made |
116
+ | [Contributing](CONTRIBUTING.md) | Development setup and contribution guidelines |
117
+ | [Report an issue](https://github.com/albertsdk/hsync-common/issues) | Open development and bug tracking |
118
+ | [Security Policy](SECURITY.md) | Supported versions and how to report vulnerabilities |
119
+
120
+ ## Associated Ecosystem Components
121
+
122
+ The other components of the HSYNC ecosystem:
123
+
124
+ - [HSYNC Main](https://github.com/albertsdk/hsync/blob/main/README.md) — Umbrella repository and project overview.
125
+ - [HSYNC Server](https://github.com/albertsdk/hsync-server/blob/main/README.md) — Central sync hub: REST API, WebSocket relay, file storage.
126
+ - [HSYNC Client](https://github.com/albertsdk/hsync-client/blob/main/README.md) — CLI client: Server Mode and p2p Mode.
127
+ - [HSYNC Desktop](https://github.com/albertsdk/hsync-desktop/blob/main/README.md) — Desktop GUI front-end. *(in development)*
128
+ - [HSYNC Android](https://github.com/albertsdk/hsync-android/blob/main/README.md) — Android client app. *(in development)*
129
+ - [HSYNC Bootnode](https://github.com/albertsdk/hsync-bootnode/blob/main/README.md) — Optional Internet discovery node for P2P (`boot/1`, no-log, RAM-only).
130
+
131
+ ## Security & Vulnerability Reporting
132
+
133
+ To report a vulnerability, please use GitHub's **Private Vulnerability Reporting**:
134
+
135
+ 👉 **[Report a vulnerability](https://github.com/albertsdk/hsync-common/security/advisories/new)**
136
+
137
+ See our [Security Policy](SECURITY.md) for supported versions and hardening
138
+ recommendations.
139
+
140
+ ## 🙋‍♂️ A note from the maintainer
141
+
142
+ This project was born out of the need for a system capable of replicating the contents of a folder from a PC or Android device to a NAS, primarily for backup purposes. Several solutions were already available, but I couldn't find one that met all my requirements. This led to the somewhat questionable decision to develop one from scratch, while also providing an opportunity to gain a deeper understanding of programming languages, algorithms, frameworks, and related technologies.
143
+
144
+ Originally conceived as a hobby project, HSYNC has been under continuous development ever since. I believe it has now evolved to the point where its capabilities are comparable to those of commercial solutions, while also offering some distinctive features. As a result, it may also be suitable for deployment in certain production environments.
145
+
146
+ HSYNC is a passion project that I primarily develop and maintain in my spare time. Please keep this in mind when interacting with the project: we're all doing our best to build something great together, but this is not a paid, full-time job for any of us.
147
+
148
+ ## Disclaimer
149
+
150
+ > [!WARNING]
151
+ > **HSYNC manipulates files and directories** — it creates, overwrites, moves, and deletes data.
152
+ > Misconfiguration, software defects, or other unforeseen conditions may lead to **data loss or
153
+ > corruption**. **Use at your own risk and always keep verified, independent backups.**
154
+
155
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. Although the author has implemented reasonable safety measures, IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY — including, without limitation, any direct, indirect, incidental, special, exemplary, or consequential damages, loss of data, or business interruption — WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156
+
157
+ This disclaimer supplements, and does not replace, the warranty disclaimer and limitation of liability provisions of the [BSD 3-Clause License](LICENSE), which govern this software.
158
+
159
+ ## License
160
+
161
+ Distributed under the [BSD 3-Clause License](LICENSE).
162
+
@@ -0,0 +1,131 @@
1
+ <p align="center">
2
+ <img src="docs/assets/hsync-logo-horizontal.svg" alt="HSYNC logo" width="300">
3
+ </p>
4
+
5
+ # HSYNC Common Library
6
+
7
+ **hsync-common** is the shared foundation that all other HSYNC projects build
8
+ upon — data formats, compression, file exclusion rules, and security utilities.
9
+ You don't install or run it directly; it's a library used by the client, server and
10
+ desktop application.
11
+
12
+ > New to HSYNC? Start with the [HSYNC Ecosystem](https://github.com/albertsdk/hsync/blob/main/README.md) for an overview of the platform before using the library.
13
+
14
+ It is also the **single source of truth for the open, versioned wire protocol**:
15
+ the shared models, JSON-Schema builders and committed fixtures live here
16
+ (`hsync_common.protocol`, `docs/protocol.md`, `docs/p2p-protocol.md`), so every
17
+ implementation speaks the same contract. The library sends no telemetry or
18
+ analytics anywhere.
19
+
20
+ > 👉 **Operational Advisory:** As with any data-management software, integrators are strongly advised to validate the library's behavior against their own data and to maintain validated, independent backups in the applications built on top of it.
21
+
22
+ ---
23
+
24
+ [![License: BSD 3-Clause](https://img.shields.io/badge/License-BSD_3--Clause-brightgreen.svg)](LICENSE)
25
+ [![CI](https://github.com/albertsdk/hsync-common/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/albertsdk/hsync-common/actions/workflows/ci.yml)
26
+ [![Release](https://img.shields.io/github/v/release/albertsdk/hsync-common)](https://github.com/albertsdk/hsync-common/releases/latest)
27
+ [![PyPI](https://img.shields.io/pypi/v/hsync-common)](https://pypi.org/project/hsync-common/)
28
+ [![Python 3.12+](https://img.shields.io/badge/Python-3.12+-blue.svg)](https://www.python.org/)
29
+
30
+ **Quick navigation:**
31
+ - **Want to contribute?** See [Contributing](CONTRIBUTING.md)
32
+ - **Looking for detailed documentation?** Navigate to [docs/README.md](docs/README.md)
33
+
34
+ ---
35
+
36
+ ## Key modules
37
+
38
+ | Module | Purpose |
39
+ |--------|---------|
40
+ | `hsync_common.models` | Unified `File`, `Dir`, `Symlink`, `Event`, `SyncAction`, `TombstoneStore`, delta transfer models |
41
+ | `hsync_common.protocol` | Versioned wire protocol: versions, capabilities, WS auth, LAN election, pairing, JSON-Schema builders, fixtures |
42
+ | `hsync_common.delta` | Rsync-style delta transfer algorithm: rolling checksum, block matching, decision heuristics |
43
+ | `hsync_common.hashing` | SHA-256 computation, adaptive chunk sizing, hex digest validation |
44
+ | `hsync_common.compression` | Zstandard helpers, `PRECOMPRESSED_EXTENSIONS`, `should_compress` |
45
+ | `hsync_common.permissions` | Octal permission SSOT, remote permission sanitization |
46
+ | `hsync_common.ignore` | `.hsyncignore` gitignore-style matcher (`IgnoreMatcher`) |
47
+ | `hsync_common.path_validation` | Path safety helpers, remote-path validators |
48
+ | `hsync_common.constants` | Shared constants (`HSYNCKEEP_FILENAME`, `HSYNCIGNORE_FILENAME`, `HSYNCFOLDER_FILENAME`, …) |
49
+ | `hsync_common.ssl_utils` | Shared SSL primitives, cert fingerprinting |
50
+ | `hsync_common.logger` | `BaseInterceptHandler`, log rotation helpers |
51
+ | `hsync_common.clock` | NTP-style clock offset computation |
52
+ | `hsync_common.format` | Human-readable bytes/duration formatting |
53
+ | `hsync_common.env` | Environment-variable parsing helpers |
54
+ | `hsync_common.text` | Text utilities (e.g. `escape_loguru_markup`) |
55
+ | `hsync_common.labels` | `ActionLabel` enum, log-label colorization, two-level origin rule (`[LOCAL …]` / `[REMOTE …]`) |
56
+ | `hsync_common.runtime` | Container runtime detection (Docker, Podman, Kubernetes), TTY detection, cgroup resource limits |
57
+ | `hsync_common.exceptions` | `HSyncError` base class |
58
+ | `hsync_common.time_utils` | Timestamp formatting/parsing SSOT |
59
+
60
+ ## Benchmarks
61
+
62
+ Hot-path micro-benchmarks live in [`bench/`](bench/) — L1 only (pure in-process
63
+ measurement), because the library has no process or transport of its own. Five
64
+ scripts cover hashing, compression, delta transfer, `.hsyncignore` matching and
65
+ model serialization; each accepts `--count N` and `--json-out FILE`.
66
+
67
+ ```bash
68
+ cd hsync-common && .venv/bin/python bench/bench_hashing.py --count 2000
69
+ ```
70
+
71
+ See [`bench/README.md`](bench/README.md) for the scope of each script, the
72
+ shared helpers and the measurement methodology.
73
+
74
+ ## Documentation
75
+
76
+ | Document | What it covers |
77
+ | -------- | -------------- |
78
+ | [Usage](docs/usage.md) | How to integrate hsync-common as a dependency |
79
+ | [Models](docs/models.md) | Shared data models reference |
80
+ | [Utilities](docs/utilities.md) | Cross-cutting utilities guide |
81
+ | [Protocol](docs/protocol.md) | Versioned wire protocol reference |
82
+ | [Ignore file](docs/ignore-file.md) | `.hsyncignore` syntax, `IgnoreMatcher` layers, and API |
83
+ | [Android Mirroring](docs/android-mirroring.md) | How Python models are mirrored in Kotlin |
84
+ | [Internal Architecture](docs/internal/architecture.md) | Shared models, utilities, and how they fit the HSYNC ecosystem |
85
+ | [Architecture Decision Records](docs/internal/adr/README.md) | Why the stable, cross-project decisions were made |
86
+ | [Contributing](CONTRIBUTING.md) | Development setup and contribution guidelines |
87
+ | [Report an issue](https://github.com/albertsdk/hsync-common/issues) | Open development and bug tracking |
88
+ | [Security Policy](SECURITY.md) | Supported versions and how to report vulnerabilities |
89
+
90
+ ## Associated Ecosystem Components
91
+
92
+ The other components of the HSYNC ecosystem:
93
+
94
+ - [HSYNC Main](https://github.com/albertsdk/hsync/blob/main/README.md) — Umbrella repository and project overview.
95
+ - [HSYNC Server](https://github.com/albertsdk/hsync-server/blob/main/README.md) — Central sync hub: REST API, WebSocket relay, file storage.
96
+ - [HSYNC Client](https://github.com/albertsdk/hsync-client/blob/main/README.md) — CLI client: Server Mode and p2p Mode.
97
+ - [HSYNC Desktop](https://github.com/albertsdk/hsync-desktop/blob/main/README.md) — Desktop GUI front-end. *(in development)*
98
+ - [HSYNC Android](https://github.com/albertsdk/hsync-android/blob/main/README.md) — Android client app. *(in development)*
99
+ - [HSYNC Bootnode](https://github.com/albertsdk/hsync-bootnode/blob/main/README.md) — Optional Internet discovery node for P2P (`boot/1`, no-log, RAM-only).
100
+
101
+ ## Security & Vulnerability Reporting
102
+
103
+ To report a vulnerability, please use GitHub's **Private Vulnerability Reporting**:
104
+
105
+ 👉 **[Report a vulnerability](https://github.com/albertsdk/hsync-common/security/advisories/new)**
106
+
107
+ See our [Security Policy](SECURITY.md) for supported versions and hardening
108
+ recommendations.
109
+
110
+ ## 🙋‍♂️ A note from the maintainer
111
+
112
+ This project was born out of the need for a system capable of replicating the contents of a folder from a PC or Android device to a NAS, primarily for backup purposes. Several solutions were already available, but I couldn't find one that met all my requirements. This led to the somewhat questionable decision to develop one from scratch, while also providing an opportunity to gain a deeper understanding of programming languages, algorithms, frameworks, and related technologies.
113
+
114
+ Originally conceived as a hobby project, HSYNC has been under continuous development ever since. I believe it has now evolved to the point where its capabilities are comparable to those of commercial solutions, while also offering some distinctive features. As a result, it may also be suitable for deployment in certain production environments.
115
+
116
+ HSYNC is a passion project that I primarily develop and maintain in my spare time. Please keep this in mind when interacting with the project: we're all doing our best to build something great together, but this is not a paid, full-time job for any of us.
117
+
118
+ ## Disclaimer
119
+
120
+ > [!WARNING]
121
+ > **HSYNC manipulates files and directories** — it creates, overwrites, moves, and deletes data.
122
+ > Misconfiguration, software defects, or other unforeseen conditions may lead to **data loss or
123
+ > corruption**. **Use at your own risk and always keep verified, independent backups.**
124
+
125
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. Although the author has implemented reasonable safety measures, IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY — including, without limitation, any direct, indirect, incidental, special, exemplary, or consequential damages, loss of data, or business interruption — WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
126
+
127
+ This disclaimer supplements, and does not replace, the warranty disclaimer and limitation of liability provisions of the [BSD 3-Clause License](LICENSE), which govern this software.
128
+
129
+ ## License
130
+
131
+ Distributed under the [BSD 3-Clause License](LICENSE).
@@ -0,0 +1,9 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ # Copyright (c) 2025 Alberto Basso
3
+
4
+ """
5
+ HSYNC Common - shared models, constants, and compression utilities.
6
+
7
+ This package provides the common data models, constants, and compression
8
+ logic shared between hsync-client and hsync-server.
9
+ """