コード例 #1
0
ファイル: peermgr.py プロジェクト: ldh1428a/LogChain
    def run(self):
        while True:
            rcvd_data = self.rcvddata_q.get()
            request_sock = self.socket_q.get()
            socketip = self.socketip_q.get()

            # Assuming the format of the incoming message is json
            rcvd_data_json = json.loads(rcvd_data)
            peerid = rcvd_data_json['ID']
            monitoring.log("log.The ID of ConnectedPeer: " + peerid)
            monitoring.log("log.The IP of ConnectedPeer: " + socketip)

            if peerid in self.peer_list:
                monitoring.log("log.Add new peer's IP to ConnectedPeerList.")
                nodeproperty.ConnectedPeerList.append([peerid, socketip])
                nodeproperty.ConnectedPeerList.sort()
                request_sock.close()


                connected_peer_list_json = json.dumps(
                    nodeproperty.ConnectedPeerList, indent=4, default=lambda o: o.__dict__, sort_keys=True)
                monitoring.log("log.Updated ConnectedPeerList(json format): "+connected_peer_list_json)
                sender.send_to_all_peers_except_itself(connected_peer_list_json, peerconnector_Port)

                set_peer.set_my_peer_num()
                set_peer.set_total_peer_num()


                monitoring.add_peer(peerid, socketip, getPeerIconfilename(peerid))

            else:
                request_sock.close()
                # If there is no ID in the peer list, ignore it.
                monitoring.log("log.Ignore it because there is no corresponding ID in the predefined list.")
コード例 #2
0
def initialize_process_for_trust_peer():
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
    monitoring.log("log.Start Logchain launcher for TrustPeer...")

    # monitoring.add_peer('producer', 'producer a', 'producer.png')
    # monitoring.log('add_peer.producer.producer abc')
    monitoring.add_peer('package', 'sdfsdf', 'package.png')
    #
    # monitoring.add_peer('delivery', 'sadfsad', 'delivery.png')
    # monitoring.add_peer('delivery', 'sdfsdf', 'delivery.png')
    # monitoring.add_peer('seller', 'seller ff', 'seller.png')

    initialize()
    monitoring.log('log.Run threads for PeerMgr.')
    if not peermgr.start_peermgr():
        monitoring.log("log.Aborted because PeerMgr execution failed.")
        return

    set_peer.set_my_peer_num()
    monitoring.log("log.My peer num: " + str(nodeproperty.My_peer_num))

    'Genesis Block Create'
    genesisblock.genesisblock_generate()

    monitoring.log("log.Start a thread to receive messages from other peers.")

    recv_thread = receiver.ReceiverThread(
        1, "RECEIVER", nodeproperty.My_IP_address, nodeproperty.My_receiver_port)
    recv_thread.start()
    monitoring.log(
        "log.The thread for receiving messages from other peers has started.")

    t_type_qt = t_type_queue_thread.TransactionTypeQueueThread(
        1, "TransactionTypeQueueThread",
        dispatch_queue_list.T_type_q
    )
    t_type_qt.start()

    v_type_qt = v_type_queue_thread.VotingTypeQueueThread(
        1, "VotingTypeQueueThread",
        dispatch_queue_list.V_type_q
    )
    v_type_qt.start()

    b_type_qt = b_type_queue_thread.BlockTypeQueueThread(
        1, "BlockTypeQueueThread",
        dispatch_queue_list.B_type_q
    )
    b_type_qt.start()