mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e3d8c0200 | ||
|
|
e0ecf06f52 |
No files matched your search
@@ -146,6 +146,26 @@ public:
|
||||
|
||||
std::shared_ptr<DhtRunner> getNode() const { return dht_; }
|
||||
|
||||
#ifdef OPENDHT_PUSH_NOTIFICATIONS
|
||||
/**
|
||||
* Decide whether a batch of values notified to a push listener must be
|
||||
* delivered as a high (urgent) priority push notification.
|
||||
*
|
||||
* Only real-time call signaling — values whose pushType is "audioCall" or
|
||||
* "videoCall", published at high priority (priority == 0) — warrants an
|
||||
* urgent push. Every other notification (presence/connection-request
|
||||
* refreshes carrying an empty pushType, value expirations, etc.) is sent at
|
||||
* normal priority so it does not saturate the mobile platform's adaptive
|
||||
* high-priority quota; once that quota is tripped, the platform silently
|
||||
* drops genuine call pushes.
|
||||
*
|
||||
* @param values the values being notified to the listener.
|
||||
* @param expired whether this notification is for expired (removed) values.
|
||||
* @return true if the notification must be sent at high priority.
|
||||
*/
|
||||
static bool isHighPriorityPush(const std::vector<std::shared_ptr<Value>>& values, bool expired) noexcept;
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
|
||||
private:
|
||||
class ConnectionListener;
|
||||
struct RestRouterTraitsTls;
|
||||
|
||||
@@ -1134,6 +1134,25 @@ DhtProxyServer::handleCancelPushListen(const asio::error_code& ec,
|
||||
pushListeners_.erase(pushListener);
|
||||
}
|
||||
|
||||
bool
|
||||
DhtProxyServer::isHighPriorityPush(const std::vector<std::shared_ptr<Value>>& values, bool expired) noexcept
|
||||
{
|
||||
// Expired-value notifications (de-registration) are never time-critical.
|
||||
if (expired)
|
||||
return false;
|
||||
// Promote to high (urgent) push priority only for real-time call signaling.
|
||||
// Background traffic — most notably connection-request refreshes, which
|
||||
// carry an empty pushType — stays at normal priority so it does not trip the
|
||||
// mobile platform's adaptive high-priority quota, which would otherwise
|
||||
// silently drop genuine call pushes once the high-priority noise ratio gets
|
||||
// too high.
|
||||
for (const auto& v : values) {
|
||||
if (v->priority == 0 and (v->pushType == "videoCall" or v->pushType == "audioCall"))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
DhtProxyServer::handlePushListen(const InfoHash& infoHash,
|
||||
const std::string& pushToken,
|
||||
@@ -1176,20 +1195,23 @@ DhtProxyServer::handlePushListen(const InfoHash& infoHash,
|
||||
json["exp"] = json["ids"];
|
||||
}
|
||||
|
||||
auto minPriority = 1000u;
|
||||
for (const auto& v : values)
|
||||
minPriority = std::min(minPriority, v->priority);
|
||||
const bool highPriority = isHighPriorityPush(values, expired);
|
||||
|
||||
if (logger_)
|
||||
logger_->debug("[proxy:server] [listen {}] [client {}] [session {}] [expired {}] [priority {}] [values {}]",
|
||||
if (logger_) {
|
||||
auto minPriority = 1000u;
|
||||
for (const auto& v : values)
|
||||
minPriority = std::min(minPriority, v->priority);
|
||||
logger_->debug("[proxy:server] [listen {}] [client {}] [session {}] [expired {}] [priority {}] [high {}] [values {}]",
|
||||
infoHash,
|
||||
clientId,
|
||||
sessionCtx->sessionId,
|
||||
expired,
|
||||
minPriority,
|
||||
highPriority,
|
||||
values.size());
|
||||
}
|
||||
|
||||
sendPushNotification(pushToken, std::move(json), type, !expired and minPriority == 0, topic);
|
||||
sendPushNotification(pushToken, std::move(json), type, highPriority, topic);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -327,4 +327,39 @@ DhtProxyTester::testShutdownStop()
|
||||
CPPUNIT_ASSERT_EQUAL(2 * C, callback_count.load());
|
||||
}
|
||||
|
||||
#ifdef OPENDHT_PUSH_NOTIFICATIONS
|
||||
void
|
||||
DhtProxyTester::testPushNotificationPriority()
|
||||
{
|
||||
auto mkValue = [](unsigned priority, const std::string& pushType) {
|
||||
auto v = std::make_shared<dht::Value>();
|
||||
v->priority = priority;
|
||||
v->pushType = pushType;
|
||||
return v;
|
||||
};
|
||||
|
||||
// Real-time call signaling at high priority => urgent push.
|
||||
CPPUNIT_ASSERT(dht::DhtProxyServer::isHighPriorityPush({mkValue(0, "videoCall")}, false));
|
||||
CPPUNIT_ASSERT(dht::DhtProxyServer::isHighPriorityPush({mkValue(0, "audioCall")}, false));
|
||||
|
||||
// Connection-request refresh (empty pushType) is noise => normal push.
|
||||
CPPUNIT_ASSERT(!dht::DhtProxyServer::isHighPriorityPush({mkValue(0, "")}, false));
|
||||
|
||||
// Any other pushType is not a call => normal push.
|
||||
CPPUNIT_ASSERT(!dht::DhtProxyServer::isHighPriorityPush({mkValue(0, "message")}, false));
|
||||
|
||||
// Expired (de-registration) notifications are never urgent, even for calls.
|
||||
CPPUNIT_ASSERT(!dht::DhtProxyServer::isHighPriorityPush({mkValue(0, "videoCall")}, true));
|
||||
|
||||
// A call value explicitly published at normal priority stays normal.
|
||||
CPPUNIT_ASSERT(!dht::DhtProxyServer::isHighPriorityPush({mkValue(1, "videoCall")}, false));
|
||||
|
||||
// Mixed batch: a single high-priority call value is enough to make it urgent.
|
||||
CPPUNIT_ASSERT(dht::DhtProxyServer::isHighPriorityPush({mkValue(0, ""), mkValue(0, "videoCall")}, false));
|
||||
|
||||
// Empty batch => normal.
|
||||
CPPUNIT_ASSERT(!dht::DhtProxyServer::isHighPriorityPush({}, false));
|
||||
}
|
||||
#endif // OPENDHT_PUSH_NOTIFICATIONS
|
||||
|
||||
} // namespace test
|
||||
@@ -21,6 +21,9 @@ class DhtProxyTester : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testPutGet40KChars);
|
||||
CPPUNIT_TEST(testFuzzy);
|
||||
CPPUNIT_TEST(testShutdownStop);
|
||||
#ifdef OPENDHT_PUSH_NOTIFICATIONS
|
||||
CPPUNIT_TEST(testPushNotificationPriority);
|
||||
#endif
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@@ -55,6 +58,15 @@ public:
|
||||
|
||||
void testShutdownStop();
|
||||
|
||||
#ifdef OPENDHT_PUSH_NOTIFICATIONS
|
||||
/**
|
||||
* The proxy must only request a high-priority push for real-time call
|
||||
* signaling (audioCall/videoCall at priority 0); everything else stays at
|
||||
* normal priority.
|
||||
*/
|
||||
void testPushNotificationPriority();
|
||||
#endif
|
||||
|
||||
private:
|
||||
dht::DhtRunner::Config clientConfig {};
|
||||
dht::DhtRunner nodePeer;
|
||||
|
||||
Reference in new issue
Block a user