Skip to content

Commit

Permalink
support turn
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Karneges committed Jan 27, 2010
1 parent f5f21ca commit 762fa75
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 68 deletions.
2 changes: 1 addition & 1 deletion iris
Submodule iris updated from 63c903 to 9fc0b5
135 changes: 96 additions & 39 deletions src/accountmodify.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>528</width>
<height>386</height>
<width>500</width>
<height>457</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -796,7 +796,7 @@
<attribute name="title">
<string>Misc.</string>
</attribute>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="ck_automatic_resource">
<property name="text">
Expand Down Expand Up @@ -881,41 +881,95 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="lb_stunHost">
<property name="text">
<string>STUN Host:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_stunHost"/>
</item>
<item>
<widget class="QLabel" name="lb_stunPort">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_stunPort">
<property name="minimumSize">
<size>
<width>56</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>56</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>STUN/TURN</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="lb_stunHost">
<property name="text">
<string>Host:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_stunHost"/>
</item>
<item>
<widget class="QLabel" name="lb_stunPort">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_stunPort">
<property name="minimumSize">
<size>
<width>56</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>56</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Username:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_stunUser">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_stunPass">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ck_custom_auth">
Expand All @@ -938,7 +992,7 @@
<bool>false</bool>
</property>
<property name="text">
<string>User:</string>
<string>Username:</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -1052,9 +1106,12 @@
<tabstop>le_dtProxy</tabstop>
<tabstop>le_stunHost</tabstop>
<tabstop>le_stunPort</tabstop>
<tabstop>le_stunUser</tabstop>
<tabstop>le_stunPass</tabstop>
<tabstop>ck_custom_auth</tabstop>
<tabstop>le_authid</tabstop>
<tabstop>le_realm</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down
4 changes: 4 additions & 0 deletions src/accountmodifydlg.cpp
Expand Up @@ -143,6 +143,8 @@ void AccountModifyDlg::init()
le_dtProxy->setText(acc.dtProxy.full());
le_stunHost->setText(acc.stunHost);
le_stunPort->setText(QString::number(acc.stunPort));
le_stunUser->setText(acc.stunUser);
le_stunPass->setText(acc.stunPass);

key = acc.pgpSecretKey;
updateUserID();
Expand Down Expand Up @@ -523,6 +525,8 @@ void AccountModifyDlg::save()
acc.dtProxy = le_dtProxy->text();
acc.stunHost = le_stunHost->text();
acc.stunPort = le_stunPort->text().toInt();
acc.stunUser = le_stunUser->text();
acc.stunPass = le_stunPass->text();

acc.pgpSecretKey = key;

Expand Down
10 changes: 10 additions & 0 deletions src/avcall/avcall.cpp
Expand Up @@ -938,6 +938,16 @@ void AvCallManager::setStunHost(const QString &host, int port)
d->rtpManager->setStunHost(host, port);
}

void AvCallManager::setStunUserPass(const QString &user, const QString &pass)
{
d->rtpManager->setStunUserPass(user, pass);
}

void AvCallManager::setStunProxy(const XMPP::AdvancedConnector::Proxy &proxy)
{
d->rtpManager->setStunProxy(proxy);
}

void AvCallManager::setBasePort(int port)
{
if(port == 0)
Expand Down
3 changes: 3 additions & 0 deletions src/avcall/avcall.h
Expand Up @@ -20,6 +20,7 @@
#define AVCALL_H

#include <QObject>
#include "xmpp.h"

class QHostAddress;

Expand Down Expand Up @@ -99,6 +100,8 @@ class AvCallManager : public QObject

void setSelfAddress(const QHostAddress &addr);
void setStunHost(const QString &host, int port);
void setStunUserPass(const QString &user, const QString &pass);
void setStunProxy(const XMPP::AdvancedConnector::Proxy &proxy);

static void setBasePort(int port);
static void setExternalAddress(const QString &host);
Expand Down
38 changes: 33 additions & 5 deletions src/avcall/jinglertp.cpp
Expand Up @@ -22,6 +22,7 @@
#include <stdlib.h>
#include <QtCrypto>
#include "iris/netnames.h"
#include "iris/turnclient.h"
#include "iris/udpportreserver.h"
#include "xmpp_client.h"

Expand Down Expand Up @@ -339,6 +340,9 @@ class JingleRtpManagerPrivate : public QObject
QString extHost;
QString stunHost;
int stunPort;
QString stunUser;
QString stunPass;
XMPP::TurnClient::Proxy stunProxy;
int basePort;
QList<JingleRtp*> sessions;
QList<JingleRtp*> pending;
Expand Down Expand Up @@ -886,6 +890,7 @@ class JingleRtpPrivate : public QObject
connect(ice, SIGNAL(localCandidatesReady(const QList<XMPP::Ice176::Candidate> &)), SLOT(ice_localCandidatesReady(const QList<XMPP::Ice176::Candidate> &)));
connect(ice, SIGNAL(componentReady(int)), SLOT(ice_componentReady(int)), Qt::QueuedConnection); // signal is not DOR-SS

ice->setProxy(manager->stunProxy);
ice->setPortReserver(portReserver);

//QList<XMPP::Ice176::LocalAddress> localAddrs;
Expand Down Expand Up @@ -931,12 +936,11 @@ class JingleRtpPrivate : public QObject
if(!stunAddr.isNull() && stunPort > 0)
{
ice->setStunService(stunAddr, stunPort, XMPP::Ice176::Auto);
// FIXME: support user/pass, to enable TURN
/*if(!opt_user.isEmpty())
if(!manager->stunUser.isEmpty())
{
ice->setStunUsername(opt_user);
ice->setStunPassword(opt_pass.toUtf8());
}*/
ice->setStunUsername(manager->stunUser);
ice->setStunPassword(manager->stunPass.toUtf8());
}
}

