Merge lp:~donadigo/switchboard-plug-networking/use-existing-connection into lp:~elementary-pantheon/switchboard-plug-networking/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: xapantu
Approved revision: 137
Merged at revision: 134
Proposed branch: lp:~donadigo/switchboard-plug-networking/use-existing-connection
Merge into: lp:~elementary-pantheon/switchboard-plug-networking/trunk
Diff against target: 84 lines (+25/-24)
1 file modified
src/Widgets/WifiInterface.vala (+25/-24)
To merge this branch: bzr merge lp:~donadigo/switchboard-plug-networking/use-existing-connection
Reviewer Review Type Date Requested Status
xapantu (community) Approve
Review via email: mp+267194@code.launchpad.net

Commit message

* Don't create new connection when it already exists.

Description of the change

The branch fixes very important bug, that makes NetworkManager exceed the limit of connections. Currently the plug blindly creates new connection (without checking if it already exists) and when you use the plug very often it ends up reaching the limit of available connections in the NetworkManager and causing problems with the plug itself.

To post a comment you must log in.
135. By Adam Bieńkowski

Always get a valid connection

136. By Adam Bieńkowski

Simplify get_valid_connection

137. By Adam Bieńkowski

Don't check if list is empty

Revision history for this message
xapantu (xapantu) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/WifiInterface.vala'
2--- src/Widgets/WifiInterface.vala 2015-08-04 19:30:02 +0000
3+++ src/Widgets/WifiInterface.vala 2015-08-06 20:43:54 +0000
4@@ -105,8 +105,18 @@
5 if (device != null) {
6 /* Do not activate connection if it is already activated */
7 if (wifi_device.get_active_access_point () != row.ap) {
8+ var connections = nm_settings.list_connections ();
9+ var device_connections = wifi_device.filter_connections (connections);
10+ var ap_connections = row.ap.filter_connections (device_connections);
11+
12+ var valid_connection = get_valid_connection (row.ap, ap_connections);
13+ if (valid_connection != null) {
14+ nm_client.activate_connection (valid_connection, wifi_device, row.ap.get_path (), null);
15+ return;
16+ }
17+
18 var setting_wireless = new NM.SettingWireless ();
19- if (setting_wireless.add_seen_bssid(row.ap.get_bssid ())) {
20+ if (setting_wireless.add_seen_bssid (row.ap.get_bssid ())) {
21 if (row.is_secured) {
22 var remote_settings = new NM.RemoteSettings (null);
23
24@@ -138,18 +148,11 @@
25 NM.Device dialog_device;
26 NM.AccessPoint dialog_ap;
27 var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);
28-
29- if (get_connection_available (dialog_connection, dialog_device)) {
30- client.activate_connection (dialog_connection,
31- dialog_device,
32- dialog_ap.get_path (),
33- null);
34- } else {
35- client.add_and_activate_connection (dialog_connection,
36- dialog_device,
37- dialog_ap.get_path (),
38- finish_connection_callback);
39- }
40+
41+ client.add_and_activate_connection (dialog_connection,
42+ dialog_device,
43+ dialog_ap.get_path (),
44+ finish_connection_callback);
45 });
46
47 dialog.run ();
48@@ -170,15 +173,14 @@
49 }
50 }
51
52- private bool get_connection_available (NM.Connection connection, NM.Device _device) {
53- bool retval = false;
54- _device.get_available_connections ().@foreach ((_connection) => {
55- if (_connection == connection) {
56- retval = true;
57- }
58- });
59+ private NM.Connection? get_valid_connection (NM.AccessPoint ap, SList<weak NM.Connection> ap_connections) {
60+ foreach (weak NM.Connection connection in ap_connections) {
61+ if (ap.connection_valid (connection)) {
62+ return connection;
63+ }
64+ }
65
66- return retval;
67+ return null;
68 }
69
70 private void finish_connection_callback (NM.Client _client,
71@@ -187,11 +189,10 @@
72 Error error) {
73 bool success = false;
74 _client.get_active_connections ().@foreach ((c) => {
75- if (c == connection)
76+ if (c == connection) {
77 success = true;
78+ }
79 });
80-
81 }
82-
83 }
84 }

Subscribers

People subscribed via source and target branches

to all changes: