Index: docs/man/deluged.1

--- docs/man/deluged.1.orig	2012-04-09 19:53:16.000000000 -0600
+++ docs/man/deluged.1	2012-07-18 09:17:45.869572849 -0600
@@ -48,6 +48,11 @@
 .TP
 .I -q --quiet
 Sets the log level to 'none', this is the same as `\-L none`
+.TP
+.I -T NAME=VALUE, --libtorrent=NAME=VALUE, --lib-torrent=NAME=VALUE
+Sets the libtorrent option NAME to the given value.
+For example, `\-T announce_ip=10.0.0.1' causes deluged to announce itself with the given IP address.
+For a complete list of options, see the libtorrent documentation.
 
 .SH SEE ALSO
 .B Homepage:
Index: libtorrent/docs/manual.html

--- libtorrent/docs/manual.html.orig	2012-07-18 09:15:20.547014587 -0600
+++ libtorrent/docs/manual.html	2012-07-18 09:17:45.874573051 -0600
@@ -3058,7 +3058,7 @@
         int inactivity_timeout;
         int unchoke_interval;
         int optimistic_unchoke_multiplier;
-        address announce_ip;
+        string announce_ip;
         int num_want;
         int initial_picker_threshold;
         int allowed_fast_set_size;
Index: libtorrent/docs/manual.rst

--- libtorrent/docs/manual.rst.orig	2012-07-18 09:15:20.580014487 -0600
+++ libtorrent/docs/manual.rst	2012-07-18 09:17:45.876573110 -0600
@@ -3024,7 +3024,7 @@
 		int inactivity_timeout;
 		int unchoke_interval;
 		int optimistic_unchoke_multiplier;
-		address announce_ip;
+		string announce_ip;
 		int num_want;
 		int initial_picker_threshold;
 		int allowed_fast_set_size;
Index: libtorrent/src/http_tracker_connection.cpp

--- libtorrent/src/http_tracker_connection.cpp.orig	2012-07-18 09:15:17.678023349 -0600
+++ libtorrent/src/http_tracker_connection.cpp	2012-07-18 09:17:45.872572976 -0600
@@ -160,12 +160,8 @@
 			url += "&numwant=";
 			url += to_string((std::min)(tracker_req().num_want, 999)).elems;
 
-			if (m_settings.announce_ip != address())
-			{
-				error_code ec;
-				std::string ip = m_settings.announce_ip.to_string(ec);
-				if (!ec) url += "&ip=" + ip;
-			}
+			if (m_settings.announce_ip != "")
+				url += "&ip=" + m_settings.announce_ip;
 
 #ifndef TORRENT_DISABLE_ENCRYPTION
 			url += "&supportcrypto=1";
Index: libtorrent/src/udp_tracker_connection.cpp

--- libtorrent/src/udp_tracker_connection.cpp.orig	2012-07-18 09:15:17.659023407 -0600
+++ libtorrent/src/udp_tracker_connection.cpp	2012-07-18 09:17:45.872572976 -0600
@@ -506,8 +506,14 @@
 		detail::write_int64(req.uploaded, out); // uploaded
 		detail::write_int32(req.event, out); // event
 		// ip address
-		if (m_settings.announce_ip != address() && m_settings.announce_ip.is_v4())
-			detail::write_uint32(m_settings.announce_ip.to_v4().to_ulong(), out);
+		if (m_settings.announce_ip != "")
+		{
+			address announce_ip = address::from_string(m_settings.announce_ip);
+			if (announce_ip.is_v4())
+				detail::write_uint32(announce_ip.to_v4().to_ulong(), out);
+			else
+				detail::write_int32(0, out);
+		}
 		else
 			detail::write_int32(0, out);
 		detail::write_int32(req.key, out); // key
Index: libtorrent/bindings/python/src/session_settings.cpp

--- libtorrent/bindings/python/src/session_settings.cpp.orig	2012-07-18 09:15:21.183012617 -0600
+++ libtorrent/bindings/python/src/session_settings.cpp	2012-07-18 09:17:45.877573138 -0600
@@ -38,6 +38,7 @@
         .def_readwrite("inactivity_timeout", &session_settings::inactivity_timeout)
         .def_readwrite("unchoke_interval", &session_settings::unchoke_interval)
         .def_readwrite("optimistic_unchoke_multiplier", &session_settings::optimistic_unchoke_multiplier)
+	.def_readwrite("announce_ip", &session_settings::announce_ip)
         .def_readwrite("num_want", &session_settings::num_want)
         .def_readwrite("initial_picker_threshold", &session_settings::initial_picker_threshold)
         .def_readwrite("allowed_fast_set_size", &session_settings::allowed_fast_set_size)
Index: libtorrent/include/libtorrent/session_settings.hpp

--- libtorrent/include/libtorrent/session_settings.hpp.orig	2012-07-18 09:15:14.416033313 -0600
+++ libtorrent/include/libtorrent/session_settings.hpp	2012-07-18 09:17:45.871572936 -0600
@@ -109,6 +109,7 @@
 			, inactivity_timeout(600)
 			, unchoke_interval(15)
 			, optimistic_unchoke_multiplier(4)
+			, announce_ip()
 			, num_want(200)
 			, initial_picker_threshold(4)
 			, allowed_fast_set_size(10)
@@ -287,7 +288,7 @@
 
 		// if this is set, this IP will be reported do the
 		// tracker in the ip= parameter.
-		address announce_ip;
+		std::string announce_ip;
 
 		// the num want sent to trackers
 		int num_want;
Index: deluge/core/daemon.py

--- deluge/core/daemon.py.orig	2012-04-09 19:53:16.000000000 -0600
+++ deluge/core/daemon.py	2012-07-18 09:23:13.110599407 -0600
@@ -47,7 +47,7 @@
 import deluge.error
 
 class Daemon(object):
-    def __init__(self, options=None, args=None, classic=False):
+    def __init__(self, parser, options=None, args=None, classic=False):
         # Check for another running instance of the daemon
         if os.path.isfile(deluge.configmanager.get_config_dir("deluged.pid")):
             # Get the PID and the port of the supposedly running daemon
@@ -138,9 +138,19 @@
         else:
             listen_interface = ""
 
+        # Handle any libtorrent settings
+	settings_dict = {}
+        if options and options.libtorrent_settings:
+            for setting in options.libtorrent_settings:
+                opt = setting.split('=', 1)
+                if len(opt) != 2:
+                    parser.error('--libtorrent requires name=value')
+                settings_dict[opt[0]] = opt[1]
+
         from deluge.core.core import Core
         # Start the core as a thread and join it until it's done
-        self.core = Core(listen_interface=listen_interface)
+        self.core = Core(listen_interface=listen_interface,
+	  settings=settings_dict)
 
         port = self.core.config["daemon_port"]
         if options and options.port:
Index: deluge/core/core.py

--- deluge/core/core.py.orig	2012-04-09 19:53:16.000000000 -0600
+++ deluge/core/core.py	2012-07-18 09:20:51.967016461 -0600
@@ -72,7 +72,7 @@
 from deluge.core.rpcserver import export
 
 class Core(component.Component):
-    def __init__(self, listen_interface=None):
+    def __init__(self, listen_interface=None, settings={}):
         log.debug("Core init..")
         component.Component.__init__(self, "Core")
 
@@ -93,8 +93,18 @@
         self.settings = lt.session_settings()
         self.settings.user_agent = "Deluge %s" % deluge.common.get_version()
 
-        # Set session settings
+        # Set other default settings
         self.settings.send_redundant_have = True
+
+        # Set passed settings
+        for key in settings.keys():
+            if hasattr(self.settings, key):
+                setattr(self.settings, key, settings[key])
+            else:
+                log.error("Illegal settings key %s" % key)
+                raise KeyError
+
+        # Set session settings
         if deluge.common.windows_check():
             self.settings.disk_io_write_mode = \
                 lt.io_buffer_mode_t.disable_os_cache
Index: deluge/main.py

--- deluge/main.py.orig	2012-04-09 19:53:16.000000000 -0600
+++ deluge/main.py	2012-07-18 09:17:45.871572936 -0600
@@ -164,6 +164,9 @@
         help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
     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("-T", "--libtorrent", "--lib-torrent",
+        dest="libtorrent_settings", action="append", metavar="NAME=VALUE",
+	help="Sets the libtorrent option NAME to VALUE")
     parser.add_option("--profile", dest="profile", action="store_true", default=False,
         help="Profiles the daemon")
 
@@ -223,7 +226,7 @@
         hsp.start()
     try:
         from deluge.core.daemon import Daemon
-        Daemon(options, args)
+        Daemon(parser, options, args)
     except deluge.error.DaemonRunningError, e:
         log.error(e)
         log.error("You cannot run multiple daemons with the same config directory set.")
