@@ -344,8 +344,9 @@ std::string CDepinMsgPoolServer::ProcessRequest(const std::string& request, cons
344344
345345 std::string token = pDepinMsgPool->GetActiveToken ();
346346 size_t messageCount = pDepinMsgPool->Size ();
347+ unsigned int messageExpiryHours = pDepinMsgPool->GetMessageExpiryHours ();
347348
348- return strprintf (" OK|%s|%d" , token, messageCount);
349+ return strprintf (" OK|%s|%d|%d " , token, messageCount, messageExpiryHours );
349350 }
350351
351352 // GETMESSAGES
@@ -976,7 +977,7 @@ bool CDepinMsgPoolClient::GetInfo(const std::string& host, int port,
976977 return false ;
977978 }
978979
979- // Parse: OK|token|count
980+ // Parse: OK|token|count|expiryhours (expiryhours is optional for backward compatibility)
980981 size_t pos1 = response.find (' |' );
981982 if (pos1 == std::string::npos) {
982983 error = " Invalid INFO response format" ;
@@ -996,61 +997,65 @@ bool CDepinMsgPoolClient::GetInfo(const std::string& host, int port,
996997 }
997998
998999 token = response.substr (pos1 + 1 , pos2 - pos1 - 1 );
999- messageCount = std::stoi (response.substr (pos2 + 1 ));
1000+
1001+ // Check if there's a third field (expiryhours)
1002+ size_t pos3 = response.find (' |' , pos2 + 1 );
1003+ if (pos3 != std::string::npos) {
1004+ // New format: OK|token|count|expiryhours
1005+ messageCount = std::stoi (response.substr (pos2 + 1 , pos3 - pos2 - 1 ));
1006+ } else {
1007+ // Old format: OK|token|count
1008+ messageCount = std::stoi (response.substr (pos2 + 1 ));
1009+ }
10001010
10011011 return true ;
10021012}
10031013
10041014bool CDepinMsgPoolClient::GetRemoteServerInfo (const std::string& host, int port,
10051015 int64_t & messageExpiryHours,
10061016 std::string& error) {
1007- // Build JSON-RPC request for depingetmsginfo
1008- UniValue request (UniValue::VOBJ);
1009- request.push_back (Pair (" jsonrpc" , " 2.0" ));
1010- request.push_back (Pair (" id" , 1 ));
1011- request.push_back (Pair (" method" , " depingetmsginfo" ));
1017+ // Use INFO command to get server configuration
1018+ std::string request = DEPIN_CMD_INFO;
1019+ std::string response;
10121020
1013- UniValue params (UniValue::VARR);
1014- request.push_back (Pair (" params" , params));
1021+ if (!SendRequest (host, port, request, response, error)) {
1022+ return false ;
1023+ }
10151024
1016- std::string response;
1017- if (!SendRequest (host, port, request.write (), response, error)) {
1025+ // Parse: OK|token|count|expiryhours
1026+ size_t pos1 = response.find (' |' );
1027+ if (pos1 == std::string::npos) {
1028+ error = " Invalid INFO response format" ;
10181029 return false ;
10191030 }
10201031
1021- // Parse JSON-RPC response
1022- UniValue reply;
1023- if (!reply.read (response)) {
1024- error = " Invalid JSON response" ;
1032+ size_t pos2 = response.find (' |' , pos1 + 1 );
1033+ if (pos2 == std::string::npos) {
1034+ error = " Invalid INFO response format" ;
10251035 return false ;
10261036 }
10271037
1028- // Check for error
1029- const UniValue& errVal = reply[" error" ];
1030- if (!errVal.isNull ()) {
1031- if (errVal.isObject () && errVal.exists (" message" )) {
1032- error = errVal[" message" ].get_str ();
1033- } else {
1034- error = " Remote node returned an error" ;
1035- }
1038+ size_t pos3 = response.find (' |' , pos2 + 1 );
1039+ if (pos3 == std::string::npos) {
1040+ error = " Server does not support message expiry info (old version)" ;
10361041 return false ;
10371042 }
10381043
1039- // Extract result
1040- const UniValue& result = reply[" result" ];
1041- if (!result.isObject ()) {
1042- error = " Invalid result format" ;
1044+ std::string status = response.substr (0 , pos1);
1045+ if (status != " OK" ) {
1046+ error = " Server error: " + response.substr (pos1 + 1 );
10431047 return false ;
10441048 }
10451049
1046- // Get messageexpiryhours
1047- const UniValue& expiryHours = find_value (result, " messageexpiryhours" );
1048- if (!expiryHours.isNum ()) {
1049- error = " messageexpiryhours not found in response" ;
1050+ // Extract expiry hours (third field)
1051+ std::string expiryStr = response.substr (pos3 + 1 );
1052+ try {
1053+ messageExpiryHours = std::stoi (expiryStr);
1054+ } catch (const std::exception& e) {
1055+ error = strprintf (" Failed to parse expiry hours: %s" , e.what ());
10501056 return false ;
10511057 }
10521058
1053- messageExpiryHours = expiryHours.get_int64 ();
10541059 return true ;
10551060}
10561061
0 commit comments