Commit caeea278 authored by Tomas Touceda's avatar Tomas Touceda
Browse files

Remove Find bridges button and the rest of the functionality

parent 1c9c8a94
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
0.2.18  13-May-2012
0.2.18  14-May-2012
  o Use consensus bandwidth for routers when microdescriptors is
    enabled. Fixes bug 3287.
  o Notify users that a warning status event has appeared by flashing
@@ -12,8 +12,6 @@
    that string if needed.) Fixes bug 5109.
  o Displays Korean, Catalan and Greek in their native scripts. Fix
    bug 5110.
  o Fix the bridge line parsing for requests to bridges.torproject.org
    when the user clicks 'find bridges now'. Fixes bug 5730.
  o Support adding comments in the same line as a config option inside
    the torrc dialog. Fixes bug 5475.
  o Remove Polipo and Torbutton from Vidalia's build scripts. Resolves
@@ -24,6 +22,8 @@
    the Vidalia binary location as the starting point for relative
    paths.
  o Enable Burmese, Croatian, Basque and Serbian translation.
  o Remove the "Find bridges" button in order to avoid compromising
    users that need to hide behind tor at all times. Fixes bug 5371.

0.2.17  11-Feb-2012
  o Improve the translation policy: do not remove translations that
+0 −5
Original line number Diff line number Diff line
@@ -86,8 +86,6 @@ set(vidalia_SRCS ${vidalia_SRCS}
  config/AbstractTorSettings.cpp
  config/AdvancedPage.cpp
  config/AppearancePage.cpp
  config/BridgeDownloader.cpp
  config/BridgeDownloaderProgressDialog.cpp
  config/BridgeUsageDialog.cpp
  config/ConfigDialog.cpp
  config/ConfigPageStack.cpp
@@ -116,8 +114,6 @@ qt4_wrap_cpp(vidalia_SRCS
  config/AbstractTorSettings.h
  config/AdvancedPage.h
  config/AppearancePage.h
  config/BridgeDownloader.h
  config/BridgeDownloaderProgressDialog.h
  config/BridgeUsageDialog.h
  config/ConfigDialog.h
  config/ConfigPage.h
@@ -271,7 +267,6 @@ qt4_wrap_ui(vidalia_SRCS
  bwgraph/BandwidthGraph.ui
  config/AdvancedPage.ui
  config/AppearancePage.ui
  config/BridgeDownloaderProgressDialog.ui
  config/BridgeUsageDialog.ui
  config/ConfigDialog.ui
  config/GeneralPage.ui
+0 −149
Original line number Diff line number Diff line
/*
**  This file is part of Vidalia, and is subject to the license terms in the
**  LICENSE file, found in the top level directory of this distribution. If you
**  did not receive the LICENSE file with this file, you may obtain it from the
**  Vidalia source package distributed by the Vidalia Project at
**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
**  including this file, may be copied, modified, propagated, or distributed
**  except according to the terms described in the LICENSE file.
*/

/*
** \file BridgeDownloader.cpp
** \brief Downloads a list of new bridge addresses via HTTPS
*/

#include "BridgeDownloader.h"
#include "Vidalia.h"

#define BRIDGEDB_HOST  "bridges.torproject.org"
#define BRIDGEDB_PORT  443

BridgeDownloader::BridgeDownloader(QObject *parent)
  : QObject(parent)
{
  _https = new QNetworkAccessManager();

  connect(_https, SIGNAL(finished(QNetworkReply *)),
          this, SLOT(httpsRequestFinished(QNetworkReply *)));
  connect(_https, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
          this, SLOT(sslErrors(QNetworkReply *, QList<QSslError>)));
}

void
BridgeDownloader::setProxy(const QString &host, int port,
                           const QString &username, const QString &password)
{
  _https->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, host, port, username, password));
}

bool
BridgeDownloader::downloadBridges(BridgeDownloadMethod method)
{
  if (! isMethodSupported(method))
    return false;

  switch (method) {
    case DownloadMethodHttps:
      startHttpsDownload();
      break;

    default:
      break;
  }
  return true;
}

bool
BridgeDownloader::isMethodSupported(BridgeDownloadMethod method)
{
  switch (method) {
    case DownloadMethodHttps:
      return QSslSocket::supportsSsl();

    default:
      break;
  }
  return false;
}

void
BridgeDownloader::startHttpsDownload()
{
  emit statusChanged(tr("Starting HTTPS bridge request..."));
  emit downloadProgress(0, 0);

  _reply = _https->get(QNetworkRequest(QUrl("https://bridges.torproject.org/?format=plain")));
  connect(_reply, SIGNAL(downloadProgress(qint64, qint64)),
          this, SIGNAL(downloadProgress(qint64, qint64)));
  vInfo("Sending an HTTPS bridge request to %1:%2.").arg(BRIDGEDB_HOST)
                                                    .arg(BRIDGEDB_PORT);
}

void
BridgeDownloader::cancelBridgeRequest()
{
  _reply->close();
  disconnect(_reply, 0, 0, 0);
}

void
BridgeDownloader::httpsStateChanged(int state)
{
  switch (state) {
    case QHttp::Connecting:
      emit statusChanged(tr("Connecting to %1:%2...").arg(BRIDGEDB_HOST)
                                                     .arg(BRIDGEDB_PORT));
      break;

    case QHttp::Sending:
      emit statusChanged(tr("Sending an HTTPS request for bridges..."));
      break;

    case QHttp::Reading:
      emit statusChanged(tr("Downloading a list of bridges..."));
      break;

    default:
      break;
  }
}

void
BridgeDownloader::httpsRequestFinished(QNetworkReply *reply)
{
  if (reply->error() != QNetworkReply::NoError) {
    QString errorString = reply->errorString();
    vWarn("Bridge request failed: %2").arg(errorString);

    emit bridgeRequestFailed(errorString);
  } else {
    QByteArray response = reply->readAll();
    vInfo("Bridge request complete: received %2 bytes.").arg(response.size());

    QStringList bridges, lines = QString(response).split("\n");
    foreach (QString line, lines) {
      line = line.trimmed();
      if (line.startsWith("bridge ", Qt::CaseInsensitive))
        bridges << line;
    }
    emit bridgeRequestFinished(bridges);
  }
  _reply->close();
  disconnect(_reply,0,0,0);
}

void
BridgeDownloader::sslErrors(QNetworkReply *reply, const QList<QSslError> &sslErrors)
{
  QString errorString;
  QStringList errorStrings;

  vWarn("%1 SSL error(s) when requesting bridge information:")
                                                      .arg(sslErrors.size());
  foreach (QSslError sslError, sslErrors) {
    errorString = sslError.errorString();
    errorStrings << errorString;
    vWarn("  SSL Error: %1").arg(errorString);
  }
}
+0 −122
Original line number Diff line number Diff line
/*
**  This file is part of Vidalia, and is subject to the license terms in the
**  LICENSE file, found in the top level directory of this distribution. If you
**  did not receive the LICENSE file with this file, you may obtain it from the
**  Vidalia source package distributed by the Vidalia Project at
**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
**  including this file, may be copied, modified, propagated, or distributed
**  except according to the terms described in the LICENSE file.
*/

/*
** \file BridgeDownloader.h
** \brief Downloads a list of new bridge addresses via HTTPS
*/

#ifndef _BRIDGEDOWNLOADER_H
#define _BRIDGEDOWNLOADER_H

#include <QtNetwork>

class BridgeDownloader : public QObject
{
  Q_OBJECT

public:
  /** Available bridge download methods. */
  enum BridgeDownloadMethod {
    DownloadMethodHttps, /** Download via an HTTPS connection. */
  };

  /** Default constructor.
   */
  BridgeDownloader(QObject *parent = 0);

  /** Initiates a request for a set of bridges using the specified
   * download <b>method</b>. Returns true if the request was initiated
   * successfully, or false on error.
   */
  bool downloadBridges(BridgeDownloadMethod method);

  /** Enables HTTPS proxy support, using the proxy server <b>host</b> on
   * port <b>port</b>. A <b>username</b> and <b>password</b> can also
   * optionally be supplied, if required by the proxy.
   */
  void setProxy(const QString &host, int port,
                const QString &username = QString(),
                const QString &password = QString());

  /** Returns true if <b>method</b> is supported by the currently
   * available Qt libraries.
   */
  static bool isMethodSupported(BridgeDownloadMethod method);

public slots:
  /** Cancels any pending bridge download requests.
   */
  void cancelBridgeRequest();

signals:
  /** Emitted when the underlying QHttp object reads data from an HTTPS
   * response. <b>done</b> indicates how many bytes out of <b>total</b>
   * have been read so far. Note that <b>total</b> may be 0 if the expected
   * total size of the response is not known.
   */
  void downloadProgress(qint64 done, qint64 total);

  /** Emitted when the status of the bridge request changes. <b>status</b>
   * describes the new current state of the request.
   */
  void statusChanged(const QString &status);

  /** Emitted when the previous request for bridge addresses completes
   * successfully. The QStringList <b>bridges</b> contains a (possibly empty)
   * list of bridge addresses parsed from the received response.
   */
  void bridgeRequestFinished(const QStringList &bridges);

  /** Emitted when the previous request for bridge addresses fails. The
   * QString <b>error</b> is a human-readable string describing the error
   * encountered.
   */
  void bridgeRequestFailed(const QString &error);

private slots:
  /** Called when the state of the underlying QHttp object changes. A
   * statusChanged() signal is emitted with the appropriate text
   * describing the new state of the request.
   */
  void httpsStateChanged(int state);

  /** Called when the underlying QHttp object used to make the bridge
   * request completes. <b>error</b> is set to false if the request was
   * successful, or true if the request failed. If <b>id</b> does not
   * match the request ID previously returned by QHttp::get(), then the
   * signal is ignored since it is the result of a close() or abort()
   * request.
   */
  void httpsRequestFinished(QNetworkReply *reply);

  /** Called when the HTTPS connection encounters one or more
   * <b>sslErrors</b>. Currently the errors are just logged and
   * bridgeRequestFailed() is <i>not</i> emitted, since QHttp will also
   * emit
   */
  void sslErrors(QNetworkReply *, const QList<QSslError> &sslErrors);

private:
  /** Initiates an HTTPS connection to bridges.torproject.org to start
   * downloading a set of bridges.
   */
  void startHttpsDownload();

  /** Used to connect to the bridge database, send an HTTPS request for
   * new bridge addresses and then read the response. */
  QNetworkAccessManager* _https;

  /** Identifier of the current bridge request */
  QNetworkReply *_reply;
};

#endif
+0 −90
Original line number Diff line number Diff line
/*
**  This file is part of Vidalia, and is subject to the license terms in the
**  LICENSE file, found in the top level directory of this distribution. If you
**  did not receive the LICENSE file with this file, you may obtain it from the
**  Vidalia source package distributed by the Vidalia Project at
**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
**  including this file, may be copied, modified, propagated, or distributed
**  except according to the terms described in the LICENSE file.
*/

/*
** \file BridgeDownloaderProgressDialog.cpp
** \brief Displays the progress of a request for bridge addresses
*/

#include "BridgeDownloaderProgressDialog.h"

#include <QTimer>


BridgeDownloaderProgressDialog::BridgeDownloaderProgressDialog(QWidget *parent)
  : QDialog(parent)
{
  ui.setupUi(this);

  connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)),
          this, SLOT(buttonClicked(QAbstractButton *)));

  setModal(true);
}

