gitoriaLog in with ident

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainbb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmremain/plugins/http1/native_web_socket_server.hl

4.0 KB

  1. \* hl:http1 — the native WebSocket server. Subclass it (`inherit
  2. NativeWebSocketServer`) and answer the declared events below; each
  3. connected peer arrives as a WsClient (send/ping/close). AUTO-LISTEN: the
  4. file root IS the constructor and ends with listen(), so
  5. `new NativeWebSocketServer(port = 8888)` serves immediately. *\
  6. /* Mission 064 (decision D9): the h1 plugin performs the RFC 6455 Upgrade/101
  7. handshake and framing (shared core plugins/http/ws_common.zig); this
  8. wrapper maps the native event stream onto on/emit, mirroring
  9. NativeHttpServer. A SUBCLASS does not inherit this run body and calls
  10. listen() from its own root. */
  11. \* A peer completed the upgrade and is connected. *\
  12. emit connect(
  13. WsClient client \\ the new peer — send/ping/close
  14. )
  15. \* A complete text (or binary) message arrived from a peer. *\
  16. emit message(
  17. WsClient client \\ who sent it
  18. String data \\ the message payload
  19. )
  20. \* The peer answered a client.ping(). *\
  21. emit pong(
  22. WsClient client \\ who answered
  23. )
  24. \* A connection ended — the peer is already unregistered. *\
  25. emit close(
  26. WsClient client \\ who left
  27. )
  28. \* OPTIONAL: plain HTTP answered on the same port, exactly as
  29. NativeHttpServer's request. *\
  30. emit request(
  31. Hybrid req \\ method, path, headers, body, bytes, params, respond
  32. )
  33. Number port = 8080 \\ the port listen() binds
  34. String host = "0.0.0.0" \\ the interface to bind
  35. Number threads = 4 \\ I/O worker threads
  36. Boolean listening = false \\ true after a successful bind
  37. Hybrid clients = {} \\ live WsClients by connection id
  38. Number #srcId = 0
  39. Number #wsSrcId = 0
  40. \* Bind the configured port and start the WebSocket engine (idempotent). *\
  41. listen() {
  42. if (listening == true) {
  43. return null
  44. }
  45. srv = __native("http1.create_server", port, host, "", "", threads)
  46. if (srv == null) {
  47. // A REFUSAL, NOT PROSE (mission 286) — same reason as NativeHttpServer's.
  48. hlError("hl:http1: listen() failed: could not bind port " + port + " on " + host + " — the port is already taken. The line just above, 'bind() failed on port " + port + "', names the process holding it: stop that process, or start this app on another port (--port N, or HL_PORT=N)")
  49. }
  50. wsev = __native("http1.ws_events")
  51. listening = true
  52. #srcId = __native("eventloop.register", srv, "request")
  53. #wsSrcId = __native("eventloop.register", wsev, "wsEvent")
  54. }
  55. \* One text frame to EVERY connected peer; answers how many received it. *\
  56. broadcast(
  57. String text \\ the frame to send
  58. ) {
  59. return __native("http1.ws_broadcast", text)
  60. }
  61. \* Stop this server: both event sources retired, workers joined, listener
  62. closed — the port is free again. Answers false when not listening. *\
  63. close() {
  64. if (listening == false) {
  65. return false
  66. }
  67. listening = false
  68. __native("eventloop.unregister", #srcId)
  69. __native("eventloop.unregister", #wsSrcId)
  70. return __native("http1.close", port)
  71. }
  72. // Raw native events ({ kind, id, data, binary, code }) re-emitted as the
  73. // documented surface — emit is the universal primitive.
  74. on wsEvent(ev) {
  75. key = "c" + ev.id
  76. if (ev.kind == "connect") {
  77. client = new WsClient(ev.id, ev.cookie, ev.host != '' ? ev.host : null, headerHash(ev.headers)) // the upgrade's cookie, host and headers ride with the connection (creator, 2026-09-12; tickets #74, #105)
  78. clients[key] = client
  79. emit connect(client)
  80. }
  81. if (ev.kind == "message") {
  82. client = clients[key]
  83. if (client != null) {
  84. emit message(client, ev.data)
  85. }
  86. }
  87. if (ev.kind == "pong") {
  88. client = clients[key]
  89. if (client != null) {
  90. emit pong(client)
  91. }
  92. }
  93. if (ev.kind == "close") {
  94. client = clients[key]
  95. clients[key] = null
  96. if (client != null) {
  97. emit close(client)
  98. }
  99. }
  100. }
  101. // The upgrade's headers arrive as `name: value` lines (names already lowercase);
  102. // a connection is handed them as a hash (ticket #105).
  103. headerHash(lines) {
  104. let nl = "
  105. "
  106. let out = {}
  107. if (lines == null || lines == '') { return out }
  108. for (line of lines.split(nl)) {
  109. let colon = line.indexOf(': ')
  110. if (colon > 0) { out[line.slice(0, colon)] = line.slice(colon + 2) }
  111. }
  112. return out
  113. }
  114. // Run body: bind the configured port (idempotent, like NativeHttpServer).
  115. listen()

Branches

Latest commits

  • bb64d57cmission 012 (ticket #25 API part): every /api/projects/<x>/… route takes the project's id (12-char record id) as well as its slug, same answers byte for byte; tickets stay under their project, no global /api/tickets/<x>. gate 315/0 (old code: the 13 id checks fail), connect 60/0, live-data copy old vs new 1,484 identical, slug vs id 772 identicalmre
  • 7538b034mission 011 (ticket #25 web part): short page URLs /<slug> and /<slug>/<number>; /projects/<slug>, /projects/<slug>/<n>, /projects/<slug>/tickets/<n> and /tickets/<ref> answer 301 (current slug); slug pages moved behind hl:web's own routes after construction (they answered /__hl/* and /components/*.hl); reserved slugs refused; API paths unchanged. gate 293/0, connect 60/0, live-data copy 187/0, API old vs new: only page links differmre
  • 0369106emission 010 (code order) 4/4: README file map + import order + 'Same output' test, STATUS (entry, lessons, how to verify), LOG, report; tests/realdata-baseline.mjs + realdata-compare*.py (a cleanup answers the same on live data), tests/letcount.pymre
  • a75e0279mission 010 (code order) 3/4: let only where a variable is reassigned or re-bound in a loop body (456 lets → plain declarations; Hybriel refuses a plain declaration inside a loop on its 2nd pass). gate 249/0, connect 60/0, real-data reads identical, a 50-step write sequence (API + faces) identical to the old codemre
  • e9d5c618mission 010 (code order) 2/4: one lib/ file per topic — store.hl split into projects / tickets (+ relations) / events / tickets-helpers, util.hl shared helpers (env, storage dir, URLs, sorts, Vienna time), the function routes out of project.hl into lib/api.hl (thin; auth/filters/Accept in api-helpers.hl), invite + member-removal logic out of the faces/routes into invites.hl / tickets.hl; project.hl is the map. /login/callback gets req + the session store by reference. gate 249/0, connect 60/0, real-data reads identicalmre
  • 97e269b5mission 010 (code order) 1/4: .hl files out of the root — lib/ (store, users, connections, invites, migrate, markdown, mdview, import = ticketfile, util = localtime, jsoncheck, api-helpers = api), tools/import.hl, components/styles.hl; import paths only. gate 249/0, connect 60/0, real-data reads identicalmre
  • 38f9d10ftickets: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gate 249/0, connect 60/0mre
  • d3db6139tickets: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 249/0, connect 60/0mre
  • bce182e3tickets: Hybriel master 7eea0d32 (#126 memory, #48 lambda copies its argument); migrate.hl lambdas take &logmre
  • 4137be0fantcolony#40: mission references point to the moved missionsmre
  • 9bfba36aantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • c7bd2645tickets: Hybriel master 73267707 (#122 fixed); compactNow workaround removed (#110 covered)mre
  • 2ab91ee9tickets: gate checks rows appear once (session sync); re-vendor to ff51cf46 stopped on hybriel#122, stays 837fe120mre
  • e01c2b1dtickets#24: installable app (manifest, service worker, offline list), own icon; gate waits for the hello's pongmre
  • 752fbb7fdeploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • 38bdd5e4deploy.sh: never send .git or .gitignore to Byrodinmre
  • f12fa1bcState of 2026-09-27, before the move to gitoriamre