Changes in 2.0
What changed from JBend 1.4, and what old code needs
JBend 1.x (2020 to 2022) was assembled in Main with method calls and grew a config language that was never finished or committed.
Version 2.0 finishes that idea and rebuilds the parts that could not be trusted on a public server. Class names and the public methods
1.x applications used are kept.
New
- Startup from configuration.
Mainreadsconfig/application.confand does nothing else. Blocks for web, WebSocket and TCP servers, the bridge, the proxy, database, login, caretaker and application threads, with handler classes named in the file. - Config errors are reported with line numbers before anything starts. Values can come from environment variables.
- Request and Response objects and a
handlehook for HTTP, with deferred responses for database-backed pages. - Mounts, page variables,
upgrade(WebSockets on the web server's port),/api/status. - The WebSocket bridge, for putting a TCP server in a browser.
- Query parameters:
new ServerQuery("... WHERE name = ?", name), plusvalue(),count(),failed(). - Sessions with random tokens, and a JSON account API.
- Custom console commands with
Console.register. - Bind addresses and connection limits per server.
Fixed
| Area | 1.x | 2.0 |
|---|---|---|
| Reading | One buffer shared by every connection, decoded whole as a string. Requests split across reads were lost; binary data was mangled. | Bytes are collected per connection until a whole message is there. |
| Writing | One non-blocking write per message. Whatever the socket would not take at once was dropped, so large files arrived truncated. | Per-connection send queue, drained as the socket allows. |
| Connections | Looked up by remote port, so two clients behind different addresses with the same port were confused. | Each socket carries its own connection object. |
| Static files | GET /../../etc/passwd was served. Most types were sent with the wrong content type. | Paths are resolved and confined; a full content-type table. |
| HTTP | No keep-alive, no Content-Length, no HEAD. | HTTP/1.1 with all three. |
| WebSocket | Single unfragmented frames up to 64 KB; no ping, no close handshake, no origin check. | The full framing rules of RFC 6455. |
| Passwords | Encrypted with a key written in the source, so anyone with the code could decrypt every password. | Salted PBKDF2 hashes. |
| Identity | A usr cookie containing the username. Anyone could set it and be anyone. | Random session tokens, stored hashed. |
| Admin | A web form that ran console commands for whoever sent the right cookie. | Removed. The console is the terminal. |
| SQL | Statements built by joining strings, including text from requests. | Prepared statements with parameters. |
| Database | A queue shared between threads without synchronisation; a lost connection meant a restart; the caretaker called System.exit when a check failed. | A thread-safe queue, automatic reconnect, and a caretaker that only reports. |
| CPU | The console, login handler, data manager and application loop spun without sleeping, each holding a core at 100%. | Every thread blocks or sleeps when it has nothing to do. |
| Repository | The MySQL driver's full source tree, a built jar, object files and editor files were committed. | The driver jar and its licence only. |
Running a 1.x application on 2.0
Applications that compiled against 1.4 need these changes:
| 1.x | 2.0 |
|---|---|
Your own com.Main building a Launcher | Delete it and describe the application in config/application.conf; or keep it, using new Launcher() and the add... methods, which still exist. |
new Server(new WebSocket(port) { ... }) inline | A named subclass, referenced by handler. processCustomMessage is unchanged. |
users, bans, settings tables | jbend_users, jbend_sessions, jbend_bans. Old tables are left alone and no longer read. Accounts must be registered again. |
Checking the usr cookie | req.user() or c.getUser(). |
Form posts with packet=0/1/3 for register, login, logout | POST /api/register, /api/login, /api/logout. |
env.cfg and routes.cfg next to src | config/application.conf; routes inline or in a file named by routes. |
ServerQuery with SQL built from strings | Still runs. Move values to ? parameters. |
getResponse() text parsing | Still works. value("column") is simpler. |
processGET / processPOST overrides | Still called. New code should override handle. |
Main.launcher.cryptography() | Still there. The hand-written ciphers in com.util.crypt were a learning exercise and are not used by JBend for anything; do not protect real data with them. |