void
BridgeDownloaderProgressDialog::setVisible(bool visible)
{
  if (visible) {
    ui.progressBar->setRange(0, 0);
    ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
  }
  QDialog::setVisible(visible);
}

void
BridgeDownloaderProgressDialog::setStatus(const QString &status)
{
  ui.lblStatus->setText(status);
}

void
BridgeDownloaderProgressDialog::setDownloadProgress(qint64 done, qint64 total)
{
  ui.progressBar->setRange(0, total);
  ui.progressBar->setValue(done);
}

void
BridgeDownloaderProgressDialog::bridgeRequestFinished(const QStringList &bridges)
{
  Q_UNUSED(bridges);

  accept();
}

void
BridgeDownloaderProgressDialog::bridgeRequestFailed(const QString &error)
{
  ui.lblStatus->setText(tr("Unable to download bridges: %1").arg(error));

  ui.progressBar->setRange(0, 1);
  ui.progressBar->setValue(1);

  ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel
                                     | QDialogButtonBox::Retry
                                     | QDialogButtonBox::Help);
}

void
BridgeDownloaderProgressDialog::buttonClicked(QAbstractButton *button)
{
  int standardButton = ui.buttonBox->standardButton(button);
  if (standardButton == QDialogButtonBox::Retry) {
    setStatus(tr("Retrying bridge request..."));
    setDownloadProgress(0, 0);
    ui.buttonBox->setStandardButtons(QDialogButtonBox::Cancel);

    QTimer::singleShot(1000, this, SIGNAL(retry()));
  } else {
    done(standardButton);
  }
}
Loading