Skip to content

Commit

Permalink
- update client crate to 0.2.1
Browse files Browse the repository at this point in the history
- updated x25519_dalek to avoid breaking change
- updated a couple dependencies that were issuing warning about being deprecated
  • Loading branch information
connorcarpenter committed Apr 1, 2023
1 parent 13078ca commit 693ed1f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
10 changes: 5 additions & 5 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "webrtc-unreliable-client"
version = "0.2.0"
version = "0.2.1"
authors = []
description = "Just enough hacks to connect a native client to a https://github.com/triplehex/webrtc-unreliable server"
workspace = ".."
Expand Down Expand Up @@ -29,7 +29,7 @@ thiserror = "1.0.30"
waitgroup = "0.1.2"
url = "2.2.2"
rustls = { version = "0.19.0", features = ["dangerous_configuration"]}
rcgen = { version = "0.8.14", features = ["pem", "x509-parser"]}
rcgen = { version = "0.10.0", features = ["pem", "x509-parser"]}
ring = "0.16.20"
sha-1 = "0.9.1"
sha2 = "0.9.1"
Expand All @@ -45,12 +45,12 @@ aes = "0.6.0"
subtle = "2.4.1"
ccm = "0.3.0"
aes-gcm = "0.8.0"
der-parser = "5.0"
x509-parser = "0.9"
der-parser = "8.2.0"
x509-parser = "0.15.0"
webpki = "0.21.4"
rand_core = "0.6.3"
p256 = { version = "0.11.1", features=["default", "ecdh", "ecdsa"] }
x25519-dalek = "2.0.0-pre.1"
x25519-dalek = { version = "2.0.0-rc.2", features = ["static_secrets"]}
hmac = "0.10.1"
elliptic-curve = { version = "0.12.3", features = ["default", "ecdh", "sec1"] }
uuid = { version = "0.8.2", features = ["v4"] }
Expand Down
37 changes: 20 additions & 17 deletions client/src/addr_cell.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
sync::Arc,
};

use regex::Regex;
use tokio::sync::Mutex;

/// The server's socket address, if it has been found
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ServerAddr {
/// Client has found the server's socket address
Found(SocketAddr),
/// Client is still finding the server's socket address
Finding,
}

// MaybeAddr
struct MaybeAddr(pub(crate) ServerAddr);

Expand Down Expand Up @@ -37,28 +46,22 @@ impl AddrCell {
}
}

/// The server's socket address, if it has been found
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum ServerAddr {
/// Client has found the server's socket address
Found(SocketAddr),
/// Client is still finding the server's socket address
Finding,
}

pub(crate) fn candidate_to_addr(candidate_str: &str) -> ServerAddr {
let pattern =
Regex::new(r"\b(?P<ip_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) (?P<port>[0-9]{1,5})\b")
.expect("failed to compile regex pattern");
let pattern = Regex::new(r"\b(?P<ip_addr>(?:[0-9]{1,3}\.){3}[0-9]{1,3}|(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))) (?P<port>[0-9]{1,5})\b")
.expect("failed to compile regex pattern");

let captures = pattern
.captures(candidate_str)
.expect("regex failed to find SocketAddr string");

let ip_addr = captures["ip_addr"]
.parse::<Ipv4Addr>()
.expect("not a valid ip address..");
let port = &captures["port"].parse::<u16>().expect("not a valid port..");
if let Ok(ip_addr) = captures["ip_addr"].parse::<Ipv6Addr>() {
ServerAddr::Found(SocketAddr::new(IpAddr::V6(ip_addr), *port))
} else {
let ip_addr = captures["ip_addr"]
.parse::<Ipv4Addr>()
.expect("not a valid ip address..");

ServerAddr::Found(SocketAddr::new(IpAddr::V4(ip_addr), *port))
ServerAddr::Found(SocketAddr::new(IpAddr::V4(ip_addr), *port))
}
}
2 changes: 1 addition & 1 deletion client/src/webrtc/crates/dtls/curve/named_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn elliptic_curve_keypair(curve: NamedCurve) -> Result<NamedCurveKeypair> {
)
}
NamedCurve::X25519 => {
let secret_key = x25519_dalek::StaticSecret::new(OsRng);
let secret_key = x25519_dalek::StaticSecret::random_from_rng(OsRng);
let public_key = x25519_dalek::PublicKey::from(&secret_key);
(
public_key.as_bytes().to_vec(),
Expand Down
11 changes: 8 additions & 3 deletions demos/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::{Error, Result};
use tokio::time::Duration;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::{
sync::mpsc::{UnboundedReceiver, UnboundedSender},
time::Duration,
};

use webrtc_unreliable_client::{AddrCell, ServerAddr, Socket};

Expand Down Expand Up @@ -63,7 +65,10 @@ async fn read_loop(
}
}

async fn write_loop(addr_cell: AddrCell, to_server_sender: UnboundedSender<Box<[u8]>>) -> Result<()> {
async fn write_loop(
addr_cell: AddrCell,
to_server_sender: UnboundedSender<Box<[u8]>>,
) -> Result<()> {
let mut count = 0;

loop {
Expand Down

0 comments on commit 693ed1f

Please sign in to comment.