summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2018-06-19 13:57:06 (GMT)
committerKevin Smith <git@kismith.co.uk>2018-06-19 15:57:25 (GMT)
commit83434963a7b10b759ffe3fdc1312efdef282a450 (patch)
tree7cf46b95fc0327cc338259f07e10d609c6ed4c68 /Swiften/Network
parentddc60687e44209d136c63776b5dc714791b41436 (diff)
downloadswift-83434963a7b10b759ffe3fdc1312efdef282a450.zip
swift-83434963a7b10b759ffe3fdc1312efdef282a450.tar.bz2
Don't double-connect to IP literals
Before this change, an IP literal would be attempted directly, and if that failed it would then 'resolve' the literal and try the result. Test-Information: Added a unit test verifying the bug before fixing it. Change-Id: Ic887c74152f5a4b259392dad402952b3777268b1
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/Connector.cpp2
-rw-r--r--Swiften/Network/StaticDomainNameResolver.cpp4
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp21
3 files changed, 25 insertions, 2 deletions
diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp
index 5eddaba..ca924bb 100644
--- a/Swiften/Network/Connector.cpp
+++ b/Swiften/Network/Connector.cpp
@@ -31,3 +31,2 @@ void Connector::start() {
assert(!timer);
- queriedAllServices = false;
auto hostAddress = HostAddress::fromString(hostname);
@@ -38,2 +37,3 @@ void Connector::start() {
if (serviceLookupPrefix) {
+ queriedAllServices = false;
serviceQuery = resolver->createServiceQuery(*serviceLookupPrefix, hostname);
diff --git a/Swiften/Network/StaticDomainNameResolver.cpp b/Swiften/Network/StaticDomainNameResolver.cpp
index 95b3dd9..b8f4c7a 100644
--- a/Swiften/Network/StaticDomainNameResolver.cpp
+++ b/Swiften/Network/StaticDomainNameResolver.cpp
@@ -52,2 +52,6 @@ namespace {
}
+ if (auto address = HostAddress::fromString(host)) {
+ // IP Literals should resolve to themselves
+ resolver->addAddress(host, *address);
+ }
StaticDomainNameResolver::AddressesMap::const_iterator i = resolver->getAddresses().find(host);
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 8524439..658aaf7 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.cpp
@@ -28,2 +28,3 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testConnect_NoServiceLookups_DefaultPort);
+ CPPUNIT_TEST(testConnect_OnlyLiteral);
CPPUNIT_TEST(testConnect_FirstAddressHostFails);
@@ -121,2 +122,17 @@ class ConnectorTest : public CppUnit::TestFixture {
+ void testConnect_OnlyLiteral() {
+ auto testling = Connector::create("1.1.1.1", 1234, boost::none, resolver, connectionFactory, timerFactory);
+ testling->onConnectFinished.connect(boost::bind(&ConnectorTest::handleConnectorFinished, this, _1, _2));
+
+ auto address1 = HostAddress::fromString("1.1.1.1").get();
+ connectionFactory->failingPorts.push_back(HostAddressPort(address1, 1234));
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(!connections[0]);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connectionFactory->createdConnections.size()));
+ }
+
void testConnect_FirstAddressHostFails() {
@@ -358,3 +374,5 @@ class ConnectorTest : public CppUnit::TestFixture {
std::shared_ptr<Connection> createConnection() {
- return std::make_shared<MockConnection>(failingPorts, isResponsive, eventLoop);
+ auto connection = std::make_shared<MockConnection>(failingPorts, isResponsive, eventLoop);
+ createdConnections.push_back(connection);
+ return connection;
}
@@ -364,2 +382,3 @@ class ConnectorTest : public CppUnit::TestFixture {
std::vector<HostAddressPort> failingPorts;
+ std::vector<std::shared_ptr<MockConnection>> createdConnections;
};