usernet 0.7.0__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 (109) hide show
  1. usernet-0.7.0/.editorconfig +14 -0
  2. usernet-0.7.0/.gitattributes +5 -0
  3. usernet-0.7.0/.github/workflows/build.yml +286 -0
  4. usernet-0.7.0/.github/workflows/nightly.yml +90 -0
  5. usernet-0.7.0/.gitignore +23 -0
  6. usernet-0.7.0/.python-version +1 -0
  7. usernet-0.7.0/CLAUDE.md +25 -0
  8. usernet-0.7.0/CONTRIBUTING.md +3 -0
  9. usernet-0.7.0/LICENSE +5 -0
  10. usernet-0.7.0/LICENSES/0BSD.txt +5 -0
  11. usernet-0.7.0/PKG-INFO +116 -0
  12. usernet-0.7.0/README.md +84 -0
  13. usernet-0.7.0/REUSE.toml +13 -0
  14. usernet-0.7.0/bench/README.md +128 -0
  15. usernet-0.7.0/bench/box-setup.sh +47 -0
  16. usernet-0.7.0/bench/kernel_server.py +89 -0
  17. usernet-0.7.0/bench/macro.py +200 -0
  18. usernet-0.7.0/bench/micro.py +217 -0
  19. usernet-0.7.0/bench/run.py +290 -0
  20. usernet-0.7.0/docs/DESIGN.md +155 -0
  21. usernet-0.7.0/docs/DEVELOPMENT.md +104 -0
  22. usernet-0.7.0/docs/MANUAL.md +341 -0
  23. usernet-0.7.0/docs/OPERATIONS.md +144 -0
  24. usernet-0.7.0/pyproject.toml +154 -0
  25. usernet-0.7.0/src/usernet/__init__.py +81 -0
  26. usernet-0.7.0/src/usernet/aio.py +24 -0
  27. usernet-0.7.0/src/usernet/errors.py +69 -0
  28. usernet-0.7.0/src/usernet/http.py +357 -0
  29. usernet-0.7.0/src/usernet/link.py +107 -0
  30. usernet-0.7.0/src/usernet/log.py +90 -0
  31. usernet-0.7.0/src/usernet/net/__init__.py +14 -0
  32. usernet-0.7.0/src/usernet/net/backend.py +127 -0
  33. usernet-0.7.0/src/usernet/net/checksum.py +63 -0
  34. usernet-0.7.0/src/usernet/net/events.py +96 -0
  35. usernet-0.7.0/src/usernet/net/icmp.py +144 -0
  36. usernet-0.7.0/src/usernet/net/ipv4.py +205 -0
  37. usernet-0.7.0/src/usernet/net/stack.py +604 -0
  38. usernet-0.7.0/src/usernet/net/tcb.py +1169 -0
  39. usernet-0.7.0/src/usernet/net/tcp.py +385 -0
  40. usernet-0.7.0/src/usernet/net/udp.py +88 -0
  41. usernet-0.7.0/src/usernet/pcap.py +74 -0
  42. usernet-0.7.0/src/usernet/py.typed +0 -0
  43. usernet-0.7.0/src/usernet/resolve.py +93 -0
  44. usernet-0.7.0/src/usernet/routing.py +44 -0
  45. usernet-0.7.0/src/usernet/runtime/__init__.py +10 -0
  46. usernet-0.7.0/src/usernet/runtime/driver.py +466 -0
  47. usernet-0.7.0/src/usernet/runtime/stdio.py +167 -0
  48. usernet-0.7.0/src/usernet/runtime/tls.py +201 -0
  49. usernet-0.7.0/src/usernet/runtime/transport.py +283 -0
  50. usernet-0.7.0/src/usernet/socks/__init__.py +9 -0
  51. usernet-0.7.0/src/usernet/socks/client.py +91 -0
  52. usernet-0.7.0/src/usernet/socks/protocol.py +316 -0
  53. usernet-0.7.0/src/usernet/socks/server.py +377 -0
  54. usernet-0.7.0/src/usernet/testing/__init__.py +24 -0
  55. usernet-0.7.0/src/usernet/testing/link.py +153 -0
  56. usernet-0.7.0/src/usernet/testing/pcap.py +46 -0
  57. usernet-0.7.0/src/usernet/testing/peer.py +235 -0
  58. usernet-0.7.0/src/usernet/testing/pipes.py +99 -0
  59. usernet-0.7.0/src/usernet/testing/tls_endpoint.py +78 -0
  60. usernet-0.7.0/src/usernet/version.py +24 -0
  61. usernet-0.7.0/tests/__init__.py +3 -0
  62. usernet-0.7.0/tests/conformance/README.md +152 -0
  63. usernet-0.7.0/tests/conformance/__init__.py +13 -0
  64. usernet-0.7.0/tests/conformance/conftest.py +185 -0
  65. usernet-0.7.0/tests/conformance/far_server.py +35 -0
  66. usernet-0.7.0/tests/conformance/impair.sh +91 -0
  67. usernet-0.7.0/tests/conformance/pmtu.sh +84 -0
  68. usernet-0.7.0/tests/conformance/preflight.py +226 -0
  69. usernet-0.7.0/tests/conformance/setup.sh +48 -0
  70. usernet-0.7.0/tests/conformance/test_kernel_icmp.py +64 -0
  71. usernet-0.7.0/tests/conformance/test_kernel_pmtu.py +80 -0
  72. usernet-0.7.0/tests/conformance/test_kernel_soak.py +91 -0
  73. usernet-0.7.0/tests/conformance/test_kernel_tcp.py +587 -0
  74. usernet-0.7.0/tests/conformance/trace.py +146 -0
  75. usernet-0.7.0/tests/conformance/tun.py +197 -0
  76. usernet-0.7.0/tests/conftest.py +28 -0
  77. usernet-0.7.0/tests/integration/__init__.py +3 -0
  78. usernet-0.7.0/tests/integration/test_churn.py +181 -0
  79. usernet-0.7.0/tests/integration/test_soak.py +145 -0
  80. usernet-0.7.0/tests/integration/test_socks_client.py +203 -0
  81. usernet-0.7.0/tests/integration/test_socks_relays.py +108 -0
  82. usernet-0.7.0/tests/integration/test_socks_resolver.py +236 -0
  83. usernet-0.7.0/tests/integration/test_socks_server_input.py +151 -0
  84. usernet-0.7.0/tests/integration/test_stack_e2e.py +452 -0
  85. usernet-0.7.0/tests/integration/test_tls.py +272 -0
  86. usernet-0.7.0/tests/unit/__init__.py +3 -0
  87. usernet-0.7.0/tests/unit/test_checksum.py +130 -0
  88. usernet-0.7.0/tests/unit/test_conformance_trace.py +168 -0
  89. usernet-0.7.0/tests/unit/test_conformance_tun.py +96 -0
  90. usernet-0.7.0/tests/unit/test_httpcore_seam.py +91 -0
  91. usernet-0.7.0/tests/unit/test_ipv4_icmp.py +277 -0
  92. usernet-0.7.0/tests/unit/test_logging_redaction.py +111 -0
  93. usernet-0.7.0/tests/unit/test_pcap.py +62 -0
  94. usernet-0.7.0/tests/unit/test_resolve.py +66 -0
  95. usernet-0.7.0/tests/unit/test_routing.py +75 -0
  96. usernet-0.7.0/tests/unit/test_sans_io_guard.py +68 -0
  97. usernet-0.7.0/tests/unit/test_socks_protocol.py +234 -0
  98. usernet-0.7.0/tests/unit/test_stack_aborted.py +134 -0
  99. usernet-0.7.0/tests/unit/test_stack_checksums.py +154 -0
  100. usernet-0.7.0/tests/unit/test_stack_fuzz.py +291 -0
  101. usernet-0.7.0/tests/unit/test_stack_icmp_errors.py +252 -0
  102. usernet-0.7.0/tests/unit/test_stack_timers.py +123 -0
  103. usernet-0.7.0/tests/unit/test_stdio.py +106 -0
  104. usernet-0.7.0/tests/unit/test_tcb.py +1558 -0
  105. usernet-0.7.0/tests/unit/test_tcb_stateful.py +690 -0
  106. usernet-0.7.0/tests/unit/test_tcp_encoding.py +145 -0
  107. usernet-0.7.0/tests/unit/test_transport.py +327 -0
  108. usernet-0.7.0/tests/unit/test_transport_codecs.py +195 -0
  109. usernet-0.7.0/uv.lock +801 -0
