bulb/control~ TorControl

new TorControl(socket, optionsopt)

Parameters:
NameTypeAttributesDescription
socketSocket

net.Socket connected to Tor's control port

optionsobject<optional>
Properties
NameTypeAttributesDefaultDescription
authOnConnectboolean<optional>
true

Automatically authenticate

Methods

addEventListeners(events)

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

attachStream(streamId, circuitIdopt, hopNumberopt)

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

authenticate(token)

Authenticates with the control port given the supplied param

Parameters:
NameTypeDescription
tokenstring

cleanCircuits()

Clears DNS cache and establishes new clean circuits

clearDnsCache()

Forget client side hostname->ip cache

closeCicuit(circuitId, optionsopt)

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

closeStream(streamId, reasonopt)

Closes the exit for the given stream

Parameters:
NameTypeAttributesDefaultDescription
streamIdstring

ID for the stream to close

reasonnumber<optional>
1

Reason code for closing stream

createAddressMapping(target, replacement)

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

createCircuit(purposeopt)

Creates a new circuit, returning the newly created circuit ID

Parameters:
NameTypeAttributesDefaultDescription
purposestring<optional>
"general"

The circuit purpose, either general|controller

createHiddenService(ports, optionsopt)

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

destroyHiddenService(serviceId)

Takes down a running hidden service owned by this controller

Parameters:
NameTypeDescription
serviceIdstring

Tor hidden service ID

dropGuards()

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

dumpHeartbeat()

Dumps a heartbeat message to the logs

dumpStats()

Dump stats to tor log file

enableDebug()

Set open logs to debug level

extendCircuit(circuitId)

Extends the existing circuit

Parameters:
NameTypeDescription
circuitIdstring

The circuit ID to extend

fetchHiddenServiceDescriptor(serviceId, serverLongNameopt)

Fetches descriptors for the given hidden service

Parameters:
NameTypeAttributesDescription
serviceIdstring

ID for the hidden service

serverLongNamestring<optional>

Long name for specific server to use

getAuthChallenge(nonce)

Requests an authentication challenge from tor

Parameters:
NameTypeDescription
noncestring

Client nonce for authenticating

getConfig(keyword)

Return the values for the given configuration key

Parameters:
NameTypeDescription
keywordstring

Configuration key

getInfo(keyword)

Get information from Tor not stored in configuration

Parameters:
NameTypeDescription
keywordstring

Keyword for info to fetch

getProtocolInfo()

Ask tor for general information

halt()

Shutdown tor immediately

loadConfig(configText)

Instruct Tor to load the configuration file from the given text

Parameters:
NameTypeDescription
configTextstring

Complete torrc config text to load

postDescriptor(descriptor, optionsopt)

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

postHiddenServiceDescriptor(descriptor, serverLongNameopt)

Launch a hidden service descriptor upload

Parameters:
NameTypeAttributesDescription
descriptorstring
serverLongNamestring<optional>

Long name for specific server to use

quit()

Tells Tor to hang up on the controller

redirectStream(streamId, address, portopt)

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

reloadConfig()

Reloads the config values set

removeEventListeners()

Instructs Tor to stop listening for events

resetConfig(keyword)

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

Parameters:
NameTypeDescription
keywordstring

Configuration key

resolve(address, optionsopt)

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

saveConfig()

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

setCircuitPurpose(circuitId, purpose)

Sets the purpose of the given circuit

Parameters:
NameTypeDescription
circuitIdstring

The identifier for the circuit

purposestring

One of general|controller

setConfig(keyword, value)

Change the value for a configuration variable

Parameters:
NameTypeDescription
keywordstring

Configuration key

valuestring

New value to set

shutdown()

Controlled shutdown signal

signal(signal)

Sends a signal to the control port

Parameters:
NameTypeDescription
signalstring

takeOwnership()

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

(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

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