summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/FileTransfer')
-rw-r--r--Swiften/FileTransfer/DefaultFileTransferTransporter.cpp12
-rw-r--r--Swiften/FileTransfer/FailingTransportSession.cpp4
-rw-r--r--Swiften/FileTransfer/FileTransferManagerImpl.cpp4
-rw-r--r--Swiften/FileTransfer/IncomingJingleFileTransfer.cpp68
-rw-r--r--Swiften/FileTransfer/JingleFileTransfer.cpp50
-rw-r--r--Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp6
-rw-r--r--Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp62
-rw-r--r--Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp8
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp34
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp12
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp6
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp30
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp24
-rw-r--r--Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp6
14 files changed, 163 insertions, 163 deletions
diff --git a/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp b/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp
index c6987c0..ae3d7e0 100644
--- a/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp
+++ b/Swiften/FileTransfer/DefaultFileTransferTransporter.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2013-2016 Isode Limited. 2 * Copyright (c) 2013-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 */
@@ -133,7 +133,7 @@ void DefaultFileTransferTransporter::handleActivateProxySessionResult(const std:
133 133
134void DefaultFileTransferTransporter::startActivatingProxy(const JID& proxyServiceJID) { 134void DefaultFileTransferTransporter::startActivatingProxy(const JID& proxyServiceJID) {
135 // activate proxy 135 // activate proxy
136 SWIFT_LOG(debug) << "Start activating proxy " << proxyServiceJID.toString() << " with sid = " << s5bSessionID << "." << std::endl; 136 SWIFT_LOG(debug) << "Start activating proxy " << proxyServiceJID.toString() << " with sid = " << s5bSessionID << ".";
137 S5BProxyRequest::ref proxyRequest = std::make_shared<S5BProxyRequest>(); 137 S5BProxyRequest::ref proxyRequest = std::make_shared<S5BProxyRequest>();
138 proxyRequest->setSID(s5bSessionID); 138 proxyRequest->setSID(s5bSessionID);
139 proxyRequest->setActivate(role == Initiator ? responder : initiator); 139 proxyRequest->setActivate(role == Initiator ? responder : initiator);
@@ -207,7 +207,7 @@ std::shared_ptr<TransportSession> DefaultFileTransferTransporter::createLocalCan
207 transportSession = std::make_shared<S5BTransportSession<SOCKS5BytestreamClientSession> >(proxySession, stream); 207 transportSession = std::make_shared<S5BTransportSession<SOCKS5BytestreamClientSession> >(proxySession, stream);
208 } 208 }
209 else { 209 else {
210 SWIFT_LOG(error) << "Failed obtaining proxy session with candidate JID " << candidate.jid << " and dstAddr " << getLocalCandidateSOCKS5DstAddr() << "." << std::endl; 210 SWIFT_LOG(error) << "Failed obtaining proxy session with candidate JID " << candidate.jid << " and dstAddr " << getLocalCandidateSOCKS5DstAddr() << ".";
211 } 211 }
212 } 212 }
213 213
@@ -234,7 +234,7 @@ std::shared_ptr<TransportSession> DefaultFileTransferTransporter::createLocalCan
234 transportSession = std::make_shared<S5BTransportSession<SOCKS5BytestreamClientSession> >(proxySession, stream); 234 transportSession = std::make_shared<S5BTransportSession<SOCKS5BytestreamClientSession> >(proxySession, stream);
235 } 235 }
236 else { 236 else {
237 SWIFT_LOG(error) << "Failed obtaining proxy session with candidate JID " << candidate.jid << " and dstAddr " << getLocalCandidateSOCKS5DstAddr() << "." << std::endl; 237 SWIFT_LOG(error) << "Failed obtaining proxy session with candidate JID " << candidate.jid << " and dstAddr " << getLocalCandidateSOCKS5DstAddr() << ".";
238 } 238 }
239 } 239 }
240 240
@@ -255,11 +255,11 @@ std::string DefaultFileTransferTransporter::getSOCKS5DstAddr() const {
255 std::string result; 255 std::string result;
256 if (role == Initiator) { 256 if (role == Initiator) {
257 result = getInitiatorCandidateSOCKS5DstAddr(); 257 result = getInitiatorCandidateSOCKS5DstAddr();
258 SWIFT_LOG(debug) << "Initiator S5B DST.ADDR = " << s5bSessionID << " + " << initiator.toString() << " + " << responder.toString() << " : " << result << std::endl; 258 SWIFT_LOG(debug) << "Initiator S5B DST.ADDR = " << s5bSessionID << " + " << initiator.toString() << " + " << responder.toString() << " : " << result;
259 } 259 }
260 else { 260 else {
261 result = getResponderCandidateSOCKS5DstAddr(); 261 result = getResponderCandidateSOCKS5DstAddr();
262 SWIFT_LOG(debug) << "Responder S5B DST.ADDR = " << s5bSessionID << " + " << responder.toString() << " + " << initiator.toString() << " : " << result << std::endl; 262 SWIFT_LOG(debug) << "Responder S5B DST.ADDR = " << s5bSessionID << " + " << responder.toString() << " + " << initiator.toString() << " : " << result;
263 } 263 }
264 return result; 264 return result;
265} 265}
diff --git a/Swiften/FileTransfer/FailingTransportSession.cpp b/Swiften/FileTransfer/FailingTransportSession.cpp
index d1eb6a6..b9c79a0 100644
--- a/Swiften/FileTransfer/FailingTransportSession.cpp
+++ b/Swiften/FileTransfer/FailingTransportSession.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2016 Isode Limited. 2 * Copyright (c) 2016-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 */
@@ -14,7 +14,7 @@ FailingTransportSession::~FailingTransportSession() {
14} 14}
15 15
16void FailingTransportSession::start() { 16void FailingTransportSession::start() {
17 SWIFT_LOG(error) << "Trying to start failing transport." << std::endl; 17 SWIFT_LOG(error) << "Trying to start failing transport.";
18 onFinished(FileTransferError(FileTransferError::PeerError)); 18 onFinished(FileTransferError(FileTransferError::PeerError));
19} 19}
20 20
diff --git a/Swiften/FileTransfer/FileTransferManagerImpl.cpp b/Swiften/FileTransfer/FileTransferManagerImpl.cpp
index 05dd3bb..98eb50e 100644
--- a/Swiften/FileTransfer/FileTransferManagerImpl.cpp
+++ b/Swiften/FileTransfer/FileTransferManagerImpl.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 */
@@ -156,7 +156,7 @@ OutgoingFileTransfer::ref FileTransferManagerImpl::createOutgoingFileTransfer(
156 } 156 }
157 } 157 }
158 else { 158 else {
159 SWIFT_LOG(warning) << "No entity capabilities information for " << receipient.toString() << std::endl; 159 SWIFT_LOG(warning) << "No entity capabilities information for " << receipient.toString();
160 } 160 }
161 161
162 return outgoingFTManager->createOutgoingFileTransfer(iqRouter->getJID(), receipient, bytestream, fileInfo, options); 162 return outgoingFTManager->createOutgoingFileTransfer(iqRouter->getJID(), receipient, bytestream, fileInfo, options);
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);
diff --git a/Swiften/FileTransfer/JingleFileTransfer.cpp b/Swiften/FileTransfer/JingleFileTransfer.cpp
index cc1cd1c..3d05db9 100644
--- a/Swiften/FileTransfer/JingleFileTransfer.cpp
+++ b/Swiften/FileTransfer/JingleFileTransfer.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2013-2018 Isode Limited. 2 * Copyright (c) 2013-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 */
@@ -78,7 +78,7 @@ boost::optional<FileTransferError> JingleFileTransfer::getFileTransferError(Jing
78 78
79void JingleFileTransfer::handleRemoteTransportCandidateSelectFinished( 79void JingleFileTransfer::handleRemoteTransportCandidateSelectFinished(
80 const std::string& s5bSessionID, const boost::optional<JingleS5BTransportPayload::Candidate>& candidate) { 80 const std::string& s5bSessionID, const boost::optional<JingleS5BTransportPayload::Candidate>& candidate) {
81 SWIFT_LOG(debug) << std::endl; 81 SWIFT_LOG(debug);
82 82
83 ourCandidateChoice = candidate; 83 ourCandidateChoice = candidate;
84 ourCandidateSelectFinished = true; 84 ourCandidateSelectFinished = true;
@@ -98,42 +98,42 @@ void JingleFileTransfer::handleRemoteTransportCandidateSelectFinished(
98 98
99// decide on candidates according to http://xmpp.org/extensions/xep-0260.html#complete 99// decide on candidates according to http://xmpp.org/extensions/xep-0260.html#complete
100void JingleFileTransfer::decideOnCandidates() { 100void JingleFileTransfer::decideOnCandidates() {
101 SWIFT_LOG(debug) << std::endl; 101 SWIFT_LOG(debug);
102 if (!ourCandidateSelectFinished || !theirCandidateSelectFinished) { 102 if (!ourCandidateSelectFinished || !theirCandidateSelectFinished) {
103 SWIFT_LOG(debug) << "Can't make a decision yet!" << std::endl; 103 SWIFT_LOG(debug) << "Can't make a decision yet!";
104 return; 104 return;
105 } 105 }
106 if (!ourCandidateChoice && !theirCandidateChoice) { 106 if (!ourCandidateChoice && !theirCandidateChoice) {
107 SWIFT_LOG(debug) << "No candidates succeeded." << std::endl; 107 SWIFT_LOG(debug) << "No candidates succeeded.";
108 fallback(); 108 fallback();
109 } 109 }
110 else if (ourCandidateChoice && !theirCandidateChoice) { 110 else if (ourCandidateChoice && !theirCandidateChoice) {
111 SWIFT_LOG(debug) << "Start transfer using remote candidate: " << ourCandidateChoice.get().cid << "." << std::endl; 111 SWIFT_LOG(debug) << "Start transfer using remote candidate: " << ourCandidateChoice.get().cid << ".";
112 startTransferViaRemoteCandidate(); 112 startTransferViaRemoteCandidate();
113 } 113 }
114 else if (theirCandidateChoice && !ourCandidateChoice) { 114 else if (theirCandidateChoice && !ourCandidateChoice) {
115 SWIFT_LOG(debug) << "Start transfer using local candidate: " << theirCandidateChoice.get().cid << "." << std::endl; 115 SWIFT_LOG(debug) << "Start transfer using local candidate: " << theirCandidateChoice.get().cid << ".";
116 startTransferViaLocalCandidate(); 116 startTransferViaLocalCandidate();
117 } 117 }
118 else { 118 else {
119 SWIFT_LOG(debug) << "Choosing between candidates " 119 SWIFT_LOG(debug) << "Choosing between candidates "
120 << ourCandidateChoice->cid << "(" << ourCandidateChoice->priority << ")" << " and " 120 << ourCandidateChoice->cid << "(" << ourCandidateChoice->priority << ")" << " and "
121 << theirCandidateChoice->cid << "(" << theirCandidateChoice->priority << ")" << std::endl; 121 << theirCandidateChoice->cid << "(" << theirCandidateChoice->priority << ")";
122 if (ourCandidateChoice->priority > theirCandidateChoice->priority) { 122 if (ourCandidateChoice->priority > theirCandidateChoice->priority) {
123 SWIFT_LOG(debug) << "Start transfer using remote candidate: " << ourCandidateChoice.get().cid << "." << std::endl; 123 SWIFT_LOG(debug) << "Start transfer using remote candidate: " << ourCandidateChoice.get().cid << ".";
124 startTransferViaRemoteCandidate(); 124 startTransferViaRemoteCandidate();
125 } 125 }
126 else if (ourCandidateChoice->priority < theirCandidateChoice->priority) { 126 else if (ourCandidateChoice->priority < theirCandidateChoice->priority) {
127 SWIFT_LOG(debug) << "Start transfer using local candidate:" << theirCandidateChoice.get().cid << "." << std::endl; 127 SWIFT_LOG(debug) << "Start transfer using local candidate:" << theirCandidateChoice.get().cid << ".";
128 startTransferViaLocalCandidate(); 128 startTransferViaLocalCandidate();
129 } 129 }
130 else { 130 else {
131 if (hasPriorityOnCandidateTie()) { 131 if (hasPriorityOnCandidateTie()) {
132 SWIFT_LOG(debug) << "Start transfer using remote candidate: " << ourCandidateChoice.get().cid << std::endl; 132 SWIFT_LOG(debug) << "Start transfer using remote candidate: " << ourCandidateChoice.get().cid;
133 startTransferViaRemoteCandidate(); 133 startTransferViaRemoteCandidate();
134 } 134 }
135 else { 135 else {
136 SWIFT_LOG(debug) << "Start transfer using local candidate: " << theirCandidateChoice.get().cid << std::endl; 136 SWIFT_LOG(debug) << "Start transfer using local candidate: " << theirCandidateChoice.get().cid;
137 startTransferViaLocalCandidate(); 137 startTransferViaLocalCandidate();
138 } 138 }
139 } 139 }
@@ -142,11 +142,11 @@ void JingleFileTransfer::decideOnCandidates() {
142 142
143void JingleFileTransfer::handleProxyActivateFinished( 143void JingleFileTransfer::handleProxyActivateFinished(
144 const std::string& s5bSessionID, ErrorPayload::ref error) { 144 const std::string& s5bSessionID, ErrorPayload::ref error) {
145 SWIFT_LOG(debug) << std::endl; 145 SWIFT_LOG(debug);
146 if (!isWaitingForLocalProxyActivate()) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 146 if (!isWaitingForLocalProxyActivate()) { SWIFT_LOG(warning) << "Incorrect state"; return; }
147 147
148 if (error) { 148 if (error) {
149 SWIFT_LOG(debug) << "Error activating proxy" << std::endl; 149 SWIFT_LOG(debug) << "Error activating proxy";
150 JingleS5BTransportPayload::ref proxyError = std::make_shared<JingleS5BTransportPayload>(); 150 JingleS5BTransportPayload::ref proxyError = std::make_shared<JingleS5BTransportPayload>();
151 proxyError->setSessionID(s5bSessionID); 151 proxyError->setSessionID(s5bSessionID);
152 proxyError->setProxyError(true); 152 proxyError->setProxyError(true);
@@ -164,18 +164,18 @@ void JingleFileTransfer::handleProxyActivateFinished(
164 164
165void JingleFileTransfer::handleTransportInfoReceived( 165void JingleFileTransfer::handleTransportInfoReceived(
166 const JingleContentID& /* contentID */, JingleTransportPayload::ref transport) { 166 const JingleContentID& /* contentID */, JingleTransportPayload::ref transport) {
167 SWIFT_LOG(debug) << std::endl; 167 SWIFT_LOG(debug);
168 168
169 if (JingleS5BTransportPayload::ref s5bPayload = std::dynamic_pointer_cast<JingleS5BTransportPayload>(transport)) { 169 if (JingleS5BTransportPayload::ref s5bPayload = std::dynamic_pointer_cast<JingleS5BTransportPayload>(transport)) {
170 if (s5bPayload->hasCandidateError() || !s5bPayload->getCandidateUsed().empty()) { 170 if (s5bPayload->hasCandidateError() || !s5bPayload->getCandidateUsed().empty()) {
171 SWIFT_LOG(debug) << "Received candidate decision from peer" << std::endl; 171 SWIFT_LOG(debug) << "Received candidate decision from peer";
172 if (!isTryingCandidates()) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 172 if (!isTryingCandidates()) { SWIFT_LOG(warning) << "Incorrect state"; return; }
173 173
174 theirCandidateSelectFinished = true; 174 theirCandidateSelectFinished = true;
175 if (!s5bPayload->hasCandidateError()) { 175 if (!s5bPayload->hasCandidateError()) {
176 auto theirCandidate = localCandidates.find(s5bPayload->getCandidateUsed()); 176 auto theirCandidate = localCandidates.find(s5bPayload->getCandidateUsed());
177 if (theirCandidate == localCandidates.end()) { 177 if (theirCandidate == localCandidates.end()) {
178 SWIFT_LOG(warning) << "Got invalid candidate" << std::endl; 178 SWIFT_LOG(warning) << "Got invalid candidate";
179 terminate(JinglePayload::Reason::GeneralError); 179 terminate(JinglePayload::Reason::GeneralError);
180 return; 180 return;
181 } 181 }
@@ -184,27 +184,27 @@ void JingleFileTransfer::handleTransportInfoReceived(
184 decideOnCandidates(); 184 decideOnCandidates();
185 } 185 }
186 else if (!s5bPayload->getActivated().empty()) { 186 else if (!s5bPayload->getActivated().empty()) {
187 SWIFT_LOG(debug) << "Received peer activate from peer" << std::endl; 187 SWIFT_LOG(debug) << "Received peer activate from peer";
188 if (!isWaitingForPeerProxyActivate()) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 188 if (!isWaitingForPeerProxyActivate()) { SWIFT_LOG(warning) << "Incorrect state"; return; }
189 189
190 if (ourCandidateChoice->cid == s5bPayload->getActivated()) { 190 if (ourCandidateChoice->cid == s5bPayload->getActivated()) {
191 startTransferring(createRemoteCandidateSession()); 191 startTransferring(createRemoteCandidateSession());
192 } 192 }
193 else { 193 else {
194 SWIFT_LOG(warning) << "ourCandidateChoice doesn't match activated proxy candidate!" << std::endl; 194 SWIFT_LOG(warning) << "ourCandidateChoice doesn't match activated proxy candidate!";
195 terminate(JinglePayload::Reason::GeneralError); 195 terminate(JinglePayload::Reason::GeneralError);
196 } 196 }
197 } 197 }
198 else if (s5bPayload->hasProxyError()) { 198 else if (s5bPayload->hasProxyError()) {
199 SWIFT_LOG(debug) << "Received proxy error. Trying to fall back to IBB." << std::endl; 199 SWIFT_LOG(debug) << "Received proxy error. Trying to fall back to IBB.";
200 fallback(); 200 fallback();
201 } 201 }
202 else { 202 else {
203 SWIFT_LOG(debug) << "Ignoring unknown info" << std::endl; 203 SWIFT_LOG(debug) << "Ignoring unknown info";
204 } 204 }
205 } 205 }
206 else { 206 else {
207 SWIFT_LOG(debug) << "Ignoring unknown info" << std::endl; 207 SWIFT_LOG(debug) << "Ignoring unknown info";
208 } 208 }
209} 209}
210 210
diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp
index 834a401..7cb4cbb 100644
--- a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.cpp
+++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.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 */
@@ -45,7 +45,7 @@ LocalJingleTransportCandidateGenerator::LocalJingleTransportCandidateGenerator(
45} 45}
46 46
47LocalJingleTransportCandidateGenerator::~LocalJingleTransportCandidateGenerator() { 47LocalJingleTransportCandidateGenerator::~LocalJingleTransportCandidateGenerator() {
48 SWIFT_LOG_ASSERT(!s5bServerInitializeRequest, warning) << std::endl; 48 SWIFT_LOG_ASSERT(!s5bServerInitializeRequest, warning);
49} 49}
50 50
51void LocalJingleTransportCandidateGenerator::start() { 51void LocalJingleTransportCandidateGenerator::start() {
@@ -98,7 +98,7 @@ void LocalJingleTransportCandidateGenerator::handleS5BServerInitialized(bool suc
98 } 98 }
99 } 99 }
100 else { 100 else {
101 SWIFT_LOG(warning) << "Unable to start SOCKS5 server" << std::endl; 101 SWIFT_LOG(warning) << "Unable to start SOCKS5 server";
102 if (s5bServerResourceUser_) { 102 if (s5bServerResourceUser_) {
103 s5bServerResourceUser_->onSuccessfulInitialized.disconnect(boost::bind(&LocalJingleTransportCandidateGenerator::handleS5BServerInitialized, this, _1)); 103 s5bServerResourceUser_->onSuccessfulInitialized.disconnect(boost::bind(&LocalJingleTransportCandidateGenerator::handleS5BServerInitialized, this, _1));
104 } 104 }
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
89void OutgoingJingleFileTransfer::start() { 89void 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
111void OutgoingJingleFileTransfer::terminate(JinglePayload::Reason::Type reason) { 111void 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
142void OutgoingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) { 142void 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
164void OutgoingJingleFileTransfer::handleTransportAcceptReceived(const JingleContentID&, JingleTransportPayload::ref transport) { 164void 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
177void OutgoingJingleFileTransfer::handleTransportRejectReceived(const JingleContentID &, std::shared_ptr<JingleTransportPayload>) { 177void 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
183void OutgoingJingleFileTransfer::sendSessionInfoHash() { 183void 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
192void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( 192void 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
227void OutgoingJingleFileTransfer::fallback() { 227void 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
242void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) { 242void 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
258void OutgoingJingleFileTransfer::startTransferring(std::shared_ptr<TransportSession> transportSession) { 258void 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
271void OutgoingJingleFileTransfer::setInternalState(State state) { 271void 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
277void OutgoingJingleFileTransfer::setFinishedState( 277void 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
303void OutgoingJingleFileTransfer::stopAll() { 303void 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
330void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { 330void 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
342void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { 342void 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
401void OutgoingJingleFileTransfer::handleWaitForRemoteTerminationTimeout() { 401void 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}
diff --git a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp
index 56013ca..4023be3 100644
--- a/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.cpp
+++ b/Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.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 */
@@ -56,14 +56,14 @@ void RemoteJingleTransportCandidateSelector::stopSelectingCandidate() {
56 56
57void RemoteJingleTransportCandidateSelector::tryNextCandidate() { 57void RemoteJingleTransportCandidateSelector::tryNextCandidate() {
58 if (candidates.empty()) { 58 if (candidates.empty()) {
59 SWIFT_LOG(debug) << "No more candidates" << std::endl; 59 SWIFT_LOG(debug) << "No more candidates";
60 onCandidateSelectFinished( 60 onCandidateSelectFinished(
61 boost::optional<JingleS5BTransportPayload::Candidate>(), std::shared_ptr<SOCKS5BytestreamClientSession>()); 61 boost::optional<JingleS5BTransportPayload::Candidate>(), std::shared_ptr<SOCKS5BytestreamClientSession>());
62 } 62 }
63 else { 63 else {
64 lastCandidate = candidates.top(); 64 lastCandidate = candidates.top();
65 candidates.pop(); 65 candidates.pop();
66 SWIFT_LOG(debug) << "Trying candidate " << lastCandidate.cid << std::endl; 66 SWIFT_LOG(debug) << "Trying candidate " << lastCandidate.cid;
67 if ((lastCandidate.type == JingleS5BTransportPayload::Candidate::DirectType && options.isDirectAllowed()) || 67 if ((lastCandidate.type == JingleS5BTransportPayload::Candidate::DirectType && options.isDirectAllowed()) ||
68 (lastCandidate.type == JingleS5BTransportPayload::Candidate::AssistedType && options.isAssistedAllowed()) || 68 (lastCandidate.type == JingleS5BTransportPayload::Candidate::AssistedType && options.isAssistedAllowed()) ||
69 (lastCandidate.type == JingleS5BTransportPayload::Candidate::ProxyType && options.isProxiedAllowed())) { 69 (lastCandidate.type == JingleS5BTransportPayload::Candidate::ProxyType && options.isProxiedAllowed())) {
@@ -75,7 +75,7 @@ void RemoteJingleTransportCandidateSelector::tryNextCandidate() {
75 s5bSession->start(); 75 s5bSession->start();
76 } 76 }
77 else { 77 else {
78 SWIFT_LOG(debug) << "Can't handle this type of candidate" << std::endl; 78 SWIFT_LOG(debug) << "Can't handle this type of candidate";
79 tryNextCandidate(); 79 tryNextCandidate();
80 } 80 }
81 } 81 }
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
index 5ddd32b..a3f0dab 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.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 */
@@ -49,7 +49,7 @@ SOCKS5BytestreamClientSession::~SOCKS5BytestreamClientSession() {
49 49
50void SOCKS5BytestreamClientSession::start() { 50void SOCKS5BytestreamClientSession::start() {
51 assert(state == Initial); 51 assert(state == Initial);
52 SWIFT_LOG(debug) << "Trying to connect via TCP to " << addressPort.toString() << "." << std::endl; 52 SWIFT_LOG(debug) << "Trying to connect via TCP to " << addressPort.toString() << ".";
53 weFailedTimeout->start(); 53 weFailedTimeout->start();
54 connectFinishedConnection = connection->onConnectFinished.connect( 54 connectFinishedConnection = connection->onConnectFinished.connect(
55 boost::bind(&SOCKS5BytestreamClientSession::handleConnectFinished, this, _1)); 55 boost::bind(&SOCKS5BytestreamClientSession::handleConnectFinished, this, _1));
@@ -57,7 +57,7 @@ void SOCKS5BytestreamClientSession::start() {
57} 57}
58 58
59void SOCKS5BytestreamClientSession::stop() { 59void SOCKS5BytestreamClientSession::stop() {
60 SWIFT_LOG(debug) << std::endl; 60 SWIFT_LOG(debug);
61 if (state < Ready) { 61 if (state < Ready) {
62 weFailedTimeout->stop(); 62 weFailedTimeout->stop();
63 } 63 }
@@ -70,7 +70,7 @@ void SOCKS5BytestreamClientSession::stop() {
70} 70}
71 71
72void SOCKS5BytestreamClientSession::process() { 72void SOCKS5BytestreamClientSession::process() {
73 SWIFT_LOG(debug) << "unprocessedData.size(): " << unprocessedData.size() << std::endl; 73 SWIFT_LOG(debug) << "unprocessedData.size(): " << unprocessedData.size();
74 ByteArray bndAddress; 74 ByteArray bndAddress;
75 switch(state) { 75 switch(state) {
76 case Initial: 76 case Initial:
@@ -124,19 +124,19 @@ void SOCKS5BytestreamClientSession::process() {
124 } 124 }
125 unprocessedData.clear(); 125 unprocessedData.clear();
126 state = Ready; 126 state = Ready;
127 SWIFT_LOG(debug) << "session ready" << std::endl; 127 SWIFT_LOG(debug) << "session ready";
128 // issue ready signal so the bytestream can be used for reading or writing 128 // issue ready signal so the bytestream can be used for reading or writing
129 weFailedTimeout->stop(); 129 weFailedTimeout->stop();
130 onSessionReady(false); 130 onSessionReady(false);
131 break; 131 break;
132 case Ready: 132 case Ready:
133 SWIFT_LOG(debug) << "Received further data in Ready state." << std::endl; 133 SWIFT_LOG(debug) << "Received further data in Ready state.";
134 break; 134 break;
135 case Reading: 135 case Reading:
136 case Writing: 136 case Writing:
137 case Finished: 137 case Finished:
138 SWIFT_LOG(debug) << "Unexpected receive of data. Current state: " << state << std::endl; 138 SWIFT_LOG(debug) << "Unexpected receive of data. Current state: " << state;
139 SWIFT_LOG(debug) << "Data: " << Hexify::hexify(unprocessedData) << std::endl; 139 SWIFT_LOG(debug) << "Data: " << Hexify::hexify(unprocessedData);
140 unprocessedData.clear(); 140 unprocessedData.clear();
141 //assert(false); 141 //assert(false);
142 } 142 }
@@ -150,7 +150,7 @@ void SOCKS5BytestreamClientSession::hello() {
150} 150}
151 151
152void SOCKS5BytestreamClientSession::authenticate() { 152void SOCKS5BytestreamClientSession::authenticate() {
153 SWIFT_LOG(debug) << std::endl; 153 SWIFT_LOG(debug);
154 SafeByteArray header = createSafeByteArray("\x05\x01\x00\x03", 4); 154 SafeByteArray header = createSafeByteArray("\x05\x01\x00\x03", 4);
155 SafeByteArray message = header; 155 SafeByteArray message = header;
156 append(message, createSafeByteArray(boost::numeric_cast<char>(destination.size()))); 156 append(message, createSafeByteArray(boost::numeric_cast<char>(destination.size())));
@@ -168,7 +168,7 @@ void SOCKS5BytestreamClientSession::startReceiving(std::shared_ptr<WriteBytestre
168 writeBytestream->write(unprocessedData); 168 writeBytestream->write(unprocessedData);
169 unprocessedData.clear(); 169 unprocessedData.clear();
170 } else { 170 } else {
171 SWIFT_LOG(debug) << "Session isn't ready for transfer yet!" << std::endl; 171 SWIFT_LOG(debug) << "Session isn't ready for transfer yet!";
172 } 172 }
173} 173}
174 174
@@ -180,7 +180,7 @@ void SOCKS5BytestreamClientSession::startSending(std::shared_ptr<ReadBytestream>
180 boost::bind(&SOCKS5BytestreamClientSession::sendData, this)); 180 boost::bind(&SOCKS5BytestreamClientSession::sendData, this));
181 sendData(); 181 sendData();
182 } else { 182 } else {
183 SWIFT_LOG(debug) << "Session isn't ready for transfer yet!" << std::endl; 183 SWIFT_LOG(debug) << "Session isn't ready for transfer yet!";
184 } 184 }
185} 185}
186 186
@@ -205,7 +205,7 @@ void SOCKS5BytestreamClientSession::sendData() {
205} 205}
206 206
207void SOCKS5BytestreamClientSession::finish(bool error) { 207void SOCKS5BytestreamClientSession::finish(bool error) {
208 SWIFT_LOG(debug) << std::endl; 208 SWIFT_LOG(debug);
209 if (state < Ready) { 209 if (state < Ready) {
210 weFailedTimeout->stop(); 210 weFailedTimeout->stop();
211 } 211 }
@@ -227,10 +227,10 @@ void SOCKS5BytestreamClientSession::finish(bool error) {
227void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) { 227void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) {
228 connectFinishedConnection.disconnect(); 228 connectFinishedConnection.disconnect();
229 if (error) { 229 if (error) {
230 SWIFT_LOG(debug) << "Failed to connect via TCP to " << addressPort.toString() << "." << std::endl; 230 SWIFT_LOG(debug) << "Failed to connect via TCP to " << addressPort.toString() << ".";
231 finish(true); 231 finish(true);
232 } else { 232 } else {
233 SWIFT_LOG(debug) << "Successfully connected via TCP" << addressPort.toString() << "." << std::endl; 233 SWIFT_LOG(debug) << "Successfully connected via TCP" << addressPort.toString() << ".";
234 disconnectedConnection = connection->onDisconnected.connect( 234 disconnectedConnection = connection->onDisconnected.connect(
235 boost::bind(&SOCKS5BytestreamClientSession::handleDisconnected, this, _1)); 235 boost::bind(&SOCKS5BytestreamClientSession::handleDisconnected, this, _1));
236 dataReadConnection = connection->onDataRead.connect( 236 dataReadConnection = connection->onDataRead.connect(
@@ -242,7 +242,7 @@ void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) {
242} 242}
243 243
244void SOCKS5BytestreamClientSession::handleDataRead(std::shared_ptr<SafeByteArray> data) { 244void SOCKS5BytestreamClientSession::handleDataRead(std::shared_ptr<SafeByteArray> data) {
245 SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data->size() << std::endl; 245 SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data->size();
246 if (state != Reading) { 246 if (state != Reading) {
247 append(unprocessedData, *data); 247 append(unprocessedData, *data);
248 process(); 248 process();
@@ -254,14 +254,14 @@ void SOCKS5BytestreamClientSession::handleDataRead(std::shared_ptr<SafeByteArray
254} 254}
255 255
256void SOCKS5BytestreamClientSession::handleDisconnected(const boost::optional<Connection::Error>& error) { 256void SOCKS5BytestreamClientSession::handleDisconnected(const boost::optional<Connection::Error>& error) {
257 SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error") << std::endl; 257 SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error");
258 if (error) { 258 if (error) {
259 finish(true); 259 finish(true);
260 } 260 }
261} 261}
262 262
263void SOCKS5BytestreamClientSession::handleWeFailedTimeout() { 263void SOCKS5BytestreamClientSession::handleWeFailedTimeout() {
264 SWIFT_LOG(debug) << "Failed due to timeout!" << std::endl; 264 SWIFT_LOG(debug) << "Failed due to timeout!";
265 finish(true); 265 finish(true);
266} 266}
267 267
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp
index cd4cfaa..72c4d41 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-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 */
@@ -46,7 +46,7 @@ SOCKS5BytestreamProxiesManager::~SOCKS5BytestreamProxiesManager() {
46 46
47void SOCKS5BytestreamProxiesManager::addS5BProxy(S5BProxyRequest::ref proxy) { 47void SOCKS5BytestreamProxiesManager::addS5BProxy(S5BProxyRequest::ref proxy) {
48 if (proxy) { 48 if (proxy) {
49 SWIFT_LOG_ASSERT(HostAddress::fromString(proxy->getStreamHost().get().host), warning) << std::endl; 49 SWIFT_LOG_ASSERT(HostAddress::fromString(proxy->getStreamHost().get().host), warning);
50 if (!localS5BProxies_) { 50 if (!localS5BProxies_) {
51 localS5BProxies_ = std::vector<S5BProxyRequest::ref>(); 51 localS5BProxies_ = std::vector<S5BProxyRequest::ref>();
52 } 52 }
@@ -62,7 +62,7 @@ const boost::optional<std::vector<S5BProxyRequest::ref> >& SOCKS5BytestreamProxi
62} 62}
63 63
64void SOCKS5BytestreamProxiesManager::connectToProxies(const std::string& sessionID) { 64void SOCKS5BytestreamProxiesManager::connectToProxies(const std::string& sessionID) {
65 SWIFT_LOG(debug) << "session ID: " << sessionID << std::endl; 65 SWIFT_LOG(debug) << "session ID: " << sessionID;
66 ProxyJIDClientSessionVector clientSessions; 66 ProxyJIDClientSessionVector clientSessions;
67 67
68 if (localS5BProxies_) { 68 if (localS5BProxies_) {
@@ -71,7 +71,7 @@ void SOCKS5BytestreamProxiesManager::connectToProxies(const std::string& session
71 if (proxyHostAddress) { 71 if (proxyHostAddress) {
72 std::shared_ptr<Connection> conn = connectionFactory_->createConnection(); 72 std::shared_ptr<Connection> conn = connectionFactory_->createConnection();
73 HostAddressPort addressPort = HostAddressPort(proxyHostAddress.get(), proxy->getStreamHost().get().port); 73 HostAddressPort addressPort = HostAddressPort(proxyHostAddress.get(), proxy->getStreamHost().get().port);
74 SWIFT_LOG_ASSERT(addressPort.isValid(), warning) << std::endl; 74 SWIFT_LOG_ASSERT(addressPort.isValid(), warning);
75 std::shared_ptr<SOCKS5BytestreamClientSession> session = std::make_shared<SOCKS5BytestreamClientSession>(conn, addressPort, sessionID, timerFactory_); 75 std::shared_ptr<SOCKS5BytestreamClientSession> session = std::make_shared<SOCKS5BytestreamClientSession>(conn, addressPort, sessionID, timerFactory_);
76 JID proxyJid = proxy->getStreamHost().get().jid; 76 JID proxyJid = proxy->getStreamHost().get().jid;
77 clientSessions.push_back(std::pair<JID, std::shared_ptr<SOCKS5BytestreamClientSession> >(proxyJid, session)); 77 clientSessions.push_back(std::pair<JID, std::shared_ptr<SOCKS5BytestreamClientSession> >(proxyJid, session));
@@ -103,7 +103,7 @@ std::shared_ptr<SOCKS5BytestreamClientSession> SOCKS5BytestreamProxiesManager::g
103 i->second->stop(); 103 i->second->stop();
104 } 104 }
105 } 105 }
106 SWIFT_LOG_ASSERT(activeSession, warning) << "No active session with matching ID found." << std::endl; 106 SWIFT_LOG_ASSERT(activeSession, warning) << "No active session with matching ID found.";
107 107
108 proxySessions_.erase(sessionID); 108 proxySessions_.erase(sessionID);
109 109
@@ -144,7 +144,7 @@ void SOCKS5BytestreamProxiesManager::handleNameLookupResult(const std::vector<Ho
144 } 144 }
145 else { 145 else {
146 if (addresses.empty()) { 146 if (addresses.empty()) {
147 SWIFT_LOG(warning) << "S5B proxy hostname does not resolve." << std::endl; 147 SWIFT_LOG(warning) << "S5B proxy hostname does not resolve.";
148 } 148 }
149 else { 149 else {
150 // generate proxy per returned address 150 // generate proxy per returned address
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp
index 90c42dd..1efc54a 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamProxyFinder.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-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 */
@@ -71,10 +71,10 @@ void SOCKS5BytestreamProxyFinder::handleProxyResponse(std::shared_ptr<GenericReq
71 requester->onResponse.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, requester, _1, _2)); 71 requester->onResponse.disconnect(boost::bind(&SOCKS5BytestreamProxyFinder::handleProxyResponse, this, requester, _1, _2));
72 pendingRequests.erase(requester); 72 pendingRequests.erase(requester);
73 if (error) { 73 if (error) {
74 SWIFT_LOG(debug) << "ERROR" << std::endl; 74 SWIFT_LOG(debug) << "ERROR";
75 } else { 75 } else {
76 if (request) { 76 if (request) {
77 SWIFT_LOG(debug) << "add request" << std::endl; 77 SWIFT_LOG(debug) << "add request";
78 proxyHosts.push_back(request); 78 proxyHosts.push_back(request);
79 } 79 }
80 } 80 }
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
index a6b75da..7fc1388 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2018 Isode Limited. 2 * Copyright (c) 2012-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 */
@@ -48,12 +48,12 @@ SOCKS5BytestreamServerManager::SOCKS5BytestreamServerManager(
48} 48}
49 49
50SOCKS5BytestreamServerManager::~SOCKS5BytestreamServerManager() { 50SOCKS5BytestreamServerManager::~SOCKS5BytestreamServerManager() {
51 SWIFT_LOG_ASSERT(!connectionServer, warning) << std::endl; 51 SWIFT_LOG_ASSERT(!connectionServer, warning);
52 SWIFT_LOG_ASSERT(!getPublicIPRequest, warning) << std::endl; 52 SWIFT_LOG_ASSERT(!getPublicIPRequest, warning);
53 SWIFT_LOG_ASSERT(!forwardPortRequest, warning) << std::endl; 53 SWIFT_LOG_ASSERT(!forwardPortRequest, warning);
54 SWIFT_LOG_ASSERT(state == Start, warning) << std::endl; 54 SWIFT_LOG_ASSERT(state == Start, warning);
55 if (portMapping && !unforwardPortRequest) { 55 if (portMapping && !unforwardPortRequest) {
56 SWIFT_LOG(warning) << "Port forwarding still alive. Trying to remove it now." << std::endl; 56 SWIFT_LOG(warning) << "Port forwarding still alive. Trying to remove it now.";
57 unforwardPortRequest = natTraverser->createRemovePortForwardingRequest(portMapping.get().getLocalPort(), portMapping.get().getPublicPort()); 57 unforwardPortRequest = natTraverser->createRemovePortForwardingRequest(portMapping.get().getLocalPort(), portMapping.get().getPublicPort());
58 unforwardPortRequest->start(); 58 unforwardPortRequest->start();
59 } 59 }
@@ -116,25 +116,25 @@ void SOCKS5BytestreamServerManager::initialize() {
116 assert(!connectionServer); 116 assert(!connectionServer);
117 unsigned short port; 117 unsigned short port;
118 for (port = LISTEN_PORTS_BEGIN; port < LISTEN_PORTS_END; ++port) { 118 for (port = LISTEN_PORTS_BEGIN; port < LISTEN_PORTS_END; ++port) {
119 SWIFT_LOG(debug) << "Trying to start server on port " << port << std::endl; 119 SWIFT_LOG(debug) << "Trying to start server on port " << port;
120 connectionServer = connectionServerFactory->createConnectionServer(HostAddress::fromString("::").get(), port); 120 connectionServer = connectionServerFactory->createConnectionServer(HostAddress::fromString("::").get(), port);
121 boost::optional<ConnectionServer::Error> error = connectionServer->tryStart(); 121 boost::optional<ConnectionServer::Error> error = connectionServer->tryStart();
122 if (!error) { 122 if (!error) {
123 break; 123 break;
124 } 124 }
125 else if (*error != ConnectionServer::Conflict) { 125 else if (*error != ConnectionServer::Conflict) {
126 SWIFT_LOG(debug) << "Error starting server" << std::endl; 126 SWIFT_LOG(debug) << "Error starting server";
127 onInitialized(false); 127 onInitialized(false);
128 return; 128 return;
129 } 129 }
130 connectionServer.reset(); 130 connectionServer.reset();
131 } 131 }
132 if (!connectionServer) { 132 if (!connectionServer) {
133 SWIFT_LOG(debug) << "Unable to find an open port" << std::endl; 133 SWIFT_LOG(debug) << "Unable to find an open port";
134 onInitialized(false); 134 onInitialized(false);
135 return; 135 return;
136 } 136 }
137 SWIFT_LOG(debug) << "Server started succesfully" << std::endl; 137 SWIFT_LOG(debug) << "Server started succesfully";
138 connectionServerPort = port; 138 connectionServerPort = port;
139 139
140 // Start bytestream server. Should actually happen before the connectionserver is started 140 // Start bytestream server. Should actually happen before the connectionserver is started
@@ -211,10 +211,10 @@ void SOCKS5BytestreamServerManager::stop() {
211 211
212void SOCKS5BytestreamServerManager::handleGetPublicIPResult(boost::optional<HostAddress> address) { 212void SOCKS5BytestreamServerManager::handleGetPublicIPResult(boost::optional<HostAddress> address) {
213 if (address) { 213 if (address) {
214 SWIFT_LOG(debug) << "Public IP discovered as " << address.get().toString() << "." << std::endl; 214 SWIFT_LOG(debug) << "Public IP discovered as " << address.get().toString() << ".";
215 } 215 }
216 else { 216 else {
217 SWIFT_LOG(debug) << "No public IP discoverable." << std::endl; 217 SWIFT_LOG(debug) << "No public IP discoverable.";
218 } 218 }
219 219
220 publicAddress = address; 220 publicAddress = address;
@@ -225,10 +225,10 @@ void SOCKS5BytestreamServerManager::handleGetPublicIPResult(boost::optional<Host
225 225
226void SOCKS5BytestreamServerManager::handleForwardPortResult(boost::optional<NATPortMapping> mapping) { 226void SOCKS5BytestreamServerManager::handleForwardPortResult(boost::optional<NATPortMapping> mapping) {
227 if (mapping) { 227 if (mapping) {
228 SWIFT_LOG(debug) << "Mapping port was successful." << std::endl; 228 SWIFT_LOG(debug) << "Mapping port was successful.";
229 } 229 }
230 else { 230 else {
231 SWIFT_LOG(debug) << "Mapping port has failed." << std::endl; 231 SWIFT_LOG(debug) << "Mapping port has failed.";
232 } 232 }
233 233
234 portMapping = mapping; 234 portMapping = mapping;
@@ -243,7 +243,7 @@ void SOCKS5BytestreamServerManager::handleUnforwardPortResult(boost::optional<bo
243 portMapping.reset(); 243 portMapping.reset();
244 } 244 }
245 else { 245 else {
246 SWIFT_LOG(warning) << "Failed to remove port forwarding." << std::endl; 246 SWIFT_LOG(warning) << "Failed to remove port forwarding.";
247 } 247 }
248 attemptedPortMapping_ = false; 248 attemptedPortMapping_ = false;
249 unforwardPortRequest.reset(); 249 unforwardPortRequest.reset();
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
index 0fd40bf..a4ab751 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2018 Isode Limited. 2 * Copyright (c) 2010-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 */
@@ -33,13 +33,13 @@ SOCKS5BytestreamServerSession::SOCKS5BytestreamServerSession(
33 33
34SOCKS5BytestreamServerSession::~SOCKS5BytestreamServerSession() { 34SOCKS5BytestreamServerSession::~SOCKS5BytestreamServerSession() {
35 if (state != Finished && state != Initial) { 35 if (state != Finished && state != Initial) {
36 SWIFT_LOG(warning) << "SOCKS5BytestreamServerSession unfinished" << std::endl; 36 SWIFT_LOG(warning) << "SOCKS5BytestreamServerSession unfinished";
37 finish(); 37 finish();
38 } 38 }
39} 39}
40 40
41void SOCKS5BytestreamServerSession::start() { 41void SOCKS5BytestreamServerSession::start() {
42 SWIFT_LOG(debug) << std::endl; 42 SWIFT_LOG(debug);
43 dataReadConnection = connection->onDataRead.connect( 43 dataReadConnection = connection->onDataRead.connect(
44 boost::bind(&SOCKS5BytestreamServerSession::handleDataRead, this, _1)); 44 boost::bind(&SOCKS5BytestreamServerSession::handleDataRead, this, _1));
45 state = WaitingForAuthentication; 45 state = WaitingForAuthentication;
@@ -50,7 +50,7 @@ void SOCKS5BytestreamServerSession::stop() {
50} 50}
51 51
52void SOCKS5BytestreamServerSession::startSending(std::shared_ptr<ReadBytestream> stream) { 52void SOCKS5BytestreamServerSession::startSending(std::shared_ptr<ReadBytestream> stream) {
53 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!" << std::endl; return; } 53 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!"; return; }
54 54
55 readBytestream = stream; 55 readBytestream = stream;
56 state = WritingData; 56 state = WritingData;
@@ -62,7 +62,7 @@ void SOCKS5BytestreamServerSession::startSending(std::shared_ptr<ReadBytestream>
62} 62}
63 63
64void SOCKS5BytestreamServerSession::startReceiving(std::shared_ptr<WriteBytestream> stream) { 64void SOCKS5BytestreamServerSession::startReceiving(std::shared_ptr<WriteBytestream> stream) {
65 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!" << std::endl; return; } 65 if (state != ReadyForTransfer) { SWIFT_LOG(debug) << "Not ready for transfer!"; return; }
66 66
67 writeBytestream = stream; 67 writeBytestream = stream;
68 state = ReadingData; 68 state = ReadingData;
@@ -93,7 +93,7 @@ void SOCKS5BytestreamServerSession::handleDataAvailable() {
93} 93}
94 94
95void SOCKS5BytestreamServerSession::handleDisconnected(const boost::optional<Connection::Error>& error) { 95void SOCKS5BytestreamServerSession::handleDisconnected(const boost::optional<Connection::Error>& error) {
96 SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error") << std::endl; 96 SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error");
97 finish(error ? boost::optional<FileTransferError>(FileTransferError::PeerError) : boost::optional<FileTransferError>()); 97 finish(error ? boost::optional<FileTransferError>(FileTransferError::PeerError) : boost::optional<FileTransferError>());
98} 98}
99 99
@@ -109,7 +109,7 @@ void SOCKS5BytestreamServerSession::process() {
109 if (i == 2 + authCount) { 109 if (i == 2 + authCount) {
110 // Authentication message is complete 110 // Authentication message is complete
111 if (i != unprocessedData.size()) { 111 if (i != unprocessedData.size()) {
112 SWIFT_LOG(debug) << "Junk after authentication mechanism" << std::endl; 112 SWIFT_LOG(debug) << "Junk after authentication mechanism";
113 } 113 }
114 unprocessedData.clear(); 114 unprocessedData.clear();
115 connection->write(createSafeByteArray("\x05\x00", 2)); 115 connection->write(createSafeByteArray("\x05\x00", 2));
@@ -130,7 +130,7 @@ void SOCKS5BytestreamServerSession::process() {
130 i += 2; 130 i += 2;
131 if (i <= unprocessedData.size()) { 131 if (i <= unprocessedData.size()) {
132 if (i != unprocessedData.size()) { 132 if (i != unprocessedData.size()) {
133 SWIFT_LOG(debug) << "Junk after authentication mechanism" << std::endl; 133 SWIFT_LOG(debug) << "Junk after authentication mechanism";
134 } 134 }
135 unprocessedData.clear(); 135 unprocessedData.clear();
136 streamID = byteArrayToString(requestID); 136 streamID = byteArrayToString(requestID);
@@ -142,18 +142,18 @@ void SOCKS5BytestreamServerSession::process() {
142 result.push_back(boost::numeric_cast<unsigned char>(requestID.size())); 142 result.push_back(boost::numeric_cast<unsigned char>(requestID.size()));
143 } 143 }
144 catch (const boost::numeric::bad_numeric_cast& e) { 144 catch (const boost::numeric::bad_numeric_cast& e) {
145 SWIFT_LOG(warning) << "SOCKS5 request ID is too long (" << requestID.size() << "): " << e.what() << std::endl; 145 SWIFT_LOG(warning) << "SOCKS5 request ID is too long (" << requestID.size() << "): " << e.what();
146 finish(); 146 finish();
147 return; 147 return;
148 } 148 }
149 append(result, concat(requestID, createByteArray("\x00\x00", 2))); 149 append(result, concat(requestID, createByteArray("\x00\x00", 2)));
150 if (!hasBytestream) { 150 if (!hasBytestream) {
151 SWIFT_LOG(debug) << "Readstream or Wrtiestream with ID " << streamID << " not found!" << std::endl; 151 SWIFT_LOG(debug) << "Readstream or Wrtiestream with ID " << streamID << " not found!";
152 connection->write(result); 152 connection->write(result);
153 finish(boost::optional<FileTransferError>(FileTransferError::PeerError)); 153 finish(boost::optional<FileTransferError>(FileTransferError::PeerError));
154 } 154 }
155 else { 155 else {
156 SWIFT_LOG(debug) << "Found stream. Sent OK." << std::endl; 156 SWIFT_LOG(debug) << "Found stream. Sent OK.";
157 connection->write(result); 157 connection->write(result);
158 state = ReadyForTransfer; 158 state = ReadyForTransfer;
159 } 159 }
@@ -185,7 +185,7 @@ void SOCKS5BytestreamServerSession::sendData() {
185} 185}
186 186
187void SOCKS5BytestreamServerSession::finish(const boost::optional<FileTransferError>& error) { 187void SOCKS5BytestreamServerSession::finish(const boost::optional<FileTransferError>& error) {
188 SWIFT_LOG(debug) << "state: " << state << std::endl; 188 SWIFT_LOG(debug) << "state: " << state;
189 if (state == Finished) { 189 if (state == Finished) {
190 return; 190 return;
191 } 191 }
diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
index 80667b6..fad02da 100644
--- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
@@ -5,7 +5,7 @@
5 */ 5 */
6 6
7/* 7/*
8 * Copyright (c) 2015-2016 Isode Limited. 8 * Copyright (c) 2015-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 */
@@ -238,7 +238,7 @@ private:
238 std::shared_ptr<SafeByteArray> dataToSend; 238 std::shared_ptr<SafeByteArray> dataToSend;
239 //ByteArray failingData = Hexify::unhexify("8417947d1d305c72c11520ea7d2c6e787396705e72c312c6ccc3f66613d7cae1b91b7ab48e8b59a17d559c15fb51"); 239 //ByteArray failingData = Hexify::unhexify("8417947d1d305c72c11520ea7d2c6e787396705e72c312c6ccc3f66613d7cae1b91b7ab48e8b59a17d559c15fb51");
240 //append(dataToSend, failingData); 240 //append(dataToSend, failingData);
241 //SWIFT_LOG(debug) << "hexed: " << Hexify::hexify(failingData) << std::endl; 241 //SWIFT_LOG(debug) << "hexed: " << Hexify::hexify(failingData);
242 do { 242 do {
243 ByteArray rndArray = generateRandomByteArray(correctData->size()); 243 ByteArray rndArray = generateRandomByteArray(correctData->size());
244 dataToSend = createSafeByteArrayRef(vecptr(rndArray), rndArray.size()); 244 dataToSend = createSafeByteArrayRef(vecptr(rndArray), rndArray.size());
@@ -255,7 +255,7 @@ private:
255 255
256 void handleConnectionDataWritten(const SafeByteArray& data) { 256 void handleConnectionDataWritten(const SafeByteArray& data) {
257 append(unprocessedInput, data); 257 append(unprocessedInput, data);
258 //SWIFT_LOG(debug) << "unprocessedInput (" << unprocessedInput.size() << "): " << Hexify::hexify(unprocessedInput) << std::endl; 258 //SWIFT_LOG(debug) << "unprocessedInput (" << unprocessedInput.size() << "): " << Hexify::hexify(unprocessedInput);
259 } 259 }
260 260
261 void handleSessionReady(bool error) { 261 void handleSessionReady(bool error) {