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,8 +1,8 @@
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2019 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/FileTransfer/IncomingJingleFileTransfer.h>
@@ -64,14 +64,14 @@ IncomingJingleFileTransfer::~IncomingJingleFileTransfer() {
hashCalculator = nullptr;
}
void IncomingJingleFileTransfer::accept(
std::shared_ptr<WriteBytestream> stream,
const FileTransferOptions& options) {
- SWIFT_LOG(debug) << std::endl;
- if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; }
+ SWIFT_LOG(debug);
+ if (state != Initial) { SWIFT_LOG(warning) << "Incorrect state"; return; }
assert(!this->stream);
this->stream = stream;
this->options = options;
assert(!hashCalculator);
@@ -82,21 +82,21 @@ void IncomingJingleFileTransfer::accept(
writeStreamDataReceivedConnection = stream->onWrite.connect(
boost::bind(&IncomingJingleFileTransfer::handleWriteStreamDataReceived, this, _1));
JingleS5BTransportPayload::ref s5bTransport = initialContent->getTransport<JingleS5BTransportPayload>();
JingleIBBTransportPayload::ref ibbTransport = initialContent->getTransport<JingleIBBTransportPayload>();
if (s5bTransport) {
- SWIFT_LOG(debug) << "Got S5B transport as initial payload." << std::endl;
+ SWIFT_LOG(debug) << "Got S5B transport as initial payload.";
setTransporter(transporterFactory->createResponderTransporter(
getInitiator(), getResponder(), s5bTransport->getSessionID(), options));
transporter->addRemoteCandidates(s5bTransport->getCandidates(), s5bTransport->getDstAddr());
setState(GeneratingInitialLocalCandidates);
transporter->startGeneratingLocalCandidates();
}
else if (ibbTransport && options.isInBandAllowed()) {
- SWIFT_LOG(debug) << "Got IBB transport as initial payload." << std::endl;
+ SWIFT_LOG(debug) << "Got IBB transport as initial payload.";
setTransporter(transporterFactory->createResponderTransporter(
getInitiator(), getResponder(), ibbTransport->getSessionID(), options));
startTransferring(transporter->createIBBReceiveSession(
ibbTransport->getSessionID(),
description->getFileInfo().getSize(),
@@ -109,22 +109,22 @@ void IncomingJingleFileTransfer::accept(
session->sendTerminate(JinglePayload::Reason::UnsupportedTransports);
setFinishedState(FileTransfer::State::Failed, FileTransferError(FileTransferError::PeerError));
}
}
void IncomingJingleFileTransfer::cancel() {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
terminate(state == Initial ? JinglePayload::Reason::Decline : JinglePayload::Reason::Cancel);
}
void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
const std::string& s5bSessionID,
const std::vector<JingleS5BTransportPayload::Candidate>& candidates,
const std::string& dstAddr) {
- SWIFT_LOG(debug) << std::endl;
- if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; }
+ SWIFT_LOG(debug);
+ if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state"; return; }
fillCandidateMap(localCandidates, candidates);
JingleS5BTransportPayload::ref transport = std::make_shared<JingleS5BTransportPayload>();
transport->setSessionID(s5bSessionID);
transport->setMode(JingleS5BTransportPayload::TCPMode);
@@ -137,39 +137,39 @@ void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
setState(TryingCandidates);
transporter->startTryingRemoteCandidates();
}
void IncomingJingleFileTransfer::handleSessionInfoReceived(JinglePayload::ref jinglePayload) {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
JingleFileTransferHash::ref transferHash = jinglePayload->getPayload<JingleFileTransferHash>();
if (transferHash) {
- SWIFT_LOG(debug) << "Received hash information." << std::endl;
+ SWIFT_LOG(debug) << "Received hash information.";
waitOnHashTimer->stop();
if (transferHash->getFileInfo().getHashes().find("sha-1") != transferHash->getFileInfo().getHashes().end()) {
hashes["sha-1"] = transferHash->getFileInfo().getHash("sha-1").get();
}
if (transferHash->getFileInfo().getHashes().find("md5") != transferHash->getFileInfo().getHashes().end()) {
hashes["md5"] = transferHash->getFileInfo().getHash("md5").get();
}
if (state == WaitingForHash) {
checkHashAndTerminate();
}
}
else {
- SWIFT_LOG(debug) << "Ignoring unknown session info" << std::endl;
+ SWIFT_LOG(debug) << "Ignoring unknown session info";
}
}
void IncomingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) {
- SWIFT_LOG(debug) << std::endl;
- if (state == Finished) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; }
+ SWIFT_LOG(debug);
+ if (state == Finished) { SWIFT_LOG(warning) << "Incorrect state"; return; }
if (state == Finished) {
- SWIFT_LOG(debug) << "Already terminated" << std::endl;
+ SWIFT_LOG(debug) << "Already terminated";
return;
}
stopAll();
if (reason && reason->type == JinglePayload::Reason::Cancel) {
setFinishedState(FileTransfer::State::Canceled, FileTransferError(FileTransferError::PeerError));
@@ -184,36 +184,36 @@ void IncomingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<
void IncomingJingleFileTransfer::checkHashAndTerminate() {
if (verifyData()) {
terminate(JinglePayload::Reason::Success);
}
else {
- SWIFT_LOG(warning) << "Hash verification failed" << std::endl;
+ SWIFT_LOG(warning) << "Hash verification failed";
terminate(JinglePayload::Reason::MediaError);
}
}
void IncomingJingleFileTransfer::checkIfAllDataReceived() {
if (receivedBytes == getFileSizeInBytes()) {
- SWIFT_LOG(debug) << "All data received." << std::endl;
+ SWIFT_LOG(debug) << "All data received.";
bool hashInfoAvailable = false;
for (const auto& hashElement : hashes) {
hashInfoAvailable |= !hashElement.second.empty();
}
if (!hashInfoAvailable) {
- SWIFT_LOG(debug) << "No hash information yet. Waiting a while on hash info." << std::endl;
+ SWIFT_LOG(debug) << "No hash information yet. Waiting a while on hash info.";
setState(WaitingForHash);
waitOnHashTimer->start();
}
else {
checkHashAndTerminate();
}
}
else if (receivedBytes > getFileSizeInBytes()) {
- SWIFT_LOG(debug) << "We got more than we could handle!" << std::endl;
+ SWIFT_LOG(debug) << "We got more than we could handle!";
terminate(JinglePayload::Reason::MediaError);
}
}
void IncomingJingleFileTransfer::handleWriteStreamDataReceived(
const std::vector<unsigned char>& data) {
@@ -222,59 +222,59 @@ void IncomingJingleFileTransfer::handleWriteStreamDataReceived(
onProcessedBytes(data.size());
checkIfAllDataReceived();
}
void IncomingJingleFileTransfer::handleTransportReplaceReceived(
const JingleContentID& content, JingleTransportPayload::ref transport) {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
if (state != WaitingForFallbackOrTerminate) {
- SWIFT_LOG(warning) << "Incorrect state" << std::endl;
+ SWIFT_LOG(warning) << "Incorrect state";
return;
}
JingleIBBTransportPayload::ref ibbTransport;
if (options.isInBandAllowed() && (ibbTransport = std::dynamic_pointer_cast<JingleIBBTransportPayload>(transport))) {
- SWIFT_LOG(debug) << "transport replaced with IBB" << std::endl;
+ SWIFT_LOG(debug) << "transport replaced with IBB";
startTransferring(transporter->createIBBReceiveSession(
ibbTransport->getSessionID(),
description->getFileInfo().getSize(),
stream));
session->sendTransportAccept(content, ibbTransport);
}
else {
- SWIFT_LOG(debug) << "Unknown replace transport" << std::endl;
+ SWIFT_LOG(debug) << "Unknown replace transport";
session->sendTransportReject(content, transport);
}
}
JingleContentID IncomingJingleFileTransfer::getContentID() const {
return JingleContentID(initialContent->getName(), initialContent->getCreator());
}
bool IncomingJingleFileTransfer::verifyData() {
if (hashes.empty()) {
- SWIFT_LOG(debug) << "no verification possible, skipping" << std::endl;
+ SWIFT_LOG(debug) << "no verification possible, skipping";
return true;
}
if (hashes.find("sha-1") != hashes.end()) {
- SWIFT_LOG(debug) << "Verify SHA-1 hash: " << (hashes["sha-1"] == hashCalculator->getSHA1Hash()) << std::endl;
+ SWIFT_LOG(debug) << "Verify SHA-1 hash: " << (hashes["sha-1"] == hashCalculator->getSHA1Hash());
return hashes["sha-1"] == hashCalculator->getSHA1Hash();
}
else if (hashes.find("md5") != hashes.end()) {
- SWIFT_LOG(debug) << "Verify MD5 hash: " << (hashes["md5"] == hashCalculator->getMD5Hash()) << std::endl;
+ SWIFT_LOG(debug) << "Verify MD5 hash: " << (hashes["md5"] == hashCalculator->getMD5Hash());
return hashes["md5"] == hashCalculator->getMD5Hash();
}
else {
- SWIFT_LOG(debug) << "Unknown hash, skipping" << std::endl;
+ SWIFT_LOG(debug) << "Unknown hash, skipping";
return true;
}
}
void IncomingJingleFileTransfer::handleWaitOnHashTimerTicked() {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
waitOnHashTimer->stop();
terminate(JinglePayload::Reason::Success);
}
const JID& IncomingJingleFileTransfer::getSender() const {
return getInitiator();
@@ -282,20 +282,20 @@ const JID& IncomingJingleFileTransfer::getSender() const {
const JID& IncomingJingleFileTransfer::getRecipient() const {
return getResponder();
}
void IncomingJingleFileTransfer::setState(State state) {
- SWIFT_LOG(debug) << state << std::endl;
+ SWIFT_LOG(debug) << state;
this->state = state;
onStateChanged(FileTransfer::State(getExternalState(state)));
}
void IncomingJingleFileTransfer::setFinishedState(
FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
this->state = Finished;
onStateChanged(type);
onFinished(error);
}
void IncomingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) {
@@ -337,13 +337,13 @@ void IncomingJingleFileTransfer::stopAll() {
case Transferring:
assert(transportSession);
transferFinishedConnection.disconnect();
transportSession->stop();
transportSession.reset();
break;
- case Finished: SWIFT_LOG(warning) << "Already finished" << std::endl; break;
+ case Finished: SWIFT_LOG(warning) << "Already finished"; break;
}
if (state != Initial) {
removeTransporter();
}
}
@@ -353,36 +353,36 @@ bool IncomingJingleFileTransfer::hasPriorityOnCandidateTie() const {
void IncomingJingleFileTransfer::fallback() {
setState(WaitingForFallbackOrTerminate);
}
void IncomingJingleFileTransfer::startTransferViaRemoteCandidate() {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
setState(WaitingForPeerProxyActivate);
}
else {
startTransferring(createRemoteCandidateSession());
}
}
void IncomingJingleFileTransfer::startTransferViaLocalCandidate() {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
setState(WaitingForLocalProxyActivate);
transporter->startActivatingProxy(theirCandidateChoice->jid);
}
else {
startTransferring(createLocalCandidateSession());
}
}
void IncomingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSession> transportSession) {
- SWIFT_LOG(debug) << std::endl;
+ SWIFT_LOG(debug);
this->transportSession = transportSession;
transferFinishedConnection = transportSession->onFinished.connect(
boost::bind(&IncomingJingleFileTransfer::handleTransferFinished, this, _1));
setState(Transferring);
transportSession->start();
@@ -406,13 +406,13 @@ std::shared_ptr<TransportSession> IncomingJingleFileTransfer::createLocalCandida
std::shared_ptr<TransportSession> IncomingJingleFileTransfer::createRemoteCandidateSession() {
return transporter->createRemoteCandidateSession(stream, ourCandidateChoice.get());
}
void IncomingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) {
- SWIFT_LOG(debug) << reason << std::endl;
+ SWIFT_LOG(debug) << reason;
if (state != Finished) {
session->sendTerminate(reason);
}
stopAll();
setFinishedState(getExternalFinishedState(reason), getFileTransferError(reason));