[network/libktorrent] src/dht: ABI/API break: use enum class for RPCMsg::Type

Jack Hill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 3d40a098013248f1fde1a1b828a4117f634b9457 by Jack Hill.
Committed on 15/08/2026 at 10:19.
Pushed by jackh into branch 'master'.

ABI/API break: use enum class for RPCMsg::Type

No downstream changes required.

M  +2    -2    src/dht/announcersp.cpp
M  +1    -1    src/dht/errmsg.cpp
M  +2    -2    src/dht/findnodereq.cpp
M  +2    -2    src/dht/findnodersp.cpp
M  +2    -2    src/dht/getpeersreq.cpp
M  +3    -3    src/dht/getpeersrsp.cpp
M  +1    -1    src/dht/nodelookup.cpp
M  +2    -2    src/dht/pingreq.cpp
M  +2    -2    src/dht/pingrsp.cpp
M  +4    -4    src/dht/rpcmsg.cpp
M  +1    -1    src/dht/rpcmsg.h
M  +1    -1    src/dht/rpcserver.cpp
M  +1    -1    src/dht/tests/rpcmsgtest.cpp

https://invent.kde.org/network/libktorrent/-/commit/3d40a098013248f1fde1a1b828a4117f634b9457

diff --git a/src/dht/announcersp.cpp b/src/dht/announcersp.cpp
index 9e657d37..d0dbcefa 100644
--- a/src/dht/announcersp.cpp
+++ b/src/dht/announcersp.cpp
@@ -17,12 +17,12 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 AnnounceRsp::AnnounceRsp()
-    : RPCMsg(QByteArray(), ANNOUNCE_PEER, RSP_MSG, Key())
+    : RPCMsg(QByteArray(), ANNOUNCE_PEER, Type::RSP_MSG, Key())
 {
 }
 
 AnnounceRsp::AnnounceRsp(const QByteArray &mtid, const Key &id)
-    : RPCMsg(mtid, ANNOUNCE_PEER, RSP_MSG, id)
+    : RPCMsg(mtid, ANNOUNCE_PEER, Type::RSP_MSG, id)
 {
 }
 
diff --git a/src/dht/errmsg.cpp b/src/dht/errmsg.cpp
index 2f580ff1..b95a2a56 100644
--- a/src/dht/errmsg.cpp
+++ b/src/dht/errmsg.cpp
@@ -20,7 +20,7 @@ ErrMsg::ErrMsg()
 }
 
 ErrMsg::ErrMsg(const QByteArray &mtid, const Key &id, const QString &msg)
-    : RPCMsg(mtid, NONE, ERR_MSG, id)
+    : RPCMsg(mtid, NONE, Type::ERR_MSG, id)
     , msg(msg)
 {
 }
diff --git a/src/dht/findnodereq.cpp b/src/dht/findnodereq.cpp
index 7dc06cee..8c628dad 100644
--- a/src/dht/findnodereq.cpp
+++ b/src/dht/findnodereq.cpp
@@ -17,12 +17,12 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 FindNodeReq::FindNodeReq()
-    : RPCMsg(QByteArray(), FIND_NODE, REQ_MSG, Key())
+    : RPCMsg(QByteArray(), FIND_NODE, Type::REQ_MSG, Key())
 {
 }
 
 FindNodeReq::FindNodeReq(const Key &id, const Key &target)
-    : RPCMsg(QByteArray(), FIND_NODE, REQ_MSG, id)
+    : RPCMsg(QByteArray(), FIND_NODE, Type::REQ_MSG, id)
     , target(target)
 {
 }
diff --git a/src/dht/findnodersp.cpp b/src/dht/findnodersp.cpp
index 21c80979..b467d801 100644
--- a/src/dht/findnodersp.cpp
+++ b/src/dht/findnodersp.cpp
@@ -17,12 +17,12 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 FindNodeRsp::FindNodeRsp()
-    : RPCMsg(QByteArray(), FIND_NODE, RSP_MSG, Key())
+    : RPCMsg(QByteArray(), FIND_NODE, Type::RSP_MSG, Key())
 {
 }
 
 FindNodeRsp::FindNodeRsp(const QByteArray &mtid, const Key &id)
