diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 20:09:34 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-16 20:09:34 +0000 |
commit | a4564bbdff060a3b9d1793ba0b01b4dfb0684826 (patch) | |
tree | 76d1b35bd3ad260a1b673846d5b27e5fc32ceec9 /remoting/jingle_glue | |
parent | 487209b9298d131be927809d88e42a9e598ece80 (diff) | |
download | chromium_src-a4564bbdff060a3b9d1793ba0b01b4dfb0684826.zip chromium_src-a4564bbdff060a3b9d1793ba0b01b4dfb0684826.tar.gz chromium_src-a4564bbdff060a3b9d1793ba0b01b4dfb0684826.tar.bz2 |
Fix LibjingleTransportFactory to refresh STUN/Relay.
Previously chromoting host would get relay info only when started. Relay
token expires within several hours, which means relay session creation would
always fail from the host running for longer than several hours, and that
makes connection impossible in some configurations. Moved code that
gets Jingle info to LibjingleTransportFactory and it's responsible for
refreshing relay token every hour.
BUG=318897
R=rmsousa@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=240926
Review URL: https://codereview.chromium.org/98173006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/jingle_glue')
-rw-r--r-- | remoting/jingle_glue/jingle_info_request.cc | 30 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_info_request.h | 18 |
2 files changed, 32 insertions, 16 deletions
diff --git a/remoting/jingle_glue/jingle_info_request.cc b/remoting/jingle_glue/jingle_info_request.cc index e75b89f..d41f18a 100644 --- a/remoting/jingle_glue/jingle_info_request.cc +++ b/remoting/jingle_glue/jingle_info_request.cc @@ -8,6 +8,7 @@ #include "base/message_loop/message_loop.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" +#include "base/time/time.h" #include "net/base/net_util.h" #include "remoting/jingle_glue/iq_sender.h" #include "third_party/libjingle/source/talk/base/socketaddress.h" @@ -16,12 +17,13 @@ namespace remoting { +const int kRequestTimeoutSeconds = 5; + JingleInfoRequest::JingleInfoRequest(SignalStrategy* signal_strategy) : iq_sender_(signal_strategy) { } -JingleInfoRequest::~JingleInfoRequest() { -} +JingleInfoRequest::~JingleInfoRequest() {} void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) { on_jingle_info_cb_ = callback; @@ -30,19 +32,39 @@ void JingleInfoRequest::Send(const OnJingleInfoCallback& callback) { request_ = iq_sender_.SendIq( buzz::STR_GET, buzz::STR_EMPTY, iq_body.Pass(), base::Bind(&JingleInfoRequest::OnResponse, base::Unretained(this))); + if (!request_) { + // If we failed to send IqRequest it means that SignalStrategy is + // disconnected. Notify the caller. + std::vector<talk_base::SocketAddress> stun_hosts; + std::vector<std::string> relay_hosts; + std::string relay_token; + on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); + return; + } + request_->SetTimeout(base::TimeDelta::FromSeconds(kRequestTimeoutSeconds)); } void JingleInfoRequest::OnResponse(IqRequest* request, const buzz::XmlElement* stanza) { + std::vector<talk_base::SocketAddress> stun_hosts; + std::vector<std::string> relay_hosts; + std::string relay_token; + + if (!stanza) { + LOG(WARNING) << "Jingle info request has timed out."; + on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); + return; + } + const buzz::XmlElement* query = stanza->FirstNamed(buzz::QN_JINGLE_INFO_QUERY); if (query == NULL) { LOG(WARNING) << "No Jingle info found in Jingle Info query response." << stanza->Str(); + on_jingle_info_cb_.Run(relay_token, relay_hosts, stun_hosts); return; } - std::vector<talk_base::SocketAddress> stun_hosts; const buzz::XmlElement* stun = query->FirstNamed(buzz::QN_JINGLE_INFO_STUN); if (stun) { for (const buzz::XmlElement* server = @@ -63,8 +85,6 @@ void JingleInfoRequest::OnResponse(IqRequest* request, } } - std::vector<std::string> relay_hosts; - std::string relay_token; const buzz::XmlElement* relay = query->FirstNamed(buzz::QN_JINGLE_INFO_RELAY); if (relay) { relay_token = relay->TextNamed(buzz::QN_JINGLE_INFO_TOKEN); diff --git a/remoting/jingle_glue/jingle_info_request.h b/remoting/jingle_glue/jingle_info_request.h index a1b10de..118aa4a 100644 --- a/remoting/jingle_glue/jingle_info_request.h +++ b/remoting/jingle_glue/jingle_info_request.h @@ -13,7 +13,6 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "remoting/jingle_glue/iq_sender.h" -#include "third_party/libjingle/source/talk/base/sigslot.h" namespace buzz { class XmlElement; @@ -34,17 +33,14 @@ class SignalStrategy; // // This class is not threadsafe and should be used on the same thread it is // created on. -// -// TODO(ajwong): Add support for a timeout. -class JingleInfoRequest : public sigslot::has_slots<> { +class JingleInfoRequest { public: - // Callback to receive the Jingle configuration settings. The arguments are - // passed by pointer so the receive may call swap on them. The receiver does - // NOT own the arguments, which are guaranteed only to be alive for the - // duration of the callback. - typedef base::Callback<void ( - const std::string&, const std::vector<std::string>&, - const std::vector<talk_base::SocketAddress>&)> OnJingleInfoCallback; + // Callback to receive the Jingle configuration settings. All fields are empty + // if the request has timed out. + typedef base::Callback<void(const std::string& relay_token, + const std::vector<std::string>& relay_servers, + const std::vector<talk_base::SocketAddress>& + stun_servers)> OnJingleInfoCallback; explicit JingleInfoRequest(SignalStrategy* signal_strategy); virtual ~JingleInfoRequest(); |