mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb66dded17 | ||
|
|
91d54d09d1 | ||
|
|
4d0ecb8075 | ||
|
|
b0f8526872 | ||
|
|
6dc004c338 |
No files matched your search
@@ -130,6 +130,7 @@ if (NOT MSVC)
|
||||
message(STATUS "simdutf not found with pkgconfig")
|
||||
if (OPENDHT_DOWNLOAD_DEPS)
|
||||
message(STATUS "Fallback mode specified, downloading simdutf")
|
||||
set(SIMDUTF_CXX_STANDARD ${CMAKE_CXX_STANDARD} CACHE INTERNAL "C++ standard for simdutf downloader")
|
||||
set(SIMDUTF_TESTS OFF CACHE INTERNAL "Disable tests for simdutf downloader")
|
||||
set(SIMDUTF_TOOLS OFF CACHE INTERNAL "Disable tools for simdutf downloader")
|
||||
FetchContent_Declare(simdutf
|
||||
|
||||
@@ -294,8 +294,10 @@ void
|
||||
NetworkEngine::clear()
|
||||
{
|
||||
for (auto& request : requests) {
|
||||
request.second->cancel();
|
||||
request.second->node->setExpired();
|
||||
if (request.second->node)
|
||||
request.second->node->setExpired();
|
||||
else
|
||||
request.second->setExpired();
|
||||
}
|
||||
requests.clear();
|
||||
partial_messages.clear();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#define close(x) closesocket(x)
|
||||
#define write(s, b, f) send(s, b, (int) strlen(b), 0)
|
||||
#define write(s, b, f) send(s, b, (int) (f), 0)
|
||||
#define _poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout)
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
|
||||
@@ -282,7 +282,7 @@ DhtRunnerTester::testBootstrapSetsConnectingState()
|
||||
|
||||
dht::DhtRunner::Context context;
|
||||
context.statusChangedCallback = [&](dht::NodeStatus status4, dht::NodeStatus status6) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::lock_guard lock(mutex);
|
||||
sawConnecting = sawConnecting || status4 == dht::NodeStatus::Connecting
|
||||
|| status6 == dht::NodeStatus::Connecting;
|
||||
cv.notify_all();
|
||||
@@ -299,8 +299,10 @@ DhtRunnerTester::testBootstrapSetsConnectingState()
|
||||
|
||||
clientNode.bootstrap("127.0.0.1", std::to_string(bound.getPort()));
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lock, 5s, [&] { return sawConnecting; }));
|
||||
{
|
||||
std::unique_lock lock(mutex);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lock, 5s, [&] { return sawConnecting; }));
|
||||
}
|
||||
|
||||
bootstrapNode.shutdown();
|
||||
bootstrapNode.join();
|
||||
@@ -382,7 +384,7 @@ DhtRunnerTester::testBootstrapMissingNodeThenPutFails()
|
||||
|
||||
dht::DhtRunner::Context context;
|
||||
context.statusChangedCallback = [&](dht::NodeStatus status4, dht::NodeStatus status6) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::lock_guard lock(mutex);
|
||||
if (status4 == dht::NodeStatus::Connecting || status6 == dht::NodeStatus::Connecting)
|
||||
sawConnecting = true;
|
||||
if (sawConnecting && status4 == dht::NodeStatus::Disconnected && status6 == dht::NodeStatus::Disconnected)
|
||||
@@ -400,14 +402,14 @@ DhtRunnerTester::testBootstrapMissingNodeThenPutFails()
|
||||
|
||||
clientNode.bootstrap("127.0.0.1", std::to_string(missingPort));
|
||||
clientNode.put(dht::InfoHash::get("bootstrap-missing-put"), dht::Value {"value"}, [&](bool ok) {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::lock_guard lock(mutex);
|
||||
putReturnedBeforeDisconnect = !sawDisconnectedAfterConnecting;
|
||||
putDone.set_value(ok);
|
||||
cv.notify_all();
|
||||
});
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::unique_lock lock(mutex);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lock, 10s, [&] { return sawConnecting; }));
|
||||
CPPUNIT_ASSERT(cv.wait_for(lock, 20s, [&] { return sawDisconnectedAfterConnecting; }));
|
||||
}
|
||||
@@ -419,6 +421,48 @@ DhtRunnerTester::testBootstrapMissingNodeThenPutFails()
|
||||
clientNode.join();
|
||||
}
|
||||
|
||||
void
|
||||
DhtRunnerTester::testShutdownCompletesWithPendingPut()
|
||||
{
|
||||
node1.shutdown();
|
||||
node1.join();
|
||||
node2.shutdown();
|
||||
node2.join();
|
||||
|
||||
dht::DhtRunner::Config config;
|
||||
config.dht_config.node_config.max_peer_req_per_sec = -1;
|
||||
config.dht_config.node_config.max_req_per_sec = -1;
|
||||
config.dht_config.node_config.max_store_size = -1;
|
||||
config.dht_config.node_config.max_store_keys = -1;
|
||||
|
||||
auto getUnusedPort = [&]() {
|
||||
dht::DhtRunner tmpNode;
|
||||
tmpNode.run(0, config);
|
||||
auto port = tmpNode.getBoundPort();
|
||||
tmpNode.shutdown();
|
||||
tmpNode.join();
|
||||
return port;
|
||||
};
|
||||
|
||||
auto missingPort = getUnusedPort();
|
||||
|
||||
dht::DhtRunner clientNode;
|
||||
clientNode.run(0, config);
|
||||
while (clientNode.getBoundPort() == missingPort)
|
||||
missingPort = getUnusedPort();
|
||||
|
||||
clientNode.bootstrap("127.0.0.1", std::to_string(missingPort));
|
||||
clientNode.put(dht::InfoHash::get("shutdown-pending-put"), dht::Value {"value"}, [](bool) {});
|
||||
|
||||
std::promise<void> shutdownDone;
|
||||
auto shutdownFuture = shutdownDone.get_future();
|
||||
clientNode.shutdown([&]() { shutdownDone.set_value(); });
|
||||
|
||||
CPPUNIT_ASSERT(std::future_status::ready == shutdownFuture.wait_for(5s));
|
||||
|
||||
clientNode.join();
|
||||
}
|
||||
|
||||
void
|
||||
DhtRunnerTester::testListen()
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ class DhtRunnerTester : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testBootstrapSetsConnectingState);
|
||||
CPPUNIT_TEST(testBootstrapThenPutNoRace);
|
||||
CPPUNIT_TEST(testBootstrapMissingNodeThenPutFails);
|
||||
CPPUNIT_TEST(testShutdownCompletesWithPendingPut);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
dht::DhtRunner node1 {};
|
||||
@@ -68,6 +69,7 @@ public:
|
||||
void testBootstrapSetsConnectingState();
|
||||
void testBootstrapThenPutNoRace();
|
||||
void testBootstrapMissingNodeThenPutFails();
|
||||
void testShutdownCompletesWithPendingPut();
|
||||
/**
|
||||
* Test listen method with lot of datas
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user