-    : RPCMsg(mtid, FIND_NODE, RSP_MSG, id)
+    : RPCMsg(mtid, FIND_NODE, Type::RSP_MSG, id)
 {
 }
 
diff --git a/src/dht/getpeersreq.cpp b/src/dht/getpeersreq.cpp
index f35d0719..fb869dd3 100644
--- a/src/dht/getpeersreq.cpp
+++ b/src/dht/getpeersreq.cpp
@@ -17,12 +17,12 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 GetPeersReq::GetPeersReq()
-    : RPCMsg(QByteArray(), GET_PEERS, REQ_MSG, Key())
+    : RPCMsg(QByteArray(), GET_PEERS, Type::REQ_MSG, Key())
 {
 }
 
 GetPeersReq::GetPeersReq(const Key &id, const Key &info_hash)
-    : RPCMsg(QByteArray(), GET_PEERS, REQ_MSG, id)
+    : RPCMsg(QByteArray(), GET_PEERS, Type::REQ_MSG, id)
     , info_hash(info_hash)
 {
 }
diff --git a/src/dht/getpeersrsp.cpp b/src/dht/getpeersrsp.cpp
index 4c3d0cac..00a7a4b4 100644
--- a/src/dht/getpeersrsp.cpp
+++ b/src/dht/getpeersrsp.cpp
@@ -18,18 +18,18 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 GetPeersRsp::GetPeersRsp()
-    : RPCMsg(QByteArray(), dht::GET_PEERS, dht::RSP_MSG, QByteArray())
+    : RPCMsg(QByteArray(), dht::GET_PEERS, dht::Type::RSP_MSG, QByteArray())
 {
 }
 
 GetPeersRsp::GetPeersRsp(const QByteArray &mtid, const Key &id, const QByteArray &token)
-    : RPCMsg(mtid, dht::GET_PEERS, dht::RSP_MSG, id)
+    : RPCMsg(mtid, dht::GET_PEERS, dht::Type::RSP_MSG, id)
     , token(token)
 {
 }
 
 GetPeersRsp::GetPeersRsp(const QByteArray &mtid, const Key &id, const DBItemList &values, const QByteArray &token)
-    : RPCMsg(mtid, dht::GET_PEERS, dht::RSP_MSG, id)
+    : RPCMsg(mtid, dht::GET_PEERS, dht::Type::RSP_MSG, id)
     , token(token)
     , items(values)
 {
diff --git a/src/dht/nodelookup.cpp b/src/dht/nodelookup.cpp
index c816a33e..992a36ee 100644
--- a/src/dht/nodelookup.cpp
+++ b/src/dht/nodelookup.cpp
@@ -54,7 +54,7 @@ void NodeLookup::callFinished(RPCCall *, RPCMsg *rsp)
     }
 
     // check the response and see if it is a good one
