Add some command line options to the daemon to set the listen

interfaces, -i and -u
This commit is contained in:
Andrew Resch 2009-05-30 00:22:14 +00:00
parent d29934a534
commit 019c78db47
4 changed files with 37 additions and 6 deletions

View File

@ -78,7 +78,7 @@ STATUS_KEYS = ['active_time', 'compact', 'distributed_copies', 'download_payload
'tracker_status', 'trackers', 'upload_payload_rate'] 'tracker_status', 'trackers', 'upload_payload_rate']
class Core(component.Component): class Core(component.Component):
def __init__(self): def __init__(self, listen_interface=None):
log.debug("Core init..") log.debug("Core init..")
component.Component.__init__(self, "Core") component.Component.__init__(self, "Core")
@ -141,6 +141,13 @@ class Core(component.Component):
# Get the core config # Get the core config
self.config = deluge.configmanager.ConfigManager("core.conf") 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): def start(self):
"""Starts the core""" """Starts the core"""
# New release check information # New release check information
@ -153,6 +160,10 @@ class Core(component.Component):
# Save the libtorrent session state # Save the libtorrent session state
self.__save_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 # Make sure the config file has been saved
self.config.save() self.config.save()

View File

@ -123,7 +123,7 @@ class Daemon(object):
log.debug("options: %s", options) log.debug("options: %s", options)
log.debug("args: %s", args) log.debug("args: %s", args)
# Set the config directory # Set the config directory
if options: if options and options.config:
deluge.configmanager.set_config_dir(options.config) deluge.configmanager.set_config_dir(options.config)
from deluge.core.core import Core from deluge.core.core import Core
@ -133,10 +133,16 @@ class Daemon(object):
port = self.core.config["daemon_port"] port = self.core.config["daemon_port"]
if options and options.port: if options and options.port:
port = options.port port = options.port
if options and options.ui_interface:
interface = options.ui_interface
else:
interface = ""
self.rpcserver = RPCServer( self.rpcserver = RPCServer(
port=port, port=port,
allow_remote=self.core.config["allow_remote"], allow_remote=self.core.config["allow_remote"],
listen=not classic listen=not classic,
interface=interface
) )
# Register the daemon and the core RPCs # Register the daemon and the core RPCs

View File

@ -61,6 +61,7 @@ DEFAULT_PREFS = {
"compact_allocation": False, "compact_allocation": False,
"download_location": deluge.common.get_default_download_dir(), "download_location": deluge.common.get_default_download_dir(),
"listen_ports": [6881, 6891], "listen_ports": [6881, 6891],
"listen_interface": "",
"copy_torrent_file": False, "copy_torrent_file": False,
"torrentfiles_location": deluge.common.get_default_download_dir(), "torrentfiles_location": deluge.common.get_default_download_dir(),
"plugins_location": os.path.join(deluge.configmanager.get_config_dir(), "plugins"), "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._on_set_state_location)
self.config.register_set_function("listen_ports", self.config.register_set_function("listen_ports",
self._on_set_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.config.register_set_function("random_port",
self._on_set_random_port) self._on_set_random_port)
self.config.register_set_function("outgoing_ports", 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 # Only set the listen ports if random_port is not true
if self.config["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]) 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): def _on_set_random_port(self, key, value):
log.debug("random port value set to %s", value) log.debug("random port value set to %s", value)
@ -263,7 +270,7 @@ class PreferencesManager(component.Component):
# Set the listen ports # Set the listen ports
log.debug("listen port range set to %s-%s", listen_ports[0], log.debug("listen port range set to %s-%s", listen_ports[0],
listen_ports[1]) 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): def _on_set_outgoing_ports(self, key, value):
if not self.config["random_outgoing_ports"]: if not self.config["random_outgoing_ports"]:

View File

@ -131,6 +131,13 @@ def start_daemon():
version=deluge.common.get_version()) version=deluge.common.get_version())
parser.add_option("-p", "--port", dest="port", parser.add_option("-p", "--port", dest="port",
help="Port daemon will listen on", action="store", type="int") 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", parser.add_option("-d", "--do-not-daemonize", dest="donot",
help="Do not daemonize", action="store_true", default=False) help="Do not daemonize", action="store_true", default=False)
parser.add_option("-c", "--config", dest="config", parser.add_option("-c", "--config", dest="config",
@ -144,7 +151,7 @@ def start_daemon():
parser.add_option("-q", "--quiet", dest="quiet", 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) 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, 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 # Get the options and args from the OptionParser
(options, args) = parser.parse_args() (options, args) = parser.parse_args()