diff --git a/deluge/core/core.py b/deluge/core/core.py index 93f55c14d..4183f2f25 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -78,7 +78,7 @@ STATUS_KEYS = ['active_time', 'compact', 'distributed_copies', 'download_payload 'tracker_status', 'trackers', 'upload_payload_rate'] class Core(component.Component): - def __init__(self): + def __init__(self, listen_interface=None): log.debug("Core init..") component.Component.__init__(self, "Core") @@ -141,6 +141,13 @@ class Core(component.Component): # 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 + def start(self): """Starts the core""" # New release check information @@ -153,6 +160,10 @@ class Core(component.Component): # Save the libtorrent session state self.__save_session_state() + # We stored a copy of the old interface value + if self.__old_interface: + self.config["listen_interface"] = self.__old_interface + # Make sure the config file has been saved self.config.save() diff --git a/deluge/core/daemon.py b/deluge/core/daemon.py index ecbfbe984..202cd414e 100644 --- a/deluge/core/daemon.py +++ b/deluge/core/daemon.py @@ -123,7 +123,7 @@ class Daemon(object): log.debug("options: %s", options) log.debug("args: %s", args) # Set the config directory - if options: + if options and options.config: deluge.configmanager.set_config_dir(options.config) from deluge.core.core import Core @@ -133,10 +133,16 @@ class Daemon(object): port = self.core.config["daemon_port"] if options and options.port: port = options.port + if options and options.ui_interface: + interface = options.ui_interface + else: + interface = "" + self.rpcserver = RPCServer( port=port, allow_remote=self.core.config["allow_remote"], - listen=not classic + listen=not classic, + interface=interface ) # Register the daemon and the core RPCs diff --git a/deluge/core/preferencesmanager.py b/deluge/core/preferencesmanager.py index 3c2ad4e03..7f88c0f9b 100644 --- a/deluge/core/preferencesmanager.py +++ b/deluge/core/preferencesmanager.py @@ -61,6 +61,7 @@ DEFAULT_PREFS = { "compact_allocation": False, "download_location": deluge.common.get_default_download_dir(), "listen_ports": [6881, 6891], + "listen_interface": "", "copy_torrent_file": False, "torrentfiles_location": deluge.common.get_default_download_dir(), "plugins_location": os.path.join(deluge.configmanager.get_config_dir(), "plugins"), @@ -162,6 +163,8 @@ class PreferencesManager(component.Component): self._on_set_state_location) self.config.register_set_function("listen_ports", self._on_set_listen_ports) + self.config.register_set_function("listen_interface", + self._on_set_listen_interface) self.config.register_set_function("random_port", self._on_set_random_port) self.config.register_set_function("outgoing_ports", @@ -245,7 +248,11 @@ class PreferencesManager(component.Component): # Only set the listen ports if random_port is not true if self.config["random_port"] is not True: log.debug("listen port range set to %s-%s", value[0], value[1]) - self.session.listen_on(value[0], value[1]) + self.session.listen_on(value[0], value[1], str(self.config["listen_interface"])) + + def _on_set_listen_interface(self, key, value): + # Call the random_port callback since it'll do what we need + self._on_set_random_port("random_port", self.config["random_port"]) def _on_set_random_port(self, key, value): log.debug("random port value set to %s", value) @@ -263,7 +270,7 @@ class PreferencesManager(component.Component): # Set the listen ports log.debug("listen port range set to %s-%s", listen_ports[0], listen_ports[1]) - self.session.listen_on(listen_ports[0], listen_ports[1]) + self.session.listen_on(listen_ports[0], listen_ports[1], str(self.config["listen_interface"])) def _on_set_outgoing_ports(self, key, value): if not self.config["random_outgoing_ports"]: diff --git a/deluge/main.py b/deluge/main.py index 0caac8ace..22b2488fc 100644 --- a/deluge/main.py +++ b/deluge/main.py @@ -131,6 +131,13 @@ def start_daemon(): version=deluge.common.get_version()) parser.add_option("-p", "--port", dest="port", help="Port daemon will listen on", action="store", type="int") + parser.add_option("-i", "--interface", dest="interface", + help="Interface daemon will listen for bittorrent connections on, \ +this should be an IP address", + action="store", type="str") + parser.add_option("-u", "--ui-interface", dest="ui_interface", + help="Interface daemon will listen for UI connections on, this should be\ + an IP address", action="store", type="str") parser.add_option("-d", "--do-not-daemonize", dest="donot", help="Do not daemonize", action="store_true", default=False) parser.add_option("-c", "--config", dest="config", @@ -144,7 +151,7 @@ def start_daemon(): parser.add_option("-q", "--quiet", dest="quiet", help="Sets the log level to 'none', this is the same as `-L none`", action="store_true", default=False) parser.add_option("--profile", dest="profile", action="store_true", default=False, - help="Profiles the daemon" ) + help="Profiles the daemon") # Get the options and args from the OptionParser (options, args) = parser.parse_args()