예제 #1
0
    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()

            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 run(self):
        while True:
            rcvd_data = self.rcvddata_q.get()
            request_sock = self.socket_q.get()

            # Assuming the format of the incoming message is json
            rcvd_list = json.loads(rcvd_data)

            monitoring.log("log.Received ConnectedPeerList: " + rcvd_data)

            request_sock.close()

            nodeproperty.ConnectedPeerList = rcvd_list
            set_peer.set_my_peer_num()
            set_peer.set_total_peer_num()