From 16f7c07cfce1879fa0319b4304bb6e11f9a6dd9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be> Date: Sun, 30 Dec 2012 13:45:03 +0100 Subject: File Transfer refactoring. Rename run() to start(), and provide stop() placeholder. Change-Id: I44257a0fca89c9345054a5d6fa3c1b4768995081 diff --git a/Swiften/Examples/NetworkTool/main.cpp b/Swiften/Examples/NetworkTool/main.cpp index 4ac7e6a..10a0aa6 100644 --- a/Swiften/Examples/NetworkTool/main.cpp +++ b/Swiften/Examples/NetworkTool/main.cpp @@ -58,7 +58,7 @@ int main(int argc, char* argv[]) { if (std::string(argv[1]) == "get-public-ip") { boost::shared_ptr<NATTraversalGetPublicIPRequest> query = natTraverser.createGetPublicIPRequest(); query->onResult.connect(boost::bind(&handleGetPublicIPRequestResponse, _1)); - query->run(); + query->start(); eventLoop.run(); } else if (std::string(argv[1]) == "add-port-forward") { @@ -67,7 +67,7 @@ int main(int argc, char* argv[]) { } boost::shared_ptr<NATTraversalForwardPortRequest> query = natTraverser.createForwardPortRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3])); query->onResult.connect(boost::bind(&handleGetForwardPortRequestResponse, _1)); - query->run(); + query->start(); eventLoop.run(); } else if (std::string(argv[1]) == "remove-port-forward") { @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) { } boost::shared_ptr<NATTraversalRemovePortForwardingRequest> query = natTraverser.createRemovePortForwardingRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3])); query->onResult.connect(boost::bind(&handleRemovePortForwardingRequestResponse, _1)); - query->run(); + query->start(); eventLoop.run(); } else if (std::string(argv[1]) == "get-local-ip") { diff --git a/Swiften/FileTransfer/ConnectivityManager.cpp b/Swiften/FileTransfer/ConnectivityManager.cpp index 7d25991..5ed500c 100644 --- a/Swiften/FileTransfer/ConnectivityManager.cpp +++ b/Swiften/FileTransfer/ConnectivityManager.cpp @@ -34,13 +34,13 @@ void ConnectivityManager::addListeningPort(int port) { boost::shared_ptr<NATTraversalGetPublicIPRequest> getIPRequest = natTraversalWorker->createGetPublicIPRequest(); if (getIPRequest) { getIPRequest->onResult.connect(boost::bind(&ConnectivityManager::natTraversalGetPublicIPResult, this, _1)); - getIPRequest->run(); + getIPRequest->start(); } boost::shared_ptr<NATTraversalForwardPortRequest> forwardPortRequest = natTraversalWorker->createForwardPortRequest(port, port); if (forwardPortRequest) { forwardPortRequest->onResult.connect(boost::bind(&ConnectivityManager::natTraversalForwardPortResult, this, _1)); - forwardPortRequest->run(); + forwardPortRequest->start(); } } @@ -49,7 +49,7 @@ void ConnectivityManager::removeListeningPort(int port) { ports.erase(port); boost::shared_ptr<NATTraversalRemovePortForwardingRequest> removePortForwardingRequest = natTraversalWorker->createRemovePortForwardingRequest(port, port); if (removePortForwardingRequest) { - removePortForwardingRequest->run(); + removePortForwardingRequest->start(); } } diff --git a/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.cpp b/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.cpp index 4b205cb..988be7b 100644 --- a/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.cpp +++ b/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.cpp @@ -27,7 +27,7 @@ DefaultLocalJingleTransportCandidateGenerator::DefaultLocalJingleTransportCandid DefaultLocalJingleTransportCandidateGenerator::~DefaultLocalJingleTransportCandidateGenerator() { } -void DefaultLocalJingleTransportCandidateGenerator::generateLocalTransportCandidates(JingleTransportPayload::ref transportPayload) { +void DefaultLocalJingleTransportCandidateGenerator::start(JingleTransportPayload::ref transportPayload) { if (boost::dynamic_pointer_cast<JingleIBBTransportPayload>(transportPayload)) { JingleTransportPayload::ref payL = boost::make_shared<JingleTransportPayload>(); payL->setSessionID(transportPayload->getSessionID()); @@ -83,6 +83,9 @@ void DefaultLocalJingleTransportCandidateGenerator::generateLocalTransportCandid } +void DefaultLocalJingleTransportCandidateGenerator::stop() { +} + bool DefaultLocalJingleTransportCandidateGenerator::isActualCandidate(JingleTransportPayload::ref transportPayload) { if (!transportPayload.get()) return false; return false; diff --git a/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.h b/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.h index 7d45491..b729d0d 100644 --- a/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.h +++ b/Swiften/FileTransfer/DefaultLocalJingleTransportCandidateGenerator.h @@ -22,7 +22,8 @@ public: DefaultLocalJingleTransportCandidateGenerator(ConnectivityManager* connectivityManager, SOCKS5BytestreamRegistry* s5bRegistry, SOCKS5BytestreamProxy* s5bProxy, JID& ownJID); virtual ~DefaultLocalJingleTransportCandidateGenerator(); - virtual void generateLocalTransportCandidates(JingleTransportPayload::ref); + virtual void start(JingleTransportPayload::ref); + virtual void stop(); virtual bool isActualCandidate(JingleTransportPayload::ref); virtual int getPriority(JingleTransportPayload::ref); diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp index c462381..0d576ac 100644 --- a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp @@ -112,7 +112,7 @@ void IncomingJingleFileTransfer::accept(WriteBytestream::ref stream) { candidateSelector->addRemoteTransportCandidates(s5bTransport); candidateSelector->setRequesterTarget(session->getInitiator(), ourJID); s5bTransport->setSessionID(s5bSessionID); - candidateGenerator->generateLocalTransportCandidates(s5bTransport); + candidateGenerator->start(s5bTransport); } else { assert(false); diff --git a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h index 14c128a..474b01d 100644 --- a/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h +++ b/Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h @@ -16,10 +16,12 @@ namespace Swift { class SWIFTEN_API LocalJingleTransportCandidateGenerator { public: virtual ~LocalJingleTransportCandidateGenerator(); + /** * Should call onLocalTransportCandidatesGenerated if it has finished discovering local candidates. */ - virtual void generateLocalTransportCandidates(JingleTransportPayload::ref) = 0; + virtual void start(JingleTransportPayload::ref) = 0; + virtual void stop() = 0; virtual bool isActualCandidate(JingleTransportPayload::ref) = 0; virtual int getPriority(JingleTransportPayload::ref) = 0; diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp index 4da70ef..8229a2f 100644 --- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp +++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp @@ -54,7 +54,8 @@ OutgoingJingleFileTransfer::OutgoingJingleFileTransfer(JingleSession::ref sessio filename = fileInfo.getName(); localCandidateGenerator = localFactory->createCandidateGenerator(); - localCandidateGenerator->onLocalTransportCandidatesGenerated.connect(boost::bind(&OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1)); + localCandidateGenerator->onLocalTransportCandidatesGenerated.connect( + boost::bind(&OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1)); remoteCandidateSelector = remoteFactory->createCandidateSelector(); remoteCandidateSelector->onRemoteTransportCandidateSelectFinished.connect(boost::bind(&OutgoingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished, this, _1)); @@ -77,7 +78,7 @@ void OutgoingJingleFileTransfer::start() { //s5bProxy->connectToProxies(s5bSessionID); JingleS5BTransportPayload::ref transport = boost::make_shared<JingleS5BTransportPayload>(); - localCandidateGenerator->generateLocalTransportCandidates(transport); + localCandidateGenerator->start(transport); } void OutgoingJingleFileTransfer::stop() { diff --git a/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp index 4c6ae72..9d180a0 100644 --- a/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp +++ b/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp @@ -10,6 +10,7 @@ #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/Override.h> #include <Swiften/Base/Log.h> #include <Swiften/Client/DummyStanzaChannel.h> #include <Swiften/Elements/IBB.h> @@ -80,12 +81,6 @@ public: class FakeLocalJingleTransportCandidateGenerator : public LocalJingleTransportCandidateGenerator { public: - virtual void generateLocalTransportCandidates(JingleTransportPayload::ref payload) { - JingleS5BTransportPayload::ref payL = make_shared<JingleS5BTransportPayload>(); - payL->setSessionID(payload->getSessionID()); - onLocalTransportCandidatesGenerated(payL); - } - void emitonLocalTransportCandidatesGenerated(JingleTransportPayload::ref payload) { onLocalTransportCandidatesGenerated(payload); } @@ -101,6 +96,14 @@ public: virtual JingleTransport::ref selectTransport(JingleTransportPayload::ref) { return JingleTransport::ref(); } + + virtual void start(JingleTransportPayload::ref payload) SWIFTEN_OVERRIDE { + JingleS5BTransportPayload::ref payL = make_shared<JingleS5BTransportPayload>(); + payL->setSessionID(payload->getSessionID()); + onLocalTransportCandidatesGenerated(payL); + } + + virtual void stop() SWIFTEN_OVERRIDE {} }; class FakeLocalJingleTransportCandidateGeneratorFactory : public LocalJingleTransportCandidateGeneratorFactory { diff --git a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp index 0c324bf..73b496a 100644 --- a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp +++ b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp @@ -28,6 +28,7 @@ #include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/IBB.h> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/Override.h> #include <Swiften/Base/IDGenerator.h> #include <Swiften/EventLoop/DummyEventLoop.h> #include <Swiften/Network/PlatformNATTraversalWorker.h> @@ -87,14 +88,6 @@ public: class OFakeLocalJingleTransportCandidateGenerator : public LocalJingleTransportCandidateGenerator { public: - virtual void generateLocalTransportCandidates(JingleTransportPayload::ref /* payload */) { - //JingleTransportPayload::ref payL = make_shared<JingleTransportPayload>(); - //payL->setSessionID(payload->getSessionID()); - JingleS5BTransportPayload::ref payL = boost::make_shared<JingleS5BTransportPayload>(); - - onLocalTransportCandidatesGenerated(payL); - } - void emitonLocalTransportCandidatesGenerated(JingleTransportPayload::ref payload) { onLocalTransportCandidatesGenerated(payload); } @@ -110,6 +103,16 @@ public: virtual JingleTransport::ref selectTransport(JingleTransportPayload::ref) { return JingleTransport::ref(); } + + virtual void start(JingleTransportPayload::ref /* payload */) SWIFTEN_OVERRIDE { + //JingleTransportPayload::ref payL = make_shared<JingleTransportPayload>(); + //payL->setSessionID(payload->getSessionID()); + JingleS5BTransportPayload::ref payL = boost::make_shared<JingleS5BTransportPayload>(); + + onLocalTransportCandidatesGenerated(payL); + } + + virtual void stop() SWIFTEN_OVERRIDE {} }; class OFakeLocalJingleTransportCandidateGeneratorFactory : public LocalJingleTransportCandidateGeneratorFactory { diff --git a/Swiften/Network/NATTraversalForwardPortRequest.h b/Swiften/Network/NATTraversalForwardPortRequest.h index 35b23c4..48f85ea 100644 --- a/Swiften/Network/NATTraversalForwardPortRequest.h +++ b/Swiften/Network/NATTraversalForwardPortRequest.h @@ -16,7 +16,8 @@ namespace Swift { public: virtual ~NATTraversalForwardPortRequest(); - virtual void run() = 0; + virtual void start() = 0; + virtual void stop() = 0; boost::signal<void (boost::optional<NATPortMapping>)> onResult; }; diff --git a/Swiften/Network/NATTraversalGetPublicIPRequest.h b/Swiften/Network/NATTraversalGetPublicIPRequest.h index db1f005..1270db3 100644 --- a/Swiften/Network/NATTraversalGetPublicIPRequest.h +++ b/Swiften/Network/NATTraversalGetPublicIPRequest.h @@ -14,7 +14,8 @@ namespace Swift { public: virtual ~NATTraversalGetPublicIPRequest(); - virtual void run() = 0; + virtual void start() = 0; + virtual void stop() = 0; boost::signal<void (boost::optional<HostAddress>)> onResult; }; diff --git a/Swiften/Network/NATTraversalRemovePortForwardingRequest.h b/Swiften/Network/NATTraversalRemovePortForwardingRequest.h index c82ae03..210cbcb 100644 --- a/Swiften/Network/NATTraversalRemovePortForwardingRequest.h +++ b/Swiften/Network/NATTraversalRemovePortForwardingRequest.h @@ -27,7 +27,8 @@ namespace Swift { public: virtual ~NATTraversalRemovePortForwardingRequest(); - virtual void run() = 0; + virtual void start() = 0; + virtual void stop() = 0; boost::signal<void (boost::optional<bool> /* failure */)> onResult; }; diff --git a/Swiften/Network/NullNATTraverser.cpp b/Swiften/Network/NullNATTraverser.cpp index 8cb35cd..43fcd08 100644 --- a/Swiften/Network/NullNATTraverser.cpp +++ b/Swiften/Network/NullNATTraverser.cpp @@ -21,10 +21,13 @@ class NullNATTraversalGetPublicIPRequest : public NATTraversalGetPublicIPRequest NullNATTraversalGetPublicIPRequest(EventLoop* eventLoop) : eventLoop(eventLoop) { } - virtual void run() { + virtual void start() { eventLoop->postEvent(boost::bind(boost::ref(onResult), boost::optional<HostAddress>())); } + virtual void stop() { + } + private: EventLoop* eventLoop; }; @@ -34,10 +37,13 @@ class NullNATTraversalForwardPortRequest : public NATTraversalForwardPortRequest NullNATTraversalForwardPortRequest(EventLoop* eventLoop) : eventLoop(eventLoop) { } - virtual void run() { + virtual void start() { eventLoop->postEvent(boost::bind(boost::ref(onResult), boost::optional<NATPortMapping>())); } + virtual void stop() { + } + private: EventLoop* eventLoop; }; @@ -47,10 +53,13 @@ class NullNATTraversalRemovePortForwardingRequest : public NATTraversalRemovePor NullNATTraversalRemovePortForwardingRequest(EventLoop* eventLoop) : eventLoop(eventLoop) { } - virtual void run() { + virtual void start() { eventLoop->postEvent(boost::bind(boost::ref(onResult), boost::optional<bool>(true))); } + virtual void stop() { + } + private: EventLoop* eventLoop; }; diff --git a/Swiften/Network/PlatformNATTraversalWorker.cpp b/Swiften/Network/PlatformNATTraversalWorker.cpp index eeecb38..40d6da6 100644 --- a/Swiften/Network/PlatformNATTraversalWorker.cpp +++ b/Swiften/Network/PlatformNATTraversalWorker.cpp @@ -50,10 +50,14 @@ class PlatformNATTraversalGetPublicIPRequest : public NATTraversalGetPublicIPReq PlatformNATTraversalGetPublicIPRequest(PlatformNATTraversalWorker* worker) : PlatformNATTraversalRequest(worker) { } - virtual void run() { + virtual void start() { doRun(); } + virtual void stop() { + // TODO + } + virtual void runBlocking() { onResult(getNATTraversalInterface()->getPublicIP()); } @@ -64,10 +68,14 @@ class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortReq PlatformNATTraversalForwardPortRequest(PlatformNATTraversalWorker* worker, unsigned int localIP, unsigned int publicIP) : PlatformNATTraversalRequest(worker), localIP(localIP), publicIP(publicIP) { } - virtual void run() { + virtual void start() { doRun(); } + virtual void stop() { + // TODO + } + virtual void runBlocking() { onResult(getNATTraversalInterface()->addPortForward(boost::numeric_cast<int>(localIP), boost::numeric_cast<int>(publicIP))); } @@ -82,10 +90,14 @@ class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemov PlatformNATTraversalRemovePortForwardingRequest(PlatformNATTraversalWorker* worker, const NATPortMapping& mapping) : PlatformNATTraversalRequest(worker), mapping(mapping) { } - virtual void run() { + virtual void start() { doRun(); } + virtual void stop() { + // TODO + } + virtual void runBlocking() { onResult(getNATTraversalInterface()->removePortForward(mapping)); } @@ -96,7 +108,8 @@ class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemov PlatformNATTraversalWorker::PlatformNATTraversalWorker(EventLoop* eventLoop) : eventLoop(eventLoop), stopRequested(false), natPMPSupported(boost::logic::indeterminate), natPMPInterface(NULL), miniUPnPSupported(boost::logic::indeterminate), miniUPnPInterface(NULL) { nullNATTraversalInterface = new NullNATTraversalInterface(); - thread = new boost::thread(boost::bind(&PlatformNATTraversalWorker::run, this)); + // FIXME: This should be done from start(), and the current start() should be an internal method + thread = new boost::thread(boost::bind(&PlatformNATTraversalWorker::start, this)); } PlatformNATTraversalWorker::~PlatformNATTraversalWorker() { @@ -143,7 +156,7 @@ boost::shared_ptr<NATTraversalRemovePortForwardingRequest> PlatformNATTraversalW return boost::make_shared<PlatformNATTraversalRemovePortForwardingRequest>(this, mapping); } -void PlatformNATTraversalWorker::run() { +void PlatformNATTraversalWorker::start() { while (!stopRequested) { PlatformNATTraversalRequest::ref request; { @@ -162,6 +175,10 @@ void PlatformNATTraversalWorker::run() { } } +void PlatformNATTraversalWorker::stop() { + // TODO +} + void PlatformNATTraversalWorker::addRequestToQueue(PlatformNATTraversalRequest::ref request) { { boost::lock_guard<boost::mutex> lock(queueMutex); diff --git a/Swiften/Network/PlatformNATTraversalWorker.h b/Swiften/Network/PlatformNATTraversalWorker.h index 8060e31..6148705 100644 --- a/Swiften/Network/PlatformNATTraversalWorker.h +++ b/Swiften/Network/PlatformNATTraversalWorker.h @@ -43,7 +43,8 @@ namespace Swift { private: NATTraversalInterface* getNATTraversalInterface() const; void addRequestToQueue(boost::shared_ptr<PlatformNATTraversalRequest>); - void run(); + void start(); + void stop(); private: EventLoop* eventLoop; -- cgit v0.10.2-6-g49f6