当前位置: 首页>>代码示例>>Python>>正文


Python Protocol.start方法代码示例

本文整理汇总了Python中xpra.net.protocol.Protocol.start方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.start方法的具体用法?Python Protocol.start怎么用?Python Protocol.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xpra.net.protocol.Protocol的用法示例。


在下文中一共展示了Protocol.start方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_protocol

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
 def make_protocol(self, socktype, conn, frominfo=""):
     netlog.info("New %s connection received%s", socktype, frominfo)
     protocol = Protocol(self, conn, self.process_packet)
     self._potential_protocols.append(protocol)
     protocol.large_packets.append("info-response")
     protocol.challenge_sent = False
     protocol.authenticator = None
     if socktype=="tcp":
         protocol.auth_class = self.tcp_auth_class
         protocol.encryption = self.tcp_encryption
         protocol.keyfile = self.tcp_encryption_keyfile
     elif socktype=="vsock":
         protocol.auth_class = self.vsock_auth_class
         protocol.encryption = None
         protocol.keyfile = None
     else:
         protocol.auth_class = self.auth_class
         protocol.encryption = self.encryption
         protocol.keyfile = self.encryption_keyfile
     protocol.socket_type = socktype
     protocol.invalid_header = self.invalid_header
     protocol.receive_aliases.update(self._aliases)
     authlog("socktype=%s, auth class=%s, encryption=%s, keyfile=%s", socktype, protocol.auth_class, protocol.encryption, protocol.keyfile)
     if protocol.encryption and ENCRYPT_FIRST_PACKET:
         password = self.get_encryption_key(None, protocol.keyfile)
         protocol.set_cipher_in(protocol.encryption, DEFAULT_IV, password, DEFAULT_SALT, DEFAULT_ITERATIONS, INITIAL_PADDING)
     protocol.start()
     self.timeout_add(SOCKET_TIMEOUT*1000, self.verify_connection_accepted, protocol)
     return True
开发者ID:ljmljz,项目名称:xpra,代码行数:31,代码来源:server_core.py

示例2: SimpleClient

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
class SimpleClient(object):

    def init(self, exit_cb, packets=[]):
        self.packets = packets
        sock = socket.socket(socket.AF_UNIX)
        sock.settimeout(5)
        sock.connect(TEST_SOCKFILE)
        sock.settimeout(None)
        sc = makeSocketConnection(sock, "test-client-socket")
        self.protocol = Protocol(gobject, sc, self.process_packet, None)
        self.protocol.start()
        if len(self.packets)>0:
            gobject.timeout_add(1000, self.send_packet)

    def send_packet(self):
        self.protocol.send_now(self.packets[0])
        self.packets = self.packets[1:]
        return len(self.packets)>0

    def process_packet(self, proto, packet):
        log.info("process_packet(%s, %s)", proto, packet)

    def get_packet(self, *args):
        log.info("get_packet(%s)", args)
        return None
开发者ID:svn2github,项目名称:Xpra,代码行数:27,代码来源:test_protocol_base.py

示例3: _new_connection

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
 def _new_connection(self, listener, *args):
     socktype = self.socket_types.get(listener, "")
     sock, address = listener.accept()
     if len(self._potential_protocols)>=self._max_connections:
         log.error("too many connections (%s), ignoring new one", len(self._potential_protocols))
         sock.close()
         return  True
     try:
         peername = sock.getpeername()
     except:
         peername = str(address)
     sockname = sock.getsockname()
     target = peername or sockname
     sock.settimeout(self._socket_timeout)
     log("new_connection(%s) sock=%s, sockname=%s, address=%s, peername=%s", args, sock, sockname, address, peername)
     sc = SocketConnection(sock, sockname, address, target, socktype)
     log.info("New connection received: %s", sc)
     protocol = Protocol(self, sc, self.process_packet)
     protocol.large_packets.append("info-response")
     protocol.authenticator = None
     protocol.invalid_header = self.invalid_header
     protocol.receive_aliases.update(self._aliases)
     self._potential_protocols.append(protocol)
     protocol.start()
     self.timeout_add(SOCKET_TIMEOUT*1000, self.verify_connection_accepted, protocol)
     return True
