Skip to content

Commit

Permalink
release 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
miximtor committed Apr 8, 2019
1 parent 0bff1e3 commit d9ff365
Show file tree
Hide file tree
Showing 24 changed files with 2,933 additions and 499 deletions.
9 changes: 6 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third_party/boost"]
path = third_party/boost
url = https://github.com/microcai/boost.git
[submodule "third_party/spdlog"]
path = third_party/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "third_party/fmt"]
path = third_party/fmt
url = https://github.com/fmtlib/fmt.git
39 changes: 18 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,34 @@ cmake_minimum_required(VERSION 3.13)
project(msocks)

set(CMAKE_CXX_STANDARD 17)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_ARCHITECTURE -x64)
set(Boost_USE_STATIC_RUNTIME ON)

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -Wall")

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/modules)

find_package(Boost 1.66 COMPONENTS system coroutine)
find_package(Botan2 2.10.0 REQUIRED)
find_package(Boost 1.69 COMPONENTS system coroutine random REQUIRED)
find_package(glog REQUIRED)
include_directories(${GLOG_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${BOTAN2_INCLUDE_DIRS})
include_directories(third_party/spdlog/include)
include_directories(src)

if (NOT Boost_FOUND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/boost)
endif()
add_definitions(-DBOOST_ASIO_NO_DEPRECATED)
add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)

if(WIN32)
add_definitions(-DMSOCKS_WINDOWS)
if (MSVC)
add_definitions(-D_WIN32_WINNT=0x0A00)
add_definitions(-DMSOCKS_MSVC)
elseif(MINGW)
add_definitions(-DMSOCKS_MINGW)
elseif(UNIX)
add_definitions(-DMSOCKS_UNIX)
endif()

find_package(Glog REQUIRED)
find_package(Botan2 2.8.0 REQUIRED)

add_definitions(-DBOOST_ASIO_NO_DEPRECATED)
add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING)
add_definitions(-DGLOG_NO_ABBREVIATED_SEVERITIES)

add_subdirectory(${PROJECT_SOURCE_DIR}/src)
if (UNIX)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX})
endif()

2 changes: 2 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"server": "0.0.0.0",
"server_port": 6999,
"local" : "127.0.0.1",
"local_port" : 1081,
"password": "123456",
"method": "ChaCha(20)",
"speed_limit" : 1024
Expand Down
2,192 changes: 2,192 additions & 0 deletions modules/FindBoost.cmake

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/FindBotan2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ find_path(BOTAN2_INCLUDE_DIR

# find the library
find_library(BOTAN2_LIBRARY
NAMES botan-2 libbotan-2
NAMES botan-2 libbotan-2 botan
HINTS
${PC_BOTAN2_LIBDIR}
${PC_BOTAN2_LIBRARY_DIRS}
Expand Down
48 changes: 0 additions & 48 deletions modules/FindGlog.cmake

This file was deleted.

25 changes: 15 additions & 10 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ set(SESSION_FILE
session/client_session.cpp
session/server_session.cpp
session/server_session.hpp
)
session/session.hpp)

set(ENDPOINT_FILE
endpoint/server.cpp
endpoint/server.hpp
endpoint/client.cpp endpoint/client.hpp endpoint/endpoint.hpp)
endpoint/client.cpp
endpoint/client.hpp
endpoint/endpoint.hpp
)

