- Forward client message to specific game server, by using a profile
node.json
- Key exchange and data encryption
- Multithread and have simple load balance policy: Least Connections
- Auto reload profile
node.json
every 10 seconds for add new game server. - Protocol convert: Convert other tcp protocol to
moon.PTYPE_SOCKET_MOON
- If you want convert other tcp protocol, modify this code:
static awaitable<asio::error_code> read_message(tcp::socket& sock, asio::streambuf& buf)
{
std::tuple<asio::error_code, size_t> res =
co_await asio::async_read(sock, buf, asio::transfer_exactly(sizeof(uint16_t)), use_nothrow_awaitable);
if (!std::get<0>(res))
{
auto data = reinterpret_cast<const char*>(buf.data().data());
uint16_t size;
memcpy(&size, data, sizeof(uint16_t));
size = network_to_host_short(size);
buf.prepare(size);
res = co_await asio::async_read(sock, buf, asio::transfer_exactly(size), use_nothrow_awaitable);
}
co_return std::get<0>(res);
}
- Write your handeshark code here:
static awaitable<bool> handshake(tcp::socket& from, tcp::socket& to)
{
//asio::streambuf handshake;
//auto e1 = co_await read_message(from, handshake);
//if (e1)
//{
// CONSOLE_LOG("Handshake read %s: %s\n", address(from).data(), e1.message().data());
// co_return false;
//}
// auto content = message_content(handshake);
// TODO
// e. Diffie-Hellman Key exchange
...
- Handle client to server message:
transfer_client_to_server
- Handle server to client message:
transfer_server_to_client
- windows:
premake5 vs2022
- linux(gcc 11+):
premake5 gmake & make config=release
# proxy [-p listenport] [-c filename] [-t threadnum]
./proxy -p 5001 -c node.json -t 32