Example #1
0
 def set_up(self):
     self.setup_config()
     RPCServer(listen=False)
     self.core = Core()
     self.session = lt.session()
     self.torrent = None
     return component.start()
Example #2
0
    def __init__(self, listen_interface=None):
        log.debug("Core init..")
        component.Component.__init__(self, "Core")

        # Start the libtorrent session
        log.info("Starting libtorrent %s session..", lt.version)

        # Create the client fingerprint
        version = [int(value.split("-")[0]) for value in
                   deluge.common.get_version().split(".")]
        while len(version) < 4:
            version.append(0)

        self.session = lt.session(lt.fingerprint("DE", *version), flags=0)

        # Load the session state if available
        self.__load_session_state()

        # Set the user agent
        self.settings = lt.session_settings()
        self.settings.user_agent = "Deluge/%(deluge_version)s Libtorrent/%(lt_version)s" % \
                        { 'deluge_version': deluge.common.get_version(),
                          'lt_version': self.get_libtorrent_version().rpartition(".")[0] }

        # Set session settings
        self.settings.send_redundant_have = True
        if deluge.common.windows_check():
            self.settings.disk_io_write_mode = \
                lt.io_buffer_mode_t.disable_os_cache
            self.settings.disk_io_read_mode = \
                lt.io_buffer_mode_t.disable_os_cache
        self.session.set_settings(self.settings)

        # Load metadata extension
        self.session.add_extension(lt.create_metadata_plugin)
        self.session.add_extension(lt.create_ut_metadata_plugin)
        self.session.add_extension(lt.create_smart_ban_plugin)

        # Create the components
        self.eventmanager = EventManager()
        self.preferencesmanager = PreferencesManager()
        self.alertmanager = AlertManager()
        self.pluginmanager = PluginManager(self)
        self.torrentmanager = TorrentManager()
        self.filtermanager = FilterManager(self)
        self.authmanager = AuthManager()

        # New release check information
        self.new_release = None

        # Get the core config
        self.config = deluge.configmanager.ConfigManager("core.conf")
        self.config.save()

        # If there was an interface value from the command line, use it, but
        # store the one in the config so we can restore it on shutdown
        self.__old_interface = None
        if listen_interface:
            self.__old_interface = self.config["listen_interface"]
            self.config["listen_interface"] = listen_interface
Example #3
0
 def setUp(self):
     self.setup_config()
     global rpcserver
     global core
     rpcserver = RPCServer(listen=False)
     core = Core()
     self.session = lt.session()
     self.torrent = None
     return component.start()
Example #4
0
    def __init__(self, listen_interface=None):
        log.debug("Core init..")
        component.Component.__init__(self, "Core")

        # Start the libtorrent session
        log.info("Starting libtorrent %s session..", lt.version)

        # Create the client fingerprint
        version = [int(value.split("-")[0]) for value in deluge.common.get_version().split(".")]
        while len(version) < 4:
            version.append(0)

        # Note: All libtorrent python bindings to set plugins/extensions need to be disabled
        # due to  GIL issue. https://code.google.com/p/libtorrent/issues/detail?id=369
        # Setting session flags to 1 enables all libtorrent default plugins
        self.session = lt.session(lt.fingerprint("DE", *version), flags=1)

        # Load the session state if available
        self.__load_session_state()

        # Set the user agent
        self.settings = lt.session_settings()
        self.settings.user_agent = "Deluge %s" % deluge.common.get_version()
        # Increase the alert queue size so that alerts don't get lost
        self.settings.alert_queue_size = 10000

        # Set session settings
        self.settings.send_redundant_have = True
        if deluge.common.windows_check():
            self.settings.disk_io_write_mode = \
                lt.io_buffer_mode_t.disable_os_cache
            self.settings.disk_io_read_mode = \
                lt.io_buffer_mode_t.disable_os_cache
        self.session.set_settings(self.settings)

        # Load metadata extension
        # Note: All libtorrent python bindings to set plugins/extensions need to be disabled
        # due to  GIL issue. https://code.google.com/p/libtorrent/issues/detail?id=369
        # self.session.add_extension(lt.create_metadata_plugin)
        # self.session.add_extension(lt.create_ut_metadata_plugin)
        # self.session.add_extension(lt.create_smart_ban_plugin)

        # Create the components
        self.eventmanager = EventManager()
        self.preferencesmanager = PreferencesManager()
        self.alertmanager = AlertManager()
        self.pluginmanager = PluginManager(self)
        self.torrentmanager = TorrentManager()
        self.filtermanager = FilterManager(self)
        self.autoadd = AutoAdd()
        self.authmanager = AuthManager()

        # New release check information
        self.new_release = None

        # Get the core config
        self.config = deluge.configmanager.ConfigManager("core.conf")

        # If there was an interface value from the command line, use it, but
        # store the one in the config so we can restore it on shutdown
        self.__old_interface = None
        if listen_interface:
            self.__old_interface = self.config["listen_interface"]
            self.config["listen_interface"] = listen_interface
