perf: faster builds, leaner daemon, smoother install/run (0.9.20)

Reuse libcstcore.a for tests with -MMD incremental deps; idle-backoff the
parliament seat loop; defer curl init and cache settings; add systemd helper.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
WHC
2026-10-29 11:41:16 +08:00
co-authored by Cursor
parent 812e3ee265
commit 2f96b050d6
13 changed files with 278 additions and 103 deletions
+22 -12
View File
@@ -272,33 +272,43 @@ int cst_parliament_daemon_run(const char *password, const char *instance_id,
signal(SIGHUP, on_sig);
#endif
g_stop = 0;
int tick = 0;
int tick = 0, idle = 0;
while (!g_stop) {
cst_peer_session_t sess;
char herr[128];
if (cst_peer_accept((intptr_t)ls, &cert, sk, realm.pk, 500, &sess, herr,
sizeof(herr)) == 0) {
/* Accept wait backs off when idle so a quiet seat barely wakes. */
int accept_ms = idle > 20 ? 2000 : idle > 5 ? 1000 : 400;
if (cst_peer_accept((intptr_t)ls, &cert, sk, realm.pk, accept_ms, &sess,
herr, sizeof(herr)) == 0) {
sync_on_session(&sess);
cst_peer_close(&sess);
idle = 0;
} else {
idle++;
}
int push = cst_parliament_sync_pending();
tick++;
if ((push || tick % 10 == 0) && disc) {
/* Dial peers on push, or periodically (slower while idle). */
int period = idle > 20 ? 45 : idle > 5 ? 20 : 8;
if ((push || tick % period == 0) && disc) {
cst_peer_info_t peers[16];
int n = cst_discover_peers(disc, peers, 16);
for (int i = 0; i < n; i++) {
if (peers[i].port <= 0)
continue;
if (cst_peer_dial(peers[i].host, peers[i].port, &cert, sk, realm.pk,
3000, &sess, herr, sizeof(herr)) == 0) {
sync_on_session(&sess);
cst_peer_close(&sess);
if (n > 0 || push) {
for (int i = 0; i < n; i++) {
if (peers[i].port <= 0)
continue;
if (cst_peer_dial(peers[i].host, peers[i].port, &cert, sk, realm.pk,
3000, &sess, herr, sizeof(herr)) == 0) {
sync_on_session(&sess);
cst_peer_close(&sess);
idle = 0;
}
}
}
if (push)
cst_parliament_sync_ack();
}
sleep_ms(200);
/* No extra sleep: accept_ms already paced the loop. */
}
if (disc)
cst_discover_stop(disc);