diff options
author | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-20 01:33:18 +0200 |
---|---|---|
committer | tiptorrent development team <tiptorrent@soleta.eu> | 2021-09-29 15:49:05 +0200 |
commit | 3e0254bf3cf9f0e8b0eef124530aa97f528c056b (patch) | |
tree | 7623277ead99ead5a6073df943399ba2456df845 /src | |
parent | 88e02d424b042ad35880670fe4c7c0643073de79 (diff) |
prioritize direct download for non existing redirections
allocate the direct download slot from server if there are no
redirections and no other client is currently downloading this file
already.
Diffstat (limited to 'src')
-rw-r--r-- | src/core.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -352,6 +352,21 @@ void tip_client_pending(struct tip_client *cli) cli->state = TIP_CLIENT_PENDING; } +static bool tip_direct_download_in_progress(const struct tip_client *cli) +{ + struct tip_client *this; + + list_for_each_entry(this, &client_list, list) { + if (cli->addr.sin_addr.s_addr == this->addr.sin_addr.s_addr) + continue; + if (cli->state != TIP_CLIENT_PENDING && + !strcmp(cli->path, this->path)) + return true; + } + + return false; +} + void tip_client_activate_pending(bool redirect_only) { struct tip_client *cli, *next; @@ -361,9 +376,13 @@ void tip_client_activate_pending(bool redirect_only) if (cli->state != TIP_CLIENT_PENDING) continue; redirected = tip_client_redirect(cli); - if (!redirected && redirect_only) - continue; - + if (!redirected) { + if (redirect_only) + continue; + /* another client is fetching this file from server, skip. */ + if (tip_direct_download_in_progress(cli)) + continue; + } ev_io_set(&cli->io, tip_client_socket(cli), EV_READ | EV_WRITE); ev_io_start(tip_main_loop, &cli->io); ev_timer_again(tip_main_loop, &cli->timer); |