]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
Remove some unnecessary log messages and use better Exceptions.
authorCameron Dale <camrdale@gmail.com>
Fri, 18 Apr 2008 02:14:05 +0000 (19:14 -0700)
committerCameron Dale <camrdale@gmail.com>
Fri, 18 Apr 2008 02:14:05 +0000 (19:14 -0700)
apt_p2p/HTTPServer.py
apt_p2p/PeerManager.py
apt_p2p/util.py
apt_p2p_Khashmir/knode.py

index d72423e083746f79bc353a00627cdb1d1ebccc02..da582fc350d5fb61218d7b7971374adaa5f91390 100644 (file)
@@ -191,9 +191,7 @@ class UploadThrottlingProtocol(ThrottlingProtocol):
     def registerProducer(self, producer, streaming):
         ThrottlingProtocol.registerProducer(self, producer, streaming)
         streamType = getattr(producer, 'stream', None)
-        log.msg('Registered a producer %r with type %r' % (producer, streamType))
         if isinstance(streamType, UploadStream):
-            log.msg('Throttling')
             self.throttle = True
 
 
index 737669751da78ee9a3242996aed50e41dc5aa18b..d4c7aace9ad04dce45fceb1ac944c61803a7cc96 100644 (file)
@@ -19,6 +19,10 @@ from Hash import PIECE_SIZE
 from apt_p2p_Khashmir.bencode import bdecode
 from apt_p2p_conf import config
 
+
+class PeerError(Exception):
+    """An error occurred downloading from peers."""
+    
 class GrowingFileStream(stream.FileStream):
     """Modified to stream data from a file as it becomes available.
     
@@ -181,10 +185,10 @@ class StreamToFile:
     def _gotData(self, data):
         """Process the received data."""
         if self.outFile.closed:
-            raise Exception, "outFile was unexpectedly closed"
+            raise PeerError, "outFile was unexpectedly closed"
         
         if data is None:
-            raise Exception, "Data is None?"
+            raise PeerError, "Data is None?"
         
         # Make sure we don't go too far
         if self.length is not None and self.position + len(data) > self.length:
@@ -398,7 +402,6 @@ class FileDownload:
 
         if self.pieces is None:
             # Send a request to one or more peers
-            log.msg('Checking for a peer to request piece hashes from')
             for site in self.peers:
                 if self.peers[site].get('failed', False) != True:
                     log.msg('Sending a piece hash request to %r' % (site, ))
@@ -412,7 +415,6 @@ class FileDownload:
                     if self.outstanding >= 4:
                         break
         
-        log.msg('Done sending piece hash requests for now, %d outstanding' % self.outstanding)
         if self.pieces is None and self.outstanding <= 0:
             # Continue without the piece hashes
             log.msg('Could not retrieve the piece hashes from the peers')
@@ -424,7 +426,6 @@ class FileDownload:
         log.msg('Got a piece hash response %d from %r' % (response.code, site))
         if response.code != 200:
             # Request failed, try a different peer
-            log.msg('Did not like response %d from %r' % (response.code, site))
             self.getPeerPieces(key, site)
         else:
             # Read the response stream to a string
@@ -521,11 +522,9 @@ class FileDownload:
     #{ Downloading the pieces
     def getPieces(self):
         """Download the next pieces from the peers."""
-        log.msg('Checking for more piece requests to send')
         self.sort()
         piece = self.nextFinish
         while self.outstanding < 4 and self.peerlist and piece < len(self.completePieces):
-            log.msg('Checking piece %d' % piece)
             if self.completePieces[piece] == False:
                 # Send a request to the highest ranked peer
                 peer = self.peerlist.pop()
@@ -543,7 +542,6 @@ class FileDownload:
                                      'errbackArgs': (piece, peer)})
             piece += 1
                 
-        log.msg('Finished checking pieces, %d outstanding, next piece %d of %d' % (self.outstanding, self.nextFinish, len(self.completePieces)))
         # Check if we're done
         if self.outstanding <= 0 and self.nextFinish >= len(self.completePieces):
             log.msg('We seem to be done with all pieces')
index ec0287cec4bc9790ad348a232d769644844b7445..51582f77ac2ef1d6554e7f60bcd178a251c6c487 100644 (file)
@@ -117,7 +117,7 @@ def ipAddrFromChicken():
          f.close()
          current_ip = ip_search.findall(data)
          return current_ip
-    except Exception:
+    except:
          return []
 
 def uncompact(s):
index 9acf9b777392857cfa247dd4d40505ba3338abac..2cefe236b93e36455b66e46ffccd43d8fb11f630 100644 (file)
@@ -7,6 +7,9 @@ from twisted.python import log
 
 from node import Node, NULL_ID
 
+class KNodeError(Exception):
+    """An error occurred in contacting the node."""
+
 class KNodeBase(Node):
     """A basic node that can only be pinged and help find other nodes."""
     
@@ -16,12 +19,12 @@ class KNodeBase(Node):
             senderid = dict['id']
         except KeyError:
             log.msg("No peer id in response")
-            raise Exception, "No peer id in response."
+            raise KNodeError, "No peer id in response."
         else:
             if self.id != NULL_ID and senderid != self.id:
                 log.msg("Got response from different node than expected.")
                 self.table.invalidateNode(self)
-                raise Exception, "Node ID has changed"
+                raise KNodeError, "Node ID has changed"
                 
         return dict