Circuit Control II
Now that we've used the AnonControlClient to see some circuit info, lets use it to assemble circuits with a little more customization!
Creating a Random Circuit
We will be introducing the function extendCircuits , which is used to negotiate a new circuit. If no arguments are passed, extendCircuits will select a circuit using the default, randomized selection process, and return a circuit ID number.
const circuitID = await anonControlClient.extendCircuit();
console.log("Randomly created circuit:", circuitID);This circuit ID can then be used to manage it further, including closing that specific circuit:
await anonControlClient.closeCircuit(circuitID)Creating a Manual Circuit
The extendCircuit function can also take in an object structured like below, specifying the relays in order by fingerprint:
{
serverSpecs: [
"41E262A8DAFB34B7AD5F82280813584101E2A47A",
"41ADDE21CDCE614FF35DA58CDC15BC7A4A6DFE4D"
]
}As is evident, it is not essential to specify a path of exactly three relays. So long as the first fingerprint has the Guard flag (which means the relay can act as an entry relay) and the final fingerprint has the Exit flag (which means it's able to forward your traffic over the clear-web), the circuit can be of any length. It can even consist of a single node, so long as that relay can be both an Entry and Exit node!
How do we find the available fingerprints and the information needed to build a circuit from them? We have recently rolled out a new function in the NPM SDK: routerStatus that does exactly that!
Using the routerStatus Function
Note: Ensure that you have updated your npm client by running npm update within the working directory after it has been setup, to have access to this new function. Once the control client is setup, the new function simply needs to be called asynchronously:
Once the promise is resolved, the function returns a JSON file listing. Let's have a look at its format:
Relays are listed in order, and have their own object which includes information on its IP, bandwidth and flags!