summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-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
4 files changed, 46 insertions, 29 deletions
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,5 +1,5 @@
/*
- * Copyright (c) 2013-2014 Isode Limited.
+ * Copyright (c) 2013-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -8,13 +8,18 @@
using namespace Swift;
-FileTransfer::FileTransfer() : fileSizeInBytes(0) {
+FileTransfer::FileTransfer() : fileSizeInBytes_(0), state_(State::Initial) {
}
FileTransfer::~FileTransfer() {
}
+void FileTransfer::setState(const State& state) {
+ state_ = state;
+ onStateChanged(state);
+}
+
void FileTransfer::setFileInfo(const std::string& name, boost::uintmax_t size) {
- filename = name;
- fileSizeInBytes = size;
+ filename_ = name;
+ fileSizeInBytes_ = size;
}
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
@@ -21,6 +21,12 @@
#include <Swiften/FileTransfer/FileTransferError.h>
namespace Swift {
+ /**
+ * The FileTransfer class provides a general interface for file-transfer
+ * implmenetations. Currently, only Jingle File Transfer based on XEP-0234 is
+ * implementated in the \ref OutgoingJingleFileTransfer and
+ * \ref IncomingJingleFileTransfer classes.
+ */
class SWIFTEN_API FileTransfer {
public:
struct State {
@@ -49,11 +55,15 @@ namespace Swift {
virtual void cancel() = 0;
const std::string& getFileName() const {
- return filename;
+ return filename_;
}
boost::uintmax_t getFileSizeInBytes() const {
- return fileSizeInBytes;
+ return fileSizeInBytes_;
+ }
+
+ const State& getState() const {
+ return state_;
}
public:
@@ -62,10 +72,12 @@ namespace Swift {
boost::signal<void (boost::optional<FileTransferError>)> onFinished;
protected:
+ void setState(const State& state);
void setFileInfo(const std::string& name, boost::uintmax_t size);
private:
- boost::uintmax_t fileSizeInBytes;
- std::string filename;
+ boost::uintmax_t fileSizeInBytes_;
+ std::string filename_;
+ State state_;
};
}
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
@@ -89,7 +89,7 @@ void OutgoingJingleFileTransfer::start() {
}
setTransporter(transporterFactory->createInitiatorTransporter(getInitiator(), getResponder(), options));
- setState(GeneratingInitialLocalCandidates);
+ setInternalState(GeneratingInitialLocalCandidates);
transporter->startGeneratingLocalCandidates();
}
@@ -116,7 +116,7 @@ void OutgoingJingleFileTransfer::handleSessionAcceptReceived(
if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transportPayload)) {
transporter->addRemoteCandidates(s5bPayload->getCandidates(), s5bPayload->getDstAddr());
- setState(TryingCandidates);
+ setInternalState(TryingCandidates);
transporter->startTryingRemoteCandidates();
}
else {
@@ -178,7 +178,7 @@ void OutgoingJingleFileTransfer::sendSessionInfoHash() {
void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
const std::string& s5bSessionID, const std::vector<JingleS5BTransportPayload::Candidate>& candidates, const std::string& dstAddr) {
SWIFT_LOG(debug) << std::endl;
- if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state" << std::endl; return; }
+ if (state != GeneratingInitialLocalCandidates) { SWIFT_LOG(warning) << "Incorrect state: " << state << std::endl; return; }
fillCandidateMap(localCandidates, candidates);
@@ -195,7 +195,7 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated(
transport->addCandidate(candidate);
SWIFT_LOG(debug) << "\t" << "S5B candidate: " << candidate.hostPort.toString() << std::endl;
}
- setState(WaitingForAccept);
+ setInternalState(WaitingForAccept);
session->sendInitiate(contentID, description, transport);
}
@@ -205,7 +205,7 @@ void OutgoingJingleFileTransfer::fallback() {
JingleIBBTransportPayload::ref ibbTransport = boost::make_shared<JingleIBBTransportPayload>();
ibbTransport->setBlockSize(DEFAULT_BLOCK_SIZE);
ibbTransport->setSessionID(idGenerator->generateID());
- setState(FallbackRequested);
+ setInternalState(FallbackRequested);
session->sendTransportReplace(contentID, ibbTransport);
}
else {
@@ -225,7 +225,7 @@ void OutgoingJingleFileTransfer::handleTransferFinished(boost::optional<FileTran
sendSessionInfoHash();
// wait for other party to terminate session after they have verified the hash
- setState(WaitForTermination);
+ setInternalState(WaitForTermination);
waitForRemoteTermination->start();
}
}
@@ -238,15 +238,15 @@ void OutgoingJingleFileTransfer::startTransferring(boost::shared_ptr<TransportSe
boost::bind(boost::ref(onProcessedBytes), _1));
transferFinishedConnection = transportSession->onFinished.connect(
boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1));
- setState(Transferring);
+ setInternalState(Transferring);
transportSession->start();
}
-void OutgoingJingleFileTransfer::setState(State state) {
+void OutgoingJingleFileTransfer::setInternalState(State state) {
SWIFT_LOG(debug) << state << std::endl;
this->state = state;
- onStateChanged(FileTransfer::State(getExternalState(state)));
+ setState(FileTransfer::State(getExternalState(state)));
}
void OutgoingJingleFileTransfer::setFinishedState(
@@ -306,7 +306,7 @@ void OutgoingJingleFileTransfer::startTransferViaRemoteCandidate() {
SWIFT_LOG(debug) << std::endl;
if (ourCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
- setState(WaitingForPeerProxyActivate);
+ setInternalState(WaitingForPeerProxyActivate);
}
else {
transportSession = createRemoteCandidateSession();
@@ -318,7 +318,7 @@ void OutgoingJingleFileTransfer::startTransferViaLocalCandidate() {
SWIFT_LOG(debug) << std::endl;
if (theirCandidateChoice->type == JingleS5BTransportPayload::Candidate::ProxyType) {
- setState(WaitingForLocalProxyActivate);
+ setInternalState(WaitingForLocalProxyActivate);
transporter->startActivatingProxy(theirCandidateChoice->jid);
}
else {
@@ -332,7 +332,7 @@ void OutgoingJingleFileTransfer::startTransferringIfCandidateAcknowledged() {
startTransferring(transportSession);
}
else {
- setState(WaitingForCandidateAcknowledge);
+ setInternalState(WaitingForCandidateAcknowledge);
}
}
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
@@ -12,27 +12,27 @@
#pragma once
-#include <boost/shared_ptr.hpp>
#include <boost/optional/optional.hpp>
+#include <boost/shared_ptr.hpp>
#include <Swiften/Base/API.h>
#include <Swiften/Base/Override.h>
-#include <Swiften/Jingle/JingleContentID.h>
#include <Swiften/Elements/JingleFileTransferFileInfo.h>
-#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
-#include <Swiften/FileTransfer/JingleFileTransfer.h>
#include <Swiften/FileTransfer/FileTransferOptions.h>
+#include <Swiften/FileTransfer/JingleFileTransfer.h>
+#include <Swiften/FileTransfer/OutgoingFileTransfer.h>
+#include <Swiften/Jingle/JingleContentID.h>
#include <Swiften/Network/Timer.h>
namespace Swift {
- class ReadBytestream;
- class IDGenerator;
- class IncrementalBytestreamHashCalculator;
class CryptoProvider;
class FileTransferTransporter;
class FileTransferTransporterFactory;
- class TransportSession;
+ class IDGenerator;
+ class IncrementalBytestreamHashCalculator;
+ class ReadBytestream;
class TimerFactory;
+ class TransportSession;
class SWIFTEN_API OutgoingJingleFileTransfer : public OutgoingFileTransfer, public JingleFileTransfer {
public:
@@ -98,7 +98,7 @@ namespace Swift {
void handleWaitForRemoteTerminationTimeout();
void stopAll();
- void setState(State state);
+ void setInternalState(State state);
void setFinishedState(FileTransfer::State::Type, const boost::optional<FileTransferError>& error);
static FileTransfer::State::Type getExternalState(State state);