当前位置: 首页>>代码示例>>Python>>正文


Python Function.find_file_by_md5方法代码示例

本文整理汇总了Python中Function.find_file_by_md5方法的典型用法代码示例。如果您正苦于以下问题:Python Function.find_file_by_md5方法的具体用法?Python Function.find_file_by_md5怎么用?Python Function.find_file_by_md5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Function的用法示例。


在下文中一共展示了Function.find_file_by_md5方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import Function [as 别名]
# 或者: from Function import find_file_by_md5 [as 别名]

#.........这里部分代码省略.........
							else:
								func.write_daemon_error(self.name, addr[0], "ADD FILE - User not logged")

					elif str(ricevutoByte[0:4], "ascii") == const.CODE_REMOVEFILE:
						if self.SN:
							if func.isUserLogged(ricevutoByte[4:20], self.listUsers):
								findFile = False
								i = 0
								for file in self.listFiles:
									if (ricevutoByte[4:20] == file[2]) and (ricevutoByte[20:] == file[0]):
										findFile = True
										del self.listFiles[i]
										func.write_daemon_success(self.name, addr[0], "REMOVE FILE: " + str(ricevutoByte[20:], "ascii").strip())
										i -= 1
									i += 1
								if not findFile:
									func.write_daemon_error(self.name, addr[0], "REMOVE FILE - File not exists")
							else:
								func.write_daemon_error(self.name, addr[0], "REMOVE FILE - User not logged")

					elif str(ricevutoByte[0:4], "ascii") == const.CODE_LOGOUT: ### LOGOUT
						if self.SN:
							i = 0
							for user in self.listUsers:
								if ricevutoByte[4:] == user[2]:
									del user

							nDelete = 0
							for file in self.listFiles:
								if ricevutoByte[4:] == file[2]:
									del self.listFiles[i]
									nDelete += 1
									i -= 1
								i += 1

							pk = pack.answer_logout(nDelete)
							conn.sendall(pk)
							func.write_daemon_success(self.name, addr[0], "LOGOUT OK")


					elif str(ricevutoByte[0:4], "ascii") == const.CODE_QUERY: ### QUERY tra SN
						func.write_daemon_text(self.name, addr[0], "QUERY - " + func.reformat_string(str(ricevutoByte[82:],"ascii")))
						if func.add_pktid(ricevutoByte[4:20], self.listPkt, self.port) is True:
							# Inoltro
							pk = pack.forward_query(ricevutoByte)
							func.forward(pk, addr[0], self.sn_network)

							# Rispondi
							listFileFounded = []
							listFileFounded = func.search_file(bytes(func.reformat_string(str(ricevutoByte[82:],"ascii")),"ascii"), self.listFiles, self.listUsers) # Da controllare
							if len(listFileFounded) != 0:
								for x in listFileFounded:
									pk = pack.answer_query(ricevutoByte[4:20], x[2], x[3], str(x[0], "ascii"), str(x[1], "ascii"))
									sC = func.create_socket_client(func.roll_the_dice(str(ricevutoByte[20:75], "ascii")), ricevutoByte[75:80])
									if sC != None:
										sC.sendall(pk)
										sC.close()
						#else:
						#	func.write_daemon_error(self.name, addr[0], "Pacchetto già ricevuto")

					elif str(ricevutoByte[0:4], "ascii") == const.CODE_ANSWER_QUERY: ### RISPOSTA QUERY tra SN
						if func.check_query(ricevutoByte[4:20], self.listPkt, self.port):
							listResultQuery.append([ricevutoByte[80:112], ricevutoByte[112:], ricevutoByte[20:75], ricevutoByte[75:80]])
						else: 
							func.write_daemon_error(self.name, addr[0], "ANSWER QUERY - Ricerca conclusa")
					
					elif str(ricevutoByte[0:4], "ascii") == const.CODE_DOWNLOAD: ### DOWNLOAD
						func.write_daemon_text(self.name, addr[0], "UPLOAD")
						filef = func.find_file_by_md5(ricevutoByte[4:])
						if filef != const.ERROR_FILE:
							func.upload(filef, conn)

					elif(str(ricevutoByte[0:4], "ascii") == const.CODE_SEARCH): ### Richiesta di ricerca da un peer
						if self.SN:
							del listResultQuery[:]
							func.write_daemon_text(self.name, addr[0], "INIZIO RICERCA DI: " + str(ricevutoByte[20:], "ascii").strip())
							pk = pack.query(self.host, ricevutoByte[20:])
							func.add_pktid(pk[4:20], self.listPkt, self.port)

							for x in self.sn_network:
								sNet = func.create_socket_client(func.roll_the_dice(x[0]), x[1])
								if sNet != None:
									sNet.sendall(pk)
									sNet.close()

							listaRisultatiDellaQuery = []
							listaRisultatiDellaQuery = func.search_file(bytes(str(ricevutoByte[20:],"ascii").strip(),"ascii"), self.listFiles, self.listUsers)
							for x in listaRisultatiDellaQuery:
								listResultQuery.append(x)


							#func.send_afin(conn, self.listResultQuery)

							daemonAfin = threading.Thread(target=sendAfin, args=(conn, ))
							daemonAfin.start()

							#t = Timer(int(const.MAX_TIME / 1000), func.send_afin, (conn, self.listResultQuery))
					else:
						func.write_daemon_error(self.name, addr[0], "Ricevuto pacchetto sbagliato: " + str(ricevutoByte, "ascii"))
			s.close()
开发者ID:tommasoberlose,项目名称:p2p_kazaa,代码行数:104,代码来源:Daemon.py


注:本文中的Function.find_file_by_md5方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。