Commands

These commands could be built by the end-user along with Controller.request() but the faster way is to use the corresponding wrapper provided on the Controller.

Base command class

class aiostem.command.Command[source]

Bases: object

Base class for all commands.

ADAPTER: ClassVar[TypeAdapter[Self] | None] = None

Cached adapter used while serializing the command.

command: ClassVar[CommandWord]

Command word this command is for.

classmethod adapter() TypeAdapter[Self][source]

Get a cached type adapter to serialize a command.

Return type:

TypeAdapter[Self]

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Serialize the command to text.

This command is not intended to be called by the end user.

Parameters:

struct (Mapping[str, Any]) – a dictionary serialization for this structure.

Returns:

str – Text that can be sent to Tor’s control port.

serialize() str[source]

Serialize this command to a string.

Return type:

str

Authentication commands

class aiostem.command.CommandAuthenticate[source]

Bases: Command

Command implementation for AUTHENTICATE.

This command is used to authenticate to the server.

command: ClassVar[CommandWord] = 'AUTHENTICATE'

Command word this command is for.

token: Annotated[bytes] | str | None = None

Password or token used to authenticate with the server.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append AUTHENTICATE specific arguments.

Return type:

str

class aiostem.command.CommandAuthChallenge[source]

Bases: Command

Command implementation for AUTHCHALLENGE.

This command is used to begin the authentication routine for the SAFECOOKIE authentication method.

NONCE_LENGTH: ClassVar[int] = 32

Length of the nonce we expect to receive (when bytes).

command: ClassVar[CommandWord] = 'AUTHCHALLENGE'

Command word this command is for.

nonce: Annotated[bytes] | str

Nonce value, a new one is generated when none is provided.

classmethod generate_nonce() bytes[source]

Generate a nonce value of 32 bytes.

Return type:

bytes

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append AUTHCHALLENGE specific arguments.

Return type:

str

Configuration commands

class aiostem.command.CommandGetConf[source]

Bases: Command

Command implementation for GETCONF.

Request the value of zero or more configuration variable(s).

command: ClassVar[CommandWord] = 'GETCONF'

Command word this command is for.

keywords: MutableSequence[str]

List of configuration keys to request (duplicates mean duplicate answers).

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append GETCONF specific arguments.

Return type:

str

class aiostem.command.CommandLoadConf[source]

Bases: Command

Command implementation for LOADCONF.

This command allows a controller to upload the text of a config file to Tor over the control port. This config file is then loaded as if it had been read from disk.

command: ClassVar[CommandWord] = 'LOADCONF'

Command word this command is for.

text: str

Raw configuration text to load.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append LOADCONF specific arguments.

Return type:

str

class aiostem.command.CommandResetConf[source]

Bases: CommandSetConf

Command implementation for RESETCONF.

Remove all settings for a given configuration option entirely, assign its default value (if any), and then assign the value provided.

command: ClassVar[CommandWord] = 'RESETCONF'

Command word this command is for.

class aiostem.command.CommandSaveConf[source]

Bases: Command

Command implementation for SAVECONF.

Instructs the server to write out its configuration options into torrc.

command: ClassVar[CommandWord] = 'SAVECONF'

Command word this command is for.

force: bool = False

If %include is used on torrc, SAVECONF will not write the configuration to disk. When set, the configuration will be overwritten even if %include is used. You can find out whether this flag is needed using config-can-saveconf on CommandGetInfo.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append SAVECONF specific arguments.

Return type:

str

class aiostem.command.CommandSetConf[source]

Bases: Command

Command implementation for SETCONF.

Change the value of one or more configuration variables.

command: ClassVar[CommandWord] = 'SETCONF'

Command word this command is for.

values: MutableMapping[str, MutableSequence[int | str] | int | str | None]

All the configuration values you want to set.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append SETCONF specific arguments.

Return type:

str

Hidden services commands

class aiostem.command.CommandAddOnion[source]

