forked from miximtor/msocks
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* systemd support * refactory * intrusive_list * use intrusive list * use macro buffer size controls * add visual stuio ignores * add session buffer size macro control * remove boost third party * shadowsocks protocol supported
- Loading branch information
Showing
35 changed files
with
1,370 additions
and
1,037 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,8 @@ | |
# Clion build outputs | ||
.idea* | ||
cmake-build-* | ||
|
||
#Visual Studio build outputs | ||
|
||
CMakeSettings.json | ||
.vs* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
[Unit] | ||
Description = msocks daemon service | ||
|
||
[Service] | ||
ExecStart=/usr/bin/msocks | ||
Type = simple | ||
ExecStart=/usr/bin/msocks s 0.0.0.0 4500 123456 4096 | ||
ExecStop=/bin/kill -TERM $MAINPID | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Created by maxtorm on 2019/4/13. | ||
// | ||
#pragma once | ||
|
||
#include <boost/asio/spawn.hpp> | ||
#include <boost/asio/ip/tcp.hpp> | ||
#include <spdlog/spdlog.h> | ||
|
||
using namespace boost::asio; | ||
using namespace boost::system; | ||
|
||
namespace msocks | ||
{ | ||
|
||
class basic_endpoint : public noncopyable | ||
{ | ||
protected: | ||
|
||
explicit basic_endpoint(io_context& ioc) : | ||
ioc_(ioc), acceptor_(ioc) | ||
{} | ||
|
||
template <typename SessionCreate> | ||
void start_service(SessionCreate create, const ip::tcp::endpoint& ep) | ||
{ | ||
spawn( | ||
ioc_, | ||
[create(std::move(create)), this, ep](yield_context yield) | ||
{ | ||
do_async_accept(create, ep, yield); | ||
}); | ||
} | ||
|
||
io_context& ioc_; | ||
ip::tcp::acceptor acceptor_; | ||
|
||
private: | ||
|
||
template <typename SessionCreate> | ||
void do_async_accept(SessionCreate create, const ip::tcp::endpoint ep, yield_context yield) | ||
{ | ||
try | ||
{ | ||
acceptor_.open(ep.protocol()); | ||
acceptor_.set_option(ip::tcp::socket::reuse_address(true)); | ||
acceptor_.bind(ep); | ||
acceptor_.listen(); | ||
while (true) | ||
{ | ||
ip::tcp::socket s(ioc_); | ||
acceptor_.async_accept(s, yield); | ||
auto session = create(std::move(s)); | ||
session->go(); | ||
} | ||
} | ||
catch (system_error & e) | ||
{ | ||
std::stringstream ss; | ||
ss << ep; | ||
spdlog::error("endpoint {}: error {}", ss.str(), e.what()); | ||
} | ||
} | ||
}; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Created by maxtorm on 2019/4/13. | ||
// | ||
|
||
#pragma once | ||
#include <msocks/endpoint/basic_endpoint.hpp> | ||
|
||
namespace msocks | ||
{ | ||
|
||
struct client_config | ||
{ | ||
client_config() : timeout(0) | ||
{ | ||
}; | ||
std::string local_address; | ||
uint16_t local_port = 0; | ||
std::string remote_address; | ||
uint16_t remote_port = 0; | ||
std::vector<uint8_t> key; | ||
std::string method; | ||
boost::posix_time::seconds timeout; | ||
}; | ||
|
||
class client_endpoint final : public basic_endpoint | ||
{ | ||
public: | ||
client_endpoint(io_context& ioc, client_config cfg) : | ||
basic_endpoint(ioc), | ||
cfg_(std::move(cfg)) | ||
{} | ||
|
||
void start(); | ||
|
||
private: | ||
client_config cfg_; | ||
|
||
}; | ||
|
||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Created by maxtorm on 2019/4/13. | ||
// | ||
#pragma once | ||
|
||
#include <msocks/endpoint/basic_endpoint.hpp> | ||
#include <msocks/session/pool.hpp> | ||
#include <msocks/session/server_session.hpp> | ||
#include <msocks/utility/rate_limiter.hpp> | ||
|
||
namespace msocks | ||
{ | ||
|
||
struct server_endpoint_config | ||
{ | ||
server_endpoint_config() : timeout(0) {}; | ||
std::string server_address; | ||
uint16_t server_port = 0; | ||
size_t speed_limit = 0; | ||
std::vector<uint8_t> key; | ||
bool no_delay = true; | ||
std::string method; | ||
boost::posix_time::seconds timeout; | ||
}; | ||
|
||
class server_endpoint final : public basic_endpoint | ||
{ | ||
public: | ||
server_endpoint(io_context& ioc, pool<server_session>& session_pool, server_endpoint_config cfg); | ||
|
||
void start(); | ||
private: | ||
pool<server_session>& session_pool_; | ||
server_endpoint_config cfg_; | ||
std::shared_ptr<utility::rate_limiter> limiter_; | ||
}; | ||
|
||
} |
Oops, something went wrong.