Ping (ICMP echo request / response) will give you the peer latency, but not the available bandwidth that peer has. You need bandwidth, because TCP is good at working with bandwidth * delays products and figure out how to make a connection quickly, even if it rolls over the satellite.
What you do is connect with everyone. The presence of 40 peers is not uncommon. And then you decide what to cancel based on their current rates in relation to you (until you become a seeder). It should also be quite dynamic, as the available bandwidth varies over time. The best advice I can give is to read
http://www.bittorrent.org/bittorrentecon.pdf
which gives a general idea of ββhow to realize the economy. But many customers do different things than paper, so reading the code is another option.
So: you want to measure bandwidth, not latency. Therefore, ping is the wrong tool to work with. Bandwidth measurement is easiest to do by monitoring the packet rate of the peer-to-peer network.
I think the choking / unlocking algorithm and the selection of peers are one of the most difficult parts to get right in the client. This is best solved with a pen, paper, and brain, rather than sitting in front of a computer by writing code.
source share