From 39e60a019a2bfbc88bc26a3577eeb7f259159a0e Mon Sep 17 00:00:00 2001 From: tiptorrent development team Date: Tue, 8 Feb 2022 12:19:07 +0100 Subject: bail out after maximum number of retries stop downloading remaining chunks if one is missing after the maximum number of retries. --- src/main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 88e5bd8..3e88308 100644 --- a/src/main.c +++ b/src/main.c @@ -534,7 +534,7 @@ int main(int argc, char *argv[]) uint64_t data_len = 0, file_size = 0; bool file_chunk[MAX_CHUNKS] = {}; uint64_t chunk_size; - int i, k, fd; + int i, k, fd, ret; if (argc != 3) { printf("%s [ip] [file]\n", argv[0]); @@ -553,7 +553,11 @@ int main(int argc, char *argv[]) do { filename = argv[2]; _cli.state = TIP_CLIENT_HEAD_HEADER; - } while (tip_client_request_file(&_cli, addr, filename) > 0); + ret = tip_client_request_file(&_cli, addr, filename); + } while (ret > 0); + + if (ret < 0) + goto err_max_retries; if (_cli.state != TIP_CLIENT_DONE) goto err; @@ -574,8 +578,11 @@ int main(int argc, char *argv[]) do { syslog(LOG_INFO, "Requesting file %s to server\n", filename); _cli.state = TIP_CLIENT_GET_HEADER; + ret = tip_client_request_file(&_cli, addr, filename); + } while (ret > 0); - } while (tip_client_request_file(&_cli, addr, filename) > 0); + if (ret < 0) + goto err_max_retries; tip_client_progress(&_cli, true); file_chunk[k] = true; @@ -605,4 +612,11 @@ err: tip_client_stats.direct_from_server, tip_client_stats.redirects); return EXIT_FAILURE; + +err_max_retries: + syslog(LOG_INFO, "Failure after maximum number of retries. " + "Direct from server: %u Redirected: %u\n", + tip_client_stats.direct_from_server, + tip_client_stats.redirects); + return EXIT_FAILURE; } -- cgit v1.2.3-18-g5258