letify 3.0.7__tar.gz → 3.0.8__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 (331) hide show
  1. {letify-3.0.7 → letify-3.0.8}/PKG-INFO +1 -1
  2. {letify-3.0.7 → letify-3.0.8}/docs/SPEC.md +27 -0
  3. {letify-3.0.7 → letify-3.0.8}/letify/__init__.py +1 -1
  4. {letify-3.0.7 → letify-3.0.8}/letify-core/Cargo.lock +2 -2
  5. {letify-3.0.7 → letify-3.0.8}/letify-core/Cargo.toml +1 -1
  6. {letify-3.0.7 → letify-3.0.8}/letify-core/letify/Cargo.toml +1 -1
  7. letify-3.0.8/letify-core/letify-link/src/rendezvous/demux.rs +338 -0
  8. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/rendezvous.rs +6 -0
  9. letify-3.0.8/letify-core/letify-link/tests/demux.rs +375 -0
  10. {letify-3.0.7 → letify-3.0.8}/letify-ext/package-lock.json +2 -2
  11. {letify-3.0.7 → letify-3.0.8}/letify-ext/package.json +1 -1
  12. {letify-3.0.7 → letify-3.0.8}/pyproject.toml +1 -1
  13. {letify-3.0.7 → letify-3.0.8}/.github/workflows/ci.yml +0 -0
  14. {letify-3.0.7 → letify-3.0.8}/.github/workflows/docs.yml +0 -0
  15. {letify-3.0.7 → letify-3.0.8}/.github/workflows/letify-link.yml +0 -0
  16. {letify-3.0.7 → letify-3.0.8}/.github/workflows/publish-crates.yml +0 -0
  17. {letify-3.0.7 → letify-3.0.8}/.github/workflows/publish.yml +0 -0
  18. {letify-3.0.7 → letify-3.0.8}/.github/workflows/reserve-crates.yml +0 -0
  19. {letify-3.0.7 → letify-3.0.8}/.gitignore +0 -0
  20. {letify-3.0.7 → letify-3.0.8}/.researchtree +0 -0
  21. {letify-3.0.7 → letify-3.0.8}/CLAUDE.md +0 -0
  22. {letify-3.0.7 → letify-3.0.8}/LICENSE +0 -0
  23. {letify-3.0.7 → letify-3.0.8}/PROJECT.md +0 -0
  24. {letify-3.0.7 → letify-3.0.8}/README.md +0 -0
  25. {letify-3.0.7 → letify-3.0.8}/docs/COMPONENT.md +0 -0
  26. {letify-3.0.7 → letify-3.0.8}/docs/INTENT.md +0 -0
  27. {letify-3.0.7 → letify-3.0.8}/docs/NETWORK.md +0 -0
  28. {letify-3.0.7 → letify-3.0.8}/docs/ROADMAP-3.0.md +0 -0
  29. {letify-3.0.7 → letify-3.0.8}/docs/guide/01-getting-started.md +0 -0
  30. {letify-3.0.7 → letify-3.0.8}/docs/guide/02-providers.md +0 -0
  31. {letify-3.0.7 → letify-3.0.8}/docs/guide/03-execution-modes.md +0 -0
  32. {letify-3.0.7 → letify-3.0.8}/docs/guide/04-environments-and-data.md +0 -0
  33. {letify-3.0.7 → letify-3.0.8}/docs/guide/05-concurrency.md +0 -0
  34. {letify-3.0.7 → letify-3.0.8}/docs/guide/06-cost.md +0 -0
  35. {letify-3.0.7 → letify-3.0.8}/docs/guide/07-troubleshooting.md +0 -0
  36. {letify-3.0.7 → letify-3.0.8}/docs/guide/08-releasing.md +0 -0
  37. {letify-3.0.7 → letify-3.0.8}/docs/guide/09-agent.md +0 -0
  38. {letify-3.0.7 → letify-3.0.8}/docs/guide/README.md +0 -0
  39. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/01-/354/213/234/354/236/221/355/225/230/352/270/260.md" +0 -0
  40. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/02-/355/224/204/353/241/234/353/260/224/354/235/264/353/215/224.md" +0 -0
  41. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/03-/354/213/244/355/226/211-/353/260/251/354/213/235.md" +0 -0
  42. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/04-/355/231/230/352/262/275/352/263/274-/353/215/260/354/235/264/355/204/260.md" +0 -0
  43. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/05-/353/217/231/354/213/234-/354/213/244/355/226/211.md" +0 -0
  44. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/06-/353/271/204/354/232/251.md" +0 -0
  45. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/07-/353/254/270/354/240/234-/355/225/264/352/262/260.md" +0 -0
  46. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/08-/353/246/264/353/246/254/354/212/244.md" +0 -0
  47. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/09-/354/227/220/354/235/264/354/240/204/355/212/270.md" +0 -0
  48. {letify-3.0.7 → letify-3.0.8}/docs/guide/ko/README.md +0 -0
  49. {letify-3.0.7 → letify-3.0.8}/docs/locales/README_ko.md +0 -0
  50. {letify-3.0.7 → letify-3.0.8}/docs/mkdocs.yml +0 -0
  51. {letify-3.0.7 → letify-3.0.8}/examples/README.md +0 -0
  52. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/.letify.example +0 -0
  53. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/00_smoke.py +0 -0
  54. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/01_sweep.py +0 -0
  55. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/02_resume.py +0 -0
  56. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/03_watch.py +0 -0
  57. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/README.md +0 -0
  58. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/README_ko.md +0 -0
  59. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/common.py +0 -0
  60. {letify-3.0.7 → letify-3.0.8}/examples/nvfp4-lora/recipe.py +0 -0
  61. {letify-3.0.7 → letify-3.0.8}/letify/cli.py +0 -0
  62. {letify-3.0.7 → letify-3.0.8}/letify/config/__init__.py +0 -0
  63. {letify-3.0.7 → letify-3.0.8}/letify/config/inventory.py +0 -0
  64. {letify-3.0.7 → letify-3.0.8}/letify/config/login.py +0 -0
  65. {letify-3.0.7 → letify-3.0.8}/letify/config/schema.py +0 -0
  66. {letify-3.0.7 → letify-3.0.8}/letify/config/secrets.py +0 -0
  67. {letify-3.0.7 → letify-3.0.8}/letify/config/writer.py +0 -0
  68. {letify-3.0.7 → letify-3.0.8}/letify/declare/__init__.py +0 -0
  69. {letify-3.0.7 → letify-3.0.8}/letify/declare/cache.py +0 -0
  70. {letify-3.0.7 → letify-3.0.8}/letify/declare/env.py +0 -0
  71. {letify-3.0.7 → letify-3.0.8}/letify/declare/exit.py +0 -0
  72. {letify-3.0.7 → letify-3.0.8}/letify/declare/function.py +0 -0
  73. {letify-3.0.7 → letify-3.0.8}/letify/declare/instance.py +0 -0
  74. {letify-3.0.7 → letify-3.0.8}/letify/declare/reduce.py +0 -0
  75. {letify-3.0.7 → letify-3.0.8}/letify/declare/replicas.py +0 -0
  76. {letify-3.0.7 → letify-3.0.8}/letify/errors.py +0 -0
  77. {letify-3.0.7 → letify-3.0.8}/letify/install.py +0 -0
  78. {letify-3.0.7 → letify-3.0.8}/letify/launcher.py +0 -0
  79. {letify-3.0.7 → letify-3.0.8}/letify/paths.py +0 -0
  80. {letify-3.0.7 → letify-3.0.8}/letify/protocol/__init__.py +0 -0
  81. {letify-3.0.7 → letify-3.0.8}/letify/protocol/codec.py +0 -0
  82. {letify-3.0.7 → letify-3.0.8}/letify/protocol/driver.py +0 -0
  83. {letify-3.0.7 → letify-3.0.8}/letify/protocol/handle.py +0 -0
  84. {letify-3.0.7 → letify-3.0.8}/letify/protocol/wire.py +0 -0
  85. {letify-3.0.7 → letify-3.0.8}/letify/protocol/worker.py +0 -0
  86. {letify-3.0.7 → letify-3.0.8}/letify/providers/__init__.py +0 -0
  87. {letify-3.0.7 → letify-3.0.8}/letify/providers/base.py +0 -0
  88. {letify-3.0.7 → letify-3.0.8}/letify/providers/colab.py +0 -0
  89. {letify-3.0.7 → letify-3.0.8}/letify/providers/colab_files.py +0 -0
  90. {letify-3.0.7 → letify-3.0.8}/letify/providers/colab_keepalive.py +0 -0
  91. {letify-3.0.7 → letify-3.0.8}/letify/providers/elice.py +0 -0
  92. {letify-3.0.7 → letify-3.0.8}/letify/providers/kaggle.py +0 -0
  93. {letify-3.0.7 → letify-3.0.8}/letify/providers/kaggle_adapter.py +0 -0
  94. {letify-3.0.7 → letify-3.0.8}/letify/providers/local.py +0 -0
  95. {letify-3.0.7 → letify-3.0.8}/letify/providers/modal.py +0 -0
  96. {letify-3.0.7 → letify-3.0.8}/letify/providers/modal_adapter.py +0 -0
  97. {letify-3.0.7 → letify-3.0.8}/letify/providers/naming.py +0 -0
  98. {letify-3.0.7 → letify-3.0.8}/letify/providers/shell.py +0 -0
  99. {letify-3.0.7 → letify-3.0.8}/letify/providers/tunnel.py +0 -0
  100. {letify-3.0.7 → letify-3.0.8}/letify/providers/usage.py +0 -0
  101. {letify-3.0.7 → letify-3.0.8}/letify/remoting/__init__.py +0 -0
  102. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/__init__.py +0 -0
  103. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/client.py +0 -0
  104. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/cuda.py +0 -0
  105. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/executor.py +0 -0
  106. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/frames.py +0 -0
  107. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/guard.py +0 -0
  108. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/tensor.py +0 -0
  109. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/trace.py +0 -0
  110. {letify-3.0.7 → letify-3.0.8}/letify/remoting/device/value.py +0 -0
  111. {letify-3.0.7 → letify-3.0.8}/letify/render.py +0 -0
  112. {letify-3.0.7 → letify-3.0.8}/letify/runtime/__init__.py +0 -0
  113. {letify-3.0.7 → letify-3.0.8}/letify/runtime/bootstrap.py +0 -0
  114. {letify-3.0.7 → letify-3.0.8}/letify/runtime/broker.py +0 -0
  115. {letify-3.0.7 → letify-3.0.8}/letify/runtime/channel.py +0 -0
  116. {letify-3.0.7 → letify-3.0.8}/letify/runtime/control.py +0 -0
  117. {letify-3.0.7 → letify-3.0.8}/letify/runtime/lease.py +0 -0
  118. {letify-3.0.7 → letify-3.0.8}/letify/runtime/pool.py +0 -0
  119. {letify-3.0.7 → letify-3.0.8}/letify/runtime/reattach.py +0 -0
  120. {letify-3.0.7 → letify-3.0.8}/letify/runtime/session.py +0 -0
  121. {letify-3.0.7 → letify-3.0.8}/letify/runtime/takeover.py +0 -0
  122. {letify-3.0.7 → letify-3.0.8}/letify/runtime/telemetry.py +0 -0
  123. {letify-3.0.7 → letify-3.0.8}/letify/runtime/workers.py +0 -0
  124. {letify-3.0.7 → letify-3.0.8}/letify/store/__init__.py +0 -0
  125. {letify-3.0.7 → letify-3.0.8}/letify/store/backends/__init__.py +0 -0
  126. {letify-3.0.7 → letify-3.0.8}/letify/store/backends/drive.py +0 -0
  127. {letify-3.0.7 → letify-3.0.8}/letify/store/backends/filesystem.py +0 -0
  128. {letify-3.0.7 → letify-3.0.8}/letify/store/backends/google_auth.py +0 -0
  129. {letify-3.0.7 → letify-3.0.8}/letify/store/backends/layout.py +0 -0
  130. {letify-3.0.7 → letify-3.0.8}/letify/store/backends/objects.py +0 -0
  131. {letify-3.0.7 → letify-3.0.8}/letify/store/cas.py +0 -0
  132. {letify-3.0.7 → letify-3.0.8}/letify/store/handoff.py +0 -0
  133. {letify-3.0.7 → letify-3.0.8}/letify/store/pathdata.py +0 -0
  134. {letify-3.0.7 → letify-3.0.8}/letify/store/sendorder.py +0 -0
  135. {letify-3.0.7 → letify-3.0.8}/letify/store/volume.py +0 -0
  136. {letify-3.0.7 → letify-3.0.8}/letify/stubs.py +0 -0
  137. {letify-3.0.7 → letify-3.0.8}/letify/tools.py +0 -0
  138. {letify-3.0.7 → letify-3.0.8}/letify/transport/__init__.py +0 -0
  139. {letify-3.0.7 → letify-3.0.8}/letify/transport/announce.py +0 -0
  140. {letify-3.0.7 → letify-3.0.8}/letify/transport/link.py +0 -0
  141. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkagent.py +0 -0
  142. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkchannel.py +0 -0
  143. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkd.py +0 -0
  144. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkmailbox.py +0 -0
  145. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkpump.py +0 -0
  146. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkshim.py +0 -0
  147. {letify-3.0.7 → letify-3.0.8}/letify/transport/linksignal.py +0 -0
  148. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkupload.py +0 -0
  149. {letify-3.0.7 → letify-3.0.8}/letify/transport/linkwebsocket.py +0 -0
  150. {letify-3.0.7 → letify-3.0.8}/letify/transport/nat.py +0 -0
  151. {letify-3.0.7 → letify-3.0.8}/letify/transport/pipeline.py +0 -0
  152. {letify-3.0.7 → letify-3.0.8}/letify/transport/portmap.py +0 -0
  153. {letify-3.0.7 → letify-3.0.8}/letify/transport/probe.py +0 -0
  154. {letify-3.0.7 → letify-3.0.8}/letify/transport/rendezvous.py +0 -0
  155. {letify-3.0.7 → letify-3.0.8}/letify/transport/sshopts.py +0 -0
  156. {letify-3.0.7 → letify-3.0.8}/letify/transport/strategies.py +0 -0
  157. {letify-3.0.7 → letify-3.0.8}/letify/useragent.py +0 -0
  158. {letify-3.0.7 → letify-3.0.8}/letify-core/.gitignore +0 -0
  159. {letify-3.0.7 → letify-3.0.8}/letify-core/build.py +0 -0
  160. {letify-3.0.7 → letify-3.0.8}/letify-core/letify/LICENSE +0 -0
  161. {letify-3.0.7 → letify-3.0.8}/letify-core/letify/README.md +0 -0
  162. {letify-3.0.7 → letify-3.0.8}/letify-core/letify/src/lib.rs +0 -0
  163. {letify-3.0.7 → letify-3.0.8}/letify-core/letify/tests/link.rs +0 -0
  164. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/Cargo.toml +0 -0
  165. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/LICENSE +0 -0
  166. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/README.md +0 -0
  167. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/examples/bench.rs +0 -0
  168. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/examples/udp_rate.rs +0 -0
  169. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/acceptor.rs +0 -0
  170. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/bin/letify-link.rs +0 -0
  171. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/config.rs +0 -0
  172. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/driver.rs +0 -0
  173. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/error.rs +0 -0
  174. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/frame.rs +0 -0
  175. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/handshake.rs +0 -0
  176. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/hysteresis.rs +0 -0
  177. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/identity.rs +0 -0
  178. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/keys.rs +0 -0
  179. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/lib.rs +0 -0
  180. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/observe.rs +0 -0
  181. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/paths.rs +0 -0
  182. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/plan.rs +0 -0
  183. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/policing.rs +0 -0
  184. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/punch.rs +0 -0
  185. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/record.rs +0 -0
  186. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/relay.rs +0 -0
  187. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/replay.rs +0 -0
  188. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/session.rs +0 -0
  189. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/sidecar.rs +0 -0
  190. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/signal.rs +0 -0
  191. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/stream.rs +0 -0
  192. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/stun.rs +0 -0
  193. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/tcp.rs +0 -0
  194. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/trace.rs +0 -0
  195. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/src/udp.rs +0 -0
  196. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/acceptor.rs +0 -0
  197. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/api.rs +0 -0
  198. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/common/mod.rs +0 -0
  199. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/diag_sim.rs +0 -0
  200. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/driver.rs +0 -0
  201. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/fairness.rs +0 -0
  202. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/gauge.rs +0 -0
  203. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/handshake.rs +0 -0
  204. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/hysteresis.rs +0 -0
  205. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/keepalive.rs +0 -0
  206. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/mobile.rs +0 -0
  207. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/nat.rs +0 -0
  208. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/paths.rs +0 -0
  209. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/qad.rs +0 -0
  210. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/rekey.rs +0 -0
  211. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/relay.rs +0 -0
  212. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/relay_pairing.rs +0 -0
  213. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/rendezvous.rs +0 -0
  214. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/reorder.rs +0 -0
  215. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/replay.rs +0 -0
  216. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/resume.rs +0 -0
  217. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/revoke.rs +0 -0
  218. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/session.rs +0 -0
  219. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/sidecar.rs +0 -0
  220. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/signal.rs +0 -0
  221. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/startup.rs +0 -0
  222. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/subflows.rs +0 -0
  223. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/trace.rs +0 -0
  224. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/udp.rs +0 -0
  225. {letify-3.0.7 → letify-3.0.8}/letify-core/letify-link/tests/udp_bench.rs +0 -0
  226. {letify-3.0.7 → letify-3.0.8}/letify-core/rust-toolchain.toml +0 -0
  227. {letify-3.0.7 → letify-3.0.8}/letify-ext/.vscodeignore +0 -0
  228. {letify-3.0.7 → letify-3.0.8}/letify-ext/LICENSE +0 -0
  229. {letify-3.0.7 → letify-3.0.8}/letify-ext/README.md +0 -0
  230. {letify-3.0.7 → letify-3.0.8}/letify-ext/media/icon.svg +0 -0
  231. {letify-3.0.7 → letify-3.0.8}/letify-ext/src/cli.ts +0 -0
  232. {letify-3.0.7 → letify-3.0.8}/letify-ext/src/extension.ts +0 -0
  233. {letify-3.0.7 → letify-3.0.8}/letify-ext/src/history.ts +0 -0
  234. {letify-3.0.7 → letify-3.0.8}/letify-ext/src/model.ts +0 -0
  235. {letify-3.0.7 → letify-3.0.8}/letify-ext/src/poll.ts +0 -0
  236. {letify-3.0.7 → letify-3.0.8}/letify-ext/src/render.ts +0 -0
  237. {letify-3.0.7 → letify-3.0.8}/letify-ext/test/cli.test.ts +0 -0
  238. {letify-3.0.7 → letify-3.0.8}/letify-ext/test/manifest.test.ts +0 -0
  239. {letify-3.0.7 → letify-3.0.8}/letify-ext/test/model.test.ts +0 -0
  240. {letify-3.0.7 → letify-3.0.8}/letify-ext/test/regressions.test.ts +0 -0
  241. {letify-3.0.7 → letify-3.0.8}/letify-ext/tsconfig.json +0 -0
  242. {letify-3.0.7 → letify-3.0.8}/letify-signal/README.md +0 -0
  243. {letify-3.0.7 → letify-3.0.8}/letify-signal/cloudflare.config.ts +0 -0
  244. {letify-3.0.7 → letify-3.0.8}/letify-signal/package-lock.json +0 -0
  245. {letify-3.0.7 → letify-3.0.8}/letify-signal/package.json +0 -0
  246. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/auth.ts +0 -0
  247. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/ed25519.ts +0 -0
  248. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/handler.ts +0 -0
  249. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/index.ts +0 -0
  250. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/limiter.ts +0 -0
  251. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/mailbox.ts +0 -0
  252. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/objects.ts +0 -0
  253. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/protocol.ts +0 -0
  254. {letify-3.0.7 → letify-3.0.8}/letify-signal/src/storage.ts +0 -0
  255. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/auth.test.ts +0 -0
  256. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/ed25519.test.ts +0 -0
  257. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/helpers.ts +0 -0
  258. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/interop.test.ts +0 -0
  259. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/limiter.test.ts +0 -0
  260. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/mailbox.test.ts +0 -0
  261. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/objects.test.ts +0 -0
  262. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/setup.ts +0 -0
  263. {letify-3.0.7 → letify-3.0.8}/letify-signal/test/worker.test.ts +0 -0
  264. {letify-3.0.7 → letify-3.0.8}/letify-signal/tsconfig.json +0 -0
  265. {letify-3.0.7 → letify-3.0.8}/letify-signal/vitest.config.ts +0 -0
  266. {letify-3.0.7 → letify-3.0.8}/letify_providers.py +0 -0
  267. {letify-3.0.7 → letify-3.0.8}/scripts/publish-crates.sh +0 -0
  268. {letify-3.0.7 → letify-3.0.8}/scripts/sync-main.sh +0 -0
  269. {letify-3.0.7 → letify-3.0.8}/scripts/version.py +0 -0
  270. {letify-3.0.7 → letify-3.0.8}/tests/conftest.py +0 -0
  271. {letify-3.0.7 → letify-3.0.8}/tests/fake_kaggle_adapter.py +0 -0
  272. {letify-3.0.7 → letify-3.0.8}/tests/fake_modal_adapter.py +0 -0
  273. {letify-3.0.7 → letify-3.0.8}/tests/test_cli.py +0 -0
  274. {letify-3.0.7 → letify-3.0.8}/tests/test_cli_output.py +0 -0
  275. {letify-3.0.7 → letify-3.0.8}/tests/test_colab_keepalive.py +0 -0
  276. {letify-3.0.7 → letify-3.0.8}/tests/test_config.py +0 -0
  277. {letify-3.0.7 → letify-3.0.8}/tests/test_core.py +0 -0
  278. {letify-3.0.7 → letify-3.0.8}/tests/test_data.py +0 -0
  279. {letify-3.0.7 → letify-3.0.8}/tests/test_data_in_place.py +0 -0
  280. {letify-3.0.7 → letify-3.0.8}/tests/test_data_streaming.py +0 -0
  281. {letify-3.0.7 → letify-3.0.8}/tests/test_declare.py +0 -0
  282. {letify-3.0.7 → letify-3.0.8}/tests/test_device.py +0 -0
  283. {letify-3.0.7 → letify-3.0.8}/tests/test_device_compile.py +0 -0
  284. {letify-3.0.7 → letify-3.0.8}/tests/test_distributed.py +0 -0
  285. {letify-3.0.7 → letify-3.0.8}/tests/test_drive_handoff.py +0 -0
  286. {letify-3.0.7 → letify-3.0.8}/tests/test_drive_store.py +0 -0
  287. {letify-3.0.7 → letify-3.0.8}/tests/test_editor_sessions.py +0 -0
  288. {letify-3.0.7 → letify-3.0.8}/tests/test_elice.py +0 -0
  289. {letify-3.0.7 → letify-3.0.8}/tests/test_frames.py +0 -0
  290. {letify-3.0.7 → letify-3.0.8}/tests/test_install.py +0 -0
  291. {letify-3.0.7 → letify-3.0.8}/tests/test_kaggle.py +0 -0
  292. {letify-3.0.7 → letify-3.0.8}/tests/test_kaggle_cookie.py +0 -0
  293. {letify-3.0.7 → letify-3.0.8}/tests/test_kaggle_link.py +0 -0
  294. {letify-3.0.7 → letify-3.0.8}/tests/test_link_agent.py +0 -0
  295. {letify-3.0.7 → letify-3.0.8}/tests/test_link_channel.py +0 -0
  296. {letify-3.0.7 → letify-3.0.8}/tests/test_link_command_channel.py +0 -0
  297. {letify-3.0.7 → letify-3.0.8}/tests/test_link_exec.py +0 -0
  298. {letify-3.0.7 → letify-3.0.8}/tests/test_link_log.py +0 -0
  299. {letify-3.0.7 → letify-3.0.8}/tests/test_link_mailbox_close.py +0 -0
  300. {letify-3.0.7 → letify-3.0.8}/tests/test_link_opt_in.py +0 -0
  301. {letify-3.0.7 → letify-3.0.8}/tests/test_link_signal.py +0 -0
  302. {letify-3.0.7 → letify-3.0.8}/tests/test_link_ssh_stream.py +0 -0
  303. {letify-3.0.7 → letify-3.0.8}/tests/test_link_upload.py +0 -0
  304. {letify-3.0.7 → letify-3.0.8}/tests/test_linkd.py +0 -0
  305. {letify-3.0.7 → letify-3.0.8}/tests/test_network_guard.py +0 -0
  306. {letify-3.0.7 → letify-3.0.8}/tests/test_notebook.py +0 -0
  307. {letify-3.0.7 → letify-3.0.8}/tests/test_parallel_placement.py +0 -0
  308. {letify-3.0.7 → letify-3.0.8}/tests/test_paths.py +0 -0
  309. {letify-3.0.7 → letify-3.0.8}/tests/test_portmap.py +0 -0
  310. {letify-3.0.7 → letify-3.0.8}/tests/test_protocol.py +0 -0
  311. {letify-3.0.7 → letify-3.0.8}/tests/test_providers.py +0 -0
  312. {letify-3.0.7 → letify-3.0.8}/tests/test_punch_sockets.py +0 -0
  313. {letify-3.0.7 → letify-3.0.8}/tests/test_quic_removed.py +0 -0
  314. {letify-3.0.7 → letify-3.0.8}/tests/test_remoting.py +0 -0
  315. {letify-3.0.7 → letify-3.0.8}/tests/test_render.py +0 -0
  316. {letify-3.0.7 → letify-3.0.8}/tests/test_run_control.py +0 -0
  317. {letify-3.0.7 → letify-3.0.8}/tests/test_run_reattach.py +0 -0
  318. {letify-3.0.7 → letify-3.0.8}/tests/test_run_takeover.py +0 -0
  319. {letify-3.0.7 → letify-3.0.8}/tests/test_runtime.py +0 -0
  320. {letify-3.0.7 → letify-3.0.8}/tests/test_shell_workers.py +0 -0
  321. {letify-3.0.7 → letify-3.0.8}/tests/test_ship.py +0 -0
  322. {letify-3.0.7 → letify-3.0.8}/tests/test_store.py +0 -0
  323. {letify-3.0.7 → letify-3.0.8}/tests/test_strategies.py +0 -0
  324. {letify-3.0.7 → letify-3.0.8}/tests/test_stubs.py +0 -0
  325. {letify-3.0.7 → letify-3.0.8}/tests/test_suite_guards.py +0 -0
  326. {letify-3.0.7 → letify-3.0.8}/tests/test_tailcat_removed.py +0 -0
  327. {letify-3.0.7 → letify-3.0.8}/tests/test_transport.py +0 -0
  328. {letify-3.0.7 → letify-3.0.8}/tests/test_tunnel_agent_login.py +0 -0
  329. {letify-3.0.7 → letify-3.0.8}/tests/test_tunnel_setup.py +0 -0
  330. {letify-3.0.7 → letify-3.0.8}/tests/test_user_agent.py +0 -0
  331. {letify-3.0.7 → letify-3.0.8}/tests/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: letify
