def run(self): from app import APP APP.Functions.set_process_name ( "0@TFTPD_DATA" ) logger = APP.LoggingClient ( name = "TFTPD%05d" % self.pid ) queue_errors = 0 while 1: try: (client_address, initiating_packet, filename, filesize) = self.rfQueue.get() except: queue_errors += 1 if queue_errors > 2: logger ("Too many errors reading rfqueue") break time.sleep(queue_errors) queue_errors = 0 if client_address is None: break logger ("Sending %s to %s" % (filename, client_address)) try: with open(filename, 'r') as source: try: (bytes, dt, speed) = Protocol.Handle_RRQ (initiating_packet, client_address, source) logger ( "Sent %d bytes to %s at %.1f kB/s" % (bytes, client_address, speed/ 1024) ) except Protocol.TFTPProtocolError as e: logger ( "TFTP Protocol Error: %s" % e ) except: info = sys.exc_info()[:2] logger ( "TFTP error: %s, %s" % (info[0], info[1])) logger ( "EXIT" )
def handle_RRQ (self, ipacket, client_address): from os import urandom from random import randint from StringIO import StringIO print "Handling %s from %s, sending random data." % (ipacket, client_address) stream = StringIO ( urandom ( randint(1000,20000) ) ) Protocol.Handle_RRQ ( ipacket, client_address, stream ) return stream.len()