mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Use a shorter timeout for first output connections.
This commit is contained in:
parent
4baf56c4ce
commit
fd1e281cba
6 changed files with 23 additions and 18 deletions
|
@ -31,7 +31,7 @@ int activitypub_request(snac *snac, char *url, d_char **data)
|
||||||
|
|
||||||
/* get from the net */
|
/* get from the net */
|
||||||
response = http_signed_request(snac, "GET", url,
|
response = http_signed_request(snac, "GET", url,
|
||||||
NULL, NULL, 0, &status, &payload, &p_size);
|
NULL, NULL, 0, &status, &payload, &p_size, 0);
|
||||||
|
|
||||||
if (valid_status(status)) {
|
if (valid_status(status)) {
|
||||||
/* ensure it's ActivityPub data */
|
/* ensure it's ActivityPub data */
|
||||||
|
@ -131,7 +131,7 @@ int timeline_request(snac *snac, char **id, d_char **wrk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size)
|
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size, int timeout)
|
||||||
/* sends a message to an Inbox */
|
/* sends a message to an Inbox */
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
@ -139,7 +139,7 @@ int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_s
|
||||||
xs *j_msg = xs_json_dumps_pp(msg, 4);
|
xs *j_msg = xs_json_dumps_pp(msg, 4);
|
||||||
|
|
||||||
response = http_signed_request(snac, "POST", inbox,
|
response = http_signed_request(snac, "POST", inbox,
|
||||||
NULL, j_msg, strlen(j_msg), &status, payload, p_size);
|
NULL, j_msg, strlen(j_msg), &status, payload, p_size, timeout);
|
||||||
|
|
||||||
xs_free(response);
|
xs_free(response);
|
||||||
|
|
||||||
|
@ -167,14 +167,14 @@ d_char *get_actor_inbox(snac *snac, char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size)
|
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout)
|
||||||
/* sends a message to an actor */
|
/* sends a message to an actor */
|
||||||
{
|
{
|
||||||
int status = 400;
|
int status = 400;
|
||||||
xs *inbox = get_actor_inbox(snac, actor);
|
xs *inbox = get_actor_inbox(snac, actor);
|
||||||
|
|
||||||
if (!xs_is_null(inbox))
|
if (!xs_is_null(inbox))
|
||||||
status = send_to_inbox(snac, inbox, msg, payload, p_size);
|
status = send_to_inbox(snac, inbox, msg, payload, p_size, timeout);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1084,7 +1084,7 @@ void process_queue(snac *snac)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* deliver */
|
/* deliver */
|
||||||
status = send_to_inbox(snac, inbox, msg, &payload, &p_size);
|
status = send_to_inbox(snac, inbox, msg, &payload, &p_size, retries == 0 ? 3 : 8);
|
||||||
|
|
||||||
snac_log(snac, xs_fmt("process_queue sent to inbox %s %d", inbox, status));
|
snac_log(snac, xs_fmt("process_queue sent to inbox %s %d", inbox, status));
|
||||||
|
|
||||||
|
|
5
http.c
5
http.c
|
@ -14,7 +14,8 @@
|
||||||
d_char *http_signed_request(snac *snac, char *method, char *url,
|
d_char *http_signed_request(snac *snac, char *method, char *url,
|
||||||
d_char *headers,
|
d_char *headers,
|
||||||
d_char *body, int b_size,
|
d_char *body, int b_size,
|
||||||
int *status, d_char **payload, int *p_size)
|
int *status, d_char **payload, int *p_size,
|
||||||
|
int timeout)
|
||||||
/* does a signed HTTP request */
|
/* does a signed HTTP request */
|
||||||
{
|
{
|
||||||
xs *l1;
|
xs *l1;
|
||||||
|
@ -95,7 +96,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url,
|
||||||
hdrs = xs_dict_append(hdrs, "user-agent", USER_AGENT);
|
hdrs = xs_dict_append(hdrs, "user-agent", USER_AGENT);
|
||||||
|
|
||||||
response = xs_http_request(method, url, hdrs,
|
response = xs_http_request(method, url, hdrs,
|
||||||
body, b_size, status, payload, p_size);
|
body, b_size, status, payload, p_size, timeout);
|
||||||
|
|
||||||
srv_archive("SEND", hdrs, body, b_size, *status, response, *payload, *p_size);
|
srv_archive("SEND", hdrs, body, b_size, *status, response, *payload, *p_size);
|
||||||
|
|
||||||
|
|
7
snac.h
7
snac.h
|
@ -138,7 +138,8 @@ void purge_all(void);
|
||||||
d_char *http_signed_request(snac *snac, char *method, char *url,
|
d_char *http_signed_request(snac *snac, char *method, char *url,
|
||||||
d_char *headers,
|
d_char *headers,
|
||||||
d_char *body, int b_size,
|
d_char *body, int b_size,
|
||||||
int *status, d_char **payload, int *p_size);
|
int *status, d_char **payload, int *p_size,
|
||||||
|
int timeout);
|
||||||
int check_signature(snac *snac, char *req);
|
int check_signature(snac *snac, char *req);
|
||||||
|
|
||||||
void httpd(void);
|
void httpd(void);
|
||||||
|
@ -158,9 +159,9 @@ d_char *msg_update(snac *snac, char *object);
|
||||||
|
|
||||||
int activitypub_request(snac *snac, char *url, d_char **data);
|
int activitypub_request(snac *snac, char *url, d_char **data);
|
||||||
int actor_request(snac *snac, char *actor, d_char **data);
|
int actor_request(snac *snac, char *actor, d_char **data);
|
||||||
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size);
|
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size, int timeout);
|
||||||
d_char *get_actor_inbox(snac *snac, char *actor);
|
d_char *get_actor_inbox(snac *snac, char *actor);
|
||||||
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size);
|
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout);
|
||||||
int is_msg_public(snac *snac, char *msg);
|
int is_msg_public(snac *snac, char *msg);
|
||||||
void process_queue(snac *snac);
|
void process_queue(snac *snac);
|
||||||
void post(snac *snac, char *msg);
|
void post(snac *snac, char *msg);
|
||||||
|
|
|
@ -64,7 +64,7 @@ int webfinger_request(char *qs, char **actor, char **user)
|
||||||
else {
|
else {
|
||||||
xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
|
xs *url = xs_fmt("https:/" "/%s/.well-known/webfinger?resource=%s", host, resource);
|
||||||
|
|
||||||
xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size);
|
xs_http_request("GET", url, headers, NULL, 0, &status, &payload, &p_size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_status(status)) {
|
if (valid_status(status)) {
|
||||||
|
|
13
xs_curl.h
13
xs_curl.h
|
@ -5,8 +5,8 @@
|
||||||
#define _XS_CURL_H
|
#define _XS_CURL_H
|
||||||
|
|
||||||
d_char *xs_http_request(char *method, char *url, d_char *headers,
|
d_char *xs_http_request(char *method, char *url, d_char *headers,
|
||||||
d_char *body, int b_size,
|
d_char *body, int b_size, int *status,
|
||||||
int *status, d_char **payload, int *p_size);
|
d_char **payload, int *p_size, int timeout);
|
||||||
|
|
||||||
#ifdef XS_IMPLEMENTATION
|
#ifdef XS_IMPLEMENTATION
|
||||||
|
|
||||||
|
@ -84,8 +84,8 @@ static int _post_callback(char *buffer, size_t size,
|
||||||
|
|
||||||
|
|
||||||
d_char *xs_http_request(char *method, char *url, d_char *headers,
|
d_char *xs_http_request(char *method, char *url, d_char *headers,
|
||||||
d_char *body, int b_size,
|
d_char *body, int b_size, int *status,
|
||||||
int *status, d_char **payload, int *p_size)
|
d_char **payload, int *p_size, int timeout)
|
||||||
/* does an HTTP request */
|
/* does an HTTP request */
|
||||||
{
|
{
|
||||||
d_char *response;
|
d_char *response;
|
||||||
|
@ -101,7 +101,10 @@ d_char *xs_http_request(char *method, char *url, d_char *headers,
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 8L);
|
if (timeout <= 0)
|
||||||
|
timeout = 8;
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long) timeout);
|
||||||
|
|
||||||
#ifdef FORCE_HTTP_1_1
|
#ifdef FORCE_HTTP_1_1
|
||||||
/* force HTTP/1.1 */
|
/* force HTTP/1.1 */
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
/* e8b70248081aa9086f64861bc85a67f390c41afb */
|
/* f64030f1449390169bd09bdcbb052b1a70f8002a */
|
||||||
|
|
Loading…
Reference in a new issue