[vidalia/alpha] Load routers asynchronously

commit 693a7754c5010f756140f805e22a0168b52be630 Author: Tomás Touceda <chiiph@torproject.org> Date: Mon Feb 13 12:54:20 2012 -0300 Load routers asynchronously --- src/vidalia/network/NetViewer.cpp | 53 ++++++++++++++++++++++++++++--------- src/vidalia/network/NetViewer.h | 25 ++++++++++++----- 2 files changed, 58 insertions(+), 20 deletions(-) diff --git a/src/vidalia/network/NetViewer.cpp b/src/vidalia/network/NetViewer.cpp index 0e0a161..0a88ec5 100644 --- a/src/vidalia/network/NetViewer.cpp +++ b/src/vidalia/network/NetViewer.cpp @@ -224,12 +224,8 @@ NetViewer::refresh() /* Clear the data */ clear(); - /* Load router information */ - loadNetworkStatus(); - /* Load existing address mappings */ - loadAddressMap(); - /* Load Circuits and Streams information */ - loadConnections(); + /* Async router load */ + preLoadNetworkStatus(); /* Ok, they can refresh again. */ ui.actionRefresh->setEnabled(true); @@ -331,21 +327,52 @@ NetViewer::help() } /** Retrieves a list of all running routers from Tor and their descriptors, - * and adds them to the RouterListWidget. */ + * and adds them to the _router list. */ void -NetViewer::loadNetworkStatus() +NetViewer::preLoadNetworkStatus() { NetworkStatus networkStatus = _torControl->getNetworkStatus(); - foreach (RouterStatus rs, networkStatus) { + + if(_torControl->useMicrodescriptors()) + ui.treeRouterList->hideColumn(RouterListWidget::StatusColumn); + + foreach(RouterStatus rs, networkStatus) { if (!rs.isRunning()) continue; - + RouterDescriptor rd = _torControl->getRouterDescriptor(rs.id()); + if(_torControl->useMicrodescriptors()) { + rd.appendRouterStatusInfo(rs); + } if (!rd.isEmpty()) - addRouter(rd); + _routers << rd; QCoreApplication::processEvents(); } + + _it = _routers.constBegin(); + QTimer::singleShot(200, this, SLOT(loadNetworkStatus())); +} + +/** Adds routers to the RouterListWidget after they have been loaded + * in the internal _router list */ +void +NetViewer::loadNetworkStatus() +{ + int count = 0, thres = 10; + for(; _it != _routers.constEnd() and count < thres; ++_it, ++count) { + addRouter((*_it)); + QCoreApplication::processEvents(); + } + + if(_it != _routers.constEnd()) + QTimer::singleShot(10, this, SLOT(loadNetworkStatus())); + else { + /* Load existing address mappings */ + loadAddressMap(); + /* Load Circuits and Streams information */ + loadConnections(); + } } /** Adds a router to our list of servers and retrieves geographic location @@ -420,8 +447,8 @@ NetViewer::routerSelected(const QList<RouterDescriptor> &routers) * map. But our current map sucks and you can't even tell when one is * selected anyway. Worry about this when we actually get to Marble. */ - if (routers.size() == 1) - _map->selectRouter(routers[0].id()); + // if (routers.size() == 1) + // _map->selectRouter(routers[0].id()); } /** Called when the user selects a router on the network map. Displays a diff --git a/src/vidalia/network/NetViewer.h b/src/vidalia/network/NetViewer.h index b1c40be..0293306 100644 --- a/src/vidalia/network/NetViewer.h +++ b/src/vidalia/network/NetViewer.h @@ -73,6 +73,10 @@ public slots: /** Clears all known information */ void clear(); + /** Adds a router to our list of servers and retrieves geographic location + * information for the server. */ + void addRouter(const RouterDescriptor &rd); + protected: /** Called when the user changes the UI translation. */ void retranslateUi(); @@ -105,17 +109,18 @@ private slots: * returnPressed from the search field. */ void onRouterSearch(); + /** Adds routers to the RouterListWidget after they have been loaded + * in the internal _router list */ + void loadNetworkStatus(); + private: /** */ void setupGeoIpResolver(); - /** Retrieves a list of all running routers from Tor and their descriptors, - * and adds them to the RouterListWidget. */ - void loadNetworkStatus(); /** Loads a list of address mappings from Tor. */ void loadAddressMap(); - /** Adds a router to our list of servers and retrieves geographic location - * information for the server. */ - void addRouter(const RouterDescriptor &rd); + /** Retrieves a list of all running routers from Tor and their descriptors, + * and adds them to the _routers list. */ + void preLoadNetworkStatus(); /** TorControl object used to talk to Tor. */ TorControl* _torControl; @@ -125,7 +130,13 @@ private: GeoIpResolver _geoip; /** Stores a list of address mappings from Tor. */ AddressMap _addressMap; - + + /** RouterDescriptor list that is used to load the routers in an + * asyc way */ + QList<RouterDescriptor> _routers; + /** Iterator to keep the loaded routers at any time */ + QList<RouterDescriptor>::const_iterator _it; + /** Widget that displays the Tor network map. */ #if defined(USE_MARBLE) TorMapWidget* _map;
participants (1)
-
chiiph@torproject.org