summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/FileTransfer/IncomingJingleFileTransfer.cpp')
-rw-r--r--Swiften/FileTransfer/IncomingJingleFileTransfer.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp
index d5de5e4..7c46c60 100644
--- a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp
+++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2011-2016 Isode Limited. 2 * Copyright (c) 2011-2019 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -67,8 +67,8 @@ IncomingJingleFileTransfer::~IncomingJingleFileTransfer() {
67void IncomingJingleFileTransfer::accept( 67void IncomingJingleFileTransfer::accept(
68 std::shared_ptr<WriteBytestream> stream, 68 std::shared_ptr<WriteBytestream> stream,
69 const FileTransferOptions& options) { 69 const FileTransferOptions& options) {
70 SWIFT_LOG(debug) << std::endl; 70 SWIFT_LOG(debug);
71 if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 71 if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state"; return; }
72 72
73 assert(!this->stream); 73 assert(!this->stream);
74 this->stream = stream; 74 this->stream = stream;
@@ -85,7 +85,7 @@ void IncomingJingleFileTransfer::accept(
85 JingleS5BTransportPayload::ref s5bTransport = initialContent->getTransport<JingleS5BTransportPayload>(); 85 JingleS5BTransportPayload::ref s5bTransport = initialContent->getTransport<JingleS5BTransportPayload>();
86 JingleIBBTransportPayload::ref ibbTransport = initialContent->getTransport<JingleIBBTransportPayload>(); 86 JingleIBBTransportPayload::ref ibbTransport = initialContent->getTransport<JingleIBBTransportPayload>();
87 if (s5bTransport) { 87 if (s5bTransport) {
88 SWIFT_LOG(debug) << "Got S5B transport as initial payload." << std::endl; 88 SWIFT_LOG(debug) << "Got S5B transport as initial payload.";
89 setTransporter(transporterFactory->createResponderTransporter( 89 setTransporter(transporterFactory->createResponderTransporter(
90 getInitiator(), getResponder(), s5bTransport->getSessionID(), options)); 90 getInitiator(), getResponder(), s5bTransport->getSessionID(), options));
91 transporter->addRemoteCandidates(s5bTransport->getCandidates(), s5bTransport->getDstAddr()); 91 transporter->addRemoteCandidates(s5bTransport->getCandidates(), s5bTransport->getDstAddr());
@@ -93,7 +93,7 @@ void IncomingJingleFileTransfer::accept(
93 transporter->startGeneratingLocalCandidates(); 93 transporter->startGeneratingLocalCandidates();
94 } 94 }
95 else if (ibbTransport && options.isInBandAllowed()) { 95 else if (ibbTransport && options.isInBandAllowed()) {
96 SWIFT_LOG(debug) << "Got IBB transport as initial payload." << std::endl; 96 SWIFT_LOG(debug) << "Got IBB transport as initial payload.";
97 setTransporter(transporterFactory->createResponderTransporter( 97 setTransporter(transporterFactory->createResponderTransporter(
98 getInitiator(), getResponder(), ibbTransport->getSessionID(), options)); 98 getInitiator(), getResponder(), ibbTransport->getSessionID(), options));
99 99
@@ -112,7 +112,7 @@ void IncomingJingleFileTransfer::accept(
112} 112}
113 113
114void IncomingJingleFileTransfer::cancel() { 114void IncomingJingleFileTransfer::cancel() {
115 SWIFT_LOG(debug) << std::endl; 115 SWIFT_LOG(debug);
116 terminate(state == Initial ? JinglePayload::Reason::Decline : JinglePayload::Reason::Cancel); 116 terminate(state == Initial ? JinglePayload::Reason::Decline : JinglePayload::Reason::Cancel);
117} 117}
118 118
@@ -120,8 +120,8 @@ void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
120 const std::string& s5bSessionID, 120 const std::string& s5bSessionID,
121 const std::vector<JingleS5BTransportPayload::Candidate>& candidates, 121 const std::vector<JingleS5BTransportPayload::Candidate>& candidates,
122 const std::string& dstAddr) { 122 const std::string& dstAddr) {
123 SWIFT_LOG(debug) << std::endl; 123 SWIFT_LOG(debug);
124 if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 124 if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state"; return; }
125 125
126 fillCandidateMap(localCandidates, candidates); 126 fillCandidateMap(localCandidates, candidates);
127 127
@@ -140,11 +140,11 @@ void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
140 140
141 141
142void IncomingJingleFileTransfer::handleSessionInfoReceived(JinglePayload::ref jinglePayload) { 142void IncomingJingleFileTransfer::handleSessionInfoReceived(JinglePayload::ref jinglePayload) {
143 SWIFT_LOG(debug) << std::endl; 143 SWIFT_LOG(debug);
144 144
145 JingleFileTransferHash::ref transferHash = jinglePayload->getPayload<JingleFileTransferHash>(); 145 JingleFileTransferHash::ref transferHash = jinglePayload->getPayload<JingleFileTransferHash>();
146 if (transferHash) { 146 if (transferHash) {
147 SWIFT_LOG(debug) << "Received hash information." << std::endl; 147 SWIFT_LOG(debug) << "Received hash information.";
148 waitOnHashTimer->stop(); 148 waitOnHashTimer->stop();
149 if (transferHash->getFileInfo().getHashes().find("sha-1") != transferHash->getFileInfo().getHashes().end()) { 149 if (transferHash->getFileInfo().getHashes().find("sha-1") != transferHash->getFileInfo().getHashes().end()) {
150 hashes["sha-1"] = transferHash->getFileInfo().getHash("sha-1").get(); 150 hashes["sha-1"] = transferHash->getFileInfo().getHash("sha-1").get();
@@ -157,16 +157,16 @@ void IncomingJingleFileTransfer::handleSessionInfoReceived(JinglePayload::ref ji
157 } 157 }
158 } 158 }
159 else { 159 else {
160 SWIFT_LOG(debug) << "Ignoring unknown session info" << std::endl; 160 SWIFT_LOG(debug) << "Ignoring unknown session info";
161 } 161 }
162} 162}
163 163
164void IncomingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) { 164void IncomingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) {
165 SWIFT_LOG(debug) << std::endl; 165 SWIFT_LOG(debug);
166 if (state == Finished) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 166 if (state == Finished) { SWIFT_LOG(warning) << "Incorrect state"; return; }
167 167
168 if (state == Finished) { 168 if (state == Finished) {
169 SWIFT_LOG(debug) << "Already terminated" << std::endl; 169 SWIFT_LOG(debug) << "Already terminated";
170 return; 170 return;
171 } 171 }
172 172
@@ -187,21 +187,21 @@ void IncomingJingleFileTransfer::checkHashAndTerminate() {
187 terminate(JinglePayload::Reason::Success); 187 terminate(JinglePayload::Reason::Success);
188 } 188 }
189 else { 189 else {
190 SWIFT_LOG(warning) << "Hash verification failed" << std::endl; 190 SWIFT_LOG(warning) << "Hash verification failed";
191 terminate(JinglePayload::Reason::MediaError); 191 terminate(JinglePayload::Reason::MediaError);
192 } 192 }
193} 193}
194 194
195void IncomingJingleFileTransfer::checkIfAllDataReceived() { 195void IncomingJingleFileTransfer::checkIfAllDataReceived() {
196 if (receivedBytes == getFileSizeInBytes()) { 196 if (receivedBytes == getFileSizeInBytes()) {
197 SWIFT_LOG(debug) << "All data received." << std::endl; 197 SWIFT_LOG(debug) << "All data received.";
198 bool hashInfoAvailable = false; 198 bool hashInfoAvailable = false;
199 for (const auto& hashElement : hashes) { 199 for (const auto& hashElement : hashes) {
200 hashInfoAvailable |= !hashElement.second.empty(); 200 hashInfoAvailable |= !hashElement.second.empty();
201 } 201 }
202 202
203 if (!hashInfoAvailable) { 203 if (!hashInfoAvailable) {
204 SWIFT_LOG(debug) << "No hash information yet. Waiting a while on hash info." << std::endl; 204 SWIFT_LOG(debug) << "No hash information yet. Waiting a while on hash info.";
205 setState(WaitingForHash); 205 setState(WaitingForHash);
206 waitOnHashTimer->start(); 206 waitOnHashTimer->start();
207 } 207 }
@@ -210,7 +210,7 @@ void IncomingJingleFileTransfer::checkIfAllDataReceived() {
210 } 210 }
211 } 211 }
212 else if (receivedBytes > getFileSizeInBytes()) { 212 else if (receivedBytes > getFileSizeInBytes()) {
213 SWIFT_LOG(debug) << "We got more than we could handle!" << std::endl; 213 SWIFT_LOG(debug) << "We got more than we could handle!";
214 terminate(JinglePayload::Reason::MediaError); 214 terminate(JinglePayload::Reason::MediaError);
215 } 215 }
216} 216}
@@ -225,15 +225,15 @@ void IncomingJingleFileTransfer::handleWriteStreamDataReceived(
225 225
226void IncomingJingleFileTransfer::handleTransportReplaceReceived( 226void IncomingJingleFileTransfer::handleTransportReplaceReceived(
227 const JingleContentID& content, JingleTransportPayload::ref transport) { 227 const JingleContentID& content, JingleTransportPayload::ref transport) {
228 SWIFT_LOG(debug) << std::endl; 228 SWIFT_LOG(debug);
229 if (state != WaitingForFallbackOrTerminate) { 229 if (state != WaitingForFallbackOrTerminate) {
230 SWIFT_LOG(warning) << "Incorrect state" << std::endl; 230 SWIFT_LOG(warning) << "Incorrect state";
231 return; 231 return;
232 } 232 }
233 233
234 JingleIBBTransportPayload::ref ibbTransport; 234 JingleIBBTransportPayload::ref ibbTransport;
235 if (options.isInBandAllowed() && (ibbTransport = std::dynamic_pointer_cast<JingleIBBTransportPayload>(transport))) { 235 if (options.isInBandAllowed() && (ibbTransport = std::dynamic_pointer_cast<JingleIBBTransportPayload>(transport))) {
236 SWIFT_LOG(debug) << "transport replaced with IBB" << std::endl; 236 SWIFT_LOG(debug) << "transport replaced with IBB";
237 237
238 startTransferring(transporter->createIBBReceiveSession( 238 startTransferring(transporter->createIBBReceiveSession(
239 ibbTransport->getSessionID(), 239 ibbTransport->getSessionID(),
@@ -242,7 +242,7 @@ void IncomingJingleFileTransfer::handleTransportReplaceReceived(
242 session->sendTransportAccept(content, ibbTransport); 242 session->sendTransportAccept(content, ibbTransport);
243 } 243 }
244 else { 244 else {
245 SWIFT_LOG(debug) << "Unknown replace transport" << std::endl; 245 SWIFT_LOG(debug) << "Unknown replace transport";
246 session->sendTransportReject(content, transport); 246 session->sendTransportReject(content, transport);
247 } 247 }
248} 248}
@@ -253,25 +253,25 @@ JingleContentID IncomingJingleFileTransfer::getContentID() const {
253 253
254bool IncomingJingleFileTransfer::verifyData() { 254bool IncomingJingleFileTransfer::verifyData() {
255 if (hashes.empty()) { 255 if (hashes.empty()) {
256 SWIFT_LOG(debug) << "no verification possible, skipping" << std::endl; 256 SWIFT_LOG(debug) << "no verification possible, skipping";
257 return true; 257 return true;
258 } 258 }
259 if (hashes.find("sha-1") != hashes.end()) { 259 if (hashes.find("sha-1") != hashes.end()) {
260 SWIFT_LOG(debug) << "Verify SHA-1 hash: " << (hashes["sha-1"] == hashCalculator->getSHA1Hash()) << std::endl; 260 SWIFT_LOG(debug) << "Verify SHA-1 hash: " << (hashes["sha-1"] == hashCalculator->getSHA1Hash());
261 return hashes["sha-1"] == hashCalculator->getSHA1Hash(); 261 return hashes["sha-1"] == hashCalculator->getSHA1Hash();
262 } 262 }
263 else if (hashes.find("md5") != hashes.end()) { 263 else if (hashes.find("md5") != hashes.end()) {
264 SWIFT_LOG(debug) << "Verify MD5 hash: " << (hashes["md5"] == hashCalculator->getMD5Hash()) << std::endl; 264 SWIFT_LOG(debug) << "Verify MD5 hash: " << (hashes["md5"] == hashCalculator->getMD5Hash());
265 return hashes["md5"] == hashCalculator->getMD5Hash(); 265 return hashes["md5"] == hashCalculator->getMD5Hash();
266 } 266 }
267 else { 267 else {
268 SWIFT_LOG(debug) << "Unknown hash, skipping" << std::endl; 268 SWIFT_LOG(debug) << "Unknown hash, skipping";
269 return true; 269 return true;
270 } 270 }
271} 271}
272 272
273void IncomingJingleFileTransfer::handleWaitOnHashTimerTicked() { 273void IncomingJingleFileTransfer::handleWaitOnHashTimerTicked() {
274 SWIFT_LOG(debug) << std::endl; 274 SWIFT_LOG(debug);
275 waitOnHashTimer->stop(); 275 waitOnHashTimer->stop();
276 terminate(JinglePayload::Reason::Success); 276 terminate(JinglePayload::Reason::Success);
277} 277}
@@ -285,14 +285,14 @@ const JID& IncomingJingleFileTransfer::getRecipient() const {
285} 285}
286 286
287void IncomingJingleFileTransfer::setState(State state) { 287void IncomingJingleFileTransfer::setState(State state) {
288 SWIFT_LOG(debug) << state << std::endl; 288 SWIFT_LOG(debug) << state;
289 this->state = state; 289 this->state = state;
290 onStateChanged(FileTransfer::State(getExternalState(state))); 290 onStateChanged(FileTransfer::State(getExternalState(state)));
291} 291}
292 292
293void IncomingJingleFileTransfer::setFinishedState( 293void IncomingJingleFileTransfer::setFinishedState(
294 FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) { 294 FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) {
295 SWIFT_LOG(debug) << std::endl; 295 SWIFT_LOG(debug);
296 this->state = Finished; 296 this->state = Finished;
297 onStateChanged(type); 297 onStateChanged(type);
298 onFinished(error); 298 onFinished(error);
@@ -340,7 +340,7 @@ void IncomingJingleFileTransfer::stopAll() {
340 transportSession->stop(); 340 transportSession->stop();
341 transportSession.reset(); 341 transportSession.reset();
342 break; 342 break;
343 case Finished: SWIFT_LOG(warning) << "Already finished" << std::endl; break; 343 case Finished: SWIFT_LOG(warning) << "Already finished"; break;
344 } 344 }
345 if (state != Initial) { 345 if (state != Initial) {
346 removeTransporter(); 346 removeTransporter();
@@ -356,7 +356,7 @@ void IncomingJingleFileTransfer::fallback() {
356} 356}
357 357
358void IncomingJingleFileTransfer::startTransferViaRemoteCandidate() { 358void IncomingJingleFileTransfer::startTransferViaRemoteCandidate() {
359 SWIFT_LOG(debug) << std::endl; 359 SWIFT_LOG(debug);
360 360
361 if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { 361 if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
362 setState(WaitingForPeerProxyActivate); 362 setState(WaitingForPeerProxyActivate);
@@ -367,7 +367,7 @@ void IncomingJingleFileTransfer::startTransferViaRemoteCandidate() {
367} 367}
368 368
369void IncomingJingleFileTransfer::startTransferViaLocalCandidate() { 369void IncomingJingleFileTransfer::startTransferViaLocalCandidate() {
370 SWIFT_LOG(debug) << std::endl; 370 SWIFT_LOG(debug);
371 371
372 if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { 372 if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
373 setState(WaitingForLocalProxyActivate); 373 setState(WaitingForLocalProxyActivate);
@@ -379,7 +379,7 @@ void IncomingJingleFileTransfer::startTransferViaLocalCandidate() {
379} 379}
380 380
381void IncomingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSession> transportSession) { 381void IncomingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSession> transportSession) {
382 SWIFT_LOG(debug) << std::endl; 382 SWIFT_LOG(debug);
383 383
384 this->transportSession = transportSession; 384 this->transportSession = transportSession;
385 transferFinishedConnection = transportSession->onFinished.connect( 385 transferFinishedConnection = transportSession->onFinished.connect(
@@ -409,7 +409,7 @@ std::shared_ptr<TransportSession> IncomingJingleFileTransfer::createRemoteCandid
409} 409}
410 410
411void IncomingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) { 411void IncomingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) {
412 SWIFT_LOG(debug) << reason << std::endl; 412 SWIFT_LOG(debug) << reason;
413 413
414 if (state != Finished) { 414 if (state != Finished) {
415 session->sendTerminate(reason); 415 session->sendTerminate(reason);