Bases: Command

Command implementation for ADD_ONION.

Tells Tor to create a new onion “hidden” Service, with the specified private key and algorithm.

command: ClassVar[CommandWord] = 'ADD_ONION'

Command word this command is for.

key: Annotated[Annotated[Annotated[RSAPrivateKey] | Annotated[Ed25519PrivateKey] | Annotated[OnionServiceKeyStruct]] | Annotated[OnionServiceNewKeyStruct]]

The service key, either provided directly of generated by Tor.

flags: Annotated[set[OnionServiceFlags]]

Set of boolean options to attach to this service.

max_streams: Annotated[int] | None = None

Optional number between 0 and 65535 which is the maximum streams that can be attached on a rendezvous circuit. Setting it to 0 means unlimited which is also the default behavior.

ports: MutableSequence[Annotated[VirtualPortTarget]]

As in an arguments to config HiddenServicePort, port,target.

client_auth: MutableSequence[Annotated[HsDescClientAuth]]

Client authentications for Onion V2, syntax is ClientName[:ClientBlob].

client_auth_v3: MutableSequence[Annotated[X25519PublicKey]]

String syntax is a base32-encoded x25519 public key with only the key part.

pow_defenses_enabled: bool | None = None

Enable proof-of-work based service DoS mitigation.

Note

Available starting from Tor v0.4.9.x

pow_queue_rate: Annotated[int] | None = None

The sustained rate of rendezvous requests to dispatch from the priority queue.

Note

Available starting from Tor v0.4.9.x

pow_queue_burst: Annotated[int] | None = None

The maximum burst size for rendezvous requests handled from the priority queue.

Note

Available starting from Tor v0.4.9.x

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append ADD_ONION specific arguments.

Return type:

str

class aiostem.command.CommandDelOnion[source]

Bases: Command

Command implementation for DEL_ONION.

Tells the server to remove an Onion “hidden” Service, that was previously created trough CommandAddOnion. It is only possible to remove onion services that were created on the same control connection as the DEL_ONION command, and those that belong to no control connection in particular (the DETACH flag was specified upon creation).

command: ClassVar[CommandWord] = 'DEL_ONION'

Command word this command is for.

address: Annotated[Annotated[HiddenServiceAddressV2] | Annotated[HiddenServiceAddressV3]]

This is the v2 or v3 address without the .onion suffix.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append DEL_ONION specific arguments.

Return type:

str

class aiostem.command.CommandHsFetch[source]

Bases: Command

Command implementation for HSFETCH.

This command launches hidden service descriptor fetch(es) for the given address.

command: ClassVar[CommandWord] = 'HSFETCH'

Command word this command is for.

servers: MutableSequence[LongServerName]

Optional list of servers to contact for a hidden service descriptor.

address: Annotated[Annotated[HiddenServiceAddressV2] | Annotated[HiddenServiceAddressV3]]

Onion address (v2 or v3) to request a descriptor for, without the .onion suffix.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append HSFETCH specific arguments.

Return type:

str

class aiostem.command.CommandHsPost[source]

Bases: Command

Command implementation for HSPOST.

This command launches a hidden service descriptor upload to the specified HSDirs. If one or more Server arguments are provided, an upload is triggered on each of them in parallel. If no Server options are provided, it behaves like a normal HS descriptor upload and will upload to the set of responsible HS directories.

command: ClassVar[CommandWord] = 'HSPOST'

Command word this command is for.

servers: MutableSequence[LongServerName]

List of servers to upload the descriptor to (if any is provided).

address: Annotated[Annotated[HiddenServiceAddressV2] | Annotated[HiddenServiceAddressV3]] | None = None

This is the optional v2 or v3 address without the .onion suffix.

descriptor: str

Descriptor content as raw text.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append HSPOST specific arguments.

Return type:

str

class aiostem.command.CommandOnionClientAuthAdd[source]

Bases: Command

