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
=== modified file 'src/Widgets/WifiInterface.vala'
--- src/Widgets/WifiInterface.vala 2015-08-04 19:30:02 +0000
+++ src/Widgets/WifiInterface.vala 2015-08-06 20:43:54 +0000
@@ -105,8 +105,18 @@
105 if (device != null) { 105 if (device != null) {
106 /* Do not activate connection if it is already activated */106 /* Do not activate connection if it is already activated */
107 if (wifi_device.get_active_access_point () != row.ap) {107 if (wifi_device.get_active_access_point () != row.ap) {
108 var connections = nm_settings.list_connections ();
109 var device_connections = wifi_device.filter_connections (connections);
110 var ap_connections = row.ap.filter_connections (device_connections);
111
112 var valid_connection = get_valid_connection (row.ap, ap_connections);
113 if (valid_connection != null) {
114 nm_client.activate_connection (valid_connection, wifi_device, row.ap.get_path (), null);
115 return;
116 }
117
108 var setting_wireless = new NM.SettingWireless ();118 var setting_wireless = new NM.SettingWireless ();
109 if (setting_wireless.add_seen_bssid(row.ap.get_bssid ())) {119 if (setting_wireless.add_seen_bssid (row.ap.get_bssid ())) {
110 if (row.is_secured) {120 if (row.is_secured) {
111 var remote_settings = new NM.RemoteSettings (null);121 var remote_settings = new NM.RemoteSettings (null);
112122
@@ -138,18 +148,11 @@
138 NM.Device dialog_device;148 NM.Device dialog_device;
139 NM.AccessPoint dialog_ap;149 NM.AccessPoint dialog_ap;
140 var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);150 var dialog_connection = dialog.get_connection (out dialog_device, out dialog_ap);
141151
142 if (get_connection_available (dialog_connection, dialog_device)) {152 client.add_and_activate_connection (dialog_connection,
143 client.activate_connection (dialog_connection,153 dialog_device,
144 dialog_device,154 dialog_ap.get_path (),
145 dialog_ap.get_path (),155 finish_connection_callback);
146 null);
147 } else {
148 client.add_and_activate_connection (dialog_connection,
149 dialog_device,
150 dialog_ap.get_path (),
151 finish_connection_callback);
152 }
153 }); 156 });
154157
155 dialog.run (); 158 dialog.run ();
@@ -170,15 +173,14 @@
170 }173 }
171 }174 }
172175
173 private bool get_connection_available (NM.Connection connection, NM.Device _device) {176 private NM.Connection? get_valid_connection (NM.AccessPoint ap, SList<weak NM.Connection> ap_connections) {
174 bool retval = false;177 foreach (weak NM.Connection connection in ap_connections) {
175 _device.get_available_connections ().@foreach ((_connection) => {178 if (ap.connection_valid (connection)) {
176 if (_connection == connection) {179 return connection;
177 retval = true;180 }
178 } 181 }
179 });
180182
181 return retval;183 return null;
182 }184 }
183185
184 private void finish_connection_callback (NM.Client _client,186 private void finish_connection_callback (NM.Client _client,
@@ -187,11 +189,10 @@
187 Error error) {189 Error error) {
188 bool success = false;190 bool success = false;
189 _client.get_active_connections ().@foreach ((c) => {191 _client.get_active_connections ().@foreach ((c) => {
190 if (c == connection) 192 if (c == connection) {
191 success = true;193 success = true;
194 }
192 });195 });
193
194 }196 }
195
196 }197 }
197}198}

Subscribers

People subscribed via source and target branches

to all changes: