Circuit Control I
So far, we've seen two libraries as part of the Anyone NPM SDK:
Anon - the Anyone Client, which negotiates and maintains circuits through the network and runs a proxy server to forward traffic
AnonSocksClient - used in place of a typical requests library to forward get, post and other methods to the Anyone client!
Now, we will introduce one of the most powerful libraries - AnonControlClient - which interacts with the control port of the Anyone client and provides a new level of configurability. You can see circuit information that is hidden from most applications, send commands and manage circuits. Let's dive in!
Starting and Authenticating
For obvious reasons, not every app running locally alongside the Anyone Client can see or modify its behavior. Processes need to authenticate themselves on the client's control port and the AnonControlClient is no exception. Let's import it, much like the other libraries.
The control client is then instantiated much like anon, specifying the host and port number of the client to bind to. 127.0.0.1
and 9051
are the default values and will work with the default Anon object.
From there, assuming you have anon running anywhere in the local network, authenticating to the control port is simple
Let's create a new file control.js
and put this all together. Notice that, unlike the SOCKS client, the AnonControlClient is only instantiated after we have given the Anyone client time to establish itself. In addition, best practices are also to call .end()
on the control client once it is complete.
Running node control.js
should yield the following success message:
Reading Circuit Info
Now that we have authenticated, lets see what circuits have been created. The Anyone client often maintains multiple circuits within the network, and these can be seen as a JSON file with the circuitsStatus()
function.
Adding the above two lines after .authenticate
and running as before will see a new JSON file outputted, like below:
This shows a list of objects, each representing a single circuit - that shows the circuit's status and the first relay within it!
To get further relay info, you could call getRelayInfo
Last updated