Command implementation for ONION_CLIENT_AUTH_ADD.

Tells the connected Tor to add client-side v3 client auth credentials for the onion service with address. The key is the x25519 private key that should be used for this client, and nickname is an optional nickname for the client.

command: ClassVar[CommandWord] = 'ONION_CLIENT_AUTH_ADD'

Command word this command is for.

address: HiddenServiceAddressV3

V3 onion address without the .onion suffix.

key: Annotated[Annotated[X25519PrivateKey] | Annotated[OnionClientAuthKeyStruct]]

The private x25519 key used to authenticate to address.

nickname: str | None = None

An optional nickname for the client.

flags: Annotated[set[OnionClientAuthFlags]]

Whether this client’s credentials should be stored on the file system.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append ONION_CLIENT_AUTH_ADD specific arguments.

Return type:

str

class aiostem.command.CommandOnionClientAuthRemove[source]

Bases: Command

Command implementation for ONION_CLIENT_AUTH_REMOVE.

Tells the connected Tor to remove the client-side v3 client auth credentials for the onion service with address.

command: ClassVar[CommandWord] = 'ONION_CLIENT_AUTH_REMOVE'

Command word this command is for.

address: HiddenServiceAddressV3

V3 onion address without the .onion suffix.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append ONION_CLIENT_AUTH_REMOVE specific arguments.

Return type:

str

class aiostem.command.CommandOnionClientAuthView[source]

Bases: Command

Command implementation for ONION_CLIENT_AUTH_VIEW.

Tells the connected Tor to list all the stored client-side v3 client auth credentials for address. If no address is provided, list all the stored client-side v3 client auth credentials.

command: ClassVar[CommandWord] = 'ONION_CLIENT_AUTH_VIEW'

Command word this command is for.

address: HiddenServiceAddressV3 | None = None

V3 onion address without the .onion suffix.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append ONION_CLIENT_AUTH_VIEW specific arguments.

Return type:

str

Streams and circuits

class aiostem.command.CommandAttachStream[source]

Bases: Command

Command implementation for ATTACHSTREAM.

This message informs the server that the specified stream should be associated with the circuit.

command: ClassVar[CommandWord] = 'ATTACHSTREAM'

Command word this command is for.

stream: int

Stream to associate to the provided circuit.

circuit: int

Circuit identifier to attach the stream onto.

hop: int | None = None

When set, Tor will choose the HopNumth hop in the circuit as the exit node, rather that the last node in the circuit. Hops are 1-indexed; generally, it is not permitted to attach to hop 1.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append ATTACHSTREAM specific arguments.

Return type:

str

class aiostem.command.CommandCloseCircuit[source]

Bases: Command

Command implementation for CLOSECIRCUIT.

Tells the server to close the specified circuit.

When if_unused is True, do not close the circuit unless it is unused.

command: ClassVar[CommandWord] = 'CLOSECIRCUIT'

Command word this command is for.

circuit: int

Circuit identifier to close.

if_unused: bool = False

Do not close the circuit unless it is unused.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append CLOSECIRCUIT specific arguments.

Return type:

str

class aiostem.command.CommandCloseStream[source]

Bases: Command

Command implementation for CLOSESTREAM.

Tells the server to close the specified stream.

command: ClassVar[CommandWord] = 'CLOSESTREAM'

Command word this command is for.

stream: int

Identifier to the stream to close.

reason: StreamCloseReasonInt

Provide a reason for the stream to be closed.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append CLOSESTREAM specific arguments.

Return type:

str

class aiostem.command.CommandDropGuards[source]

Bases: Command

Command implementation for DROPGUARDS.

Tells the server to drop all guard nodes.

Warning

Do not invoke this command lightly; it can increase vulnerability to tracking attacks over time.

command: ClassVar[CommandWord] = 'DROPGUARDS'

Command word this command is for.

class aiostem.command.CommandExtendCircuit[source]

