diff options
| author | 2022-09-23 19:37:01 +0200 | |
|---|---|---|
| committer | 2022-09-23 19:37:01 +0200 | |
| commit | bbf5471039a973fed918441150ef76ff0db7682a (patch) | |
| tree | 64d6fd0dbc63a2102fd1d2615bbcb85473f19f40 /activitypub.c | |
| parent | New functions send_to_inbox() and send_to_actor(). (diff) | |
| download | snac2-bbf5471039a973fed918441150ef76ff0db7682a.tar.gz snac2-bbf5471039a973fed918441150ef76ff0db7682a.tar.xz snac2-bbf5471039a973fed918441150ef76ff0db7682a.zip | |
New function process_queue().
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index 5d54833..b654beb 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -80,9 +80,10 @@ int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_s | |||
| 80 | { | 80 | { |
| 81 | int status; | 81 | int status; |
| 82 | d_char *response; | 82 | d_char *response; |
| 83 | xs *j_msg = xs_json_dumps_pp(msg, 4); | ||
| 83 | 84 | ||
| 84 | response = http_signed_request(snac, "POST", inbox, | 85 | response = http_signed_request(snac, "POST", inbox, |
| 85 | NULL, msg, strlen(msg), &status, payload, p_size); | 86 | NULL, j_msg, strlen(j_msg), &status, payload, p_size); |
| 86 | 87 | ||
| 87 | free(response); | 88 | free(response); |
| 88 | 89 | ||
| @@ -108,5 +109,48 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s | |||
| 108 | status = 400; | 109 | status = 400; |
| 109 | } | 110 | } |
| 110 | 111 | ||
| 112 | snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status)); | ||
| 113 | |||
| 111 | return status; | 114 | return status; |
| 112 | } | 115 | } |
| 116 | |||
| 117 | |||
| 118 | void process_queue(snac *snac) | ||
| 119 | /* processes the queue */ | ||
| 120 | { | ||
| 121 | xs *list; | ||
| 122 | char *p, *fn; | ||
| 123 | int queue_retry_max = xs_number_get(xs_dict_get(srv_config, "queue_retry_max")); | ||
| 124 | |||
| 125 | list = queue(snac); | ||
| 126 | |||
| 127 | p = list; | ||
| 128 | while (xs_list_iter(&p, &fn)) { | ||
| 129 | xs *q_item = dequeue(snac, fn); | ||
| 130 | char *type; | ||
| 131 | |||
| 132 | if ((type = xs_dict_get(q_item, "type")) == NULL) | ||
| 133 | type = "output"; | ||
| 134 | |||
| 135 | if (strcmp(type, "output") == 0) { | ||
| 136 | int status; | ||
| 137 | char *actor = xs_dict_get(q_item, "actor"); | ||
| 138 | char *msg = xs_dict_get(q_item, "object"); | ||
| 139 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | ||
| 140 | |||
| 141 | /* deliver */ | ||
| 142 | status = send_to_actor(snac, actor, msg, NULL, 0); | ||
| 143 | |||
| 144 | if (!valid_status(status)) { | ||
| 145 | /* error sending; reenqueue? */ | ||
| 146 | if (retries > queue_retry_max) | ||
| 147 | snac_log(snac, xs_fmt("process_queue giving up %s %d", actor, status)); | ||
| 148 | else { | ||
| 149 | /* reenqueue */ | ||
| 150 | enqueue_output(snac, actor, msg, retries + 1); | ||
| 151 | snac_log(snac, xs_fmt("process_queue requeue %s %d", actor, retries + 1)); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
| 156 | } | ||