diff --git a/include/opendht/callbacks.h b/include/opendht/callbacks.h index b58a8b1fe83c8c802f5c7a7293a11625496e3eba..b3b1b6f7a255a7fabdb1234fe8511b7fbbab6409 100644 --- a/include/opendht/callbacks.h +++ b/include/opendht/callbacks.h @@ -1,7 +1,8 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. - * Author : Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/opendht/dht.h b/include/opendht/dht.h index 09bb0f56bb1c4f26246acb1b692e774ae943d56a..2bc18b5bb7162c7a4151d4d15d511ff0c34ed368 100644 --- a/include/opendht/dht.h +++ b/include/opendht/dht.h @@ -1,7 +1,8 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. - * Author(s) : Adrien Béraud <adrien.beraud@savoirfairelinux.com> - * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index fbc89dee56a59f916b8c2ab96778d63a3871342b..d7f573e56b1a7f2f7dfe3fe9ef56dc5236751ffa 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -1,7 +1,8 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. - * Author(s) : Adrien Béraud <adrien.beraud@savoirfairelinux.com> - * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/include/opendht/securedht.h b/include/opendht/securedht.h index cd67bff81293a7291e81cc08b65bb2f9d44220d9..a4ff6ec4a0b0342bdb66560f9312817c704031e8 100644 --- a/include/opendht/securedht.h +++ b/include/opendht/securedht.h @@ -1,7 +1,8 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. - * Author : Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index 0a3eb5471339a0ccdaa50491685349aa667b619d..31db722bc248fd732615a688f8a760a5d249367b 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -27,8 +27,6 @@ #include "dhtrunner.h" -#include <iostream> - constexpr const char* const HTTP_PROTO {"http://"}; namespace dht { diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp index 2b5756fe634a82464087e46fb017660f57572fe0..5be8da7361a649e6f1c516e33be76dd3fb6cf55c 100644 --- a/src/dht_proxy_server.cpp +++ b/src/dht_proxy_server.cpp @@ -82,33 +82,35 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port) std::this_thread::sleep_for(std::chrono::seconds(1)); } while (service_->is_up() && !stopListeners) { - lockListener_.lock(); + { + std::lock_guard<std::mutex> lock(lockListener_); + auto listener = currentListeners_.begin(); + while (listener != currentListeners_.end()) { + if (dht_ && listener->session->is_closed()) { + dht_->cancelListen(listener->hash, std::move(listener->token)); + // Remove listener if unused + listener = currentListeners_.erase(listener); + } else { + ++listener; + } + } + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + // Remove last listeners + { + std::lock_guard<std::mutex> lock(lockListener_); auto listener = currentListeners_.begin(); while (listener != currentListeners_.end()) { - if (dht_ && listener->session->is_closed()) { - dht_->cancelListen(listener->hash, std::move(listener->token)); + if (dht_) { + dht_->cancelListen(listener->hash, std::move(listener->token.get())); // Remove listener if unused listener = currentListeners_.erase(listener); } else { - ++listener; + ++listener; } } - lockListener_.unlock(); - std::this_thread::sleep_for(std::chrono::seconds(1)); - } - // Remove last listeners - lockListener_.lock(); - auto listener = currentListeners_.begin(); - while (listener != currentListeners_.end()) { - if (dht_) { - dht_->cancelListen(listener->hash, std::move(listener->token.get())); - // Remove listener if unused - listener = currentListeners_.erase(listener); - } else { - ++listener; - } } - lockListener_.unlock(); }); dht->forwardAllMessages(true); @@ -123,13 +125,14 @@ void DhtProxyServer::stop() { service_->stop(); - lockListener_.lock(); - auto listener = currentListeners_.begin(); - while (listener != currentListeners_.end()) { - listener->session->close(); - ++ listener; + { + std::lock_guard<std::mutex> lock(lockListener_); + auto listener = currentListeners_.begin(); + while (listener != currentListeners_.end()) { + listener->session->close(); + ++ listener; + } } - lockListener_.unlock(); stopListeners = true; // listenThreads_ will stop because there is no more sessions if (listenThread_.joinable()) @@ -248,9 +251,10 @@ DhtProxyServer::listen(const std::shared_ptr<restbed::Session>& session) const } return !s->is_closed(); }); - lockListener_.lock(); - currentListeners_.emplace_back(std::move(listener)); - lockListener_.unlock(); + { + std::lock_guard<std::mutex> lock(lockListener_); + currentListeners_.emplace_back(std::move(listener)); + } } else { session->close(restbed::SERVICE_UNAVAILABLE, "{\"err\":\"Incorrect DhtRunner\"}"); } diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp index 589bc80de94efbabc07ea0e4a4f5402657ac575d..6a1fab5fa9ec1e3be8dad92df4cf917024bb2b07 100644 --- a/src/dhtrunner.cpp +++ b/src/dhtrunner.cpp @@ -1,7 +1,8 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. - * Author(s) : Adrien Béraud <adrien.beraud@savoirfairelinux.com> - * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/securedht.cpp b/src/securedht.cpp index 99c7557e789139a63350a1d7b430ff268134f5e0..338bcb2c55d8fd3875903e53b75b16b390ea1d10 100644 --- a/src/securedht.cpp +++ b/src/securedht.cpp @@ -1,7 +1,8 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. - * Author : Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/tools/dhtnode.cpp b/tools/dhtnode.cpp index 6776876fca216a794197f4e5c92e94e62ba6620d..7c2ca14f1975a1e9e1d38ada3ef3d53d823db9a8 100644 --- a/tools/dhtnode.cpp +++ b/tools/dhtnode.cpp @@ -1,8 +1,9 @@ /* * Copyright (C) 2014-2017 Savoir-faire Linux Inc. * - * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> - * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Authors: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Simon Désaulniers <simon.desaulniers@savoirfairelinux.com> + * Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/tools/tools_common.h b/tools/tools_common.h index c71fa680fc2f25c340f3cdac4ef64f308312a383..cbd8a5c8d4350d828c917d15c345267540ab9223 100644 --- a/tools/tools_common.h +++ b/tools/tools_common.h @@ -2,6 +2,7 @@ * Copyright (C) 2014-2017 Savoir-faire Linux Inc. * * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> + * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by