Skip to content
Snippets Groups Projects
Commit fc6507ab authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #9871: disable STUN for account if STUN setup failed

parent bf5888b8
No related branches found
No related tags found
No related merge requests found
...@@ -354,7 +354,7 @@ void SipTransport::createSipTransport(SIPAccount *account) ...@@ -354,7 +354,7 @@ void SipTransport::createSipTransport(SIPAccount *account)
pjsip_transport *transport = createTlsTransport(remoteAddr, account->getLocalInterface(), account->getTlsListenerPort(), account->getTlsSetting()); pjsip_transport *transport = createTlsTransport(remoteAddr, account->getLocalInterface(), account->getTlsListenerPort(), account->getTlsSetting());
account->transport_ = transport; account->transport_ = transport;
} else if (account->isStunEnabled()) { } else if (account->isStunEnabled()) {
pjsip_transport *transport = createStunTransport(account->getStunServerName(), account->getStunPort()); pjsip_transport *transport = createSTUNTransport(*account);
if(transport == NULL) if(transport == NULL)
transport = createUdpTransport(account->getLocalInterface(), account->getLocalPort()); transport = createUdpTransport(account->getLocalInterface(), account->getLocalPort());
account->transport_ = transport; account->transport_ = transport;
...@@ -482,14 +482,15 @@ pjsip_tpselector *SipTransport::initTransportSelector(pjsip_transport *transport ...@@ -482,14 +482,15 @@ pjsip_tpselector *SipTransport::initTransportSelector(pjsip_transport *transport
return tp; return tp;
} }
pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint16_t port) pjsip_transport *SipTransport::createSTUNTransport(SIPAccount &account)
{ {
pjsip_transport *transport; pj_str_t serverName = account.getStunServerName();
pj_uint16_t port = account.getStunPort();
DEBUG("SipTransport: Create stun transport server name: %s, port: %d", serverName, port);// account->getStunPort()); DEBUG("SipTransport: Create STUN transport server name: %s, port: %d", serverName, port);
if (createStunResolver(serverName, port) != PJ_SUCCESS) { if (createStunResolver(serverName, port) != PJ_SUCCESS) {
ERROR("SipTransport: Can't resolve STUN server"); ERROR("SipTransport: Can't resolve STUN server");
Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(""); Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(account.getAccountID());
return NULL; return NULL;
} }
...@@ -499,13 +500,13 @@ pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint1 ...@@ -499,13 +500,13 @@ pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint1
if (pj_sockaddr_in_init(&boundAddr, &serverName, 0) != PJ_SUCCESS) { if (pj_sockaddr_in_init(&boundAddr, &serverName, 0) != PJ_SUCCESS) {
ERROR("SipTransport: Can't initialize IPv4 socket on %*s:%i", serverName.slen, serverName.ptr, port); ERROR("SipTransport: Can't initialize IPv4 socket on %*s:%i", serverName.slen, serverName.ptr, port);
Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(""); Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(account.getAccountID());
return NULL; return NULL;
} }
if (pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock) != PJ_SUCCESS) { if (pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock) != PJ_SUCCESS) {
ERROR("SipTransport: Can't create or bind socket"); ERROR("SipTransport: Can't create or bind socket");
Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(""); Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(account.getAccountID());
return NULL; return NULL;
} }
...@@ -515,7 +516,7 @@ pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint1 ...@@ -515,7 +516,7 @@ pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint1
if (pjstun_get_mapped_addr(&cp_->factory, 1, &sock, &serverName, port, &serverName, port, &pub_addr) != PJ_SUCCESS) { if (pjstun_get_mapped_addr(&cp_->factory, 1, &sock, &serverName, port, &serverName, port, &pub_addr) != PJ_SUCCESS) {
ERROR("SipTransport: Can't contact STUN server"); ERROR("SipTransport: Can't contact STUN server");
pj_sock_close(sock); pj_sock_close(sock);
Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(""); Manager::instance().getDbusManager()->getConfigurationManager()->stunStatusFailure(account.getAccountID());
return NULL; return NULL;
} }
...@@ -524,6 +525,7 @@ pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint1 ...@@ -524,6 +525,7 @@ pjsip_transport *SipTransport::createStunTransport(pj_str_t serverName, pj_uint1
pj_ntohs(pub_addr.sin_port) pj_ntohs(pub_addr.sin_port)
}; };
pjsip_transport *transport;
pjsip_udp_transport_attach2(endpt_, PJSIP_TRANSPORT_UDP, sock, &a_name, 1, pjsip_udp_transport_attach2(endpt_, PJSIP_TRANSPORT_UDP, sock, &a_name, 1,
&transport); &transport);
......
...@@ -156,12 +156,6 @@ class SipTransport { ...@@ -156,12 +156,6 @@ class SipTransport {
pj_uint16_t tlsListenerPort, pj_uint16_t tlsListenerPort,
pjsip_tls_setting *tlsSetting); pjsip_tls_setting *tlsSetting);
/**
* Create a UDP transport using stun server to resove public address
* @param account The account for which a transport must be created.
*/
pjsip_transport *createStunTransport(pj_str_t serverName, pj_uint16_t port);
/** /**
* This function unset the transport for a given account. * This function unset the transport for a given account.
*/ */
...@@ -180,6 +174,8 @@ class SipTransport { ...@@ -180,6 +174,8 @@ class SipTransport {
private: private:
NON_COPYABLE(SipTransport); NON_COPYABLE(SipTransport);
pjsip_transport *createSTUNTransport(SIPAccount &account);
/** /**
* UDP Transports are stored in this map in order to retreive them in case * UDP Transports are stored in this map in order to retreive them in case
* several accounts would share the same port number. * several accounts would share the same port number.
......
...@@ -490,7 +490,6 @@ key_exchange_changed_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) ...@@ -490,7 +490,6 @@ key_exchange_changed_cb(GtkWidget *widget UNUSED, gpointer data UNUSED)
gtk_widget_set_sensitive(zrtp_button, sensitive); gtk_widget_set_sensitive(zrtp_button, sensitive);
} }
static void use_sip_tls_cb(GtkWidget *widget, gpointer data) static void use_sip_tls_cb(GtkWidget *widget, gpointer data)
{ {
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "sliders.h" #include "sliders.h"
#include "statusicon.h" #include "statusicon.h"
#include "assistant.h" #include "assistant.h"
#include "accountlist.h"
#include "accountlistconfigdialog.h" #include "accountlistconfigdialog.h"
#include "dbus.h" #include "dbus.h"
...@@ -448,14 +449,22 @@ accounts_changed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED) ...@@ -448,14 +449,22 @@ accounts_changed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED)
} }
static void static void
stun_status_failure_cb(DBusGProxy *proxy UNUSED, const gchar *reason, void *foo UNUSED) stun_status_failure_cb(DBusGProxy *proxy UNUSED, const gchar *accountID, void *foo UNUSED)
{ {
ERROR("Error: Stun status failure: %s failed", reason); ERROR("Error: Stun status failure: account %s failed to setup STUN",
accountID);
// Disable STUN for the account that tried to create the STUN transport
account_t *account = account_list_get_by_id(accountID);
if (account) {
account_replace(account, ACCOUNT_SIP_STUN_ENABLED, "false");
dbus_set_account_details(account);
}
} }
static void static void
stun_status_success_cb(DBusGProxy *proxy UNUSED, const gchar *message UNUSED, void *foo UNUSED) stun_status_success_cb(DBusGProxy *proxy UNUSED, const gchar *message UNUSED, void *foo UNUSED)
{ {
DEBUG("STUN setup successful");
} }
static void static void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment