Browse Source

Renamed UDP and TCP server classes

develop
Robin Thoni 6 years ago
parent
commit
c83fe8b662

+ 5
- 5
src/main.cpp View File

@@ -1,7 +1,7 @@
1 1
 #include <iostream>
2 2
 #include <QCoreApplication>
3
-#include "dns-server/QUdpDnsServer.h"
4
-#include "dns-server/QTcpDnsServer.h"
3
+#include "dns-server/QDnsUdpServer.h"
4
+#include "dns-server/QDnsTcpServer.h"
5 5
 #include "dns-base/QDnsBase.h"
6 6
 
7 7
 int main(int argc, char* argv[])
@@ -11,7 +11,7 @@ int main(int argc, char* argv[])
11 11
     QHostAddress bindAddress("127.0.0.1");
12 12
     quint16 bindPort = 5053;
13 13
 
14
-    auto onRequest = [](QDns::Server::QUdpDnsServer::OnRequestParams params)
14
+    auto onRequest = [](QDns::Server::QDnsUdpServer::OnRequestParams params)
15 15
     {
16 16
         QDns::Base::QDnsPacket answer = params.packet.makeAnswer();
17 17
         auto header = answer.getHeader();
@@ -24,11 +24,11 @@ int main(int argc, char* argv[])
24 24
                                   });
25 25
     };
26 26
 
27
-    QDns::Server::QTcpDnsServer tcpServer;
27
+    QDns::Server::QDnsTcpServer tcpServer;
28 28
     tcpServer.start(bindAddress, bindPort);
29 29
     QObject::connect(&tcpServer, &QDns::Server::QDnsServer::onRequest, onRequest);
30 30
 
31
-    QDns::Server::QUdpDnsServer udpServer;
31
+    QDns::Server::QDnsUdpServer udpServer;
32 32
     udpServer.start(bindAddress, bindPort);
33 33
     QObject::connect(&udpServer, &QDns::Server::QDnsServer::onRequest, onRequest);
34 34
 

+ 6
- 6
src/modules/dns-server/CMakeLists.txt View File

@@ -14,12 +14,12 @@ find_package(Qt5Network REQUIRED)
14 14
 add_library(${PROJECT_NAME}
15 15
         src/QDnsServer.cpp
16 16
         includes/dns-server/QDnsServer.h
17
-        src/QUdpDnsServer.cpp
18
-        includes/dns-server/QUdpDnsServer.h
19
-        src/QTcpDnsServer.cpp
20
-        includes/dns-server/QTcpDnsServer.h
21
-        src/QTcpDnsServerClient.cpp
22
-        src/QTcpDnsServerClient.h)
17
+        src/QDnsUdpServer.cpp
18
+        includes/dns-server/QDnsUdpServer.h
19
+        src/QDnsTcpServer.cpp
20
+        includes/dns-server/QDnsTcpServer.h
21
+        src/QDnsTcpServerClient.cpp
22
+        src/QDnsTcpServerClient.h)
23 23
 
24 24
 target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network qdnsagg-dns-base)
25 25
 

src/modules/dns-server/includes/dns-server/QTcpDnsServer.h → src/modules/dns-server/includes/dns-server/QDnsTcpServer.h View File

@@ -12,13 +12,13 @@ namespace QDns
12 12
 {
13 13
     namespace Server
14 14
     {
15
-        class QTcpDnsServerClient;
15
+        class QDnsTcpServerClient;
16 16
 
17
-        class QTcpDnsServer : public QDnsServer
17
+        class QDnsTcpServer : public QDnsServer
18 18
         {
19 19
             Q_OBJECT
20 20
         public:
21
-            QTcpDnsServer();
21
+            QDnsTcpServer();
22 22
 
23 23
         public slots:
24 24
             bool start(const QHostAddress& host, quint16 port) override;
@@ -29,7 +29,7 @@ namespace QDns
29 29
         private:
30 30
             QTcpServer* m_socket;
31 31
 
32
-            QList<QTcpDnsServerClient*> m_clients;
32
+            QList<QDnsTcpServerClient*> m_clients;
33 33
         };
34 34
     }
35 35
 }

src/modules/dns-server/includes/dns-server/QUdpDnsServer.h → src/modules/dns-server/includes/dns-server/QDnsUdpServer.h View File