Bases: Command

Command implementation for EXTENDCIRCUIT.

This request takes one of two forms: either circuit is zero, in which case it is a request for the server to build a new circuit, or circuit is nonzero, in which case it is a request for the server to extend an existing circuit with that ID according to the specified path provided in servers.

command: ClassVar[CommandWord] = 'EXTENDCIRCUIT'

Command word this command is for.

circuit: int

Circuit identifier to extend, 0 to create a new circuit.

servers: Annotated[MutableSequence[LongServerName]]

List of servers to extend the circuit onto (or no server).

purpose: Literal[<CircuitPurpose.CONTROLLER: 'CONTROLLER'>, <CircuitPurpose.GENERAL: 'GENERAL'>] | None = None

Circuit purpose or None to use a default purpose.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append EXTENDCIRCUIT specific arguments.

Return type:

str

class aiostem.command.CommandRedirectStream[source]

Bases: Command

Command implementation for REDIRECTSTREAM.

Tells the server to change the exit address on the specified stream. If port is specified, changes the destination port as well.

No remapping is performed on the new provided address.

command: ClassVar[CommandWord] = 'REDIRECTSTREAM'

Command word this command is for.

stream: int

Stream identifier to redirect.

address: AnyHost

Destination address to redirect it to.

port: Annotated[int] | None = None

Optional port to redirect the stream to.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append REDIRECTSTREAM specific arguments.

Return type:

str

class aiostem.command.CommandSetCircuitPurpose[source]

Bases: Command

Command implementation for SETCIRCUITPURPOSE.

This changes the descriptor’s purpose.

Hints:

See CommandPostDescriptor for more details on purpose.

command: ClassVar[CommandWord] = 'SETCIRCUITPURPOSE'

Command word this command is for.

circuit: int

Circuit ID to set the purpose on.

purpose: Literal[<CircuitPurpose.CONTROLLER: 'CONTROLLER'>, <CircuitPurpose.GENERAL: 'GENERAL'>]

Set purpose of the provided circuit.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append SETCIRCUITPURPOSE specific arguments.

Return type:

str

Control commands

These commands have near to no side effect on the network but are used internally.

class aiostem.command.CommandDropOwnership[source]

Bases: Command

Command implementation for DROPOWNERSHIP.

This command instructs Tor to relinquish ownership of its control connection. As such tor will not shut down when this control connection is closed.

command: ClassVar[CommandWord] = 'DROPOWNERSHIP'

Command word this command is for.

class aiostem.command.CommandDropTimeouts[source]

Bases: Command

Command implementation for DROPTIMEOUTS.

Tells the server to drop all circuit build times.

Warning

Do not invoke this command lightly; it can increase vulnerability to tracking attacks over time.

command: ClassVar[CommandWord] = 'DROPTIMEOUTS'

Command word this command is for.

class aiostem.command.CommandGetInfo[source]

Bases: Command

Command implementation for GETINFO.

Unlike GETCONF this message is used for data that are not stored in the Tor configuration file, and that may be longer than a single line.

command: ClassVar[CommandWord] = 'GETINFO'

Command word this command is for.

keywords: MutableSequence[str]

List of keywords to request the value from. One or more must be provided.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append GETINFO specific arguments.

Return type:

str

class aiostem.command.CommandMapAddress[source]

Bases: Command

Command implementation for MAPADDRESS.

The client sends this message to the server in order to tell it that future SOCKS requests for connections to the original address should be replaced with connections to the specified replacement address.

command: ClassVar[CommandWord] = 'MAPADDRESS'

Command word this command is for.

addresses: MutableMapping[AnyHost, AnyHost]

Map of addresses to remap on socks requests.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append MAPADDRESS specific arguments.

Return type:

str

class aiostem.command.CommandProtocolInfo[source]

Bases: Command

Command implementation for PROTOCOLINFO.

This command tells the controller what kinds of authentication are supported.

