🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: rocksolid.shared.tor
4 messages
4 total messages Started by Anonymous@news.n Tue, 11 May 2021 08:09
How to correctly read the control port when Tor is started with `--ControlPort a
#216
Author: Anonymous@news.n
Date: Tue, 11 May 2021 08:09
25 lines
1353 bytes
It is possible to start Tor with the following arguments (or parameters in Tor's config file):

    --ControlPort auto --ControlPortWriteToFile <TEMPORARY_FILE_PATH>>

So Tor [writes][1] to `<TEMPORARY_FILE_PATH>` file the following:

    PORT7.0.0.1:58771

and you just read it in your program. This sounds obvious but if I'm not missing something it is not.

So I think the following steps are necessary to read the correct port number:

1. Make sure that `<TEMPORARY_FILE_PATH>` does not exist [to eliminate risk that you read some old value].
1. Start Tor process with the arguments
1. Wait until `<TEMPORARY_FILE_PATH>` file exists [the file may exist but its content may not be flushed just yet now]
1. Repeat
    * Open `<TEMPORARY_FILE_PATH>` file for reading and read a single line (ending with `n`)
    * When the line starts with `PORT=`, you can parse the port -> success & break from loop.

I'm aware that you can start Tor and just wait few hunder milliseconds, read the file and you'll get *most likely* the correct port number. However, I want to read always the correct port number.

My question is: What is the recommended (and correct) procedure to read the control port number?

  [1]: https://github.com/torproject/tor/blob/1d18ecbc5f74e8aba8096e9bfd851ff775bbce0d/src/feature/control/control.c#L134
--
Posted on Rocksolid Light
Re: How to correctly read the control port when Tor is started with `--ControlPort a
#217
Author: Anonymous@news.n
Date: Tue, 11 May 2021 08:26
18 lines
826 bytes
Anonymous wrote:

> It is possible to start Tor with the following arguments (or parameters in Tor's config file):

>     --ControlPort auto --ControlPortWriteToFile <TEMPORARY_FILE_PATH>>

> So Tor [writes][1] to `<TEMPORARY_FILE_PATH>` file the following:

>     PORT7.0.0.1:58771

> and you just read it in your program. This sounds obvious but if I'm not missing something it is not.

> ...

> I'm aware that you can start Tor and just wait few hunder milliseconds, read the file and you'll get *most likely* the correct port number. However, I want to read always the correct port number.

Is the concern that you may read an old file? The steps you list sound correct and it should work. Maybe test the mtime (file modification time) to see if is a new file or not before using the info.
--
Posted on Rocksolid Light
Re: How to correctly read the control port when Tor is started with `--ControlPort a
#218
Author: Marc SCHAEFER
Date: Tue, 11 May 2021 08:30
7 lines
208 bytes
Anonymous <Anonymous@news.novabbs.org> wrote:
> My question is: What is the recommended (and correct) procedure to read the control port number?

Set it statically with:

   ControlPort

in the configuration?
Re: How to correctly read the control port when Tor is started with `--ControlPort a
#219
Author: Anonymous@news.n
Date: Wed, 12 May 2021 02:44
14 lines
696 bytes
Anonymous wrote:

> It is possible to start Tor with the following arguments (or parameters in Tor's config file):

>     --ControlPort auto --ControlPortWriteToFile <TEMPORARY_FILE_PATH>>

> So Tor [writes][1] to `<TEMPORARY_FILE_PATH>` file the following:

>     PORT7.0.0.1:58771

> and you just read it in your program. This sounds obvious but if I'm not missing something it is not.

If the control port is set only when Tor starts, you could use a script to modify torrc at each start with a new port number. You would create the port number randomly in your script. Then there is no need to read the log, you know the port number that the script generated.
--
Posted on Rocksolid Light
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads