Commit 491ab443 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

Do not add missing CRLF at the control port.

We will be building commands, no need to really include the logic to
add missing CRLF. Instead, catch malformed commands during development.
parent 0e880d8f
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
// <http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use bytes::{BufMut, Bytes, BytesMut};
use bytes::Bytes;
use std::{
    cell::Cell,
    rc::{Rc, Weak},
@@ -94,7 +94,7 @@ impl ControlPortInner {

    fn send_command(
        self: &Rc<Self>,
        mut command: Bytes,
        command: Bytes,
        handler: Box<dyn FnOnce(Result<Reply, ControlPortError>)>,
    ) {
        if self.closed.get() {
@@ -104,11 +104,10 @@ impl ControlPortInner {
            return;
        }

        if !command.ends_with(b"\r\n") {
            let mut buf = BytesMut::from(command);
            buf.put(&b"\r\n"[..]);
            command = buf.freeze();
        }
        debug_assert!(
            command.ends_with(b"\r\n"),
            "Commands are expected to end with CRLF."
        );

        // The callback is going to be called before other commands are sent,
        // therefore it is safe to queue the callback at this point, as next
+5 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use bytes::Bytes;
use nserror::nsresult;
use nserror::{NS_ERROR_NOT_CONNECTED, NS_OK};
use nsstring::{nsACString, nsCString};
@@ -68,10 +67,13 @@ impl ControlPortXpcom {
        command: &nsACString,
        handler: &torITorMessageHandler,
    ) -> Result<(), nsresult> {
        let command = Bytes::copy_from_slice(&command[..]);
        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_command(
            command,
            command.into(),
            Box::new(move |reply| {
                let mut buf = Vec::new();
                let reply = match reply {