diff options
| -rw-r--r-- | activitypub.c | 11 | ||||
| -rw-r--r-- | data.c | 53 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 66 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c index 5fb60ba..ce3be35 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -2261,6 +2261,9 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) | |||
| 2261 | return -1; | 2261 | return -1; |
| 2262 | } | 2262 | } |
| 2263 | 2263 | ||
| 2264 | /* this instance is alive */ | ||
| 2265 | instance_failure(actor, 2); | ||
| 2266 | |||
| 2264 | /* question votes may not have a type */ | 2267 | /* question votes may not have a type */ |
| 2265 | if (xs_is_null(type)) | 2268 | if (xs_is_null(type)) |
| 2266 | type = "Note"; | 2269 | type = "Note"; |
| @@ -3152,6 +3155,11 @@ void process_queue_item(xs_dict *q_item) | |||
| 3152 | return; | 3155 | return; |
| 3153 | } | 3156 | } |
| 3154 | 3157 | ||
| 3158 | if (instance_failure(inbox, 0)) { | ||
| 3159 | srv_debug(1, xs_fmt("too many failures for instance %s", inbox)); | ||
| 3160 | return; | ||
| 3161 | } | ||
| 3162 | |||
| 3155 | /* deliver (if previous error status was a timeout, try now longer) */ | 3163 | /* deliver (if previous error status was a timeout, try now longer) */ |
| 3156 | if (p_status == 599) | 3164 | if (p_status == 599) |
| 3157 | timeout = xs_number_get(xs_dict_get_def(srv_config, "queue_timeout_2", "8")); | 3165 | timeout = xs_number_get(xs_dict_get_def(srv_config, "queue_timeout_2", "8")); |
| @@ -3163,6 +3171,9 @@ void process_queue_item(xs_dict *q_item) | |||
| 3163 | 3171 | ||
| 3164 | status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, timeout); | 3172 | status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, timeout); |
| 3165 | 3173 | ||
| 3174 | /* register or clear a value for this instance */ | ||
| 3175 | instance_failure(inbox, valid_status(status) ? 2 : 1); | ||
| 3176 | |||
| 3166 | if (payload) { | 3177 | if (payload) { |
| 3167 | if (p_size > 64) { | 3178 | if (p_size > 64) { |
| 3168 | /* trim the message */ | 3179 | /* trim the message */ |
| @@ -112,6 +112,9 @@ int srv_open(const char *basedir, int auto_upgrade) | |||
| 112 | xs *tmpdir = xs_fmt("%s/tmp", srv_basedir); | 112 | xs *tmpdir = xs_fmt("%s/tmp", srv_basedir); |
| 113 | mkdirx(tmpdir); | 113 | mkdirx(tmpdir); |
| 114 | 114 | ||
| 115 | xs *faildir = xs_fmt("%s/failure", srv_basedir); | ||
| 116 | mkdirx(faildir); | ||
| 117 | |||
| 115 | #ifdef __APPLE__ | 118 | #ifdef __APPLE__ |
| 116 | /* Apple uses st_atimespec instead of st_atim etc */ | 119 | /* Apple uses st_atimespec instead of st_atim etc */ |
| 117 | #define st_atim st_atimespec | 120 | #define st_atim st_atimespec |
| @@ -3039,6 +3042,56 @@ xs_list *content_search(snac *user, const char *regex, | |||
| 3039 | } | 3042 | } |
| 3040 | 3043 | ||
| 3041 | 3044 | ||
| 3045 | int instance_failure(const char *url, int op) | ||
| 3046 | /* do some checks and accounting on instance failures */ | ||
| 3047 | { | ||
| 3048 | int ret = 0; | ||
| 3049 | xs *l = xs_split(url, "/"); | ||
| 3050 | const char *hostname = xs_list_get(l, 2); | ||
| 3051 | double mt; | ||
| 3052 | |||
| 3053 | if (!xs_is_string(hostname)) | ||
| 3054 | return 0; | ||
| 3055 | |||
| 3056 | xs *md5 = xs_md5_hex(hostname, strlen(hostname)); | ||
| 3057 | xs *fn = xs_fmt("%s/%s", srv_basedir, md5); | ||
| 3058 | |||
| 3059 | switch (op) { | ||
| 3060 | case 0: /** check **/ | ||
| 3061 | if ((mt = mtime(fn)) != 0.0) { | ||
| 3062 | /* grace time */ | ||
| 3063 | double seconds_failing = 30 * (24 * 60 * 60); | ||
| 3064 | |||
| 3065 | if ((double)time(NULL) - mt > seconds_failing) | ||
| 3066 | ret = -1; | ||
| 3067 | } | ||
| 3068 | |||
| 3069 | break; | ||
| 3070 | |||
| 3071 | case 1: /** register a failure **/ | ||
| 3072 | if (mtime(fn) == 0.0) { | ||
| 3073 | FILE *f; | ||
| 3074 | |||
| 3075 | /* only create once, as the date will be used */ | ||
| 3076 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 3077 | fprintf(f, "%s\n", hostname); | ||
| 3078 | fclose(f); | ||
| 3079 | } | ||
| 3080 | } | ||
| 3081 | |||
| 3082 | break; | ||
| 3083 | |||
| 3084 | case 2: /** clear a failure **/ | ||
| 3085 | /* called whenever a message comes from this instance */ | ||
| 3086 | unlink(fn); | ||
| 3087 | |||
| 3088 | break; | ||
| 3089 | } | ||
| 3090 | |||
| 3091 | return ret; | ||
| 3092 | } | ||
| 3093 | |||
| 3094 | |||
| 3042 | /** notifications **/ | 3095 | /** notifications **/ |
| 3043 | 3096 | ||
| 3044 | xs_str *notify_check_time(snac *snac, int reset) | 3097 | xs_str *notify_check_time(snac *snac, int reset) |
| @@ -278,6 +278,8 @@ int content_match(const char *file, const xs_dict *msg); | |||
| 278 | xs_list *content_search(snac *user, const char *regex, | 278 | xs_list *content_search(snac *user, const char *regex, |
| 279 | int priv, int skip, int show, int max_secs, int *timeout); | 279 | int priv, int skip, int show, int max_secs, int *timeout); |
| 280 | 280 | ||
| 281 | int instance_failure(const char *url, int op); | ||
| 282 | |||
| 281 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); | 283 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); |
| 282 | void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); | 284 | void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); |
| 283 | void enqueue_output_raw(const char *keyid, const char *seckey, | 285 | void enqueue_output_raw(const char *keyid, const char *seckey, |