def from_bytes(cls, data): if not check_bytes_length(data, 68): return None offset = 0 offset, length = Network.read_byte_as_int(data, offset) offset, protocol = Network.read_bytes(data, 19, offset) offset, reserved = Network.read_bytes(data, 8, offset) offset, info_hash = Network.read_bytes(data, 20, offset) offset, peer_id = Network.read_bytes(data, 20, offset) result = cls(info_hash) result.length = length result.protocol = protocol result.reserved = reserved result.peer_id = peer_id return result
def from_bytes(cls, data): if not check_minimal_bytes_length(data, 10): return None offset = 1 offset, piece_index = Network.read_integer(data, offset) offset, data_offset = Network.read_integer(data, offset) offset, data_bytes = Network.read_bytes(data, len(data) - offset, offset) return cls(piece_index, data_offset, data_bytes)
def from_bytes(cls, data): added = [] dropped = [] offset, payload_data = Network.read_bytes(data, len(data) - 2, 2) payload = Bencode.bdecode(payload_data) if b'added' in payload: addedbytes = payload[b'added'] total_peers = int(len(addedbytes) / 6) offset = 0 for index in range(total_peers): added.append(uri_from_bytes(addedbytes[offset:offset + 6])) offset += 6 return cls(added, dropped)
def from_bytes(cls, data): if not check_minimal_bytes_length(data, 2): return None offset, payload_data = Network.read_bytes(data, len(data) - 2, 2) payload = Bencode.bdecode(payload_data) metadata_message_type = payload[b'msg_type'] piece_index = payload[b'piece'] total_size = 0 metadata = None if metadata_message_type == MetadataMessageType.Data: if b'total_size' not in payload: return None total_size = payload[b'total_size'] metadata = data[2 + len(Bencode.bencode(payload)):len(data)] return cls(None, metadata_message_type, piece_index, total_size, metadata)
def from_bytes(cls, data): if not check_minimal_bytes_length(data, 3): return None offset, payload = Network.read_bytes(data, len(data) - 2, 2) return cls(payload)
def from_bytes(cls, data): if not check_minimal_bytes_length(data, 2): return None offset, bitfield = Network.read_bytes(data, len(data) - 1, 1) return cls(bitfield)