Implement outbound bandwidth limiting for i2psnark

This commit is contained in:
zzz
2008-04-07 17:41:58 +00:00
parent d57356f807
commit edc02e5efa
7 changed files with 89 additions and 13 deletions

View File

@@ -68,6 +68,7 @@ class PeerCheckerTask extends TimerTask
// we will add them back to the end of the list.
List removed = new ArrayList();
int uploadLimit = coordinator.allowedUploaders();
boolean overBWLimit = coordinator.overUpBWLimit();
while (it.hasNext())
{
Peer peer = (Peer)it.next();
@@ -109,7 +110,8 @@ class PeerCheckerTask extends TimerTask
// (Note use of coordinator.uploaders)
if (((coordinator.uploaders == uploadLimit
&& coordinator.interestedAndChoking > 0)
|| coordinator.uploaders > uploadLimit)
|| coordinator.uploaders > uploadLimit
|| overBWLimit)
&& !peer.isChoking())
{
// Check if it still wants pieces from us.
@@ -125,6 +127,15 @@ class PeerCheckerTask extends TimerTask
it.remove();
removed.add(peer);
}
else if (overBWLimit)
{
Snark.debug("BW limit, choke peer: " + peer,
Snark.INFO);
peer.setChoking(true);
uploaders--;
coordinator.uploaders--;
removedCount++;
}
else if (peer.isInteresting() && peer.isChoked())
{
// If they are choking us make someone else a downloader
@@ -209,7 +220,8 @@ class PeerCheckerTask extends TimerTask
}
// Optimistically unchoke a peer
coordinator.unchokePeer();
if (!overBWLimit)
coordinator.unchokePeer();
// Put peers back at the end of the list that we removed earlier.
coordinator.peers.addAll(removed);