TorController

Represents a Tor controller for issuing commands

Constructor

new TorController(socket, optionsopt)

Parameters:
NameTypeAttributesDescription
socketSocket

net.Socket connected to Tor's control port

optionsobject<optional>
Properties
NameTypeAttributesDefaultDescription
authOnConnectboolean<optional>
true

Automatically authenticate

Methods

(static) createChallengeResponse(cookie, clientNonce, serverNonce) → {string}

Creates the challenge response from a SAFECOOKIE challenge

Parameters:
NameTypeDescription
cookiestring

The secret cookie string

clientNoncestring

Client nonce sent with auth challenge

serverNoncestring

Server nonce reply from auth challenge

Returns:
Type: 
string

(static) createReplySplitter()

Creates a message splitter from incoming socket data

addEventListeners(events, callback)

Instructs Tor to send asynchronous events for the given types - these events will be emitted from the controller. Calling this method resets previously set event listeners

Parameters:
NameTypeDescription
eventsArray.<string>

List of event types to listen for

callbackTorController~addEventListenersCallback

attachStream(streamId, circuitIdopt, hopNumberopt, callback)

Attaches the specified stream to the given circuit

Parameters:
NameTypeAttributesDefaultDescription
streamIdstring

ID for the stream to attach

circuitIdstring<optional>
0

Circuit to attach stream

hopNumbernumber<optional>

Which hop to exit circuit

callbackTorController~attachStreamCallback

authenticate(token, callback)

Authenticates with the control port given the supplied param

Parameters:
NameTypeDescription
tokenstring
callbackTorController~authenticateCallback

cleanCircuits(callback)

Clears DNS cache and establishes new clean circuits

Parameters:
NameTypeDescription
callbackTorController~cleanCircuitsCallback

clearDnsCache(callback)

Forget client side hostname->ip cache

Parameters:
NameTypeDescription
callbackTorController~clearDnsCacheCallback

closeCicuit(circuitId, optionsopt, callback)

Closes the given circuit

Parameters:
NameTypeAttributesDescription
circuitIdstring

ID for the circuit to close

optionsobject<optional>
Properties
NameTypeAttributesDefaultDescription
ifUnusedboolean<optional>
false

Only close if not in use

callbackTorController~closeCircuitCallback

closeStream(streamId, reasonopt, callback)

Closes the exit for the given stream

Parameters:
NameTypeAttributesDefaultDescription
streamIdstring

ID for the stream to close

reasonnumber<optional>
1

Reason code for closing stream

callbackTorController~closeStreamCallback

createAddressMapping(target, replacement, callback)

Instruct Tor to route requests to the target to the replacement

Parameters:
NameTypeDescription
targetstring

Original address to map

replacementstring

New address to route request to target

callbackTorController~createAddressMappingCallback

createCircuit(purposeopt, callback)

Creates a new circuit, returning the newly created circuit ID

Parameters:
NameTypeAttributesDefaultDescription
purposestring<optional>
"general"

The circuit purpose, either general|controller

callbackTorController~createCircuitCallback

createHiddenService(ports, optionsopt, callback)

Establishes a hidden service on the given target

Parameters:
NameTypeAttributesDescription
portsarray

Array containing optional virtualPort (defaults to 80) and target ip:port string

optionsobject<optional>

module:commands#ADD_ONION

callbackTorController~createHiddenServiceCallback

destroyHiddenService(serviceId, callback)

Takes down a running hidden service owned by this controller

Parameters:
NameTypeDescription
serviceIdstring

Tor hidden service ID

callbackTorController~destroyHiddenServiceCallback

dropGuards(callback)

Tells the server to drop all guard nodes. Do not invoke this command lightly; it can increase vulnerability to tracking attacks over time.

Parameters:
NameTypeDescription
callbackTorController~dropGuardsCallback

dumpHeartbeat(callback)

Dumps a heartbeat message to the logs

Parameters:
NameTypeDescription
callbackTorController~dumpHeartbeatCallback

dumpStats(callback)

Dump stats to tor log file

Parameters:
NameTypeDescription
callbackTorController~dumpStatsCallback

enableDebug(callback)

Set open logs to debug level

Parameters:
NameTypeDescription
callbackTorController~enableDebugCallback

extendCircuit(circuitId, callback)

Extends the existing circuit

Parameters:
NameTypeDescription
circuitIdstring

The circuit ID to extend

callbackTorController~extendCircuitCallback

fetchHiddenServiceDescriptor(serviceId, serverLongNameopt, callback)

Fetches descriptors for the given hidden service

Parameters:
NameTypeAttributesDescription
serviceIdstring

ID for the hidden service

serverLongNamestring<optional>

Long name for specific server to use

callbackTorController~fetchHiddenServiceDescriptorCallback

getAuthChallenge(nonce, callback)

Requests an authentication challenge from tor

Parameters:
NameTypeDescription
noncestring

Client nonce for authenticating

callbackTorController~getAuthChallengeCallback

getConfig(keyword, callback)

Return the values for the given configuration key

Parameters:
NameTypeDescription
keywordstring

Configuration key

callbackTorController~getConfigCallback

getInfo(keyword, callback)

Get information from Tor not stored in configuration

Parameters:
NameTypeDescription
keywordstring

Keyword for info to fetch

callbackTorController~getInfoCallback

getProtocolInfo(callback)

Ask tor for general information

Parameters:
NameTypeDescription
callbackTorController~getProtocolInfoCallback

halt(callback)

Shutdown tor immediately

Parameters:
NameTypeDescription
callbackTorController~haltCallback

loadConfig(configText, callback)

Instruct Tor to load the configuration file from the given text

Parameters:
NameTypeDescription
configTextstring

Complete torrc config text to load

callbackTorController~loadConfigCallback

postDescriptor(descriptor, optionsopt, callback)

Inform the server about a new descriptor

Parameters:
NameTypeAttributesDescription
descriptorobject

Key-value pairs for server descriptor

optionsobject<optional>
Properties
NameTypeAttributesDefaultDescription
purposestring<optional>
"general"

general|controller|bridge

cacheboolean<optional>
true

Flag for caching descriptor

callbackTorController~postDescriptorCallback

postHiddenServiceDescriptor(descriptor, serverLongNameopt, callback)

Launch a hidden service descriptor upload

Parameters:
NameTypeAttributesDescription
descriptorstring
serverLongNamestring<optional>

Long name for specific server to use

callbackTorController~postHiddenServiceDescriptorCallback

quit(callback)

Tells Tor to hang up on the controller

Parameters:
NameTypeDescription
callbackTorController~quitCallback

redirectStream(streamId, address, portopt, callback)

Change the exit address on a given stream

Parameters:
NameTypeAttributesDescription
streamIdstring

ID for stream to redirect

addressstring

Exit address for the given stream

portnumber<optional>

Exit port for the given stream

callbackTorController~redirectStreamCallback

reloadConfig(callback)

Reloads the config values set

Parameters:
NameTypeDescription
callbackTorController~reloadConfigCallback

removeEventListeners(callback)

Instructs Tor to stop listening for events

Parameters:
NameTypeDescription
callbackTorController~removeEventListenersCallback

resetConfig(keyword, callback)

Change the value for a configuration variable to it's default

Parameters:
NameTypeDescription
keywordstring

Configuration key

callbackTorController~resetConfigCallback

resolve(address, optionsopt, callback)

Launch remote hostname lookup - answer returnd as async ADDRMAP event

Parameters:
NameTypeAttributesDescription
addressstring

Address to lookup

optionsobject<optional>
Properties
NameTypeAttributesDefaultDescription
reverseboolean<optional>
false

Perform reverse lookup

callbackTorController~resolveCallback

saveConfig(callback)

Tell Tor to write out it's config value to it's torrc

Parameters:
NameTypeDescription
callbackTorController~saveConfigCallback

