예제 #1
0
	def dispatch(self, data, host, port):
		retCode, result = self.msgManager.resRequest(data)
		if retCode != 0:
			self.logger.logger('Error Request')
		else:
			responseData = {}
			if result['request'] == 'scan':
				self.logger.logger('Request: SCAN')
				if not os.path.isfile(result['path']):
					responseData['response'] = 1
				else:
					hashval = ndutil.getMd5(result['path'])
					reqTime = ndutil.getCreated()
					fileSize = ndutil.getSize(result['path'])

					if (fileSize/1024/1024) >= 32:
						responseData['response'] = 1
					else:
						scanCode, scanResult = self.dbManager.scan(reqTime, result['path'], hashval)
						if scanCode == 0:
							responseData['response'] = 0
							nums = scanResult.split('/', 1)
							responseData['hashval'] = hashval
							responseData['positive'] = nums[0]
							responseData['total'] = nums[1]
						if scanCode == 1:
							responseData['response'] = 2
						if scanCode == 2:
							responseData['response'] = 2
							self.fsLock.acquire()
							self.fsQueue.put('%s,%s' % (hashval, result['path']), 1)
							self.fsLock.release()

			msg = self.msgManager.genResponse(responseData)
			self.transport.write(msg, (host, port))
예제 #2
0
    def run(self):
        self.rpcMonitor.setDownloadedTotal(0)
        self.rpcMonitor.setDuplicatedTotal(0)
        while True:
            data, fileName = self.dpQueue.get(1)

            # filte 0KB file
            if ndutil.getSize(fileName) == 0:
                self.pdLock.acquire()
                self.pdQueue.put(data, 1)
                self.rpcMonitor.incPdQueueSize()
                self.pdLock.release()
                continue

                # duplicate?
            md5Value = ndutil.getMd5(fileName)

            path = self.dbManager.get_path_by_hashval(md5Value)
            if path is not None:
                self.dbManager.update_item(data, "NULL", path, md5Value, 1)
                self.rpcMonitor.incDuplicatedTotal()
                self.logger.logger("Duplicated %s" % path)
                os.remove(fileName)
                continue

            newFileName = "%s/%s.apk" % (self.dirStore, md5Value)
            shutil.move(fileName, newFileName)
            self.dbManager.update_item(data, "NULL", newFileName, md5Value, 1)
            self.rpcMonitor.incDownloadedTotal()
            self.logger.logger("Downloaded %s" % data)