Page 1 of 1

Report IP address to the tracker

Posted: Sat Oct 17, 2009 5:34 pm
by axelgenus
Hi guys,

my ISP connects all its customers to a MAN which uses private IP addresses (is a NAT-ed network). When I use Deluge it works flawlessy when it tries to connect to outer IP's but when another customer of my same ISP is in the swarm it doesn't work anymore. Some BitTorrent clients allow to override the IP address reported to the tracker and this feature is very important for me and the other customers of my same ISP (we're talking about one of the greatest italian ISP: fastweb). It would be possible to write a plugin which adds this extra feature to Deluge? There's no linux client (except rtorrent) which supports this feature.

Thank you,
Alessandro.

Re: Report IP address to the tracker

Posted: Sun Aug 07, 2011 9:04 am
by gkuenning
I previously posted a fix for this defect in ticket 1681, which has disappeared from the Trac. It's also mentioned in ticket 1384 (which led me here). I tried to post my patch as a comment to 1384, but the Trac permissions wouldn't let me. Who is the cretin who thinks it's a good idea to keep community members from contributing code? And who is responsible for deleting the previous ticket?

Once again, here's the patch. Sigh.

Code: Select all

Index: docs/man/deluged.1

--- docs/man/deluged.1.orig	2010-08-20 15:20:51.000000000 -0600
+++ docs/man/deluged.1	2011-03-31 18:06:24.000000000 -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: deluge/core/core.py

--- deluge/core/core.py.orig	2010-08-20 15:20:51.000000000 -0600
+++ deluge/core/core.py	2011-03-31 17:36:35.000000000 -0600
@@ -69,7 +69,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")
 
@@ -90,8 +90,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
         self.session.set_settings(self.settings)
 
         # Load metadata extension

====================

Index: deluge/core/daemon.py

--- deluge/core/daemon.py.orig	2010-08-20 15:20:51.000000000 -0600
+++ deluge/core/daemon.py	2011-03-31 01:01:32.000000000 -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
@@ -133,9 +133,18 @@
         if options and options.config:
             deluge.configmanager.set_config_dir(options.config)
 
+        # Handle any libtorrent settings
+        if options and options.libtorrent_settings:
+            settings_dict = {}
+            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()
+        self.core = Core(settings=settings_dict)
 
         port = self.core.config["daemon_port"]
         if options and options.port:

====================

Index: deluge/main.py

--- deluge/main.py.orig	2011-03-31 00:49:22.000000000 -0600
+++ deluge/main.py	2011-03-31 02:10:26.000000000 -0600
@@ -152,6 +152,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")
 
@@ -211,7 +214,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.")

====================

Index: libtorrent/include/libtorrent/session_settings.hpp

--- libtorrent/include/libtorrent/session_settings.hpp.orig	2010-11-03 22:44:40.000000000 -0600
+++ libtorrent/include/libtorrent/session_settings.hpp	2011-03-31 05:52:14.000000000 -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: libtorrent/src/udp_tracker_connection.cpp

--- libtorrent/src/udp_tracker_connection.cpp.orig	2010-11-03 22:44:43.000000000 -0600
+++ libtorrent/src/udp_tracker_connection.cpp	2011-03-31 06:04:42.000000000 -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/src/http_tracker_connection.cpp

--- libtorrent/src/http_tracker_connection.cpp.orig	2010-11-03 22:44:43.000000000 -0600
+++ libtorrent/src/http_tracker_connection.cpp	2011-03-31 05:59:08.000000000 -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/docs/manual.html

--- libtorrent/docs/manual.html.orig	2010-11-03 22:44:48.000000000 -0600
+++ libtorrent/docs/manual.html	2011-03-31 18:01:51.000000000 -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	2010-11-03 22:44:48.000000000 -0600
+++ libtorrent/docs/manual.rst	2011-03-31 18:02:13.000000000 -0600
@@ -3018,7 +3018,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/bindings/python/src/session_settings.cpp

--- libtorrent/bindings/python/src/session_settings.cpp.orig	2010-11-03 22:44:48.000000000 -0600
+++ libtorrent/bindings/python/src/session_settings.cpp	2011-03-31 03:47:10.000000000 -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)

Re: Report IP address to the tracker

Posted: Sun Aug 07, 2011 11:57 am
by Cas
How about you find out all the facts before casting aspersions. If you had been following the Deluge community you would know that we had a major issue with spam on Trac so had to enable email verification (hence your error) and it is possible your ticket was accidentally caught up in cleaning out the spam.

If you verify your email on Trac you can add to the ticket.

Re: Report IP address to the tracker

Posted: Mon Aug 08, 2011 10:48 pm
by JimmyCZ
Thanks to gkuenning for this useful patch!

It's working well, I only had some complication with format of this patch. Gkuenning's patch is for version 1.3.0, I updated it for Deluge version 1.3.1 and 1.3.2, rb_libtorrent version 0.15.6 and 0.15.7 (actual stable and testing in Portage).

For Gentoo users, I also wrote appropriate ebuilds. Create local overlay (see http://bit.ly/nfgfv5), copy content of deluge-ebuilds.tgz into it and simply emerge (patches are included in ebuilds).

Re: Report IP address to the tracker

Posted: Tue Aug 09, 2011 11:59 am
by Cas
I'm afraid the patch is not the best solution. However since updating ticket #1384, OmegaPhil has put together a Deluge patch that includes all UIs which we should see shortly.

Also libtorrent 0.15RC now includes python binding for announce_ip.

Re: Report IP address to the tracker

Posted: Tue Mar 12, 2013 8:57 am
by oldhouse
Is there anyway I can report IP address to tracker while using Deluge for windows?

Re: Report IP address to the tracker

Posted: Tue Mar 12, 2013 1:14 pm
by Cas
If you get the original source code files from git you can modify them and drop them into appropriate Deluge dir and it will use them.

Re: Report IP address to the tracker

Posted: Tue Mar 12, 2013 3:09 pm
by oldhouse
Cas wrote:If you get the original source code files from git you can modify them and drop them into appropriate Deluge dir and it will use them.
Mmmm I would be glad to do that but I think it's far from my knowledge :geek: