Skip to content

Commit acd9080

Browse files
committed
dbus: rauc: add topic that enables/disables polling for updates
Polling for updates should only be done with user consent as it creates a connection to our server, which has privacy implications. Signed-off-by: Leonard Göhrs <[email protected]>
1 parent ba7f058 commit acd9080

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

demo_files/srv/tacd/state.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"format_version": 1,
33
"persistent_topics": {
44
"/v1/tac/display/show_help": false,
5-
"/v1/tac/setup_mode": false
5+
"/v1/tac/setup_mode": false,
6+
"/v1/tac/update/enable_polling": true
67
}
78
}

openapi.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,21 @@ paths:
743743
schema:
744744
type: number
745745

746+
/v1/tac/update/enable_polling:
747+
put:
748+
summary: Enable periodic polling for operating system updates
749+
tags: [Updating]
750+
requestBody:
751+
content:
752+
application/json:
753+
schema:
754+
type: boolean
755+
responses:
756+
'204':
757+
description: Polling for OS updates was enabled/disabled
758+
'400':
759+
description: The value could not be parsed as boolean
760+
746761
/v1/tac/update/operation:
747762
get:
748763
summary: Get the currently running system update operation

src/broker/topic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ impl<E: Serialize + DeserializeOwned + Clone + PartialEq> Topic<E> {
338338
}
339339

340340
/// Wait until the topic is set to the specified value
341-
#[allow(dead_code)]
342341
pub async fn wait_for(self: &Arc<Self>, val: E) {
343342
let (mut stream, sub) = self.clone().subscribe_unbounded();
344343

src/dbus/rauc.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub struct Rauc {
104104
pub channels: Arc<Topic<Vec<Channel>>>,
105105
pub reload: Arc<Topic<bool>>,
106106
pub should_reboot: Arc<Topic<bool>>,
107+
pub enable_polling: Arc<Topic<bool>>,
107108
}
108109

109110
fn compare_versions(v1: &str, v2: &str) -> Option<Ordering> {
@@ -178,6 +179,7 @@ fn would_reboot_into_other_slot(slot_status: &SlotStatus, primary: Option<String
178179

179180
async fn channel_polling_task(
180181
conn: Arc<Connection>,
182+
enable_polling: Arc<Topic<bool>>,
181183
channels: Arc<Topic<Vec<Channel>>>,
182184
slot_status: Arc<Topic<Arc<SlotStatus>>>,
183185
name: String,
@@ -188,6 +190,10 @@ async fn channel_polling_task(
188190
.try_get()
189191
.and_then(|chs| chs.into_iter().find(|ch| ch.name == name))
190192
{
193+
// Make sure update polling is enabled before doing anything,
194+
// as contacting the update server requires user consent.
195+
enable_polling.wait_for(true).await;
196+
191197
let polling_interval = channel.polling_interval;
192198
let slot_status = slot_status.try_get();
193199

@@ -224,6 +230,7 @@ async fn channel_polling_task(
224230
async fn channel_list_update_task(
225231
conn: Arc<Connection>,
226232
mut reload_stream: Receiver<bool>,
233+
enable_polling: Arc<Topic<bool>>,
227234
channels: Arc<Topic<Vec<Channel>>>,
228235
slot_status: Arc<Topic<Arc<SlotStatus>>>,
229236
) {
@@ -266,6 +273,7 @@ async fn channel_list_update_task(
266273
for name in names.into_iter() {
267274
let polling_task = spawn(channel_polling_task(
268275
conn.clone(),
276+
enable_polling.clone(),
269277
channels.clone(),
270278
slot_status.clone(),
271279
name,
@@ -290,6 +298,14 @@ impl Rauc {
290298
channels: bb.topic_ro("/v1/tac/update/channels", None),
291299
reload: bb.topic_wo("/v1/tac/update/channels/reload", Some(true)),
292300
should_reboot: bb.topic_ro("/v1/tac/update/should_reboot", Some(false)),
301+
enable_polling: bb.topic(
302+
"/v1/tac/update/enable_polling",
303+
true,
304+
true,
305+
true,
306+
Some(false),
307+
1,
308+
),
293309
}
294310
}
295311

@@ -306,6 +322,7 @@ impl Rauc {
306322
spawn(channel_list_update_task(
307323
Arc::new(Connection),
308324
reload_stream,
325+
inst.enable_polling.clone(),
309326
inst.channels.clone(),
310327
inst.slot_status.clone(),
311328
));
@@ -488,6 +505,7 @@ impl Rauc {
488505
spawn(channel_list_update_task(
489506
conn.clone(),
490507
reload_stream,
508+
inst.enable_polling.clone(),
491509
inst.channels.clone(),
492510
inst.slot_status.clone(),
493511
));

0 commit comments

Comments
 (0)