diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-12-25 14:39:48 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-05-11 10:22:56 (GMT) |
commit | 927d62cc54c8a5087dba6b61afa9ad30dc528a23 (patch) | |
tree | e67dc911bd30c0519d31a542d8e085bbb209879d /Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp | |
parent | 17b188343e7208b875af7af30d94f0bf948f6b93 (diff) | |
download | swift-927d62cc54c8a5087dba6b61afa9ad30dc528a23.zip swift-927d62cc54c8a5087dba6b61afa9ad30dc528a23.tar.bz2 |
File Transfer refactoring.
Allocate S5B server lazily.
Forward forts lazily.
Various state machine fixes.
Temporarily disabling S5B proxy support.
Change-Id: I3145e85a99b15a7e457306bbfbe9c0eb570191e4
Diffstat (limited to 'Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp')
-rw-r--r-- | Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp | 89 |
1 files changed, 85 insertions, 4 deletions
diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp index 338f221..1e96b22 100644 --- a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp +++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp @@ -1,14 +1,95 @@ /* - * Copyright (c) 2011 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2011 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +/* + * Copyright (c) 2013 Remko Tronçon + * Licensed under the GNU General Public License. + * See the COPYING file for more information. */ #include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h> -namespace Swift { +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/bind.hpp> + +#include <Swiften/Base/Log.h> +#include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Base/foreach.h> +#include <Swiften/Elements/JingleS5BTransportPayload.h> +#include <Swiften/Network/ConnectionFactory.h> +#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> + +using namespace Swift; + +RemoteJingleTransportCandidateSelector::RemoteJingleTransportCandidateSelector( + ConnectionFactory* connectionFactory, + TimerFactory* timerFactory) : + connectionFactory(connectionFactory), + timerFactory(timerFactory) { +} RemoteJingleTransportCandidateSelector::~RemoteJingleTransportCandidateSelector() { } +void RemoteJingleTransportCandidateSelector::addCandidates( + const std::vector<JingleS5BTransportPayload::Candidate>& candidates) { + foreach(JingleS5BTransportPayload::Candidate c, candidates) { + this->candidates.push(c); + } +} + +void RemoteJingleTransportCandidateSelector::startSelectingCandidate() { + tryNextCandidate(); +} + +void RemoteJingleTransportCandidateSelector::stopSelectingCandidate() { + if (s5bSession) { + sessionReadyConnection.disconnect(); + s5bSession->stop(); + } +} + +void RemoteJingleTransportCandidateSelector::tryNextCandidate() { + if (candidates.empty()) { + SWIFT_LOG(debug) << "No more candidates" << std::endl; + onCandidateSelectFinished( + boost::optional<JingleS5BTransportPayload::Candidate>(), boost::shared_ptr<SOCKS5BytestreamClientSession>()); + } + else { + lastCandidate = candidates.top(); + candidates.pop(); + SWIFT_LOG(debug) << "Trying candidate " << lastCandidate.cid << std::endl; + if (lastCandidate.type == JingleS5BTransportPayload::Candidate::DirectType + || lastCandidate.type == JingleS5BTransportPayload::Candidate::AssistedType + || lastCandidate.type == JingleS5BTransportPayload::Candidate::ProxyType ) { + boost::shared_ptr<Connection> connection = connectionFactory->createConnection(); + s5bSession = boost::make_shared<SOCKS5BytestreamClientSession>( + connection, lastCandidate.hostPort, socks5DstAddr, timerFactory); + sessionReadyConnection = s5bSession->onSessionReady.connect( + boost::bind(&RemoteJingleTransportCandidateSelector::handleSessionReady, this, _1)); + s5bSession->start(); + } + else { + SWIFT_LOG(debug) << "Can't handle this type of candidate" << std::endl; + tryNextCandidate(); + } + } +} + +void RemoteJingleTransportCandidateSelector::handleSessionReady(bool error) { + sessionReadyConnection.disconnect(); + if (error) { + s5bSession.reset(); + tryNextCandidate(); + } + else { + onCandidateSelectFinished(lastCandidate, s5bSession); + } +} + +void RemoteJingleTransportCandidateSelector::setSOCKS5DstAddr(const std::string& socks5DstAddr) { + this->socks5DstAddr = socks5DstAddr; } |