setCircuitPurpose(circuitId, purpose, callback)

Sets the purpose of the given circuit

Parameters:
NameTypeDescription
circuitIdstring

The identifier for the circuit

purposestring

One of general|controller

callbackTorController~setCircuitPurposeCallback

setConfig(keyword, value, callback)

Change the value for a configuration variable

Parameters:
NameTypeDescription
keywordstring

Configuration key

valuestring

New value to set

callbackTorController~setConfigCallback

shutdown(callback)

Controlled shutdown signal

Parameters:
NameTypeDescription
callbackTorController~shutdownCallback

signal(signal, callback)

Sends a signal to the control port

Parameters:
NameTypeDescription
signalstring
callbackTorController~signalCallback

takeOwnership(callback)

Take ownership of the tor process - will close tor when the connection closes

Parameters:
NameTypeDescription
callbackTorController~takeOwnershipCallback

Type Definitions

addEventListenersCallback(error)

Parameters:
NameTypeDescription
errorobject | null

attachStreamCallback(error)

Parameters:
NameTypeDescription
errorobject | null

cleanCircuitsCallback(error)

Parameters:
NameTypeDescription
errorobject | null

clearDnsCacheCallback(error)

Parameters:
NameTypeDescription
errorobject | null

closeCircuitCallback(error)

Parameters:
NameTypeDescription
errorobject | null

closeStreamCallback(error)

Parameters:
NameTypeDescription
errorobject | null

createAddressMappingCallback(error)

Parameters:
NameTypeDescription
errorobject | null

createCircuitCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultArray.<string>

createHiddenServiceCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultAddOnionResult

destroyHiddenServiceCallback(error)

Parameters:
NameTypeDescription
errorobject | null

dropGuardsCallback(error)

Parameters:
NameTypeDescription
errorobject | null

dumpHeartbeatCallback(error)

Parameters:
NameTypeDescription
errorobject | null

dumpStatsCallback(error)

Parameters:
NameTypeDescription
errorobject | null

enableDebugCallback(error)

Parameters:
NameTypeDescription
errorobject | null

extendCircuitCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultArray.<string>

fetchHiddenServiceDescriptorCallback(error)

Parameters:
NameTypeDescription
errorobject | null

getAuthChallengeCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultAuthChallengeResult

getConfigCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultGetConfigResult

getInfoCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultstring

getProtocolInfoCallback(error, result)

Parameters:
NameTypeDescription
errorobject | null
resultProtocolInfoResult

haltCallback(error)

Parameters:
NameTypeDescription
errorobject | null

loadConfigCallback(error)

Parameters:
NameTypeDescription
errorobject | null

postDescriptorCallback(error)

Parameters:
NameTypeDescription
errorobject | null

postHiddenServiceDescriptorCallback(error)

Parameters:
NameTypeDescription
errorobject | null

quitCallback(error)

Parameters:
NameTypeDescription
errorobject | null

redirectStreamCallback(error)

Parameters:
NameTypeDescription
errorobject | null

reloadConfigCallback(error)

Parameters:
NameTypeDescription
errorobject | null

resetConfigCallback(error)

Parameters:
NameTypeDescription
errorobject | null

resolveCallback(error)

Parameters:
NameTypeDescription
errorobject | null

saveConfigCallback(error)

Parameters:
NameTypeDescription
errorobject | null

setCircuitPurposeCallback(error)

Parameters:
NameTypeDescription
errorobject | null

setConfigCallback(error)

Parameters:
NameTypeDescription
errorobject | null

shutdownCallback(error)

Parameters:
NameTypeDescription
errorobject | null

signalCallback(error)

Parameters:
NameTypeDescription
errorobject | null

takeOwnershipCallback(error)

Parameters:
NameTypeDescription
errorobject | null

Events

close

Fires when the underlying socket closes

error

Fired when the underlying socket encounters an error

Type:
  • error

ready

Fires when the controller is authenticated and ready to send commands