def recv_bitfield(self, length):
"""
Received only at the start of a connection when a peer wants to
tell you all the pieces it has in a very compact form.
:param length: The size of the payload, a number of bits
representing the number of pieces
"""
payload = self.recv(length)
bits = BitArray(bytes=payload)
for i in range(len(self.torrent.pieces)):
sha, piece = self.torrent.pieces.items()[i]
piece = self.PIECE(sha, self, have=bits[i])
self.pieces[sha] = piece
评论列表
文章目录