-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add megaphone broadcast handling, ping check, server tracking #1152
Conversation
12573a5
to
b5c332a
Compare
Codecov Report
@@ Coverage Diff @@
## master #1152 +/- ##
======================================
Coverage 100% 100%
======================================
Files 60 60
Lines 9940 9940
======================================
Hits 9940 9940 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
@@ -570,15 +615,18 @@ where | |||
rotate_message_table: bool, | |||
check_storage: bool, | |||
connected_at: u64, | |||
services: &Vec<Service>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW &[T]
tends to be more idiomatic rather than &Vec<T>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, is that used only when its a reference, or just in general as its shorter than Vec<T>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He just meant for &Vec. If you're not doing anything too Vec specific, more types are able to deref into &[T] so it's good practice to prefer the slice type. I just linked this doc so, here's its further explanation https://deterministic.space/elegant-apis-in-rust.html#use-conversion-traits
@@ -479,7 +524,7 @@ where | |||
Either::A(ClientMessage::Nack { .. }) => { | |||
self.data.srv.metrics.incr("ua.command.nack").ok(); | |||
self.data.webpush.as_mut().unwrap().stats.nacks += 1; | |||
ClientState::WaitingForAcks | |||
ClientState::Await |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug I noticed and fixed here, as its supposed to return to the prior state.
@@ -422,6 +439,20 @@ where | |||
return Ok(next_state.into()); | |||
} | |||
match try_ready!(self.data.input_or_notif()) { | |||
Either::A(ClientMessage::BroadcastSubscribe { broadcasts }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "broadcasts" is being used as a parameter, local variable and key here. It's a bit confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used to destructure, then its re-bound locally as the Vec, and passed into a function. I can remove an intermediary reassignment though and pass the resulting Vec directly to the single use of it in a function, that might clear it up some.
df46ebe
to
edd627a
Compare
autopush_rs/src/server/mod.rs
Outdated
@@ -659,8 +702,20 @@ impl<T> WebpushSocket<T> { | |||
Error: From<T::SinkError>, | |||
{ | |||
if self.ping { | |||
debug!("sending a ping"); | |||
match self.inner.start_send(Message::Ping(Vec::new()))? { | |||
let mut msg = Message::Ping(Vec::new()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy mut kill here: let msg = if let etc else Message::Ping(Vec::new())
autopush_rs/src/server/mod.rs
Outdated
self.waiting = WaitingFor::SendPing; | ||
socket.broadcast_delta = None; | ||
} else { | ||
let at = Instant::now() + self.srv.opts.auto_ping_timeout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these 2 lines are duplicated in both cases
autopush_rs/src/util/megaphone.rs
Outdated
val.into_iter().map(|v| v.into()).collect() | ||
} | ||
|
||
pub fn to_hashmap(service_vec: Vec<Service>) -> HashMap<String, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function consumes service_vec so one of the rust naming conventions prefers it called into_hashmap https://deterministic.space/elegant-apis-in-rust.html#more-method-name-conventions
@@ -570,15 +615,18 @@ where | |||
rotate_message_table: bool, | |||
check_storage: bool, | |||
connected_at: u64, | |||
services: &Vec<Service>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He just meant for &Vec. If you're not doing anything too Vec specific, more types are able to deref into &[T] so it's good practice to prefer the slice type. I just linked this doc so, here's its further explanation https://deterministic.space/elegant-apis-in-rust.html#use-conversion-traits
/// Update a `ClientServices` to account for a new service. | ||
/// | ||
/// Returns services that have changed. | ||
pub fn client_service_add_service(&self, client_service: &mut ClientServices, services: &[Service]) -> Option<Vec<Service>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long line! (we could use cargo fmt run, separate commit though)
/// Returns services that have changed. | ||
pub fn client_service_add_service(&self, client_service: &mut ClientServices, services: &[Service]) -> Option<Vec<Service>> { | ||
let mut svc_delta = self.change_count_delta(client_service).unwrap_or(Vec::new()); | ||
for svc in services.iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off hand i don't know if it's easily refactorable/doable but: service_delta has a very similar loop here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, they both need to do slightly different things though, so I didn't see any way to abstract it out.
edd627a
to
9ec6808
Compare
Handles broadcast subscriptions per client, holds a single broadcast change set tracker, and sends out broadcasts at the ping interval to clients that have new broadcast deltas to send. Issue #1129
9ec6808
to
1fe4eeb
Compare
Handles broadcast subscriptions per client, holds a single broadcast
change set tracker, and sends out broadcasts at the ping interval to
clients that have new broadcast deltas to send.
Issue #1129
Note: Only remaining work is to add the megaphone polling portion that grabs the broadcast master list and keeps it up to date.