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

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

ABI/API break: use enum class for dht::Method

No downstream changes required.

M  +2    -2    src/dht/announcereq.cpp
M  +2    -2    src/dht/announcersp.cpp
M  +1    -1    src/dht/announcetask.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  +1    -1    src/dht/rpccall.cpp
M  +1    -1    src/dht/rpcmsg.cpp
M  +1    -1    src/dht/rpcmsg.h
M  +5    -5    src/dht/rpcmsgfactory.cpp
M  +1    -1    src/dht/rpcserver.cpp
M  +8    -8    src/dht/tests/rpcmsgtest.cpp

https://invent.kde.org/network/libktorrent/-/commit/38ce8a8cabb90a984e09637c10d4ca2256ac8447

diff --git a/src/dht/announcereq.cpp b/src/dht/announcereq.cpp
index db676df2..e2cd4d91 100644
--- a/src/dht/announcereq.cpp
+++ b/src/dht/announcereq.cpp
@@ -18,7 +18,7 @@ namespace dht
 {
 AnnounceReq::AnnounceReq()
 {
-    method = dht::ANNOUNCE_PEER;
+    method = dht::Method::ANNOUNCE_PEER;
 }
 
 AnnounceReq::AnnounceReq(const Key &id, const Key &info_hash, Uint16 port, const QByteArray &token)
@@ -26,7 +26,7 @@ AnnounceReq::AnnounceReq(const Key &id, const Key &info_hash, Uint16 port, const
     , port(port)
     , token(token)
 {
-    method = dht::ANNOUNCE_PEER;
+    method = dht::Method::ANNOUNCE_PEER;
 }
 
 AnnounceReq::~AnnounceReq()
diff --git a/src/dht/announcersp.cpp b/src/dht/announcersp.cpp
index d0dbcefa..6511d769 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, Type::RSP_MSG, Key())
+    : RPCMsg(QByteArray(), Method::ANNOUNCE_PEER, Type::RSP_MSG, Key())
 {
 }
 
 AnnounceRsp::AnnounceRsp(const QByteArray &mtid, const Key &id)
-    : RPCMsg(mtid, ANNOUNCE_PEER, Type::RSP_MSG, id)
+    : RPCMsg(mtid, Method::ANNOUNCE_PEER, Type::RSP_MSG, id)
 {
 }
 
diff --git a/src/dht/announcetask.cpp b/src/dht/announcetask.cpp
index 82678336..44ac357b 100644
--- a/src/dht/announcetask.cpp
+++ b/src/dht/announcetask.cpp
@@ -50,7 +50,7 @@ void AnnounceTask::callFinished(RPCCall *c, RPCMsg *rsp)
     // Out(SYS_DHT|LOG_DEBUG) << "AnnounceTask::callFinished" << endl;
     // if we do not have a get peers response, return
     // announce_peer's response are just empty anyway
-    if (c->getMsgMethod() != dht::GET_PEERS) {
+    if (c->getMsgMethod() != dht::Method::GET_PEERS) {
         return;
     }
 
diff --git a/src/dht/errmsg.cpp b/src/dht/errmsg.cpp
index b95a2a56..73f53e9a 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, Type::ERR_MSG, id)
+    : RPCMsg(mtid, Method::NONE, Type::ERR_MSG, id)
     , msg(msg)
 {
 }
diff --git a/src/dht/findnodereq.cpp b/src/dht/findnodereq.cpp
index 8c628dad..89da596b 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, Type::REQ_MSG, Key())
+    : RPCMsg(QByteArray(), Method::FIND_NODE, Type::REQ_MSG, Key())
 {
 }
 
 FindNodeReq::FindNodeReq(const Key &id, const Key &target)
-    : RPCMsg(QByteArray(), FIND_NODE, Type::REQ_MSG, id)
+    : RPCMsg(QByteArray(), Method::FIND_NODE, Type::REQ_MSG, id)
     , target(target)
 {
 }
diff --git a/src/dht/findnodersp.cpp b/src/dht/findnodersp.cpp
index b467d801..ab471cc4 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, Type::RSP_MSG, Key())
+    : RPCMsg(QByteArray(), Method::FIND_NODE, Type::RSP_MSG, Key())
 {
 }
 
 FindNodeRsp::FindNodeRsp(const QByteArray &mtid, const Key &id)
-    : RPCMsg(mtid, FIND_NODE, Type::RSP_MSG, id)
+    : RPCMsg(mtid, Method::FIND_NODE, Type::RSP_MSG, id)
 {
 }
 
diff --git a/src/dht/getpeersreq.cpp b/src/dht/getpeersreq.cpp
index fb869dd3..bdc8a41e 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, Type::REQ_MSG, Key())
+    : RPCMsg(QByteArray(), Method::GET_PEERS, Type::REQ_MSG, Key())
 {
 }
 
 GetPeersReq::GetPeersReq(const Key &id, const Key &info_hash)
