[Dextrose] [PATCH sugar] Add support for connecting to shared upstream network connections via Ad-hoc

Sascha Silbe silbe at activitycentral.com
Sat Sep 15 04:35:05 EDT 2012


Before, Sugar implicitly assumed all ad-hoc networks are peer-to-peer,
using link-local addressing. However, unlike infrastructure mode
wireless networks, where there's a clear "master" node (the Access
Point) and for most networks the AP is providing DHCP & co for clients
to use, there's no such obvious model for Ad-hoc. Some networks, like
those set up by Sugar by default, are fully peer-to-peer and use
link-local addressing. Others are created by a "master" node, often
used to provide access to some upstream network (e.g. the
internet). Various other ways of organising an ad-hoc network are in
active development (e.g. B.A.T.M.A.N).

Since there's neither a predominant model nor a way to reliably
determine the model in use for a particular network before connecting
to it (and NetworkManager can't do the detection automatically
either), we need to use some kind of heuristic.

Two kinds of models can be guessed from the SSID with reasonable
accuracy:

1. The default Ad-hoc network "channels" create by Sugar by default
   (on channels 1, 3 and 11), being fully peer-to-peer and using
   link-local addressing. The SSID of these networks is "Ad-hoc
   Network <channel number>".

2. Upstream network connections shared by Dextrose (and probably
   future Sugar upstream versions). These use an SSID of "<user name>
   network".

For any other network, we'll try DHCP, just in case it's an ad-hoc
network created with nm-applet (Gnome).

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
This is a cleaned-up version of a three-line patch we've been shipping
in Dextrose ever since the 3G sharing feature landed in 2010.


 src/jarabe/desktop/networkviews.py |   17 ++++++++++++++++-
 src/jarabe/model/network.py        |   22 ++++++++++++++++++----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
index c949b7e..52ebf68 100644
--- a/src/jarabe/desktop/networkviews.py
+++ b/src/jarabe/desktop/networkviews.py
@@ -357,7 +357,22 @@ class WirelessNetworkView(EventPulsingIcon):
             settings.wireless.mode = 'adhoc'
             settings.wireless.band = 'bg'
             settings.ip4_config = IP4Config()
-            settings.ip4_config.method = 'link-local'
+            if network.is_sugar_adhoc_network(self._ssid):
+                # The 3 default Sugar "ad-hoc channels" are
+                # peer-to-peer with link-local addressing.
+                settings.ip4_config.method = 'link-local'
+            elif network.is_sugar_shared_network(self._ssid):
+                # Upstream connection shared by another computer
+                # running Sugar. The sharer set up DHCP & co for us to
+                # use.
+                settings.ip4_config.method = 'auto'
+            else:
+                # We don't recognise the type of network. As a random
+                # guess, try DHCP.
+                # TODO: When support for falling back to link-local on
+                # DHCP failure lands in upstream NetworkManager, we
+                # should switch to that.
+                settings.ip4_config.method = 'auto'
 
         wireless_security = self._get_security()
         settings.wireless_security = wireless_security
diff --git a/src/jarabe/model/network.py b/src/jarabe/model/network.py
index 930ba13..0f76631 100644
--- a/src/jarabe/model/network.py
+++ b/src/jarabe/model/network.py
@@ -330,15 +330,29 @@ def frequency_to_channel(frequency):
 
 
 def is_sugar_adhoc_network(ssid):
-    """Checks whether an access point is a sugar Ad-hoc network.
+    """Check whether an access point is a sugar Ad-hoc network.
+
+    Return True if the network identified by ssid is likely to be a
+    Sugar Ad-hoc network channel (peer-to-peer, using link-local
+    addressing), or False otherwise.
 
     Keyword arguments:
-    ssid -- Ssid of the access point.
+    ssid -- SSID of the access point
+    """
+    return ssid.startswith('Ad-hoc Network ')
+
 
-    Return: Boolean
+def is_sugar_shared_network(ssid):
+    """Check whether the AP is sharing an upstream connection via Sugar
 
+    Return True if the network identified by ssid is likely to be
+    sharing an upstream network connection via Sugar, or False
+    otherwise.
+
+    Keyword arguments:
+    ssid -- SSID of the access point
     """
-    return ssid.startswith('Ad-hoc Network')
+    return ssid.endswith(' network')
 
 
 class WirelessSecurity(object):
-- 
1.7.10.4



More information about the Dextrose mailing list