commit f0e17d6

default  ·  2022-11-17 17:33:54 +0000 UTC
parent a12da31
Queue messages to inboxes instead of actors.
3 files changed,  +39, -14
M data.c
M snac.h
+33, -8
 1@@ -212,6 +212,28 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
 2 }
 3 
 4 
 5+d_char *inbox_list(snac *snac, char *msg)
 6+/* returns the list of inboxes that are recipients of this message */
 7+{
 8+    d_char *list = xs_list_new();
 9+    xs *rcpts    = recipient_list(snac, msg, 1);
10+    char *p, *v;
11+
12+    p = rcpts;
13+    while (xs_list_iter(&p, &v)) {
14+        xs *inbox;
15+
16+        if ((inbox = get_actor_inbox(snac, v)) != NULL) {
17+            /* add the inbox if it's not already there */
18+            if (xs_list_in(list, inbox) == -1)
19+                list = xs_list_append(list, inbox);
20+        }
21+    }
22+
23+    return list;
24+}
25+
26+
27 int is_msg_public(snac *snac, char *msg)
28 /* checks if a message is public */
29 {
30@@ -930,27 +952,30 @@ void process_queue(snac *snac)
31 
32         if (strcmp(type, "output") == 0) {
33             int status;
34-            char *actor = xs_dict_get(q_item, "actor");
35+            char *inbox = xs_dict_get(q_item, "inbox");
36             char *msg   = xs_dict_get(q_item, "object");
37             int retries = xs_number_get(xs_dict_get(q_item, "retries"));
38             xs *payload = NULL;
39             int p_size = 0;
40 
41+            if (xs_is_null(inbox) || xs_is_null(msg))
42+                continue;
43+
44             /* deliver */
45-            status = send_to_actor(snac, actor, msg, &payload, &p_size);
46+            status = send_to_inbox(snac, inbox, msg, &payload, &p_size);
47 
48             if (!valid_status(status)) {
49                 /* error sending; requeue? */
50                 if (retries > queue_retry_max)
51-                    snac_log(snac, xs_fmt("process_queue giving up %s %d", actor, status));
52+                    snac_log(snac, xs_fmt("process_queue giving up %s %d", inbox, status));
53                 else {
54                     /* requeue */
55-                    enqueue_output(snac, msg, actor, retries + 1);
56-                    snac_log(snac, xs_fmt("process_queue requeue %s %d", actor, retries + 1));
57+                    enqueue_output(snac, msg, inbox, retries + 1);
58+                    snac_log(snac, xs_fmt("process_queue requeue %s %d", inbox, retries + 1));
59                 }
60             }
61             else
62-                snac_log(snac, xs_fmt("process_queue sent to actor %s %d", actor, status));
63+                snac_log(snac, xs_fmt("process_queue sent to inbox %s %d", inbox, status));
64         }
65         else
66         if (strcmp(type, "input") == 0) {
67@@ -1005,10 +1030,10 @@ void process_queue(snac *snac)
68 void post(snac *snac, char *msg)
69 /* enqueues a message to all its recipients */
70 {
71-    xs *rcpts = recipient_list(snac, msg, 1);
72+    xs *inboxes = inbox_list(snac, msg);
73     char *p, *v;
74 
75-    p = rcpts;
76+    p = inboxes;
77     while (xs_list_iter(&p, &v)) {
78         enqueue_output(snac, msg, v, 0);
79     }
M data.c
+5, -5
 1@@ -1063,11 +1063,11 @@ void enqueue_input(snac *snac, char *msg, char *req, int retries)
 2 }
 3 
 4 
 5-void enqueue_output(snac *snac, char *msg, char *actor, int retries)
 6+void enqueue_output(snac *snac, char *msg, char *inbox, int retries)
 7 /* enqueues an output message for an actor */
 8 {
 9-    if (strcmp(actor, snac->actor) == 0) {
10-        snac_debug(snac, 1, xs_str_new("enqueue refused to myself"));
11+    if (xs_startswith(inbox, snac->actor)) {
12+        snac_debug(snac, 1, xs_str_new("refusing enqueue to myself"));
13         return;
14     }
15 
16@@ -1078,13 +1078,13 @@ void enqueue_output(snac *snac, char *msg, char *actor, int retries)
17     xs *rn   = xs_number_new(retries);
18 
19     qmsg = xs_dict_append(qmsg, "type",    "output");
20-    qmsg = xs_dict_append(qmsg, "actor",   actor);
21+    qmsg = xs_dict_append(qmsg, "inbox",   inbox);
22     qmsg = xs_dict_append(qmsg, "object",  msg);
23     qmsg = xs_dict_append(qmsg, "retries", rn);
24 
25     _enqueue_put(fn, qmsg);
26 
27-    snac_debug(snac, 1, xs_fmt("enqueue_output %s %s %d", actor, fn, retries));
28+    snac_debug(snac, 1, xs_fmt("enqueue_output %s %s %d", inbox, fn, retries));
29 }
30 
31 
M snac.h
+1, -1
1@@ -92,7 +92,7 @@ int history_del(snac *snac, char *id);
2 d_char *history_list(snac *snac);
3 
4 void enqueue_input(snac *snac, char *msg, char *req, int retries);
5-void enqueue_output(snac *snac, char *msg, char *actor, int retries);
6+void enqueue_output(snac *snac, char *msg, char *inbox, int retries);
7 void enqueue_email(snac *snac, char *msg, int retries);
8 
9 d_char *queue(snac *snac);