set(CONFIG_FILE
config/config.hpp
Expand All @@ -17,10 +20,10 @@ set(CONFIG_FILE
set(UTILITY_FILE
utility/socks_constants.hpp
utility/socket_pair.hpp
utility/signal_handle.hpp utility/limiter.hpp)
utility/signal_handle.hpp
utility/limiter.hpp
utility/local_socks5.hpp utility/socks_erorr.hpp)

include_directories(${PROJECT_SOURCE_DIR}/src/)
include_directories(${BOTAN2_INCLUDE_DIRS})

add_executable(${PROJECT_NAME}
${SESSION_FILE}
Expand All @@ -30,8 +33,10 @@ add_executable(${PROJECT_NAME}
main.cpp
)

IF(WIN32)
target_link_libraries(${PROJECT_NAME} ${GLOG_LIBRARIES} ${BOTAN2_LIBRARIES} boost_system-mt boost_coroutine-mt ws2_32 wsock32 )
ELSE(WIN32)
target_link_libraries(${PROJECT_NAME} ${GLOG_LIBRARIES} ${BOTAN2_LIBRARIES} boost_system boost_coroutine pthread)
ENDIF(WIN32)

IF (WIN32)
target_link_options(${PROJECT_NAME} PRIVATE -fstack-protector)
target_link_libraries(${PROJECT_NAME} Botan2::Botan2 Boost::system Boost::random Boost::coroutine ws2_32 wsock32)
ELSE ()
target_link_libraries(${PROJECT_NAME} Botan2::Botan2 Boost::system Boost::random Boost::coroutine pthread)
ENDIF ()
24 changes: 24 additions & 0 deletions src/config/config.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
#pragma once

#include <string>

namespace msocks
{

struct config
{
enum Type
{
Server = 0,
Client = 1
};
Type type;
std::string server;
unsigned short server_port;
std::string local;
unsigned short local_port;
std::string password;
std::string method;
std::size_t speed_limit;
};

}
15 changes: 8 additions & 7 deletions src/endpoint/client.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "client.hpp"
#include <boost/asio/spawn.hpp>
#include <session/client_session.hpp>
#include <glog/logging.h>
#include <usings.hpp>

namespace msocks
Expand All @@ -21,12 +20,14 @@ void client::start()
{
spawn(strand, [this](yield_context yield)
{
async_accept(yield,[this](ip::tcp::socket socket) -> std::shared_ptr<client_session>
{
return std::make_shared<client_session>(
strand,std::move(socket),remote,key
);
});
async_accept(
yield,
[this](ip::tcp::socket socket)
{
return std::make_shared<client_session>(
strand, std::move(socket), remote, key
);
});
});
context.run();
}
Expand Down
19 changes: 14 additions & 5 deletions src/endpoint/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/asio/spawn.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <usings.hpp>
#include <spdlog/spdlog.h>

namespace msocks
{
Expand All @@ -22,12 +23,20 @@ struct endpoint : public noncopyable
template <typename SessionFactory>
void async_accept(yield_context yield,SessionFactory factory)
{
while (true)
try
{
ip::tcp::socket socket(context);
acceptor.async_accept(socket,yield);
auto session = factory(std::move(socket));
session->go();
while (true)
{
ip::tcp::socket socket(context);
acceptor.async_accept(socket,yield);
auto session = factory(std::move(socket));
session->go();
}
} catch (system_error & e)
{
auto ep = acceptor.local_endpoint();
std::string addr_port = ep.address().to_string() + ":"+std::to_string(ep.port());
spdlog::error("{} error: {}",addr_port,e.what());
}
}

Expand Down
26 changes: 14 additions & 12 deletions src/endpoint/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <boost/asio/spawn.hpp>
#include <session/server_session.hpp>
#include <glog/logging.h>

#include <usings.hpp>

Expand All @@ -11,26 +10,29 @@ namespace msocks

server::server(
const ip::tcp::endpoint &listen,
const std::vector<uint8_t> &key_) :
const std::vector<uint8_t> &key_,
std::size_t limit) :
endpoint(listen),
key(key_),
limiter(new utility::limiter(strand,512*1024))
limiter(new utility::limiter(strand, limit * 1024))
{
}

void server::start()
{
spawn(strand, [this](yield_context yield)
{
async_accept(yield, [this](ip::tcp::socket socket)
{
return std::make_shared<server_session>(
strand,
std::move(socket),
key,
limiter
);
});
async_accept(
yield,
[this](ip::tcp::socket socket)
{
return std::make_shared<server_session>(
strand,
std::move(socket),
key,
limiter
);
});
});
limiter->start();
context.run();
Expand Down
2 changes: 1 addition & 1 deletion src/endpoint/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace msocks
class server : public endpoint
{
public:
server(const ip::tcp::endpoint &listen,const std::vector<uint8_t> & key_);
server(const ip::tcp::endpoint &listen,const std::vector<uint8_t> & key_,std::size_t limit);
void start();
private:
const std::vector<uint8_t> &key;
Expand Down
Loading

0 comments on commit d9ff365

Please sign in to comment.