Skip to content

Commit b133fb5

Browse files
authored
Merge pull request #326 from jolavillette/fix/rnp-timestamp-trustdb-churn
fix(pgp): throttle trust-db rewrite in RNPPGPHandler::locked_timeStampKey
2 parents 87adcd9 + 089b66e commit b133fb5

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/pgp/rnppgphandler.cc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,23 @@ ops_keyring_t *OpenPGPSDKHandler::allocateOPSKeyring()
262262

263263
void RNPPGPHandler::locked_timeStampKey(const RsPgpId& key_id)
264264
{
265-
_public_keyring_map[key_id]._time_stamp = time(nullptr);
266-
_trustdb_changed = true;
265+
rstime_t now = time(nullptr);
266+
_public_keyring_map[key_id]._time_stamp = now;
267+
268+
// Only flag the trust database for rewrite once per hour. This function is
269+
// called on every PGP key usage (e.g. VerifySignBin(), which runs on every
270+
// GXS identity validation and every connection). Flagging _trustdb_changed
271+
// on each call caused the whole private trust database (thousands of
272+
// packets) to be rewritten and re-read every few seconds. Updating the
273+
// in-memory usage timestamp on every call is cheap and stays; only the
274+
// on-disk sync is throttled. OpenPGPSDKHandler throttles the same way (see
275+
// openpgpsdkhandler.cc); the rnp port had dropped it.
276+
static rstime_t last_trustdb_update_because_of_stamp = 0;
277+
if(now > last_trustdb_update_because_of_stamp + 3600)
278+
{
279+
_trustdb_changed = true;
280+
last_trustdb_update_because_of_stamp = now;
281+
}
267282
}
268283

269284
bool rnp_get_passphrase_cb(rnp_ffi_t /* ffi */,

0 commit comments

Comments
 (0)