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:
@@ -504,6 +504,18 @@ pub extern "C" fn BakaShrot_Disconnect(client: i64) -> isize {
|
||||
})
|
||||
}
|
||||
|
||||
/// Keeps the connection open: 1, or 0 if it failed (`ConnectionLost`:
|
||||
/// connect again). The server closes a connection silent for 5 min; an
|
||||
/// app waiting longer between requests calls this every minute or so
|
||||
/// (the DLL has no thread of its own to do it).
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn BakaShrot_Ping(client: i64) -> isize {
|
||||
call(client, 0, |state| {
|
||||
state.client()?.ping()?;
|
||||
Ok(1)
|
||||
})
|
||||
}
|
||||
|
||||
fn node(state: &State) -> &str {
|
||||
state.client.as_ref().map_or("", Client::node)
|
||||
}
|
||||
|
||||
@@ -391,11 +391,16 @@ fn exports() {
|
||||
assert_eq!(error(client).0, code(ErrorCode::InvalidArgument));
|
||||
}
|
||||
assert_eq!(BakaShrot_IsConnected(client), 1);
|
||||
// A ping keeps it open, its last error cleared.
|
||||
assert_eq!(BakaShrot_Ping(client), 1);
|
||||
assert_eq!(error(client).0, 0);
|
||||
|
||||
// Closed: requests refused, the settings kept.
|
||||
assert_eq!(BakaShrot_Disconnect(client), 1);
|
||||
assert_eq!(BakaShrot_Disconnect(client), 0);
|
||||
assert_eq!(BakaShrot_IsConnected(client), 0);
|
||||
assert_eq!(BakaShrot_Ping(client), 0);
|
||||
assert_eq!(error(client).0, code(ErrorCode::NotConnected));
|
||||
assert_eq!(get_w(client, BakaShrot_GetNodeW), "");
|
||||
assert_eq!(BakaShrot_QueryW(client, w("SELECT 1").as_ptr()), 0);
|
||||
assert_eq!(error(client).0, code(ErrorCode::NotConnected));
|
||||
@@ -470,6 +475,7 @@ fn clients() {
|
||||
assert_eq!(failed, code(ErrorCode::InvalidArgument));
|
||||
assert!(why.contains("no client 99"), "{why}");
|
||||
assert_eq!(BakaShrot_IsConnected(99), 0);
|
||||
assert_eq!(BakaShrot_Ping(99), 0);
|
||||
assert_eq!(BakaShrot_GetMessageId(-5), 0);
|
||||
assert_eq!(get_w(99, BakaShrot_GetMessageDataW), "");
|
||||
assert_eq!(BakaShrot_FreeClient(99), 0);
|
||||
|
||||
Reference in New Issue
Block a user