@@ -0,0 +1,14 @@
1
+ # SPDX-FileCopyrightText: 2026 René de Hesselle <dehesselle@web.de>
2
+ #
3
+ # SPDX-License-Identifier: 0BSD
4
+
5
+ root = true
6
+
7
+ [*]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
+
13
+ [*.md]
14
+ trim_trailing_whitespace = false
@@ -0,0 +1,5 @@
1
+ # SPDX-FileCopyrightText: 2026 René de Hesselle <dehesselle@web.de>
2
+ #
3
+ # SPDX-License-Identifier: 0BSD
4
+
5
+ * text=auto eol=lf
@@ -0,0 +1,286 @@
1
+ # SPDX-FileCopyrightText: 2026 René de Hesselle <dehesselle@web.de>
2
+ #
3
+ # SPDX-License-Identifier: 0BSD
4
+
5
+ name: Build
6
+ on:
7
+ push:
8
+ branches: ["**"]
9
+ tags: ["v[0-9]*"]
10
+ pull_request:
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ jobs:
16
+ #-----------------------------------------------------------------------------
17
+
18
+ Lint:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - name: Checkout repository
22
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23
+ with:
24
+ persist-credentials: false
25
+
26
+ - name: Install uv
27
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
28
+
29
+ # keep aligned with [tool.ruff] in pyproject.toml
30
+ - name: Check formatting
31
+ run: uvx --from 'ruff~=0.16.0' ruff format --check .
32
+
33
+ - name: Lint
34
+ run: uvx --from 'ruff~=0.16.0' ruff check .
35
+
36
+ - name: Check REUSE compliance
37
+ run: uvx reuse lint
38
+
39
+ #-----------------------------------------------------------------------------
40
+
41
+ Test:
42
+ strategy:
43
+ fail-fast: false
44
+ matrix:
45
+ os: [ubuntu-latest, windows-latest, macos-latest]
46
+ python: ["3.12"]
47
+ include:
48
+ - os: ubuntu-latest
49
+ python: "3.14"
50
+ runs-on: ${{ matrix.os }}
51
+ steps:
52
+ # full history for hatch-vcs
53
+ - name: Checkout repository
54
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
55
+ with:
56
+ fetch-depth: 0
57
+ persist-credentials: false
58
+
59
+ - name: Install uv
60
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
61
+ with:
62
+ python-version: ${{ matrix.python }}
63
+
64
+ # per OS: mypy narrows sys.platform checks to the host
65
+ - name: Type-check
66
+ run: uv run --locked mypy src
67
+
68
+ # Everything except the tun-device conformance suite, which needs a real
69
+ # kernel and runs in the job below.
70
+ - name: Run tests
71
+ run: uv run --locked pytest -q -m "not linux_only" --cov --cov-report= --cov-fail-under=0
72
+ env:
73
+ COVERAGE_FILE: .coverage.test-${{ matrix.os }}-${{ matrix.python }}
74
+
75
+ - name: Upload coverage data
76
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
77
+ with:
78
+ name: coverage-test-${{ matrix.os }}-${{ matrix.python }}
79
+ path: .coverage.*
80
+ include-hidden-files: true
81
+
82
+ #-----------------------------------------------------------------------------
83
+
84
+ Conformance:
85
+ # Validates our TCP against a real kernel stack over a tun device. Two
86
+ # instances of our own stack can be consistently wrong together, so this is
87
+ # the only layer that proves conformance rather than self-agreement.
88
+ # The same tests run locally under WSL2.
89
+ #
90
+ # One job per link, so a red one names what broke. A tun device is
91
+ # lossless, so the clean run exercises the happy path and the protocol;
92
+ # each impairment profile exercises a different part of recovery (see
93
+ # impair.sh); kernel-variants changes what the kernel tells us.
94
+ strategy:
95
+ fail-fast: false
96
+ matrix:
97
+ link:
98
+ - clean
99
+ - loss
100
+ - reorder
101
+ - duplicate
102
+ - corrupt
103
+ - bottleneck
104
+ - long-fat
105
+ - kernel-variants
106
+ runs-on: ubuntu-latest
107
+ env:
108
+ LINK: ${{ matrix.link }}
109
+ steps:
110
+ # full history for hatch-vcs
111
+ - name: Checkout repository
112
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
113
+ with:
114
+ fetch-depth: 0
115
+ persist-credentials: false
116
+
117
+ - name: Install uv
118
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
119
+
120
+ - name: Install project
121
+ run: uv sync --locked
122
+
123
+ # Root creates the interface; the tests then run as the ordinary user,
124
+ # because `ip tuntap add ... user` is what makes that possible.
125
+ - name: Create tun device
126
+ run: sudo sh tests/conformance/setup.sh
127
+
128
+ - name: Run preflight
129
+ run: uv run --locked python -m tests.conformance.preflight
130
+
131
+ # impair.sh degrades *both* directions -- a plain root qdisc is egress
132
+ # only and would leave our own retransmission untested.
133
+ - name: Impair the link
134
+ if: matrix.link != 'clean' && matrix.link != 'kernel-variants'
135
+ run: |
136
+ sudo sh tests/conformance/impair.sh "$LINK"
137
+ echo "USERNET_TUN_NETEM=1" >> "$GITHUB_ENV"
138
+
139
+ # Window scaling off, and a route that makes the kernel offer a small
140
+ # MSS. The runner is thrown away afterwards, so global settings are fine.
141
+ - name: Change what the kernel offers
142
+ if: matrix.link == 'kernel-variants'
143
+ run: |
144
+ sudo sysctl -w net.ipv4.tcp_window_scaling=0
145
+ sudo ip route change 10.99.0.0/24 dev usernet0 proto kernel scope link \
146
+ src 10.99.0.1 advmss 536
147
+
148
+ # A hop narrower than the tun device, for path-MTU discovery.
149
+ - name: Build a narrow hop
150
+ if: matrix.link == 'clean'
151
+ run: sudo sh tests/conformance/pmtu.sh
152
+
153
+ - name: Run tests
154
+ run: uv run --locked pytest tests/conformance -v --cov --cov-report= --cov-fail-under=0
155
+ env:
156
+ COVERAGE_FILE: .coverage.conformance-${{ matrix.link }}
157
+
158
+ - name: Upload coverage data
159
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
160
+ with:
161
+ name: coverage-conformance-${{ matrix.link }}
162
+ path: .coverage.*
163
+ include-hidden-files: true
164
+
165
+ #-----------------------------------------------------------------------------
166
+
167
+ Coverage:
168
+ # Every job's measurements combined, so the conformance runs count too.
169
+ # The floor in pyproject.toml fails this job if coverage falls. It applies
170
+ # here only: each job above measures part of the code, so they pass
171
+ # --cov-fail-under=0.
172
+ runs-on: ubuntu-latest
173
+ needs:
174
+ - Test
175
+ - Conformance
176
+ steps:
177
+ - name: Checkout repository
178
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
179
+ with:
180
+ persist-credentials: false
181
+
182
+ - name: Install uv
183
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
184
+
185
+ - name: Download coverage data
186
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
187
+ with:
188
+ pattern: coverage-*
189
+ merge-multiple: true
190
+
191
+ # The version pytest-cov uses, from uv.lock. The summary is written
192
+ # whatever the outcome; the last command is the one held to the floor.
193
+ - name: Combine and report
194
+ run: |
195
+ uvx --from coverage==7.15.4 coverage combine
196
+ uvx --from coverage==7.15.4 coverage report --format=markdown --fail-under=0 \
197
+ >> "$GITHUB_STEP_SUMMARY"
198
+ uvx --from coverage==7.15.4 coverage report
199
+
200
+ #-----------------------------------------------------------------------------
201
+
202
+ Build:
203
+ runs-on: ubuntu-latest
204
+ steps:
205
+ - name: Checkout repository
206
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
207
+ with:
208
+ fetch-depth: 0
209
+ persist-credentials: false
210
+
211
+ - name: Install uv
212
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
213
+
214
+ - name: Build project
215
+ run: uv build --no-sources
216
+
217
+ - name: Smoke-test wheel
218
+ run: |
219
+ uv run --isolated --no-project --with dist/*.whl python - <<'EOF'
220
+ import os
221
+ import usernet
222
+ print(usernet.__version__)
223
+ if os.environ["GITHUB_REF_TYPE"] == "tag":
224
+ expected = os.environ["GITHUB_REF_NAME"].removeprefix("v")
225
+ assert usernet.__version__ == expected, (usernet.__version__, expected)
226
+ EOF
227
+
228
+ - name: Upload artifacts
229
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
230
+ with:
231
+ name: dist
232
+ path: dist/
233
+
234
+ #-----------------------------------------------------------------------------
235
+
236
+ Release:
237
+ runs-on: ubuntu-latest
238
+ permissions:
239
+ contents: write
240
+ needs:
241
+ - Lint
242
+ - Test
243
+ - Conformance
244
+ - Coverage
245
+ - Build
246
+ if: startsWith(github.ref, 'refs/tags/v')
247
+ steps:
248
+ - name: Download artifacts
249
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
250
+ with:
251
+ name: dist
252
+ path: dist/
253
+
254
+ - name: Create draft release
255
+ env:
256
+ GH_TOKEN: ${{ github.token }}
257
+ run: >-
258
+ gh release create "$GITHUB_REF_NAME" dist/*
259
+ --repo "$GITHUB_REPOSITORY"
260
+ --draft
261
+ --verify-tag
262
+ --generate-notes
263
+
264
+ #-----------------------------------------------------------------------------
265
+
266
+ PyPI:
267
+ runs-on: ubuntu-latest
268
+ permissions:
269
+ id-token: write
270
+ needs:
271
+ - Build
272
+ - Release
273
+ if: startsWith(github.ref, 'refs/tags/v')
274
+ environment:
275
+ name: pypi
276
+ url: https://pypi.org/p/usernet
277
+
278
+ steps:
279
+ - name: Download artifacts
280
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
281
+ with:
282
+ name: dist
283
+ path: dist/
284
+
285
+ - name: Publish to PyPI
286
+ uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
@@ -0,0 +1,90 @@
1
+ # SPDX-FileCopyrightText: 2026 René de Hesselle <dehesselle@web.de>
2
+ #
3
+ # SPDX-License-Identifier: 0BSD
4
+
5
+ # The searches too long for every push: Hypothesis at depth, the driver soak
6
+ # across hundreds of seeds, and minutes of mixed traffic against the kernel.
7
+ # A failure here never blocks a pull request; it shows on the Actions page and
8
+ # GitHub mails it to whoever last changed the schedule. GitHub disables the
9
+ # schedule after 60 days without activity in the repository, which is intended:
10
+ # the nightly runs cover the weeks after a change, then stop until the next one.
11
+
12
+ name: Nightly
13
+ on:
14
+ schedule:
15
+ - cron: "17 3 * * *"
16
+ workflow_dispatch:
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ #-----------------------------------------------------------------------------
23
+
24
+ Search:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ # full history for hatch-vcs
28
+ - name: Checkout repository
29
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
30
+ with:
31
+ fetch-depth: 0
32
+ persist-credentials: false
33
+
34
+ - name: Install uv
35
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
36
+
37
+ # The profile is in tests/conftest.py. Its searches run for minutes, so
38
+ # the per-test timeout is lifted to an hour; a hang still ends. There is
39
+ # no example database between runs, so each run draws fresh examples.
40
+ - name: Search deeper with Hypothesis
41
+ run: uv run --locked pytest tests/unit -q -o timeout=3600
42
+ env:
43
+ HYPOTHESIS_PROFILE: nightly
44
+
45
+ # New seeds every run: the 500 after the previous run's. Any failure
46
+ # names its seed, which USERNET_SOAK_SEED replays alone.
47
+ - name: Soak the driver
48
+ run: |
49
+ export USERNET_SOAK_SEED_BASE=$(( GITHUB_RUN_NUMBER * 500 ))
50
+ uv run --locked pytest tests/integration/test_soak.py -q
51
+ env:
52
+ USERNET_SOAK_SEEDS: "500"
53
+
54
+ #-----------------------------------------------------------------------------
55
+
56
+ Soak:
57
+ strategy:
58
+ fail-fast: false
59
+ matrix:
60
+ link: [loss, reorder, bottleneck]
61
+ runs-on: ubuntu-latest
62
+ env:
63
+ LINK: ${{ matrix.link }}
64
+ steps:
65
+ # full history for hatch-vcs
66
+ - name: Checkout repository
67
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
68
+ with:
69
+ fetch-depth: 0
70
+ persist-credentials: false
71
+
72
+ - name: Install uv
73
+ uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
74
+
75
+ - name: Install project
76
+ run: uv sync --locked
77
+
78
+ - name: Create tun device
79
+ run: sudo sh tests/conformance/setup.sh
80
+
81
+ - name: Impair the link
82
+ run: sudo sh tests/conformance/impair.sh "$LINK"
83
+
84
+ # A new seed every run, printed with the result and named in a failure.
85
+ - name: Run ten minutes of mixed traffic
86
+ run: uv run --locked pytest tests/conformance/test_kernel_soak.py -v -s
87
+ env:
88
+ USERNET_TUN_NETEM: "1"
89
+ USERNET_CONFORMANCE_SOAK: "600"
90
+ USERNET_CONFORMANCE_SOAK_SEED: ${{ github.run_number }}
@@ -0,0 +1,23 @@
1
+ # SPDX-FileCopyrightText: 2026 René de Hesselle <dehesselle@web.de>
2
+ #
3
+ # SPDX-License-Identifier: 0BSD
4
+
5
+ # Python-generated files
6
+ __pycache__/
7
+ *.py[oc]
8
+ build/
9
+ dist/
10
+ wheels/
11
+ *.egg-info
12
+ .mypy_cache
13
+ .pytest_cache
14
+ .ruff_cache
15
+ src/usernet/version.py
16
+
17
+ # Virtual environments
18
+ .venv
19
+
20
+ # other
21
+ .hypothesis
22
+ # benchmark output
23
+ bench/results/
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,25 @@
1
+ # CLAUDE.md
2
+
3
+ usernet is a userspace TCP/IPv4 stack, driver and SOCKS5 proxy for VPN clients
4
+ whose tunnel carries raw IP; `pyac` and `pyts` build on it.
5
+
6
+ - Read docs/DESIGN.md before architectural changes, and respect its core
7
+ principles. Before changing a module, read its docstring: that is where the
8
+ module's own reasoning lives.
9
+ - docs/MANUAL.md describes the public API, and docs/OPERATIONS.md the runtime
10
+ behavior (defaults, limits, failures, diagnostics).
11
+ - bench/README.md covers benchmarking and results; tests/conformance/README.md
12
+ covers the kernel conformance suite.
13
+
14
+ @docs/DEVELOPMENT.md
15
+
16
+ Documentation rules:
17
+
18
+ - Keep README.md short. A change that affects design, usage or behavior
19
+ updates the matching document in the same change.
20
+ - Keep DESIGN.md current, with no project history. Reasoning that concerns
21
+ only one module goes in that module's docstring, not in docs/.
22
+ - Nothing in this package may refer to a consumer's CLI or tunnel protocol,
23
+ except as an example.
24
+
25
+ Run the five checks from DEVELOPMENT.md before committing.
@@ -0,0 +1,3 @@
1
+ # Contribution guidelines
2
+
3
+ I'm open to receiving bug reports, but I'm not really interested in anything else at this point. You can still bring forward whatever you want to say, just manage your expectations accordingly.
usernet-0.7.0/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (C) 2026 by René de Hesselle
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,5 @@
1
+ Copyright (C) 2026 by René de Hesselle
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
usernet-0.7.0/PKG-INFO ADDED
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.5
2
+ Name: usernet
3
+ Version: 0.7.0
4
+ Summary: A userspace TCP/IP stack and SOCKS5 proxy for tunnels that carry raw IP
5
+ Project-URL: Homepage, https://github.com/dehesselle/usernet
6
+ Project-URL: Documentation, https://github.com/dehesselle/usernet/blob/master/docs/MANUAL.md
7
+ Project-URL: Issues, https://github.com/dehesselle/usernet/issues
8
+ Project-URL: Changelog, https://github.com/dehesselle/usernet/releases
9
+ Author-email: René de Hesselle <dehesselle@web.de>
10
+ License-Expression: 0BSD
11
+ License-File: LICENSE
12
+ License-File: LICENSES/0BSD.txt
13
+ Keywords: asyncio,ip,network-stack,socks5,tcp,tunnel,userspace,vpn
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Framework :: AsyncIO
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Internet :: Proxy Servers
24
+ Classifier: Topic :: System :: Networking
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.12
27
+ Provides-Extra: httpx
28
+ Requires-Dist: httpx<0.29,>=0.27; extra == 'httpx'
29
+ Provides-Extra: testing
30
+ Requires-Dist: trustme>=1.1; extra == 'testing'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # usernet
34
+
35
+ A userspace TCP/IPv4 stack for VPN clients whose tunnel carries raw IP packets.
36
+ A client built on it needs nothing from the operating system: no tun device, no
37
+ virtual adapter, no routing change, no administrator rights. It hands
38
+ decapsulated packets to usernet and gets back connections, an asyncio stream
39
+ pair, an httpx client, or a local SOCKS5 proxy that ordinary tools can use.
40
+
41
+ usernet does not provide the tunnel itself. A tunnel is anything that
42
+ implements `IpLink`: `pyac` supplies CSTP over TLS, and `pyts` supplies
43
+ WireGuard over DERP. The library needs only the standard library; the httpx
44
+ bridge is an optional extra.
45
+
46
+ ## Installation and usage
47
+
48
+ ```sh
49
+ uv add usernet
50
+ uv add "usernet[httpx]" # with the httpx bridge
51
+ ```
52
+
53
+ The example below opens a connection through the stack. `VirtualLink` is the
54
+ in-memory test link that ships with the package; a real client passes its own
55
+ tunnel there instead.
56
+
57
+ ```python
58
+ import asyncio
59
+
60
+ from usernet import Driver
61
+ from usernet.testing import TcpPeer, VirtualLink
62
+ from usernet.testing.peer import http_handler
63
+
64
+
65
+ async def main() -> None:
66
+ # A real tunnel goes here. VirtualLink connects to an in-memory TCP peer.
67
+ peer = TcpPeer(ip="10.0.0.5", port=80, handler=http_handler(b"hello"))
68
+ driver = Driver(VirtualLink(peer, address="10.0.0.2"))
69
+ driver.start()
70
+ try:
71
+ stream = await driver.connect("10.0.0.5", 80)
72
+ await stream.write(b"GET / HTTP/1.1\r\nHost: internal\r\n\r\n")
73
+ print((await stream.read_all()).decode())
74
+ finally:
75
+ await driver.aclose()
76
+
77
+
78
+ asyncio.run(main())
79
+ ```
80
+
81
+ ## Caveats
82
+
83
+ - A SOCKS5 listener lets every local process into the VPN without
84
+ authentication. `Socks5Server` therefore binds to loopback only unless told
85
+ otherwise.
86
+ - Hostnames are resolved only by the resolver you give the driver. They are
87
+ never sent to the host's DNS. Without a resolver, only addresses work.
88
+ - TCP is client-only: the stack opens connections and never accepts them.
89
+
90
+ ## Documentation
91
+
92
+ <!-- Absolute links: this file is also the PyPI project description. -->
93
+
94
+ - [docs/MANUAL.md](https://github.com/dehesselle/usernet/blob/master/docs/MANUAL.md):
95
+ the library API, covering how to supply a tunnel, the driver, streams, HTTP,
96
+ SOCKS5, resolvers, errors, logging and the test helpers
97
+ - [docs/DESIGN.md](https://github.com/dehesselle/usernet/blob/master/docs/DESIGN.md):
98
+ architecture, seams, scope and the core principles the code must keep
99
+ - [docs/OPERATIONS.md](https://github.com/dehesselle/usernet/blob/master/docs/OPERATIONS.md):
100
+ runtime behavior, covering defaults and limits, failure and recovery,
101
+ diagnostics, and troubleshooting hangs
102
+ - [docs/DEVELOPMENT.md](https://github.com/dehesselle/usernet/blob/master/docs/DEVELOPMENT.md):
103
+ setup, checks, test strategy, CI and releasing
104
+ - [tests/conformance/README.md](https://github.com/dehesselle/usernet/blob/master/tests/conformance/README.md):
105
+ the test suite against a real Linux kernel
106
+ - [bench/README.md](https://github.com/dehesselle/usernet/blob/master/bench/README.md):
107
+ benchmark method and measured results
108
+
109
+ ## AI disclosure
110
+
111
+ Substantial parts of this code were generated with Sonnet 5.x/Opus 5.x.
112
+ Generated code was tested, but not every line was reviewed in detail.
113
+
114
+ ## License
115
+
116
+ [0BSD](https://github.com/dehesselle/usernet/blob/master/LICENSES/0BSD.txt)
@@ -0,0 +1,84 @@
1
+ # usernet
2
+
3
+ A userspace TCP/IPv4 stack for VPN clients whose tunnel carries raw IP packets.
4
+ A client built on it needs nothing from the operating system: no tun device, no
5
+ virtual adapter, no routing change, no administrator rights. It hands
6
+ decapsulated packets to usernet and gets back connections, an asyncio stream
7
+ pair, an httpx client, or a local SOCKS5 proxy that ordinary tools can use.
8
+
9
+ usernet does not provide the tunnel itself. A tunnel is anything that
10
+ implements `IpLink`: `pyac` supplies CSTP over TLS, and `pyts` supplies
11
+ WireGuard over DERP. The library needs only the standard library; the httpx
12
+ bridge is an optional extra.
13
+
14
+ ## Installation and usage
15
+
16
+ ```sh
17
+ uv add usernet
18
+ uv add "usernet[httpx]" # with the httpx bridge
19
+ ```
20
+
21
+ The example below opens a connection through the stack. `VirtualLink` is the
22
+ in-memory test link that ships with the package; a real client passes its own
23
+ tunnel there instead.
24
+
25
+ ```python
26
+ import asyncio
27
+
28
+ from usernet import Driver
29
+ from usernet.testing import TcpPeer, VirtualLink
30
+ from usernet.testing.peer import http_handler
31
+
32
+
33
+ async def main() -> None:
34
+ # A real tunnel goes here. VirtualLink connects to an in-memory TCP peer.
35
+ peer = TcpPeer(ip="10.0.0.5", port=80, handler=http_handler(b"hello"))
36
+ driver = Driver(VirtualLink(peer, address="10.0.0.2"))
37
+ driver.start()
38
+ try:
39
+ stream = await driver.connect("10.0.0.5", 80)
40
+ await stream.write(b"GET / HTTP/1.1\r\nHost: internal\r\n\r\n")
41
+ print((await stream.read_all()).decode())
42
+ finally:
43
+ await driver.aclose()
44
+
45
+
46
+ asyncio.run(main())
47
+ ```
48
+
49
+ ## Caveats
50
+
51
+ - A SOCKS5 listener lets every local process into the VPN without
52
+ authentication. `Socks5Server` therefore binds to loopback only unless told
53
+ otherwise.
54
+ - Hostnames are resolved only by the resolver you give the driver. They are
55
+ never sent to the host's DNS. Without a resolver, only addresses work.
56
+ - TCP is client-only: the stack opens connections and never accepts them.
57
+
58
+ ## Documentation
59
+
60
+ <!-- Absolute links: this file is also the PyPI project description. -->
61
+
62
+ - [docs/MANUAL.md](https://github.com/dehesselle/usernet/blob/master/docs/MANUAL.md):
63
+ the library API, covering how to supply a tunnel, the driver, streams, HTTP,
64
+ SOCKS5, resolvers, errors, logging and the test helpers
65
+ - [docs/DESIGN.md](https://github.com/dehesselle/usernet/blob/master/docs/DESIGN.md):
66
+ architecture, seams, scope and the core principles the code must keep
67
+ - [docs/OPERATIONS.md](https://github.com/dehesselle/usernet/blob/master/docs/OPERATIONS.md):
68
+ runtime behavior, covering defaults and limits, failure and recovery,
69
+ diagnostics, and troubleshooting hangs
70
+ - [docs/DEVELOPMENT.md](https://github.com/dehesselle/usernet/blob/master/docs/DEVELOPMENT.md):
71
+ setup, checks, test strategy, CI and releasing
72
+ - [tests/conformance/README.md](https://github.com/dehesselle/usernet/blob/master/tests/conformance/README.md):
73
+ the test suite against a real Linux kernel
74
+ - [bench/README.md](https://github.com/dehesselle/usernet/blob/master/bench/README.md):
75
+ benchmark method and measured results
76
+
77
+ ## AI disclosure
78
+
79
+ Substantial parts of this code were generated with Sonnet 5.x/Opus 5.x.
80
+ Generated code was tested, but not every line was reviewed in detail.
81
+
82
+ ## License
83
+
84
+ [0BSD](https://github.com/dehesselle/usernet/blob/master/LICENSES/0BSD.txt)
@@ -0,0 +1,13 @@
1
+ version = 1
2
+
3
+ # Files that can't carry an SPDX comment, or shouldn't: docs stay clean when
4
+ # rendered, and uv.lock is regenerated.
5
+ [[annotations]]
6
+ path = [
7
+ "**.md",
8
+ "src/usernet/py.typed",
9
+ "uv.lock",
10
+ ".python-version",
11
+ ]
12
+ SPDX-FileCopyrightText = "2026 René de Hesselle <dehesselle@web.de>"
13
+ SPDX-License-Identifier = "0BSD"