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>

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>

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[]>

Retrieves the current circuit status. Returns: A promise that resolves with an array of CircuitStatus objects.

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>

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>

Retrieves information about a relay.

  • fingerprint: string - The fingerprint of the relay Returns: A promise that resolves with a RelayInfo object.

end(): void

Closes the connection to the Anon Control Port.

Interfaces

CircuitStatus

  • circuitId: number

  • state: string

  • relays: Relay[]

  • buildFlags: string[]

  • purpose: string

  • timeCreated: Date

Relay

  • fingerprint: string

  • nickname: string

ExtendCircuitOptions

  • circuitId?: number

  • serverSpecs?: string[]

  • purpose?: 'general' | 'controller'

RelayInfo

  • fingerprint: string

  • nickname: string

  • ip: string

  • orPort: number

  • flags: 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();

Last updated