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
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:
| ... | ... | @@ -5,18 +5,6 @@ |
| 5 | 5 | #include "nsISupports.idl"
|
| 6 | 6 | #include "nsIFile.idl"
|
| 7 | 7 | |
| 8 | -[scriptable, uuid(4b250614-968a-412f-9191-9ffd9d4bd001)]
|
|
| 9 | -interface torITorControlPortReceiver : nsISupports {
|
|
| 10 | - void onAsyncMessage(in ACString message);
|
|
| 11 | - void onClosed();
|
|
| 12 | -};
|
|
| 13 | - |
|
| 14 | -[scriptable, uuid(1389d157-4695-43a2-a7d8-538aaa350766)]
|
|
| 15 | -interface torITorMessageHandler : nsISupports {
|
|
| 16 | - void onMessage(in ACString message);
|
|
| 17 | - void onError(in ACString error);
|
|
| 18 | -};
|
|
| 19 | - |
|
| 20 | 8 | [scriptable, uuid(8d817c29-e35c-4a4b-ad29-fb24b83ea8cd)]
|
| 21 | 9 | interface torITorReplyCallback : nsISupports {
|
| 22 | 10 | void onReply([optional] in ACString reply);
|
| ... | ... | @@ -37,9 +25,6 @@ interface torITorNotificationListener : nsISupports { |
| 37 | 25 | // TODO: Remove once we have a provider.
|
| 38 | 26 | [scriptable, uuid(f56d710e-5650-4b8c-8d31-279f360003ee)]
|
| 39 | 27 | interface torITorControlPort : nsISupports {
|
| 40 | - void start(in torITorControlPortReceiver receiver);
|
|
| 41 | - void sendCommand(in ACString command, in torITorMessageHandler handler);
|
|
| 42 | - |
|
| 43 | 28 | void authenticate(in Array<uint8_t> password,
|
| 44 | 29 | in torITorReplyCallback callback);
|
| 45 | 30 | void getBootstrapPhase(in torITorReplyCallback callback);
|
| ... | ... | @@ -65,7 +50,7 @@ interface torITorControlPort : nsISupports { |
| 65 | 50 | void close();
|
| 66 | 51 | };
|
| 67 | 52 | |
| 68 | -[scriptable, uuid(2537313c-e120-408c-a2f6-86e6e1bdf899)]
|
|
| 53 | +[builtinclass, scriptable, uuid(2537313c-e120-408c-a2f6-86e6e1bdf899)]
|
|
| 69 | 54 | interface torITorService : nsISupports {
|
| 70 | 55 | // For development purposes...
|
| 71 | 56 | torITorControlPort createControlPort(in ACString host, in long port);
|
| ... | ... | @@ -3,7 +3,6 @@ |
| 3 | 3 | // <http://opensource.org/licenses/MIT>, at your option. This file may not be
|
| 4 | 4 | // copied, modified, or distributed except according to those terms.
|
| 5 | 5 | |
| 6 | -use bytes::Bytes;
|
|
| 7 | 6 | use std::{net::IpAddr, rc::Rc};
|
| 8 | 7 | use tinystr::TinyAsciiStr;
|
| 9 | 8 | |
| ... | ... | @@ -213,23 +212,3 @@ impl<CP: ControlPortInterface> TorController<CP> { |
| 213 | 212 | self.send_command(commands::signal_newnym(), handler);
|
| 214 | 213 | }
|
| 215 | 214 | } |
| 216 | - |
|
| 217 | -// TODO: Remove once we merge all parts of tor-browser#44930.
|
|
| 218 | -impl<CP: ControlPortInterface> TorController<CP> {
|
|
| 219 | - #[inline]
|
|
| 220 | - pub fn send_raw_command(
|
|
| 221 | - &self,
|
|
| 222 | - command: Bytes,
|
|
| 223 | - handler: Box<dyn FnOnce(Result<Reply, ControllerError>)>,
|
|
| 224 | - ) {
|
|
| 225 | - self.0.send_command(
|
|
| 226 | - command,
|
|
| 227 | - Box::new(|res| handler(res.map_err(|e| ControllerError::from(e)))),
|
|
| 228 | - );
|
|
| 229 | - }
|
|
| 230 | - |
|
| 231 | - #[inline]
|
|
| 232 | - pub fn set_async_handler(&self, cb: Option<Box<dyn Fn(Reply)>>) {
|
|
| 233 | - self.0.set_async_handler(cb);
|
|
| 234 | - }
|
|
| 235 | -} |
| ... | ... | @@ -15,7 +15,7 @@ mod test_utils; |
| 15 | 15 | |
| 16 | 16 | pub use dispatcher::ReplyDispatcher;
|
| 17 | 17 | pub use error::ReplyError;
|
| 18 | -pub use line::{DetailReplyLine, EndReplyLine};
|
|
| 18 | +pub use line::DetailReplyLine;
|
|
| 19 | 19 | pub use reply::Reply;
|
| 20 | 20 | |
| 21 | 21 | #[cfg(test)]
|
| ... | ... | @@ -10,10 +10,7 @@ use serde_json::{json, Value as JsonValue}; |
| 10 | 10 | use std::rc::Rc;
|
| 11 | 11 | use thin_vec::ThinVec;
|
| 12 | 12 | use tor_provider::ctor::*;
|
| 13 | -use xpcom::interfaces::{
|
|
| 14 | - nsIFile, torITorControlPortReceiver, torITorMessageHandler, torITorNotificationListener,
|
|
| 15 | - torITorReplyCallback,
|
|
| 16 | -};
|
|
| 13 | +use xpcom::interfaces::{nsIFile, torITorNotificationListener, torITorReplyCallback};
|
|
| 17 | 14 | use xpcom::RefPtr;
|
| 18 | 15 | |
| 19 | 16 | // Actually used, but the compiler does not detect it.
|
| ... | ... | @@ -41,80 +38,6 @@ impl ControlPortXpcom { |
| 41 | 38 | Ok(Self::allocate(InitControlPortXpcom { control_port }))
|
| 42 | 39 | }
|
| 43 | 40 | |
| 44 | - xpcom_method!(start => Start(receiver: *const torITorControlPortReceiver));
|
|
| 45 | - pub fn start(&self, receiver: &torITorControlPortReceiver) -> Result<(), nsresult> {
|
|
| 46 | - let receiver = RefPtr::new(receiver);
|
|
| 47 | - let receiver2 = receiver.clone();
|
|
| 48 | - self.control_port
|
|
| 49 | - .set_async_handler(Some(Box::new(move |reply| {
|
|
| 50 | - let mut buf = Vec::new();
|
|
| 51 | - if let Err(e) = reply.write_to(&mut buf) {
|
|
| 52 | - log::error!(
|
|
| 53 | - "Cannot convert the reply to the raw message: {}.",
|
|
| 54 | - e.to_string()
|
|
| 55 | - );
|
|
| 56 | - return;
|
|
| 57 | - }
|
|
| 58 | - if buf.ends_with(b"\r\n") {
|
|
| 59 | - buf.truncate(buf.len() - 2);
|
|
| 60 | - }
|
|
| 61 | - // These conversions re-use the buffer, Gecko uses the same
|
|
| 62 | - // allocator for Rust and C++ (see the nsstring crate).
|
|
| 63 | - let as_str = nsCString::from(buf);
|
|
| 64 | - // Safety: call to an XPCOM method that we expect to be exposed
|
|
| 65 | - // on Rust. As per the documentation in nsstring, it is safe to
|
|
| 66 | - // pass nsCStrings created in Rust to C++.
|
|
| 67 | - unsafe { receiver.OnAsyncMessage(&*as_str) };
|
|
| 68 | - })));
|
|
| 69 | - self.control_port.set_close_handler(Box::new(move || {
|
|
| 70 | - // Safety: call to an XPCOM method of our interface that we crafted
|
|
| 71 | - // to make sure it was exposed on Rust bindings.
|
|
| 72 | - unsafe { receiver2.OnClosed() };
|
|
| 73 | - }));
|
|
| 74 | - Ok(())
|
|
| 75 | - }
|
|
| 76 | - |
|
| 77 | - xpcom_method!(send_command => SendCommand(command: *const nsACString, handler: *const torITorMessageHandler));
|
|
| 78 | - pub fn send_command(
|
|
| 79 | - &self,
|
|
| 80 | - command: &nsACString,
|
|
| 81 | - handler: &torITorMessageHandler,
|
|
| 82 | - ) -> Result<(), nsresult> {
|
|
| 83 | - let mut command = command.to_vec();
|
|
| 84 | - if !command.ends_with(b"\r\n") {
|
|
| 85 | - command.extend_from_slice(b"\r\n");
|
|
| 86 | - }
|
|
| 87 | - let handler = RefPtr::new(handler);
|
|
| 88 | - self.control_port.send_raw_command(
|
|
| 89 | - command.into(),
|
|
| 90 | - Box::new(move |reply| {
|
|
| 91 | - let mut buf = Vec::new();
|
|
| 92 | - let reply = match reply {
|
|
| 93 | - Ok(r) => r,
|
|
| 94 | - Err(e) => {
|
|
| 95 | - let as_str = nsCString::from(e.to_string());
|
|
| 96 | - // Safety: see the async notification handler.
|
|
| 97 | - unsafe { handler.OnError(&*as_str) };
|
|
| 98 | - return;
|
|
| 99 | - }
|
|
| 100 | - };
|
|
| 101 | - if let Err(e) = reply.write_to(&mut buf) {
|
|
| 102 | - let as_str = nsCString::from(e.to_string());
|
|
| 103 | - // Safety: see the async notification handler.
|
|
| 104 | - unsafe { handler.OnError(&*as_str) };
|
|
| 105 | - return;
|
|
| 106 | - }
|
|
| 107 | - if buf.ends_with(b"\r\n") {
|
|
| 108 | - buf.truncate(buf.len() - 2);
|
|
| 109 | - }
|
|
| 110 | - let as_str = nsCString::from(buf);
|
|
| 111 | - // Safety: see the async notification handler.
|
|
| 112 | - unsafe { handler.OnMessage(&*as_str) };
|
|
| 113 | - }),
|
|
| 114 | - );
|
|
| 115 | - Ok(())
|
|
| 116 | - }
|
|
| 117 | - |
|
| 118 | 41 | xpcom_method!(close => Close());
|
| 119 | 42 | pub fn close(&self) -> Result<(), nsresult> {
|
| 120 | 43 | self.control_port.close().map_err(|e| match e {
|