Commit 3fcf8e84 authored by Elena's avatar Elena 🤷‍♀️ Committed by Pier Angelo Vendrame
Browse files

fixup! TB 44806: Implement the tor integration in Rust.

TB 44930: Implement the commands on the Rust control port

Rename ITor... interfaces to torITor...

The prefix is basically a namespace, and really few interfaces do not
have one, so add that prefix also to our interfaces.
parent 14bc2a35
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -7,17 +7,17 @@

#include "nsCOMPtr.h"

#include "ITorService.h"
#include "torITorService.h"

// Inspired by
// toolkit/components/extensions/storage/ExtensionStorageComponents.h.

// Implemented in Rust
extern "C" nsresult NewTorServiceImpl(ITorService** aResult);
extern "C" nsresult NewTorServiceImpl(torITorService** aResult);

namespace torproject {
already_AddRefed<ITorService> NewTorService() {
  nsCOMPtr<ITorService> service;
already_AddRefed<torITorService> NewTorService() {
  nsCOMPtr<torITorService> service;
  nsresult rv = NewTorServiceImpl(getter_AddRefs(service));
  if (NS_WARN_IF(NS_FAILED(rv))) {
    return nullptr;
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ Classes = [
    {
        'cid': '{2537313c-e120-408c-a2f6-86e6e1bdf899}',
        'contract_ids': ['@torproject.org/tor-service;1'],
        'interfaces': ['ITorService'],
        'interfaces': ['torITorService'],
        'constructor': 'torproject::NewTorService',
        'headers': ['torproject/TorService.h'],
        'js_name': 'tor',
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

XPIDL_MODULE = "tor"
XPIDL_SOURCES += ["ITorService.idl"]
XPIDL_SOURCES += ["torITorService.idl"]
XPCOM_MANIFESTS += [
    "components.conf",
]
+8 −8
Original line number Diff line number Diff line
@@ -6,27 +6,27 @@
#include "nsIFile.idl"

[scriptable, uuid(4b250614-968a-412f-9191-9ffd9d4bd001)]
interface ITorControlPortReceiver : nsISupports {
interface torITorControlPortReceiver : nsISupports {
  void onAsyncMessage(in ACString message);
};

[scriptable, uuid(1389d157-4695-43a2-a7d8-538aaa350766)]
interface ITorMessageHandler : nsISupports {
interface torITorMessageHandler : nsISupports {
  void onMessage(in ACString message);
  void onError(in ACString error);
};

// TODO: Remove once we have a provider.
[scriptable, uuid(f56d710e-5650-4b8c-8d31-279f360003ee)]
interface ITorControlPort : nsISupports {
  void start(in ITorControlPortReceiver receiver);
  void sendCommand(in ACString command, in ITorMessageHandler handler);
interface torITorControlPort : nsISupports {
  void start(in torITorControlPortReceiver receiver);
  void sendCommand(in ACString command, in torITorMessageHandler handler);
  void close();
};

[scriptable, uuid(2537313c-e120-408c-a2f6-86e6e1bdf899)]
interface ITorService : nsISupports {
interface torITorService : nsISupports {
  // For development purposes...
  ITorControlPort createControlPort(in ACString host, in long port);
  ITorControlPort createControlPortIPC(in nsIFile socket);
  torITorControlPort createControlPort(in ACString host, in long port);
  torITorControlPort createControlPortIPC(in nsIFile socket);
};
+11 −8
Original line number Diff line number Diff line
@@ -6,14 +6,17 @@ use bytes::Bytes;
use nserror::nsresult;
use nserror::{NS_ERROR_NOT_CONNECTED, NS_OK};
use nsstring::{nsACString, nsCString};
use tor_provider::ctor::ControlPort;
use tor_provider::ctor::ControlSocketError;
use xpcom::interfaces::{nsIFile, ITorControlPort, ITorControlPortReceiver, ITorMessageHandler};
use tor_provider::ctor::{ControlPort, ControlSocketError};
use xpcom::interfaces::{nsIFile, torITorControlPortReceiver, torITorMessageHandler};
use xpcom::RefPtr;

// Actually used, but the compiler does not detect it.
#[allow(unused)]
use xpcom::interfaces::torITorControlPort;

use super::control_socket::ControlSocketXpcom;

#[xpcom(implement(ITorControlPort), atomic)]
#[xpcom(implement(torITorControlPort), atomic)]
pub struct ControlPortXpcom {
    control_port: ControlPort,
}
@@ -32,8 +35,8 @@ impl ControlPortXpcom {
        Ok(Self::allocate(InitControlPortXpcom { control_port }))
    }

    xpcom_method!(start => Start(receiver: *const ITorControlPortReceiver));
    pub fn start(&self, receiver: &ITorControlPortReceiver) -> Result<(), nsresult> {
    xpcom_method!(start => Start(receiver: *const torITorControlPortReceiver));
    pub fn start(&self, receiver: &torITorControlPortReceiver) -> Result<(), nsresult> {
        let receiver = RefPtr::new(receiver);
        self.control_port.set_async_handler(Box::new(move |reply| {
            let mut buf = Vec::new();
@@ -58,11 +61,11 @@ impl ControlPortXpcom {
        Ok(())
    }

    xpcom_method!(send_command => SendCommand(command: *const nsACString, handler: *const ITorMessageHandler));
    xpcom_method!(send_command => SendCommand(command: *const nsACString, handler: *const torITorMessageHandler));
    pub fn send_command(
        &self,
        command: &nsACString,
        handler: &ITorMessageHandler,
        handler: &torITorMessageHandler,
    ) -> Result<(), nsresult> {
        let command = Bytes::copy_from_slice(&command[..]);
        let handler = RefPtr::new(handler);
Loading