Skip to content
Snippets Groups Projects
Commit 35d0260a authored by fedor.brunner's avatar fedor.brunner
Browse files

ignore address-related errors for getaddrinfo. Fixes #7611

cleanup of jingle_transport.py
parent ccda82c1
No related branches found
No related tags found
No related merge requests found
...@@ -178,30 +178,39 @@ class JingleTransportSocks5(JingleTransport): ...@@ -178,30 +178,39 @@ class JingleTransportSocks5(JingleTransport):
return return
if not self.connection: if not self.connection:
return return
local_ip_cand = []
port = int(gajim.config.get('file_transfers_port')) port = int(gajim.config.get('file_transfers_port'))
#type preference of connection type. XEP-0260 section 2.2 #type preference of connection type. XEP-0260 section 2.2
type_preference = 126 type_preference = 126
c = {'host': self.connection.peerhost[0]} priority = (2**16) * type_preference
c['candidate_id'] = self.connection.connection.getAnID()
c['port'] = port hosts = set()
c['type'] = 'direct' local_ip_cand = []
c['jid'] = self.ourjid
c['priority'] = (2**16) * type_preference
c = {'host': self.connection.peerhost[0],
'candidate_id': self.connection.connection.getAnID(),
'port': port,
'type': 'direct',
'jid': self.ourjid,
'priority': priority}
hosts.add(self.connection.peerhost[0])
local_ip_cand.append(c) local_ip_cand.append(c)
for addr in socket.getaddrinfo(socket.gethostname(), None): try:
if not addr[4][0] in local_ip_cand and not addr[4][0].startswith('127'): for addrinfo in socket.getaddrinfo(socket.gethostname(), None):
c = {'host': addr[4][0]} addr = addrinfo[4][0]
c['candidate_id'] = self.connection.connection.getAnID() if not addr in hosts and not addr.startswith('127'):
c['port'] = port c = {'host': addr,
c['type'] = 'direct' 'candidate_id': self.connection.connection.getAnID(),
c['jid'] = self.ourjid 'port': port,
c['priority'] = (2**16) * type_preference 'type': 'direct',
c['initiator'] = self.file_props.sender 'jid': self.ourjid,
c['target'] = self.file_props.receiver 'priority': priority,
local_ip_cand.append(c) 'initiator': self.file_props.sender,
'target': self.file_props.receiver}
hosts.add(addr)
local_ip_cand.append(c)
except socket.gaierror:
pass # ignore address-related errors for getaddrinfo
self._add_candidates(local_ip_cand) self._add_candidates(local_ip_cand)
...@@ -209,6 +218,7 @@ class JingleTransportSocks5(JingleTransport): ...@@ -209,6 +218,7 @@ class JingleTransportSocks5(JingleTransport):
if not self.connection: if not self.connection:
return return
type_preference = 126 type_preference = 126
priority = (2**16) * type_preference
additional_ip_cand = [] additional_ip_cand = []
port = int(gajim.config.get('file_transfers_port')) port = int(gajim.config.get('file_transfers_port'))
ft_add_hosts = gajim.config.get('ft_add_hosts_to_send') ft_add_hosts = gajim.config.get('ft_add_hosts_to_send')
...@@ -216,14 +226,14 @@ class JingleTransportSocks5(JingleTransport): ...@@ -216,14 +226,14 @@ class JingleTransportSocks5(JingleTransport):
if ft_add_hosts: if ft_add_hosts:
hosts = [e.strip() for e in ft_add_hosts.split(',')] hosts = [e.strip() for e in ft_add_hosts.split(',')]
for h in hosts: for h in hosts:
c = {'host': h} c = {'host': h,
c['candidate_id'] = self.connection.connection.getAnID() 'candidate_id': self.connection.connection.getAnID(),
c['port'] = port 'port': port,
c['type'] = 'direct' 'type': 'direct',
c['jid'] = self.ourjid 'jid': self.ourjid,
c['priority'] = (2**16) * type_preference 'priority': priority,
c['initiator'] = self.file_props.sender 'initiator': self.file_props.sender,
c['target'] = self.file_props.receiver 'target': self.file_props.receiver}
additional_ip_cand.append(c) additional_ip_cand.append(c)
self._add_candidates(additional_ip_cand) self._add_candidates(additional_ip_cand)
...@@ -232,6 +242,7 @@ class JingleTransportSocks5(JingleTransport): ...@@ -232,6 +242,7 @@ class JingleTransportSocks5(JingleTransport):
if not self.connection: if not self.connection:
return return
type_preference = 10 type_preference = 10
priority = (2**16) * type_preference
proxy_cand = [] proxy_cand = []
socks5conn = self.connection socks5conn = self.connection
proxyhosts = socks5conn._get_file_transfer_proxies_from_config(self.file_props) proxyhosts = socks5conn._get_file_transfer_proxies_from_config(self.file_props)
...@@ -240,14 +251,14 @@ class JingleTransportSocks5(JingleTransport): ...@@ -240,14 +251,14 @@ class JingleTransportSocks5(JingleTransport):
self.file_props.proxyhosts = proxyhosts self.file_props.proxyhosts = proxyhosts
for proxyhost in proxyhosts: for proxyhost in proxyhosts:
c = {'host': proxyhost['host']} c = {'host': proxyhost['host'],
c['candidate_id'] = self.connection.connection.getAnID() 'candidate_id': self.connection.connection.getAnID(),
c['port'] = int(proxyhost['port']) 'port': int(proxyhost['port']),
c['type'] = 'proxy' 'type': 'proxy',
c['jid'] = proxyhost['jid'] 'jid': proxyhost['jid'],
c['priority'] = (2**16) * type_preference 'priority': priority,
c['initiator'] = self.file_props.sender 'initiator': self.file_props.sender,
c['target'] = self.file_props.receiver 'target': self.file_props.receiver}
proxy_cand.append(c) proxy_cand.append(c)
self._add_candidates(proxy_cand) self._add_candidates(proxy_cand)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment