Skip to content

Commit

Permalink
add UserName type
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Jan 7, 2024
1 parent 7d9c784 commit 4e17ce7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/server/session/endpoint/candidate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::server::certificate::RTCDtlsFingerprint;
use crate::shared::types::{EndpointId, SessionId};
use crate::shared::types::{EndpointId, SessionId, UserName};
use base64::{prelude::BASE64_STANDARD, Engine};
use ring::rand::{SecureRandom, SystemRandom};
use sdp::util::ConnectionRole;
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Candidate {
self.endpoint_id
}

pub(crate) fn username(&self) -> String {
pub(crate) fn username(&self) -> UserName {
format!(
"{}:{}",
self.local_conn_cred.ice_ufrag, self.peer_conn_cred.ice_ufrag
Expand Down
6 changes: 3 additions & 3 deletions src/server/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ pub mod endpoint;

use crate::server::certificate::RTCDtlsFingerprint;
use crate::server::session::endpoint::candidate::{Candidate, ConnectionCredentials};
use crate::shared::types::{EndpointId, SessionId};
use crate::shared::types::{EndpointId, SessionId, UserName};
use endpoint::Endpoint;

#[derive(Default, Debug)]
pub struct Session {
session_id: SessionId,
fingerprint: RTCDtlsFingerprint,
endpoints: RefCell<HashMap<EndpointId, Rc<Endpoint>>>,
candidates: RefCell<HashMap<String, Rc<Candidate>>>,
candidates: RefCell<HashMap<UserName, Rc<Candidate>>>,
}

impl Session {
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Session {
candidates.remove(&username).is_some()
}

pub(crate) fn find_candidate(&self, username: &str) -> Option<Rc<Candidate>> {
pub(crate) fn find_candidate(&self, username: &UserName) -> Option<Rc<Candidate>> {
let candidates = self.candidates.borrow();
candidates.get(username).cloned()
}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use retty::transport::TransportContext;
use std::net::SocketAddr;

pub type EndpointId = u64;
pub type SessionId = u64;
pub type EndpointId = u64;
pub type UserName = String;

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct FourTuple {
Expand Down

0 comments on commit 4e17ce7

Please sign in to comment.