开发者ID:Brainiarc7,项目名称:xpra,代码行数:28,代码来源:server_core.py

示例4: new_connection

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
 def new_connection(self, *args):
     log.info("new_connection(%s)", args)
     sock, address = self.listener.accept()
     log.info("new_connection(%s) sock=%s, address=%s", args, sock, address)
     sock.settimeout(None)
     sock.setblocking(1)
     sc = makeSocketConnection(sock, str(address)+"server")
     protocol = Protocol(gobject, sc, self.process_packet)
     protocol.salt = None
     protocol.set_compression_level(1)
     protocol.start()
     return True
开发者ID:svn2github,项目名称:Xpra,代码行数:14,代码来源:test_protocol_base.py

示例5: _new_connection

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
 def _new_connection(self, listener, *args):
     if self._closing:
         netlog.warn("ignoring new connection during shutdown")
         return False
     socktype = self.socket_types.get(listener)
     assert socktype, "cannot find socket type for %s" % listener
     sock, address = listener.accept()
     if len(self._potential_protocols)>=self._max_connections:
         netlog.error("too many connections (%s), ignoring new one", len(self._potential_protocols))
         sock.close()
         return True
     try:
         peername = sock.getpeername()
     except:
         peername = str(address)
     sockname = sock.getsockname()
     target = peername or sockname
     sock.settimeout(self._socket_timeout)
     netlog("new_connection(%s) sock=%s, timeout=%s, sockname=%s, address=%s, peername=%s", args, sock, self._socket_timeout, sockname, address, peername)
     sc = SocketConnection(sock, sockname, address, target, socktype)
     netlog("socket connection: %s", sc)
     frominfo = ""
     if peername:
         frominfo = " from %s" % pretty_socket(peername)
     elif socktype=="unix-domain":
         frominfo = " on %s" % sockname
     netlog.info("New %s connection received%s", socktype, frominfo)
     protocol = Protocol(self, sc, self.process_packet)
     self._potential_protocols.append(protocol)
     protocol.large_packets.append("info-response")
     protocol.challenge_sent = False
     protocol.authenticator = None
     if socktype=="tcp":
         protocol.auth_class = self.tcp_auth_class
         protocol.encryption = self.tcp_encryption
         protocol.keyfile = self.tcp_encryption_keyfile
     else:
         protocol.auth_class = self.auth_class
         protocol.encryption = self.encryption
         protocol.keyfile = self.encryption_keyfile
     protocol.socket_type = socktype
     protocol.invalid_header = self.invalid_header
     protocol.receive_aliases.update(self._aliases)
     authlog("socktype=%s, auth class=%s, encryption=%s, keyfile=%s", socktype, protocol.auth_class, protocol.encryption, protocol.keyfile)
     if protocol.encryption and ENCRYPT_FIRST_PACKET:
         password = self.get_encryption_key(None, protocol.keyfile)
         protocol.set_cipher_in(protocol.encryption, DEFAULT_IV, password, DEFAULT_SALT, DEFAULT_ITERATIONS, INITIAL_PADDING)
     protocol.start()
     self.timeout_add(SOCKET_TIMEOUT*1000, self.verify_connection_accepted, protocol)
     return True
开发者ID:svn2github,项目名称:Xpra,代码行数:52,代码来源:server_core.py

