diff options
author | Tobias Markmann <tm@ayena.de> | 2015-01-11 15:40:09 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2015-02-11 09:36:03 (GMT) |
commit | f176050a50fb846bbad3fb49d6b2f7a2c81e3589 (patch) | |
tree | bd93b8b540cb3818cc0d47d44b9dd8751dd17dd5 /Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp | |
parent | 71e34ffa7144441bc5a7fce15728f506daffc756 (diff) | |
download | swift-f176050a50fb846bbad3fb49d6b2f7a2c81e3589.zip swift-f176050a50fb846bbad3fb49d6b2f7a2c81e3589.tar.bz2 |
Wait for responder to terminate the the file transfer session after data
verification.
Test-Information:
Tested with FileTransferTest (coming with future commit) and inspected
the logs.
Change-Id: Idd2739e15ab944e8486065cb2a3bc559ce9053d1
Diffstat (limited to 'Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp')
-rw-r--r-- | Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index 4183af7..07e927e 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp @@ -33,24 +33,26 @@ #include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h> #include <Swiften/FileTransfer/FileTransferTransporter.h> #include <Swiften/FileTransfer/FileTransferTransporterFactory.h> #include <Swiften/FileTransfer/ReadBytestream.h> #include <Swiften/FileTransfer/TransportSession.h> #include <Swiften/Crypto/CryptoProvider.h> +#include <Swiften/Network/TimerFactory.h> #include <Swiften/Base/Log.h> using namespace Swift; static const int DEFAULT_BLOCK_SIZE = 4096; OutgoingJingleFileTransfer::OutgoingJingleFileTransfer( const JID& toJID, JingleSession::ref session, boost::shared_ptr<ReadBytestream> stream, FileTransferTransporterFactory* transporterFactory, + TimerFactory* timerFactory, IDGenerator* idGenerator, const JingleFileTransferFileInfo& fileInfo, const FileTransferOptions& options, CryptoProvider* crypto) : JingleFileTransfer(session, toJID, transporterFactory), idGenerator(idGenerator), @@ -64,12 +66,15 @@ OutgoingJingleFileTransfer::OutgoingJingleFileTransfer( setFileInfo(fileInfo.getName(), fileInfo.getSize()); // calculate both, MD5 and SHA-1 since we don't know which one the other side supports hashCalculator = new IncrementalBytestreamHashCalculator(true, true, crypto); stream->onRead.connect( boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1)); + + waitForRemoteTermination = timerFactory->createTimer(5000); + waitForRemoteTermination->onTick.connect(boost::bind(&OutgoingJingleFileTransfer::handleWaitForRemoteTerminationTimeout, this)); } OutgoingJingleFileTransfer::~OutgoingJingleFileTransfer() { stream->onRead.disconnect( boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1)); delete hashCalculator; @@ -196,13 +201,16 @@ void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTran if (error) { terminate(JinglePayload::Reason::ConnectivityError); } else { sendSessionInfoHash(); - terminate(JinglePayload::Reason::Success); + + // wait for other party to terminate session after they have verified the hash + setState(WaitForTermination); + waitForRemoteTermination->start(); } } void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSession> transportSession) { SWIFT_LOG(debug) << std::endl; @@ -238,12 +246,13 @@ FileTransfer::State::Type OutgoingJingleFileTransfer::getExternalState(State sta case TryingCandidates: return FileTransfer::State::Negotiating; case WaitingForPeerProxyActivate: return FileTransfer::State::Negotiating; case WaitingForLocalProxyActivate: return FileTransfer::State::Negotiating; case WaitingForCandidateAcknowledge: return FileTransfer::State::Negotiating; case FallbackRequested: return FileTransfer::State::Negotiating; case Transferring: return FileTransfer::State::Transferring; + case WaitForTermination: return FileTransfer::State::Transferring; case Finished: return FileTransfer::State::Finished; } assert(false); return FileTransfer::State::Initial; } @@ -262,12 +271,14 @@ void OutgoingJingleFileTransfer::stopAll() { assert(transportSession); processedBytesConnection.disconnect(); transferFinishedConnection.disconnect(); transportSession->stop(); transportSession.reset(); break; + case WaitForTermination: + break; case Finished: SWIFT_LOG(warning) << "Already finished" << std::endl; break; } if (state != Initial) { delete transporter; } } @@ -340,6 +351,13 @@ boost::shared_ptr<TransportSession> OutgoingJingleFileTransfer::createLocalCandi } boost::shared_ptr<TransportSession> OutgoingJingleFileTransfer::createRemoteCandidateSession() { return transporter->createRemoteCandidateSession(stream); } +void OutgoingJingleFileTransfer::handleWaitForRemoteTerminationTimeout() { + assert(state == WaitForTermination); + SWIFT_LOG(warning) << "Other party did not terminate session. Terminate it now." << std::endl; + waitForRemoteTermination->stop(); + terminate(JinglePayload::Reason::MediaError); +} + |