-    : RPCMsg(QByteArray(), GET_PEERS, Type::REQ_MSG, id)
+    : RPCMsg(QByteArray(), Method::GET_PEERS, Type::REQ_MSG, id)
     , info_hash(info_hash)
 {
 }
diff --git a/src/dht/getpeersrsp.cpp b/src/dht/getpeersrsp.cpp
index 00a7a4b4..489e0d29 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::Type::RSP_MSG, QByteArray())
+    : RPCMsg(QByteArray(), dht::Method::GET_PEERS, dht::Type::RSP_MSG, QByteArray())
 {
 }
 
 GetPeersRsp::GetPeersRsp(const QByteArray &mtid, const Key &id, const QByteArray &token)
-    : RPCMsg(mtid, dht::GET_PEERS, dht::Type::RSP_MSG, id)
+    : RPCMsg(mtid, dht::Method::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::Type::RSP_MSG, id)
+    : RPCMsg(mtid, dht::Method::GET_PEERS, dht::Type::RSP_MSG, id)
     , token(token)
     , items(values)
 {
diff --git a/src/dht/nodelookup.cpp b/src/dht/nodelookup.cpp
index 992a36ee..7f43cc33 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::Type::RSP_MSG) {
+    if (rsp->getMethod() == dht::Method::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 2ab07c1c..bf38ad7a 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, Type::REQ_MSG, Key())
+    : RPCMsg(QByteArray(), Method::PING, Type::REQ_MSG, Key())
 {
 }
 
 PingReq::PingReq(const Key &id)
-    : RPCMsg(QByteArray(), PING, Type::REQ_MSG, id)
+    : RPCMsg(QByteArray(), Method::PING, Type::REQ_MSG, id)
 {
 }
 
diff --git a/src/dht/pingrsp.cpp b/src/dht/pingrsp.cpp
index f191e529..c6346f45 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, Type::RSP_MSG, Key())
+    : RPCMsg(QByteArray(), Method::PING, Type::RSP_MSG, Key())
 {
 }
 
 PingRsp::PingRsp(const QByteArray &mtid, const Key &id)
-    : RPCMsg(mtid, PING, Type::RSP_MSG, id)
+    : RPCMsg(mtid, Method::PING, Type::RSP_MSG, id)
 {
 }
 
diff --git a/src/dht/rpccall.cpp b/src/dht/rpccall.cpp
index 1e6309ac..e91df2b8 100644
--- a/src/dht/rpccall.cpp
+++ b/src/dht/rpccall.cpp
@@ -54,7 +54,7 @@ Method RPCCall::getMsgMethod() const
     if (msg) {
         return msg->getMethod();
     } else {
-        return dht::NONE;
+        return dht::Method::NONE;
     }
 }
 
