[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



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 tor.

//application_main.cpp
//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();
}

//libtor.h
//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 start_tor_main
int
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@xxxxxxxxxxxx> 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-windows.zip

I just tested it with today's Tor Git-repo. And it works for me.

--gv

_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev