1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Paged SyncState, Added Ping, Required ALPN on the server, Capped retention ages, Closed idle database connections

- Protocol 8: SyncStateRequest takes `after` (a Pair), SyncState has
  `more` and 32768 heads at most (MAX_HEADS_PER_PACKET), the lists and
  missing attachments in the first page only; heads_after in storage,
  both ends of replication read in pages (step 17)
- Protocol 8: Ping / Pong (19, 20) keep an idle connection open
  (IDLE_TIMEOUT_SECS 300, KEEPALIVE_SECS 60). Client::ping,
  BakaShrot_Ping, Python ping(), C# Ping(), the PureBasic prototype; the
  tool's --follow, Python's follow(), C#'s Follow() and the replication
  links ping every minute while waiting longer, so sync_interval over
  5 min works now (dropped from known-issues.md)
- The server closes a client offering no ALPN right after TLS: rustls
  only refused one offering other protocols
- Retention ages are 100 years at most (MAX_RETENTION_AGE); the cutoff
  is computed once, saturating (Retention::cutoff): a huge age wrapped
  around to almost nothing in milliseconds
- [server] idle_database_connections (8 by default, 0-512): the idle
  read and query connections each pool keeps, those unused for a minute
  closed by a sweeping thread
- Tests for each, docs, the C header, revamp.md (step 18)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 23:19:58 +01:00
parent c513d8bf05
commit 6fae7e61c9
34 changed files with 1066 additions and 164 deletions
+39
View File
@@ -59,6 +59,7 @@ fn defaults() {
assert_eq!(server.synchronous, Synchronous::Full);
assert_eq!(server.max_attachment_size, 1 << 30);
assert_eq!(server.retention_interval, Duration::from_secs(60));
assert_eq!(server.idle_database_connections, 8);
assert_eq!(config.retention.age("logs"), None);
assert_eq!(config.replication.retry_delay, Duration::from_secs(10));
assert_eq!(config.replication.sync_interval, Duration::from_secs(5));
@@ -75,6 +76,7 @@ database = "data/messages.sqlite"
synchronous = "NORMAL"
max_attachment_size = 0
retention_interval = "1h30m"
idle_database_connections = 0
[replication]
push_to = ["10.0.0.2:7000", "server-3.lan:7001", "[fd00::4]:7000"]
@@ -89,6 +91,7 @@ batch_size = 10000
assert_eq!(config.server.synchronous, Synchronous::Normal);
assert_eq!(config.server.max_attachment_size, 0);
assert_eq!(config.server.retention_interval, Duration::from_secs(5400));
assert_eq!(config.server.idle_database_connections, 0);
assert_eq!(config.replication.push_to.len(), 3);
assert_eq!(config.replication.accept_from[2], "fd00::4");
assert_eq!(config.replication.retry_delay, Duration::from_secs(60));
@@ -122,6 +125,24 @@ logs = "30d"
assert_eq!(age("other"), days(365));
}
/// Ages go up to 100 years, and the cutoff never wraps around.
#[test]
fn retention_cutoff() {
let config = Config::parse(&with(
"[retention]\nlogs = \"36500d\"\nsensors = \"1h\"\n\"*\" = \"forever\"\n",
))
.unwrap();
assert_eq!(config.retention.age("logs"), days(36_500));
let now = 2_000_000_000_000;
assert_eq!(
config.retention.cutoff("sensors", now),
Some(now - 3_600_000)
);
// Longer than the clock is old: nothing is past it yet.
assert_eq!(config.retention.cutoff("logs", now), Some(0));
assert_eq!(config.retention.cutoff("other", now), None);
}
#[test]
fn permissions() {
let config = Config::parse(&with(
@@ -277,6 +298,14 @@ fn refusals() {
&with("retention_interval = \"0s\"\n"),
"'0s' isn't a duration",
),
(
&with("idle_database_connections = 513\n"),
"513 idle database connections: 0 to 512",
),
(
&with("idle_database_connections = -1\n"),
"invalid value: integer `-1`",
),
// [retention]
(
&with("[retention]\nlogs = \"30\"\n"),
@@ -295,6 +324,16 @@ fn refusals() {
&with("[retention]\nsensors.kitchen = \"1d\"\n"),
"quote names with dots",
),
// 100 years at most: past 2^64 ms an age once wrapped around to
// almost nothing ("18446744073709552s" was 384 ms).
(
&with("[retention]\nlogs = \"36501d\"\n"),
"100 years (36500d) at most",
),
(
&with("[retention]\nlogs = \"18446744073709552s\"\n"),
"100 years (36500d) at most",
),
// [replication]
(
&with("[replication]\npush_to = [\"10.0.0.2\"]\n"),