When a message with an already known traversal_id is received,
        we try to build a duplication message and send it in to a protocol
        dependent recipient. This is used in contracts traversing
        the graph, when the contract has reached again the same shard.
        This message is necessary, as silently ignoring the incoming bids
        adds a lot of latency to the nested contracts (it is waiting to receive
        message from all the recipients).

def on_message(self, msg):
        '''
        When a message with an already known traversal_id is received,
        we try to build a duplication message and send it in to a protocol
        dependent recipient. This is used in contracts traversing
        the graph, when the contract has reached again the same shard.
        This message is necessary, as silently ignoring the incoming bids
        adds a lot of latency to the nested contracts (it is waiting to receive
        message from all the recipients).
        '''
        self.log('Received message: %r', msg)

        # Check if it isn't expired message
        time_left = time.left(msg.expiration_time)
        if time_left < 0:
            self.log('Throwing away expired message. Time left: %s, '
                     'msg_class: %r', time_left, msg.get_msg_class())
            return False

        # Check for duplicated message
        if msg.message_id in self._message_ids:
            self.log("Throwing away duplicated message %r",
                     msg.get_msg_class())
            return False
        else:
            self._message_ids.set(msg.message_id, True, msg.expiration_time)

        # Check for known traversal ids:
        if IFirstMessage.providedBy(msg):
            t_id = msg.traversal_id
            if t_id is None:
                self.warning(
                    "Received corrupted message. The traversal_id is None ! "
                    "Message: %r", msg)
                return False
            if t_id in self._traversal_ids:
                self.log('Throwing away already known traversal id %r, '
                         'msg_class: %r', t_id, msg.get_msg_class())
                recp = msg.duplication_recipient()
                if recp:
                    resp = msg.duplication_message()
                    self.post(recp, resp)
                return False
            else:
                self._traversal_ids.set(t_id, True, msg.expiration_time)

        # Handle registered dialog
        if IDialogMessage.providedBy(msg):
            recv_id = msg.receiver_id
            if recv_id is not None and \
               recv_id in self._agency_agent._protocols:
                protocol = self._agency_agent._protocols[recv_id]
                protocol.on_message(msg)
                return True

        # Handle new conversation coming in (interest)
        # if msg.protocol_id == 'alert':
        #     print self._agency_agent._interests
        p_type = msg.protocol_type
        if p_type in self._agency_agent._interests:
            p_id = msg.protocol_id
            interest = self._agency_agent._interests[p_type].get(p_id)
            if interest and interest.schedule_message(msg):
                return True

        self.debug("Couldn't find appropriate protocol for message: "
                   "%s", msg.get_msg_class())
        return False