diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-08 03:29:35 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-08 03:29:35 +0100 |
| commit | 058432130628d00764663ecf819a9adc6793768d (patch) | |
| tree | d3f49f111fbfaa48647cca2600adcf9017af2d30 /src/bin/server/tls.rs | |
| parent | web: serve latest.php through PHP and refuse stray PHP files (diff) | |
| download | zagan-bet-058432130628d00764663ecf819a9adc6793768d.tar.gz zagan-bet-058432130628d00764663ecf819a9adc6793768d.zip | |
v5.0.0: protocol v5 and the browser frontend
Protocol v5 replaces newline lines with bounded [u32 len][text] frames and REQ/RES/EVT envelopes. Requests carry correlation ids and the server replays the last 256 replies per connection, so a gateway retry cannot double-debit and a late reply cannot clobber a newer request. HELLO/PONG carry server time; crash rounds announce started_at and push coalesced 10 Hz ticks. Crash now commits sha256(seed) before a round and reveals the seed when it ends, so clients recompute the crash point.
Adds the webd/ gateway: one blocking thread, one ClientCore and one pinned upstream TLS connection per session, an HttpOnly session cookie, takeover, and a 60-second grace window. The browser sends Command JSON and renders View JSON; it never speaks the game protocol or stores credentials.
Adds the vanilla TypeScript browser app at /play/ (login, lobby, all four games, history, notices, crash verification), the nginx /play and /ws routes, and the headless DOM smoke test. webd and the app stay out of the TUI/GUI/server build graph.
The client/server version moves to 5.0.0 in lockstep; v4 peers are refused at HELLO.
Diffstat (limited to '')
| -rw-r--r-- | src/bin/server/tls.rs | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/bin/server/tls.rs b/src/bin/server/tls.rs index 420b5b4..eb94637 100644 --- a/src/bin/server/tls.rs +++ b/src/bin/server/tls.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use std::io::{Read, Write}; | 1 | use std::io::{Read, Write}; |
| 2 | use std::net::TcpStream; | 2 | use std::net::TcpStream; |
| 3 | 3 | ||
| 4 | use zagan_bet::protocol::LineBuffer; | 4 | use zagan_bet::protocol::{FrameBuffer, write_frame}; |
| 5 | 5 | ||
| 6 | #[derive(Clone)] | 6 | #[derive(Clone)] |
| 7 | pub struct TlsServer { | 7 | pub struct TlsServer { |
| @@ -44,34 +44,31 @@ impl TlsServer { | |||
| 44 | 44 | ||
| 45 | pub struct TlsStream { | 45 | pub struct TlsStream { |
| 46 | stream: native_tls::TlsStream<TcpStream>, | 46 | stream: native_tls::TlsStream<TcpStream>, |
| 47 | lines: LineBuffer, | 47 | frames: FrameBuffer, |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | impl TlsStream { | 50 | impl TlsStream { |
| 51 | pub fn new(stream: native_tls::TlsStream<TcpStream>) -> Self { | 51 | pub fn new(stream: native_tls::TlsStream<TcpStream>) -> Self { |
| 52 | Self { | 52 | Self { |
| 53 | stream, | 53 | stream, |
| 54 | lines: LineBuffer::new(), | 54 | frames: FrameBuffer::new(), |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | pub fn read_line(&mut self, s: &mut String) -> std::io::Result<usize> { | 58 | /// Read one protocol frame. `Ok(0)` is EOF with no partial frame. |
| 59 | match self.lines.read_line(&mut self.stream)? { | 59 | pub fn read_frame(&mut self, out: &mut String) -> std::io::Result<usize> { |
| 60 | Some(line) => { | 60 | match self.frames.read_frame(&mut self.stream)? { |
| 61 | s.push_str(&line); | 61 | Some(frame) => { |
| 62 | s.push('\n'); | 62 | let length = frame.len(); |
| 63 | Ok(line.len() + 1) | 63 | out.push_str(&frame); |
| 64 | Ok(length) | ||
| 64 | } | 65 | } |
| 65 | None => Ok(0), | 66 | None => Ok(0), |
| 66 | } | 67 | } |
| 67 | } | 68 | } |
| 68 | 69 | ||
| 69 | pub fn write_line(&mut self, msg: &str) -> std::io::Result<()> { | 70 | pub fn write_frame(&mut self, msg: &str) -> std::io::Result<()> { |
| 70 | use std::io::Write; | 71 | write_frame(&mut self.stream, msg) |
| 71 | self.stream.write_all(msg.as_bytes())?; | ||
| 72 | self.stream.write_all(b"\n")?; | ||
| 73 | self.stream.flush()?; | ||
| 74 | Ok(()) | ||
| 75 | } | 72 | } |
| 76 | 73 | ||
| 77 | pub fn peer_addr(&self) -> std::io::Result<std::net::SocketAddr> { | 74 | pub fn peer_addr(&self) -> std::io::Result<std::net::SocketAddr> { |