Example #5
0
    def __init__(self, listen_interface=None):
        log.debug("Core init..")
        component.Component.__init__(self, "Core")

        # Start the libtorrent session
        log.info("Starting libtorrent %s session..", lt.version)

        # Create the client fingerprint
        version = deluge.common.VersionSplit(deluge.common.get_version()).version
        while len(version) < 4:
            version.append(0)

        # In libtorrent versions below 0.16.7.0 disable extension bindings due to GIL issue.
        # https://code.google.com/p/libtorrent/issues/detail?id=369
        if deluge.common.VersionSplit(lt.version) >= deluge.common.VersionSplit("0.16.7.0"):
            self.session = lt.session(lt.fingerprint("DE", *version), flags=0)
        else:
            # Setting session flags to 1 enables all libtorrent default plugins
            self.session = lt.session(lt.fingerprint("DE", *version), flags=1)

        # Load the session state if available
        self.__load_session_state()

        # Set the user agent
        self.settings = lt.session_settings()
        self.settings.user_agent = "Deluge %s" % deluge.common.get_version()
        # Increase the alert queue size so that alerts don't get lost
        self.settings.alert_queue_size = 10000

        # Set session settings
        self.settings.send_redundant_have = True
        if deluge.common.windows_check() and lt.version_major == 0 and lt.version_minor <= 15:
            self.settings.disk_io_write_mode = \
                lt.io_buffer_mode_t.disable_os_cache
            self.settings.disk_io_read_mode = \
                lt.io_buffer_mode_t.disable_os_cache
        self.session.set_settings(self.settings)

        # Load metadata extension
        # In libtorrent versions below 0.16.7.0 disable extension bindings due to GIL issue.
        # https://code.google.com/p/libtorrent/issues/detail?id=369
        if deluge.common.VersionSplit(lt.version) >= deluge.common.VersionSplit("0.16.7.0"):
            self.session.add_extension("metadata_transfer")
            self.session.add_extension("ut_metadata")
            self.session.add_extension("smart_ban")

        # Create the components
        self.eventmanager = EventManager()
        self.preferencesmanager = PreferencesManager()
        self.alertmanager = AlertManager()
        self.pluginmanager = PluginManager(self)
        self.torrentmanager = TorrentManager()
        self.filtermanager = FilterManager(self)
        self.autoadd = AutoAdd()
        self.authmanager = AuthManager()

        # New release check information
        self.new_release = None

        # Get the core config
        self.config = deluge.configmanager.ConfigManager("core.conf")

        # If there was an interface value from the command line, use it, but
        # store the one in the config so we can restore it on shutdown
        self.__old_interface = None
        if listen_interface:
            if deluge.common.is_ip(listen_interface):
                self.__old_interface = self.config["listen_interface"]
                self.config["listen_interface"] = listen_interface
            else:
                log.error("Invalid listen interface (must be IP Address): %s", listen_interface)
Example #6
0
    def __init__(self, listen_interface=None, read_only_config_keys=None):
        log.debug('Core init...')
        component.Component.__init__(self, 'Core')

        deluge_version = deluge.common.get_version()
        split_version = deluge.common.VersionSplit(deluge_version).version
        while len(split_version) < 4:
            split_version.append(0)

        deluge_fingerprint = lt.generate_fingerprint('DE', *split_version)
        user_agent = 'Deluge/{} libtorrent/{}'.format(deluge_version, self.get_libtorrent_version())

        # Start the libtorrent session.
        log.debug('Starting session (fingerprint: %s, user_agent: %s)', deluge_fingerprint, user_agent)
        settings_pack = {'peer_fingerprint': deluge_fingerprint,
                         'user_agent': user_agent,
                         'ignore_resume_timestamps': True}
        self.session = lt.session(settings_pack, flags=0)

        # Load the settings, if available.
        self._load_session_state()

        # Enable libtorrent extensions
        # Allows peers to download the metadata from the swarm directly
        self.session.add_extension('ut_metadata')
        # Ban peers that sends bad data
        self.session.add_extension('smart_ban')

        # Create the components
        self.eventmanager = EventManager()
        self.preferencesmanager = PreferencesManager()
        self.alertmanager = AlertManager()
        self.pluginmanager = PluginManager(self)
        self.torrentmanager = TorrentManager()
        self.filtermanager = FilterManager(self)
        self.authmanager = AuthManager()

        # New release check information
        self.new_release = None

        # External IP Address from libtorrent
        self.external_ip = None
        self.eventmanager.register_event_handler('ExternalIPEvent', self._on_external_ip_event)

        # GeoIP instance with db loaded
        self.geoip_instance = None

        # These keys will be dropped from the set_config() RPC and are
        # configurable from the command-line.
        self.read_only_config_keys = read_only_config_keys
        log.debug('read_only_config_keys: %s', read_only_config_keys)

        # Get the core config
        self.config = ConfigManager('core.conf')
        self.config.save()

        # If there was an interface value from the command line, use it, but
        # store the one in the config so we can restore it on shutdown
        self.__old_interface = None
        if listen_interface:
            if deluge.common.is_ip(listen_interface):
                self.__old_interface = self.config['listen_interface']
                self.config['listen_interface'] = listen_interface
            else:
                log.error('Invalid listen interface (must be IP Address): %s', listen_interface)

        # New release check information
        self.__new_release = None

        # Session status timer
        self.session_status = {}
        self.session_status_timer_interval = 0.5
        self.session_status_timer = task.LoopingCall(self.session.post_session_stats)
        self.alertmanager.register_handler('session_stats_alert', self._on_alert_session_stats)
        self._session_rates = {(k_rate, k_bytes): 0 for k_rate, k_bytes in SESSION_RATES_MAPPING.items()}
        self.session_rates_timer_interval = 2
        self.session_rates_timer = task.LoopingCall(self._update_session_rates)