Пример #1
0
def receive_event(p_thrd_name, p_inq, p_socketq):
    transaction_count = 0
    while True:
        logging.debug("Waiting for T type msg.")
        recv_data = p_inq.get()
        request_sock = p_socketq.get()

        logging.debug("Transaction received")
        transaction_count = transaction_count + 1
        # print(transaction_count)

        file_controller.add_transaction(recv_data)
        logging.debug("Transaction added to mempool: " + recv_data)

        # transaction_count = len(file_controller.get_transaction_list())
        # print(transaction_count)
        if transaction_count == 30:
            #print ("Enter transaciotn count")
            difficulty = 0

            transaction.Transactions = file_controller.get_transaction_list()

            merkle = merkle_tree.MerkleTree()
            transaction.Merkle_root = merkle.get_merkle(
                transaction.Transactions)
            logging.debug("Transaction list Merkle _root: " +
                          transaction.Merkle_root)

            'blind voting'
            logging.debug("Start blind voting")
            voting.blind_voting(transaction.Merkle_root)
            logging.debug("End voting")
            '''
            time.sleep(5)

            difficulty = voting.result_voting()

            file_controller.remove_all_voting()
            if(difficulty > 0):
                block_generator.generate_block(
                    difficulty, merkle_root, transactions)
            else :
                print("Wait block")


            file_controller.remove_all_transactions()
            '''
            transaction_count = 0

        request_sock.close()
Пример #2
0
def receive_event(p_thrd_name, p_inq):
    transaction_count = 0
    while True:
        monitoring.log("log.Waiting for T type msg.")
        (recv_data, request_sock) = p_inq.get()
        # request_sock = p_socketq.get()

        # recv_data = p_inq.get()
        # request_sock = p_socketq.get()
        Data_jobj = json.loads(recv_data)
        monitoring.log("log.T type msg rcvd: " + recv_data)
        monitoring.log("log.T Type - " + Data_jobj['type'])
        transaction_count = transaction_count + 1

        file_controller.add_transaction(recv_data)
        monitoring.log("log.Transaction added to transaction pool: " +
                       recv_data)

        if (transaction_count == voting.TransactionCountForConsensus) or (
                Data_jobj['type'] == 'CT') or (Data_jobj['type'] == 'RT'):
            # difficulty = 0

            transaction.Transactions = file_controller.get_transaction_list()
            print(transaction.Transactions)
            merkle = merkle_tree.MerkleTree()
            transaction.Merkle_root = merkle.get_merkle(
                transaction.Transactions)
            monitoring.log("log.Transaction list Merkle _root: " +
                           transaction.Merkle_root)

            monitoring.log("log.Start blind voting")
            voting.blind_voting(transaction.Merkle_root)
            monitoring.log("log.End voting")

            transaction_count = 0

        request_sock.close()
Пример #3
0
def receive_event(p_thrd_name, p_inq):
    transaction_count = 0
    while True:
        monitoring.log("log.Waiting for T type msg.")
        (recv_data, request_sock) = p_inq.get()
        # request_sock = p_socketq.get()

        # recv_data = p_inq.get()
        # request_sock = p_socketq.get()
        Data_jobj = json.loads(recv_data)
        monitoring.log("log.T type msg rcvd: " + recv_data)
        monitoring.log("log.T Type - " + Data_jobj['type'])

        monitoring.log("log.T Type from ip " + Data_jobj['sender_ip'])

        myip = nodeproperty.My_IP_address

        if Data_jobj['sender_ip'] == myip:
            monitoring.log("transaction." + '<span style = "color:#ff0000;">' +
                           '.' + recv_data + '.' + '</span>')
        else:
            monitoring.log("transaction." + recv_data)

        transaction_count = transaction_count + 1

        file_controller.add_transaction(recv_data)

        monitoring.log("log.Transaction added to transaction pool: " +
                       recv_data)

        if (transaction_count == voting.TransactionCountForConsensus) or (
                Data_jobj['type'] == 'CT') or (Data_jobj['type'] == 'RT'):
            # difficulty = 0

            transaction.Transactions = file_controller.get_transaction_list()

            merkle = merkle_tree.MerkleTree()
            transaction.Merkle_root = merkle.get_merkle(
                transaction.Transactions)
            monitoring.log("log.Transaction list Merkle _root: " +
                           transaction.Merkle_root)

            monitoring.log("log.Start blind voting")
            voting.blind_voting(transaction.Merkle_root)
            monitoring.log("log.End voting")

            # # try
            # file_controller.remove_all_transactions()
            # file_controller.remove_all_voting()
            # # try
            '''
            time.sleep(5)

            difficulty = voting.result_voting()

            file_controller.remove_all_voting()
            if(difficulty > 0):
                block_generator.generate_block(
                    difficulty, merkle_root, transactions)
            else :
                print("Wait block")


            file_controller.remove_all_transactions()
            '''
            transaction_count = 0
            monitoring.log('reset.Reset All transaction Items')

        request_sock.close()