def receive_message(self, message, echohash): is_debug_log_enabled = log.isEnabledFor(logging.DEBUG) if is_debug_log_enabled: log.info('MESSAGE RECEIVED', node=pex(self.raiden.address), echohash=pex(echohash), message=message, message_sender=pex(message.sender)) try: on_udp_message(self.raiden, message) # only send the Ack if the message was handled without exceptions ack = Ack( self.raiden.address, echohash, ) self.maybe_send_ack( message.sender, ack, ) except (InvalidAddress, UnknownAddress, UnknownTokenAddress) as e: if is_debug_log_enabled: log.warn(str(e)) else: if is_debug_log_enabled: log.debug( 'ACK', node=pex(self.raiden.address), to=pex(message.sender), echohash=pex(echohash), )
def receive_message(self, message, message_id): is_debug_log_enabled = log.isEnabledFor(logging.DEBUG) if is_debug_log_enabled: log.info('MESSAGE RECEIVED', node=pex(self.raiden.address), message_id=message_id, message=message, message_sender=pex(message.sender)) try: on_udp_message(self.raiden, message) # only send the Processed message if the message was handled without exceptions processed_message = Processed(self.raiden.address, message_id) self.maybe_send_processed( message.sender, processed_message, ) except (InvalidAddress, UnknownAddress, UnknownTokenAddress) as e: if is_debug_log_enabled: log.warn(str(e)) else: if is_debug_log_enabled: log.debug( 'PROCESSED', node=pex(self.raiden.address), to=pex(message.sender), message_id=message_id, )
def receive_message(self, message): """ Handle a Raiden protocol message. The protocol requires durability of the messages. The UDP transport relies on the node's WAL for durability. The message will be converted to a state change, saved to the WAL, and *processed* before the durability is confirmed, which is a stronger property than what is required of any transport. """ # pylint: disable=unidiomatic-typecheck if on_udp_message(self.raiden, message): # Sending Delivered after the message is decoded and *processed* # gives a stronger guarantee than what is required from a # transport. # # Alternatives are, from weakest to strongest options: # - Just save it on disk and asynchronously process the messages # - Decode it, save to the WAL, and asynchronously process the # state change # - Decode it, save to the WAL, and process it (the current # implementation) delivered_message = Delivered(message.message_identifier) self.raiden.sign(delivered_message) self.maybe_send( message.sender, delivered_message, )
def _receive_message(self, message): self.log.info( 'MESSAGE RECEIVED', node=pex(self._raiden_service.address), message=message, message_sender=pex(message.sender), ) try: if on_udp_message(self._raiden_service, message): # TODO: Maybe replace with Matrix read receipts. # Unfortunately those work on an 'up to' basis, not on individual messages # which means that message order is important which isn't guaranteed between # federated servers. # See: https://matrix.org/docs/spec/client_server/r0.3.0.html#id57 delivered_message = Delivered(message.message_identifier) self._raiden_service.sign(delivered_message) self._send_immediate(message.sender, json.dumps(delivered_message.to_dict())) except (InvalidAddress, UnknownAddress, UnknownTokenAddress): self.log.warn('Exception while processing message', exc_info=True) return self.log.debug( 'DELIVERED', node=pex(self._raiden_service.address), to=pex(message.sender), message_identifier=message.message_identifier, )
def test_close_channel_lack_of_balance_proof(raiden_chain, deposit, token_addresses): app0, app1 = raiden_chain token_address = token_addresses[0] token_network_identifier = views.get_token_network_identifier_by_token_address( views.state_from_app(app0), app0.raiden.default_registry.address, token_address, ) token_proxy = app0.raiden.chain.token(token_address) initial_balance0 = token_proxy.balance_of(app0.raiden.address) initial_balance1 = token_proxy.balance_of(app1.raiden.address) amount = 100 identifier = 1 secret = pending_mediated_transfer( raiden_chain, token_network_identifier, amount, identifier, ) # Stop app0 to avoid sending the unlock app0.raiden.transport.stop_and_wait() reveal_secret = RevealSecret( random.randint(0, UINT64_MAX), secret, ) app0.raiden.sign(reveal_secret) udp_message_handler.on_udp_message(app1.raiden, reveal_secret) channel_state = get_channelstate(app0, app1, token_network_identifier) waiting.wait_for_settle( app0.raiden, app0.raiden.default_registry.address, token_address, [channel_state.identifier], app0.raiden.alarm.wait_time, ) expected_balance0 = initial_balance0 + deposit - amount expected_balance1 = initial_balance1 + deposit + amount assert token_proxy.balance_of(app0.raiden.address) == expected_balance0 assert token_proxy.balance_of(app1.raiden.address) == expected_balance1
def sign_and_inject(message, key, address, app): """Sign the message with key and inject it directly in the app protocol layer.""" message.sign(key, address) on_udp_message(app.raiden, message)