summaryrefslogtreecommitdiff
path: root/client-native-lib
diff options
context:
space:
mode:
Diffstat (limited to 'client-native-lib')
-rw-r--r--client-native-lib/Cargo.toml14
-rw-r--r--client-native-lib/src/crypto.rs9
-rw-r--r--client-native-lib/src/lib.rs1
-rw-r--r--client-native-lib/src/peer.rs93
4 files changed, 54 insertions, 63 deletions
diff --git a/client-native-lib/Cargo.toml b/client-native-lib/Cargo.toml
index 15a1084..c7c36d5 100644
--- a/client-native-lib/Cargo.toml
+++ b/client-native-lib/Cargo.toml
@@ -4,22 +4,22 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-tokio = { version = "1.21", features = ["full"] }
-futures-util = "0.3.24"
+tokio = { version = "1.25", features = ["full"] }
+futures-util = "0.3.26"
-webrtc = "0.5.0"
+webrtc = "0.6.0"
tokio-tungstenite = { version = "*", features = ["rustls-tls"] }
url = "2.3.1"
-serde = { version = "1.0.144", features = ["derive"] }
+serde = { version = "1.0.152", features = ["derive"] }
serde_json = "*"
log = "0.4"
fastpbkdf2 = "0.1.0"
aes-gcm = "0.10.1"
-sha256 = "1.0.3"
+sha256 = "1.1.2"
rand = "0.8.5"
rand_chacha = "0.3.1"
-base64 = "0.13.0"
-bytes = "1.2.1"
+base64 = "0.21.0"
+bytes = "1.4.0"
diff --git a/client-native-lib/src/crypto.rs b/client-native-lib/src/crypto.rs
index 239c9f3..0472ec7 100644
--- a/client-native-lib/src/crypto.rs
+++ b/client-native-lib/src/crypto.rs
@@ -7,6 +7,7 @@ use aes_gcm::{
aead::{generic_array::sequence::GenericSequence, Aead},
Aes256Gcm, KeyInit, Nonce,
};
+use base64::Engine;
use log::info;
pub struct Key(Aes256Gcm);
@@ -14,7 +15,9 @@ pub struct Key(Aes256Gcm);
impl Key {
pub fn derive(secret: &str) -> Self {
info!("running key generation...");
- let salt = base64::decode("thisisagoodsaltAAAAAAA==").unwrap();
+ let salt = base64::engine::general_purpose::STANDARD
+ .decode("thisisagoodsaltAAAAAAA==")
+ .unwrap();
let mut key = [0u8; 32];
fastpbkdf2::pbkdf2_hmac_sha256(secret.as_bytes(), salt.as_slice(), 250000, &mut key);
@@ -28,10 +31,10 @@ impl Key {
let ciphertext = self.0.encrypt(&iv, s.as_bytes()).unwrap();
let mut packet = iv.to_vec(); // TODO this could be doing less allocations
packet.extend(ciphertext);
- base64::encode(packet)
+ base64::engine::general_purpose::STANDARD.encode(packet)
}
pub fn decrypt(&self, s: &str) -> String {
- let r = base64::decode(s).unwrap();
+ let r = base64::engine::general_purpose::STANDARD.decode(s).unwrap();
let iv = &r[0..12];
let ciphertext = &r[12..];
let plaintext = self.0.decrypt(Nonce::from_slice(iv), ciphertext).unwrap();
diff --git a/client-native-lib/src/lib.rs b/client-native-lib/src/lib.rs
index 1380688..32418d4 100644
--- a/client-native-lib/src/lib.rs
+++ b/client-native-lib/src/lib.rs
@@ -35,7 +35,6 @@ pub struct Config {
pub(crate) fn build_api() -> webrtc::api::API {
let mut media_engine = MediaEngine::default();
media_engine.register_default_codecs().unwrap();
-
let mut registry = Registry::new();
registry = register_default_interceptors(registry, &mut media_engine).unwrap();
APIBuilder::new()
diff --git a/client-native-lib/src/peer.rs b/client-native-lib/src/peer.rs
index b3b4dd4..8c27234 100644
--- a/client-native-lib/src/peer.rs
+++ b/client-native-lib/src/peer.rs
@@ -69,34 +69,28 @@ impl Peer {
.on_peer_connection_state_change(Box::new(move |s: RTCPeerConnectionState| {
info!("connection state changed: {s}");
Box::pin(async {})
- }))
- .await;
-
+ }));
{
let weak = Arc::<Peer>::downgrade(&peer);
- peer.peer_connection
- .on_ice_candidate(box move |c| {
- if let Some(peer) = weak.upgrade() {
- Box::pin(async move {
- if let Some(c) = c {
- peer.on_ice_candidate(c).await
- }
- })
- } else {
- Box::pin(async move {})
- }
- })
- .await;
+ peer.peer_connection.on_ice_candidate(box move |c| {
+ if let Some(peer) = weak.upgrade() {
+ Box::pin(async move {
+ if let Some(c) = c {
+ peer.on_ice_candidate(c).await
+ }
+ })
+ } else {
+ Box::pin(async move {})
+ }
+ })
}
{
let weak = Arc::<Peer>::downgrade(&peer);
- peer.peer_connection
- .on_negotiation_needed(box move || {
- let peer = weak.upgrade().unwrap();
- Box::pin(async { peer.on_negotiation_needed().await })
- })
- .await;
+ peer.peer_connection.on_negotiation_needed(box move || {
+ let peer = weak.upgrade().unwrap();
+ Box::pin(async { peer.on_negotiation_needed().await })
+ })
}
{
@@ -124,37 +118,34 @@ impl Peer {
}
})
})
- .await;
}
{
let weak = Arc::<Peer>::downgrade(&peer);
- peer.peer_connection
- .on_data_channel(box move |dc| {
- let peer = weak.upgrade().unwrap();
- Box::pin(async move {
- if let Some(res) = peer
- .remote_provided
- .read()
- .await
- .get(&dc.label().to_string())
- {
- info!("data channel for ({:?}) '{:?}'", res.id, res.label);
- peer.inst
- .event_handler
- .resource_connected(
- peer.clone(),
- res,
- TransportChannel::DataChannel(dc),
- )
- .await;
- } else {
- warn!("got unassociated data channel; closed connection");
- dc.close().await.unwrap();
- }
- })
+ peer.peer_connection.on_data_channel(box move |dc| {
+ let peer = weak.upgrade().unwrap();
+ Box::pin(async move {
+ if let Some(res) = peer
+ .remote_provided
+ .read()
+ .await
+ .get(&dc.label().to_string())
+ {
+ info!("data channel for ({:?}) '{:?}'", res.id, res.label);
+ peer.inst
+ .event_handler
+ .resource_connected(
+ peer.clone(),
+ res,
+ TransportChannel::DataChannel(dc),
+ )
+ .await;
+ } else {
+ warn!("got unassociated data channel; closed connection");
+ dc.close().await.unwrap();
+ }
})
- .await;
+ })
}
peer
}
@@ -228,10 +219,8 @@ impl Peer {
pub async fn on_ice_candidate(&self, candidate: RTCIceCandidate) {
debug!("publishing local ICE candidate");
- self.send_relay(RelayMessage::IceCandidate(
- candidate.to_json().await.unwrap(),
- ))
- .await;
+ self.send_relay(RelayMessage::IceCandidate(candidate.to_json().unwrap()))
+ .await;
}
pub async fn on_remote_ice_candidate(&self, candidate: RTCIceCandidateInit) {
debug!("adding remote ICE candidate");