def test_bitencoding2(self): pieces = set([0]) message = specs.PieceBitFieldMessage.create(pieces) code = message.pack() object = Message.parse(code) self.assert_(isinstance(object, PieceBitFieldMessage)) self.assertEqual(object.pieces, pieces)
def test_identity(self): peer_id = ''.join(random.choice(string.letters) for _ in range(20)) handshake = specs.HandshakeMessage.create(peer_id) bytes = handshake.pack() new_handshake = Message.parse(bytes) self.assert_(isinstance(new_handshake, specs.HandshakeMessage))
def test_iomessage(self): peer_id = ''.join(random.choice(string.letters) for _ in range(20)) handshake = specs.HandshakeMessage.create(peer_id) bytes = handshake.pack() new_handshake = Message.parse(bytes) self.assert_(new_handshake.is_valid()) self.assertEqual(new_handshake.peer_id, peer_id)
def stringReceived(self, message): """Overrides method to receive a message without the prefix """ logging.debug('Received: {0} from {1}'.format(repr(message[0]), self.partner_address)) if self.handshaked and self.choked: logging.info('Ignoring message because the peer is choked') return try: message_object = Message.parse(message) except MessageException as error: logging.error('Decoding error ' + str(error)) self.drop() return handler = self.handlers.get(type(message_object), self.receive_default) handler(message_object)