[Debtorrent-commits] r84 - /debtorrent/branches/http-listen/DebTorrent/download_bt1.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sat Jun 2 20:35:00 UTC 2007


Author: camrdale-guest
Date: Sat Jun  2 20:35:00 2007
New Revision: 84

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=84
Log:
More documentation.

Modified:
    debtorrent/branches/http-listen/DebTorrent/download_bt1.py

Modified: debtorrent/branches/http-listen/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/http-listen/DebTorrent/download_bt1.py?rev=84&op=diff
==============================================================================
--- debtorrent/branches/http-listen/DebTorrent/download_bt1.py (original)
+++ debtorrent/branches/http-listen/DebTorrent/download_bt1.py Sat Jun  2 20:35:00 2007
@@ -580,13 +580,13 @@
     @type spewflag: C{threading.Event}
     @ivar spewflag: unknown
     @type superseedflag: C{threading.Event}
-    @ivar superseedflag: unknown
-    @type whenpaused: unknown
-    @ivar whenpaused: unknown
+    @ivar superseedflag: indicates the upload is in super-seed mode
+    @type whenpaused: C{float}
+    @ivar whenpaused: the time when the download was paused
     @type finflag: C{threading.Event}
-    @ivar finflag: unknown
-    @type rerequest: unknown
-    @ivar rerequest: unknown
+    @ivar finflag: whether the download is complete
+    @type rerequest: L{BT1.Rerequester.Rerequester}
+    @ivar rerequest: the Rerequester instance to use to communicate with the tracker
     @type tcp_ack_fudge: C{float}
     @ivar tcp_ack_fudge: the fraction of TCP ACK download overhead to add to 
         upload rate calculations
@@ -595,13 +595,13 @@
     @type appdataobj: L{ConfigDir.ConfigDir}
     @ivar appdataobj: the configuration and cache directory manager
     @type excflag: C{threading.Event}
-    @ivar excflag: unknown
-    @type failed: unknown
-    @ivar failed: unknown
-    @type checking: unknown
-    @ivar checking: unknown
-    @type started: unknown
-    @ivar started: unknown
+    @ivar excflag: whether an exception has occurred
+    @type failed: C{boolean}
+    @ivar failed: whether the download failed
+    @type checking: C{boolean}
+    @ivar checking: whether the download is in the initialization phase
+    @type started: C{boolean}
+    @ivar started: whether the download has been started
     @type picker: L{BT1.PiecePicker.PiecePicker}
     @ivar picker: the PiecePicker instance
     @type choker: L{BT1.Choker.Choker}
@@ -612,30 +612,30 @@
     @ivar files: the full file names and lengths of all the files in the download
     @type datalength: C{long}
     @ivar datalength: the total length of the download
