00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file NetViewer.h 00013 ** \version $Id: NetViewer.h 4054 2009-08-17 02:25:08Z edmanm $ 00014 ** \brief Displays a map of the Tor network and the user's circuits 00015 */ 00016 00017 #ifndef _NETVIEWER_H 00018 #define _NETVIEWER_H 00019 00020 #include "config.h" 00021 #include "ui_NetViewer.h" 00022 #include "VidaliaWindow.h" 00023 #include "GeoIpResolver.h" 00024 00025 #if defined(USE_MARBLE) 00026 #include "TorMapWidget.h" 00027 #else 00028 #include "TorMapImageView.h" 00029 #endif 00030 00031 #include "TorControl.h" 00032 00033 #include <QMainWindow> 00034 #include <QStringList> 00035 #include <QEvent> 00036 #include <QTimer> 00037 #include <QHash> 00038 00039 class QDateTime; 00040 00041 00042 class NetViewer : public VidaliaWindow 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 /** Default constructor */ 00048 NetViewer(QWidget* parent = 0); 00049 00050 public slots: 00051 /** Displays the network map window. */ 00052 void showWindow(); 00053 /** Loads a list of current circuits and streams. */ 00054 void loadConnections(); 00055 /** Adds <b>circuit</b> to the list and the map */ 00056 void addCircuit(const Circuit &circuit); 00057 /** Adds <b>stream</b> to the list of circuits, under the appropriate 00058 * circuit. */ 00059 void addStream(const Stream &stream); 00060 00061 /** Called when a NEWDESC event arrives. Retrieves new router descriptors 00062 * for the router identities given in <b>ids</b> and updates the router list 00063 * and network map. 00064 */ 00065 void newDescriptors(const QStringList &ids); 00066 00067 /** Called when Tor has mapped the address <b>from</b> to the address 00068 * <b>to</b>. <b>expires</b> indicates the time at which when the address 00069 * mapping will no longer be considered valid. 00070 */ 00071 void addressMapped(const QString &from, const QString &to, 00072 const QDateTime &expires); 00073 00074 /** Clears all known information */ 00075 void clear(); 00076 00077 protected: 00078 /** Called when the user changes the UI translation. */ 00079 void retranslateUi(); 00080 00081 private slots: 00082 /** Called when the user selects the "Help" action on the toolbar. */ 00083 void help(); 00084 /** Called when the user selects the "Refresh" action on the toolbar */ 00085 void refresh(); 00086 /** Called when the user selects a circuit on the circuit list */ 00087 void circuitSelected(const Circuit &circuit); 00088 /** Called when an IP has been resolved to geographic information. */ 00089 void resolved(int id, const QList<GeoIp> &geoips); 00090 /** Called when the user selects one or more routers in the list. */ 00091 void routerSelected(const QList<RouterDescriptor> &routers); 00092 /** Handles when we get connected to Tor network */ 00093 void onAuthenticated(); 00094 /** Handles when we get disconnected from Tor network */ 00095 void onDisconnected(); 00096 /** Resolves IP addresses in the resolve queue to geographic information. */ 00097 void resolve(); 00098 /** Called when the user selects a router on the network map. Displays a 00099 * dialog with detailed information for the router specified by 00100 * <b>id</b>.*/ 00101 void displayRouterInfo(const QString &id); 00102 /** Called when the user clicks the "Zoom In" button. */ 00103 void zoomIn(); 00104 /** Called when the user clicks the "Zoom Out" button. */ 00105 void zoomOut(); 00106 /** Called when the user clicks "Full Screen" or presses Escape on the map. 00107 * Toggles the map between normal and a full screen viewing modes. */ 00108 void toggleFullScreen(); 00109 00110 private: 00111 /** Adds an IP address to the resolve queue and updates the queue timers. */ 00112 void addToResolveQueue(const QHostAddress &ip, const QString &id); 00113 /** Retrieves a list of all running routers from Tor and their descriptors, 00114 * and adds them to the RouterListWidget. */ 00115 void loadNetworkStatus(); 00116 /** Loads a list of address mappings from Tor. */ 00117 void loadAddressMap(); 00118 /** Adds a router to our list of servers and retrieves geographic location 00119 * information for the server. */ 00120 void addRouter(const RouterDescriptor &rd); 00121 00122 /** TorControl object used to talk to Tor. */ 00123 TorControl* _torControl; 00124 /** Timer that fires once an hour to update the router list. */ 00125 QTimer _refreshTimer; 00126 /** GeoIpResolver used to geolocate routers by IP address. */ 00127 GeoIpResolver _geoip; 00128 /** Queue for IPs pending resolution to geographic information. */ 00129 QList<QHostAddress> _resolveQueue; 00130 /** Maps pending GeoIP requests to server IDs. */ 00131 QHash<QString, QString> _resolveMap; 00132 /** Stores a list of address mappings from Tor. */ 00133 AddressMap _addressMap; 00134 /** Timer used to delay GeoIP requests for MIN_RESOLVE_QUEUE_DELAY 00135 * milliseconds after we've inserted the last item into the queue. */ 00136 QTimer _minResolveQueueTimer; 00137 /** Timer used to limit the delay of GeoIP requests to 00138 * MAX_RESOLVE_QUEUE_DELAY milliseconds after inserting the first item 00139 * into the queue. */ 00140 QTimer _maxResolveQueueTimer; 00141 00142 /** Widget that displays the Tor network map. */ 00143 #if defined(USE_MARBLE) 00144 TorMapWidget* _map; 00145 #else 00146 TorMapImageView* _map; 00147 #endif 00148 00149 /** Qt Designer generated object **/ 00150 Ui::NetViewer ui; 00151 }; 00152 00153 #endif 00154