Remove the "expected" next ID

It's an unnecessary extra layer better handled locally.
This commit is contained in:
Luke Parker
2023-09-27 11:10:12 -04:00
parent 90318d7214
commit 269db1c4be
6 changed files with 12 additions and 18 deletions

View File

@@ -140,9 +140,9 @@ impl MessageQueue {
}
}
pub async fn next(&self, expected: u64) -> QueuedMessage {
pub async fn next(&self) -> QueuedMessage {
loop {
let json = self.json_call("next", serde_json::json!([self.service, expected])).await;
let json = self.json_call("next", serde_json::json!([self.service])).await;
// Convert from a Value to a type via reserialization
let msg: Option<QueuedMessage> = serde_json::from_str(
@@ -174,7 +174,6 @@ impl MessageQueue {
);
}
// TODO: Verify the sender's signature
// TODO: Check the ID is sane
return msg;
}

View File

@@ -107,16 +107,11 @@ mod binaries {
/*
Gets the next message in queue for this service.
This is not authenticated due to the fact every nonce would have to be saved to prevent replays,
or a challenge-response protocol implemented. Neither are worth doing when there should be no
sensitive data on this server.
The expected index is used to ensure a service didn't fall out of sync with this service. It
should always be either the next message's ID or *TODO*.
This is not authenticated due to the fact every nonce would have to be saved to prevent
replays, or a challenge-response protocol implemented. Neither are worth doing when there
should be no sensitive data on this server.
*/
pub(crate) fn get_next_message(service: Service, _expected: u64) -> Option<QueuedMessage> {
// TODO: Verify the expected next message ID matches
pub(crate) fn get_next_message(service: Service) -> Option<QueuedMessage> {
let queue_outer = (*QUEUES).read().unwrap();
let queue = queue_outer[&service].read().unwrap();
let next = queue.last_acknowledged().map(|i| i + 1).unwrap_or(0);
@@ -229,8 +224,8 @@ async fn main() {
.unwrap();
module
.register_method("next", |args, _| {
let args = args.parse::<(Service, u64)>().unwrap();
Ok(get_next_message(args.0, args.1))
let args = args.parse::<Service>().unwrap();
Ok(get_next_message(args))
})
.unwrap();
module