commit cddb272
grunfink
·
2025-09-28 12:40:24 +0000 UTC
parent 5d95ffa
New function actor_failure() (again, but much better).
M
data.c
+39,
-0
1@@ -3042,6 +3042,45 @@ xs_list *content_search(snac *user, const char *regex,
2 }
3
4
5+int actor_failure(const char *actor, int op)
6+/* actor failure maintenance */
7+{
8+ int ret = 0;
9+
10+ xs *md5 = xs_md5_hex(actor, strlen(actor));
11+ xs *fn = xs_fmt("%s/failure/%s", srv_basedir, md5);
12+
13+ switch (op) {
14+ case 0: /** check **/
15+ if (mtime(fn))
16+ ret = -1;
17+
18+ break;
19+
20+ case 1: /** register a failure **/
21+ if (mtime(fn) == 0.0) {
22+ FILE *f;
23+
24+ /* only create once, as the date will be used */
25+ if ((f = fopen(fn, "w")) != NULL) {
26+ fprintf(f, "%s\n", actor);
27+ fclose(f);
28+ }
29+ }
30+
31+ break;
32+
33+ case 2: /** clear a failure **/
34+ /* called whenever a message comes from this instance */
35+ unlink(fn);
36+
37+ break;
38+ }
39+
40+ return ret;
41+}
42+
43+
44 int instance_failure(const char *url, int op)
45 /* do some checks and accounting on instance failures */
46 {
M
snac.h
+1,
-0
1@@ -278,6 +278,7 @@ int content_match(const char *file, const xs_dict *msg);
2 xs_list *content_search(snac *user, const char *regex,
3 int priv, int skip, int show, int max_secs, int *timeout);
4
5+int actor_failure(const char *actor, int op);
6 int instance_failure(const char *url, int op);
7
8 void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);