diff options
Diffstat (limited to 'Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp')
| -rw-r--r-- | Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index 367fc97..57a18a8 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | /* | 7 | /* |
| 8 | * Copyright (c) 2013-2016 Isode Limited. | 8 | * Copyright (c) 2013-2019 Isode Limited. |
| 9 | * All rights reserved. | 9 | * All rights reserved. |
| 10 | * See the COPYING file for more information. | 10 | * See the COPYING file for more information. |
| 11 | */ | 11 | */ |
| @@ -87,9 +87,9 @@ OutgoingJingleFileTransfer::~OutgoingJingleFileTransfer() { | |||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | void OutgoingJingleFileTransfer::start() { | 89 | void OutgoingJingleFileTransfer::start() { |
| 90 | SWIFT_LOG(debug) << std::endl; | 90 | SWIFT_LOG(debug); |
| 91 | if (state != Initial) { | 91 | if (state != Initial) { |
| 92 | SWIFT_LOG(warning) << "Incorrect state" << std::endl; | 92 | SWIFT_LOG(warning) << "Incorrect state"; |
| 93 | return; | 93 | return; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| @@ -109,7 +109,7 @@ void OutgoingJingleFileTransfer::cancel() { | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | void OutgoingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) { | 111 | void OutgoingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) { |
| 112 | SWIFT_LOG(debug) << reason << std::endl; | 112 | SWIFT_LOG(debug) << reason; |
| 113 | 113 | ||
| 114 | if (state != Initial && state != GeneratingInitialLocalCandidates && state != Finished) { | 114 | if (state != Initial && state != GeneratingInitialLocalCandidates && state != Finished) { |
| 115 | session->sendTerminate(reason); | 115 | session->sendTerminate(reason); |
| @@ -122,8 +122,8 @@ void OutgoingJingleFileTransfer::handleSessionAcceptReceived( | |||
| 122 | const JingleContentID&, | 122 | const JingleContentID&, |
| 123 | JingleDescription::ref, | 123 | JingleDescription::ref, |
| 124 | JingleTransportPayload::ref transportPayload) { | 124 | JingleTransportPayload::ref transportPayload) { |
| 125 | SWIFT_LOG(debug) << std::endl; | 125 | SWIFT_LOG(debug); |
| 126 | if (state != WaitingForAccept) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } | 126 | if (state != WaitingForAccept) { SWIFT_LOG(warning) << "Incorrect state"; return; } |
| 127 | 127 | ||
| 128 | if (JingleS5BTransportPayload::ref s5bPayload = std::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) { | 128 | if (JingleS5BTransportPayload::ref s5bPayload = std::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) { |
| 129 | transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr()); | 129 | transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr()); |
| @@ -134,14 +134,14 @@ void OutgoingJingleFileTransfer::handleSessionAcceptReceived( | |||
| 134 | startTransferring(transporter->createIBBSendSession(ibbPayload->getSessionID(), ibbPayload->getBlockSize().get_value_or(DEFAULT_BLOCK_SIZE), stream)); | 134 | startTransferring(transporter->createIBBSendSession(ibbPayload->getSessionID(), ibbPayload->getBlockSize().get_value_or(DEFAULT_BLOCK_SIZE), stream)); |
| 135 | } | 135 | } |
| 136 | else { | 136 | else { |
| 137 | SWIFT_LOG(debug) << "Unknown transport payload. Falling back." << std::endl; | 137 | SWIFT_LOG(debug) << "Unknown transport payload. Falling back."; |
| 138 | fallback(); | 138 | fallback(); |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) { | 142 | void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) { |
| 143 | SWIFT_LOG(debug) << std::endl; | 143 | SWIFT_LOG(debug); |
| 144 | if (state == Finished) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } | 144 | if (state == Finished) { SWIFT_LOG(warning) << "Incorrect state: " << state; return; } |
| 145 | 145 | ||
| 146 | stopAll(); | 146 | stopAll(); |
| 147 | if (state == WaitForTermination) { | 147 | if (state == WaitForTermination) { |
| @@ -162,26 +162,26 @@ void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional< | |||
| 162 | } | 162 | } |
| 163 | 163 | ||
| 164 | void OutgoingJingleFileTransfer::handleTransportAcceptReceived(const JingleContentID&, JingleTransportPayload::ref transport) { | 164 | void OutgoingJingleFileTransfer::handleTransportAcceptReceived(const JingleContentID&, JingleTransportPayload::ref transport) { |
| 165 | SWIFT_LOG(debug) << std::endl; | 165 | SWIFT_LOG(debug); |
| 166 | if (state != FallbackRequested) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } | 166 | if (state != FallbackRequested) { SWIFT_LOG(warning) << "Incorrect state"; return; } |
| 167 | 167 | ||
| 168 | if (JingleIBBTransportPayload::ref ibbPayload = std::dynamic_pointer_cast<JingleIBBTransportPayload>(transport)) { | 168 | if (JingleIBBTransportPayload::ref ibbPayload = std::dynamic_pointer_cast<JingleIBBTransportPayload>(transport)) { |
| 169 | startTransferring(transporter->createIBBSendSession(ibbPayload->getSessionID(), ibbPayload->getBlockSize().get_value_or(DEFAULT_BLOCK_SIZE), stream)); | 169 | startTransferring(transporter->createIBBSendSession(ibbPayload->getSessionID(), ibbPayload->getBlockSize().get_value_or(DEFAULT_BLOCK_SIZE), stream)); |
| 170 | } | 170 | } |
| 171 | else { | 171 | else { |
| 172 | SWIFT_LOG(debug) << "Unknown transport replacement" << std::endl; | 172 | SWIFT_LOG(debug) << "Unknown transport replacement"; |
| 173 | terminate(JinglePayload::Reason::FailedTransport); | 173 | terminate(JinglePayload::Reason::FailedTransport); |
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | void OutgoingJingleFileTransfer::handleTransportRejectReceived(const JingleContentID &, std::shared_ptr<JingleTransportPayload>) { | 177 | void OutgoingJingleFileTransfer::handleTransportRejectReceived(const JingleContentID &, std::shared_ptr<JingleTransportPayload>) { |
| 178 | SWIFT_LOG(debug) << std::endl; | 178 | SWIFT_LOG(debug); |
| 179 | 179 | ||
| 180 | terminate(JinglePayload::Reason::UnsupportedTransports); | 180 | terminate(JinglePayload::Reason::UnsupportedTransports); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | void OutgoingJingleFileTransfer::sendSessionInfoHash() { | 183 | void OutgoingJingleFileTransfer::sendSessionInfoHash() { |
| 184 | SWIFT_LOG(debug) << std::endl; | 184 | SWIFT_LOG(debug); |
| 185 | 185 | ||
| 186 | JingleFileTransferHash::ref hashElement = std::make_shared<JingleFileTransferHash>(); | 186 | JingleFileTransferHash::ref hashElement = std::make_shared<JingleFileTransferHash>(); |
| 187 | hashElement->getFileInfo().addHash(HashElement("sha-1", hashCalculator->getSHA1Hash())); | 187 | hashElement->getFileInfo().addHash(HashElement("sha-1", hashCalculator->getSHA1Hash())); |
| @@ -191,8 +191,8 @@ void OutgoingJingleFileTransfer::sendSessionInfoHash() { | |||
| 191 | 191 | ||
| 192 | void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( | 192 | void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( |
| 193 | const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { | 193 | const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { |
| 194 | SWIFT_LOG(debug) << std::endl; | 194 | SWIFT_LOG(debug); |
| 195 | if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } | 195 | if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state; return; } |
| 196 | 196 | ||
| 197 | fillCandidateMap(localCandidates, candidates); | 197 | fillCandidateMap(localCandidates, candidates); |
| 198 | 198 | ||
| @@ -203,7 +203,7 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( | |||
| 203 | 203 | ||
| 204 | JingleTransportPayload::ref transport; | 204 | JingleTransportPayload::ref transport; |
| 205 | if (candidates.empty()) { | 205 | if (candidates.empty()) { |
| 206 | SWIFT_LOG(debug) << "no S5B candidates generated. Send IBB transport candidate." << std::endl; | 206 | SWIFT_LOG(debug) << "no S5B candidates generated. Send IBB transport candidate."; |
| 207 | JingleIBBTransportPayload::ref ibbTransport = std::make_shared<JingleIBBTransportPayload>(); | 207 | JingleIBBTransportPayload::ref ibbTransport = std::make_shared<JingleIBBTransportPayload>(); |
| 208 | ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); | 208 | ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); |
| 209 | ibbTransport->setSessionID(idGenerator->generateID()); | 209 | ibbTransport->setSessionID(idGenerator->generateID()); |
| @@ -216,7 +216,7 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( | |||
| 216 | s5bTransport->setDstAddr(dstAddr); | 216 | s5bTransport->setDstAddr(dstAddr); |
| 217 | for (auto&& candidate : candidates) { | 217 | for (auto&& candidate : candidates) { |
| 218 | s5bTransport->addCandidate(candidate); | 218 | s5bTransport->addCandidate(candidate); |
| 219 | SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl; | 219 | SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString(); |
| 220 | } | 220 | } |
| 221 | transport = s5bTransport; | 221 | transport = s5bTransport; |
| 222 | } | 222 | } |
| @@ -226,7 +226,7 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( | |||
| 226 | 226 | ||
| 227 | void OutgoingJingleFileTransfer::fallback() { | 227 | void OutgoingJingleFileTransfer::fallback() { |
| 228 | if (options.isInBandAllowed()) { | 228 | if (options.isInBandAllowed()) { |
| 229 | SWIFT_LOG(debug) << "Trying to fallback to IBB transport." << std::endl; | 229 | SWIFT_LOG(debug) << "Trying to fallback to IBB transport."; |
| 230 | JingleIBBTransportPayload::ref ibbTransport = std::make_shared<JingleIBBTransportPayload>(); | 230 | JingleIBBTransportPayload::ref ibbTransport = std::make_shared<JingleIBBTransportPayload>(); |
| 231 | ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); | 231 | ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); |
| 232 | ibbTransport->setSessionID(idGenerator->generateID()); | 232 | ibbTransport->setSessionID(idGenerator->generateID()); |
| @@ -234,14 +234,14 @@ void OutgoingJingleFileTransfer::fallback() { | |||
| 234 | session->sendTransportReplace(contentID, ibbTransport); | 234 | session->sendTransportReplace(contentID, ibbTransport); |
| 235 | } | 235 | } |
| 236 | else { | 236 | else { |
| 237 | SWIFT_LOG(debug) << "Fallback to IBB transport not allowed." << std::endl; | 237 | SWIFT_LOG(debug) << "Fallback to IBB transport not allowed."; |
| 238 | terminate(JinglePayload::Reason::ConnectivityError); | 238 | terminate(JinglePayload::Reason::ConnectivityError); |
| 239 | } | 239 | } |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) { | 242 | void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) { |
| 243 | SWIFT_LOG(debug) << std::endl; | 243 | SWIFT_LOG(debug); |
| 244 | if (state != Transferring) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; } | 244 | if (state != Transferring) { SWIFT_LOG(warning) << "Incorrect state: " << state; return; } |
| 245 | 245 | ||
| 246 | if (error) { | 246 | if (error) { |
| 247 | terminate(JinglePayload::Reason::ConnectivityError); | 247 | terminate(JinglePayload::Reason::ConnectivityError); |
| @@ -256,7 +256,7 @@ void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTran | |||
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | void OutgoingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSession> transportSession) { | 258 | void OutgoingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSession> transportSession) { |
| 259 | SWIFT_LOG(debug) << std::endl; | 259 | SWIFT_LOG(debug); |
| 260 | 260 | ||
| 261 | this->transportSession = transportSession; | 261 | this->transportSession = transportSession; |
| 262 | processedBytesConnection = transportSession->onBytesSent.connect( | 262 | processedBytesConnection = transportSession->onBytesSent.connect( |
| @@ -269,14 +269,14 @@ void OutgoingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSess | |||
| 269 | 269 | ||
| 270 | 270 | ||
| 271 | void OutgoingJingleFileTransfer::setInternalState(State state) { | 271 | void OutgoingJingleFileTransfer::setInternalState(State state) { |
| 272 | SWIFT_LOG(debug) << state << std::endl; | 272 | SWIFT_LOG(debug) << state; |
| 273 | this->state = state; | 273 | this->state = state; |
| 274 | setState(FileTransfer::State(getExternalState(state))); | 274 | setState(FileTransfer::State(getExternalState(state))); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | void OutgoingJingleFileTransfer::setFinishedState( | 277 | void OutgoingJingleFileTransfer::setFinishedState( |
| 278 | FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) { | 278 | FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) { |
| 279 | SWIFT_LOG(debug) << std::endl; | 279 | SWIFT_LOG(debug); |
| 280 | this->state = Finished; | 280 | this->state = Finished; |
| 281 | onStateChanged(type); | 281 | onStateChanged(type); |
| 282 | onFinished(error); | 282 | onFinished(error); |
| @@ -301,9 +301,9 @@ FileTransfer::State::Type OutgoingJingleFileTransfer::getExternalState(State sta | |||
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | void OutgoingJingleFileTransfer::stopAll() { | 303 | void OutgoingJingleFileTransfer::stopAll() { |
| 304 | SWIFT_LOG(debug) << state << std::endl; | 304 | SWIFT_LOG(debug) << state; |
| 305 | switch (state) { | 305 | switch (state) { |
| 306 | case Initial: SWIFT_LOG(warning) << "Not yet started" << std::endl; break; | 306 | case Initial: SWIFT_LOG(warning) << "Not yet started"; break; |
| 307 | case GeneratingInitialLocalCandidates: transporter->stopGeneratingLocalCandidates(); break; | 307 | case GeneratingInitialLocalCandidates: transporter->stopGeneratingLocalCandidates(); break; |
| 308 | case WaitingForAccept: break; | 308 | case WaitingForAccept: break; |
| 309 | case TryingCandidates: transporter->stopTryingRemoteCandidates(); break; | 309 | case TryingCandidates: transporter->stopTryingRemoteCandidates(); break; |
| @@ -320,7 +320,7 @@ void OutgoingJingleFileTransfer::stopAll() { | |||
| 320 | break; | 320 | break; |
| 321 | case WaitForTermination: | 321 | case WaitForTermination: |
| 322 | break; | 322 | break; |
| 323 | case Finished: SWIFT_LOG(warning) << "Already finished" << std::endl; break; | 323 | case Finished: SWIFT_LOG(warning) << "Already finished"; break; |
| 324 | } | 324 | } |
| 325 | if (state != Initial) { | 325 | if (state != Initial) { |
| 326 | removeTransporter(); | 326 | removeTransporter(); |
| @@ -328,7 +328,7 @@ void OutgoingJingleFileTransfer::stopAll() { | |||
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { | 330 | void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { |
| 331 | SWIFT_LOG(debug) << std::endl; | 331 | SWIFT_LOG(debug); |
| 332 | 332 | ||
| 333 | if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { | 333 | if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { |
| 334 | setInternalState(WaitingForPeerProxyActivate); | 334 | setInternalState(WaitingForPeerProxyActivate); |
| @@ -340,7 +340,7 @@ void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { | |||
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { | 342 | void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { |
| 343 | SWIFT_LOG(debug) << std::endl; | 343 | SWIFT_LOG(debug); |
| 344 | 344 | ||
| 345 | if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { | 345 | if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { |
| 346 | setInternalState(WaitingForLocalProxyActivate); | 346 | setInternalState(WaitingForLocalProxyActivate); |
| @@ -400,7 +400,7 @@ std::shared_ptr<TransportSession> OutgoingJingleFileTransfer::createRemoteCandid | |||
| 400 | 400 | ||
| 401 | void OutgoingJingleFileTransfer::handleWaitForRemoteTerminationTimeout() { | 401 | void OutgoingJingleFileTransfer::handleWaitForRemoteTerminationTimeout() { |
| 402 | assert(state == WaitForTermination); | 402 | assert(state == WaitForTermination); |
| 403 | SWIFT_LOG(warning) << "Other party did not terminate session. Terminate it now." << std::endl; | 403 | SWIFT_LOG(warning) << "Other party did not terminate session. Terminate it now."; |
| 404 | waitForRemoteTermination->stop(); | 404 | waitForRemoteTermination->stop(); |
| 405 | terminate(JinglePayload::Reason::MediaError); | 405 | terminate(JinglePayload::Reason::MediaError); |
| 406 | } | 406 | } |
Swift