示例6: _new_connection

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
 def _new_connection(self, listener, *args):
     socktype = self.socket_types.get(listener)
     assert socktype, "cannot find socket type for %s" % listener
     sock, address = listener.accept()
     if len(self._potential_protocols) >= self._max_connections:
         netlog.error("too many connections (%s), ignoring new one", len(self._potential_protocols))
         sock.close()
         return True
     try:
         peername = sock.getpeername()
     except:
         peername = str(address)
     sockname = sock.getsockname()
     target = peername or sockname
     sock.settimeout(self._socket_timeout)
     netlog(
         "new_connection(%s) sock=%s, timeout=%s, sockname=%s, address=%s, peername=%s",
         args,
         sock,
         self._socket_timeout,
         sockname,
         address,
         peername,
     )
     sc = SocketConnection(sock, sockname, address, target, socktype)
     netlog("socket connection: %s", sc)
     frominfo = ""
     if peername:
         frominfo = " from %s" % str(peername)
     netlog.info("New %s connection received%s", socktype, frominfo)
     protocol = Protocol(self, sc, self.process_packet)
     self._potential_protocols.append(protocol)
     protocol.large_packets.append("info-response")
     protocol.challenge_sent = False
     protocol.authenticator = None
     if socktype == "tcp":
         protocol.auth_class = self.tcp_auth_class
     else:
         protocol.auth_class = self.auth_class
     protocol.socket_type = socktype
     protocol.invalid_header = self.invalid_header
     protocol.receive_aliases.update(self._aliases)
     protocol.start()
     self.timeout_add(SOCKET_TIMEOUT * 1000, self.verify_connection_accepted, protocol)
     return True
开发者ID:svn2github,项目名称:Xpra,代码行数:47,代码来源:server_core.py

示例7: new_control_connection

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
 def new_control_connection(self, sock, address):
     if len(self.potential_protocols)>=self.max_connections:
         log.error("too many connections (%s), ignoring new one", len(self.potential_protocols))
         sock.close()
         return  True
     try:
         peername = sock.getpeername()
     except:
         peername = str(address)
     sockname = sock.getsockname()
     target = peername or sockname
     #sock.settimeout(0)
     log("new_control_connection() sock=%s, sockname=%s, address=%s, peername=%s", sock, sockname, address, peername)
     sc = SocketConnection(sock, sockname, address, target, "unix-domain")
     log.info("New proxy instance control connection received: %s", sc)
     protocol = Protocol(self, sc, self.process_control_packet)
     protocol.large_packets.append("info-response")
     self.potential_protocols.append(protocol)
     protocol.start()
     self.timeout_add(SOCKET_TIMEOUT*1000, self.verify_connection_accepted, protocol)
     return True
开发者ID:svn2github,项目名称:Xpra,代码行数:23,代码来源:proxy_instance_process.py

示例8: XpraClientBase

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]

#.........这里部分代码省略.........
    def exit(self):
        sys.exit()


    def client_type(self):
        #overriden in subclasses!
        return "Python"

    def get_scheduler(self):
        raise NotImplementedError()

    def setup_connection(self, conn):
        log("setup_connection(%s)", conn)
        self._protocol = Protocol(self.get_scheduler(), conn, self.process_packet, self.next_packet)
        self._protocol.large_packets.append("keymap-changed")
        self._protocol.large_packets.append("server-settings")
        self._protocol.large_packets.append("logging")
        self._protocol.set_compression_level(self.compression_level)
        self._protocol.receive_aliases.update(self._aliases)
        self._protocol.enable_default_encoder()
        self._protocol.enable_default_compressor()
        self.have_more = self._protocol.source_has_more
        if conn.timeout>0:
            self.timeout_add((conn.timeout + EXTRA_TIMEOUT) * 1000, self.verify_connected)

    def init_packet_handlers(self):
        self._packet_handlers = {
            "hello"             : self._process_hello,
            }
        self._ui_packet_handlers = {
            "challenge":                self._process_challenge,
            "disconnect":               self._process_disconnect,
            "set_deflate":              self._process_set_deflate,
            "startup-complete":         self._process_startup_complete,
            Protocol.CONNECTION_LOST:   self._process_connection_lost,
            Protocol.GIBBERISH:         self._process_gibberish,
            Protocol.INVALID:           self._process_invalid,
            }

    def init_authenticated_packet_handlers(self):
        self._packet_handlers["send-file"] = self._process_send_file


    def init_aliases(self):
        packet_types = list(self._packet_handlers.keys())
        packet_types += list(self._ui_packet_handlers.keys())
        i = 1
        for key in packet_types:
            self._aliases[i] = key
            self._reverse_aliases[key] = i
            i += 1

    def send_hello(self, challenge_response=None, client_salt=None):
        try:
            hello = self.make_hello_base()
            if (self.password_file or os.environ.get('XPRA_PASSWORD')) and not challenge_response:
                #avoid sending the full hello: tell the server we want
                #a packet challenge first
                hello["challenge"] = True
            else:
                hello.update(self.make_hello())
        except Exception as e:
            log.error("error preparing connection: %s", e, exc_info=True)
            self.quit(EXIT_INTERNAL_ERROR)
            return
        if challenge_response:
