public class BandwidthManager extends Object implements BandwidthListener
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:
| Constructor and Description |
|---|
BandwidthManager(I2PAppContext ctx,
int upLimit,
int downLimit) |
| Modifier and Type | Method and Description |
|---|---|
void |
downloaded(int size)
We received this many bytes
|
long |
getDownBWLimit()
Current limit in BPS
|
long |
getDownloadRate()
The average rate in Bps
|
(package private) long |
getRequestRate()
The average rate in Bps
|
long |
getUpBWLimit()
Current limit in BPS
|
long |
getUploadRate()
The average rate in Bps
|
boolean |
overDownBWLimit()
Are we currently over the limit?
|
boolean |
overUpBWLimit()
Are we currently over the limit?
|
(package private) void |
setDownBWLimit(long downLimit)
Current limit in Bps
|
(package private) void |
setUpBWLimit(long upLimit)
Current limit in Bps
|
boolean |
shouldRequest(Peer peer,
int size)
Should we request this many bytes?
|
boolean |
shouldSend(int size)
Should we send this many bytes? Do NOT call uploaded() if this returns true.
|
String |
toString()
In HTML for debug page
|
void |
uploaded(int size)
We unconditionally sent this many bytes
|
BandwidthManager(I2PAppContext ctx, int upLimit, int downLimit)
public void downloaded(int size)
downloaded in interface BandwidthListenersize - the number of bytes receivedpublic long getDownBWLimit()
getDownBWLimit in interface BandwidthListenerpublic long getDownloadRate()
getDownloadRate in interface BandwidthListenerlong getRequestRate()
public long getUpBWLimit()
getUpBWLimit in interface BandwidthListenerpublic long getUploadRate()
getUploadRate in interface BandwidthListenerpublic boolean overDownBWLimit()
overDownBWLimit in interface BandwidthListenerpublic boolean overUpBWLimit()
overUpBWLimit in interface BandwidthListenervoid setDownBWLimit(long downLimit)
void setUpBWLimit(long upLimit)
public boolean shouldRequest(Peer peer, int size)
shouldRequest in interface BandwidthListenerpeer - ignoredsize - the number of bytes to requestpublic boolean shouldSend(int size)
shouldSend in interface BandwidthListenersize - the number of bytes to sendpublic void uploaded(int size)
uploaded in interface BandwidthListenersize - the number of bytes sent