Tor源碼分析二 -- 目錄結構

  Tor由於經過了長年的開發,版本到現在已經有很多。筆者選用的是tor-0.2.3.25版本。關於版本變遷和更新說明,請大家自行查看:

  https://gitweb.torproject.org/tor.git (需翻牆)


1. 源碼目錄關係圖

  Tor的源碼目錄中包括doc, contrib, src等一些列很莫名的文件。其實,在這些所有的文件中,除了src文件夾,其他都可以在初期暫時不去理會。所以,這裏我們就談src文件夾下的目錄結構,也是Tor源碼核心的目錄結構。

  上面兩圖已經基本給出了各個子目錄之間的關係和引用次數。總的來說,src目錄下包括下列這樣的目錄:

  1)win32:用於Windows的目錄,內部只含有一個orconfig.h文件。主要用於Tor源碼的跨平臺編譯。

  2)common:Tor源碼中基本通用函數的封裝目錄。包括:OpenSSL,Libevent的封裝,TLS的封裝,鏈表和哈希表的實現等。

  3)tools:Tor使用工具目錄。包括:密鑰驗證,證書生成,域名解析和防火牆輔助的實現。

  4)or:Tor核心程序邏輯目錄。(Tor系統所有核心協議的實現目錄)包括:客戶端身份核心代碼,路由身份核心代碼,目錄服務器身份核心代碼等。

  5)test:Tor源碼各功能模塊的測試代碼目錄。

  6)config:配置文件模板目錄


2. or目錄下的各文件

  or目錄是Tor源代碼的核心,有必要簡要介紹下該目錄下的文件的主要作用:(細節部分後期會逐個文件分別進行分析)


以下部分同時用於OP與OR:(Onion Proxy, Onion Router)

  1)Buffers:緩衝區相關結構體及處理函數;

    a generic interface buffer. Buffers are fairly opaque string holders that can read to or flush from: memory, file descriptors, or TLS connections.

  2)Circuitbuild:鏈路建立相關函數;

    The actual details of building circuits.

  3)Circuitlist:鏈路列表及鏈路控制相關函數;

    Manage the global circuit list.

  4)Circuituse:鏈路獲取或使用相關函數;

    Launch the right sort of circuits and attach streams to them.

  5)Command:Tor Cell數據包的所有命令處理函數;

    Functions for processing incoming cells.

  6)Config:Tor系統配置選項處理函數;

    Code to parse and interpret configuration files.

  7)Connection:通用連接相關函數;

    General high-level functions to handle reading and writing on connections.

  8)Connection_edge:邊緣連接相關函數;(邊緣連接包括應用代理連接AP和出口連接EXIT)

    Handle edge streams.

  9)Connection_or:OR連接相關函數;

    Functions to handle OR connections, TLS handshaking, and cells on the network.

  10)Control:Tor系統控制相關函數;

    Implementation for Tor's control-socket interface. See doc/spec/control-spec.txt for full details on protocol.

  11)Cpuworker:多線程(加解密)處理函數;

    Implements a farm of 'CPU worker' processes to perform CPU-intensive tasks in another thread or process, to not interrupt the main thread.

  12)Directory:目錄服務器連接相關操作函數;

    Code to send and fetch directories and router descriptors via HTTP. Directories usedirserv.c to generate the results; clients use routers.c to parse them.

  13)Geoip:Geoip功能相關函數;(一般用於Bridge用戶來自的國家統計)

    Functions related to maintaining an IP-to-country database; to summarizing client connections by country to entry guards, bridges, and directory servers; and for statistics on answering network status requests.

  14)Hibernate:休眠相關處理函數;

    Functions to close listeners, stop allowing new circuits, etc in preparation for closing down or going dormant; and to track bandwidth and time intervals to know when to hibernate and when to stop hibernating.

  15)Main:主程序

    Toplevel module. Handles signals, multiplexes between connections, implements main loop, and drives scheduled events.

  16)Microdesc:微描述符處理相關函數;

  17)Networkstatus:網絡狀態文檔處理函數;

    Functions and structures for handling network status documents as a client or cache.

  18)Nodelist:路由節點列表相關處理函數;

  19)Ntmain:nt服務相關函數;

  20)Onion:Cell封裝處理相關函數;

    Functions to queue create cells, and handle onionskin parsing and creation.

  21)Policies:出入口策略相關函數;

    Code to parse and use address policies and exit policies.

  22)Reason:差錯原因相關函數;

    Convert circuit, stream, and orconn error reasons to and/or from strings and errno values.

  23)Relay:Relay Cell相關處理函數;

    Handle relay cell encryption/decryption, plus packaging and receiving from circuits, plus queuing on circuits.

  24)Rendcommon:Hidden Service通用代碼;

    Rendezvous implementation: shared code between introducers, services, clients, and rendezvous points.

  25)Routerlist:路由信息列表相關處理函數;

    Code to maintain and access the global list of routerinfos for known servers.

  26)Routerparse:路由描述符與目錄的解析與驗證相關函數;

    Code to parse and validate router descriptors and directories.

  27)Status:狀態保存與秒記錄函數;

    Keep status information and log the heartbeat messages.

  28)Tormain:主函數接口;

    Stub module containing a main() function. Allows unit test binary to link againstmain.c.

  29)Transports:Pluggable Transports related code.

  30)Rephist:歷史信息與數據統計相關函數;

    Basic history and "reputation" functionality to remember which servers have worked in the past, how much bandwidth we've been using, which ports we tend to want, and so on; further, exit port statistics, cell statistics, and connection statistics.


以下部分用於OR:(Onion Router)

  1)Dirsev:目錄服務器核心實現,生成及管理目錄內容;

    Directory server core implementation. Manages directory contents and generates directories.

  2)Dirvote:目錄服務器投票與共識相關操作函數;

    Functions to compute directory consensus, and schedule voting.

  3)Dns:服務器域名解析服務相關函數;

    Implements a local cache for DNS results for Tor servers. This is implemented as a wrapper around Adam Langley'seventdns.c code. (We can't just use gethostbyname() and friends because we really need to be nonblocking.)

  4)Rendmid:Hidden Service中間服務點實現代碼;

    Implement introductions points and rendezvous points.

  5)Rendservice:Hidden Service服務功能代碼;

    The hidden-service side of rendezvous functionality.

  6)Router:Onion Router核心實現;

    OR functionality, including key maintenance, generating and uploading server descriptors, retrying OR connections.


以下部分用於OP:(Onion Proxy)

  1)Dnsserv:客戶端域名解析代理服務器相關函數;

    Implements client-side DNS proxy server code. Note: this is the DNS Server code, not the Server DNS code. Confused? This code runs on client-side, and acts as a DNS server. The code indns.c, on the other hand, runs on Tor servers, and acts as a DNS client.

  2)Eventdns:暫略

  3)Rendclient:Hidden Service客戶端代碼;

    Client code to access location-hidden services.


  筆者暫時沒有全部查閱上述代碼,如果有差錯的地方,請大家指點。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章