command: ClassVar[CommandWord] = 'PROTOCOLINFO'

Command word this command is for.

version: int | None = None

Optional version to request information for (ignored by Tor at the moment).

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append PROTOCOLINFO specific arguments.

Return type:

str

class aiostem.command.CommandQuit[source]

Bases: Command

Command implementation for QUIT.

Tells the server to hang up on this controller connection.

command: ClassVar[CommandWord] = 'QUIT'

Command word this command is for.

class aiostem.command.CommandResolve[source]

Bases: Command

Command implementation for RESOLVE.

This command launches a remote hostname lookup request for every specified request (or reverse lookup if reverse is specified). Note that the request is done in the background: to see the answers, your controller will need to listen for EventWord.ADDRMAP events.

command: ClassVar[CommandWord] = 'RESOLVE'

Command word this command is for.

addresses: MutableSequence[AnyHost]

List of addresses get a resolution for.

reverse: bool = False

Whether we should perform a reverse lookup resolution.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append RESOLVE specific arguments.

Return type:

str

class aiostem.command.CommandSetEvents[source]

Bases: Command

Command implementation for SETEVENTS.

Request the server to inform the client about interesting events.

command: ClassVar[CommandWord] = 'SETEVENTS'

Command word this command is for.

events: set[EventWord]

Set of event names to receive the corresponding events.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append SETEVENTS specific arguments.

Return type:

str

class aiostem.command.CommandSignal[source]

Bases: Command

Command implementation for SIGNAL.

Send a signal to Tor.

command: ClassVar[CommandWord] = 'SIGNAL'

Command word this command is for.

signal: Signal

The signal to send to Tor.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append SIGNAL specific arguments.

Return type:

str

class aiostem.command.CommandTakeOwnership[source]

Bases: Command

Command implementation for TAKEOWNERSHIP.

This command instructs Tor to shut down when this control connection is closed. It affects each control connection that sends it independently; if multiple control connections send the TAKEOWNERSHIP command to a Tor instance, Tor will shut down when any of those connections closes.

command: ClassVar[CommandWord] = 'TAKEOWNERSHIP'

Command word this command is for.

class aiostem.command.CommandUseFeature[source]

Bases: Command

Command implementation for USEFEATURE.

Adding additional features to the control protocol sometimes will break backwards compatibility. Initially such features are added into Tor and disabled by default. USEFEATURE can enable these additional features.

Note

To get a list of available features please use features/names with CommandGetInfo.

command: ClassVar[CommandWord] = 'USEFEATURE'

Command word this command is for.

features: set[Feature | str]

Set of features to enable.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append USEFEATURE specific arguments.

Return type:

str

Bridge commands

class aiostem.command.CommandPostDescriptor[source]

Bases: Command

Command implementation for POSTDESCRIPTOR.

command: ClassVar[CommandWord] = 'POSTDESCRIPTOR'

Command word this command is for.

purpose: DescriptorPurpose | None = None

Purpose of the provided descriptor.

cache: Annotated[bool] | None = None

Cache the provided descriptor internally.

descriptor: str

Descriptor content.

serialize_from_struct(struct: Mapping[str, Any]) str[source]

Append POSTDESCRIPTOR specific arguments.

Return type:

str

Command serializer

class aiostem.command.CommandSerializer[source]

Helper class used to serialize an existing command.

__init__(name: CommandWord) None[source]

Create a new command serializer.

This is used internally by Command.serialize().

Parameters:

name (CommandWord) – The command name.

END_OF_LINE: ClassVar[str] = '\r\n'

End of line to use while serializing a command.

serialize() str[source]

Serialize the arguments to a string.

Returns:

str – Text that can be pushed to the server.

property command: CommandWord

Get the command name for the underlying command.

property arguments: MutableSequence[ArgumentKeyword | ArgumentString]

Get the list of command arguments.

property body: str | None

Get the command body, if any.

Command names

class aiostem.command.CommandWord[source]

Bases: StrEnum

All handled command words.

SETCONF = 'SETCONF'

Change the value of one or more configuration variables.

See also

RESETCONF = 'RESETCONF'

Remove all settings for a given configuration option entirely.

See also

GETCONF = 'GETCONF'

Request the value of zero or more configuration variable(s).

See also

SETEVENTS = 'SETEVENTS'

Request the server to inform the client about interesting events.

See also

AUTHENTICATE = 'AUTHENTICATE'

Used to authenticate to the server.

See also

SAVECONF = 'SAVECONF'

Instructs the server to write out its config options into its torrc.

See also

SIGNAL = 'SIGNAL'

Send a signal to the server.

See also

MAPADDRESS = 'MAPADDRESS'

Tell the server to replace addresses on future SOCKS requests.

See also

GETINFO = 'GETINFO'

Get server information.

See also

EXTENDCIRCUIT = 'EXTENDCIRCUIT'

Build a new or extend an existing circuit.

See also

SETCIRCUITPURPOSE = 'SETCIRCUITPURPOSE'

Change the purpose of a circuit.

See also

SETROUTERPURPOSE = 'SETROUTERPURPOSE'

Not implemented because it was marked as obsolete as of Tor v0.2.0.8.

ATTACHSTREAM = 'ATTACHSTREAM'

Request that the specified stream should be associated with the specified circuit.

See also

POSTDESCRIPTOR = 'POSTDESCRIPTOR'

This message informs the server about a new router descriptor.

See also

REDIRECTSTREAM = 'REDIRECTSTREAM'

Tells the server to change the exit address on the specified stream.

See also

CLOSESTREAM = 'CLOSESTREAM'

Tells the server to close the specified stream.

See also

CLOSECIRCUIT = 'CLOSECIRCUIT'

Tells the server to close the specified circuit.

See also

QUIT = 'QUIT'

Tells the server to hang up on this controller connection.

See also

USEFEATURE = 'USEFEATURE'

Enable additional features.

See also

RESOLVE = 'RESOLVE'

This command launches a remote hostname lookup request for every specified request.

See also

PROTOCOLINFO = 'PROTOCOLINFO'

This command tells the controller what kinds of authentication are supported.

See also

LOADCONF = 'LOADCONF'

This command allows to upload the text of a config file to Tor over the control port.

See also

TAKEOWNERSHIP = 'TAKEOWNERSHIP'

Instructs Tor to shut down when this control connection is closed.

See also

AUTHCHALLENGE = 'AUTHCHALLENGE'

Begin the authentication routine for the SAFECOOKIE method.

See also

DROPGUARDS = 'DROPGUARDS'

Tells the server to drop all guard nodes.

See also

HSFETCH = 'HSFETCH'

Launches hidden service descriptor fetch(es).

See also

ADD_ONION = 'ADD_ONION'

Tells the server to create a new onion “hidden” service.

See also

DEL_ONION = 'DEL_ONION'

Tells the server to remove an onion “hidden” service.

See also

HSPOST = 'HSPOST'

This command launches a hidden service descriptor upload to the specified HSDirs.

See also

ONION_CLIENT_AUTH_ADD = 'ONION_CLIENT_AUTH_ADD'

Add client-side v3 client auth credentials for a onion service.

See also

ONION_CLIENT_AUTH_REMOVE = 'ONION_CLIENT_AUTH_REMOVE'

Remove client-side v3 client auth credentials for a onion service.

See also

ONION_CLIENT_AUTH_VIEW = 'ONION_CLIENT_AUTH_VIEW'

List client-side v3 client auth credentials for a onion service.

See also

DROPOWNERSHIP = 'DROPOWNERSHIP'

This command instructs Tor to relinquish ownership of its control connection.

See also

DROPTIMEOUTS = 'DROPTIMEOUTS'

Tells the server to drop all circuit build times.

See also