Module interpreter

Module interpreter 

Source
Expand description

Interactive interpreter for Tor control protocol.

This module provides an interactive command interpreter for interacting with Tor’s control interface, supporting both interpreter commands (like /help, /events, /info) and direct Tor control commands.

§Overview

The interpreter provides a REPL-like interface for communicating with Tor, adding usability features such as:

  • IRC-style interpreter commands (prefixed with /)
  • Direct Tor control protocol command passthrough
  • Event buffering and filtering
  • Relay information lookup by fingerprint, nickname, or IP address
  • Tab completion support via the autocomplete module
  • Built-in help system via the help module

§Interpreter Commands

Commands prefixed with / are handled by the interpreter itself:

CommandDescription
/help [topic]Display help information
/events [types...]Show buffered events, optionally filtered by type
/events CLEARClear the event buffer
/info [relay]Show information about a relay
/python enable|disableToggle Python command mode
/quitExit the interpreter

All other commands are passed directly to Tor’s control interface.

§Architecture

The interpreter wraps a Controller and maintains:

  • A bounded event buffer (most recent 100 events)
  • Multiline context state for complex commands
  • Python command mode toggle

§Example

use stem_rs::Controller;
use stem_rs::interpreter::ControlInterpreter;

let mut controller = Controller::from_port("127.0.0.1:9051".parse()?).await?;
controller.authenticate(None).await?;

let mut interpreter = ControlInterpreter::new(&mut controller);

// Run interpreter commands
let help = interpreter.run_command("/help").await?;
println!("{}", help);

// Run Tor control commands
let version = interpreter.run_command("GETINFO version").await?;
println!("Tor version: {}", version);

§See Also

§Python Stem Equivalent

This module corresponds to Python Stem’s stem.interpreter module.

Modules§

arguments
Command-line argument parsing for the interpreter prompt.
autocomplete
Tab completion for the interpreter prompt.
help
Help system for the interpreter prompt.

Structs§

ControlInterpreter
Interactive command interpreter for Tor control protocol.