Skip to content
Permalink
Browse files

working direct connect

  • Loading branch information
syntacticsugarglider committed Nov 16, 2019
1 parent 4681e59 commit 870affa1f66702b0b20db69249cf7fb20d84bb14
@@ -5,7 +5,7 @@ authors = ["Izzy Swart <zenerboson@gmail.com>"]
edition = "2018"

[workspace]
members = [".", "./derive", "examples/vessel", "examples/native_vessel"]
members = [".", "./derive", "examples/vessel", "examples/native_vessel", "examples/network"]

[features]
cbor = ["serde_cbor"]
@@ -36,7 +36,8 @@ web-sys = { version = "0.3.30", optional = true, features = [
"RtcPeerConnection",
"RtcSessionDescriptionInit",
"RtcSdpType",
"RtcIceCandidateInit"
"RtcIceCandidateInit",
"RtcDataChannel"
] }
js-sys = { version = "0.3.30", optional = true }
wasm-bindgen-futures = { version = "0.4.4", optional = true }

This file was deleted.

@@ -0,0 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
@@ -0,0 +1,19 @@
[package]
name = "network"
version = "0.1.0"
authors = ["Izzy Swart <zenerboson@gmail.com>"]
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2.54"
vessels = { path = "../../", features = ["core"] }
futures-preview = { version = "=0.3.0-alpha.19", features = ["async-await"] }
js-sys = "0.3.31"
console_error_panic_hook = "0.1.6"

[dependencies.web-sys]
version = "0.3.4"
features = ["console"]
@@ -0,0 +1,42 @@
use vessels::{
channel::IdChannel,
core,
core::{
executor::Spawn,
hal::{
crypto::Rng,
network::{Network, StaticCandidate},
},
orchestrator::containers::{web::WebContainers, Containers},
Executor, Vessel,
},
format::{ApplyDecode, Cbor},
log,
};
use wasm_bindgen::prelude::*;

#[wasm_bindgen(start)]
pub fn main() {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
core::<dyn Executor>().unwrap().run(async move {
let mut network = Network::new().unwrap();
let ufrag = [236, 97, 14];
let pwd = [
221, 45, 14, 120, 112, 243, 215, 166, 168, 89, 18, 184, 182, 112, 11, 34, 199, 155, 31,
137, 228, 246, 137, 69,
];
let fingerprint = [
120, 10, 220, 61, 141, 117, 214, 168, 211, 147, 233, 45, 60, 120, 108, 126, 232, 219,
165, 127, 127, 253, 62, 79, 9, 5, 147, 126, 109, 96, 21, 103,
];
let connection = network
.connect(StaticCandidate {
addr: "127.0.0.1:61200".parse().unwrap(),
pwd,
fingerprint,
ufrag,
})
.await
.unwrap();
});
}
@@ -3,7 +3,7 @@

<body>
<script type="module">
import init from './vessel.js';
import init from './network.js';

async function run() {
await init();
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Kind)]
pub struct StaticCandidate {
pub ufrag: [u8; 3],
pub pwd: [u8; 16],
pub pwd: [u8; 24],
pub fingerprint: [u8; 32],
pub addr: SocketAddr,
}
@@ -31,33 +31,38 @@ impl<F: IFuture> IFuture for SendAssert<F> {
struct SendAssert<F: IFuture>(Pin<Box<F>>);

impl INetwork for Network {
fn connect(&mut self, candidate: StaticCandidate) -> Future<Result<Box<dyn IPeer>, ConnectError>> {
fn connect(
&mut self,
candidate: StaticCandidate,
) -> Future<Result<Box<dyn IPeer>, ConnectError>> {
Box::pin(SendAssert(Box::pin(async move {
let mut fingerprint = String::new();
for byte in candidate.fingerprint.iter() {
write!(fingerprint, "{:X}:", byte).unwrap();
write!(fingerprint, "{:02X}:", byte).unwrap();
}
fingerprint.pop();
let sdp = format!(
"v=0
o=- 0 2 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE data
a=msid-semantic: WMS
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=setup:passive
a=mid:data
a=ice-ufrag:{}
a=ice-pwd:{}
a=fingerprint:sha-256 {}",
r#"v=0
o=- 0 2 IN IP4 0.0.0.0
s=-
t=0 0
a=group:BUNDLE 0
a=msid-semantic: WMS
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=setup:passive
a=mid:0
a=ice-ufrag:{}
a=ice-pwd:{}
a=fingerprint:sha-256 {}
"#,
base64::encode(&candidate.ufrag),
base64::encode(&candidate.pwd),
fingerprint
);
let connection =
RtcPeerConnection::new().expect("could not instantiate peer connection");
connection.create_data_channel("signalling");
let offer = JsFuture::from(connection.create_offer()).await.unwrap();
JsFuture::from(connection.set_local_description(offer.dyn_ref().unwrap()))
.await
@@ -74,7 +79,7 @@ impl INetwork for Network {
candidate.addr.ip(),
candidate.addr.port()
))
.sdp_mid(Some("data"))
.sdp_mid(Some("0"))
.sdp_m_line_index(Some(0)),
)),
)

0 comments on commit 870affa

Please sign in to comment.
You can’t perform that action at this time.