summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-10-29 10:12:03 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-10-30 12:49:14 (GMT)
commitcb62de17d1e17fd3049a6bc8155a100574a42a85 (patch)
treeddbabd81818f1dd16ba2ebc96b45267a1d2e4bf2
parent1d921f3d39ed134ca7f1d40011c1a07a5835b73c (diff)
downloadswift-cb62de17d1e17fd3049a6bc8155a100574a42a85.zip
swift-cb62de17d1e17fd3049a6bc8155a100574a42a85.tar.bz2
Add FileTransfer::getState() method
In addition, this adds the file-transfer classes to the Doxygen documentation. Test-Information: Unit and integration tests still pass. Change-Id: Ib6c16078c90ed56fae835cb2abfea8a564c3afa3
-rw-r--r--Documentation/API/Doxyfile7
-rw-r--r--Swiften/FileTransfer/FileTransfer.cpp13
-rw-r--r--Swiften/FileTransfer/FileTransfer.h20
-rw-r--r--Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp24
-rw-r--r--Swiften/FileTransfer/OutgoingJingleFileTransfer.h18
5 files changed, 50 insertions, 32 deletions
diff --git a/Documentation/API/Doxyfile b/Documentation/API/Doxyfile
index 84fdaac..0634800 100644
--- a/Documentation/API/Doxyfile
+++ b/Documentation/API/Doxyfile
@@ -87,21 +87,22 @@ WARN_LOGFILE =
87INPUT = \ 87INPUT = \
88 Swiften/Avatars \ 88 Swiften/Avatars \
89 Swiften/Base \ 89 Swiften/Base \
90 Swiften/Chat \ 90 Swiften/Chat \
91 Swiften/Client/Client.h \ 91 Swiften/Client/Client.h \
92 Swiften/Client/CoreClient.h \
93 Swiften/Client/ClientError.h \ 92 Swiften/Client/ClientError.h \
94 Swiften/Client/StanzaChannel.h \ 93 Swiften/Client/CoreClient.h \
94 Swiften/Client/MemoryStorages.h \
95 Swiften/Client/NickResolver.h \ 95 Swiften/Client/NickResolver.h \
96 Swiften/Client/StanzaChannel.h \
96 Swiften/Client/Storages.h \ 97 Swiften/Client/Storages.h \
97 Swiften/Client/MemoryStorages.h \
98 Swiften/Component/Component.h \ 98 Swiften/Component/Component.h \
99 Swiften/Component/CoreComponent.h \ 99 Swiften/Component/CoreComponent.h \
100 Swiften/Disco \ 100 Swiften/Disco \
101 Swiften/Elements \ 101 Swiften/Elements \
102 Swiften/EventLoop \ 102 Swiften/EventLoop \
103 Swiften/FileTransfer \
103 Swiften/JID \ 104 Swiften/JID \
104 Swiften/MUC \ 105 Swiften/MUC \
105 Swiften/Presence \ 106 Swiften/Presence \
106 Swiften/Queries \ 107 Swiften/Queries \
107 Swiften/Roster/XMPPRoster.h \ 108 Swiften/Roster/XMPPRoster.h \
diff --git a/Swiften/FileTransfer/FileTransfer.cpp b/Swiften/FileTransfer/FileTransfer.cpp
index 6b594aa..f63a4e8 100644
--- a/Swiften/FileTransfer/FileTransfer.cpp
+++ b/Swiften/FileTransfer/FileTransfer.cpp
@@ -1,20 +1,25 @@
1/* 1/*
2 * Copyright (c) 2013-2014 Isode Limited. 2 * Copyright (c) 2013-2015 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 */
6 6
7#include <Swiften/FileTransfer/FileTransfer.h> 7#include <Swiften/FileTransfer/FileTransfer.h>
8 8
9using namespace Swift; 9using namespace Swift;
10 10
11FileTransfer::FileTransfer() : fileSizeInBytes(0) { 11FileTransfer::FileTransfer() : fileSizeInBytes_(0), state_(State::Initial) {
12} 12}
13 13
14FileTransfer::~FileTransfer() { 14FileTransfer::~FileTransfer() {
15} 15}
16 16
17void FileTransfer::setState(const State& state) {
18 state_ = state;
19 onStateChanged(state);
20}
21
17void FileTransfer::setFileInfo(const std::string& name, boost::uintmax_t size) { 22void FileTransfer::setFileInfo(const std::string& name, boost::uintmax_t size) {
18 filename = name; 23 filename_ = name;
19 fileSizeInBytes = size; 24 fileSizeInBytes_ = size;
20} 25}
diff --git a/Swiften/FileTransfer/FileTransfer.h b/Swiften/FileTransfer/FileTransfer.h
index 01c8295..afb3f7b 100644
--- a/Swiften/FileTransfer/FileTransfer.h
+++ b/Swiften/FileTransfer/FileTransfer.h
@@ -19,10 +19,16 @@
19#include <Swiften/Base/API.h> 19#include <Swiften/Base/API.h>
20#include <Swiften/Base/boost_bsignals.h> 20#include <Swiften/Base/boost_bsignals.h>
21#include <Swiften/FileTransfer/FileTransferError.h> 21#include <Swiften/FileTransfer/FileTransferError.h>
22 22
23namespace Swift { 23namespace Swift {
24 /**
25 * The FileTransfer class provides a general interface for file-transfer
26 * implmenetations. Currently, only Jingle File Transfer based on XEP-0234 is
27 * implementated in the \ref OutgoingJingleFileTransfer and
28 * \ref IncomingJingleFileTransfer classes.
29 */
24 class SWIFTEN_API FileTransfer { 30 class SWIFTEN_API FileTransfer {
25 public: 31 public:
26 struct State { 32 struct State {
27 enum Type { 33 enum Type {
28 Initial, 34 Initial,
@@ -47,25 +53,31 @@ namespace Swift {
47 virtual ~FileTransfer(); 53 virtual ~FileTransfer();
48 54
49 virtual void cancel() = 0; 55 virtual void cancel() = 0;
50 56
51 const std::string& getFileName() const { 57 const std::string& getFileName() const {
52 return filename; 58 return filename_;
53 } 59 }
54 60
55 boost::uintmax_t getFileSizeInBytes() const { 61 boost::uintmax_t getFileSizeInBytes() const {
56 return fileSizeInBytes; 62 return fileSizeInBytes_;
63 }
64
65 const State& getState() const {
66 return state_;
57 } 67 }
58 68
59 public: 69 public:
60 boost::signal<void (size_t /* proccessedBytes */)> onProcessedBytes; 70 boost::signal<void (size_t /* proccessedBytes */)> onProcessedBytes;
61 boost::signal<void (const State&)> onStateChanged; 71 boost::signal<void (const State&)> onStateChanged;
62 boost::signal<void (boost::optional<FileTransferError>)> onFinished; 72 boost::signal<void (boost::optional<FileTransferError>)> onFinished;
63 73
64 protected: 74 protected:
75 void setState(const State& state);
65 void setFileInfo(const std::string& name, boost::uintmax_t size); 76 void setFileInfo(const std::string& name, boost::uintmax_t size);
66 77
67 private: 78 private:
68 boost::uintmax_t fileSizeInBytes; 79 boost::uintmax_t fileSizeInBytes_;
69 std::string filename; 80 std::string filename_;
81 State state_;
70 }; 82 };
71} 83}
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
index f9441cd..6369581 100644
--- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
+++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
@@ -87,11 +87,11 @@ void OutgoingJingleFileTransfer::start() {
87 SWIFT_LOG(warning) << "Incorrect state" << std::endl; 87 SWIFT_LOG(warning) << "Incorrect state" << std::endl;
88 return; 88 return;
89 } 89 }
90 90
91 setTransporter(transporterFactory->createInitiatorTransporter(getInitiator(), getResponder(), options)); 91 setTransporter(transporterFactory->createInitiatorTransporter(getInitiator(), getResponder(), options));
92 setState(GeneratingInitialLocalCandidates); 92 setInternalState(GeneratingInitialLocalCandidates);
93 transporter->startGeneratingLocalCandidates(); 93 transporter->startGeneratingLocalCandidates();
94} 94}
95 95
96void OutgoingJingleFileTransfer::cancel() { 96void OutgoingJingleFileTransfer::cancel() {
97 terminate(JinglePayload::Reason::Cancel); 97 terminate(JinglePayload::Reason::Cancel);
@@ -114,11 +114,11 @@ void OutgoingJingleFileTransfer::handleSessionAcceptReceived(
114 SWIFT_LOG(debug) << std::endl; 114 SWIFT_LOG(debug) << std::endl;
115 if (state != WaitingForAccept) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 115 if (state != WaitingForAccept) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; }
116 116
117 if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) { 117 if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) {
118 transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr()); 118 transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr());
119 setState(TryingCandidates); 119 setInternalState(TryingCandidates);
120 transporter->startTryingRemoteCandidates(); 120 transporter->startTryingRemoteCandidates();
121 } 121 }
122 else { 122 else {
123 SWIFT_LOG(debug) << "Unknown transport payload. Falling back." << std::endl; 123 SWIFT_LOG(debug) << "Unknown transport payload. Falling back." << std::endl;
124 fallback(); 124 fallback();
@@ -176,11 +176,11 @@ void OutgoingJingleFileTransfer::sendSessionInfoHash() {
176} 176}
177 177
178void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated( 178void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
179 const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) { 179 const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) {
180 SWIFT_LOG(debug) << std::endl; 180 SWIFT_LOG(debug) << std::endl;
181 if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; } 181 if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; }
182 182
183 fillCandidateMap(localCandidates, candidates); 183 fillCandidateMap(localCandidates, candidates);
184 184
185 JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>(); 185 JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>();
186 fileInfo.addHash(HashElement("sha-1", ByteArray())); 186 fileInfo.addHash(HashElement("sha-1", ByteArray()));
@@ -193,21 +193,21 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
193 transport->setDstAddr(dstAddr); 193 transport->setDstAddr(dstAddr);
194 foreach(JingleS5BTransportPayload::Candidate candidate, candidates) { 194 foreach(JingleS5BTransportPayload::Candidate candidate, candidates) {
195 transport->addCandidate(candidate); 195 transport->addCandidate(candidate);
196 SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl; 196 SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl;
197 } 197 }
198 setState(WaitingForAccept); 198 setInternalState(WaitingForAccept);
199 session->sendInitiate(contentID, description, transport); 199 session->sendInitiate(contentID, description, transport);
200} 200}
201 201
202void OutgoingJingleFileTransfer::fallback() { 202void OutgoingJingleFileTransfer::fallback() {
203 if (options.isInBandAllowed()) { 203 if (options.isInBandAllowed()) {
204 SWIFT_LOG(debug) << "Trying to fallback to IBB transport." << std::endl; 204 SWIFT_LOG(debug) << "Trying to fallback to IBB transport." << std::endl;
205 JingleIBBTransportPayload::ref ibbTransport = boost::make_shared<JingleIBBTransportPayload>(); 205 JingleIBBTransportPayload::ref ibbTransport = boost::make_shared<JingleIBBTransportPayload>();
206 ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE); 206 ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE);
207 ibbTransport->setSessionID(idGenerator->generateID()); 207 ibbTransport->setSessionID(idGenerator->generateID());
208 setState(FallbackRequested); 208 setInternalState(FallbackRequested);
209 session->sendTransportReplace(contentID, ibbTransport); 209 session->sendTransportReplace(contentID, ibbTransport);
210 } 210 }
211 else { 211 else {
212 SWIFT_LOG(debug) << "Fallback to IBB transport not allowed." << std::endl; 212 SWIFT_LOG(debug) << "Fallback to IBB transport not allowed." << std::endl;
213 terminate(JinglePayload::Reason::ConnectivityError); 213 terminate(JinglePayload::Reason::ConnectivityError);
@@ -223,11 +223,11 @@ void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTran
223 } 223 }
224 else { 224 else {
225 sendSessionInfoHash(); 225 sendSessionInfoHash();
226 226
227 // wait for other party to terminate session after they have verified the hash 227 // wait for other party to terminate session after they have verified the hash
228 setState(WaitForTermination); 228 setInternalState(WaitForTermination);
229 waitForRemoteTermination->start(); 229 waitForRemoteTermination->start();
230 } 230 }
231} 231}
232 232
233void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSession> transportSession) { 233void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSession> transportSession) {
@@ -236,19 +236,19 @@ void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSe
236 this->transportSession = transportSession; 236 this->transportSession = transportSession;
237 processedBytesConnection = transportSession->onBytesSent.connect( 237 processedBytesConnection = transportSession->onBytesSent.connect(
238 boost::bind(boost::ref(onProcessedBytes), _1)); 238 boost::bind(boost::ref(onProcessedBytes), _1));
239 transferFinishedConnection = transportSession->onFinished.connect( 239 transferFinishedConnection = transportSession->onFinished.connect(
240 boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1)); 240 boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1));
241 setState(Transferring); 241 setInternalState(Transferring);
242 transportSession->start(); 242 transportSession->start();
243} 243}
244 244
245 245
246void OutgoingJingleFileTransfer::setState(State state) { 246void OutgoingJingleFileTransfer::setInternalState(State state) {
247 SWIFT_LOG(debug) << state << std::endl; 247 SWIFT_LOG(debug) << state << std::endl;
248 this->state = state; 248 this->state = state;
249 onStateChanged(FileTransfer::State(getExternalState(state))); 249 setState(FileTransfer::State(getExternalState(state)));
250} 250}
251 251
252void OutgoingJingleFileTransfer::setFinishedState( 252void OutgoingJingleFileTransfer::setFinishedState(
253 FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) { 253 FileTransfer::State::Type type, const boost::optional<FileTransferError>& error) {
254 SWIFT_LOG(debug) << std::endl; 254 SWIFT_LOG(debug) << std::endl;
@@ -304,11 +304,11 @@ void OutgoingJingleFileTransfer::stopAll() {
304 304
305void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() { 305void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() {
306 SWIFT_LOG(debug) << std::endl; 306 SWIFT_LOG(debug) << std::endl;
307 307
308 if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { 308 if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
309 setState(WaitingForPeerProxyActivate); 309 setInternalState(WaitingForPeerProxyActivate);
310 } 310 }
311 else { 311 else {
312 transportSession = createRemoteCandidateSession(); 312 transportSession = createRemoteCandidateSession();
313 startTransferringIfCandidateAcknowledged(); 313 startTransferringIfCandidateAcknowledged();
314 } 314 }
@@ -316,11 +316,11 @@ void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() {
316 316
317void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() { 317void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() {
318 SWIFT_LOG(debug) << std::endl; 318 SWIFT_LOG(debug) << std::endl;
319 319
320 if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) { 320 if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
321 setState(WaitingForLocalProxyActivate); 321 setInternalState(WaitingForLocalProxyActivate);
322 transporter->startActivatingProxy(theirCandidateChoice->jid); 322 transporter->startActivatingProxy(theirCandidateChoice->jid);
323 } 323 }
324 else { 324 else {
325 transportSession = createLocalCandidateSession(); 325 transportSession = createLocalCandidateSession();
326 startTransferringIfCandidateAcknowledged(); 326 startTransferringIfCandidateAcknowledged();
@@ -330,11 +330,11 @@ void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() {
330void OutgoingJingleFileTransfer::startTransferringIfCandidateAcknowledged() { 330void OutgoingJingleFileTransfer::startTransferringIfCandidateAcknowledged() {
331 if (candidateAcknowledged) { 331 if (candidateAcknowledged) {
332 startTransferring(transportSession); 332 startTransferring(transportSession);
333 } 333 }
334 else { 334 else {
335 setState(WaitingForCandidateAcknowledge); 335 setInternalState(WaitingForCandidateAcknowledge);
336 } 336 }
337} 337}
338 338
339void OutgoingJingleFileTransfer::handleTransportInfoAcknowledged(const std::string& id) { 339void OutgoingJingleFileTransfer::handleTransportInfoAcknowledged(const std::string& id) {
340 if (id == candidateSelectRequestID) { 340 if (id == candidateSelectRequestID) {
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h
index 4cb2685..96b465b 100644
--- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h
+++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h
@@ -10,31 +10,31 @@
10 * See the COPYING file for more information. 10 * See the COPYING file for more information.
11 */ 11 */
12 12
13#pragma once 13#pragma once
14 14
15#include <boost/shared_ptr.hpp>
16#include <boost/optional/optional.hpp> 15#include <boost/optional/optional.hpp>
16#include <boost/shared_ptr.hpp>
17 17
18#include <Swiften/Base/API.h> 18#include <Swiften/Base/API.h>
19#include <Swiften/Base/Override.h> 19#include <Swiften/Base/Override.h>
20#include <Swiften/Jingle/JingleContentID.h>
21#include <Swiften/Elements/JingleFileTransferFileInfo.h> 20#include <Swiften/Elements/JingleFileTransferFileInfo.h>
22#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
23#include <Swiften/FileTransfer/JingleFileTransfer.h>
24#include <Swiften/FileTransfer/FileTransferOptions.h> 21#include <Swiften/FileTransfer/FileTransferOptions.h>
22#include <Swiften/FileTransfer/JingleFileTransfer.h>
23#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
24#include <Swiften/Jingle/JingleContentID.h>
25#include <Swiften/Network/Timer.h> 25#include <Swiften/Network/Timer.h>
26 26
27namespace Swift { 27namespace Swift {
28 class ReadBytestream;
29 class IDGenerator;
30 class IncrementalBytestreamHashCalculator;
31 class CryptoProvider; 28 class CryptoProvider;
32 class FileTransferTransporter; 29 class FileTransferTransporter;
33 class FileTransferTransporterFactory; 30 class FileTransferTransporterFactory;
34 class TransportSession; 31 class IDGenerator;
32 class IncrementalBytestreamHashCalculator;
33 class ReadBytestream;
35 class TimerFactory; 34 class TimerFactory;
35 class TransportSession;
36 36
37 class SWIFTEN_API OutgoingJingleFileTransfer : public OutgoingFileTransfer, public JingleFileTransfer { 37 class SWIFTEN_API OutgoingJingleFileTransfer : public OutgoingFileTransfer, public JingleFileTransfer {
38 public: 38 public:
39 OutgoingJingleFileTransfer( 39 OutgoingJingleFileTransfer(
40 const JID& to, 40 const JID& to,
@@ -96,11 +96,11 @@ namespace Swift {
96 virtual boost::shared_ptr<TransportSession> createRemoteCandidateSession() SWIFTEN_OVERRIDE; 96 virtual boost::shared_ptr<TransportSession> createRemoteCandidateSession() SWIFTEN_OVERRIDE;
97 97
98 void handleWaitForRemoteTerminationTimeout(); 98 void handleWaitForRemoteTerminationTimeout();
99 99
100 void stopAll(); 100 void stopAll();
101 void setState(State state); 101 void setInternalState(State state);
102 void setFinishedState(FileTransfer::State::Type, const boost::optional<FileTransferError>& error); 102 void setFinishedState(FileTransfer::State::Type, const boost::optional<FileTransferError>& error);
103 103
104 static FileTransfer::State::Type getExternalState(State state); 104 static FileTransfer::State::Type getExternalState(State state);
105 105
106 private: 106 private: