ability to discover STUN server with SRV records of jabber server

This commit is contained in:
Yann Leboulanger 2010-01-07 18:02:05 +01:00
parent e8b88db629
commit c1d0013cb0
6 changed files with 52 additions and 15 deletions

View File

@ -2128,7 +2128,7 @@ $T will be replaced by auto-not-available timeout</property>
<child>
<widget class="GtkTable" id="table9">
<property name="visible">True</property>
<property name="n_columns">3</property>
<property name="n_columns">4</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
@ -2148,8 +2148,8 @@ $T will be replaced by auto-not-available timeout</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="left_attach">3</property>
<property name="right_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@ -2157,12 +2157,28 @@ $T will be replaced by auto-not-available timeout</property>
<widget class="GtkEntry" id="stun_server_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">STUN server hostname. If none given, Gajim will try
to discover one from server.</property>
<property name="invisible_char">&#x25CF;</property>
<signal name="changed" handler="stun_server_entry_changed"/>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="stun_checkbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_stun_checkbutton_toggled"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</widget>

View File

@ -277,6 +277,7 @@ class Config:
'audio_output_device': [opt_str, 'autoaudiosink'],
'video_input_device': [opt_str, 'autovideosrc ! videoscale ! ffmpegcolorspace'],
'video_output_device': [opt_str, 'autovideosink'],
'use_stun_server': [opt_bool, True, _('If True, Gajim will try to use a STUN server when using jingle. The one in "stun_server" option, or the one given by the jabber server.')],
'stun_server': [opt_str, '', _('STUN server to use when using jingle')],
}

View File

@ -150,6 +150,7 @@ class CommonConnection:
self.private_storage_supported = False
self.muc_jid = {} # jid of muc server for each transport type
self._stun_servers = [] # STUN servers of our jabber server
self.get_config_values_or_default()
@ -1508,6 +1509,13 @@ class Connection(CommonConnection, ConnectionHandlers):
self.discoverInfo(gajim.config.get_per('accounts', self.name, 'hostname'),
id_prefix='Gajim_')
self.privacy_rules_requested = False
# Discover Stun server(s)
gajim.resolver.resolve('_stun._udp.' + helpers.idn_to_ascii(
self.connected_hostname), self._on_stun_resolved)
def _on_stun_resolved(self, host, result_array):
if len(result_array) != 0:
self._stun_servers = self._hosts = [i for i in result_array]
def _request_privacy(self):
iq = common.xmpp.Iq('get', common.xmpp.NS_PRIVACY, xmlns = '')

View File

@ -213,8 +213,7 @@ class ConnectionDisco:
continue
items.append(attr)
jid = helpers.get_full_jid_from_iq(iq_obj)
hostname = gajim.config.get_per('accounts', self.name,
'hostname')
hostname = gajim.config.get_per('accounts', self.name, 'hostname')
id_ = iq_obj.getID()
if jid == hostname and id_[:6] == 'Gajim_':
for item in items:

View File

@ -72,15 +72,18 @@ class JingleRTPContent(JingleContent):
# pidgin and telepathy-gabble don't follow the XEP, and it won't work
# due to bad controlling-mode
params = {'controlling-mode': self.session.weinitiate, 'debug': False}
stun_server = gajim.config.get('stun_server')
if stun_server:
try:
ip = socket.getaddrinfo(stun_server, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM)[0][4][0]
except socket.gaierror, (errnum, errstr):
log.warn('Lookup of stun ip failed: %s' % errstr)
else:
params['stun-ip'] = ip
if gajim.config.get('use_stun_server'):
stun_server = gajim.config.get('stun_server')
if not stun_server and self._stun_servers:
stun_server = self._stun_servers[0]['host']
if stun_server:
try:
ip = socket.getaddrinfo(stun_server, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM)[0][4][0]
except socket.gaierror, (errnum, errstr):
log.warn('Lookup of stun ip failed: %s' % errstr)
else:
params['stun-ip'] = ip
self.p2pstream = self.p2psession.new_stream(participant,
farsight.DIRECTION_RECV, 'nice', params)

View File

@ -452,9 +452,15 @@ class PreferencesWindow:
combobox = self.xml.get_widget(opt_name + '_combobox')
combobox.set_sensitive(False)
# Connection
# STUN
cb = self.xml.get_widget('stun_checkbutton')
st = gajim.config.get('use_stun_server')
cb.set_active(st)
entry = self.xml.get_widget('stun_server_entry')
entry.set_text(gajim.config.get('stun_server'))
if not st:
entry.set_sensitive(False)
### Advanced tab ###
# open links with
@ -1085,6 +1091,10 @@ class PreferencesWindow:
def on_video_output_combobox_changed(self, widget):
self.on_av_combobox_changed(widget, 'video_output')
def on_stun_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'use_stun_server',
[self.xml.get_widget('stun_server_entry')])
def stun_server_entry_changed(self, widget):
gajim.config.set('stun_server', widget.get_text().decode('utf-8'))