diff options
-rw-r--r-- | src/buddy.py | 2 | ||||
-rw-r--r-- | src/linklocal_plugin.py | 30 | ||||
-rw-r--r-- | src/presenceservice.py | 5 | ||||
-rw-r--r-- | src/psutils.py | 28 | ||||
-rw-r--r-- | src/server_plugin.py | 4 | ||||
-rw-r--r-- | src/telepathy_plugin.py | 11 |
6 files changed, 57 insertions, 23 deletions
diff --git a/src/buddy.py b/src/buddy.py index 426a844..84da0a7 100644 --- a/src/buddy.py +++ b/src/buddy.py @@ -906,7 +906,7 @@ class GenericOwner(Buddy): if tp.status == CONNECTION_STATUS_CONNECTED: self._set_self_olpc_properties(tp) - def _ip4_address_changed_cb(self, monitor, address): + def _ip4_address_changed_cb(self, monitor, address, iface): """Handle IPv4 address change, set property to generate event""" props = {_PROP_IP4_ADDRESS: address} self.set_properties(props) diff --git a/src/linklocal_plugin.py b/src/linklocal_plugin.py index 5646018..b741d02 100644 --- a/src/linklocal_plugin.py +++ b/src/linklocal_plugin.py @@ -62,6 +62,10 @@ class LinkLocalPlugin(TelepathyPlugin): self._watch = self._sys_bus.watch_name_owner('org.freedesktop.Avahi', self._avahi_owner_cb) + # Glib source ID indicating we have to wait before be allowed to try + # to connect + self._have_to_wait_id = 0 + def _avahi_owner_cb(self, unique_name): had_avahi = self._have_avahi @@ -89,7 +93,8 @@ class LinkLocalPlugin(TelepathyPlugin): self._watch = None def _could_connect(self): - return TelepathyPlugin._could_connect(self) and self._have_avahi + return TelepathyPlugin._could_connect(self) and self._have_avahi and \ + self._have_to_wait_id == 0 def _get_account_info(self): """Retrieve connection manager parameters for this account @@ -194,3 +199,26 @@ class LinkLocalPlugin(TelepathyPlugin): ret[handle] = 'salut/' + psutils.escape_identifier(ident) return ret + + + def _have_to_wait_cb(self): + if self._have_to_wait_id > 0: + gobject.source_remove(self._have_to_wait_id) + self._have_to_wait_id = 0 + + _logger.debug("Timeout elapsed. Salut can connect now") + self.start() + + def _ip4_address_changed_cb(self, ip4am, address, iface): + TelepathyPlugin._ip4_address_changed_cb(self, ip4am, address, iface) + + # FIXME: what about IPv6 ? + if iface == "msh0" and not address.startswith("169.254."): + # msh0 got a not link-local IP so we are connected to a school + # server. Let's disable Salut. See #6299 for details. + _logger.debug("Connected to a school server. Disable Salut") + self._stop() + + # Salut can't connect during the next 2 minutes + self._have_to_wait_id = gobject.timeout_add(120000, + self._have_to_wait_cb) diff --git a/src/presenceservice.py b/src/presenceservice.py index fa38efd..02a5ba4 100644 --- a/src/presenceservice.py +++ b/src/presenceservice.py @@ -148,9 +148,12 @@ class PresenceService(ExportedGObject): def _tp_status_cb(self, plugin, status, reason): if status == CONNECTION_STATUS_CONNECTED: self._tp_connected(plugin) - if plugin == self._server_plugin and self._ll_plugin: + if (plugin == self._server_plugin and self._ll_plugin) or \ + (plugin == self._ll_plugin and self._server_plugin and \ + self._server_plugin.status == CONNECTION_STATUS_CONNECTED): # For now, Gabble takes precedence over Salut to alleviate # corner cases where laptops on mesh can't talk to ones on APs + _logger.debug("Gabble takes precedence, disconnect Salut") self._ll_plugin.cleanup() else: self._tp_disconnected(plugin) diff --git a/src/psutils.py b/src/psutils.py index 6b8ec95..f7c6db7 100644 --- a/src/psutils.py +++ b/src/psutils.py @@ -129,7 +129,7 @@ class IP4AddressMonitor(gobject.GObject): __gsignals__ = { 'address-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) + ([gobject.TYPE_PYOBJECT, gobject.TYPE_STRING])) } __gproperties__ = { @@ -155,22 +155,22 @@ class IP4AddressMonitor(gobject.GObject): sys_bus = dbus.SystemBus() self._watch = sys_bus.watch_name_owner(NM_SERVICE, self._nm_owner_cb) if not sys_bus.name_has_owner(NM_SERVICE): - addr = self._get_address_fallback() - self._update_address(addr) + addr, iface = self._get_address_fallback() + self._update_address(addr, iface) def do_get_property(self, pspec): if pspec.name == "address": return self._addr - def _update_address(self, new_addr): + def _update_address(self, new_addr, iface): if new_addr == "0.0.0.0": new_addr = None if new_addr == self._addr: return self._addr = new_addr - _logger.debug("IP4 address now '%s'" % new_addr) - self.emit('address-changed', new_addr) + _logger.debug("IP4 address now '%s' (%s)" % (new_addr, iface)) + self.emit('address-changed', new_addr, iface) def _connect_to_nm(self): """Connect to NM device state signals to tell when the IPv4 address changes""" @@ -215,7 +215,7 @@ class IP4AddressMonitor(gobject.GObject): if act_stage != 8 and act_stage != 7: # not activated return - self._update_address(props[6]) + self._update_address(props[6], props[1]) def _device_properties_error_cb(self, err): _logger.debug("Error querying device properties: %s" % err) @@ -244,11 +244,11 @@ class IP4AddressMonitor(gobject.GObject): self._query_device_properties(device) def _nm_device_no_longer_active_cb(self, device): - self._update_address(None) + self._update_address(None, None) def _nm_state_change_cb(self, new_state): if new_state == 4: # NM_STATE_DISCONNECTED - self._update_address(None) + self._update_address(None, None) def _nm_owner_cb(self, unique_name): """Clear state when NM goes away""" @@ -259,10 +259,10 @@ class IP4AddressMonitor(gobject.GObject): match.remove() self._matches = [] if self._nm_has_been_present: - self._update_address(None) + self._update_address(None, None) else: - addr = self._get_address_fallback() - self._update_address(addr) + addr, iface = self._get_address_fallback() + self._update_address(addr, iface) elif not self._nm_present: # NM started up self._nm_present = True @@ -278,7 +278,7 @@ class IP4AddressMonitor(gobject.GObject): SIOCGIFADDR = 0x8915 addr = fcntl.ioctl(fd, SIOCGIFADDR, struct.pack('256s', iface[:15]))[20:24] s.close() - return socket.inet_ntoa(addr) + return socket.inet_ntoa(addr), iface def _get_address_fallback(self): import commands @@ -290,4 +290,4 @@ class IP4AddressMonitor(gobject.GObject): if fields[0] == "0.0.0.0": iface = fields[len(fields) - 1] return self._get_iface_address(iface) - return None + return None, None diff --git a/src/server_plugin.py b/src/server_plugin.py index 4a32042..8d0a4f0 100644 --- a/src/server_plugin.py +++ b/src/server_plugin.py @@ -62,8 +62,8 @@ class ServerPlugin(TelepathyPlugin): self._friends_channel = None - def _ip4_address_changed_cb(self, ip4am, address): - TelepathyPlugin._ip4_address_changed_cb(self, ip4am, address) + def _ip4_address_changed_cb(self, ip4am, address, iface): + TelepathyPlugin._ip4_address_changed_cb(self, ip4am, address, iface) if address: _logger.debug("::: valid IP4 address, conn_status %s" % diff --git a/src/telepathy_plugin.py b/src/telepathy_plugin.py index c486884..0fb4b05 100644 --- a/src/telepathy_plugin.py +++ b/src/telepathy_plugin.py @@ -163,9 +163,6 @@ class TelepathyPlugin(gobject.GObject): """ raise NotImplementedError - def start(self): - raise NotImplementedError - def suggest_room_for_activity(self, activity_id): """Suggest a room to use to share the given activity. """ @@ -340,6 +337,7 @@ class TelepathyPlugin(gobject.GObject): self._backoff_id = 0 self._ip4am.disconnect(self._ip4am_sigid) + self._ip4am_sigid = 0 def _contacts_offline(self, handles): """Handle contacts going offline (send message, update set)""" @@ -544,6 +542,11 @@ class TelepathyPlugin(gobject.GObject): otherwise initiate a connection and transfer control to _connect_reply_cb or _connect_error_cb """ + + if self._ip4am_sigid == 0: + self._ip4am_sigid = self._ip4am.connect('address-changed', + self._ip4_address_changed_cb) + if self._conn is not None: return @@ -555,7 +558,7 @@ class TelepathyPlugin(gobject.GObject): else: _logger.debug('%r: Postponing connection', self) - def _ip4_address_changed_cb(self, ip4am, address): + def _ip4_address_changed_cb(self, ip4am, address, iface): _logger.debug("::: IP4 address now %s", address) self._reconnect_timeout = self._RECONNECT_INITIAL_TIMEOUT |