AnonControlClient
The AnonControlClient class provides a way to interact with the Anon Control Port, allowing you to authenticate, send commands, and manage circuits.
Constructor
constructor(host: string = '127.0.0.1', port: number = 9051) Creates a new instance of the AnonControlClient class.
host:string- The host of the Anon Control Port. Default:'127.0.0.1'port:number- The port number of the Anon Control Port. Default:9051
Methods
authenticate(password: string = 'password'): Promise<void>
authenticate(password: string = 'password'): Promise<void>Authenticates the client with the Anon Control Port.
password:string- The password for authentication. Default:'password'Returns: A promise that resolves when authentication is successful.
sendCommand(command: string): Promise<string>
sendCommand(command: string): Promise<string>Sends a command to the Anon Control Port.
command:string- The command to send Returns: A promise that resolves with the response from the Anon Control Port.
circuitStatus(): Promise<CircuitStatus[]>
circuitStatus(): Promise<CircuitStatus[]>Retrieves the current circuit status. Returns: A promise that resolves with an array of CircuitStatus objects.
extendCircuit(options: ExtendCircuitOptions = {}): Promise<number>
extendCircuit(options: ExtendCircuitOptions = {}): Promise<number>Extends an existing circuit or creates a new one.
options:ExtendCircuitOptions- Options for extending the circuit Returns: A promise that resolves with the circuit ID.
closeCircuit(circuitId: number): Promise<void>
closeCircuit(circuitId: number): Promise<void>Closes a specified circuit.
circuitId:number- The ID of the circuit to close Returns: A promise that resolves when the circuit is closed.
getRelayInfo(fingerprint: string): Promise<RelayInfo>
getRelayInfo(fingerprint: string): Promise<RelayInfo>Retrieves information about a relay.
fingerprint:string- The fingerprint of the relay Returns: A promise that resolves with a RelayInfo object.
end(): void
end(): voidCloses the connection to the Anon Control Port.
Interfaces
CircuitStatus
circuitId:numberstate:stringrelays:Relay[]buildFlags:string[]purpose:stringtimeCreated:Date
Relay
fingerprint:stringnickname:string
ExtendCircuitOptions
circuitId?:numberserverSpecs?:string[]purpose?:'general' | 'controller'
RelayInfo
fingerprint:stringnickname:stringip:stringorPort:numberflags:string[]bandwidth:number
Usage Example
import { AnonControlClient } from '@anyone-protocol/anyone-client';
const client = new AnonControlClient();
async function example() {
try {
await client.authenticate('your_password');
const circuits = await client.circuitStatus();
console.log('Current circuits:', circuits);
const newCircuitId = await client.extendCircuit();
console.log('New circuit created with ID:', newCircuitId);
const relayInfo = await client.getRelayInfo('RELAY_FINGERPRINT');
console.log('Relay info:', relayInfo);
await client.closeCircuit(newCircuitId);
console.log('Circuit closed');
} catch (error) {
console.error('Error:', error.message);
} finally {
client.end();
}
}
example();