@@ -37,21 +37,28 @@ use wasm_bindgen::prelude::*;
3737use wasm_bindgen_futures:: JsFuture ;
3838use web_sys:: { CustomEvent , MessageEvent , Response } ;
3939
40+ type EventClosure = Closure < dyn FnMut ( CustomEvent ) > ;
41+ type EventQueue = Rc < RefCell < VecDeque < EventClosure > > > ;
42+ type HyperResp = hyper:: Response < hyper:: body:: Incoming > ;
43+ type RequestFuture = Pin < Box < dyn Future < Output = hyper:: Result < HyperResp > > > > ;
44+ type ConnPin = Pin < Box < Connection < HyperStream , Box < Body > > > > ;
45+ type RespPin = Pin < Box < HyperResp > > ;
4046
4147/// The exported client struct. It Wraps the actual Client and a Queue to keep the needed
4248/// callbacks alive.
4349/// Most function calls are simply passed to the wrapped object.
4450#[ wasm_bindgen]
4551pub struct Client (
4652 WgClient ,
47- Rc < RefCell < VecDeque < Closure < dyn FnMut ( CustomEvent ) > > > > ,
53+ EventQueue ,
4854) ;
4955
5056#[ wasm_bindgen]
5157impl Client {
5258
5359 /// Creates a new Client struct by also creating the wrapped objects.
5460 #[ wasm_bindgen( constructor) ]
61+ #[ allow( clippy:: too_many_arguments) ]
5562 pub fn new (
5663 secret_str : & str ,
5764 peer_str : & str ,
@@ -178,6 +185,7 @@ enum RequestState {
178185impl WgClient {
179186
180187 /// Creates a new object.
188+ #[ allow( clippy:: too_many_arguments) ]
181189 fn new (
182190 secret_str : & str ,
183191 peer_str : & str ,
@@ -231,7 +239,7 @@ impl WgClient {
231239 current_request : Rc :: new ( RefCell :: new ( None ) ) ,
232240 request_queue : Rc :: new ( RefCell :: new ( VecDeque :: new ( ) ) ) ,
233241 pcap,
234- internal_peer_ip : ( & internal_peer_ip[ 0 ..internal_peer_ip. len ( ) - 3 ] ) . to_string ( ) ,
242+ internal_peer_ip : internal_peer_ip[ 0 ..internal_peer_ip. len ( ) - 3 ] . to_string ( ) ,
235243 _polling_interval : polling_interval,
236244 username : Rc :: new ( RefCell :: new ( String :: new ( ) ) ) ,
237245 password : Rc :: new ( RefCell :: new ( String :: new ( ) ) ) ,
@@ -252,9 +260,9 @@ impl WgClient {
252260 let port = port as u16 ;
253261 let endpoint = smoltcp:: wire:: IpEndpoint :: new ( self . internal_peer_ip . parse ( ) . unwrap ( ) , self . port ) ;
254262 if let Err ( err) = stream. connect ( endpoint, port) {
255- log:: error!( "Error when connecting websocket: {}" , err. to_string ( ) ) ;
263+ log:: error!( "Error when connecting websocket: {}" , err) ;
256264 }
257- let auth_header = if self . nonce . borrow ( ) . len ( ) != 0 {
265+ let auth_header = if ! self . nonce . borrow ( ) . is_empty ( ) {
258266 Some ( self . build_authentication_header ( "GET" , "/ws" ) )
259267 } else {
260268 None
@@ -269,7 +277,7 @@ impl WgClient {
269277 let ha1 = md5:: compute ( format ! ( "{}:{}:{}" , self . username. borrow( ) , self . realm. borrow( ) , self . password. borrow( ) ) ) ;
270278 let ha2 = md5:: compute ( format ! ( "{}:{}" , method, uri) ) ;
271279
272- let this: JsValue = js_sys:: global ( ) . try_into ( ) . unwrap ( ) ;
280+ let this: JsValue = js_sys:: global ( ) . into ( ) ;
273281 let this = web_sys:: WorkerGlobalScope :: from ( this) ;
274282 let crypto = this. crypto ( ) . unwrap ( ) ;
275283
@@ -367,7 +375,7 @@ impl WgClient {
367375
368376 // FIXME: throw exception instead of panic
369377 if let Err ( err) = stream. upgrade ( ) . unwrap ( ) . borrow_mut ( ) . connect ( endpoint, out_port) {
370- log:: error!( "Error connecting to endpoint {}: {}" , endpoint, err. to_string ( ) ) ;
378+ log:: error!( "Error connecting to endpoint {}: {}" , endpoint, err) ;
371379 return ;
372380 }
373381 * state_ref = RequestState :: Started ;
@@ -429,7 +437,7 @@ impl WgClient {
429437 let document = window. document ( ) . unwrap ( ) ;
430438 let element = document. create_element ( "a" ) . unwrap ( ) ;
431439 element. set_attribute ( "download" , "out.pcap" ) . unwrap ( ) ;
432- element. set_attribute ( "href" , & file. to_string ( ) ) . unwrap ( ) ;
440+ element. set_attribute ( "href" , & file) . unwrap ( ) ;
433441 element. set_attribute ( "target" , "_blank" ) . unwrap ( ) ;
434442 let element = wasm_bindgen:: JsValue :: from ( element) ;
435443 let element = web_sys:: HtmlElement :: from ( element) ;
@@ -451,7 +459,7 @@ impl WgClient {
451459
452460
453461/// Transforms the raw tcp stream into sender and receiver objects for hyper.
454- fn setup_connection ( sender : Weak < RefCell < Option < SendRequest < Box < Body > > > > > , conn : Weak < RefCell < Option < std :: pin :: Pin < Box < Connection < HyperStream , Box < Body > > > > > > > , state : Weak < RefCell < RequestState > > , stream : Weak < RefCell < TcpStream < ' static , WgTunDevice > > > ) {
462+ fn setup_connection ( sender : Weak < RefCell < Option < SendRequest < Box < Body > > > > > , conn : Weak < RefCell < Option < ConnPin > > > , state : Weak < RefCell < RequestState > > , stream : Weak < RefCell < TcpStream < ' static , WgTunDevice > > > ) {
455463 wasm_bindgen_futures:: spawn_local ( async move {
456464 let stream = HyperStream :: new ( stream. upgrade ( ) . unwrap ( ) . clone ( ) ) ;
457465
@@ -470,7 +478,7 @@ fn send_http_reqeust(
470478 js_request : Rc < web_sys:: Request > ,
471479 url : Rc < String > ,
472480 sender : Weak < RefCell < Option < SendRequest < Box < Body > > > > > ,
473- request : Weak < RefCell < Option < Pin < Box < dyn Future < Output = hyper :: Result < hyper :: Response < hyper :: body :: Incoming > > > > > > > > ,
481+ request : Weak < RefCell < Option < RequestFuture > > > ,
474482 state : Weak < RefCell < RequestState > > ,
475483 self_cpy : WgClient ,
476484) {
@@ -502,7 +510,7 @@ fn send_http_reqeust(
502510 req = req. header ( key, value) ;
503511 }
504512
505- if self_cpy. nonce . borrow ( ) . len ( ) != 0 {
513+ if ! self_cpy. nonce . borrow ( ) . is_empty ( ) {
506514 let auth_header = self_cpy. build_authentication_header ( & method_str, & url) ;
507515 req = req. header ( "Authorization" , auth_header) ;
508516 }
@@ -525,10 +533,10 @@ fn send_http_reqeust(
525533
526534/// Polls the sending end of the hyper connection until the request is sent.
527535fn poll_request (
528- request : Rc < RefCell < Option < Pin < Box < dyn Future < Output = hyper :: Result < hyper :: Response < hyper :: body :: Incoming > > > > > > > > ,
529- resp : Rc < RefCell < Option < Pin < Box < hyper :: Response < hyper :: body :: Incoming > > > > > > ,
536+ request : Rc < RefCell < Option < RequestFuture > > > ,
537+ resp : Rc < RefCell < Option < RespPin > > > ,
530538 mut state : std:: cell:: RefMut < ' _ , RequestState > ,
531- conn : Rc < RefCell < Option < std :: pin :: Pin < Box < Connection < HyperStream , Box < Body > > > > > > > ,
539+ conn : Rc < RefCell < Option < ConnPin > > > ,
532540) {
533541 let waker = futures:: task:: noop_waker ( ) ;
534542 let mut cx = std:: task:: Context :: from_waker ( & waker) ;
@@ -556,12 +564,12 @@ fn poll_request(
556564
557565/// Collects the raw response stream and parses it into a Response object.
558566fn poll_response (
559- resp : Rc < RefCell < Option < Pin < Box < hyper :: Response < hyper :: body :: Incoming > > > > > > ,
567+ resp : Rc < RefCell < Option < RespPin > > > ,
560568 result : Rc < RefCell < Vec < u8 > > > ,
561569 mut state_ref : std:: cell:: RefMut < ' _ , RequestState > ,
562570 self_cpy : WgClient ,
563571 id : f64 ,
564- conn : Rc < RefCell < Option < std :: pin :: Pin < Box < Connection < HyperStream , Box < Body > > > > > > > ,
572+ conn : Rc < RefCell < Option < ConnPin > > > ,
565573) {
566574 let waker = futures:: task:: noop_waker ( ) ;
567575 let mut cx = std:: task:: Context :: from_waker ( & waker) ;
0 commit comments