Nixers project: Bittorrent library - Community & Forums Related Discussions

Users browsing this thread: 15 Guest(s)
josuah
Long time nixers
This raises a few questions to me: what if the client's or the peers network is slow or a peer does not respond?

If pwpsend calls are blocking, the client will hang and wait for the response of every client before continuing with the next request, while it could send them all and wait for all answers, while still proceeding to the downloads (which would ideally never stop).

But the primitives looks good, it may be possible to use them to build asynchronous clients. I'm not yet very experienced with fork() and shared memory, but this is how I picture it based off what you propose:

Code:
/* setup shared memory: for the count of parallel requests, blocks requested... */
for (;;) {
    foreach(torrent->peers as peer) {
        if (count < MAX_REQUESTS && !fork()) {
            count++;
            if (!peer->connected) {
                pwpsend(torrent, peer, PWP_HANDSHAKE);
                pwpsend(torrent, peer, PWP_BITFIELD);
                pwpsend(torrent, peer, PWP_INTERESTED);
                pwpsend(torrent, peer, PWP_UNCHOKED);
            } else {
                if (!peer->ischoked)
                    pwpsend(torrent, peer, PWP_REQUEST); /* Request a new random block */
            }
            count--;
    }
}

And the same style for the other calls.

Another solution would be to have "pwpsend()" and friends to be asynchronous thmself, but if PWP_HANDSHAKE, PWP_BITFIELD, PWP_INTERESTED, PWP_UNCHOKED needs to be sent in this order, you would need shared with a queue for each peer listing all operations to send in turn, with a limit for not making the queue too long (requesting a piece 38 586 times to a peer not responding and still stuck at PWP_HANDSHAKE, ...).

In either case, this looks a really sane and simple interface, without complex structs to setup, neither initlibgbt() so far.

I am not good yet at networking or async programming, so there may be better/more standard ways to achieve it.


Messages In This Thread
Nixers project: Bittorrent library - by z3bra - 30-07-2017, 04:40 AM
RE: New project: Bittorrent library - by r4ndom - 30-07-2017, 05:33 AM
RE: New project: Bittorrent library - by Tmplt - 30-07-2017, 07:20 AM
RE: New project: Bittorrent library - by z3bra - 30-07-2017, 07:22 AM
RE: New project: Bittorrent library - by Tmplt - 30-07-2017, 07:31 AM
RE: New project: Bittorrent library - by z3bra - 30-07-2017, 09:15 AM
RE: New project: Bittorrent library - by Tmplt - 30-07-2017, 09:45 AM
RE: New project: Bittorrent library - by z3bra - 30-07-2017, 10:42 AM
RE: New project: Bittorrent library - by z3bra - 30-07-2017, 08:45 PM
RE: New project: Bittorrent library - by venam - 31-07-2017, 12:22 AM
RE: New project: Bittorrent library - by z3bra - 31-07-2017, 03:36 AM
RE: New project: Bittorrent library - by jkl - 31-07-2017, 04:13 AM
RE: New project: Bittorrent library - by z3bra - 31-07-2017, 07:18 AM
RE: New project: Bittorrent library - by sff - 31-07-2017, 01:28 PM
RE: New project: Bittorrent library - by z3bra - 01-08-2017, 04:19 AM
RE: New project: Bittorrent library - by r4ndom - 01-08-2017, 05:31 PM
RE: New project: Bittorrent library - by z3bra - 01-08-2017, 06:19 PM
RE: New project: Bittorrent library - by z3bra - 02-08-2017, 03:53 AM
RE: New project: Bittorrent library - by r4ndom - 02-08-2017, 06:24 AM
RE: New project: Bittorrent library - by z3bra - 02-08-2017, 08:27 AM
RE: New project: Bittorrent library - by xero - 02-08-2017, 07:27 PM
RE: New project: Bittorrent library - by z3bra - 03-08-2017, 03:31 AM
RE: New project: Bittorrent library - by r4ndom - 03-08-2017, 04:57 AM
RE: New project: Bittorrent library - by z3bra - 03-08-2017, 07:59 AM
RE: New project: Bittorrent library - by josuah - 05-08-2017, 04:06 PM
RE: New project: Bittorrent library - by z3bra - 05-08-2017, 06:18 PM
RE: New project: Bittorrent library - by josuah - 05-08-2017, 07:21 PM
RE: New project: Bittorrent library - by z3bra - 06-08-2017, 07:10 AM
RE: New project: Bittorrent library - by josuah - 06-08-2017, 01:10 PM
RE: New project: Bittorrent library - by josuah - 06-08-2017, 05:00 PM
RE: New project: Bittorrent library - by z3bra - 06-08-2017, 06:40 PM
RE: New project: Bittorrent library - by josuah - 07-08-2017, 09:38 AM
RE: New project: Bittorrent library - by z3bra - 08-08-2017, 05:49 PM
RE: New project: Bittorrent library - by josuah - 11-08-2017, 05:23 PM
RE: New project: Bittorrent library - by z3bra - 12-08-2017, 03:37 AM
RE: New project: Bittorrent library - by josuah - 12-08-2017, 07:24 AM
RE: New project: Bittorrent library - by z3bra - 12-08-2017, 08:42 AM
RE: New project: Bittorrent library - by josuah - 12-08-2017, 07:06 PM
RE: New project: Bittorrent library - by nas - 24-08-2017, 11:53 AM
RE: New project: Bittorrent library - by josuah - 24-08-2017, 01:36 PM
RE: New project: Bittorrent library - by josuah - 24-08-2017, 01:42 PM
RE: New project: Bittorrent library - by nas - 25-08-2017, 02:44 AM
RE: New project: Bittorrent library - by z3bra - 25-08-2017, 10:18 AM
RE: New project: Bittorrent library - by z3bra - 26-08-2017, 03:26 AM
RE: New project: Bittorrent library - by josuah - 29-08-2017, 02:51 AM
RE: New project: Bittorrent library - by z3bra - 29-08-2017, 03:17 AM
RE: New project: Bittorrent library - by josuah - 29-08-2017, 08:16 AM
RE: New project: Bittorrent library - by z3bra - 28-09-2017, 11:53 AM
RE: New project: Bittorrent library - by z3bra - 09-10-2017, 02:36 PM
RE: New project: Bittorrent library - by josuah - 10-10-2017, 05:24 PM
RE: New project: Bittorrent library - by z3bra - 10-10-2017, 07:36 PM
RE: New project: Bittorrent library - by josuah - 28-03-2018, 05:40 PM
RE: New project: Bittorrent library - by z3bra - 03-07-2018, 11:24 AM