예제 #1
0
def receive_event(p_thrd_name, p_inq):
    total_tx_count = 1
    while True:
        monitoring.log("log.Wait for transaction creation request.")

        dequeued = p_inq.get()

        tx = transaction.Transaction(dequeued)
        # temp = json.dumps(
        #     tx, indent=4, default=lambda o: o.__dict__, sort_keys=True)

        # for try
        temp = json.dumps(tx, default=lambda o: o.__dict__, sort_keys=True)

        # sender.send_to_all(temp)
        sender.send_to_all_peers(temp, nodeproperty.My_receiver_port)

        monitoring.log("log.Transaction creation request - rcvd: " +
                       str(dequeued))
        monitoring.log("log.Transaction creation request - rcvd(json): " +
                       str(temp))
        monitoring.log("log.Total number of transaction creation request: " +
                       str(total_tx_count))
        # monitoring.log("log."+str(p_inq.qsize()))
        total_tx_count = total_tx_count + 1
def receive_event(p_thrd_name, p_inq):
    total_tx_count = 1
    while True:
        monitoring.log("log.Waiting the request for contract deployment.")
        (restapi_request_json, restapi_request_ip) = p_inq.get()

        tx = transaction.Transaction('CT', restapi_request_ip,
                                     restapi_request_json)
        # temp = json.dumps(
        #     tx, indent=4, default=lambda o: o.__dict__, sort_keys=True)

        # for try
        temp = json.dumps(tx, default=lambda o: o.__dict__, sort_keys=True)

        # sender.send_to_all(temp)
        sender.send_to_all_peers(temp, nodeproperty.My_receiver_port)

        monitoring.log("log.Contract Deployment request - rcvd: " +
                       str(restapi_request_json))
        monitoring.log("log.Contract Deployment request - rcvd(json): " +
                       str(temp))
        monitoring.log("log.Total number of Contract Deployment request: " +
                       str(total_tx_count))
        # monitoring.log("log."+str(p_inq.qsize()))
        total_tx_count = total_tx_count + 1
예제 #3
0
def receive_event(p_thrd_name, p_inq):
    count = 1
    while True:
        logging.debug("waiting for event")

        dequeued = p_inq.get()

        tx = transaction.Transaction(dequeued)
        temp = json.dumps(
            tx, indent=4, default=lambda o: o.__dict__, sort_keys=True)

        sender.send_to_all(temp)  # 노드들 연동 후 테스트 필요 2017-09-27

        logging.debug(str(dequeued))
        logging.debug(str(temp))

        logging.debug(count)
        logging.debug(str(p_inq.qsize()))
        count = count + 1
        time.sleep(queue_strategy.SAVE_TX_DEQUEUE_INTERVAL)
예제 #4
0
def main():
    'Remove all transaction in mempool'
    file_controller.remove_all_transactions()
    # file_controller.remove_all_Block()
    file_controller.remove_all_voting()

    print("Web Server Start")

    'Peer setting'
    nodeproperty.My_IP_address = file_controller.get_my_ip()
    set_peer.set_peer()
    print("my peer : " + nodeproperty.My_peer_num)

    # node_mapping_table.set_node()와 set_peer()는 중복 기능이나, 일단 디버깅용으로 중복으로 유지함
    node_mapping_table.set_node()

    'Send to all node 10 transaction for one iteration'

    while True:
        transaction_count = 0
        # socket open

        while transaction_count < 30:
            # recv_addr = "1AVsffe"
            extra = "Coldchain service rule event"
            tx = transaction.Transaction(extra, transaction_count + 1)
            temp = json.dumps(tx,
                              indent=4,
                              default=lambda o: o.__dict__,
                              sort_keys=True)

            # send_to_all은 mapping table에 있는 정보로 broadcasting
            # send_to_all_node는 file_controller로 부터 IP List 가지고 와서 broadcasting
            # 테스트 후에 안전한 방식으로 선택
            sender.send_to_all(temp)
            #sender.send_to_all_node(temps, nodeproperty.my_ip_address, nodeproperty.port)

            transaction_count += 1

        'For block mining, time sleep'
        time.sleep(120)