Pier Angelo Vendrame pushed to branch tor-browser-156.0a1-17.0-2 at The Tor Project / Applications / Tor Browser Commits: 8f0389b9 by Pier Angelo Vendrame at 2026-11-17T15:19:56+01:00 fixup! TB 44806: Implement the tor integration in Rust. TB 45481: Remove the low-level interface. Now we only use the commands, so we do not need the low level interface that just does the reply parsing anymore. - - - - - 4 changed files: - toolkit/components/tor-integration/torITorService.idl - toolkit/components/tor-integration/tor_provider/src/ctor/controller/controller.rs - toolkit/components/tor-integration/tor_provider/src/ctor/reply_parser/mod.rs - toolkit/components/tor-integration/tor_service/src/control_port.rs Changes: ===================================== toolkit/components/tor-integration/torITorService.idl ===================================== @@ -5,18 +5,6 @@ #include "nsISupports.idl" #include "nsIFile.idl" -[scriptable, uuid(4b250614-968a-412f-9191-9ffd9d4bd001)] -interface torITorControlPortReceiver : nsISupports { - void onAsyncMessage(in ACString message); - void onClosed(); -}; - -[scriptable, uuid(1389d157-4695-43a2-a7d8-538aaa350766)] -interface torITorMessageHandler : nsISupports { - void onMessage(in ACString message); - void onError(in ACString error); -}; - [scriptable, uuid(8d817c29-e35c-4a4b-ad29-fb24b83ea8cd)] interface torITorReplyCallback : nsISupports { void onReply([optional] in ACString reply); @@ -37,9 +25,6 @@ interface torITorNotificationListener : nsISupports { // TODO: Remove once we have a provider. [scriptable, uuid(f56d710e-5650-4b8c-8d31-279f360003ee)] interface torITorControlPort : nsISupports { - void start(in torITorControlPortReceiver receiver); - void sendCommand(in ACString command, in torITorMessageHandler handler); - void authenticate(in Array<uint8_t> password, in torITorReplyCallback callback); void getBootstrapPhase(in torITorReplyCallback callback); @@ -65,7 +50,7 @@ interface torITorControlPort : nsISupports { void close(); }; -[scriptable, uuid(2537313c-e120-408c-a2f6-86e6e1bdf899)] +[builtinclass, scriptable, uuid(2537313c-e120-408c-a2f6-86e6e1bdf899)] interface torITorService : nsISupports { // For development purposes... torITorControlPort createControlPort(in ACString host, in long port); ===================================== toolkit/components/tor-integration/tor_provider/src/ctor/controller/controller.rs ===================================== @@ -3,7 +3,6 @@ // <http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. -use bytes::Bytes; use std::{net::IpAddr, rc::Rc}; use tinystr::TinyAsciiStr; @@ -213,23 +212,3 @@ impl<CP: ControlPortInterface> TorController<CP> { self.send_command(commands::signal_newnym(), handler); } } - -// TODO: Remove once we merge all parts of tor-browser#44930. -impl<CP: ControlPortInterface> TorController<CP> { - #[inline] - pub fn send_raw_command( - &self, - command: Bytes, - handler: Box<dyn FnOnce(Result<Reply, ControllerError>)>, - ) { - self.0.send_command( - command, - Box::new(|res| handler(res.map_err(|e| ControllerError::from(e)))), - ); - } - - #[inline] - pub fn set_async_handler(&self, cb: Option<Box<dyn Fn(Reply)>>) { - self.0.set_async_handler(cb); - } -} ===================================== toolkit/components/tor-integration/tor_provider/src/ctor/reply_parser/mod.rs ===================================== @@ -15,7 +15,7 @@ mod test_utils; pub use dispatcher::ReplyDispatcher; pub use error::ReplyError; -pub use line::{DetailReplyLine, EndReplyLine}; +pub use line::DetailReplyLine; pub use reply::Reply; #[cfg(test)] ===================================== toolkit/components/tor-integration/tor_service/src/control_port.rs ===================================== @@ -10,10 +10,7 @@ use serde_json::{json, Value as JsonValue}; use std::rc::Rc; use thin_vec::ThinVec; use tor_provider::ctor::*; -use xpcom::interfaces::{ - nsIFile, torITorControlPortReceiver, torITorMessageHandler, torITorNotificationListener, - torITorReplyCallback, -}; +use xpcom::interfaces::{nsIFile, torITorNotificationListener, torITorReplyCallback}; use xpcom::RefPtr; // Actually used, but the compiler does not detect it. @@ -41,80 +38,6 @@ impl ControlPortXpcom { Ok(Self::allocate(InitControlPortXpcom { control_port })) } - xpcom_method!(start => Start(receiver: *const torITorControlPortReceiver)); - pub fn start(&self, receiver: &torITorControlPortReceiver) -> Result<(), nsresult> { - let receiver = RefPtr::new(receiver); - let receiver2 = receiver.clone(); - self.control_port - .set_async_handler(Some(Box::new(move |reply| { - let mut buf = Vec::new(); - if let Err(e) = reply.write_to(&mut buf) { - log::error!( - "Cannot convert the reply to the raw message: {}.", - e.to_string() - ); - return; - } - if buf.ends_with(b"\r\n") { - buf.truncate(buf.len() - 2); - } - // These conversions re-use the buffer, Gecko uses the same - // allocator for Rust and C++ (see the nsstring crate). - let as_str = nsCString::from(buf); - // Safety: call to an XPCOM method that we expect to be exposed - // on Rust. As per the documentation in nsstring, it is safe to - // pass nsCStrings created in Rust to C++. - unsafe { receiver.OnAsyncMessage(&*as_str) }; - }))); - self.control_port.set_close_handler(Box::new(move || { - // Safety: call to an XPCOM method of our interface that we crafted - // to make sure it was exposed on Rust bindings. - unsafe { receiver2.OnClosed() }; - })); - Ok(()) - } - - xpcom_method!(send_command => SendCommand(command: *const nsACString, handler: *const torITorMessageHandler)); - pub fn send_command( - &self, - command: &nsACString, - handler: &torITorMessageHandler, - ) -> Result<(), nsresult> { - let mut command = command.to_vec(); - if !command.ends_with(b"\r\n") { - command.extend_from_slice(b"\r\n"); - } - let handler = RefPtr::new(handler); - self.control_port.send_raw_command( - command.into(), - Box::new(move |reply| { - let mut buf = Vec::new(); - let reply = match reply { - Ok(r) => r, - Err(e) => { - let as_str = nsCString::from(e.to_string()); - // Safety: see the async notification handler. - unsafe { handler.OnError(&*as_str) }; - return; - } - }; - if let Err(e) = reply.write_to(&mut buf) { - let as_str = nsCString::from(e.to_string()); - // Safety: see the async notification handler. - unsafe { handler.OnError(&*as_str) }; - return; - } - if buf.ends_with(b"\r\n") { - buf.truncate(buf.len() - 2); - } - let as_str = nsCString::from(buf); - // Safety: see the async notification handler. - unsafe { handler.OnMessage(&*as_str) }; - }), - ); - Ok(()) - } - xpcom_method!(close => Close()); pub fn close(&self) -> Result<(), nsresult> { self.control_port.close().map_err(|e| match e { View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/8f0389b9... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/8f0389b9... You're receiving this email because of your account on gitlab.torproject.org. Manage all notifications: https://gitlab.torproject.org/-/profile/notifications | Help: https://gitlab.torproject.org/help
participants (1)
-
Pier Angelo Vendrame (@pierov)