aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrunfink <grunfink@comam.es>2026-06-24 14:54:45 +0200
committergrunfink <grunfink@comam.es>2026-06-24 14:54:45 +0200
commitef7b66697f5b3261a451917d2996563a141df68a (patch)
tree71c0f409f07dbd25ebde0c17543e93ad934781cc
parent778046fa7ab73e64b6a30021f1c81fc72c58bea7 (diff)
Implemented semi-random forward_secs in enqueue_object_request() or enqueue_actor_refresh().
If forward_secs is a negative value in these functions, it's used as the modulo of a hash of the user id. This way, a refresh storm of the same object by all users is somewhat distributed in time.
-rw-r--r--activitypub.c4
-rw-r--r--data.c10
2 files changed, 12 insertions, 2 deletions
diff --git a/activitypub.c b/activitypub.c
index e9be2de..514e764 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -3077,7 +3077,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
else {
/* actor / key mismatch: don't accept blindly, but request an actor update
from the original source, as the Update may come from a relay and be legit */
- enqueue_actor_refresh(snac, actor, 0);
+ enqueue_actor_refresh(snac, actor, -10);
snac_log(snac, xs_fmt("Update: mismatched actor '%s' and key '%s'", actor, key_id));
}
@@ -3097,7 +3097,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
else
if (strcmp(atto, key_id) != 0) {
/* actor / key mismatch: request the object from the original source */
- enqueue_object_request(snac, id, 0);
+ enqueue_object_request(snac, id, -10);
snac_log(snac, xs_fmt("Update: mismatched attributedTo '%s' and key '%s'", atto, key_id));
}
diff --git a/data.c b/data.c
index 3f7ba29..9500474 100644
--- a/data.c
+++ b/data.c
@@ -3858,6 +3858,11 @@ void enqueue_close_question(snac *user, const char *id, int end_secs)
void enqueue_object_request(snac *user, const char *id, int forward_secs)
/* enqueues the request of an object in the future */
{
+ if (forward_secs < 0) {
+ /* set it to a somewhat random delay */
+ forward_secs = xs_hash_func(user->uid, strlen(user->uid)) % -forward_secs;
+ }
+
xs *qmsg = _new_qmsg("object_request", id, 0);
xs *ntid = tid(forward_secs);
xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
@@ -3886,6 +3891,11 @@ void enqueue_verify_links(snac *user)
void enqueue_actor_refresh(snac *user, const char *actor, int forward_secs)
/* enqueues an actor refresh */
{
+ if (forward_secs < 0) {
+ /* set it to a somewhat random delay */
+ forward_secs = xs_hash_func(user->uid, strlen(user->uid)) % -forward_secs;
+ }
+
xs *qmsg = _new_qmsg("actor_refresh", "", 0);
xs *ntid = tid(forward_secs);
xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);