Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed May 1, 2024
1 parent f597104 commit ebfa912
Show file tree
Hide file tree
Showing 24 changed files with 989 additions and 1,570 deletions.
1,308 changes: 49 additions & 1,259 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resolver = "2"
[workspace.dependencies]
app_dirs2 = "2.5.5"
backtrace = "0.3.69"
base64 = "0.13.0"
base64 = "0.22.1"
better-panic = "0.3.0"
bit_field = "0.10.2"
bytes = "1.4.0"
Expand Down Expand Up @@ -60,6 +60,7 @@ tracing = "0.1.37"
tracing-appender = "0.2.2"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter" ] }
trust-dns-resolver = "0.22.0"
tx5-connection = { version = "0.0.9-alpha", default-features = false, path = "crates/tx5-connection" }
tx5-core = { version = "0.0.9-alpha", default-features = false, path = "crates/tx5-core" }
tx5-go-pion-turn = { version = "0.0.9-alpha", path = "crates/tx5-go-pion-turn" }
tx5-go-pion-sys = { version = "0.0.9-alpha", path = "crates/tx5-go-pion-sys" }
Expand Down
10 changes: 10 additions & 0 deletions crates/tx5-connection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ keywords = ["holochain", "holo", "p2p", "webrtc", "networking"]
categories = ["network-programming"]
edition = "2021"

[features]
default = [ "backend-go-pion" ]

# use the tx5-go-pion crate as the webrtc backend
backend-go-pion = [ "dep:tx5-go-pion" ]

# use the webrtc-rs crate as the webrtc backend
backend-webrtc-rs = [ ]

[dependencies]
bit_field = { workspace = true }
tokio = { workspace = true, features = [ "full" ] }
tracing = { workspace = true }
tx5-core = { workspace = true }
tx5-signal = { workspace = true }
tx5-go-pion = { workspace = true, optional = true }

[dev-dependencies]
rand = { workspace = true }
Expand Down
17 changes: 17 additions & 0 deletions crates/tx5-connection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@ Holochain webrtc connection.
Starts by sending messages over the sbd signal server, if we can
upgrade to a proper webrtc p2p connection, we do so.

#### WebRTC Backend Features

Tx5 can be backed currently by 1 of 2 backend webrtc libraries.

- <b><i>`*`DEFAULT`*`</i></b> `backend-go-pion` - The pion webrtc library
writen in go (golang).
- [https://github.com/pion/webrtc](https://github.com/pion/webrtc)
- `backend-webrtc-rs` - The rust webrtc library.
- [https://github.com/webrtc-rs/webrtc](https://github.com/webrtc-rs/webrtc)

The go pion library is currently the default as it is more mature
and well tested, but comes with some overhead of calling into a different
memory/runtime. When the rust library is stable enough for holochain's
needs, we will switch the default. To switch now, or if you want to
make sure the backend doesn't change out from under you, set
no-default-features and explicitly enable the backend of your choice.

<!-- cargo-rdme end -->
1 change: 1 addition & 0 deletions crates/tx5-connection/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl Tx5Connection {
match cmd {
ConnCmd::SigRecv(sig) => {
use tx5_signal::SignalMessage::*;
#[allow(clippy::single_match)] // placeholder
match sig {
Message(msg) => {
if msg_send.send(msg).await.is_err() {
Expand Down
10 changes: 3 additions & 7 deletions crates/tx5-connection/src/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,9 @@ impl Tx5ConnFramed {
let cmd_send2 = cmd_send.clone();
let weak_conn = Arc::downgrade(&conn);
let recv_task = tokio::task::spawn(async move {
loop {
if let Some(conn) = weak_conn.upgrade() {
if let Some(msg) = conn.recv().await {
if cmd_send2.send(Cmd::Recv(msg)).await.is_err() {
break;
}
} else {
while let Some(conn) = weak_conn.upgrade() {
if let Some(msg) = conn.recv().await {
if cmd_send2.send(Cmd::Recv(msg)).await.is_err() {
break;
}
} else {
Expand Down
18 changes: 7 additions & 11 deletions crates/tx5-connection/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,13 @@ impl Tx5ConnectionHub {
let cmd_send2 = cmd_send.clone();
let weak_client = Arc::downgrade(&client);
task_list.push(tokio::task::spawn(async move {
loop {
if let Some(client) = weak_client.upgrade() {
if let Some((pub_key, msg)) = client.recv_message().await {
if cmd_send2
.send(HubCmd::CliRecv { pub_key, msg })
.await
.is_err()
{
break;
}
} else {
while let Some(client) = weak_client.upgrade() {
if let Some((pub_key, msg)) = client.recv_message().await {
if cmd_send2
.send(HubCmd::CliRecv { pub_key, msg })
.await
.is_err()
{
break;
}
} else {
Expand Down
26 changes: 25 additions & 1 deletion crates/tx5-connection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@
//! Holochain webrtc connection.
//! Starts by sending messages over the sbd signal server, if we can
//! upgrade to a proper webrtc p2p connection, we do so.
//!
//! # WebRTC Backend Features
//!
//! Tx5 can be backed currently by 1 of 2 backend webrtc libraries.
//!
//! - <b><i>`*`DEFAULT`*`</i></b> `backend-go-pion` - The pion webrtc library
//! writen in go (golang).
//! - [https://github.com/pion/webrtc](https://github.com/pion/webrtc)
//! - `backend-webrtc-rs` - The rust webrtc library.
//! - [https://github.com/webrtc-rs/webrtc](https://github.com/webrtc-rs/webrtc)
//!
//! The go pion library is currently the default as it is more mature
//! and well tested, but comes with some overhead of calling into a different
//! memory/runtime. When the rust library is stable enough for holochain's
//! needs, we will switch the default. To switch now, or if you want to
//! make sure the backend doesn't change out from under you, set
//! no-default-features and explicitly enable the backend of your choice.

#[cfg(any(
not(any(feature = "backend-go-pion", feature = "backend-webrtc-rs")),
all(feature = "backend-go-pion", feature = "backend-webrtc-rs"),
))]
compile_error!("Must specify exactly 1 webrtc backend");

use std::collections::HashMap;
use std::io::{Error, Result};
use std::sync::{Arc, Weak};

pub use tx5_signal::PubKey;
pub use tx5_signal;
use tx5_signal::PubKey;

mod hub;
pub use hub::*;
Expand Down
12 changes: 8 additions & 4 deletions crates/tx5-core/src/file_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ fn validate(path: &std::path::PathBuf, hash: &str) -> Result<std::fs::File> {
use sha2::Digest;
let mut hasher = sha2::Sha256::new();
hasher.update(data);
let on_disk_hash =
base64::encode_config(hasher.finalize(), base64::URL_SAFE_NO_PAD);

use base64::Engine;
let on_disk_hash = base64::engine::general_purpose::URL_SAFE_NO_PAD
.encode(hasher.finalize());

if on_disk_hash != hash {
return Err(Error::err(format!("FileCheckHashMiss({path:?})")));
Expand Down Expand Up @@ -183,8 +185,10 @@ mod tests {
use sha2::Digest;
let mut hasher = sha2::Sha256::new();
hasher.update(&data[..]);
let hash =
base64::encode_config(hasher.finalize(), base64::URL_SAFE_NO_PAD);

use base64::Engine;
let hash = base64::engine::general_purpose::URL_SAFE_NO_PAD
.encode(hasher.finalize());

let mut task_list = Vec::new();

Expand Down
85 changes: 0 additions & 85 deletions crates/tx5-core/src/id.rs

This file was deleted.

9 changes: 0 additions & 9 deletions crates/tx5-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ pub mod deps {
mod error;
pub use error::*;

mod id;
pub use id::*;

mod uniq;
pub use uniq::*;

mod url;
pub use crate::url::*;

mod evt;
pub use evt::*;

Expand Down
Loading

0 comments on commit ebfa912

Please sign in to comment.