當前位置: 首頁>>代碼示例>>Python>>正文


Python Control.connect方法代碼示例

本文整理匯總了Python中control.Control.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python Control.connect方法的具體用法?Python Control.connect怎麽用?Python Control.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在control.Control的用法示例。


在下文中一共展示了Control.connect方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: datagramReceived

# 需要導入模塊: from control import Control [as 別名]
# 或者: from control.Control import connect [as 別名]
    def datagramReceived(self, data, addr):
        """Event handler of receiving a UDP request.
        Verify the identity of the client and assign a Control
        to it if it is trusted.
        """
        logging.debug("received DNS request from %s:%d" % (addr[0], addr[1]))

        if not self.transmit:
            try:
                dnsq = dnslib.DNSRecord.parse(data)
                query_data = str(dnsq.q.qname).split('.')
                # Give a NXDOMAIN response
                self.answer(dnsq, addr)
            except KeyError:
                logging.info("Corrupt request")

        try:
            # One control corresponds to one client (with a unique SHA1)

            # TODO: get obfs level from query length

            if self.transmit:
                main_pw, client_sha1, number, tcp_port, remote_ip, certs_str, signature = \
                    self.parse_udp_msg_transmit(data)
            else:
                main_pw, client_sha1, number, tcp_port, remote_ip, certs_str, signature = \
                    self.parse_udp_msg(*query_data[:6])
            if (client_sha1 + main_pw) not in self.controls:
                cert = self.certs_db.query(client_sha1)
                control = Control(self, signature, client_sha1, cert[0], cert[1],
                                  remote_ip, tcp_port,
                                  main_pw, number, certs_str)
                self.controls[client_sha1 + main_pw] = control
            else:
                control = self.controls[client_sha1 + main_pw]
                control.update(remote_ip, tcp_port, number)

            control.connect()

        except CorruptedReq:
            logging.debug("corrupt request")
        except KeyError:
            logging.warning("untrusted client attempting to connect")
        except AssertionError:
            logging.debug("authentication failed or corrupt request")
        except BlacklistReq:
            logging.debug("request or salt on blacklist")
        except IllegalReq:
            logging.debug("request for too many connections")
開發者ID:projectarkc,項目名稱:arkc-server,代碼行數:51,代碼來源:coordinator.py

示例2: datagramReceived

# 需要導入模塊: from control import Control [as 別名]
# 或者: from control.Control import connect [as 別名]
    def datagramReceived(self, data, addr):
        """Event handler of receiving a UDP request.
        Verify the identity of the client and assign a Control
        to it if it is trusted.
        """
        logging.debug("received DNS request from %s:%d" % (addr[0], addr[1]))
        try:
            dnsq = dnslib.DNSRecord.parse(data)
            query_data = str(dnsq.q.qname).split('.')
            # Give a NXDOMAIN response
            self.answer(dnsq, addr)
        except KeyError:
            logging.info("Corrupt request")

        try:
            # One control corresponds to one client (with a unique SHA1)

            # TODO: get obfs level from query length

            main_pw, client_sha1, number, tcp_port, remote_ip, certs_str = \
                self.parse_udp_msg(*query_data[:6])
            if client_sha1 is None:
                raise DuplicateError
            if client_sha1 not in self.controls:
                client_pub = self.certs[client_sha1][0]
                control = Control(self, client_pub, self.certs[client_sha1][1],
                                  remote_ip, tcp_port,
                                  main_pw, number, certs_str)
                self.controls[client_sha1] = control
            else:
                control = self.controls[client_sha1]
                control.update(remote_ip, tcp_port, main_pw, number)

            control.connect()

        except CorruptedReq:
            logging.info("Corrupt request")
        except KeyError:
            logging.error("untrusted client")
        except AssertionError:
            logging.error("authentication failed or corrupt request")
        except ClientAddrChanged:
            logging.error("client address or port changed")
開發者ID:CheckMySoul,項目名稱:arkc-server,代碼行數:45,代碼來源:coordinator.py


注:本文中的control.Control.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。