Opened 10 years ago

Closed 9 years ago

Last modified 2 years ago

#1967 closed enhancement (wontfix)

The ancient architecture of Tor!!

Reported by: bee Owned by:
Priority: Medium Milestone:
Component: Core Tor/Tor Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:



Phobos (andrew, i mean the blogger at Tor!!!) told me Nick Mathewson is the chief architect of Tor!!!!!!
So i began to ask myself!!! what is the architecture of Tor?!!!!!!
Well, what's the architecture of a software in general actually!!!!!! I recall i read something about it, while reading the instructions to write RPMs for red hat!!!!!
So, when you're making a package, you've to split it in three packages!!! One package is for the "library", also known as "the shared object"!! The second one is for the "headers" for developing C software using that library! and the last one is the package within the main executable, usually a command line tool!!!!
For example, you've a package with the library of "cURL" (it's a package with .so files), another one with the headers (they're files .h, it's named after cURL-devel) and the last one is "cURL" itself, with the command line tool!!!!!!!!!!!!!!
Well, TOR is not respecting this architecture!!!!
I think it would be better to have tor made in this way!!:

  • a file!!
  • tor.h, the header for C
  • tor, the command line tool (a command line wrapper for the functions in!!!)

This new architecture is going to improve the whole tor-project a lot!!!!!!!!!!!!!
Because you could have software, made to work only with Tor!!! YEAH!!, say "tor-ready"!!!!!!!!!!

You could have a Chat system or P2P software built on "libtor"!!! And they could control everything of Tor, automatically and autonomously!!!!!!! They won't need to fork a new process and start the "tor" executable!!! And they won't need to open a local socks-server and a control port!!!! Because those software can be able to load the tor's library and they can directly call the functions they need!!!!!!!!!!!!!!!