@@ -14,11 +14,11 @@ namespace QDns
14 14
 {
15 15
     namespace Server
16 16
     {
17
-        class QUdpDnsServer : public QDnsServer
17
+        class QDnsUdpServer : public QDnsServer
18 18
         {
19 19
             Q_OBJECT
20 20
         public:
21
-            QUdpDnsServer();
21
+            QDnsUdpServer();
22 22
 
23 23
         public slots:
24 24
             bool start(const QHostAddress& host, quint16 port) override;

src/modules/dns-server/src/QTcpDnsServer.cpp → src/modules/dns-server/src/QDnsTcpServer.cpp View File

@@ -3,38 +3,38 @@
3 3
 //
4 4
 
5 5
 #include <QTcpSocket>
6
-#include "dns-server/QTcpDnsServer.h"
7
-#include "QTcpDnsServerClient.h"
6
+#include "dns-server/QDnsTcpServer.h"
7
+#include "QDnsTcpServerClient.h"
8 8
 
9 9
 namespace QDns
10 10
 {
11 11
     namespace Server
12 12
     {
13
-        QTcpDnsServer::QTcpDnsServer()
13
+        QDnsTcpServer::QDnsTcpServer()
14 14
             : m_socket(new QTcpServer(this))
15 15
         {
16
-            connect(m_socket, &QTcpServer::newConnection, this, &QTcpDnsServer::onNewConnection);
16
+            connect(m_socket, &QTcpServer::newConnection, this, &QDnsTcpServer::onNewConnection);
17 17
         }
18 18
 
19
-        bool QTcpDnsServer::start(const QHostAddress &host, quint16 port)
19
+        bool QDnsTcpServer::start(const QHostAddress &host, quint16 port)
20 20
         {
21 21
             return m_socket->listen(host, port);
22 22
         }
23 23
 
24
-        void QTcpDnsServer::onNewConnection()
24
+        void QDnsTcpServer::onNewConnection()
25 25
         {
26 26
             auto socket = m_socket->nextPendingConnection();
27 27
             if (socket == nullptr)
28 28
             {
29 29
                 return;
30 30
             }
31
-            auto client = new QTcpDnsServerClient(socket, this);
31
+            auto client = new QDnsTcpServerClient(socket, this);
32 32
             connect(socket, &QTcpSocket::disconnected, [client, this]()
33 33
             {
34 34
                 m_clients.removeOne(client);
35 35
                 client->deleteLater();
36 36
             });
37
-            connect(client, &QTcpDnsServerClient::onRequest, [this](QDnsServer::OnRequestParams params)
37
+            connect(client, &QDnsTcpServerClient::onRequest, [this](QDnsServer::OnRequestParams params)
38 38
             {
39 39
                 emit onRequest(params);
40 40
             });

src/modules/dns-server/src/QTcpDnsServerClient.cpp → src/modules/dns-server/src/QDnsTcpServerClient.cpp View File

@@ -2,23 +2,23 @@
2 2
 // Created by robin on 2/1/18.
3 3
 //
4 4
 
5
-#include "QTcpDnsServerClient.h"
5
+#include "QDnsTcpServerClient.h"
6 6
 
7 7
 namespace QDns
8 8
 {
9 9
     namespace Server
10 10
     {
11
-        QTcpDnsServerClient::QTcpDnsServerClient(QTcpSocket *socket, QObject* parent)
11
+        QDnsTcpServerClient::QDnsTcpServerClient(QTcpSocket *socket, QObject* parent)
12 12
             : QObject(parent)
13 13
             , m_socket(socket)
14 14
             , m_size(0)
15 15
         {
16 16
             m_socket->setParent(this);
17
-            connect(m_socket, &QTcpSocket::readyRead, this, &QTcpDnsServerClient::onReadyRead);
17
+            connect(m_socket, &QTcpSocket::readyRead, this, &QDnsTcpServerClient::onReadyRead);
18 18
             // TODO implement timeout (~2 mins, RFC 7766)
19 19
         }
20 20
 
21
-        void QTcpDnsServerClient::sendAnswer(const QDns::Server::QDnsServer::SendAnswerParams &answerParams)
21
+        void QDnsTcpServerClient::sendAnswer(const QDns::Server::QDnsServer::SendAnswerParams &answerParams)
22 22
         {
23 23
             auto answerRaw = answerParams.answer.serialize(); // TODO split packet if too big (>65535)
24 24
             QByteArray size;
@@ -28,7 +28,7 @@ namespace QDns
28 28
             m_socket->write(answerRaw.constData(), answerRaw.size());
29 29
         }
30 30
 
31
-        void QTcpDnsServerClient::onReadyRead()
31
+        void QDnsTcpServerClient::onReadyRead()
32 32
         {
33 33
             m_buffer.append(m_socket->readAll());
34 34
 

src/modules/dns-server/src/QTcpDnsServerClient.h → src/modules/dns-server/src/QDnsTcpServerClient.h View File

@@ -13,11 +13,11 @@ namespace QDns
13 13
 {
14 14
     namespace Server
15 15
     {
16
-        class QTcpDnsServerClient : public QObject
16
+        class QDnsTcpServerClient : public QObject
17 17
         {
18 18
             Q_OBJECT
19 19
         public:
20
-            explicit QTcpDnsServerClient(QTcpSocket* socket, QObject* parent = nullptr);
20
+            explicit QDnsTcpServerClient(QTcpSocket* socket, QObject* parent = nullptr);
21 21
 
22 22
         signals:
23 23
             void onRequest(QDnsServer::OnRequestParams params);

src/modules/dns-server/src/QUdpDnsServer.cpp → src/modules/dns-server/src/QDnsUdpServer.cpp View File

@@ -2,24 +2,24 @@
2 2
 // Created by robin on 1/24/18.
3 3
 //
4 4
 
5
-#include "dns-server/QUdpDnsServer.h"
5
+#include "dns-server/QDnsUdpServer.h"
6 6
 
7 7
 namespace QDns
8 8
 {
9 9
     namespace Server
10 10
     {
11
-        QUdpDnsServer::QUdpDnsServer()
11
+        QDnsUdpServer::QDnsUdpServer()
12 12
             : m_socket(new QUdpSocket(this))
13 13
         {
14
-            connect(m_socket, &QUdpSocket::readyRead, this, &QUdpDnsServer::onSocketReadyRead);
14
+            connect(m_socket, &QUdpSocket::readyRead, this, &QDnsUdpServer::onSocketReadyRead);
15 15
         }
16 16
 
17
-        bool QUdpDnsServer::start(const QHostAddress &host, quint16 port)
17
+        bool QDnsUdpServer::start(const QHostAddress &host, quint16 port)
18 18
         {
19 19
             return m_socket->bind(host, port);
20 20
         }
21 21
 
22
-        void QUdpDnsServer::onSocketReadyRead()
22
+        void QDnsUdpServer::onSocketReadyRead()
23 23
         {
24 24
             while (m_socket->hasPendingDatagrams())
25 25
             {
@@ -46,7 +46,7 @@ namespace QDns
46 46
             }
47 47
         }
48 48
 
49
-        void QUdpDnsServer::sendAnswer(const QDns::Server::QDnsServer::SendAnswerParams& answerParams,
49
+        void QDnsUdpServer::sendAnswer(const QDns::Server::QDnsServer::SendAnswerParams& answerParams,
50 50
                                        const QHostAddress& senderAddress, quint16 senderPort)
51 51
         {
52 52
             auto answerRaw = answerParams.answer.serialize(); // TODO split packet if too big

+ 1
- 1
src/modules/dns-server/tests/CMakeLists.txt View File

@@ -4,7 +4,7 @@ project(qdnsagg-dns-server-tests)
4 4
 add_executable(${PROJECT_NAME}
5 5
         main.cpp
6 6
         UdpDnsServer.cpp
7
-        TcpDnsServer.cpp
7
+        DnsTcpServer.cpp
8 8
         serverTests.h)
9 9
 
10 10
 target_link_libraries(${PROJECT_NAME} gtest pthread qdnsagg-dns-server)

src/modules/dns-server/tests/TcpDnsServer.cpp → src/modules/dns-server/tests/DnsTcpServer.cpp View File

@@ -8,20 +8,20 @@
8 8
 #include <QtCore/QTimer>
9 9
 #include <QtNetwork/QTcpSocket>
10 10
 
11
-#include "dns-server/QTcpDnsServer.h"
11
+#include "dns-server/QDnsTcpServer.h"
12 12
 
13 13
 #include "serverTests.h"
14 14
 
15
-struct TcpDnsServerTestParams
15
+struct DnsTcpServerTestParams
16 16
 {
17 17
     QList<const char*> hexData;
18 18
 };
19 19
 
20
-class TcpDnsServerTest : public ::testing::TestWithParam<TcpDnsServerTestParams>
20
+class DnsTcpServerTest : public ::testing::TestWithParam<DnsTcpServerTestParams>
21 21
 {
22 22
 };
23 23
 
24
-TEST_P(TcpDnsServerTest, simple)
24
+TEST_P(DnsTcpServerTest, simple)
25 25
 {
26 26
     auto params = GetParam();
27 27
     QCoreApplication app(m_argc, m_argv);
@@ -30,7 +30,7 @@ TEST_P(TcpDnsServerTest, simple)
30 30
     QObject::connect(&timer, &QTimer::timeout, qApp, &QCoreApplication::quit);
31 31
     timer.start(1000);
32 32
 
33
-    QDns::Server::QTcpDnsServer server;
33
+    QDns::Server::QDnsTcpServer server;
34 34
     ASSERT_TRUE(server.start(QHostAddress("127.0.0.1"), 5053));
35 35
     QList<QDns::Base::QDnsPacket> packets;
36 36
     QObject::connect(&server, &QDns::Server::QDnsServer::onRequest, [&packets](QDns::Server::QDnsServer::OnRequestParams params)
@@ -62,10 +62,10 @@ TEST_P(TcpDnsServerTest, simple)
62 62
     ASSERT_EQ(packets.size(), expectedPackets.size());
63 63
 }
64 64
 
65
-INSTANTIATE_TEST_CASE_P(TcpDnsServerTestInst,
66
-                        TcpDnsServerTest,
65
+INSTANTIATE_TEST_CASE_P(DnsTcpServerTestInst,
66
+                        DnsTcpServerTest,
67 67
                         ::testing::Values(
68
-                                TcpDnsServerTestParams
68
+                                DnsTcpServerTestParams
69 69
                                         {
70 70
                                                 QList<const char*>()
71 71
                                                         << "e1bc010000010000000000000266720000010001"

+ 8
- 8
src/modules/dns-server/tests/UdpDnsServer.cpp View File

@@ -7,20 +7,20 @@
7 7
 #include <QtCore/QCoreApplication>
8 8
 #include <QtCore/QTimer>
9 9
 
10
-#include "dns-server/QUdpDnsServer.h"
10
+#include "dns-server/QDnsUdpServer.h"
11 11
 
12 12
 #include "serverTests.h"
13 13
 
14
-struct UdpDnsServerTestParams
14
+struct DnsUdpServerTestParams
15 15
 {
16 16
     QList<const char*> hexData;
17 17
 };
18 18
 
19
-class UdpDnsServerTest : public ::testing::TestWithParam<UdpDnsServerTestParams>
19
+class DnsUdpServerTest : public ::testing::TestWithParam<DnsUdpServerTestParams>
20 20
 {
21 21
 };
22 22
 
23
-TEST_P(UdpDnsServerTest, simple)
23
+TEST_P(DnsUdpServerTest, simple)
24 24
 {
25 25
     auto params = GetParam();
26 26
     QCoreApplication app(m_argc, m_argv);
@@ -29,7 +29,7 @@ TEST_P(UdpDnsServerTest, simple)
29 29
     QObject::connect(&timer, &QTimer::timeout, qApp, &QCoreApplication::quit);
30 30
     timer.start(1000);
31 31
 
32
-    QDns::Server::QUdpDnsServer server;
32
+    QDns::Server::QDnsUdpServer server;
33 33
     ASSERT_TRUE(server.start(QHostAddress("127.0.0.1"), 5053));
34 34
     QList<QDns::Base::QDnsPacket> packets;
35 35
     QObject::connect(&server, &QDns::Server::QDnsServer::onRequest, [&packets](QDns::Server::QDnsServer::OnRequestParams params)
@@ -54,10 +54,10 @@ TEST_P(UdpDnsServerTest, simple)
54 54
     ASSERT_EQ(packets.size(), expectedPackets.size());
55 55
 }
56 56
 
57
-INSTANTIATE_TEST_CASE_P(UdpDnsServerTestInst,
58
-                        UdpDnsServerTest,
57
+INSTANTIATE_TEST_CASE_P(DnsUdpServerTestInst,
58
+                        DnsUdpServerTest,
59 59
                         ::testing::Values(
60
-                                UdpDnsServerTestParams
60
+                                DnsUdpServerTestParams
61 61
                                         {
62 62
                                                 QList<const char*>()
63 63
                                                         << "e1bc010000010000000000000266720000010001"

Loading…
Cancel
Save