diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2022-02-08 12:37:06 +0100 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2022-02-08 13:18:19 +0100 |
commit | a9899873198ffc1124f89b13c24091ab913a5ef1 (patch) | |
tree | 70d27cae1b19eaac283885b5a5feaab7a42bd70d | |
parent | 39e60a019a2bfbc88bc26a3577eeb7f259159a0e (diff) |
fall back to server after reaching maximum number of retries
Use the HTTP header field:
X-Accept-Redirect: off
to ask for a direct download from the server.
-rw-r--r-- | src/main.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -61,6 +61,7 @@ struct tip_client { int fd; bool error; bool redirected; + bool server_only; struct timeval tv_start, tv_last; const char *payload; }; @@ -400,7 +401,10 @@ static void tip_client_connect_cb(struct ev_loop *loop, struct ev_io *io, int ev case TIP_CLIENT_GET_HEADER: syslog(LOG_INFO, "connected to %s to fetch file %s\n", inet_ntoa(cli->addr.sin_addr), filename); - snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\n\r\n", filename); + if (cli->server_only) + snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\nX-Accept-Redirect: off\r\n\r\n", filename); + else + snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\n\r\n", filename); break; case TIP_CLIENT_HEAD_HEADER: syslog(LOG_INFO, "connected to %s to get file size of %s\n", @@ -581,6 +585,19 @@ int main(int argc, char *argv[]) ret = tip_client_request_file(&_cli, addr, filename); } while (ret > 0); + if (ret < 0) { + memset(&_cli, 0, sizeof(_cli)); + _cli.chunk_offset = chunk_size * k; + _cli.fd = fd; + _cli.server_only = true; + + do { + syslog(LOG_INFO, "Requesting file %s to server only\n", filename); + _cli.state = TIP_CLIENT_GET_HEADER; + ret = tip_client_request_file(&_cli, addr, filename); + } while (ret > 0); + } + if (ret < 0) goto err_max_retries; |