From 401f19282a90093f164d1eb79ec1cd83b0128d02 Mon Sep 17 00:00:00 2001
From: Jefry Lagrange <jefry.reyes@gmail.com>
Date: Tue, 28 Aug 2012 15:10:19 -0400
Subject: [PATCH] dont connect to local host if ip is the same or if is
 loopback

---
 src/common/jingle_transport.py | 3 ++-
 src/common/socks5.py           | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/common/jingle_transport.py b/src/common/jingle_transport.py
index 0328fca6a1..224566a007 100644
--- a/src/common/jingle_transport.py
+++ b/src/common/jingle_transport.py
@@ -177,7 +177,8 @@ class JingleTransportSocks5(JingleTransport):
             return
         local_ip_cand = []
         port = int(gajim.config.get('file_transfers_port'))
-        type_preference = 126 #type preference of connection type. XEP-0260 section 2.2
+        #type preference of connection type. XEP-0260 section 2.2
+        type_preference = 126 
         c = {'host': self.connection.peerhost[0]}
         c['candidate_id'] = self.connection.connection.getAnID()
         c['port'] = port
diff --git a/src/common/socks5.py b/src/common/socks5.py
index 5ae6583132..b6f0ab8596 100644
--- a/src/common/socks5.py
+++ b/src/common/socks5.py
@@ -34,6 +34,7 @@ from errno import EINPROGRESS
 from errno import EAFNOSUPPORT
 from xmpp.idlequeue import IdleObject
 from file_props import FilesProp
+from common import gajim
 import jingle_xtls
 if jingle_xtls.PYOPENSSL_PRESENT:
     import OpenSSL
@@ -116,10 +117,15 @@ class SocksQueue:
         self.on_failure[sid] = on_failure
         file_props = FilesProp.getFileProp(account, sid)
         file_props.failure_cb = on_failure
+        con = gajim.connections[account]
         if not file_props.streamhosts:
             on_failure(file_props.sid)
         # add streamhosts to the queue
         for streamhost in file_props.streamhosts:
+            if streamhost['host'] == '127.0.0.1' or \
+                    streamhost['host'] == '::1' or \
+                    streamhost['host'] == con.peerhost[0]:
+                continue
             if 'type' in streamhost and streamhost['type'] == 'proxy':
                 fp = None
             else:
-- 
GitLab