def on_contract(self, messages):
        for message in messages:
            contract = Contract.from_dict(message.payload.dictionary['contract'])
            if contract is None:
                self.logger.warning('Dropping invalid contract from %s', message.candidate.sock_addr)
                continue
            elif self.incoming_contracts.get(contract.id) or self.data_manager.get_contract(contract.id):
                self.logger.debug('Dropping contract %s (duplicate)', b64encode(contract.id))
                continue

            # Preliminary check to see if contract is allowed. A final check will be performed in check_block.
            if not self.check_contract(contract, fail_without_parent=False):
                self.logger.warning('Dropping contract %s (check failed)', b64encode(contract.id))
                continue

            self.logger.debug('Got contract %s', b64encode(contract.id))

            # Forward if needed
            if contract.id not in self.incoming_contracts:
                self.incoming_contracts[contract.id] = contract
                self.multicast_message(u'contract', {'contract': contract.to_dict()}, exclude=message.candidate)