def start(self, IP, CoTPort, Event, clientDataPipe, ReceiveConnectionKillSwitch, RestAPIPipe): try: self.db = sqlite3.connect(DPConst().DATABASE) os.chdir('../../../') # create socket controller self.MainSocketController.changeIP(IP) self.MainSocketController.changePort(CoTPort) sock = self.MainSocketController.createSocket() #changed from multiprocessing.pool import ThreadPool pool = ThreadPool(processes=2) self.pool = pool clientData = pool.apply_async(ClientReceptionHandler().startup, (self.clientInformationQueue, )) receiveConnection = pool.apply_async(ReceiveConnections().listen, (sock, )) # instantiate domain model and save process as object self.mainRunFunction(clientData, receiveConnection, sock, pool, Event, clientDataPipe, ReceiveConnectionKillSwitch, RestAPIPipe) except Exception as e: self.logger.critical( 'there has been a critical error in the startup of FTS' + str(e)) return -1
def start(self, IP, CoTPort, Event, clientDataPipe, ReceiveConnectionKillSwitch, RestAPIPipe): try: self.dbController = DatabaseController() # self.clear_user_table() os.chdir('../../../') # create socket controller self.TCPSocketController = TCPSocketController() self.TCPSocketController.changeIP(IP) self.TCPSocketController.changePort(CoTPort) sock = self.TCPSocketController.createSocket() pool = ThreadPool(processes=2) self.pool = pool clientData = pool.apply_async(ClientReceptionHandler().startup, (self.clientInformationQueue, )) receiveConnection = pool.apply_async(ReceiveConnections().listen, (sock, )) # instantiate domain model and save process as object self.mainRunFunction(clientData, receiveConnection, sock, pool, Event, clientDataPipe, ReceiveConnectionKillSwitch, RestAPIPipe) except Exception as e: logger.error('there has been an exception in the start function ' 'of TCPCoTService ' + str(e)) return e
def start(self, IP, CoTPort, Event, clientDataPipe, ReceiveConnectionKillSwitch, RestAPIPipe): try: self.dbController = DatabaseController() print('ssl cot service starting') os.chdir('../../') # create socket controller self.SSLSocketController = SSLSocketController() self.SSLSocketController.changeIP(IP) self.SSLSocketController.changePort(CoTPort) sock = self.SSLSocketController.createSocket() #threadpool is used as it allows the transfer of SSL socket unlike processes pool = ThreadPool(processes=2) self.pool = pool clientData = pool.apply_async(ClientReceptionHandler().startup, (self.clientInformationQueue,)) receiveConnection = pool.apply_async(ReceiveConnections().listen, (sock,)) # instantiate domain model and save process as object self.mainRunFunction(clientData, receiveConnection, sock, pool, Event, clientDataPipe, ReceiveConnectionKillSwitch, RestAPIPipe, True) except Exception as e: logger.error("there has been an exception thrown in" " the starting of the ssl service " + str(e)) return e
def mainRunFunction(self, clientData, receiveConnection, sock, pool, event, clientDataPipe, ReceiveConnectionKillSwitch, CoTSharePipe, ssl=False): print('server started') import datetime receiveconntimeoutcount = datetime.datetime.now() lastprint = datetime.datetime.now() while event.is_set(): self.CoTSharePipe = CoTSharePipe try: if ssl == True: pass self.clientDataPipe = clientDataPipe if event.is_set(): try: if ReceiveConnectionKillSwitch.is_set(): try: receiveConnection.successful() except: pass ReceiveConnectionKillSwitch.clear() receiveConnection = pool.apply_async( ReceiveConnections().listen, (sock, )) else: receiveConnectionOutput = receiveConnection.get( timeout=0.01) receiveConnection = pool.apply_async( ReceiveConnections().listen, ( sock, ssl, )) receiveconntimeoutcount = datetime.datetime.now() lastprint = datetime.datetime.now() CoTOutput = self.handel_connection_data( receiveConnectionOutput) except multiprocessing.TimeoutError: if (datetime.datetime.now() - receiveconntimeoutcount ) > datetime.timedelta(seconds=60) and ssl == True: from multiprocessing.pool import ThreadPool try: pass print('\n\nresetting\n\n') pool.terminate() pool = ThreadPool(processes=2) self.pool = pool receiveconntimeoutcount = datetime.datetime.now( ) lastprint = datetime.datetime.now() clientData = pool.apply_async( ClientReceptionHandler().startup, (self.clientInformationQueue, )) receiveConnection = pool.apply_async( ReceiveConnections().listen, ( sock, ssl, )) except Exception as e: print(str(e)) elif ssl == True and (datetime.datetime.now() - lastprint) > datetime.timedelta( seconds=30): print('time since last reset ' + str(datetime.datetime.now() - receiveconntimeoutcount)) lastprint = datetime.datetime.now() else: pass except Exception as e: self.logger.error( 'exception in receive connection within main run function ' + str(e)) try: clientDataOutput = clientData.get(timeout=0.01) if self.checkOutput(clientDataOutput) and isinstance( clientDataOutput, list): CoTOutput = self.handel_regular_data( clientDataOutput) else: raise Exception( 'client reception handler has returned data which is not of type list data is ' + str(clientDataOutput)) clientData = pool.apply_async( ClientReceptionHandler().startup, (self.clientInformationQueue, )) except multiprocessing.TimeoutError: pass except Exception as e: #self.logger.info('exception in receive client data within main run function ' + str(e)) pass try: if not CoTSharePipe.empty(): # print('getting share pipe data') data = CoTSharePipe.get() CoTOutput = self.handel_shared_data(data) else: pass except Exception as e: self.logger.error( 'there has been an excepion in the handling of data supplied by the rest API ' + str(e)) pass else: self.stop() break except Exception as e: self.logger.info( 'there has been an uncaught error thrown in mainRunFunction' + str(e)) pass self.stop()