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.
master
tiptorrent development team 2022-02-08 12:37:06 +01:00
parent 39e60a019a
commit a989987319
1 changed files with 18 additions and 1 deletions

View File

@ -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,6 +401,9 @@ 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);
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:
@ -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;