// RTP+RTCP
Expand Down Expand Up @@ -1765,6 +1769,30 @@ void JingleRtpManager::setStunHost(const QString &host, int port)
d->stunPort = port;
}

void JingleRtpManager::setStunUserPass(const QString &user, const QString &pass)
{
d->stunUser = user;
d->stunPass = pass;
}

void JingleRtpManager::setStunProxy(const XMPP::AdvancedConnector::Proxy &proxy)
{
XMPP::TurnClient::Proxy tproxy;

if(proxy.type() == XMPP::AdvancedConnector::Proxy::HttpConnect)
{
tproxy.setHttpConnect(proxy.host(), proxy.port());
tproxy.setUserPass(proxy.user(), proxy.pass());
}
else if(proxy.type() == XMPP::AdvancedConnector::Proxy::Socks)
{
tproxy.setSocks(proxy.host(), proxy.port());
tproxy.setUserPass(proxy.user(), proxy.pass());
}

d->stunProxy = tproxy;
}

void JingleRtpManager::setBasePort(int port)
{
d->basePort = port;
Expand Down
3 changes: 3 additions & 0 deletions src/avcall/jinglertp.h
Expand Up @@ -19,6 +19,7 @@
#ifndef JINGLERTP_H
#define JINGLERTP_H

#include "xmpp.h"
#include "jinglertptasks.h"

class JingleRtpChannel;
Expand Down Expand Up @@ -143,6 +144,8 @@ class JingleRtpManager : public QObject
void setSelfAddress(const QHostAddress &addr);
void setExternalAddress(const QString &host); // resolved locally
void setStunHost(const QString &host, int port);
void setStunUserPass(const QString &user, const QString &pass);
void setStunProxy(const XMPP::AdvancedConnector::Proxy &proxy);
void setBasePort(int port);

signals:
Expand Down
4 changes: 3 additions & 1 deletion src/profiles.h
Expand Up @@ -76,11 +76,13 @@ class UserAccount
VarList keybind;

XMPP::Jid dtProxy;

QString optionsBase;

QString stunHost;
int stunPort;
QString stunUser;
QString stunPass;

QByteArray tlsOverrideCert;
QString tlsOverrideDomain;
Expand Down
8 changes: 8 additions & 0 deletions src/psi_profiles.cpp
Expand Up @@ -280,6 +280,12 @@ void UserAccount::fromOptions(OptionsTree *o, QString base)
// and use default
if (tmpPort != 0) stunPort = tmpPort;
}
if (allSetOptions.contains(base + ".stun-username")) {
stunUser = o->getOption(base + ".stun-username").toString();
}
if (allSetOptions.contains(base + ".stun-password")) {
stunPass = o->getOption(base + ".stun-password").toString();
}

if (allSetOptions.contains(base + ".tls")) {
tlsOverrideCert = o->getOption(base + ".tls.override-certificate").toByteArray();
Expand Down Expand Up @@ -410,6 +416,8 @@ void UserAccount::toOptions(OptionsTree *o, QString base)

o->setOption(base + ".stun-host", stunHost);
o->setOption(base + ".stun-port", QString::number(stunPort));
o->setOption(base + ".stun-username", stunUser);
o->setOption(base + ".stun-password", stunPass);

o->setOption(base + ".tls.override-certificate", tlsOverrideCert);
o->setOption(base + ".tls.override-domain", tlsOverrideDomain);
Expand Down

0 comments on commit 762fa75

Please sign in to comment.