Package DebTorrent :: Module RateLimiter :: Class RateLimiter
[hide private]
[frames] | no frames]

Class RateLimiter

source code

Limit the upload rate.

Instance Methods [hide private]
 
__init__(self, sched, unitsize, slotsfunc=<function <lambda> at 0x2b55198e5f50>)
Initialize the instance.
source code
 
set_upload_rate(self, rate)
Set the upload rate to limit to.
source code
 
queue(self, conn)
Queue the connection for later uploading.
source code
 
try_send(self, check_time=True)
Loop through the circular queue of upload connections, trying to send on each.
source code
 
adjust_sent(self, bytes)
Add data from other places to this measure.
source code
 
ping(self, delay)
Use the new ping time to calculate an automatically adjusted upload limit.
source code
Instance Variables [hide private]
boolean autoadjust
whether the upload limit is being automatically adjusted
int autoadjustup
number of cycles remaining before adjusting up the upload rate
int bytes_sent
the number of bytes sent on the most recent attempt
BT1.Connecter.Connection last
the last connection on the circular queue of connections to send on
float lasttime
the last time data was sent
CurrentRateMeasure.Measure measure
the measurer to use to help calculate the upload rate
list of boolean pings
the latest ping results, True if the threshold was exceeded
method sched
the method to call to schedule a task with the server
int slots
the number of upload slots to use (for automatic adjustment)
method slotsfunc
the method to call to set the number of connections limits
int unitsize
when limiting upload rate, how many bytes to send at a time
float upload_rate
the maximum upload rate to limit to
Method Details [hide private]

__init__(self, sched, unitsize, slotsfunc=<function <lambda> at 0x2b55198e5f50>)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • sched (method) - the method to call to schedule a task with the server
  • unitsize (int) - when limiting upload rate, how many bytes to send at a time
  • slotsfunc (method) - the method to call to set the number of connections limits (optional, defaults to not setting anything)

set_upload_rate(self, rate)

source code 
Set the upload rate to limit to.
Parameters:
  • rate (float) - maximum KB/s to upload at (0 = no limit, -1 = automatic)

queue(self, conn)

source code 

Queue the connection for later uploading.

The queue is actually stored in the BT1.Connecter.Connection objects using their next_upload instance variable, and is circular.

If the queue is empty, this will start the queue processer.
Parameters:

try_send(self, check_time=True)

source code 
Loop through the circular queue of upload connections, trying to send on each.
Parameters:
  • check_time (boolean) - whether to make sure the bytes sent is not negative

adjust_sent(self, bytes)

source code 
Add data from other places to this measure.
Parameters:
  • bytes (int) - the amount of data that was sent/received

ping(self, delay)

source code 
Use the new ping time to calculate an automatically adjusted upload limit.
Parameters:
  • delay (float) - the elapsed time between unchoking and receiving a request