#NEWLINE# def __init__( self , server_addr , peer , path , options , stats_callback ) : #NEWLINE# #INDENT# '\n        Class that deals with talking to a single client. Being a subclass of\n        `multiprocessing.Process` this will run in a separate process from the\n        main process.\n\n        Note:\n            Do not use this class as is, inherit from it and override the\n            `get_response_data` method which must return a subclass of\n            `ResponseData`.\n\n        Args:\n            server_addr (tuple): (ip, port) of the server\n\n            peer (tuple): (ip, port of) the peer\n\n            path (string): requested file\n\n            options (dict): a dictionary containing the options the client\n                wants to negotiate.\n\n            stats_callback (callable): a callable that will be executed at the\n                end of the session. It gets passed an instance of the\n                `SessionStats` class.\n        ' #NEWLINE# self . _timeout = int ( options [ 'default_timeout' ] ) #NEWLINE# self . _server_addr = server_addr #NEWLINE# self . _reset_timeout ( ) #NEWLINE# self . _retries = int ( options [ 'retries' ] ) #NEWLINE# self . _block_size = constants . DEFAULT_BLKSIZE #NEWLINE# self . _last_block_sent = 0 #NEWLINE# self . _retransmits = 0 #NEWLINE# self . _current_block = None #NEWLINE# self . _should_stop = False #NEWLINE# self . _path = path #NEWLINE# self . _options = options #NEWLINE# self . _stats_callback = stats_callback #NEWLINE# self . _response_data = None #NEWLINE# self . _peer = peer #NEWLINE# logging . info ( ( 'New connection from peer `%s` asking for path `%s`' % ( str ( peer ) , str ( path ) ) ) ) #NEWLINE# family = socket . AF_INET6 #NEWLINE# if isinstance ( ipaddress . ip_address ( server_addr [ 0 ] ) , ipaddress . IPv4Address ) : #NEWLINE# #INDENT# family = socket . AF_INET #NEWLINE# self . _peer = ( self . _peer [ 0 ] . replace ( '::ffff:' , '' ) , self . _peer [ 1 ] ) #NEWLINE# #UNINDENT# self . _stats = SessionStats ( self . _server_addr , e . _peer , self . _path ) #NEWLINE# try : #NEWLINE# #INDENT# self . _response_data = self . get_response_data ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logging . exception ( ( 'Caught exception: %s.' % e ) ) #NEWLINE# self . _stats . error = { #NEWLINE# #INDENT# 'error_code' : constants . ERR_UNDEFINED , #NEWLINE# 'error_message' : str ( e ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# self . _listener = socket . socket ( family , socket . SOCK_DGRAM ) #NEWLINE# self . _listener . bind ( ( str ( server_addr [ 0 ] ) , 0 ) ) #NEWLINE# super ( ) . __init__ ( )