From ef815ec2c23030035aaef7047db57368c1fabfca Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Sat, 10 Jul 2021 09:28:55 +0200 Subject: [PATCH] reformat files with cargo fmt --- src/auth.rs | 15 +++++++++------ src/lib.rs | 35 +++++++++++++++++++++-------------- src/sessions.rs | 2 -- src/switchboard.rs | 6 ++---- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 55172ce..b4f14b6 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,25 +1,28 @@ +use crate::messages::RoomId; use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation}; use serde::{Deserialize, Serialize}; use std::error::Error; -use crate::messages::RoomId; #[derive(Debug, Clone, PartialEq, Eq)] pub struct ValidatedToken { pub join_hub: bool, pub kick_users: bool, - pub room_ids: Option> + pub room_ids: Option>, } impl ValidatedToken { pub fn may_join(&self, room_id: &RoomId) -> bool { if self.join_hub { if let Some(allowed_rooms) = &self.room_ids { - if allowed_rooms.contains(room_id) { // this token explicitly lets you in this room + if allowed_rooms.contains(room_id) { + // this token explicitly lets you in this room true - } else { // this token lets you in some rooms, but not this one + } else { + // this token lets you in some rooms, but not this one false } - } else { // this token lets you in any room + } else { + // this token lets you in any room true } } else { @@ -35,7 +38,7 @@ struct UserClaims { #[serde(default)] kick_users: bool, #[serde(default)] - room_ids: Option> + room_ids: Option>, } impl ValidatedToken { diff --git a/src/lib.rs b/src/lib.rs index cc1ea6b..b0d4000 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,8 +12,8 @@ use janus_plugin::sdp::{AudioCodec, MediaDirection, OfferAnswerParameters, Sdp, use janus_plugin::utils::LibcString; use janus_plugin::{ answer_sdp, build_plugin, export_plugin, janus_err, janus_huge, janus_info, janus_verb, janus_warn, offer_sdp, JanssonDecodingFlags, JanssonEncodingFlags, - JanssonValue, JanusError, JanusResult, LibraryMetadata, Plugin, PluginCallbacks, PluginResult, PluginSession, - PluginRtpPacket, PluginRtcpPacket, PluginDataPacket, RawJanssonValue, RawPluginResult, + JanssonValue, JanusError, JanusResult, LibraryMetadata, Plugin, PluginCallbacks, PluginDataPacket, PluginResult, PluginRtcpPacket, PluginRtpPacket, + PluginSession, RawJanssonValue, RawPluginResult, }; use messages::{JsepKind, MessageKind, OptionalField, Subscription}; use messages::{RoomId, UserId}; @@ -179,7 +179,13 @@ fn send_message, U: AsRef>(body: &JsonValue, for session in sessions { let handle = session.as_ref().handle; janus_huge!("Signalling message going to {:p}: {}.", handle, body); - let result = JanusError::from(push_event(handle, &PLUGIN as *const Plugin as *mut Plugin, ptr::null(), msg.as_mut_ref(), ptr::null_mut())); + let result = JanusError::from(push_event( + handle, + &PLUGIN as *const Plugin as *mut Plugin, + ptr::null(), + msg.as_mut_ref(), + ptr::null_mut(), + )); match result { Ok(_) => (), Err(JanusError { code: 458 }) => { @@ -198,7 +204,13 @@ fn send_offer, U: AsRef>(offer: &JsonValue, s for session in sessions { let handle = session.as_ref().handle; janus_huge!("Offer going to {:p}: {}.", handle, offer); - let result = JanusError::from(push_event(handle, &PLUGIN as *const Plugin as *mut Plugin, ptr::null(), msg.as_mut_ref(), jsep.as_mut_ref())); + let result = JanusError::from(push_event( + handle, + &PLUGIN as *const Plugin as *mut Plugin, + ptr::null(), + msg.as_mut_ref(), + jsep.as_mut_ref(), + )); match result { Ok(_) => (), Err(JanusError { code: 458 }) => { @@ -218,7 +230,7 @@ fn send_fir, U: AsRef>(publishers: T) { let mut packet = PluginRtcpPacket { video: 1, buffer: fir.as_mut_ptr(), - length: fir.len() as i16 + length: fir.len() as i16, }; relay_rtcp(publisher.as_ref().as_ptr(), &mut packet); } @@ -267,7 +279,8 @@ extern "C" fn init(callbacks: *mut PluginCallbacks, config_path: *const c_char) janus_err!("Error processing message: {}", e); } } - }).expect("Failed to spawn message thread."); + }) + .expect("Failed to spawn message thread."); janus_verb!("Message processing thread {} is alive.", i); } @@ -318,7 +331,7 @@ extern "C" fn destroy_session(handle: *mut PluginSession, error: *mut c_int) { if let Some(joined) = sess.join_state.get() { match joined.kind { JoinKind::Publisher => switchboard.leave_publisher(&sess), - JoinKind::Subscriber => switchboard.leave_subscriber(&sess) + JoinKind::Subscriber => switchboard.leave_subscriber(&sess), } // if this user is entirely disconnected, notify their roommates. // todo: is it better if this is instead when their publisher disconnects? @@ -433,13 +446,7 @@ fn process_join(from: &Arc, room_id: RoomId, user_id: UserId, subscribe } } Err(e) => { - janus_warn!( - "Rejecting join from {:p} to room {} as user {}. Error: {}", - from.handle, - room_id, - user_id, - e - ); + janus_warn!("Rejecting join from {:p} to room {} as user {}. Error: {}", from.handle, room_id, user_id, e); return Err(From::from("Rejecting join with invalid token!")); } }, diff --git a/src/sessions.rs b/src/sessions.rs index dfe79fa..6ef1f1c 100644 --- a/src/sessions.rs +++ b/src/sessions.rs @@ -32,7 +32,6 @@ impl JoinState { } } - /// The state associated with a single session. #[derive(Debug)] pub struct SessionState { @@ -48,7 +47,6 @@ pub struct SessionState { // todo: these following fields should be unified with the JoinState, but it's // annoying in practice because they are established during JSEP negotiation // rather than during the join flow - /// If this is a subscriber, the subscription this user has established, if any. pub subscription: OnceCell, diff --git a/src/switchboard.rs b/src/switchboard.rs index 237a583..c61a5d7 100644 --- a/src/switchboard.rs +++ b/src/switchboard.rs @@ -2,9 +2,9 @@ use crate::messages::{RoomId, UserId}; use crate::sessions::Session; use janus_plugin::janus_err; use std::borrow::Borrow; +use std::collections::hash_map::Entry; /// Tools for managing the set of subscriptions between connections. use std::collections::HashMap; -use std::collections::hash_map::Entry; use std::fmt::Debug; use std::hash::Hash; use std::sync::Arc; @@ -260,9 +260,7 @@ impl Switchboard { } pub fn get_room_users(&self, room: &RoomId) -> impl Iterator { - self.publishers_occupying(room).iter().filter_map(|s| { - s.join_state.get().map(|j| &j.user_id) - }) + self.publishers_occupying(room).iter().filter_map(|s| s.join_state.get().map(|j| &j.user_id)) } pub fn get_all_users(&self) -> impl Iterator {