Package org.klomp.snark
Class BandwidthManager
java.lang.Object
org.klomp.snark.BandwidthManager
- All Implemented Interfaces:
BandwidthListener
Bandwidth and bandwidth limits
Maintain three bandwidth estimators:
Sent, received, and requested.
There are three layers of BandwidthListeners:
BandwidthManager (total)
PeerCoordinator (per-torrent)
Peer/WebPeer (per-connection)
Here at the top, we use SyntheticRedQueues for accurate
and current moving averages of up, down, and requested bandwidth.
At the lower layers, simple weighted moving averages of
three buckets of time PeerCoordinator.CHECK_PERIOD each are used
for up and down, and requested is delegated here.
The lower layers must report to the next-higher layer.
At the Peer layer, we report inbound piece data per-read,
not per-piece, to get a smoother inbound estimate.
Only the following data are counted by the BandwidthListeners:
- Pieces (both Peer and WebPeer)
- ut_metadata
- Since:
- 0.9.62
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddownloaded(int size) We received this many byteslongCurrent limit in BPSlongThe average rate in Bps(package private) longThe average rate in BpslongCurrent limit in BPSlongThe average rate in BpsbooleanAre we currently over the limit?booleanAre we currently over the limit?(package private) voidsetDownBWLimit(long downLimit) Current limit in Bps(package private) voidsetUpBWLimit(long upLimit) Current limit in BpsbooleanshouldRequest(Peer peer, int size) Should we request this many bytes?booleanshouldSend(int size) Should we send this many bytes? Do NOT call uploaded() if this returns true.toString()In HTML for debug pagevoiduploaded(int size) We unconditionally sent this many bytes
-
Constructor Details
-
BandwidthManager
BandwidthManager(I2PAppContext ctx, int upLimit, int downLimit)
-
-
Method Details
-
setUpBWLimit
void setUpBWLimit(long upLimit) Current limit in Bps -
setDownBWLimit
void setDownBWLimit(long downLimit) Current limit in Bps -
getRequestRate
long getRequestRate()The average rate in Bps -
getUploadRate
public long getUploadRate()The average rate in Bps- Specified by:
getUploadRatein interfaceBandwidthListener
-
getDownloadRate
public long getDownloadRate()The average rate in Bps- Specified by:
getDownloadRatein interfaceBandwidthListener
-
uploaded
public void uploaded(int size) We unconditionally sent this many bytes- Specified by:
uploadedin interfaceBandwidthListener
-
downloaded
public void downloaded(int size) We received this many bytes- Specified by:
downloadedin interfaceBandwidthListener
-
shouldSend
public boolean shouldSend(int size) Should we send this many bytes? Do NOT call uploaded() if this returns true.- Specified by:
shouldSendin interfaceBandwidthListener
-
shouldRequest
Should we request this many bytes?- Specified by:
shouldRequestin interfaceBandwidthListener- Parameters:
peer- ignored
-
getUpBWLimit
public long getUpBWLimit()Current limit in BPS- Specified by:
getUpBWLimitin interfaceBandwidthListener
-
getDownBWLimit
public long getDownBWLimit()Current limit in BPS- Specified by:
getDownBWLimitin interfaceBandwidthListener
-
overUpBWLimit
public boolean overUpBWLimit()Are we currently over the limit?- Specified by:
overUpBWLimitin interfaceBandwidthListener
-
overDownBWLimit
public boolean overDownBWLimit()Are we currently over the limit?- Specified by:
overDownBWLimitin interfaceBandwidthListener
-
toString
In HTML for debug page
-