public class BandwidthManager extends Object implements BandwidthListener
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)
void setUpBWLimit(long upLimit)
void setDownBWLimit(long downLimit)
long getRequestRate()
public long getUploadRate()
getUploadRate
in interface BandwidthListener
public long getDownloadRate()
getDownloadRate
in interface BandwidthListener
public void uploaded(int size)
uploaded
in interface BandwidthListener
public void downloaded(int size)
downloaded
in interface BandwidthListener
public boolean shouldSend(int size)
shouldSend
in interface BandwidthListener
public boolean shouldRequest(Peer peer, int size)
shouldRequest
in interface BandwidthListener
peer
- ignoredpublic long getUpBWLimit()
getUpBWLimit
in interface BandwidthListener
public long getDownBWLimit()
getDownBWLimit
in interface BandwidthListener
public boolean overUpBWLimit()
overUpBWLimit
in interface BandwidthListener
public boolean overDownBWLimit()
overDownBWLimit
in interface BandwidthListener