3
- Version: 3.0.7
3
+ Version: 3.0.8
4
4
  Summary: Declarations that become infrastructure.
5
5
  Project-URL: Homepage, https://github.com/DarkPyonix/letify
6
6
  Project-URL: Documentation, https://github.com/DarkPyonix/letify/tree/main/docs
@@ -2210,6 +2210,33 @@ A `PunchOffer` with no mappings is a punch with no sockets and nothing else. It
2210
2210
 
2211
2211
  letify implements the trait with its provider bootstraps (ssh, `colab exec`, the Kaggle API and the Drive mailbox), and these are its default rendezvous. The owner also operates a signalling service at `letify.darkpyonix.dev`, a Cloudflare Worker, which letify uses as an auxiliary rendezvous in three cases: reconnection and resumption after the client changed (a new network or a new machine), pairing of two runtimes under `host="distributed"` without the client, and nodes that have no bootstrap. The service carries only small messages, signed address records and punch timing, and never session data, so its cost is small. When the service is unreachable, letify uses the bootstrap. That changes only how addresses are exchanged, not the path that carries data, so it is not a fallback to a slower path. A relay never runs on the service: a Worker cannot accept UDP, and a relay is a node role as the [Relay](#link-relay) subsection says. Another program implements it with its own signalling. darkpyonix Ember, for example, would use a hub that publishes pkarr signed packets. The library holds no provider-specific code.
2212
2212
 
2213
+ #### Rendezvous demultiplexer <!-- id: link-rendezvous-demux -->
2214
+
2215
+ > One Rendezvous shared by many concurrent punches: `Demux` routes each message to the queue of its sender.
2216
+
2217
+ A node with one identity has one `Rendezvous` and one receive cursor. A punch (`driver::punch`, `punch_session`) reads that cursor and discards every message whose sender is not its peer, so two punches over the same Rendezvous at once steal and discard each other's messages. `letify_link::rendezvous::Demux<R>` removes that: it owns the Rendezvous `R`, runs one pump task that calls `R::recv()` and files each `(from, bytes)` under `from`, and hands out one `PeerRendezvous` per peer. The driver API is unchanged: a `PeerRendezvous` is a `Rendezvous` and is passed as `rdv`.
2218
+
2219
+ 1. **API.** `Demux::new(r: R) -> Demux<R>` (needs a running tokio runtime, spawns the pump). `Demux::peer(node) -> PeerRendezvous<R>` returns the handle of a node, for an initiator that knows whom it dials. `Demux::accept().await -> io::Result<(NodeId, PeerRendezvous<R>)>` waits for a sender that has no live handle and returns its handle, with every message already queued for it. `PeerRendezvous::send(to, msg)` passes straight to `R::send`, to any node. `PeerRendezvous::recv()` yields only the messages whose sender is the handle's node, in arrival order. Counters: `PeerRendezvous::dropped()`, `Demux::dropped()` (all handles and pending peers) and `Demux::refused()`.
2220
+ 2. **Bounded queues.** Each peer queue holds at most `PEER_QUEUE` (64) messages. A message that arrives at a full queue evicts the oldest message of that queue and adds 1 to the dropped counters, so one chatty sender loses only its own oldest messages and cannot grow memory or push out another peer. Messages are at most `MAX_MESSAGE` bytes, so a queue holds at most 256 KiB.
2221
+ 3. **Unclaimed peers.** A message from a sender with no live handle opens a pending peer holding its messages in a queue as in item 2. At most `MAX_PENDING_PEERS` (64) peers are pending; a message from a further new sender is discarded and counted in `refused()`, and messages from an already pending sender are still queued. A pending peer is removed `PENDING_TTL` (60 s, the signalling TTL) after its first message if nobody claimed it, and its messages are discarded. Expiry is checked when a message arrives and when `accept` or `peer` runs. `accept` returns pending peers oldest first. `peer(node)` for a node that is pending claims that pending peer with its messages, so `peer` and `accept` never both hand out the same pending peer.
2222
+ 4. **Handles.** `peer(node)` for a node that already has a live handle returns another handle on the same queue; the handles compete for its messages. A handle that is dropped discards the messages still queued for it, and when the last handle of a node is dropped the node has no live handle. The next message from that node is a new pending peer for `accept`, and a later `peer(node)` starts empty (plus what a pending peer holds). Messages are not kept for a dropped handle, so a device that retries after its first punch ended is accepted as a new peer.
2223
+ 5. **Pump errors.** An error of kind `BrokenPipe`, `NotConnected` or `UnexpectedEof` from `R::recv` means the Rendezvous is closed and ends the pump. Any other error is treated as transient: the pump waits 1 s, doubling to at most 30 s (`PUMP_RETRY_FIRST`, `PUMP_RETRY_MAX`), and calls `recv` again, and a recv that succeeds resets the wait. After `PUMP_MAX_RETRIES` (8) errors in a row the pump ends with the last error. When the pump ends, every `PeerRendezvous::recv` and `accept` first returns what is already queued, then fails with that error (same kind and message). Nothing is retried after that, and nothing falls back: the embedder builds a new `Demux`.
2224
+ 6. **Drop.** Dropping the `Demux` aborts the pump, which drops its reference to `R`. Handles keep `R` alive for `send`. A `recv` or `accept` after the drop returns what is queued, then fails with `BrokenPipe` ("the demux was dropped").
2225
+ 7. **Undecodable messages.** The pump routes raw bytes and does not decode them, so a message that fails `Message::decode` is delivered to the handle like any other and the driver skips it as it does today. Routing by sender trusts the sender reported by `R`, as the driver does; the session handshake authenticates the peer.
2226
+
2227
+ A server:
2228
+
2229
+ ```rust
2230
+ let demux = Demux::new(SignalRendezvous::new(url, identity.clone())?);
2231
+ loop {
2232
+ let (peer, rdv) = demux.accept().await?;
2233
+ tokio::spawn(async move {
2234
+ let got = punch_session(&rdv, peer, Endpoint::Responder { acceptor }, &opts).await;
2235
+ // use got.session; rdv is dropped when the punch ends
2236
+ });
2237
+ }
2238
+ ```
2239
+
2213
2240
  #### Signalling service <!-- id: link-signal -->
2214
2241
 
2215
2242
  > A Worker with one mailbox per node id carries signed bootstrap lines to a machine that has no address, so the machine needs no ssh.
@@ -70,7 +70,7 @@ distributed: Final = Host.distributed
70
70
  # The enum class stays importable from letify.declare.instance for letify's own use.
71
71
  del Host
72
72
 
73
- __version__ = "3.0.7"
73
+ __version__ = "3.0.8"
74
74
 
75
75
 
76
76
  def fetch(tensor): # type: ignore[no-untyped-def]
@@ -396,14 +396,14 @@ dependencies = [
396
396
 
397
397
  [[package]]
398
398
  name = "letify"
399
- version = "3.0.7"
399
+ version = "3.0.8"
400
400
  dependencies = [
401
401
  "letify-link",
402
402
  ]
403
403
 
404
404
  [[package]]
405
405
  name = "letify-link"
406
- version = "3.0.7"
406
+ version = "3.0.8"
407
407
  dependencies = [
408
408
  "base64",
409
409
  "ed25519-dalek",
@@ -8,7 +8,7 @@ resolver = "3"
8
8
  members = ["letify", "letify-link"]
9
9
 
10
10
  [workspace.package]
11
- version = "3.0.7"
11
+ version = "3.0.8"
12
12
  edition = "2024"
13
13
  license = "Apache-2.0"
14
14
  repository = "https://github.com/DarkPyonix/letify"
@@ -14,7 +14,7 @@ categories = ["development-tools", "network-programming"]
14
14
  [dependencies]
15
15
  # The pin keeps a published letify on the letify-link of its own release. scripts/version.py
16
16
  # rewrites it with the version.
17
- letify-link = { version = "=3.0.7", path = "../letify-link" }
17
+ letify-link = { version = "=3.0.8", path = "../letify-link" }
18
18
 
19
19
  [features]
20
20
  # Enable the relay role of letify-link.
@@ -0,0 +1,338 @@
1
+ //! The rendezvous demultiplexer: one [`Rendezvous`] shared by many concurrent punches. It owns
2
+ //! the pump that reads the shared Rendezvous, the per-peer queues and their bounds. It does not
3
+ //! decode messages, authenticate senders or run punches. SPEC.md "Rendezvous demultiplexer".
4
+ //!
5
+ //! ```no_run
6
+ //! use std::sync::Arc;
7
+ //! use letify_link::driver::{Endpoint, PunchOptions, punch_session};
8
+ //! use letify_link::rendezvous::{Demux, MemoryHub};
9
+ //! use letify_link::{Acceptor, Config, Identity, PeerPolicy};
10
+ //!
11
+ //! # async fn run() -> std::io::Result<()> {
12
+ //! let identity = Identity::generate();
13
+ //! let hub = MemoryHub::new();
14
+ //! let acceptor = Arc::new(Acceptor::new(
15
+ //! identity.clone(),
16
+ //! PeerPolicy::from_fn(|_| true),
17
+ //! Config::default(),
18
+ //! ));
19
+ //! let demux = Demux::new(hub.endpoint(identity.node_id()));
20
+ //! loop {
21
+ //! let (peer, rdv) = demux.accept().await?;
22
+ //! let acceptor = acceptor.clone();
23
+ //! tokio::spawn(async move {
24
+ //! let opts = PunchOptions::default();
25
+ //! let _ = punch_session(&rdv, peer, Endpoint::Responder { acceptor }, &opts).await;
26
+ //! });
27
+ //! }
28
+ //! # }
29
+ //! ```
30
+
31
+ use std::collections::{HashMap, VecDeque};
32
+ use std::io;
33
+ use std::sync::{Arc, Mutex, MutexGuard};
34
+ use std::time::Duration;
35
+
36
+ use tokio::sync::Notify;
37
+ use tokio::task::JoinHandle;
38
+ use tokio::time::Instant;
39
+
40
+ use super::Rendezvous;
41
+ use crate::identity::NodeId;
42
+
43
+ /// The most messages queued for one peer. At the limit the oldest message is dropped.
44
+ pub const PEER_QUEUE: usize = 64;
45
+ /// The most peers waiting in [`Demux::accept`] at once.
46
+ pub const MAX_PENDING_PEERS: usize = 64;
47
+ /// How long an unclaimed peer waits, the time to live of the signalling service.
48
+ pub const PENDING_TTL: Duration = Duration::from_secs(60);
49
+ /// The first wait before the pump calls `recv` again after a transient error.
50
+ pub const PUMP_RETRY_FIRST: Duration = Duration::from_secs(1);
51
+ /// The longest wait between two retries of the pump.
52
+ pub const PUMP_RETRY_MAX: Duration = Duration::from_secs(30);
53
+ /// The pump ends after this many errors in a row.
54
+ pub const PUMP_MAX_RETRIES: u32 = 8;
55
+
56
+ #[derive(Default)]
57
+ struct Entry {
58
+ items: VecDeque<Vec<u8>>,
59
+ dropped: u64,
60
+ handles: usize,
61
+ notify: Arc<Notify>,
62
+ }
63
+
64
+ impl Entry {
65
+ fn push(&mut self, msg: Vec<u8>) -> bool {
66
+ let evicted = self.items.len() >= PEER_QUEUE;
67
+ if evicted {
68
+ self.items.pop_front();
69
+ self.dropped += 1;
70
+ }
71
+ self.items.push_back(msg);
72
+ evicted
73
+ }
74
+ }
75
+
76
+ #[derive(Default)]
77
+ struct State {
78
+ live: HashMap<NodeId, Entry>,
79
+ pending: VecDeque<(NodeId, Entry, Instant)>,
80
+ end: Option<(io::ErrorKind, String)>,
81
+ dropped: u64,
82
+ refused: u64,
83
+ }
84
+
85
+ impl State {
86
+ fn expire(&mut self) {
87
+ let now = Instant::now();
88
+ while let Some((_, _, first)) = self.pending.front() {
89
+ if now.duration_since(*first) < PENDING_TTL {
90
+ break;
91
+ }
92
+ self.pending.pop_front();
93
+ }
94
+ }
95
+
96
+ fn end_error(&self) -> Option<io::Error> {
97
+ self.end
98
+ .as_ref()
99
+ .map(|(kind, text)| io::Error::new(*kind, text.clone()))
100
+ }
101
+ }
102
+
103
+ struct Shared {
104
+ state: Mutex<State>,
105
+ accept_notify: Notify,
106
+ }
107
+
108
+ impl Shared {
109
+ fn lock(&self) -> MutexGuard<'_, State> {
110
+ self.state.lock().unwrap_or_else(|e| e.into_inner())
111
+ }
112
+
113
+ /// End the pump: queued messages stay readable, then every recv fails with `kind`.
114
+ fn finish(&self, kind: io::ErrorKind, text: String) {
115
+ let mut st = self.lock();
116
+ if st.end.is_none() {
117
+ st.end = Some((kind, text));
118
+ }
119
+ for entry in st.live.values() {
120
+ entry.notify.notify_waiters();
121
+ }
122
+ drop(st);
123
+ self.accept_notify.notify_waiters();
124
+ }
125
+
126
+ fn route(&self, from: NodeId, msg: Vec<u8>) {
127
+ let mut st = self.lock();
128
+ st.expire();
129
+ if let Some(entry) = st.live.get_mut(&from) {
130
+ let evicted = entry.push(msg);
131
+ let notify = entry.notify.clone();
132
+ st.dropped += u64::from(evicted);
133
+ drop(st);
134
+ notify.notify_waiters();
135
+ } else if let Some((_, entry, _)) = st.pending.iter_mut().find(|(n, _, _)| *n == from) {
136
+ let evicted = entry.push(msg);
137
+ st.dropped += u64::from(evicted);
138
+ } else if st.pending.len() < MAX_PENDING_PEERS {
139
+ let mut entry = Entry::default();
140
+ entry.push(msg);
141
+ st.pending.push_back((from, entry, Instant::now()));
142
+ drop(st);
143
+ self.accept_notify.notify_waiters();
144
+ } else {
145
+ st.refused += 1;
146
+ }
147
+ }
148
+ }
149
+
150
+ fn is_closed(kind: io::ErrorKind) -> bool {
151
+ matches!(
152
+ kind,
153
+ io::ErrorKind::BrokenPipe | io::ErrorKind::NotConnected | io::ErrorKind::UnexpectedEof
154
+ )
155
+ }
156
+
157
+ async fn pump<R: Rendezvous>(rdv: Arc<R>, shared: Arc<Shared>) {
158
+ let mut wait = PUMP_RETRY_FIRST;
159
+ let mut failures = 0u32;
160
+ loop {
161
+ match rdv.recv().await {
162
+ Ok((from, msg)) => {
163
+ failures = 0;
164
+ wait = PUMP_RETRY_FIRST;
165
+ shared.route(from, msg);
166
+ }
167
+ Err(e) => {
168
+ failures += 1;
169
+ if is_closed(e.kind()) || failures >= PUMP_MAX_RETRIES {
170
+ shared.finish(e.kind(), e.to_string());
171
+ return;
172
+ }
173
+ tokio::time::sleep(wait).await;
174
+ wait = (wait * 2).min(PUMP_RETRY_MAX);
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ /// Shares one [`Rendezvous`] between many concurrent punches by routing each message to the
181
+ /// queue of its sender. Dropping it stops the pump.
182
+ pub struct Demux<R: Rendezvous + 'static> {
183
+ rdv: Arc<R>,
184
+ shared: Arc<Shared>,
185
+ pump: JoinHandle<()>,
186
+ }
187
+
188
+ impl<R: Rendezvous + 'static> Demux<R> {
189
+ /// Take `rdv` and start the pump. Needs a running tokio runtime.
190
+ pub fn new(rdv: R) -> Self {
191
+ let rdv = Arc::new(rdv);
192
+ let shared = Arc::new(Shared {
193
+ state: Mutex::new(State::default()),
194
+ accept_notify: Notify::new(),
195
+ });
196
+ let pump = tokio::spawn(pump(rdv.clone(), shared.clone()));
197
+ Demux { rdv, shared, pump }
198
+ }
199
+
200
+ /// The handle of `node`. A pending peer of that node is claimed with its messages, and a
201
+ /// node that already has a handle gets another on the same queue.
202
+ pub fn peer(&self, node: NodeId) -> PeerRendezvous<R> {
203
+ let mut st = self.shared.lock();
204
+ st.expire();
205
+ if !st.live.contains_key(&node) {
206
+ let entry = match st.pending.iter().position(|(n, _, _)| *n == node) {
207
+ Some(i) => st.pending.remove(i).map(|(_, e, _)| e).unwrap_or_default(),
208
+ None => Entry::default(),
209
+ };
210
+ st.live.insert(node, entry);
211
+ }
212
+ self.handle(&mut st, node)
213
+ }
214
+
215
+ /// Wait for a sender that has no handle and return its handle, with the messages already
216
+ /// queued for it. Fails with the pump's error once the pump has ended and no peer waits.
217
+ pub async fn accept(&self) -> io::Result<(NodeId, PeerRendezvous<R>)> {
218
+ loop {
219
+ let notified = self.shared.accept_notify.notified();
220
+ tokio::pin!(notified);
221
+ notified.as_mut().enable();
222
+ {
223
+ let mut st = self.shared.lock();
224
+ st.expire();
225
+ if let Some((node, entry, _)) = st.pending.pop_front() {
226
+ st.live.insert(node, entry);
227
+ let handle = self.handle(&mut st, node);
228
+ return Ok((node, handle));
229
+ }
230
+ if let Some(e) = st.end_error() {
231
+ return Err(e);
232
+ }
233
+ }
234
+ notified.await;
235
+ }
236
+ }
237
+
238
+ fn handle(&self, st: &mut State, node: NodeId) -> PeerRendezvous<R> {
239
+ let entry = st.live.get_mut(&node).expect("entry was just inserted");
240
+ entry.handles += 1;
241
+ PeerRendezvous {
242
+ node,
243
+ rdv: self.rdv.clone(),
244
+ shared: self.shared.clone(),
245
+ notify: entry.notify.clone(),
246
+ }
247
+ }
248
+
249
+ /// Messages dropped so far because a queue was full, over all peers.
250
+ pub fn dropped(&self) -> u64 {
251
+ self.shared.lock().dropped
252
+ }
253
+
254
+ /// Messages discarded so far because [`MAX_PENDING_PEERS`] peers were already waiting.
255
+ pub fn refused(&self) -> u64 {
256
+ self.shared.lock().refused
257
+ }
258
+ }
259
+
260
+ impl<R: Rendezvous + 'static> Drop for Demux<R> {
261
+ fn drop(&mut self) {
262
+ self.pump.abort();
263
+ self.shared
264
+ .finish(io::ErrorKind::BrokenPipe, "the demux was dropped".into());
265
+ }
266
+ }
267
+
268
+ /// The view of a [`Demux`] for one peer: `recv` yields only that peer's messages and `send`
269
+ /// passes through. It is a [`Rendezvous`], so it is the `rdv` of `driver::punch`.
270
+ pub struct PeerRendezvous<R: Rendezvous + 'static> {
271
+ node: NodeId,
272
+ rdv: Arc<R>,
273
+ shared: Arc<Shared>,
274
+ notify: Arc<Notify>,
275
+ }
276
+
277
+ impl<R: Rendezvous + 'static> PeerRendezvous<R> {
278
+ /// The node whose messages this handle yields.
279
+ pub fn node(&self) -> NodeId {
280
+ self.node
281
+ }
282
+
283
+ /// Messages of this peer dropped so far because its queue was full.
284
+ pub fn dropped(&self) -> u64 {
285
+ self.shared
286
+ .lock()
287
+ .live
288
+ .get(&self.node)
289
+ .map_or(0, |e| e.dropped)
290
+ }
291
+ }
292
+
293
+ impl<R: Rendezvous + 'static> Drop for PeerRendezvous<R> {
294
+ fn drop(&mut self) {
295
+ let mut st = self.shared.lock();
296
+ if let Some(entry) = st.live.get_mut(&self.node) {
297
+ entry.handles -= 1;
298
+ if entry.handles == 0 {
299
+ st.live.remove(&self.node);
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ impl<R: Rendezvous + 'static> Rendezvous for PeerRendezvous<R> {
306
+ async fn send(&self, to: NodeId, msg: Vec<u8>) -> io::Result<()> {
307
+ self.rdv.send(to, msg).await
308
+ }
309
+
310
+ async fn recv(&self) -> io::Result<(NodeId, Vec<u8>)> {
311
+ loop {
312
+ let notified = self.notify.notified();
313
+ tokio::pin!(notified);
314
+ notified.as_mut().enable();
315
+ {
316
+ let mut st = self.shared.lock();
317
+ let end = st.end_error();
318
+ if let Some(entry) = st.live.get_mut(&self.node)
319
+ && let Some(msg) = entry.items.pop_front()
320
+ {
321
+ return Ok((self.node, msg));
322
+ }
323
+ if let Some(e) = end {
324
+ return Err(e);
325
+ }
326
+ }
327
+ notified.await;
328
+ }
329
+ }
330
+ }
331
+
332
+ impl<R: Rendezvous + 'static> std::fmt::Debug for PeerRendezvous<R> {
333
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
334
+ f.debug_struct("PeerRendezvous")
335
+ .field("node", &self.node)
336
+ .finish()
337
+ }
338
+ }
@@ -12,6 +12,12 @@ use std::time::Duration;
12
12
 
13
13
  use tokio::sync::mpsc;
14
14
 
15
+ mod demux;
16
+ pub use demux::{
17
+ Demux, MAX_PENDING_PEERS, PEER_QUEUE, PENDING_TTL, PUMP_MAX_RETRIES, PUMP_RETRY_FIRST,
18
+ PUMP_RETRY_MAX, PeerRendezvous,
19
+ };
20
+
15
21
  use crate::identity::NodeId;
16
22
  use crate::stun::NatType;
17
23