MCPcopy Create free account
hub / github.com/Qv2ray/Qv2ray / process

Method process

src/core/kernel/APIBackend.cpp:68–122  ·  view source on GitHub ↗

API Core Operations Start processing data.

Source from the content-addressed store, hash-verified

66 // API Core Operations
67 // Start processing data.
68 void APIWorker::process()
69 {
70 DEBUG("API Worker started.");
71 while (started)
72 {
73 QThread::msleep(1000);
74 bool dialed = false;
75 int apiFailCounter = 0;
76
77 while (running)
78 {
79 if (!dialed)
80 {
81 const auto channelAddress = "127.0.0.1:" + QString::number(GlobalConfig.kernelConfig.statsPort);
82 LOG("gRPC Version: " + QString::fromStdString(grpc::Version()));
83 grpc_channel = grpc::CreateChannel(channelAddress.toStdString(), grpc::InsecureChannelCredentials());
84 v2ray::core::app::stats::command::StatsService service;
85 stats_service_stub = service.NewStub(grpc_channel);
86 dialed = true;
87 }
88 if (apiFailCounter == QV2RAY_API_CALL_FAILEDCHECK_THRESHOLD)
89 {
90 LOG("API call failure threshold reached, cancelling further API aclls.");
91 emit OnAPIErrored(tr("Failed to get statistics data, please check if V2Ray is running properly"));
92 apiFailCounter++;
93 QThread::msleep(1000);
94 continue;
95 }
96 else if (apiFailCounter > QV2RAY_API_CALL_FAILEDCHECK_THRESHOLD)
97 {
98 // Ignored future requests.
99 QThread::msleep(1000);
100 continue;
101 }
102
103 QMap<StatisticsType, QvStatsSpeed> statsResult;
104 bool hasError = false;
105 for (const auto &[tag, config] : tagProtocolConfig)
106 {
107 const QString prefix = config.type == API_INBOUND ? "inbound" : "outbound";
108 const auto value_up = CallStatsAPIByName(prefix % ">>>" % tag % ">>>traffic>>>uplink");
109 const auto value_down = CallStatsAPIByName(prefix % ">>>" % tag % ">>>traffic>>>downlink");
110 hasError = hasError || value_up == Qv2ray_GRPC_ERROR_RETCODE || value_down == Qv2ray_GRPC_ERROR_RETCODE;
111 statsResult[config.type].first += std::max(value_up, 0LL);
112 statsResult[config.type].second += std::max(value_down, 0LL);
113 }
114 apiFailCounter = hasError ? apiFailCounter + 1 : 0;
115 // Changed: Removed isrunning check here
116 emit onAPIDataReady(statsResult);
117 QThread::msleep(1000);
118 } // end while running
119 } // end while started
120
121 workThread->exit();
122 }
123
124 qint64 APIWorker::CallStatsAPIByName(const QString &name)
125 {

Callers

nothing calls this directly

Calls 1

VersionClass · 0.85

Tested by

no test coverage detected