From 732253a9b3e88b99b36dd3298157cf502f743294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Thu, 22 Dec 2011 16:46:23 +0100 Subject: BOSH Refactoring. 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 #include #include -#include 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(boost::make_shared(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(new BOSHSessionStream(boost::make_shared(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(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 -#include - -namespace Swift { - -BOSHConnectionFactory::BOSHConnectionFactory(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* xmlParserFactory, TLSContextFactory* tlsFactory) : boshURL(boshURL), connectionFactory(connectionFactory), xmlParserFactory(xmlParserFactory), tlsFactory(tlsFactory) { - -} - -boost::shared_ptr 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 - -#include -#include -#include -#include - -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 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 namespace Swift { -BOSHConnectionPool::BOSHConnectionPool(boost::shared_ptr 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 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 BOSHConnectionPool::createConnection() { - BOSHConnection::ref connection = boost::dynamic_pointer_cast(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 #include -#include #include namespace Swift { class HTTPConnectProxiedConnectionFactory; class TLSConnectionFactory; + class BOSHConnectionPool : public boost::bsignals::trackable { public: - BOSHConnectionPool(boost::shared_ptr 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 connectionFactory; + URL boshURL; + ConnectionFactory* connectionFactory; + XMLParserFactory* xmlParserFactory; + TLSContextFactory* tlsFactory; std::vector 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 #include #include -#include #include #include #include @@ -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(URL("http", to, 5280, path), connectionFactory, &parserFactory, static_cast(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(URL("http", to, 5280, path), connectionFactory, &parserFactory, static_cast(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(factory, to, initialRID, URL(), "", ""); + PoolRef pool = boost::make_shared(boshURL, connectionFactory, &parserFactory, static_cast(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 xmppDataRead; @@ -413,7 +412,6 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture { std::string sid; std::string initial; long initialRID; - boost::shared_ptr 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 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 dist(0, LONG_MAX); + boost::uniform_int dist(0, (1LL<<53) - 1); random.seed(time(NULL)); - boost::variate_generator > randomRID(random, dist); - long initialRID = randomRID(); + long long initialRID = boost::variate_generator >(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 #include #include -#include #include #include #include @@ -31,17 +30,18 @@ namespace Swift { class BOSHSessionStream : public SessionStream, public EventOwner, public boost::enable_shared_from_this { public: BOSHSessionStream( - boost::shared_ptr 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(); -- cgit v0.10.2-6-g49f6