disconnect when avahi-daemon stop responding
fix reference in connection_handlers
This commit is contained in:
parent
b7ceb9ddf7
commit
163cfef3b8
|
@ -470,11 +470,9 @@ class ClientZeroconf:
|
|||
self.ip_to_hash = {}
|
||||
|
||||
def test_avahi(self):
|
||||
#~ self.avahi_error = False
|
||||
try:
|
||||
import avahi
|
||||
except ImportError:
|
||||
#~ self.avahi_error = True
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -489,21 +487,24 @@ class ClientZeroconf:
|
|||
self.roster = roster_zeroconf.Roster(self.zeroconf)
|
||||
|
||||
def remove_announce(self):
|
||||
return self.zeroconf.remove_announce()
|
||||
if self.zeroconf:
|
||||
return self.zeroconf.remove_announce()
|
||||
|
||||
def announce(self):
|
||||
return self.zeroconf.announce()
|
||||
if self.zeroconf:
|
||||
return self.zeroconf.announce()
|
||||
|
||||
def set_show_msg(self, show, msg):
|
||||
self.zeroconf.txt['msg'] = msg
|
||||
self.last_msg = msg
|
||||
return self.zeroconf.update_txt(show)
|
||||
if self.zeroconf:
|
||||
self.zeroconf.txt['msg'] = msg
|
||||
self.last_msg = msg
|
||||
return self.zeroconf.update_txt(show)
|
||||
|
||||
def resolve_all(self):
|
||||
self.zeroconf.resolve_all()
|
||||
if self.zeroconf:
|
||||
self.zeroconf.resolve_all()
|
||||
|
||||
def reannounce(self, txt):
|
||||
#~ if self.zeroconf:
|
||||
self.remove_announce()
|
||||
self.zeroconf.txt = txt
|
||||
self.zeroconf.port = self.port
|
||||
|
@ -538,8 +539,6 @@ class ClientZeroconf:
|
|||
self.roster.zeroconf = None
|
||||
self.roster._data = None
|
||||
self.roster = None
|
||||
#~ self.caller.show = 'offline'
|
||||
#~ self.caller.dispatch('STATUS', 'offline')
|
||||
|
||||
def kill_all_connections(self):
|
||||
for connection in self.connections.values():
|
||||
|
@ -575,7 +574,9 @@ class ClientZeroconf:
|
|||
return False
|
||||
|
||||
def getRoster(self):
|
||||
return self.roster.getRoster()
|
||||
if self.roster:
|
||||
return self.roster.getRoster()
|
||||
return {}
|
||||
|
||||
def send(self, msg_iq):
|
||||
msg_iq.setFrom(self.roster.zeroconf.name)
|
||||
|
|
|
@ -712,8 +712,8 @@ class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream):
|
|||
tim = time.localtime(timegm(tim))
|
||||
frm = msg.getFrom()
|
||||
if frm == None:
|
||||
for key in self.zeroconf.contacts:
|
||||
if ip == self.zeroconf.contacts[key][zeroconf.C_ADDRESS]:
|
||||
for key in self.connection.zeroconf.contacts:
|
||||
if ip == self.connection.zeroconf.contacts[key][zeroconf.C_ADDRESS]:
|
||||
frm = key
|
||||
frm = str(frm)
|
||||
jid = frm
|
||||
|
|
|
@ -203,8 +203,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
|||
(_('Connection with account "%s" has been lost') % self.name,
|
||||
_('To continue sending and receiving messages, you will need to reconnect.')))
|
||||
self.status = 'offline'
|
||||
self.disconnect()
|
||||
|
||||
def connect(self, data = None, show = 'online', msg = ''):
|
||||
def connect(self, show = 'online', msg = ''):
|
||||
self.get_config_values_or_default()
|
||||
if not self.connection:
|
||||
self.connection = client_zeroconf.ClientZeroconf(self)
|
||||
|
@ -214,13 +215,16 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
|||
self.dispatch('CONNECTION_LOST',
|
||||
(_('Could not connect to "%s"') % self.name,
|
||||
_('Please check if Avahi is installed.')))
|
||||
self.disconnect()
|
||||
return
|
||||
self.connection.connect(show, msg)
|
||||
if not self.connection.listener:
|
||||
self.dispatch('STATUS', 'offline')
|
||||
self.status = 'offline'
|
||||
self.dispatch('CONNECTION_LOST',
|
||||
(_('Could not start local service') % self.name,
|
||||
_('Unable to bind to port "%d".' % self.port)))
|
||||
(_('Could not start local service'),
|
||||
_('Please check if avahi-daemon is running.')))
|
||||
self.disconnect()
|
||||
return
|
||||
else:
|
||||
self.connection.announce()
|
||||
|
@ -247,8 +251,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
|||
self.connection = None
|
||||
# stop calling the timeout
|
||||
self.call_resolve_timeout = False
|
||||
|
||||
|
||||
|
||||
def reannounce(self):
|
||||
if self.connected:
|
||||
txt = {}
|
||||
|
@ -266,7 +269,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
|||
self.port = port
|
||||
last_msg = self.connection.last_msg
|
||||
self.disconnect()
|
||||
if not self.connect(show = self.status, msg = last_msg):
|
||||
if not self.connect(self.status, last_msg):
|
||||
return
|
||||
if self.status != 'invisible':
|
||||
self.connection.announce()
|
||||
|
@ -281,7 +284,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
|||
check = True #to check for errors from zeroconf
|
||||
# 'connect'
|
||||
if show != 'offline' and not self.connected:
|
||||
if not self.connect(None, show, msg):
|
||||
if not self.connect(show, msg):
|
||||
return
|
||||
if show != 'invisible':
|
||||
check = self.connection.announce()
|
||||
|
|
|
@ -65,6 +65,9 @@ class Zeroconf:
|
|||
# left for eventual later use
|
||||
pass
|
||||
|
||||
def error_callback1(self, err):
|
||||
gajim.log.debug('RR' + str(err))
|
||||
|
||||
def error_callback(self, err):
|
||||
gajim.log.debug(str(err))
|
||||
# timeouts are non-critical
|
||||
|
@ -80,7 +83,7 @@ class Zeroconf:
|
|||
# synchronous resolving
|
||||
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
||||
domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \
|
||||
reply_handler=self.service_resolved_callback, error_handler=self.error_callback)
|
||||
reply_handler=self.service_resolved_callback, error_handler=self.error_callback1)
|
||||
|
||||
def remove_service_callback(self, interface, protocol, name, stype, domain, flags):
|
||||
gajim.log.debug('Service %s in domain %s on %i.%i disappeared.' % (name, domain, interface, protocol))
|
||||
|
@ -215,9 +218,7 @@ class Zeroconf:
|
|||
else:
|
||||
txt['status'] = 'avail'
|
||||
|
||||
|
||||
self.txt = txt
|
||||
|
||||
gajim.log.debug('Publishing service %s of type %s' % (self.name, self.stype))
|
||||
self.entrygroup.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), self.name, self.stype, '', '', self.port, avahi.dict_to_txt_array(self.txt), reply_handler=self.service_added_callback, error_handler=self.service_add_fail_callback)
|
||||
self.entrygroup.Commit(reply_handler=self.service_committed_callback,
|
||||
|
@ -257,18 +258,34 @@ class Zeroconf:
|
|||
def browse_domain(self, interface, protocol, domain):
|
||||
self.new_service_type(interface, protocol, self.stype, domain, '')
|
||||
|
||||
def avahi_dbus_connect_cb(self, a, connect, disconnect):
|
||||
if connect != "":
|
||||
gajim.log.debug('Lost connection to avahi-daemon')
|
||||
try:
|
||||
self.connected = False
|
||||
self.disconnect()
|
||||
self.disconnected_CB()
|
||||
except Exception, e:
|
||||
print e
|
||||
else:
|
||||
gajim.log.debug('We are connected to avahi-daemon')
|
||||
|
||||
|
||||
|
||||
# connect to dbus
|
||||
def connect_dbus(self):
|
||||
if self.server:
|
||||
return True
|
||||
try:
|
||||
self.bus = dbus.SystemBus()
|
||||
# is there any way to check if a dbus name exists?
|
||||
# that might make the Introspect Error go away...
|
||||
self.bus.add_signal_receiver(self.avahi_dbus_connect_cb,
|
||||
"NameOwnerChanged", "org.freedesktop.DBus",
|
||||
arg0="org.freedesktop.Avahi")
|
||||
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, \
|
||||
avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
|
||||
self.server.connect_to_signal('StateChanged', self.server_state_changed_callback)
|
||||
except dbus.dbus_bindings.DBusException, e:
|
||||
self.server.connect_to_signal('StateChanged',
|
||||
self.server_state_changed_callback)
|
||||
except Exception, e:
|
||||
# Avahi service is not present
|
||||
self.server = None
|
||||
gajim.log.debug(str(e))
|
||||
|
@ -280,8 +297,8 @@ class Zeroconf:
|
|||
self.name = self.username + '@' + self.host # service name
|
||||
if not self.connect_dbus():
|
||||
return False
|
||||
self.connected = True
|
||||
|
||||
self.connected = True
|
||||
# start browsing
|
||||
if self.domain is None:
|
||||
# Explicitly browse .local
|
||||
|
@ -304,11 +321,11 @@ class Zeroconf:
|
|||
self.connected = False
|
||||
if self.service_browser:
|
||||
self.service_browser.Free()
|
||||
self.service_browser = None
|
||||
if self.domain_browser:
|
||||
self.domain_browser.Free()
|
||||
self.domain_browser = None
|
||||
self.remove_announce()
|
||||
self.service_browser = None
|
||||
self.domain_browser = None
|
||||
self.server = None
|
||||
|
||||
# refresh txt data of all contacts manually (no callback available)
|
||||
|
|
|
@ -1413,7 +1413,6 @@ class Interface:
|
|||
response = dlg.get_response()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
new_name = dlg.input_entry.get_text()
|
||||
print 'account, data', account, data, new_name
|
||||
gajim.config.set_per('accounts', account, 'name', new_name)
|
||||
status = gajim.connections[account].status
|
||||
gajim.connections[account].username = new_name
|
||||
|
|
Loading…
Reference in New Issue