diff --git a/src/dht/rpcmsg.cpp b/src/dht/rpcmsg.cpp
index ddba6947..37125ef8 100644
--- a/src/dht/rpcmsg.cpp
+++ b/src/dht/rpcmsg.cpp
@@ -14,7 +14,7 @@ namespace dht
 {
 RPCMsg::RPCMsg()
     : mtid(nullptr)
-    , method(NONE)
+    , method(Method::NONE)
     , type(Type::INVALID)
 {
 }
diff --git a/src/dht/rpcmsg.h b/src/dht/rpcmsg.h
index f9f89f08..8d8aa081 100644
--- a/src/dht/rpcmsg.h
+++ b/src/dht/rpcmsg.h
@@ -67,7 +67,7 @@ enum class Type {
  * \var NONE
  * Used for non-query messages.
  */
-enum Method {
+enum class Method {
     PING,
     FIND_NODE,
     GET_PEERS,
diff --git a/src/dht/rpcmsgfactory.cpp b/src/dht/rpcmsgfactory.cpp
index cdc572c7..c6803dcb 100644
--- a/src/dht/rpcmsgfactory.cpp
+++ b/src/dht/rpcmsgfactory.cpp
@@ -84,23 +84,23 @@ std::unique_ptr<RPCMsg> RPCMsgFactory::buildResponse(BDictNode *dict, dht::RPCMe
     // find the call
     const Method method = method_resolver->findMethod(mtid);
     switch (method) {
-    case PING:
+    case Method::PING:
         msg = std::make_unique<PingRsp>();
         msg->parse(dict);
         break;
-    case FIND_NODE:
+    case Method::FIND_NODE:
         msg = std::make_unique<FindNodeRsp>();
         msg->parse(dict);
         break;
-    case GET_PEERS:
+    case Method::GET_PEERS:
         msg = std::make_unique<GetPeersRsp>();
         msg->parse(dict);
         break;
-    case ANNOUNCE_PEER:
+    case Method::ANNOUNCE_PEER:
         msg = std::make_unique<AnnounceRsp>();
         msg->parse(dict);
         break;
-    case NONE:
+    case Method::NONE:
     default:
         throw bt::Error(u"Unknown DHT rpc call (transaction id = %1)"_s.arg(mtid[0]));
     }
diff --git a/src/dht/rpcserver.cpp b/src/dht/rpcserver.cpp
index cda2d6ab..136ec3eb 100644
--- a/src/dht/rpcserver.cpp
+++ b/src/dht/rpcserver.cpp
@@ -113,7 +113,7 @@ public:
         if (call) {
             return call->getMsgMethod();
         } else {
-            return dht::NONE;
+            return dht::Method::NONE;
         }
     }
 
diff --git a/src/dht/tests/rpcmsgtest.cpp b/src/dht/tests/rpcmsgtest.cpp
index a610a96a..982f765a 100644
--- a/src/dht/tests/rpcmsgtest.cpp
+++ b/src/dht/tests/rpcmsgtest.cpp
@@ -85,7 +85,7 @@ private Q_SLOTS:
             "d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe",
             "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re",
         };
-        current_method = dht::PING;
+        current_method = dht::Method::PING;
 
         for (const auto msg : msgs) {
             bt::BDecoder dec(msg, false);
@@ -94,7 +94,7 @@ private Q_SLOTS:
                 std::unique_ptr<dht::RPCMsg> msg = factory.build(dict.get(), this);
                 QVERIFY(msg);
                 QCOMPARE(msg->getMTID(), QByteArray("aa"));
-                QCOMPARE(msg->getMethod(), dht::PING);
+                QCOMPARE(msg->getMethod(), dht::Method::PING);
             } catch (bt::Error &e) {
                 QFAIL(e.toString().toLocal8Bit().data());
             }
@@ -108,7 +108,7 @@ private Q_SLOTS:
             "d1:rd2:id20:0123456789abcdefghij5:nodes9:def456...e1:t2:aa1:y1:re",
         };
 
-        current_method = dht::FIND_NODE;
+        current_method = dht::Method::FIND_NODE;
 
         for (const auto msg : msgs) {
             bt::BDecoder dec(msg, false);
@@ -117,7 +117,7 @@ private Q_SLOTS:
                 std::unique_ptr<dht::RPCMsg> msg = factory.build(dict.get(), this);
                 QVERIFY(msg);
                 QCOMPARE(msg->getMTID(), QByteArray("aa"));
-                QCOMPARE(msg->getMethod(), dht::FIND_NODE);
+                QCOMPARE(msg->getMethod(), dht::Method::FIND_NODE);
             } catch (bt::Error &e) {
                 QFAIL(e.toString().toLocal8Bit().data());
             }
@@ -131,7 +131,7 @@ private Q_SLOTS:
             "d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:idhtnmee1:t2:aa1:y1:re",
             "d1:rd2:id20:abcdefghij01234567895:nodes9:def456...5:token8:aoeusnthe1:t2:aa1:y1:re",
         };
-        current_method = dht::GET_PEERS;
+        current_method = dht::Method::GET_PEERS;
 
         for (const auto msg : msgs) {
             bt::BDecoder dec(msg, false);
@@ -140,7 +140,7 @@ private Q_SLOTS:
                 std::unique_ptr<dht::RPCMsg> msg = factory.build(dict.get(), this);
                 QVERIFY(msg);
                 QCOMPARE(msg->getMTID(), QByteArray("aa"));
-                QCOMPARE(msg->getMethod(), dht::GET_PEERS);
+                QCOMPARE(msg->getMethod(), dht::Method::GET_PEERS);
             } catch (bt::Error &e) {
                 QFAIL(e.toString().toLocal8Bit().data());
             }
@@ -153,7 +153,7 @@ private Q_SLOTS:
             "d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz1234564:porti6881e5:token8:aoeusnthe1:q13:announce_peer1:t2:aa1:y1:qe",
             "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re",
         };
-        current_method = dht::ANNOUNCE_PEER;
+        current_method = dht::Method::ANNOUNCE_PEER;
 
         for (const auto msg : msgs) {
             bt::BDecoder dec(msg, false);
@@ -162,7 +162,7 @@ private Q_SLOTS:
                 std::unique_ptr<dht::RPCMsg> msg = factory.build(dict.get(), this);
                 QVERIFY(msg);
                 QCOMPARE(msg->getMTID(), QByteArray("aa"));
-                QCOMPARE(msg->getMethod(), dht::ANNOUNCE_PEER);
+                QCOMPARE(msg->getMethod(), dht::Method::ANNOUNCE_PEER);
             } catch (bt::Error &e) {
                 QFAIL(e.toString().toLocal8Bit().data());
             }
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.