The current command line interface for Tor has to load "libtor" too, parse the command line and call the right functions!!!!!
A software like VIDALIA, could do the same!!!! It could control tor loading the "libtor", without needing to fork its process and start the executable "tor"(like "tor.exe") and talk to it via sockets!!!!!!! (also, i don't understand why you use real TCP sockets instead of PIPEs or UNIX sockets to control Tor from VIDALIA in very local sessions!!)

So, i began to look something in the source code of Tor!! and i think that creating a library could be very easy!!!!!!!
At first i built tor!!! and this is the line MAKE uses to create the executable:

gcc  -g -O2 -Wall -g -O2 -fno-strict-aliasing -L/tmp/libevent/lib
 -Wl,-R/tmp/libevent/lib  -o tor buffers.o circuitbuild.o
 circuitlist.o circuituse.o command.o config.o connection.o
 connection_edge.o connection_or.o control.o cpuworker.o
 directory.o dirserv.o dirvote.o dns.o dnsserv.o geoip.o
 hibernate.o main.o  networkstatus.o onion.o policies.o reasons.o
 relay.o rendcommon.o rendclient.o rendmid.o rendservice.o
 rephist.o router.o routerlist.o routerparse.o eventdns.o
 tor_main.o ../common/libor.a ../common/libor-crypto.a 
-lz -levent -lssl -lcrypto   -lpthread -ldl 

At first i think there is a minor flaw!!! "-g -O2 -Wall -g -O2" has "-g -O2" repeated two times, and this is purposeless!!!!!!!!but it's not a real bug!!!!
Well, anyhow, i noticed that there are two files with names very easy to understand: tor_main.o and main.o!!!!
So, i found the real "main()" in tor_main.o!!!!!!!! I think that if you remove it, it's enough to have a working shared object!!!!!!!!!

I then managed to create this command line!!!!!

$ gcc -shared -Wall -g -O2 -fno-strict-aliasing -L/tmp/libevent/lib
 -Wl,-R/tmp/libevent/lib  -o buffers.o circuitbuild.o
 circuitlist.o circuituse.o command.o config.o connection.o
 connection_edge.o connection_or.o control.o cpuworker.o
 directory.o dirserv.o dirvote.o dns.o dnsserv.o geoip.o
 hibernate.o main.o  networkstatus.o onion.o policies.o
 reasons.o relay.o rendcommon.o rendclient.o rendmid.o
 rendservice.o rephist.o router.o routerlist.o routerparse.o
 eventdns.o ../common/libor.a ../common/libor-crypto.a 
-lz -levent -lssl -lcrypto   -lpthread -ldl

You've to move in "./src/or" to use it!!!!!!!!! I removed a "-g -O2" and also the "tor_main.o" file from the linker!!!("linker" is the name of the step you use to create an executable using the object files!!!!!!!!!!)
I also added the "-shared" switch because i want a shared library!! and i changed the output file name to "-o"!!!!!!!!!!
That command worked with no errors!!!!!!!!!!! but i don't know if it works for real!!!!!!!!!!!
If i type "$ objdump -t" i can read the names of exported functions!!!!!! This is a small piece of the objdumps list!!!!

000b6f90 g     F .text  00000259              tor_init
00000000       F *UND*  00000000              munmap@@GLIBC_2.0
0010c210 g     F .text  000000a0              crypto_dh_generate_public
0007ced0 g     F .text  000002ad              connection_get_by_type_state_rendquery
000d9640 g     F .text  00000021              is_legal_nickname_or_hexdigest
00105de0 g     F .text  000000a5              smartlist_free
0005f3d0 g     F .text  00000136              write_to_buf_zlib
000665a0 g     F .text  000000a1              any_bridge_descriptors_known
000d8740 g     F .text  0000041a              rep_hist_load_state
0007b0d0 g     F .text  0000003f              connection_is_listener
00000000       F *UND*  00000000              EVP_PKEY_assign
0010d540 g     F .text  0000009e              crypto_cipher_decrypt_init_cipher

I believe "tor_init" being the real function to call, to initialize the library!!!!!!!!!!!!!

Well, this super analysis i made!!!!! could be useful for you!!!!!!!!!!!!
It's because i think that you've to create the tor library as i suggested!! and then allow people to build software around it!!!!!!! The command line tool of Tor will be just a software, one of the many!! using the shared library!!!!
Also vidalia could be made to work without executing "tor"/"tor.exe"!!!!!!!!!
Perhaps, you could also build a whole web browser made to work with Tor!!!!!!!!!!!!! and a system to exchange files, emails, chat, and whatever absolutely autonomous!!! based only on and working without requiring to start another process and connect to it!!!!!
Yeah!!!, this is the right architecture for software!!!!!!! The KERNEL and the interfaces (GUI, graphical interfaces; or CLI, command line interfaces) should be split!!!!!!!!!!!
If you write a software in C, or C++!!!, to download files from the NET, you can call the functions exported by libCURL!!!! You don't have to call the command line tool "cURL"!!!!!!!! YEAH!! i think the same has to be possible with Tor!!!!!!!!!!!!!!!!!!!!!


Child Tickets

Change History (11)

comment:1 Changed 10 years ago by cypherpunks

Bee, while your shared library idea is excellent, you seem to be a bit of a novice. Kindly investigate position-independent code (PIC) and its impacts on daily life.

Last edited 2 years ago by cypherpunks (previous) (diff)

comment:2 Changed 10 years ago by bee

Hi cypherpunks!!!!!!!!!

YEAH!!!!!!!!!! You're very right!!!!!! I'm sure my idea about the shared library is a good idea!! you're right about it and you're right even about this thing, that i ain't very expert about libraries!!!!!!!!!!!!
I did found something about position-independent code on Wikipedia and the man pages!!!!
I think that i've also to add the -fPIC switch to the command line of GCC!!!! To generate position-independent code and make the code of the library portable at run-time!!!!!!!! but i ain't sure if it is what you wanted to tell me!!!!!! Or perhaps it's something about global variables?!!! I don't have yet understand if all processes loading a shared-object share the same variables or if they have private globals!!!!

Kindly!!! tell me what there is to know about position-independent codes!!!!!!!
Well, a super thank you!!!!!!!!!!! twice!!!!!!! for your message!!!!! and for appreciating my idea!!!!!!!!!!!!!!!!!!!!!!!!


comment:3 Changed 10 years ago by ioerror

Resolution: not a bug
Status: newclosed

We've long discussed possibly creating a shared library. You're not the first and you won't be the last to suggest it - You're simply the most annoying, we all wish you'd knock it off but that's probably a lost cause.

However, it's worth answering you because while you will probably never cease to be annoying, someone else may discover this bug report and it will hopefully help them.

It's not clear what you'd gain and it's quite clear that it has major downsides. There are a lot of problems (network load being a great example) that would result from running different instances of Tor in every application.

Consider using 'torsocks' for applications where you want to use Tor as a library; it will handle all of the rough edges for you and it uses SOCKS to talk to Tor. You can have multiple configurations, one per application or other weird configs. As a bonus, it's a linkable library. This is how we handle ttdnsd and Tor (though that's with tsocks) interactions.

