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


Python Storage.is_all_piece_received方法代码示例

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


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

示例1: Torrent

# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import is_all_piece_received [as 别名]

#.........这里部分代码省略.........
				connection.choke()

	################################
	# Interface
	################################
	def newConnection(self, connection):
		self.connections[connection.peer_id] = connection
		print '[Torrent]\ttotal connected peers: ', len(self.connections)
		connection.bitfield(self.storage.gen_complete_str())
		

	def lostConnection(self, connection):
		if connection.peer_id in self.connections:
			del self.connections[connection.peer_id]
		self._cleanup_connection(connection)
		print '[Torrent]\ttotal connected peers: ', len(self.connections)
	################################
	# Event
	################################
	def onRequest(self, connection, block_info):
		if self.paused:
			return
		data = self.storage.get(*block_info)
		connection.piece(block_info, data)

	def onPiece(self, connection, block_info, block_data):
		if self.paused:
			return
		
		self.storage.push(block_info[0], block_info[1], block_data)
		if self.storage.is_piece_received(block_info[0]):
			self.pushHave(block_info[0])

			if self.storage.is_all_piece_received():
				# save target file
				self.storage.save_target_file(self.target_file)

				self.onComplete()

		request = (connection, block_info)
		self.downloading.remove(request)
		self._try_download()

		print 'push piece', block_info, len(block_data), ', rate:', repr(self.getDownloadRate() / 1000) + 'kb/s, complete:', repr(self.storage.get_downloaded_rate()*100)+'%'
		if connection.peer_id not in self.count_received.keys():
			self.count_received[connection.peer_id] = 1
		else:
			self.count_received[connection.peer_id] += 1

	def onCancel(self, connection, block_info):
		# now nothing to do
		pass

	def onUnchoked(self, connection):
		self._try_download()

	def onComplete(self):
		if self.completed:
			return

		time_used = time() - self.start_time
		if time_used == 0:
			time_used = 1e-7
		print '[Torrent]\tDownload Completed!', 'Total time:', time_used, 'Speed:', repr(self.storage.length / time_used / 1024) + 'kb/s'
		for peer_id in self.count_received:
			print '\t\tFrom #' + peer_id + ' received:', self.count_received[peer_id]
开发者ID:hyf042,项目名称:python-bittorrent,代码行数:70,代码来源:torrent.py

示例2: Storage

# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import is_all_piece_received [as 别名]
from storage import Storage

info = {}
info["piece_length"] = 524288
info["length"] = 524288 * 8
st = Storage(info)

print("is all piece received: ", st.is_all_piece_received())
for i in range(8):
	for j in range(32):
		st.push(i, j*16*1024, "sdfsdfsdf")
print("is all piece received: ", st.gen_priority_list())
print("is all piece received: ", st.is_all_piece_received())
开发者ID:hyf042,项目名称:python-bittorrent,代码行数:15,代码来源:unit_test_storage.py


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