Skip to content
Snippets Groups Projects
Commit 3383ce7a authored by Adrien Béraud's avatar Adrien Béraud
Browse files

dhtnode: print operation completion time

parent 04623d09
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,12 @@ void printLog(std::ostream& s, char const* m, va_list args) { ...@@ -82,6 +82,12 @@ void printLog(std::ostream& s, char const* m, va_list args) {
s.put('\n'); s.put('\n');
} }
template <class DT>
static double
print_dt(DT d) {
return std::chrono::duration_cast<std::chrono::duration<double>>(d).count();
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
...@@ -197,24 +203,25 @@ main(int argc, char **argv) ...@@ -197,24 +203,25 @@ main(int argc, char **argv)
continue; continue;
} }
auto start = std::chrono::high_resolution_clock::now();
if (op == "g") { if (op == "g") {
dht.get(id, [](const std::vector<std::shared_ptr<Value>>& values) { dht.get(id, [start](const std::vector<std::shared_ptr<Value>>& values) {
std::cout << "Get - found values : " << std::endl; auto now = std::chrono::high_resolution_clock::now();
for (const auto& a : values) { std::cout << "Get: found values (after " << print_dt(now-start) << "s)" << std::endl;
for (const auto& a : values)
std::cout << "\t" << *a << std::endl; std::cout << "\t" << *a << std::endl;
}
return true; return true;
}, [](bool ok) { }, [start](bool ok) {
std::cout << "Get - done : " << (ok ? "success" : "failure") << std::endl; auto end = std::chrono::high_resolution_clock::now();
std::cout << "Get: " << (ok ? "completed" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl;
}); });
} }
else if (op == "l") { else if (op == "l") {
std::cout << id << std::endl; std::cout << id << std::endl;
dht.listen(id, [](const std::vector<std::shared_ptr<Value>>& values) { dht.listen(id, [](const std::vector<std::shared_ptr<Value>>& values) {
std::cout << "Listen - found values : " << std::endl; std::cout << "Listen: found values:" << std::endl;
for (const auto& a : values) { for (const auto& a : values)
std::cout << "\t" << *a << std::endl; std::cout << "\t" << *a << std::endl;
}
return true; return true;
}); });
} }
...@@ -224,8 +231,9 @@ main(int argc, char **argv) ...@@ -224,8 +231,9 @@ main(int argc, char **argv)
dht.put(id, dht::Value { dht.put(id, dht::Value {
dht::ValueType::USER_DATA.id, dht::ValueType::USER_DATA.id,
std::vector<uint8_t> {v.begin(), v.end()} std::vector<uint8_t> {v.begin(), v.end()}
}, [](bool ok) { }, [start](bool ok) {
std::cout << "Put done !" << ok << std::endl; auto end = std::chrono::high_resolution_clock::now();
std::cout << "Put: " << (ok ? "success" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl;
}); });
} }
else if (op == "s") { else if (op == "s") {
...@@ -234,8 +242,9 @@ main(int argc, char **argv) ...@@ -234,8 +242,9 @@ main(int argc, char **argv)
dht.putSigned(id, dht::Value { dht.putSigned(id, dht::Value {
dht::ValueType::USER_DATA.id, dht::ValueType::USER_DATA.id,
std::vector<uint8_t> {v.begin(), v.end()} std::vector<uint8_t> {v.begin(), v.end()}
}, [](bool ok) { }, [start](bool ok) {
std::cout << "Put signed done !" << ok << std::endl; auto end = std::chrono::high_resolution_clock::now();
std::cout << "Put signed: " << (ok ? "success" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl;
}); });
} }
else if (op == "e") { else if (op == "e") {
...@@ -245,15 +254,17 @@ main(int argc, char **argv) ...@@ -245,15 +254,17 @@ main(int argc, char **argv)
dht.putEncrypted(id, InfoHash(tostr), dht::Value { dht.putEncrypted(id, InfoHash(tostr), dht::Value {
dht::ValueType::USER_DATA.id, dht::ValueType::USER_DATA.id,
std::vector<uint8_t> {v.begin(), v.end()} std::vector<uint8_t> {v.begin(), v.end()}
}, [](bool ok) { }, [start](bool ok) {
std::cout << "Put encrypted done !" << ok << std::endl; auto end = std::chrono::high_resolution_clock::now();
std::cout << "Put encrypted: " << (ok ? "success" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl;
}); });
} }
else if (op == "a") { else if (op == "a") {
in_port_t port; in_port_t port;
iss >> port; iss >> port;
dht.put(id, dht::Value {dht::IpServiceAnnouncement::TYPE.id, dht::IpServiceAnnouncement(port)}, [](bool ok) { dht.put(id, dht::Value {dht::IpServiceAnnouncement::TYPE.id, dht::IpServiceAnnouncement(port)}, [start](bool ok) {
std::cout << "Announce done !" << ok << std::endl; auto end = std::chrono::high_resolution_clock::now();
std::cout << "Announce: " << (ok ? "success" : "failure") << " (took " << print_dt(end-start) << "s)" << std::endl;
}); });
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment