Skip to content

Commit

Permalink
ubuntu14 правки
Browse files Browse the repository at this point in the history
  • Loading branch information
sv-91 committed Dec 16, 2019
1 parent 355f5d2 commit 3544160
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "3rdParty/ubuntu14/libsniper"]
path = 3rdParty/ubuntu14/libsniper/libsniper
url = git@github.com:metahashorg/libsniper.git
[submodule "3rdParty/ubuntu18/libsniper"]
path = 3rdParty/ubuntu18/libsniper
url = git@github.com:metahashorg/libsniper.git
Expand Down
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
include_directories(/usr/local/include)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if (DEFINED UBUNTU14)
add_definitions(-DUBUNTU14="")
endif()

if (NOT DEFINED UBUNTU14)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu18/secp256k1/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu18/openssl/include/)
Expand All @@ -17,6 +21,7 @@ if (DEFINED UBUNTU14)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu14/rapidjson/)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu14/libconfig/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu14/lz4/include/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu14/libsniper/)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../common_utils/")
Expand Down Expand Up @@ -173,6 +178,18 @@ if (DEFINED UBUNTU14)
find_library(CONFIG2_LIB NAMES libconfig.a HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../3rdParty/ubuntu14/libconfig/lib/)
endif()

if (DEFINED UBUNTU14)
find_package(MHSupport)

SET(SNIPER_LIBRARIES
mh_mhd
mh_xxhash
mh_libevent

uriparser.a
)
endif()

set(PROJECT_LIBS
${LZ4_LIB}

Expand Down
4 changes: 3 additions & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,11 @@ bool Server::init() {

set_threads(COUNT_THREADS);
set_port(port);


#ifndef UBUNTU14
set_connection_limit(200000);
set_per_ip_connection_limit(100);
#endif

return true;
}
12 changes: 9 additions & 3 deletions src/Server.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef SERVER_H_
#define SERVER_H_

#include <sniper/mhd/MHD.h>

#include <string>
#include <atomic>

Expand All @@ -12,7 +10,15 @@ namespace torrent_node_lib {
class Sync;
}

class Server: public sniper::mhd::MHD {
#ifdef UBUNTU14
#include <mh/mhd/MHD.h>
using MHD = mh::mhd::MHD;
#else
#include <sniper/mhd/MHD.h>
using MHD = sniper::mhd::MHD;
#endif

class Server: public MHD {
public:

Server(const torrent_node_lib::Sync &sync, int port, std::atomic<int> &countRunningThreads, const std::string &serverPrivKey)
Expand Down
38 changes: 33 additions & 5 deletions src/libeventWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "libeventWrapper.h"

#ifdef UBUNTU14
#include <mh/libevent/LibEvent.h>
#else
#include <sniper/http/SyncClient.h>
#endif

#include "check.h"
#include "OopUtils.h"
Expand Down Expand Up @@ -32,7 +36,11 @@ void LibEvent::destroy() {
LibEvent::LibEventInstance LibEvent::getInstance() {
CHECK(isInitialized.load(), "not initialized");

std::unique_ptr<sniper::http::SyncClient> libevent = std::make_unique<sniper::http::SyncClient>(10s);
#ifdef UBUNTU14
std::unique_ptr<SyncClient> libevent = std::make_unique<SyncClient>();
#else
std::unique_ptr<SyncClient> libevent = std::make_unique<SyncClient>(10s);
#endif
CHECK(libevent != nullptr, "libevent == nullptr");

return LibEventInstance(std::move(libevent));
Expand All @@ -45,18 +53,38 @@ std::string LibEvent::request(const LibEvent::LibEventInstance& instance, const
CHECK(lock.owns_lock(), "Curl instanse one of thread");

CHECK(instance.libevent != nullptr, "Incorrect curl instance");
sniper::http::SyncClient &libevent = *instance.libevent.get();

SyncClient &libevent = *instance.libevent.get();

#ifdef UBUNTU14
const size_t found = url.find_last_of(":");
std::string host = url;
int port = 80;
if (found != url.npos && url.substr(0, found) != "http" && url.substr(0, found) != "https") {
host = url.substr(0, found);
port = std::stoi(url.substr(found + 1));
}
std::string path;
const size_t foundPath = url.find("/");
if (foundPath != url.npos) {
host = url.substr(0, std::min(host.size(), foundPath));
path = url.substr(foundPath);
}

std::string response;
libevent.post_keep_alive(host, port, host, path, postData, response, timeoutSec * 1000);

return response;
#else
const auto response = libevent.post(url, postData);

return std::string(response->data());
#endif
}

LibEvent::LibEventInstance::LibEventInstance()
: libevent(nullptr)
{}

LibEvent::LibEventInstance::LibEventInstance(std::unique_ptr<sniper::http::SyncClient> &&libevent)
LibEvent::LibEventInstance::LibEventInstance(std::unique_ptr<SyncClient> &&libevent)
: libevent(std::move(libevent))
{}

Expand Down
14 changes: 12 additions & 2 deletions src/libeventWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
#include <atomic>
#include <memory>

#ifdef UBUNTU14
namespace mh {
namespace libevent {
class LibEvent;
}
}
using SyncClient = mh::libevent::LibEvent;
#else
namespace sniper {
namespace http {
class SyncClient;
}
}
using SyncClient = sniper::http::SyncClient;
#endif

struct LibEvent {
public:
Expand All @@ -20,15 +30,15 @@ struct LibEvent {

LibEventInstance();

LibEventInstance(std::unique_ptr<sniper::http::SyncClient> &&libevent);
LibEventInstance(std::unique_ptr<SyncClient> &&libevent);

LibEventInstance(LibEventInstance &&second);

~LibEventInstance();

LibEventInstance& operator=(LibEventInstance &&second);

std::unique_ptr<sniper::http::SyncClient> libevent;
std::unique_ptr<SyncClient> libevent;

private:

Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ static void serverThreadFunc(const Sync &sync, int port, const std::string &serv
try {
Server server(sync, port, countRunningServerThreads, serverPrivKey);
std::this_thread::sleep_for(1s); // Небольшая задержка сервера перед запуском
server.start("./");
const bool res = server.start("./");
CHECK(res, "Not started server");
} catch (const exception &e) {
LOGERR << e;
} catch (const std::exception &e) {
Expand Down

0 comments on commit 3544160

Please sign in to comment.