libtor
libtor copied to clipboard
Catching stdout/stderr of tor thread
I think it would be very helpful if it would be possible to catch the stdout/stderr of the tor thread. But as it's only a thread and not a sub/child process, I have no idea how to do it. Maybe it's not even possible?
I think it would be super helpful for things like parsing the log to achieve:
- knowing the progress of the bootstrapping
- parsing for errors/warnings
Currently the tor thread is quite a blackbox, of course it would be possible to communicate through the control port, but this would need another socket/lib to interact with. Parsing the log should be a lot more straight forward.
Maybe somebody has an idea how we could implement this?
I personally think that the best way to interact with Tor would be through its control port. In that regard this library is definitely lacking a few things that could make doing so easier: we could, for instance, automatically add the required flags, read the ControlPort value from file, read the cookie, etc. With some of those utilities it should become trivial to start Tor, get the authentication data and connect to its ControlPort to fetch whatever data one might need.
That said, I agree that it would still be pretty useful to have a way to capture and read logs from code, even just for potentially showing them to the user in a dedicated page or something like that.
I guess on UNIX systems we could create a pipe with mknod, then tell Tor to use that as a "file" for logging and finally start reading it like we would read a normal file using the filesystem APIs provided by Rust.
I'm not very familiar with Windows though, so I'm not sure if something similar can be done. I'll have to do some more research..
@Jikstra Using a mix of the control port and routing logs to a file gives you most of what you need (i think) A link to what i'm doing, in case it helps https://github.com/Sifir-io/sifir-rs-sdk/blob/main/tor/src/lib.rs#L282-L315
I'm not very familiar with Windows though, so I'm not sure if something similar can be done. I'll have to do some more research..
On windows we could use named pipes. I think they behave similarly to the unix pipes in that they can be opened with CreateFile. So I think it should work just fine (not tested though).