diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-12-22 15:46:23 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-12-22 16:53:18 (GMT) |
commit | 732253a9b3e88b99b36dd3298157cf502f743294 (patch) | |
tree | 3471f2d999dfe3cb2ae8f5aec5bdd7b3d1465078 | |
parent | 6c1e7d8a8339a849896566464bd9f1db33e3b3da (diff) | |
download | swift-contrib-732253a9b3e88b99b36dd3298157cf502f743294.zip swift-contrib-732253a9b3e88b99b36dd3298157cf502f743294.tar.bz2 |
BOSH Refactoring.
-rw-r--r-- | Swiften/Client/CoreClient.cpp | 15 | ||||
-rw-r--r-- | Swiften/Network/BOSHConnectionFactory.cpp | 26 | ||||
-rw-r--r-- | Swiften/Network/BOSHConnectionFactory.h | 43 | ||||
-rw-r--r-- | Swiften/Network/BOSHConnectionPool.cpp | 13 | ||||
-rw-r--r-- | Swiften/Network/BOSHConnectionPool.h | 9 | ||||
-rw-r--r-- | Swiften/Network/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp | 10 | ||||
-rw-r--r-- | Swiften/Session/BOSHSessionStream.cpp | 10 | ||||
-rw-r--r-- | Swiften/Session/BOSHSessionStream.h | 24 |
9 files changed, 48 insertions, 103 deletions
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp index cef2b24..49fb9fa 100644 --- a/Swiften/Client/CoreClient.cpp +++ b/Swiften/Client/CoreClient.cpp @@ -25,7 +25,6 @@ #include <Swiften/Client/ClientSessionStanzaChannel.h> #include <Swiften/Network/SOCKS5ProxiedConnectionFactory.h> #include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h> -#include <Swiften/Network/BOSHConnectionFactory.h> namespace Swift { @@ -83,7 +82,19 @@ void CoreClient::connect(const std::string& host) { * it would be quite painful given that potentially every stanza could be sent on a new connection. */ //sessionStream_ = boost::make_shared<BOSHSessionStream>(boost::make_shared<BOSHConnectionFactory>(options.boshURL, networkFactories->getConnectionFactory(), networkFactories->getXMLParserFactory(), networkFactories->getTLSContextFactory()), getPayloadParserFactories(), getPayloadSerializers(), networkFactories->getTLSContextFactory(), networkFactories->getTimerFactory(), networkFactories->getXMLParserFactory(), networkFactories->getEventLoop(), host, options.boshHTTPConnectProxyURL, options.boshHTTPConnectProxyAuthID, options.boshHTTPConnectProxyAuthPassword); - sessionStream_ = boost::shared_ptr<BOSHSessionStream>(new BOSHSessionStream(boost::make_shared<BOSHConnectionFactory>(options.boshURL, networkFactories->getConnectionFactory(), networkFactories->getXMLParserFactory(), networkFactories->getTLSContextFactory()), getPayloadParserFactories(), getPayloadSerializers(), networkFactories->getTLSContextFactory(), networkFactories->getTimerFactory(), networkFactories->getXMLParserFactory(), networkFactories->getEventLoop(), host, options.boshHTTPConnectProxyURL, options.boshHTTPConnectProxyAuthID, options.boshHTTPConnectProxyAuthPassword)); + sessionStream_ = boost::shared_ptr<BOSHSessionStream>(new BOSHSessionStream( + options.boshURL, + getPayloadParserFactories(), + getPayloadSerializers(), + networkFactories->getConnectionFactory(), + networkFactories->getTLSContextFactory(), + networkFactories->getTimerFactory(), + networkFactories->getXMLParserFactory(), + networkFactories->getEventLoop(), + host, + options.boshHTTPConnectProxyURL, + options.boshHTTPConnectProxyAuthID, + options.boshHTTPConnectProxyAuthPassword)); sessionStream_->onDataRead.connect(boost::bind(&CoreClient::handleDataRead, this, _1)); sessionStream_->onDataWritten.connect(boost::bind(&CoreClient::handleDataWritten, this, _1)); bindSessionToStream(); diff --git a/Swiften/Network/BOSHConnectionFactory.cpp b/Swiften/Network/BOSHConnectionFactory.cpp deleted file mode 100644 index 7b83034..0000000 --- a/Swiften/Network/BOSHConnectionFactory.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2011 Thilo Cestonaro - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -/* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#include <Swiften/Network/BOSHConnectionFactory.h> -#include <Swiften/Network/BOSHConnection.h> - -namespace Swift { - -BOSHConnectionFactory::BOSHConnectionFactory(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* xmlParserFactory, TLSContextFactory* tlsFactory) : boshURL(boshURL), connectionFactory(connectionFactory), xmlParserFactory(xmlParserFactory), tlsFactory(tlsFactory) { - -} - -boost::shared_ptr<Connection> BOSHConnectionFactory::createConnection(ConnectionFactory* overrideFactory) { - return BOSHConnection::create(boshURL, overrideFactory != NULL ? overrideFactory : connectionFactory, xmlParserFactory, tlsFactory); -} - -} diff --git a/Swiften/Network/BOSHConnectionFactory.h b/Swiften/Network/BOSHConnectionFactory.h deleted file mode 100644 index 3750057..0000000 --- a/Swiften/Network/BOSHConnectionFactory.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2011 Thilo Cestonaro - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -/* - * Copyright (c) 2011 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#pragma once - -#include <string> - -#include <Swiften/Network/ConnectionFactory.h> -#include <Swiften/Network/HostAddressPort.h> -#include <Swiften/TLS/TLSContextFactory.h> -#include <Swiften/Base/URL.h> - -namespace Swift { - -class XMLParserFactory; - -class BOSHConnectionFactory { - public: - BOSHConnectionFactory(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* xmlParserFactory, TLSContextFactory* tlsFactory); - - /** - * @param overrideFactory If non-NULL, creates a connection over the given factory instead. - */ - boost::shared_ptr<Connection> createConnection(ConnectionFactory* overrideFactory); - ConnectionFactory* getRawConnectionFactory() {return connectionFactory;} - TLSContextFactory* getTLSContextFactory() {return tlsFactory;} - private: - URL boshURL; - ConnectionFactory* connectionFactory; - XMLParserFactory* xmlParserFactory; - TLSContextFactory* tlsFactory; -}; - -} diff --git a/Swiften/Network/BOSHConnectionPool.cpp b/Swiften/Network/BOSHConnectionPool.cpp index 6c3ba7e..4886ede 100644 --- a/Swiften/Network/BOSHConnectionPool.cpp +++ b/Swiften/Network/BOSHConnectionPool.cpp @@ -16,8 +16,11 @@ #include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h> namespace Swift { -BOSHConnectionPool::BOSHConnectionPool(boost::shared_ptr<BOSHConnectionFactory> connectionFactory, const std::string& to, long initialRID, const URL& boshHTTPConnectProxyURL, const SafeString& boshHTTPConnectProxyAuthID, const SafeString& boshHTTPConnectProxyAuthPassword) - : connectionFactory(connectionFactory), +BOSHConnectionPool::BOSHConnectionPool(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* parserFactory, TLSContextFactory* tlsFactory, const std::string& to, long initialRID, const URL& boshHTTPConnectProxyURL, const SafeString& boshHTTPConnectProxyAuthID, const SafeString& boshHTTPConnectProxyAuthPassword) : + boshURL(boshURL), + connectionFactory(connectionFactory), + xmlParserFactory(parserFactory), + tlsFactory(tlsFactory), rid(initialRID), pendingTerminate(false), to(to), @@ -29,9 +32,9 @@ BOSHConnectionPool::BOSHConnectionPool(boost::shared_ptr<BOSHConnectionFactory> connectProxyFactory = NULL; } else { - ConnectionFactory* rawFactory = connectionFactory->getRawConnectionFactory(); + ConnectionFactory* rawFactory = connectionFactory; if (boshHTTPConnectProxyURL.getScheme() == "https") { - tlsConnectionFactory = new TLSConnectionFactory(connectionFactory->getTLSContextFactory(), rawFactory); + tlsConnectionFactory = new TLSConnectionFactory(tlsFactory, rawFactory); rawFactory = tlsConnectionFactory; } connectProxyFactory = new HTTPConnectProxiedConnectionFactory(rawFactory, HostAddressPort(HostAddress(boshHTTPConnectProxyURL.getHost()), boshHTTPConnectProxyURL.getPort()), boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword); @@ -206,7 +209,7 @@ void BOSHConnectionPool::handleConnectionDisconnected(const boost::optional<Conn } boost::shared_ptr<BOSHConnection> BOSHConnectionPool::createConnection() { - BOSHConnection::ref connection = boost::dynamic_pointer_cast<BOSHConnection>(connectionFactory->createConnection(connectProxyFactory)); + BOSHConnection::ref connection = BOSHConnection::create(boshURL, connectProxyFactory ? connectProxyFactory : connectionFactory, xmlParserFactory, tlsFactory); connection->onXMPPDataRead.connect(boost::bind(&BOSHConnectionPool::handleDataRead, this, _1)); connection->onSessionStarted.connect(boost::bind(&BOSHConnectionPool::handleSessionStarted, this, _1, _2)); connection->onBOSHDataRead.connect(boost::bind(&BOSHConnectionPool::handleBOSHDataRead, this, _1)); diff --git a/Swiften/Network/BOSHConnectionPool.h b/Swiften/Network/BOSHConnectionPool.h index 85e598d..2264c90 100644 --- a/Swiften/Network/BOSHConnectionPool.h +++ b/Swiften/Network/BOSHConnectionPool.h @@ -10,15 +10,15 @@ #include <vector> #include <Swiften/Base/SafeString.h> -#include <Swiften/Network/BOSHConnectionFactory.h> #include <Swiften/Network/BOSHConnection.h> namespace Swift { class HTTPConnectProxiedConnectionFactory; class TLSConnectionFactory; + class BOSHConnectionPool : public boost::bsignals::trackable { public: - BOSHConnectionPool(boost::shared_ptr<BOSHConnectionFactory> factory, const std::string& to, long initialRID, const URL& boshHTTPConnectProxyURL, const SafeString& boshHTTPConnectProxyAuthID, const SafeString& boshHTTPConnectProxyAuthPassword); + BOSHConnectionPool(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* parserFactory, TLSContextFactory* tlsFactory, const std::string& to, long initialRID, const URL& boshHTTPConnectProxyURL, const SafeString& boshHTTPConnectProxyAuthID, const SafeString& boshHTTPConnectProxyAuthPassword); ~BOSHConnectionPool(); void write(const SafeByteArray& data); void writeFooter(); @@ -48,7 +48,10 @@ namespace Swift { BOSHConnection::ref getSuitableConnection(); private: - boost::shared_ptr<BOSHConnectionFactory> connectionFactory; + URL boshURL; + ConnectionFactory* connectionFactory; + XMLParserFactory* xmlParserFactory; + TLSContextFactory* tlsFactory; std::vector<BOSHConnection::ref> connections; std::string sid; unsigned long rid; diff --git a/Swiften/Network/SConscript b/Swiften/Network/SConscript index 4a5370f..6975fe6 100644 --- a/Swiften/Network/SConscript +++ b/Swiften/Network/SConscript @@ -17,7 +17,6 @@ sourceList = [ "BoostIOServiceThread.cpp", "BOSHConnection.cpp", "BOSHConnectionPool.cpp", - "BOSHConnectionFactory.cpp", "ConnectionFactory.cpp", "ConnectionServer.cpp", "ConnectionServerFactory.cpp", diff --git a/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp b/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp index 978bf3b..1bfee10 100644 --- a/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp +++ b/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp @@ -19,7 +19,6 @@ #include <Swiften/Network/Connection.h> #include <Swiften/Network/ConnectionFactory.h> #include <Swiften/Network/BOSHConnection.h> -#include <Swiften/Network/BOSHConnectionFactory.h> #include <Swiften/Network/BOSHConnectionPool.h> #include <Swiften/Network/HostAddressPort.h> #include <Swiften/EventLoop/DummyEventLoop.h> @@ -58,7 +57,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture { "xmlns='http://jabber.org/protocol/httpbind'/>"; eventLoop = new DummyEventLoop(); connectionFactory = new MockConnectionFactory(eventLoop); - factory = boost::make_shared<BOSHConnectionFactory>(URL("http", to, 5280, path), connectionFactory, &parserFactory, static_cast<TLSContextFactory*>(NULL)); + boshURL = URL("http", to, 5280, path); sessionTerminated = 0; sessionStarted = 0; initialRID = 2349876; @@ -216,8 +215,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture { void testSession() { to = "prosody.doomsong.co.uk"; path = "http-bind/"; - factory = boost::make_shared<BOSHConnectionFactory>(URL("http", to, 5280, path), connectionFactory, &parserFactory, static_cast<TLSContextFactory*>(NULL)); - + boshURL = URL("http", to, 5280, path); PoolRef testling = createTestling(); CPPUNIT_ASSERT_EQUAL(st(1), connectionFactory->connections.size()); @@ -281,7 +279,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture { private: PoolRef createTestling() { - PoolRef pool = boost::make_shared<BOSHConnectionPool>(factory, to, initialRID, URL(), "", ""); + PoolRef pool = boost::make_shared<BOSHConnectionPool>(boshURL, connectionFactory, &parserFactory, static_cast<TLSContextFactory*>(NULL), to, initialRID, URL(), "", ""); pool->onXMPPDataRead.connect(boost::bind(&BOSHConnectionPoolTest::handleXMPPDataRead, this, _1)); pool->onBOSHDataRead.connect(boost::bind(&BOSHConnectionPoolTest::handleBOSHDataRead, this, _1)); pool->onBOSHDataWritten.connect(boost::bind(&BOSHConnectionPoolTest::handleBOSHDataWritten, this, _1)); @@ -401,6 +399,7 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture { } private: + URL boshURL; DummyEventLoop* eventLoop; MockConnectionFactory* connectionFactory; std::vector<std::string> xmppDataRead; @@ -413,7 +412,6 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture { std::string sid; std::string initial; long initialRID; - boost::shared_ptr<BOSHConnectionFactory> factory; int sessionStarted; int sessionTerminated; diff --git a/Swiften/Session/BOSHSessionStream.cpp b/Swiften/Session/BOSHSessionStream.cpp index 73bbfd6..f53b8e1 100644 --- a/Swiften/Session/BOSHSessionStream.cpp +++ b/Swiften/Session/BOSHSessionStream.cpp @@ -27,9 +27,10 @@ namespace Swift { BOSHSessionStream::BOSHSessionStream( - boost::shared_ptr<BOSHConnectionFactory> connectionFactory, /*FIXME: probably rip out*/ + const URL& boshURL, PayloadParserFactoryCollection* payloadParserFactories, PayloadSerializerCollection* payloadSerializers, + ConnectionFactory* connectionFactory, TLSContextFactory* tlsContextFactory, TimerFactory* timerFactory, XMLParserFactory* xmlParserFactory, @@ -48,12 +49,11 @@ BOSHSessionStream::BOSHSessionStream( firstHeader(true) { boost::mt19937 random; - boost::uniform_int<long> dist(0, LONG_MAX); + boost::uniform_int<long long> dist(0, (1LL<<53) - 1); random.seed(time(NULL)); - boost::variate_generator<boost::mt19937&, boost::uniform_int<long> > randomRID(random, dist); - long initialRID = randomRID(); + long long initialRID = boost::variate_generator<boost::mt19937&, boost::uniform_int<long long> >(random, dist)(); - connectionPool = new BOSHConnectionPool(connectionFactory, to, initialRID, boshHTTPConnectProxyURL, boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword); + connectionPool = new BOSHConnectionPool(boshURL, connectionFactory, xmlParserFactory, tlsContextFactory, to, initialRID, boshHTTPConnectProxyURL, boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword); connectionPool->onSessionTerminated.connect(boost::bind(&BOSHSessionStream::handlePoolSessionTerminated, this, _1)); connectionPool->onSessionStarted.connect(boost::bind(&BOSHSessionStream::handlePoolSessionStarted, this)); connectionPool->onXMPPDataRead.connect(boost::bind(&BOSHSessionStream::handlePoolXMPPDataRead, this, _1)); diff --git a/Swiften/Session/BOSHSessionStream.h b/Swiften/Session/BOSHSessionStream.h index 75c1f2a..c3f6220 100644 --- a/Swiften/Session/BOSHSessionStream.h +++ b/Swiften/Session/BOSHSessionStream.h @@ -11,7 +11,6 @@ #include <Swiften/Base/SafeString.h> #include <Swiften/Base/SafeByteArray.h> #include <Swiften/Network/BOSHConnectionPool.h> -#include <Swiften/Network/BOSHConnectionFactory.h> #include <Swiften/Session/SessionStream.h> #include <Swiften/Elements/StreamType.h> #include <Swiften/EventLoop/EventOwner.h> @@ -31,17 +30,18 @@ namespace Swift { class BOSHSessionStream : public SessionStream, public EventOwner, public boost::enable_shared_from_this<BOSHSessionStream> { public: BOSHSessionStream( - boost::shared_ptr<BOSHConnectionFactory> connectionFactory, - PayloadParserFactoryCollection* payloadParserFactories, - PayloadSerializerCollection* payloadSerializers, - TLSContextFactory* tlsContextFactory, - TimerFactory* whitespacePingLayerFactory, - XMLParserFactory* xmlParserFactory, - EventLoop* eventLoop, - const std::string& to, - const URL& boshHTTPConnectProxyURL, - const SafeString& boshHTTPConnectProxyAuthID, - const SafeString& boshHTTPConnectProxyAuthPassword + const URL& boshURL, + PayloadParserFactoryCollection* payloadParserFactories, + PayloadSerializerCollection* payloadSerializers, + ConnectionFactory* connectionFactory, + TLSContextFactory* tlsContextFactory, + TimerFactory* whitespacePingLayerFactory, + XMLParserFactory* xmlParserFactory, + EventLoop* eventLoop, + const std::string& to, + const URL& boshHTTPConnectProxyURL, + const SafeString& boshHTTPConnectProxyAuthID, + const SafeString& boshHTTPConnectProxyAuthPassword ); ~BOSHSessionStream(); |