4
4
//! components. The native component is responsible for starting the browser,
5
5
//! loading the wasm component and driving it.
6
6
7
- use std:: { env, net:: IpAddr } ;
8
-
9
- use serio:: { stream:: IoStreamExt , SinkExt as _} ;
10
- use tlsn_benches_browser_core:: {
11
- msg:: { Config , Runtime } ,
12
- FramedIo ,
13
- } ;
14
- use tlsn_benches_library:: { AsyncIo , ProverKind , ProverTrait } ;
7
+ use std:: { env, net:: IpAddr , time:: Duration } ;
15
8
16
9
use anyhow:: { anyhow, Context , Result } ;
17
10
use async_trait:: async_trait;
@@ -24,10 +17,17 @@ use chromiumoxide::{
24
17
} ;
25
18
use futures:: { Future , FutureExt , StreamExt } ;
26
19
use rust_embed:: RustEmbed ;
20
+ use serio:: { stream:: IoStreamExt , SinkExt as _} ;
27
21
use tokio:: { io, io:: AsyncWriteExt , net:: TcpListener , task:: JoinHandle } ;
28
22
use tracing:: { debug, error, info} ;
29
23
use warp:: Filter ;
30
24
25
+ use tlsn_benches_browser_core:: {
26
+ msg:: { Config , Runtime } ,
27
+ FramedIo ,
28
+ } ;
29
+ use tlsn_benches_library:: { AsyncIo , ProverKind , ProverTrait } ;
30
+
31
31
/// The IP on which the wasm component is served.
32
32
pub static DEFAULT_WASM_IP : & str = "127.0.0.1" ;
33
33
/// The IP of the websocket relay.
@@ -100,6 +100,12 @@ impl ProverTrait for BrowserProver {
100
100
101
101
relays. push ( spawn_websocket_relay ( ws_ip, ws_port) . await ?) ;
102
102
103
+ // Create a framed connection to the wasm component.
104
+ let ( wasm_left, wasm_right) = tokio:: io:: duplex ( 1 << 16 ) ;
105
+
106
+ relays. push ( spawn_port_relay ( wasm_to_native_port, Box :: new ( wasm_right) ) . await ?) ;
107
+ let mut wasm_io = FramedIo :: new ( Box :: new ( wasm_left) ) ;
108
+
103
109
let http_server = spawn_http_server ( wasm_ip, wasm_port) ?;
104
110
105
111
// Relay data from the wasm component to the server.
@@ -108,12 +114,6 @@ impl ProverTrait for BrowserProver {
108
114
// Relay data from the wasm component to the verifier.
109
115
relays. push ( spawn_port_relay ( wasm_to_verifier_port, verifier_io) . await ?) ;
110
116
111
- // Create a framed connection to the wasm component.
112
- let ( wasm_left, wasm_right) = tokio:: io:: duplex ( 1 << 16 ) ;
113
-
114
- relays. push ( spawn_port_relay ( wasm_to_native_port, Box :: new ( wasm_right) ) . await ?) ;
115
- let mut wasm_io = FramedIo :: new ( Box :: new ( wasm_left) ) ;
116
-
117
117
info ! ( "spawning browser" ) ;
118
118
119
119
// Note that the browser must be spawned only when the WebSocket relay is
@@ -129,6 +129,10 @@ impl ProverTrait for BrowserProver {
129
129
)
130
130
. await ?;
131
131
132
+ // Without this sleep, it was observed that `wasm_io.send(Config)`
133
+ // msg does not reach the browser component.
134
+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
135
+
132
136
info ! ( "sending config to the browser component" ) ;
133
137
134
138
wasm_io
@@ -267,14 +271,15 @@ async fn spawn_browser(
267
271
tokio:: spawn ( register_listeners ( & page) . await ?) ;
268
272
269
273
page. wait_for_navigation ( ) . await ?;
274
+
270
275
// Note that `format!` needs double {{ }} in order to escape them.
271
276
let _ = page
272
277
. evaluate_function ( & format ! (
273
278
r#"
274
279
async function() {{
275
- await window.worker .init();
280
+ await window.benchWorker .init();
276
281
// Do not `await` run() or else it will block the browser.
277
- window.worker .run("{}", {}, {}, {}, {});
282
+ window.benchWorker .run("{}", {}, {}, {}, {});
278
283
}}
279
284
"# ,
280
285
ws_ip, ws_port, wasm_to_server_port, wasm_to_verifier_port, wasm_to_native_port
0 commit comments