123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #ifndef __ASIO2_SOCKS5_SERVER_HPP__
- #define __ASIO2_SOCKS5_SERVER_HPP__
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- #pragma once
- #endif
- #include <asio2/base/detail/push_options.hpp>
- #include <asio2/tcp/tcp_server.hpp>
- #include <asio2/proxy/socks5_session.hpp>
- namespace asio2::detail
- {
- ASIO2_CLASS_FORWARD_DECLARE_BASE;
- ASIO2_CLASS_FORWARD_DECLARE_TCP_BASE;
- ASIO2_CLASS_FORWARD_DECLARE_TCP_SERVER;
- template<class derived_t, class session_t>
- class socks5_server_impl_t
- : public tcp_server_impl_t<derived_t, session_t>
- {
- ASIO2_CLASS_FRIEND_DECLARE_BASE;
- ASIO2_CLASS_FRIEND_DECLARE_TCP_BASE;
- ASIO2_CLASS_FRIEND_DECLARE_TCP_SERVER;
- public:
- using super = tcp_server_impl_t <derived_t, session_t>;
- using self = socks5_server_impl_t<derived_t, session_t>;
- using session_type = session_t;
- public:
-
- template<class... Args>
- explicit socks5_server_impl_t(Args&&... args)
- : super(std::forward<Args>(args)...)
- {
- }
-
- ~socks5_server_impl_t()
- {
- this->stop();
- }
-
- template<typename String, typename StrOrInt, typename... Args>
- inline bool start(String&& host, StrOrInt&& service, Args&&... args)
- {
- return this->derived()._do_start(
- std::forward<String>(host), std::forward<StrOrInt>(service),
- ecs_helper::make_ecs(detail::socks5_server_match_role{}, std::forward<Args>(args)...));
- }
- public:
-
- template<class F, class ...C>
- inline derived_t& bind_socks5_handshake(F&& fun, C&&... obj)
- {
- this->listener_.bind(event_type::upgrade,
- observer_t<std::shared_ptr<session_t>&>(
- std::forward<F>(fun), std::forward<C>(obj)...));
- return (this->derived());
- }
- };
- }
- namespace asio2
- {
- template<class derived_t, class session_t>
- using socks5_server_impl_t = detail::socks5_server_impl_t<derived_t, session_t>;
-
- template<class session_t>
- class socks5_server_t : public detail::socks5_server_impl_t<socks5_server_t<session_t>, session_t>
- {
- public:
- using detail::socks5_server_impl_t<socks5_server_t<session_t>, session_t>::socks5_server_impl_t;
- };
-
- using socks5_server = socks5_server_t<socks5_session>;
- }
- #include <asio2/base/detail/pop_options.hpp>
- #endif
|