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 2511 2008-04-12 22:02:27Z 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 <QMainWindow> 00021 #include <QStringList> 00022 #include <QEvent> 00023 #include <QTimer> 00024 #include <QHash> 00025 #include <torcontrol.h> 00026 #include <vidaliawindow.h> 00027 00028 #include "geoipresolver.h" 00029 #include "tormapwidget.h" 00030 #include "ui_netviewer.h" 00031 00032 00033 class NetViewer : public VidaliaWindow 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 /** Default constructor */ 00039 NetViewer(QWidget* parent = 0); 00040 00041 public slots: 00042 /** Displays the network map window. */ 00043 void showWindow(); 00044 /** Loads a list of current circuits and streams. */ 00045 void loadConnections(); 00046 /** Adds <b>circuit</b> to the list and the map */ 00047 void addCircuit(const Circuit &circuit); 00048 /** Adds <b>stream</b> to the list of circuits, under the appropriate 00049 * circuit. */ 00050 void addStream(const Stream &stream); 00051 /** Clears all known information */ 00052 void clear(); 00053 00054 protected: 00055 /** Called to deliver a NEWDESC event from Tor. */ 00056 void customEvent(QEvent *event); 00057 00058 private slots: 00059 /** Called when the user selects the "Help" action on the toolbar. */ 00060 void help(); 00061 /** Called when the user selects the "Refresh" action on the toolbar */ 00062 void refresh(); 00063 /** Called when the user selects a circuit on the circuit list */ 00064 void circuitSelected(Circuit circuit); 00065 /** Called when an IP has been resolved to geographic information. */ 00066 void resolved(int id, QList<GeoIp> geoips); 00067 /** Called when the user selects a router in the list. */ 00068 void routerSelected(RouterDescriptor router); 00069 /** Handles when we get connected to Tor network */ 00070 void onAuthenticated(); 00071 /** Handles when we get disconnected from Tor network */ 00072 void onDisconnected(); 00073 /** Resolves IP addresses in the resolve queue to geographic information. */ 00074 void resolve(); 00075 00076 private: 00077 /** Adds an IP address to the resolve queue and updates the queue timers. */ 00078 void addToResolveQueue(QHostAddress ip, QString id); 00079 /** Retrieves a list of all running routers from Tor and their descriptors, 00080 * and adds them to the RouterListWidget. */ 00081 void loadNetworkStatus(); 00082 /** Loads a list of address mappings from Tor. */ 00083 void loadAddressMap(); 00084 /** Adds a router to our list of servers and retrieves geographic location 00085 * information for the server. */ 00086 void addRouter(const RouterDescriptor &rd); 00087 /** Called when a NEWDESC event arrives. Retrieves new router descriptors 00088 * for the router identities given in <b>ids</b> and updates the router list 00089 * and network map. */ 00090 void newDescriptors(const QStringList &ids); 00091 00092 /** TorControl object used to talk to Tor. */ 00093 TorControl* _torControl; 00094 /** Timer that fires once an hour to update the router list. */ 00095 QTimer _refreshTimer; 00096 /** TorMapWidget that displays the map. */ 00097 TorMapWidget* _map; 00098 /** GeoIpResolver used to geolocate routers by IP address. */ 00099 GeoIpResolver _geoip; 00100 /** Queue for IPs pending resolution to geographic information. */ 00101 QList<QHostAddress> _resolveQueue; 00102 /** Maps pending GeoIP requests to server IDs. */ 00103 QHash<QString, QString> _resolveMap; 00104 /** Stores a list of address mappings from Tor. */ 00105 AddressMap _addressMap; 00106 /** Timer used to delay GeoIP requests for MIN_RESOLVE_QUEUE_DELAY 00107 * milliseconds after we've inserted the last item into the queue. */ 00108 QTimer _minResolveQueueTimer; 00109 /** Timer used to limit the delay of GeoIP requests to 00110 * MAX_RESOLVE_QUEUE_DELAY milliseconds after inserting the first item 00111 * into the queue. */ 00112 QTimer _maxResolveQueueTimer; 00113 00114 /** Qt Designer generated object **/ 00115 Ui::NetViewer ui; 00116 }; 00117 00118 #endif 00119