コード例 #1
0
        def TWISTEDSetup():

            cls._ssl_cert_path = os.path.join(TestController.DB_DIR,
                                              'server.crt')
            cls._ssl_key_path = os.path.join(TestController.DB_DIR,
                                             'server.key')

            # if db test ran, this is still hanging around and read-only, so don't bother to fail overwriting
            if not os.path.exists(cls._ssl_cert_path):

                HydrusEncryption.GenerateOpenSSLCertAndKeyFile(
                    cls._ssl_cert_path, cls._ssl_key_path)

            context_factory = twisted.internet.ssl.DefaultOpenSSLContextFactory(
                cls._ssl_key_path, cls._ssl_cert_path)

            reactor.listenSSL(
                HC.DEFAULT_SERVER_ADMIN_PORT,
                ServerServer.HydrusServiceAdmin(cls._serverside_admin_service),
                context_factory)
            reactor.listenSSL(
                HC.DEFAULT_SERVICE_PORT + 1,
                ServerServer.HydrusServiceRepositoryFile(
                    cls._serverside_file_service), context_factory)
            reactor.listenSSL(
                HC.DEFAULT_SERVICE_PORT,
                ServerServer.HydrusServiceRepositoryTag(
                    cls._serverside_tag_service), context_factory)

            reactor.listenTCP(
                45866,
                ClientLocalServer.HydrusServiceBooru(
                    cls._local_booru, allow_non_local_connections=False))
コード例 #2
0
ファイル: ServerController.py プロジェクト: Yoitsu/hydrus
            def StartServices(*args, **kwargs):

                HydrusData.Print('Starting services\u2026')

                for service in services:

                    service_key = service.GetServiceKey()
                    service_type = service.GetServiceType()

                    name = service.GetName()

                    try:

                        port = service.GetPort()

                        if service_type == HC.SERVER_ADMIN:

                            http_factory = ServerServer.HydrusServiceAdmin(
                                service)

                        elif service_type == HC.FILE_REPOSITORY:

                            http_factory = ServerServer.HydrusServiceRepositoryFile(
                                service)

                        elif service_type == HC.TAG_REPOSITORY:

                            http_factory = ServerServer.HydrusServiceRepositoryTag(
                                service)

                        else:

                            return

                        (ssl_cert_path, ssl_key_path) = self.db.GetSSLPaths()

                        sslmethod = twisted.internet.ssl.SSL.TLSv1_2_METHOD

                        context_factory = twisted.internet.ssl.DefaultOpenSSLContextFactory(
                            ssl_key_path, ssl_cert_path, sslmethod)

                        ipv6_port = None

                        try:

                            ipv6_port = reactor.listenSSL(port,
                                                          http_factory,
                                                          context_factory,
                                                          interface='::')

                        except Exception as e:

                            HydrusData.Print('Could not bind to IPv6:')

                            HydrusData.Print(str(e))

                        ipv4_port = None

                        try:

                            ipv4_port = reactor.listenSSL(
                                port, http_factory, context_factory)

                        except:

                            if ipv6_port is None:

                                raise

                        self._service_keys_to_connected_ports[service_key] = (
                            ipv4_port, ipv6_port)

                        if HydrusNetworking.LocalPortInUse(port):

                            HydrusData.Print('Running "{}" on port {}.'.format(
                                name, port))

                        else:

                            raise Exception(
                                'Tried to bind port {} for "{}" but it failed.'
                                .format(port, name))

                    except Exception as e:

                        HydrusData.Print(traceback.format_exc())

                HydrusData.Print('Services started')