开发者ID:svn2github,项目名称:Xpra,代码行数:70,代码来源:client_base.py

示例9: ProxyInstanceProcess

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
class ProxyInstanceProcess(Process):

    def __init__(self, uid, gid, env_options, session_options, client_conn, client_state, cipher, encryption_key, server_conn, caps, message_queue):
        Process.__init__(self, name=str(client_conn))
        self.uid = uid
        self.gid = gid
        self.env_options = env_options
        self.session_options = self.sanitize_session_options(session_options)
        self.client_conn = client_conn
        self.client_state = client_state
        self.cipher = cipher
        self.encryption_key = encryption_key
        self.server_conn = server_conn
        self.caps = caps
        debug("ProxyProcess%s", (uid, gid, client_conn, client_state, cipher, encryption_key, server_conn, "{..}"))
        self.client_protocol = None
        self.server_protocol = None
        self.main_queue = None
        self.message_queue = message_queue
        self.video_encoder_types = ["nvenc", "x264"]
        self.video_encoders = {}
        self.video_helper = None

    def server_message_queue(self):
        while True:
            log.info("waiting for server message on %s", self.message_queue)
            m = self.message_queue.get()
            log.info("proxy server message: %s", m)
            if m=="stop":
                self.stop("proxy server request")
                return

    def signal_quit(self, signum, frame):
        log.info("")
        log.info("proxy process pid %s got signal %s, exiting", os.getpid(), SIGNAMES.get(signum, signum))
        signal.signal(signal.SIGINT, deadly_signal)
        signal.signal(signal.SIGTERM, deadly_signal)
        self.stop(SIGNAMES.get(signum, signum))

    def idle_add(self, fn, *args, **kwargs):
        #we emulate gobject's idle_add using a simple queue
        self.main_queue.put((fn, args, kwargs))

    def timeout_add(self, timeout, fn, *args, **kwargs):
        #emulate gobject's timeout_add using idle add and a Timer
        #using custom functions to cancel() the timer when needed
        timer = None
        def idle_exec():
            v = fn(*args, **kwargs)
            if not bool(v):
                timer.cancel()
            return False
        def timer_exec():
            #just run via idle_add:
            self.idle_add(idle_exec)
        timer = Timer(timeout*1000.0, timer_exec)
        timer.start()

    def run(self):
        debug("ProxyProcess.run() pid=%s, uid=%s, gid=%s", os.getpid(), os.getuid(), os.getgid())
        #change uid and gid:
        if os.getgid()!=self.gid:
            os.setgid(self.gid)
        if os.getuid()!=self.uid:
            os.setuid(self.uid)
        debug("ProxyProcess.run() new uid=%s, gid=%s", os.getuid(), os.getgid())

        if self.env_options:
            #TODO: whitelist env update?
            os.environ.update(self.env_options)

        log.info("new proxy started for client %s and server %s", self.client_conn, self.server_conn)

        signal.signal(signal.SIGTERM, self.signal_quit)
        signal.signal(signal.SIGINT, self.signal_quit)
        debug("registered signal handler %s", self.signal_quit)

        make_daemon_thread(self.server_message_queue, "server message queue").start()

        self.main_queue = Queue()
        #setup protocol wrappers:
        self.server_packets = Queue(PROXY_QUEUE_SIZE)
        self.client_packets = Queue(PROXY_QUEUE_SIZE)
        self.client_protocol = Protocol(self, self.client_conn, self.process_client_packet, self.get_client_packet)
        self.client_protocol.restore_state(self.client_state)
        self.server_protocol = Protocol(self, self.server_conn, self.process_server_packet, self.get_server_packet)
        #server connection tweaks:
        self.server_protocol.large_packets.append("draw")
        self.server_protocol.large_packets.append("keymap-changed")
        self.server_protocol.large_packets.append("server-settings")
        self.server_protocol.set_compression_level(self.session_options.get("compression_level", 0))

        debug("starting network threads")
        self.server_protocol.start()
        self.client_protocol.start()

        #forward the hello packet:
        hello_packet = ("hello", self.filter_client_caps(self.caps))
        self.queue_server_packet(hello_packet)

#.........这里部分代码省略.........
开发者ID:Brainiarc7,项目名称:xpra,代码行数:103,代码来源:proxy_instance_process.py

示例10: ProxyInstanceProcess

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
class ProxyInstanceProcess(Process):

    def __init__(self, uid, gid, env_options, session_options, socket_dir,
                 video_encoder_modules, csc_modules,
                 client_conn, client_state, cipher, encryption_key, server_conn, caps, message_queue):
        Process.__init__(self, name=str(client_conn))
        self.uid = uid
        self.gid = gid
        self.env_options = env_options
        self.session_options = self.sanitize_session_options(session_options)
        self.socket_dir = socket_dir
        self.video_encoder_modules = video_encoder_modules
        self.csc_modules = csc_modules
        self.client_conn = client_conn
        self.client_state = client_state
        self.cipher = cipher
        self.encryption_key = encryption_key
        self.server_conn = server_conn
        self.caps = caps
        log("ProxyProcess%s", (uid, gid, client_conn, client_state, cipher, encryption_key, server_conn, "{..}"))
        self.client_protocol = None
        self.server_protocol = None
        self.exit = False
        self.main_queue = None
        self.message_queue = message_queue
        self.encode_queue = None            #holds draw packets to encode
        self.encode_thread = None
        self.video_encoding_defs = None
        self.video_encoders = None
        self.video_encoders_last_used_time = None
        self.video_encoder_types = None
        self.video_helper = None
        self.lost_windows = None
        #for handling the local unix domain socket:
        self.control_socket = None
        self.control_socket_thread = None
        self.control_socket_path = None
        self.potential_protocols = []
        self.max_connections = MAX_CONCURRENT_CONNECTIONS

    def server_message_queue(self):
        while True:
            log("waiting for server message on %s", self.message_queue)
            m = self.message_queue.get()
            log.info("proxy server message: %s", m)
            if m=="stop":
                self.stop("proxy server request")
                return

    def signal_quit(self, signum, frame):
        log.info("")
        log.info("proxy process pid %s got signal %s, exiting", os.getpid(), SIGNAMES.get(signum, signum))
        self.exit = True
        signal.signal(signal.SIGINT, deadly_signal)
        signal.signal(signal.SIGTERM, deadly_signal)
        self.stop(SIGNAMES.get(signum, signum))

    def idle_add(self, fn, *args, **kwargs):
        #we emulate gobject's idle_add using a simple queue
        self.main_queue.put((fn, args, kwargs))

    def timeout_add(self, timeout, fn, *args, **kwargs):
        #emulate gobject's timeout_add using idle add and a Timer
        #using custom functions to cancel() the timer when needed
        def idle_exec():
            v = fn(*args, **kwargs)
            if bool(v):
                self.timeout_add(timeout, fn, *args, **kwargs)
            return False
        def timer_exec():
            #just run via idle_add:
            self.idle_add(idle_exec)
        Timer(timeout/1000.0, timer_exec).start()

    def run(self):
        log("ProxyProcess.run() pid=%s, uid=%s, gid=%s", os.getpid(), os.getuid(), os.getgid())
        #change uid and gid:
        if os.getgid()!=self.gid:
            os.setgid(self.gid)
        if os.getuid()!=self.uid:
            os.setuid(self.uid)
        log("ProxyProcess.run() new uid=%s, gid=%s", os.getuid(), os.getgid())

        if self.env_options:
            #TODO: whitelist env update?
            os.environ.update(self.env_options)
        self.video_init()

        log.info("new proxy started for client %s and server %s", self.client_conn, self.server_conn)

        signal.signal(signal.SIGTERM, self.signal_quit)
        signal.signal(signal.SIGINT, self.signal_quit)
        log("registered signal handler %s", self.signal_quit)

        make_daemon_thread(self.server_message_queue, "server message queue").start()

        if self.create_control_socket():
            self.control_socket_thread = make_daemon_thread(self.control_socket_loop, "control")
            self.control_socket_thread.start()

#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Xpra,代码行数:103,代码来源:proxy_instance_process.py

示例11: XpraClientBase

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]

#.........这里部分代码省略.........
                "namespace"             : True,
                "hostname"              : socket.gethostname(),
                "uuid"                  : self.uuid,
                "username"              : self.username,
                "name"                  : get_name(),
                "client_type"           : self.client_type(),
                "python.version"        : sys.version_info[:3],
                "compression_level"     : self.compression_level,
                })
        if self.display:
            capabilities["display"] = self.display
        capabilities.update(get_platform_info())
        add_version_info(capabilities)
        mid = get_machine_id()
        if mid:
            capabilities["machine_id"] = mid

        if self.encryption:
            assert self.encryption in ENCRYPTION_CIPHERS
            iv = get_hex_uuid()[:16]
            key_salt = get_hex_uuid()+get_hex_uuid()
            iterations = 1000
            capabilities.update({
                        "cipher"                       : self.encryption,
                        "cipher.iv"                    : iv,
                        "cipher.key_salt"              : key_salt,
                        "cipher.key_stretch_iterations": iterations,
                        })
            key = self.get_encryption_key()
            if key is None:
                self.warn_and_quit(EXIT_ENCRYPTION, "encryption key is missing")
                return
            self._protocol.set_cipher_in(self.encryption, iv, key, key_salt, iterations)
            log("encryption capabilities: %s", [(k,v) for k,v in capabilities.items() if k.startswith("cipher")])
        return capabilities

    def make_hello(self):
        capabilities = {
                        "randr_notify"        : False,        #only client.py cares about this
                        "windows"            : False,        #only client.py cares about this
                       }
        if self._reverse_aliases:
            capabilities["aliases"] = self._reverse_aliases
        return capabilities

    def send(self, *parts):
        self._ordinary_packets.append(parts)
        self.have_more()

    def send_now(self, *parts):
        self._priority_packets.append(parts)
        self.have_more()

    def send_positional(self, packet):
        self._ordinary_packets.append(packet)
        self._mouse_position = None
        self.have_more()

    def send_mouse_position(self, packet):
        self._mouse_position = packet
        self.have_more()

    def have_more(self):
        #this function is overridden in setup_protocol()
        p = self._protocol
        if p and p.source:
开发者ID:svn2github,项目名称:Xpra,代码行数:70,代码来源:client_base.py

示例12: XpraClientBase

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]

#.........这里部分代码省略.........
            self._protocol.set_cipher_out(self.encryption, DEFAULT_IV, key, DEFAULT_SALT, DEFAULT_ITERATIONS, INITIAL_PADDING)
        self.have_more = self._protocol.source_has_more
        if conn.timeout>0:
            self.timeout_add((conn.timeout + EXTRA_TIMEOUT) * 1000, self.verify_connected)
        netlog("setup_connection(%s) protocol=%s", conn, self._protocol)


    def remove_packet_handlers(self, *keys):
        for k in keys:
            for d in (self._packet_handlers, self._ui_packet_handlers):
                try:
                    del d[k]
                except:
                    pass

    def set_packet_handlers(self, to, defs):
        """ configures the given packet handlers,
            and make sure we remove any existing ones with the same key
            (which can be useful for subclasses, not here)
        """
        log("set_packet_handlers(%s, %s)", to, defs)
        self.remove_packet_handlers(*defs.keys())
        for k,v in defs.items():
            to[k] = v

    def init_packet_handlers(self):
        self._packet_handlers = {}
        self._ui_packet_handlers = {}
        self.set_packet_handlers(self._packet_handlers, {"hello" : self._process_hello})
        self.set_packet_handlers(self._ui_packet_handlers, {
            "challenge":                self._process_challenge,
            "disconnect":               self._process_disconnect,
            "set_deflate":              self._process_set_deflate,
            "startup-complete":         self._process_startup_complete,
            Protocol.CONNECTION_LOST:   self._process_connection_lost,
            Protocol.GIBBERISH:         self._process_gibberish,
            Protocol.INVALID:           self._process_invalid,
            })

    def init_authenticated_packet_handlers(self):
        self.set_packet_handlers(self._packet_handlers, {"send-file" : self._process_send_file})


    def init_aliases(self):
        packet_types = list(self._packet_handlers.keys())
        packet_types += list(self._ui_packet_handlers.keys())
        i = 1
        for key in packet_types:
            self._aliases[i] = key
            self._reverse_aliases[key] = i
            i += 1

    def has_password(self):
        return self.password_file or os.environ.get('XPRA_PASSWORD')

    def send_hello(self, challenge_response=None, client_salt=None):
        try:
            hello = self.make_hello_base()
            if self.has_password() and not challenge_response:
                #avoid sending the full hello: tell the server we want
                #a packet challenge first
                hello["challenge"] = True
            else:
                hello.update(self.make_hello())
        except InitExit as e:
            log.error("error preparing connection:")
开发者ID:ljmljz,项目名称:xpra,代码行数:70,代码来源:client_base.py

示例13: ProxyInstanceProcess

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]
class ProxyInstanceProcess(Process):

    def __init__(self, uid, gid, env_options, session_options, socket_dir,
                 video_encoder_modules, csc_modules,
                 client_conn, client_state, cipher, encryption_key, server_conn, caps, message_queue):
        Process.__init__(self, name=str(client_conn))
        self.uid = uid
        self.gid = gid
        self.env_options = env_options
        self.session_options = session_options
        self.socket_dir = socket_dir
        self.video_encoder_modules = video_encoder_modules
        self.csc_modules = csc_modules
        self.client_conn = client_conn
        self.client_state = client_state
        self.cipher = cipher
        self.encryption_key = encryption_key
        self.server_conn = server_conn
        self.caps = caps
        log("ProxyProcess%s", (uid, gid, env_options, session_options, socket_dir,
                               video_encoder_modules, csc_modules,
                               client_conn, repr_ellipsized(str(client_state)), cipher, encryption_key, server_conn,
                               "%s: %s.." % (type(caps), repr_ellipsized(str(caps))), message_queue))
        self.client_protocol = None
        self.server_protocol = None
        self.exit = False
        self.main_queue = None
        self.message_queue = message_queue
        self.encode_queue = None            #holds draw packets to encode
        self.encode_thread = None
        self.video_encoding_defs = None
        self.video_encoders = None
        self.video_encoders_last_used_time = None
        self.video_encoder_types = None
        self.video_helper = None
        self.lost_windows = None
        #for handling the local unix domain socket:
        self.control_socket_cleanup = None
        self.control_socket = None
        self.control_socket_thread = None
        self.control_socket_path = None
        self.potential_protocols = []
        self.max_connections = MAX_CONCURRENT_CONNECTIONS

    def server_message_queue(self):
        while True:
            log("waiting for server message on %s", self.message_queue)
            m = self.message_queue.get()
            log("received proxy server message: %s", m)
            if m=="stop":
                self.stop("proxy server request")
                return
            elif m=="socket-handover-complete":
                log("setting sockets to blocking mode: %s", (self.client_conn, self.server_conn))
                #set sockets to blocking mode:
                set_blocking(self.client_conn)
                set_blocking(self.server_conn)
            else:
                log.error("unexpected proxy server message: %s", m)

    def signal_quit(self, signum, frame):
        log.info("")
        log.info("proxy process pid %s got signal %s, exiting", os.getpid(), SIGNAMES.get(signum, signum))
        self.exit = True
        signal.signal(signal.SIGINT, deadly_signal)
        signal.signal(signal.SIGTERM, deadly_signal)
        self.stop(SIGNAMES.get(signum, signum))

    def idle_add(self, fn, *args, **kwargs):
        #we emulate gobject's idle_add using a simple queue
        self.main_queue.put((fn, args, kwargs))

    def timeout_add(self, timeout, fn, *args, **kwargs):
        #emulate gobject's timeout_add using idle add and a Timer
        #using custom functions to cancel() the timer when needed
        def idle_exec():
            v = fn(*args, **kwargs)
            if bool(v):
                self.timeout_add(timeout, fn, *args, **kwargs)
            return False
        def timer_exec():
            #just run via idle_add:
            self.idle_add(idle_exec)
        Timer(timeout/1000.0, timer_exec).start()

    def run(self):
        log("ProxyProcess.run() pid=%s, uid=%s, gid=%s", os.getpid(), getuid(), getgid())
        setuidgid(self.uid, self.gid)
        if self.env_options:
            #TODO: whitelist env update?
            os.environ.update(self.env_options)
        self.video_init()

        log.info("new proxy instance started")
        log.info(" for client %s", self.client_conn)
        log.info(" and server %s", self.server_conn)

        signal.signal(signal.SIGTERM, self.signal_quit)
        signal.signal(signal.SIGINT, self.signal_quit)
        log("registered signal handler %s", self.signal_quit)