-    @type priority: unknown
-    @ivar priority: unknown
-    @type storage: unknown
-    @ivar storage: unknown
-    @type upmeasure: unknown
-    @ivar upmeasure: unknown
-    @type downmeasure: unknown
-    @ivar downmeasure: unknown
-    @type ratelimiter: unknown
-    @ivar ratelimiter: unknown
-    @type ratemeasure: unknown
-    @ivar ratemeasure: unknown
-    @type ratemeasure_datarejected: unknown
-    @ivar ratemeasure_datarejected: unknown
-    @type connecter: unknown
-    @ivar connecter: unknown
-    @type encoder: unknown
-    @ivar encoder: unknown
-    @type encoder_ban: unknown
-    @ivar encoder_ban: unknown
-    @type httpdownloader: unknown
-    @ivar httpdownloader: unknown
-    @type statistics: unknown
-    @ivar statistics: unknown
+    @type priority: C{list}
+    @ivar priority: the priorities to download the files at
+    @type storage: L{BT1.Storage.Storage}
+    @ivar storage: the file storage instance
+    @type upmeasure: L{CurrentRateMeasure.Measure}
+    @ivar upmeasure: the measure of the upload rate
+    @type downmeasure: L{CurrentRateMeasure.Measure}
+    @ivar downmeasure: the measure of the download rate
+    @type ratelimiter: L{RateLimiter.RateLimiter}
+    @ivar ratelimiter: the RateLimiter instance to limit the upload rate
+    @type ratemeasure: L{RateMeasure.RateMeasure}
+    @ivar ratemeasure: the RateMeasure instance
+    @type ratemeasure_datarejected: C{method}
+    @ivar ratemeasure_datarejected: the method to call when incoming data failed
+    @type connecter: L{BT1.Connecter.Connecter}
+    @ivar connecter: the Connecter instance to manage all the connections
+    @type encoder: L{BT1.Encrypter.Encoder}
+    @ivar encoder: the port listener for connections
+    @type encoder_ban: C{method}
+    @ivar encoder_ban: the method to call to ban and IP address
+    @type httpdownloader: L{BT1.HTTPDownloader.HTTPDownloader}
+    @ivar httpdownloader: the backup HTTP downloader
+    @type statistics: L{BT1.Statistics.Statistics}
+    @ivar statistics: the statistics gathering instance
     
     """
     
@@ -1047,26 +1047,80 @@
         self.encoder_ban(ip)
 
     def _received_raw_data(self, x):
+        """Update the rate limiter when data comes in.
+        
+        @type x: C{int}
+        @param x: the number of bytes that were received
+        
+        """
+        
         if self.tcp_ack_fudge:
             x = int(x*self.tcp_ack_fudge)
             self.ratelimiter.adjust_sent(x)
 
     def _received_data(self, x):
+        """Add received data to the rate measures.
+        
+        @type x: C{int}
+        @param x: the number of bytes that were received
+        
+        """
+        
         self.downmeasure.update_rate(x)
         self.ratemeasure.data_came_in(x)
 
     def _received_http_data(self, x):
+        """Add received HTTP data to the rate measures.
+        
+        @type x: C{int}
+        @param x: the number of bytes that were received
+        
+        """
+        
         self.downmeasure.update_rate(x)
         self.ratemeasure.data_came_in(x)
         self.downloader.external_data_received(x)
 
     def _cancelfunc(self, pieces):
+        """Cancel the download of pieces.
+        
+        @type pieces: C{list} of C{int}
+        @param pieces: the pieces to stop downloading
+        
+        """
+        
         self.downloader.cancel_piece_download(pieces)
         self.httpdownloader.cancel_piece_download(pieces)
+
     def _reqmorefunc(self, pieces):
+        """Request to download the pieces.
+        
+        @type pieces: C{list} of C{int}
+        @param pieces: the pieces to request
+        
+        """
+        
         self.downloader.requeue_piece_download(pieces)
 
     def startEngine(self, ratelimiter = None, statusfunc = None):
+        """Start various downloader engines.
+        
+        Starts the upload and download L{CurrentRateMeasure.Measure}, 
+        L{RateLimiter.RateLimiter}, L{BT1.Downloader.Downloader}, 
+        L{BT1.Connecter.Connecter}, L{BT1.Encrypter.Encoder}, and
+        L{BT1.HTTPDownloader.HTTPDownloader}.
+        
+        @type ratelimiter: L{RateLimiter.RateLimiter}
+        @param ratelimiter: the RateLimiter instance to use 
+            (optional, defaults to starting a new one)
+        @type statusfunc: C{method}
+        @param statusfunc: the method to call to report the current status
+            (optional, defaults to L{statusfunc}
+        @rtype: C{boolean}
+        @return: whether the engines were started
+        
+        """
+        
         if self.doneflag.isSet():
             return False
         if not statusfunc:
@@ -1138,23 +1192,43 @@
 
 
     def rerequest_complete(self):
+        """Send the completed event to the tracker."""
         if self.rerequest:
             self.rerequest.announce(1)
 
     def rerequest_stopped(self):
+        """Send the stopped event to the tracker."""
         if self.rerequest:
             self.rerequest.announce(2)
 
     def rerequest_lastfailed(self):
+        """Check if the last tracker request failed.
+        
+        @rtype: C{boolean}
+        @return: whether it failed (or False if there is no Rerequester)
+        
+        """
+        
         if self.rerequest:
             return self.rerequest.last_failed
         return False
 
     def rerequest_ondownloadmore(self):
+        """Try to trigger a tracker request."""
         if self.rerequest:
             self.rerequest.hit()
 
     def startRerequester(self, seededfunc = None, force_rapid_update = False):
+        """Start the tracker requester.
+        
+        @type seededfunc: C{method}
+        @param seededfunc: unknown
+        @type force_rapid_update: C{boolean}
+        @param force_rapid_update: whether to do quick tracker updates when 
+            requested (optional, defaults to False)
+        
+        """
+        
         if self.response.has_key('announce-list'):
             trackerlist = self.response['announce-list']
         else:
@@ -1175,6 +1249,7 @@
 
 
     def _init_stats(self):
+        """Start the statistics aggregater."""
         self.statistics = Statistics(self.upmeasure, self.downmeasure,
                     self.connecter, self.httpdownloader, self.ratelimiter,
                     self.rerequest_lastfailed, self.filedatflag)
@@ -1184,6 +1259,13 @@
             self.spewflag.set()
 
     def autoStats(self, displayfunc = None):
+        """Start the statistics automatic displayer for the user.
+        
+        @type displayfunc: C{method}
+        @param displayfunc: the method to call to print the current stats
+        
+        """
+        
         if not displayfunc:
             displayfunc = self.statusfunc
 
@@ -1195,6 +1277,13 @@
             displayfunc, self.config['display_interval'])
 
     def startStats(self):
+        """Start a statistics gatherer.
+        
+        @rtype: C{method}
+        @return: the method to call to get the gathered statistics
+        
+        """
+        
         self._init_stats()
         d = DownloaderFeedback(self.choker, self.httpdownloader, self.rawserver.add_task,
             self.upmeasure.get_rate, self.downmeasure.get_rate,
@@ -1204,10 +1293,26 @@
 
 
     def getPortHandler(self):
+        """Get the object that is called when a connection comes in.
+        
+        @rtype: L{BT1.Encrypter.Encoder}
+        @return: the object responsible for listening to a port
+        
+        """
+        
         return self.encoder
 
 
     def shutdown(self, torrentdata = {}):
+        """Shutdown the running download.
+        
+        @type torrentdata: C{dictionary}
+        @param torrentdata: any data that needs to be saved (pickled)
+        @rtype: C{boolean}
+        @return: False if a failure or exception occurred
+        
+        """
+        
         if self.checking or self.started:
             self.storagewrapper.sync()
             self.storage.close()
@@ -1225,77 +1330,232 @@
 
 
     def setUploadRate(self, rate):
+        """Set a new maximum upload rate.
+        
+        @type rate: C{float}
+        @param rate: the new upload rate (kB/s)
+        
+        """
+        
         try:
             def s(self = self, rate = rate):
+                """Worker function to actually set the rate.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to set the rate of 
+                    (optional, defaults to the current instance)
+                @type rate: C{float}
+                @param rate: the new rate to set 
+                    (optional, defaults to the L{setUploadRate} rate
+                
+                """
+                
                 self.config['max_upload_rate'] = rate
                 self.ratelimiter.set_upload_rate(rate)
+ 
             self.rawserver.add_task(s)
         except AttributeError:
             pass
 
     def setConns(self, conns, conns2 = None):
+        """Set the number of connections limits.
+        
+        @type conns: C{int}
+        @param conns: the number of uploads to fill out to with extra 
+            optimistic unchokes
+        @type conns2: C{int}
+        @param conns2: the maximum number of uploads to allow at once 
+            (optional, defaults to the value of L{conns})
+        
+        """
+        
         if not conns2:
             conns2 = conns
         try:
             def s(self = self, conns = conns, conns2 = conns2):
+                """Worker function to actually set the connection limits.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to set the rate of 
+                    (optional, defaults to the current instance)
+                @type conns: C{int}
+                @param conns: the number of uploads to fill out to with extra 
+                    optimistic unchokes
+                @type conns2: C{int}
+                @param conns2: the maximum number of uploads to allow at once
+                
+                """
+                
                 self.config['min_uploads'] = conns
                 self.config['max_uploads'] = conns2
                 if (conns > 30):
                     self.config['max_initiate'] = conns + 10
+                    
             self.rawserver.add_task(s)
         except AttributeError:
             pass
         
     def setDownloadRate(self, rate):
+        """Set a new maximum download rate.
+        
+        @type rate: C{float}
+        @param rate: the new download rate (kB/s)
+        
+        """
+        
         try:
             def s(self = self, rate = rate):
+                """Worker function to actually set the rate.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to set the rate of 
+                    (optional, defaults to the current instance)
+                @type rate: C{float}
+                @param rate: the new rate to set 
+                    (optional, defaults to the L{setDownloadRate} rate
+                
+                """
+                
                 self.config['max_download_rate'] = rate
                 self.downloader.set_download_rate(rate)
+
             self.rawserver.add_task(s)
         except AttributeError:
             pass
 
     def startConnection(self, ip, port, id):
+        """Start a new connection to a peer.
+        
+        @type ip: C{string}
+        @param ip: the IP address of the peer
+        @type port: C{int}
+        @param port: the port to contact the peer on
+        @type id: C{string}
+        @param id: the peer's ID
+        
+        """
+        
         self.encoder._start_connection((ip, port), id)
       
     def _startConnection(self, ipandport, id):
+        """Start a new connection to a peer.
+        
+        @type ipandport: (C{string}, C{int})
+        @param ipandport: the IP address and port to contact the peer on
+        @type id: C{string}
+        @param id: the peer's ID
+        
+        """
+        
         self.encoder._start_connection(ipandport, id)
         
     def setInitiate(self, initiate):
+        """Set the maximum number of connections to initiate.
+        
+        @type initiate: C{int}
+        @param initiate: the new maximum
+        
+        """
+        
         try:
             def s(self = self, initiate = initiate):
+                """Worker function to actually set the maximum.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to set the max connections of 
+                    (optional, defaults to the current instance)
+                @type initiate: C{int}
+                @param initiate: the new maximum
+                
+                """
+        
                 self.config['max_initiate'] = initiate
+
             self.rawserver.add_task(s)
         except AttributeError:
             pass
 
     def getConfig(self):
+        """Get the current configuration parameters.
+        
+        @rtype: C{dictionary}
+        @return: the configuration parameters
+        
+        """
+        
         return self.config
 
     def getDefaults(self):
+        """Get the default configuration parameters.
+        
+        @rtype: C{dictionary}
+        @return: the default configuration parameters
+        
+        """
+        
         return defaultargs(defaults)
 
     def getUsageText(self):
+        """Get the header only for the usage text (not used).
+        
+        @rtype: C{string}
+        @return: the header of the usage text
+        
+        """
+        
         return self.argslistheader
 
     def reannounce(self, special = None):
+        """Reannounce to the tracker.
+        
+        @type special: C{string}
+        @param special: the URL of the tracker to announce to 
+            (optional, defaults to the tracker list from the metainfo file)
+        
+        """
+        
         try:
             def r(self = self, special = special):
+                """Worker function to actually do the announcing.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to announce
+                    (optional, defaults to the current instance)
+                @type special: C{string}
+                @param special: the URL of the tracker to announce to 
+                
+                """
+
                 if special is None:
                     self.rerequest.announce()
                 else:
                     self.rerequest.announce(specialurl = special)
+
             self.rawserver.add_task(r)
         except AttributeError:
             pass
 
     def getResponse(self):
+        """Get the response data from the metainfo file.
+        
+        @rtype: C{dictionary}
+        @return: the response data (or None if there isn't any
+        
+        """
+        
         try:
             return self.response
         except:
             return None
 
     def Pause(self):
+        """Schedule the pausing of the download.
+
+        @rtype: C{boolean}
+        @return: whether the download pause was schedules
+        
+        """
+        
         if not self.storagewrapper:
             return False
         self.unpauseflag.clear()
@@ -1303,6 +1563,8 @@
         return True
 
     def onPause(self):
+        """Pause the download."""
+        
         self.whenpaused = clock()
         if not self.downloader:
             return
@@ -1311,10 +1573,12 @@
         self.choker.pause(True)
     
     def Unpause(self):
+        """Schedule the resuming of the download."""
         self.unpauseflag.set()
         self.rawserver.add_task(self.onUnpause)
 
     def onUnpause(self):
+        """Resume the download."""
         if not self.downloader:
             return
         self.downloader.pause(False)
@@ -1324,32 +1588,73 @@
             self.rerequest.announce(3)      # rerequest automatically if paused for >60 seconds
 
     def set_super_seed(self):
+        """Schedule the change of the upload into super-seed mode."""
         try:
             self.superseedflag.set()
             def s(self = self):
+                """Worker function to actually call the change to super-seed.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to change to super-seed
+                    (optional, defaults to the current instance)
+                
+                """
                 if self.finflag.isSet():
                     self._set_super_seed()
+
             self.rawserver.add_task(s)
         except AttributeError:
             pass
 
     def _set_super_seed(self):
+        """Change the upload into super-seed mode."""
         if not self.super_seeding_active:
             self.super_seeding_active = True
             self.errorfunc('        ** SUPER-SEED OPERATION ACTIVE **\n' +
                            '  please set Max uploads so each peer gets 6-8 kB/s')
             def s(self = self):
+                """Worker function to actually change to super-seed.
+                
+                @type self: L{BT1Download}
+                @param self: the BT1Download instance to change to super-seed
+                    (optional, defaults to the current instance)
+                
+                """
+
                 self.downloader.set_super_seed()
                 self.choker.set_super_seed()
+
             self.rawserver.add_task(s)
             if self.finflag.isSet():        # mode started when already finished
                 def r(self = self):
+                    """Worker function to actually do the announcing.
+                    
+                    @type self: L{BT1Download}
+                    @param self: the BT1Download instance to announce
+                        (optional, defaults to the current instance)
+                    
+                    """
+
                     self.rerequest.announce(3)  # so after kicking everyone off, reannounce
+
                 self.rawserver.add_task(r)
 
     def am_I_finished(self):
+        """Determine if the download is complete or still under way.
+        
+        @rtype: C{boolean}
+        @return: whether the download is complete
+        
+        """
+        
         return self.finflag.isSet()
 
     def get_transfer_stats(self):
+        """Get the total amount of data transferred.
+        
+        @rtype: (C{long}, C{long})
+        @return: the measured total upload and download bytes
+        
+        """
+        
         return self.upmeasure.get_total(), self.downmeasure.get_total()
-    




More information about the Debtorrent-commits mailing list