comment:4 Changed 10 years ago by bee

Resolution: not a bug
Status: closedreopened

I didn't said anything against you!!!!!! I neither know who you are!!!!!!!!!!!!!!!!!!! But i know you're for sure an error being!!!!!!!!!! YEAH!!!!!!!!! and this is very true!!!!!!!!!!!
enough said!!!, a shared library is surely useful!!! And it's going to preserve the backward compatibility with all the existing software!! also giving the chance to create new applications with a better integration with TOR!!!! Like the ability to start safer hidden services without opening local ports!!!!!!!!!!!!!!! Or even creating a Tor-Bundle made of the GUI or CLI interface, glibc, libtor, QT and all the others required libraries pushed into a single statically linked and very portable executable!!!!!!!!! i think it's going to be a very big file!!!!!!!!or it could be possible to compress it with UPX!!!!!!
Well, people unwilling to run different tor instances in applications made to run that way!!!!!! will still able to fire up the command line tool with the sockets interface!!! and use firefox or apache for server!!!! just alike they're doing now!!!!!! The network load thing is a lie!!!!!! Just start any downloader tool and you'll load the network even right now!!! Having the same application made with a shared library won't change anything!!!!!!!!!!! Download a linux dvd iso and you're going to overload the network without needing a p2p application neither!!!!!!!!!!!!!!!!
It's true that different applications will establish autonomous connections to the network!!!!!! This improves the stability of every single service!! and has the only consequence to gum up the statistics of tor usage!!!!!!! which i cannot actually call "a very bad thing"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Nobody is ever going to stop you, if you prefer to use "torsocks"!!!!!! what you said doesn't prove having a library to be useless or wrong!!!!!!!
I guess that you don't want to have a shared library!! because you fear to have a shared library!!!!!!!! yeah!!! and this is because you don't want the others to create software that you (wrongly!!!!!!!) believe could compromise the TOR project!!!!! as to have P2P applications exclusively based on its network!!!!!!!!! which i'm sure!!!, is something that sooner or later will happen in any way!!!!!!!!!!!


comment:5 Changed 10 years ago by ioerror

Resolution: not a bug
Status: reopenedclosed

Nice story, bro

comment:6 Changed 10 years ago by bee

Resolution: not a bug
Status: closedreopened

YEAH!!!!!!!!!!!!! suddenly everything makes sense!!!!!!! useless and unhelpful posts!!!!! even from before i was almost sure about this!!!! you're mike perry!!!!!!!!!!!!!!!!a sure "input/output error!!!!", methinks it's a very appropriate alias for you!!!!!!!!!!!!


comment:7 Changed 10 years ago by karsten

Resolution: user disappeared
Status: reopenedclosed

comment:8 Changed 10 years ago by bee


Where's the user gone?!!!!!!!! and who's him?!!!!!!!! mikeperry maybe!!!!!!!!


comment:9 Changed 10 years ago by bee

Resolution: user disappeared
Status: closedreopened

Better to reopen!!!!! also, i'm very sure mikeperry/ioerror hasn't disappeared!!!!!!!!!!!


comment:10 Changed 9 years ago by nickm

Resolution: wontfix
Status: reopenedclosed

comment:11 Changed 8 years ago by nickm

Component: Tor ClientTor
Note: See TracTickets for help on using tickets.