Reputation: 1725
Is it a good idea for a Torrent-client to close the TCP-connection with a peer, after each piece download? To prevent memory leak!
And also, does a client have to re-establish unchoked-state (and "handshake"), again and again, every time it closes the connection in peer-to-peer messaging?
Upvotes: 1
Views: 165
Reputation: 2089
It's a terrible idea and against how the protocol works.
Fundamental parts of the protocol is the constant choking and uncoking including the optimistic unchoke to find the fastest peers and use the "tit-fot-tat" algorithm.
The reason for having a larger number of connections than is currently active up- and downloading and have some standby peers "on hold" is to enable the above with peers prepared to fast go active when necessary and keep the activity flowing uninterupted.
A already open connection is cheap.
Opening a connection takes resources and time.
First the three-way TCP handshake (or the uTP/UDP handshake),
then there may be a encryption handshake,
then the protocol handshake,
then possibly a extension handshake,
then a bitfield exchange.
The connection always starts out choked and not interested.
To keep the memory consumption in check, don't open an excessive number of connections.
Real memory leaks are caused by faulty code that needs to be fixed.
Upvotes: 1
Reputation: 43125
No, that would be very inefficient since clients only retain information necessary to exchange pieces for the lifetime of a connection. If you close it then you have to re-negotiate everything with your peer.
To limit memory consumption you can simply cap the number of connections that are open at any given time. You shouldn't need more than 20-60 connections to make any torrent work.
It is ok when some fraction of those connections are idle because idle TCP sockets don't consume many resources.
In fact bittorrent is designed to always have some idle connections in the swarm, otherwise opportunistic unchoking algorithms would not work since there wouldn't be any idle peer to unchoke.
Upvotes: 1