commit 61957a8
default
·
2023-06-29 06:07:10 +0000 UTC
parent 090c7cc
Added instance blocking to data storage.
M
data.c
+66,
-0
1@@ -1751,6 +1751,72 @@ xs_list *inbox_list(void)
2 }
3
4
5+/** instance-wide operations **/
6+
7+xs_str *_instance_block_fn(const char *instance)
8+{
9+ xs *s1 = xs_replace(instance, "https:/" "/", "");
10+ xs *l = xs_split(s1, "/");
11+ char *p = xs_list_get(l, 0);
12+ xs *md5 = xs_md5_hex(p, strlen(p));
13+
14+ return xs_fmt("%s/block/%s", srv_basedir, md5);
15+}
16+
17+
18+int is_instance_blocked(const char *instance)
19+{
20+ xs *fn = _instance_block_fn(instance);
21+
22+ return !!(mtime(fn) != 0.0);
23+}
24+
25+
26+int instance_block(const char *instance)
27+/* blocks a full instance */
28+{
29+ int ret;
30+
31+ /* create the subdir */
32+ xs *dir = xs_fmt("%s/block/", srv_basedir);
33+ mkdirx(dir);
34+
35+ if (!is_instance_blocked(instance)) {
36+ xs *fn = _instance_block_fn(instance);
37+ FILE *f;
38+
39+ if ((f = fopen(fn, "w")) != NULL) {
40+ fprintf(f, "%s\n", instance);
41+ fclose(f);
42+
43+ ret = 0;
44+ }
45+ else
46+ ret = -1;
47+ }
48+ else
49+ ret = -2;
50+
51+ return ret;
52+}
53+
54+
55+int instance_unblock(const char *instance)
56+/* unblocks a full instance */
57+{
58+ int ret;
59+
60+ if (is_instance_blocked(instance)) {
61+ xs *fn = _instance_block_fn(instance);
62+ ret = unlink(fn);
63+ }
64+ else
65+ ret = -2;
66+
67+ return ret;
68+}
69+
70+
71 /** notifications **/
72
73 xs_str *notify_check_time(snac *snac, int reset)
M
snac.h
+4,
-0
1@@ -161,6 +161,10 @@ void inbox_add(const char *inbox);
2 void inbox_add_by_actor(const xs_dict *actor);
3 xs_list *inbox_list(void);
4
5+int is_instance_blocked(const char *instance);
6+int instance_block(const char *instance);
7+int instance_unblock(const char *instance);
8+
9 void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);
10 void enqueue_output_raw(const char *keyid, const char *seckey,
11 xs_dict *msg, xs_str *inbox, int retries);