Permalink
Browse files

clean code

  • Loading branch information...
AmarOk1412 committed Nov 3, 2017
1 parent 9abc88f commit 6413571301daaa2910ea5482b4084887156e63e5
View
@@ -17,7 +17,7 @@ option (OPENDHT_ARGON2 "Use included argon2 sources" OFF)
option (OPENDHT_LTO "Build with LTO" OFF)
option (OPENDHT_SANITIZE "Build with address sanitizer and stack protector" OFF)
option (OPENDHT_PROXY_SERVER "Enable DHT proxy server, use Restbed and jsoncpp" OFF)
option (OPENDHT_PROXY_SERVER_OPTIONAL "Enable sign and encrypt endpoints" OFF)
option (OPENDHT_PROXY_SERVER_IDENTITY "Allow clients to use the node identity" OFF)
option (OPENDHT_PROXY_CLIENT "Enable DHT proxy client, use Restbed and jsoncpp" OFF)
find_package(Doxygen)
@@ -93,7 +93,6 @@ include_directories (
include/
include/opendht/
${CMAKE_CURRENT_BINARY_DIR}/include/
/usr/include/jsoncpp
)
# Install dirs
@@ -157,17 +156,17 @@ list (APPEND opendht_HEADERS
if (OPENDHT_PROXY_SERVER)
add_definitions(-DOPENDHT_PROXY_SERVER=true)
if (OPENDHT_PROXY_SERVER_OPTIONAL)
add_definitions(-DOPENDHT_PROXY_SERVER_OPTIONAL=true)
if (OPENDHT_PROXY_SERVER_IDENTITY)
add_definitions(-DOPENDHT_PROXY_SERVER_IDENTITY=true)
else ()
add_definitions(-DOPENDHT_PROXY_SERVER_OPTIONAL=false)
add_definitions(-DOPENDHT_PROXY_SERVER_IDENTITY=false)
endif()
list (APPEND opendht_HEADERS
include/opendht/dhtproxyserver.h
include/opendht/base64.h
include/opendht/dht_proxy_server.h
)
list (APPEND opendht_SOURCES
src/dhtproxyserver.cpp
src/dht_proxy_server.cpp
src/base64.h
src/base64.cpp
)
else ()
View
@@ -91,13 +91,11 @@ for r in results:
- msgpack-c 1.2+, used for data serialization.
- GnuTLS 3.3+, used for cryptographic operations.
- Nettle 2.4+, a GnuTLS dependency for crypto.
- (optional) restbed 4.0+, used for the REST API.
- (optional) jsoncpp 1.7.4-3+, used for the REST API.
- Build tested with GCC 4.8+ (GNU/Linux, Android, Windows with MinGW), Clang/LLVM (Linux, macOS).
- Build tested with Microsoft Visual Studio 2015
### Optional dependencies
- restbed 4.0+, used for the REST API.
- jsoncpp 1.7.4-3+, used for the REST API.
## Contact
IRC: join us on Freenode at [`#opendht`](https://webchat.freenode.net/?channels=%23opendht).
View
@@ -135,13 +135,13 @@ AM_COND_IF([ENABLE_PROXY_SERVER], [
PKG_CHECK_MODULES([Jsoncpp], [jsoncpp >= 1.7.4])
CPPFLAGS+=" -DOPENDHT_PROXY_SERVER=true -ljsoncpp -lrestbed"
AC_ARG_ENABLE([proxy_server_optionals], AS_HELP_STRING([--enable-proxy-server-optionals],
[Enable proxy server ability]), proxy_server_optionals=yes, proxy_server_optionals=no)
AM_CONDITIONAL(ENABLE_PROXY_SERVER_OPTIONALS, test x$proxy_server_optionals == xyes)
AM_COND_IF([ENABLE_PROXY_SERVER_OPTIONALS], [
CPPFLAGS+=" -DOPENDHT_PROXY_SERVER_OPTIONAL=true"
AC_ARG_ENABLE([proxy_server_identity], AS_HELP_STRING([--enable-proxy-server-identity],
[Enable proxy server ability]), proxy_server_identity=yes, proxy_server_identity=no)
AM_CONDITIONAL(ENABLE_PROXY_SERVER_IDENTITY, test x$proxy_server_identity == xyes)
AM_COND_IF([ENABLE_PROXY_SERVER_IDENTITY], [
CPPFLAGS+=" -DOPENDHT_PROXY_SERVER_IDENTITY=true"
], [
CPPFLAGS+=" -DOPENDHT_PROXY_SERVER_OPTIONAL=false"
CPPFLAGS+=" -DOPENDHT_PROXY_SERVER_IDENTITY=false"
])
], [
CPPFLAGS+=" -DOPENDHT_PROXY_SERVER=false"
View
@@ -19,6 +19,9 @@
#pragma once
#include "opendht/dhtrunner.h"
#if OPENDHT_PROXY_SERVER
#include "opendht/dht_proxy_server.h"
#endif
#include "opendht/log.h"
#include "opendht/default_types.h"
#include "opendht/indexation/pht.h"
View

This file was deleted.

Oops, something went wrong.
@@ -21,6 +21,8 @@
#pragma once
#include "def.h"
#include "sockaddr.h"
#include "infohash.h"
#include <thread>
#include <memory>
@@ -29,6 +31,7 @@
namespace dht {
class DhtRunner;
class InfoHash;
/**
* Describes the REST API
@@ -43,13 +46,13 @@ class OPENDHT_PUBLIC DhtProxyServer
* @note if the server fails to start (if port is already used or reserved),
* it will fails silently
*/
DhtProxyServer(DhtRunner* dht, unsigned int port = 8000);
DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port = 8000);
virtual ~DhtProxyServer();
DhtProxyServer(const DhtProxyServer& other) = default;
DhtProxyServer(DhtProxyServer&& other) = default;
DhtProxyServer& operator=(const DhtProxyServer& other) = default;
DhtProxyServer& operator=(DhtProxyServer&& other) = default;
DhtProxyServer(const DhtProxyServer& other) = delete;
DhtProxyServer(DhtProxyServer&& other) = delete;
DhtProxyServer& operator=(const DhtProxyServer& other) = delete;
DhtProxyServer& operator=(DhtProxyServer&& other) = delete;
/**
* Stop the DhtProxyServer
@@ -62,6 +65,7 @@ class OPENDHT_PUBLIC DhtProxyServer
* Method: GET "/"
* Result: HTTP 200, body: Value in JSON format (one part = one value)
* On error: HTTP 404, body: {"err":"xxxx"}
* @param session
*/
void getNodeInfo(const std::shared_ptr<restbed::Session>& session) const;
@@ -74,6 +78,7 @@ class OPENDHT_PUBLIC DhtProxyServer
* {"ok": 1}
*
* On error: HTTP 404, body: {"err":"xxxx"}
* @param session
*/
void get(const std::shared_ptr<restbed::Session>& session) const;
@@ -85,6 +90,7 @@ class OPENDHT_PUBLIC DhtProxyServer
* Value in JSON format (HTTP/1.1 200 OK Content-Type: application/json)
*
* On error: HTTP 404, body: {"err":"xxxx"}
* @param session
*/
void listen(const std::shared_ptr<restbed::Session>& session) const;
@@ -95,17 +101,19 @@ class OPENDHT_PUBLIC DhtProxyServer
* Return: {"ok":"1"}
* On error: HTTP 404, body: {"err":"xxxx"} if no dht
* HTTP 400, body: {"err":"xxxx"} if bad json
* @param session
*/
void put(const std::shared_ptr<restbed::Session>& session) const;
#if OPENDHT_PROXY_SERVER_OPTIONAL
#if OPENDHT_PROXY_SERVER_IDENTITY
/**
* Put a value to sign by the proxy on the DHT
* Method: SIGN "/{InfoHash: .*}"
* body = Value to put in JSON
* Return: {"ok":"1"}
* On error: HTTP 404, body: {"err":"xxxx"} if no dht
* HTTP 400, body: {"err":"xxxx"} if bad json
* @param session
*/
void putSigned(const std::shared_ptr<restbed::Session>& session) const;
@@ -116,9 +124,10 @@ class OPENDHT_PUBLIC DhtProxyServer
* Return: {"ok":"1"}
* On error: HTTP 404, body: {"err":"xxxx"} if no dht
* HTTP 400, body: {"err":"xxxx"} if bad json
* @param session
*/
void putEncrypted(const std::shared_ptr<restbed::Session>& session) const;
#endif // OPENDHT_PROXY_SERVER_OPTIONAL
#endif // OPENDHT_PROXY_SERVER_IDENTITY
/**
* Return Values of a InfoHash filtered by a value id
@@ -129,13 +138,24 @@ class OPENDHT_PUBLIC DhtProxyServer
* {"ok": 1}
*
* On error: HTTP 404, body: {"err":"xxxx"}
* @param session
*/
void getFiltered(const std::shared_ptr<restbed::Session>& session) const;
std::thread server_thread {};
std::unique_ptr<restbed::Service> service_;
DhtRunner* dht_;
mutable std::vector<std::shared_ptr<std::thread>> listenThreads_;
std::shared_ptr<DhtRunner> dht_;
// Handle client quit for listen.
// NOTE: can be simplified when we will supports restbed 5.0
std::thread listenThread_;
struct SessionToHashToken {
std::shared_ptr<restbed::Session> session;
InfoHash hash;
size_t token;
};
mutable std::vector<SessionToHashToken> currentListeners_;
std::atomic_bool stopListeners {false};
};
}
@@ -36,10 +36,6 @@
#include <queue>
#include <chrono>
#if OPENDHT_PROXY_SERVER
#include "dhtproxyserver.h"
#endif
namespace dht {
struct Node;
@@ -366,18 +362,6 @@ class OPENDHT_PUBLIC DhtRunner {
*/
void join();
#if OPENDHT_PROXY_SERVER
/**
* Start the proxy server
* @param port used for the server
*/
void startProxyServer(unsigned int port=8000);
/**
* Stop the proxy server
*/
void stopProxyServer();
#endif //OPENDHT_PROXY_SERVER
private:
static constexpr std::chrono::seconds BOOTSTRAP_PERIOD {10};
@@ -407,10 +391,6 @@ class OPENDHT_PUBLIC DhtRunner {
std::mutex sock_mtx {};
std::vector<std::pair<Blob, SockAddr>> rcv {};
#if OPENDHT_PROXY_SERVER
std::unique_ptr<DhtProxyServer> proxy_server_;
#endif //OPENDHT_PROXY_SERVER
/** true if currently actively boostraping */
std::atomic_bool bootstraping {false};
/* bootstrap nodes given as (host, service) pairs */
View
@@ -39,7 +39,6 @@
#if OPENDHT_PROXY_SERVER
#include <json/json.h>
#include "base64.h"
#endif //OPENDHT_PROXY_SERVER
namespace dht {
@@ -356,42 +355,7 @@ struct OPENDHT_PUBLIC Value
* Build a value from a json object
* @param json
*/
Value(Json::Value& json) {
try {
if (json.isMember("id"))
id = ValueType::Id(json["id"].asInt());
} catch (...) { }
if (json.isMember("cypher")) {
auto cypherStr = json["cypher"].asString();
cypherStr = base64_decode(cypherStr);
cypher = std::vector<unsigned char>(cypherStr.begin(), cypherStr.end());
}
if (json.isMember("sig")) {
auto sigStr = json["sig"].asString();
sigStr = base64_decode(sigStr);
signature = std::vector<unsigned char>(sigStr.begin(), sigStr.end());
}
if (json.isMember("seq"))
seq = json["seq"].asInt();
if (json.isMember("owner")) {
auto ownerStr = json["owner"].asString();
auto ownerBlob = std::vector<unsigned char>(ownerStr.begin(), ownerStr.end());
owner = std::make_shared<const crypto::PublicKey>(ownerBlob);
}
if (json.isMember("to")) {
auto toStr = json["to"].asString();
recipient = InfoHash(toStr);
}
if (json.isMember("type"))
type = json["type"].asInt();
if (json.isMember("data")){
auto dataStr = json["data"].asString();
dataStr = base64_decode(dataStr);
data = std::vector<unsigned char>(dataStr.begin(), dataStr.end());
}
if (json.isMember("utype"))
user_type = json["utype"].asString();
}
Value(Json::Value& json);
#endif //OPENDHT_PROXY_SERVER
template <typename Type>
View
@@ -55,8 +55,8 @@ nobase_include_HEADERS = \
../include/opendht/indexation/pht.h
if ENABLE_PROXY_SERVER
libopendht_la_SOURCES += base64.cpp dhtproxyserver.cpp
nobase_include_HEADERS += ../include/opendht/base64.h ../include/opendht/dhtproxyserver.h
libopendht_la_SOURCES += base64.h base64.cpp dht_proxy_server.cpp
nobase_include_HEADERS += ../include/opendht/dht_proxy_server.h
endif
clean-local:
Oops, something went wrong.

0 comments on commit 6413571

Please sign in to comment.