Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

feat: add megaphone broadcast handling, ping check, server tracking #1152

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

bbangert
Copy link
Member

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.

@codecov-io
Copy link

codecov-io commented Mar 13, 2018

Codecov Report

Merging #1152 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1152   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          60      60           
  Lines        9940    9940           
======================================
  Hits         9940    9940

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b0be54...1fe4eeb. Read the comment docs.

alexcrichton
alexcrichton previously approved these changes Mar 13, 2018
Copy link
Contributor

@alexcrichton alexcrichton left a 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>,
Copy link
Contributor

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>

Copy link
Member Author

@bbangert bbangert Mar 13, 2018

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>?

Copy link
Member

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
Copy link
Member Author

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 }) => {
Copy link
Member

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.

Copy link
Member Author

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.

@bbangert bbangert force-pushed the feat/issue-1129.2 branch 3 times, most recently from df46ebe to edd627a Compare March 13, 2018 17:04
jrconlin
jrconlin previously approved these changes Mar 13, 2018
@@ -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());
Copy link
Member

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())

self.waiting = WaitingFor::SendPing;
socket.broadcast_delta = None;
} else {
let at = Instant::now() + self.srv.opts.auto_ping_timeout;
Copy link
Member

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

val.into_iter().map(|v| v.into()).collect()
}

pub fn to_hashmap(service_vec: Vec<Service>) -> HashMap<String, String> {
Copy link
Member

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>,
Copy link
Member

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>> {
Copy link
Member

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() {
Copy link
Member

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

Copy link
Member Author

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.

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
@bbangert bbangert force-pushed the feat/issue-1129.2 branch from 9ec6808 to 1fe4eeb Compare March 13, 2018 22:14
@bbangert bbangert merged commit a98c045 into master Mar 13, 2018
@bbangert bbangert deleted the feat/issue-1129.2 branch March 13, 2018 22:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants