]> code.delx.au - pymsnt/blobdiff - src/ft.py
Fixed failedMessage exception.
[pymsnt] / src / ft.py
index a91610180401613bf7cf31a1b8ef11a1c0c9540f..86fd3d1c6a7d0beeff0562abb332acf6c22c7c28 100644 (file)
--- a/src/ft.py
+++ b/src/ft.py
@@ -1,6 +1,7 @@
 # Copyright 2005 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
+from tlib.throttle import Throttler
 from tlib.xmlw import Element
 from twisted.internet import protocol
 
@@ -14,6 +15,17 @@ import random
 import sys
 
 
+def doRateLimit(setConsumer, consumer):
+       try:
+               rateLimit = int(config.ftRateLimit)
+       except ValueError:
+               rateLimit = 0
+       if rateLimit > 0:
+               throttler = Throttler(consumer, rateLimit)
+               setConsumer(throttler)
+       else:
+               setConsumer(consumer)
+
 def checkSizeOk(size):
        try:
                size = int(size)
@@ -44,11 +56,15 @@ class FTSend:
                session.legacycon.sendFile(to, self)
        
        def accept(self, legacyFileSend):
-               self.startTransfer(legacyFileSend)
+               doRateLimit(self.startTransfer, legacyFileSend)
+               self.cleanup()
        
        def reject(self):
-               del self.startTransfer
                self.cancelTransfer()
+               self.cleanup()
+       
+       def cleanup(self):
+               del self.startTransfer, self.cancelTransfer
 
 
 try:
@@ -380,17 +396,17 @@ class Proxy65(protocol.Factory):
                        assert address not in self.activeConns
                        self.activeConns[address] = None
                        
-                       if not isinstance(olist[0], (JEP65ConnectionReceive, JEP65ConnectionSend)):
+                       if not isinstance(olist[0], JEP65ConnectionReceive):
                                legacyftp = olist[0]
                                connection = olist[1]
-                       elif not isinstance(olist[1], (JEP65ConnectionReceive, JEP65ConnectionSend)):
+                       elif not isinstance(olist[1], JEP65ConnectionReceive):
                                legacyftp = olist[1]
                                connection = olist[0]
                        else:
                                LogEvent(WARN, '', "No JEP65Connection")
                                return
 
-                       legacyftp.accept(connection.transport)
+                       doRateLimit(legacyftp.accept, connection.transport)
                else:
                        LogEvent(WARN, '', "No pending connection.")
        
@@ -426,7 +442,7 @@ from debug import LogEvent, INFO, WARN, ERROR
 class OOBReceiveConnector:
        def __init__(self, ftReceive, ftHttpPush):
                self.ftReceive, self.ftHttpPush = ftReceive, ftHttpPush
-               self.ftReceive.legacyftp.accept(self)
+               doRateLimit(self.ftReceive.legacyftp.accept, self)
        
        def write(self, data):
                self.ftHttpPush.write(data)