Skip to content

Commit 335ac91

Browse files
committed
Finish doc comment
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
1 parent 397dac9 commit 335ac91

File tree

1 file changed

+25
-17
lines changed
  • crates/extensions/tedge_mqtt_bridge/src

1 file changed

+25
-17
lines changed

crates/extensions/tedge_mqtt_bridge/src/lib.rs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ impl<'a, T> BidirectionalChannelHalf<T> {
159159
/// Forward messages received from `recv_event_loop` to `target`
160160
///
161161
/// The result of running this function constitutes half the MQTT bridge, hence the name.
162-
/// Each half has two main responsibilities, one is to take messages received on the event
163-
/// loop and forward them to the target client, the other is to communicate with the corresponding
164-
/// half of the bridge to ensure published messages get acknowledged only when they have been
165-
/// fully processed.
162+
/// Each half has two main responsibilities, one is to take messages received on the event loop and
163+
/// forward them to the target client, the other is to communicate with the companion half of the
164+
/// bridge to ensure published messages get acknowledged only when they have been fully processed.
166165
///
167166
/// # Message flow
168167
/// Messages in the bridge go through a few states
@@ -184,14 +183,25 @@ impl<'a, T> BidirectionalChannelHalf<T> {
184183
///
185184
/// The channel sends [Option<Publish>] rather than [Publish] to allow the bridge to send entirely
186185
/// novel messages, and not just forwarded ones, as attaching packet IDs relies on pairing every
187-
/// [Outgoing] publish notification with a message sent by the relevant client. This means the
186+
/// [Outgoing] publish notification with a message sent by the relevant client. So, when a QoS 1
187+
/// message is forwarded, this will be accompanied by sending `Some(message)` to the channel,
188+
/// allowing the original message to be acknowledged once an acknowledgement is received for the
189+
/// forwarded message. When publishing a health message, this will be accompanied by sending `None`
190+
/// to the channel, telling the bridge to ignore the associated packet ID as this didn't arise from
191+
/// a forwarded message that itself requires acknowledgement.
188192
///
189193
/// # Health topics
194+
/// The bridge will publish health information to `health_topic` (if supplied) on `target` to enable
195+
/// other components to establish bridge health. This is intended to be used the half with cloud
196+
/// event loop, so the status of this connection will be relayed to a relevant `te` topic like its
197+
/// mosquitto-based predecessor. The payload is either `1` (healthy) or `0` (unhealthy). When the
198+
/// connection is created, the last-will message is set to send the `0` payload when the connection
199+
/// is dropped.
190200
async fn half_bridge<F: for<'a> Fn(&'a str) -> Cow<'a, str>>(
191201
mut recv_event_loop: EventLoop,
192202
target: AsyncClient,
193203
transform_topic: F,
194-
mut corresponding_bridge_half: BidirectionalChannelHalf<Option<Publish>>,
204+
mut companion_bridge_half: BidirectionalChannelHalf<Option<Publish>>,
195205
health_topic: Option<String>,
196206
name: &'static str,
197207
) {
@@ -209,7 +219,7 @@ async fn half_bridge<F: for<'a> Fn(&'a str) -> Cow<'a, str>>(
209219
.publish(health_topic, QoS::AtLeastOnce, true, C8Y_BRIDGE_UP_PAYLOAD)
210220
.await
211221
.unwrap();
212-
corresponding_bridge_half.send(None).await.unwrap();
222+
companion_bridge_half.send(None).await.unwrap();
213223
}
214224
}
215225
notification
@@ -229,7 +239,7 @@ async fn half_bridge<F: for<'a> Fn(&'a str) -> Cow<'a, str>>(
229239
)
230240
.await
231241
.unwrap();
232-
corresponding_bridge_half.send(None).await.unwrap();
242+
companion_bridge_half.send(None).await.unwrap();
233243
}
234244
}
235245
continue;
@@ -248,7 +258,7 @@ async fn half_bridge<F: for<'a> Fn(&'a str) -> Cow<'a, str>>(
248258
.await
249259
.unwrap();
250260
let publish = (publish.qos > QoS::AtMostOnce).then_some(publish);
251-
corresponding_bridge_half.send(publish).await.unwrap();
261+
companion_bridge_half.send(publish).await.unwrap();
252262
}
253263
// Forwarding acks from event loop to target
254264
Event::Incoming(
@@ -259,15 +269,13 @@ async fn half_bridge<F: for<'a> Fn(&'a str) -> Cow<'a, str>>(
259269
target.ack(&msg).await.unwrap();
260270
}
261271
}
262-
Event::Outgoing(Outgoing::Publish(pkid)) => {
263-
match corresponding_bridge_half.recv().await {
264-
Some(Some(msg)) => {
265-
forward_pkid_to_received_msg.insert(pkid, msg);
266-
}
267-
Some(None) => {}
268-
None => break,
272+
Event::Outgoing(Outgoing::Publish(pkid)) => match companion_bridge_half.recv().await {
273+
Some(Some(msg)) => {
274+
forward_pkid_to_received_msg.insert(pkid, msg);
269275
}
270-
}
276+
Some(None) => {}
277+
None => break,
278+
},
271279
_ => {}
272280
}
273281
}

0 commit comments

Comments
 (0)