[tor-dev] Embedding tor in an application and using tor without opening a port

wac waldoalvarez00 at yahoo.com
Sat Apr 13 17:42:35 UTC 2013

Hi Navis:

Good to hear you built it. I have a working library with a defined API but is not re-entrant. It can connect with a server over Tor circuits and transmit/receive data but nothing is re-entrant at all. So the same Tor thread must be used for all of that ATM.

I can fetch webpages like that however and can also do some limited chit-chat over IRC.

I attempted to add some locking to some of the data structures but that is insufficient. For instance lists and buffers. Hash tables are complex. They are defined with some macros in order to make them generic overcoming some limitations of C language but they are less than maintainable IMHO. So I was thinking to replace them with another one already built with a similar license but re-entrant. Found a very good one.

I have a couple of ideas to make it usable before that happens however.

Seems you want to put your hands at it so that makes two of us. You don't need to do what I already did. I am preparing the environment to move towards team mode. Check the website http://libtor.org. In any case remember all of this to make it solid is not just about coding.


On Thu, Apr 11, 2013 21:29 EDT Navin Francis wrote:

>I managed to build it with MSVC after tinkering with the code a little. Did
>you guys make any progress in making tor a library? It seems like I can
>directly call functions like handle_getinfo_helper in control.c to control
>//Application that starts tor in a new thread in the same process
>#include <future>
>#include <iostream>
>#include "libtor.h"
>using namespace std;
>int main(int argc, char *argv[]){
>auto tor_return=async(launch::async,start_tor_main,argc, argv);
>while (tor_return.wait_for(chrono::seconds(2))!=future_status::ready){
>char *ans;
>const char *errmsg;
>handle_getinfo_helper(NULL, "config/names", &ans, &errmsg);
>cout<"application is running! ["<ans<"]"<endl;
>return tor_return.get();
>//Duplicates the definitions in Tor. If there is a way around this, do
>tell! :)
>extern "C"{
>int start_tor_main(int argc, char *argv[]);//Tor's main() is renamed to
>handle_getinfo_helper(void *control_conn,
>const char *question, char **answer,
>const char **err_out);
>It seems like handle_getinfo_helper is called asynchronously by tor
>whenever a GETINFO is recieved on the control port so I don't need
>locking/synchronization. Can someone confirm this?
>On Sun, Apr 7, 2013 at 4:40 AM, Gisle Vanem <gvanem at broadpark.no> wrote:
>> I didn't read the original messege on this, but you have problem building
>> Tor and it's libs using MSVC? If so,
>> you could try my "GNU make" based system for MingW +
>> MSVC here:
>>  http://home.broadpark.no/~**gvanem/misc/#tor<http://home.broadpark.no/~gvanem/misc/#tor>
>>  http://home.broadpark.no/~**gvanem/misc/tor-windows.zip<http://home.broadpark.no/~gvanem/misc/tor-windows.zip>
>> I just tested it with today's Tor Git-repo. And it works for me.
>> --gv

More information about the tor-dev mailing list