00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file netviewer.h 00024 * \version $Id: netviewer.h 1845 2007-08-21 04:34:06Z edmanm $ 00025 * \brief Displays a map of the Tor network and the user's circuits 00026 */ 00027 00028 #ifndef _NETVIEWER_H 00029 #define _NETVIEWER_H 00030 00031 #include <QMainWindow> 00032 #include <QStringList> 00033 #include <QEvent> 00034 #include <QTimer> 00035 #include <QHash> 00036 #include <control/torcontrol.h> 00037 #include <util/geoip/geoipresolver.h> 00038 #include <gui/common/vidaliawindow.h> 00039 00040 #include "tormapwidget.h" 00041 #include "ui_netviewer.h" 00042 00043 00044 class NetViewer : public VidaliaWindow 00045 { 00046 Q_OBJECT 00047 00048 public: 00049 /** Default constructor */ 00050 NetViewer(QWidget* parent = 0); 00051 00052 public slots: 00053 /** Displays the network map window. */ 00054 void showWindow(); 00055 /** Loads a list of current circuits and streams. */ 00056 void loadConnections(); 00057 /** Adds <b>circuit</b> to the list and the map */ 00058 void addCircuit(Circuit circuit); 00059 /** Adds <b>stream</b> to the list of circuits, under the appropriate 00060 * circuit. */ 00061 void addStream(Stream stream); 00062 /** Clears all known information */ 00063 void clear(); 00064 00065 protected: 00066 /** Called to deliver a NEWDESC event from Tor. */ 00067 void customEvent(QEvent *event); 00068 00069 private slots: 00070 /** Called when the user selects the "Help" action on the toolbar. */ 00071 void help(); 00072 /** Called when the user selects the "Refresh" action on the toolbar */ 00073 void refresh(); 00074 /** Called when the user selects a circuit on the circuit list */ 00075 void circuitSelected(Circuit circuit); 00076 /** Called when an IP has been resolved to geographic information. */ 00077 void resolved(int id, QList<GeoIp> geoips); 00078 /** Called when the user selects a router in the list. */ 00079 void routerSelected(RouterDescriptor router); 00080 /** Handles when we get connected to Tor network */ 00081 void onAuthenticated(); 00082 /** Handles when we get disconnected from Tor network */ 00083 void onDisconnected(); 00084 /** Resolves IP addresses in the resolve queue to geographic information. */ 00085 void resolve(); 00086 00087 private: 00088 /** Adds an IP address to the resolve queue and updates the queue timers. */ 00089 void addToResolveQueue(QHostAddress ip, QString id); 00090 /** Loads a list of router descriptors from the list of IDs. */ 00091 void loadDescriptors(QStringList ids); 00092 /** Loads a list of address mappings from Tor. */ 00093 void loadAddressMap(); 00094 /** Adds a router to our list of servers and retrieves geographic location 00095 * information for the server. */ 00096 void addRouter(RouterDescriptor rd); 00097 /** Convert all hops in <b>circ</b>'s path to server identities. 00098 * <b>circ</b>'s status and circuit ID will be preserved. */ 00099 Circuit circuitPathIDs(Circuit circ); 00100 /** Convert all hops in <b>circ</b>'s path to server names. <b>circ</b>'s 00101 * status and circuit ID will be preserved. */ 00102 Circuit circuitPathNames(Circuit circ); 00103 00104 /** TorControl object used to talk to Tor. */ 00105 TorControl* _torControl; 00106 /** Timer that fires once an hour to update the router list. */ 00107 QTimer _refreshTimer; 00108 /** TorMapWidget that displays the map. */ 00109 TorMapWidget* _map; 00110 /** GeoIpResolver used to geolocate routers by IP address. */ 00111 GeoIpResolver _geoip; 00112 /** Queue for IPs pending resolution to geographic information. */ 00113 QList<QHostAddress> _resolveQueue; 00114 /** Maps pending GeoIP requests to server IDs. */ 00115 QHash<QString, QString> _resolveMap; 00116 /** Stores a list of address mappings from Tor. */ 00117 AddressMap _addressMap; 00118 /** Timer used to delay GeoIP requests for MIN_RESOLVE_QUEUE_DELAY 00119 * milliseconds after we've inserted the last item into the queue. */ 00120 QTimer _minResolveQueueTimer; 00121 /** Timer used to limit the delay of GeoIP requests to 00122 * MAX_RESOLVE_QUEUE_DELAY milliseconds after inserting the first item 00123 * into the queue. */ 00124 QTimer _maxResolveQueueTimer; 00125 00126 /** Qt Designer generated object **/ 00127 Ui::NetViewer ui; 00128 }; 00129 00130 #endif 00131