#.........这里部分代码省略.........
开发者ID:svn2github,项目名称:Xpra,代码行数:103,代码来源:proxy_instance_process.py

示例14: XpraClientBase

# 需要导入模块: from xpra.net.protocol import Protocol [as 别名]
# 或者: from xpra.net.protocol.Protocol import start [as 别名]

#.........这里部分代码省略.........
            self._aliases[i] = key
            self._reverse_aliases[key] = i
            i += 1

    def send_hello(self, challenge_response=None):
        hello = self.make_hello(challenge_response)
        log.debug("send_hello(%s) packet=%s", challenge_response, hello)
        self.send("hello", hello)
        self.timeout_add(DEFAULT_TIMEOUT, self.verify_connected)

    def verify_connected(self):
        if self.server_capabilities is None:
            #server has not said hello yet
            self.warn_and_quit(EXIT_TIMEOUT, "connection timed out")


    def make_hello(self, challenge_response=None):
        capabilities = {}
        add_version_info(capabilities)
        capabilities["python.version"] = sys.version_info[:3]
        if challenge_response:
            assert self.password
            capabilities["challenge_response"] = challenge_response
        if self.encryption:
            assert self.encryption in ENCRYPTION_CIPHERS
            capabilities["cipher"] = self.encryption
            iv = get_hex_uuid()[:16]
            capabilities["cipher.iv"] = iv
            key_salt = get_hex_uuid()
            capabilities["cipher.key_salt"] = key_salt
            iterations = 1000
            capabilities["cipher.key_stretch_iterations"] = iterations
            self._protocol.set_cipher_in(self.encryption, iv, self.get_password(), key_salt, iterations)
            log("encryption capabilities: %s", [(k,v) for k,v in capabilities.items() if k.startswith("cipher")])
        capabilities["platform"] = sys.platform
        capabilities["platform.release"] = python_platform.release()
        capabilities["platform.machine"] = python_platform.machine()
        capabilities["platform.processor"] = python_platform.processor()
        capabilities["client_type"] = self.client_type()
        capabilities["namespace"] = True
        capabilities["raw_packets"] = True
        capabilities["chunked_compression"] = True
        capabilities["bencode"] = True
        capabilities["rencode"] = has_rencode
        if has_rencode:
            capabilities["rencode.version"] = rencode_version
        capabilities["hostname"] = socket.gethostname()
        capabilities["uuid"] = self.uuid
        try:
            from xpra.platform.info import get_username, get_name
            capabilities["username"] = get_username()
            capabilities["name"] = get_name()
        except:
            log.error("failed to get username/name", exc_info=True)
        capabilities["randr_notify"] = False    #only client.py cares about this
        capabilities["windows"] = False         #only client.py cares about this
        if self._reverse_aliases:
            capabilities["aliases"] = self._reverse_aliases
        return capabilities

    def make_uuid(self):
        try:
            import hashlib
            u = hashlib.sha1()
        except:
            #try python2.4 variant:
开发者ID:svn2github,项目名称:Xpra,代码行数:70,代码来源:client_base.py


注:本文中的xpra.net.protocol.Protocol.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。