-    if (rsp->getMethod() == dht::FIND_NODE && rsp->getType() == dht::RSP_MSG) {
+    if (rsp->getMethod() == dht::FIND_NODE && rsp->getType() == dht::Type::RSP_MSG) {
         auto fnr = dynamic_cast<FindNodeRsp *>(rsp);
         if (!fnr) {
             return;
diff --git a/src/dht/pingreq.cpp b/src/dht/pingreq.cpp
index 8ca60907..2ab07c1c 100644
--- a/src/dht/pingreq.cpp
+++ b/src/dht/pingreq.cpp
@@ -15,12 +15,12 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 PingReq::PingReq()
-    : RPCMsg(QByteArray(), PING, REQ_MSG, Key())
+    : RPCMsg(QByteArray(), PING, Type::REQ_MSG, Key())
 {
 }
 
 PingReq::PingReq(const Key &id)
-    : RPCMsg(QByteArray(), PING, REQ_MSG, id)
+    : RPCMsg(QByteArray(), PING, Type::REQ_MSG, id)
 {
 }
 
diff --git a/src/dht/pingrsp.cpp b/src/dht/pingrsp.cpp
index ee3bb65f..f191e529 100644
--- a/src/dht/pingrsp.cpp
+++ b/src/dht/pingrsp.cpp
@@ -15,12 +15,12 @@ using namespace Qt::Literals::StringLiterals;
 namespace dht
 {
 PingRsp::PingRsp()
-    : RPCMsg(QByteArray(), PING, RSP_MSG, Key())
+    : RPCMsg(QByteArray(), PING, Type::RSP_MSG, Key())
 {
 }
 
 PingRsp::PingRsp(const QByteArray &mtid, const Key &id)
-    : RPCMsg(mtid, PING, RSP_MSG, id)
+    : RPCMsg(mtid, PING, Type::RSP_MSG, id)
 {
 }
 
diff --git a/src/dht/rpcmsg.cpp b/src/dht/rpcmsg.cpp
index b8262357..ddba6947 100644
--- a/src/dht/rpcmsg.cpp
+++ b/src/dht/rpcmsg.cpp
@@ -15,7 +15,7 @@ namespace dht
 RPCMsg::RPCMsg()
     : mtid(nullptr)
     , method(NONE)
-    , type(INVALID)
+    , type(Type::INVALID)
 {
 }
 
@@ -40,7 +40,7 @@ void RPCMsg::parse(bt::BDictNode *dict)
 
     const auto t = dict->getByteArrayView(TYP);
     if (t == REQ) {
-        type = REQ_MSG;
+        type = Type::REQ_MSG;
         BDictNode *args = dict->getDict(ARG);
         if (!args) {
             return;
@@ -48,7 +48,7 @@ void RPCMsg::parse(bt::BDictNode *dict)
 
         id = Key(args->getByteArrayView("id"));
     } else if (t == RSP) {
-        type = RSP_MSG;
+        type = Type::RSP_MSG;
         BDictNode *args = dict->getDict(RSP);
         if (!args) {
             return;
@@ -56,7 +56,7 @@ void RPCMsg::parse(bt::BDictNode *dict)
 
         id = Key(args->getByteArrayView("id"));
     } else if (t == ERR_DHT) {
-        type = ERR_MSG;
+        type = Type::ERR_MSG;
     } else {
         throw bt::Error(u"Unknown message type %1"_s.arg(QLatin1StringView(t)));
     }
diff --git a/src/dht/rpcmsg.h b/src/dht/rpcmsg.h
index 2675c1ae..f9f89f08 100644
--- a/src/dht/rpcmsg.h
+++ b/src/dht/rpcmsg.h
@@ -40,7 +40,7 @@ class DHT;
  * \var INVALID
  * An unknown or invalid message.
  */
-enum Type {
+enum class Type {
     REQ_MSG,
     RSP_MSG,
     ERR_MSG,
diff --git a/src/dht/rpcserver.cpp b/src/dht/rpcserver.cpp
index c668baeb..cda2d6ab 100644
--- a/src/dht/rpcserver.cpp
+++ b/src/dht/rpcserver.cpp
@@ -88,7 +88,7 @@ public:
 
                 msg->apply(dh_table);
                 // erase an existing call
-                if (msg->getType() == RSP_MSG && calls.contains(msg->getMTID())) {
+                if (msg->getType() == Type::RSP_MSG && calls.contains(msg->getMTID())) {
                     // delete the call, but first notify it off the response
                     RPCCall *c = calls.find(msg->getMTID());
                     c->response(msg.get());
diff --git a/src/dht/tests/rpcmsgtest.cpp b/src/dht/tests/rpcmsgtest.cpp
index e3e5935e..a610a96a 100644
--- a/src/dht/tests/rpcmsgtest.cpp
+++ b/src/dht/tests/rpcmsgtest.cpp
@@ -49,7 +49,7 @@ private Q_SLOTS:
             const std::unique_ptr<bt::BDictNode> dict = dec.decodeDict();
             std::unique_ptr<dht::RPCMsg> msg = factory.build(dict.get(), nullptr);
 
-            QCOMPARE(msg->getType(), dht::ERR_MSG);
+            QCOMPARE(msg->getType(), dht::Type::ERR_MSG);
             const auto err = dynamic_cast<const dht::ErrMsg *>(msg.get());
             QVERIFY(err);
             QCOMPARE(err->message(), "A Generic Error Ocurred"_L1);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.