Compare commits

..

57 Commits

Author SHA1 Message Date
aozhiwei
b013f03fdd 1 2024-09-26 15:12:51 +08:00
aozhiwei
ff39b35c05 1 2024-08-15 19:31:52 +08:00
aozhiwei
b991dc9d8c 1 2024-08-15 10:45:56 +08:00
aozhiwei
b4a74c4bd9 1 2024-04-05 16:32:45 +08:00
aozhiwei
2702692b31 1 2024-04-05 14:03:03 +08:00
azw
c89a4746dc 1 2024-04-03 05:18:05 +00:00
aozhiwei
5b87d1bf1d 1 2024-03-24 20:26:49 +08:00
aozhiwei
758e423324 1 2024-03-24 20:19:50 +08:00
aozhiwei
67880fdb53 1 2024-03-24 20:16:11 +08:00
aozhiwei
354cce97a6 1 2024-03-24 20:03:10 +08:00
aozhiwei
a244248901 1 2024-03-24 19:52:35 +08:00
aozhiwei
c748f8fa52 1 2024-03-24 19:32:34 +08:00
aozhiwei
0ad1989d8e 1 2024-03-24 19:25:36 +08:00
aozhiwei
0ede4b54fe 1 2024-03-24 18:45:05 +08:00
aozhiwei
ec94b9525a 1 2024-03-24 15:07:58 +08:00
aozhiwei
8873d2efac 1 2024-03-24 15:01:23 +08:00
aozhiwei
484a5a928a 1 2024-03-24 14:56:01 +08:00
aozhiwei
2b25856594 1 2024-03-24 14:21:03 +08:00
aozhiwei
9606fc7a1c 1 2024-03-24 14:17:16 +08:00
aozhiwei
5cc155cd2b 1 2024-03-24 14:08:43 +08:00
aozhiwei
c68e482dd8 1 2024-03-24 13:52:22 +08:00
aozhiwei
b3f165760b 1 2024-03-24 13:35:56 +08:00
aozhiwei
09ad4bea1d 1 2024-03-24 13:27:29 +08:00
aozhiwei
42ca63e9a2 1 2024-03-24 13:19:29 +08:00
aozhiwei
d20e2dcf5a 1 2024-03-24 12:28:20 +08:00
aozhiwei
7b0d28627c 1 2024-03-13 11:15:36 +08:00
aozhiwei
a3675dd417 1 2024-03-13 11:14:09 +08:00
aozhiwei
bb112e6f9a 1 2023-12-01 10:46:59 +08:00
aozhiwei
cd4bff950e 1 2023-12-01 10:44:27 +08:00
azw
f6facb7f2e 1 2023-11-27 03:34:29 +00:00
azw
81f3b0f0a3 1 2023-11-27 03:10:39 +00:00
azw
5df7e4bcc7 1 2023-11-27 02:28:00 +00:00
azw
0bf0c57cc2 1 2023-11-24 09:30:00 +00:00
aozhiwei
b9dae07be7 1 2023-11-23 17:05:49 +08:00
aozhiwei
295c29ce6b 1 2023-11-23 17:03:17 +08:00
azw
e215104358 1 2023-11-13 08:09:41 +00:00
azw
765b0b95cf 1 2023-11-13 07:05:38 +00:00
azw
2401056ac7 1 2023-11-13 07:01:17 +00:00
azw
f5965cdfb2 1 2023-11-13 07:00:59 +00:00
azw
7e4af7f435 1 2023-11-13 07:00:11 +00:00
azw
8a4e5ddc75 1 2023-11-13 06:53:33 +00:00
azw
7f456a2fea 1 2023-11-13 06:50:48 +00:00
azw
b1b9b8c3b9 1 2023-11-13 06:44:57 +00:00
azw
08f2164236 1 2023-11-13 06:31:46 +00:00
aozhiwei
30fea7fbce 1 2023-11-13 12:45:51 +08:00
aozhiwei
2379635a55 1 2023-11-13 12:01:36 +08:00
azw
d01067cd4f 1 2023-11-13 03:54:03 +00:00
azw
fedc0c25a1 1 2023-11-13 02:35:14 +00:00
azw
eda56a2ca6 1 2023-11-11 13:39:55 +00:00
aozhiwei
816b1aedf2 1 2023-10-02 12:24:43 +08:00
aozhiwei
128796e486 1 2023-10-02 12:22:13 +08:00
azw
a19ac1bf69 1 2023-09-29 06:19:11 +00:00
azw
3ffa917c5f 1 2023-09-29 00:46:16 +00:00
azw
70f0469b30 1 2023-09-29 00:39:02 +00:00
azw
cf9a023a31 1 2023-09-06 00:31:57 +00:00
azw
438247f086 1 2023-09-05 13:27:55 +00:00
azw
676965d292 1 2023-09-04 02:31:21 +00:00
48 changed files with 743 additions and 621 deletions

View File

@ -1,11 +0,0 @@
path_arr=$(echo $PWD|tr '/' '\n')
path_arr=(${path_arr})
GAME_ID=${path_arr[-5]}
if echo $GAME_ID | grep -q '[^0-9]'
then
echo 'game_id参数必须为数字'
exit 1
fi
python ../../third_party/tools/scripts/server/monitor.py wsproxy${GAME_ID} '-n1 -i1'

View File

@ -0,0 +1,14 @@
{
"open": 0,
"sndwnd": 128,
"rcvwnd": 128,
"nodelay": 2,
"interval": 10,
"resend": 2,
"nc": 1,
"rx_minrto": 10,
"fastresend": 1
}

View File

@ -0,0 +1,7 @@
[
{
"instance_id": 1,
"ip": "127.0.0.1",
"port": 7621
}
]

View File

@ -0,0 +1,16 @@
[
{
"instance_id" : 1,
"listen_ip": "127.0.0.1",
"listen_port": 7601,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17601
},
{
"instance_id" : 2,
"listen_ip": "127.0.0.1",
"listen_port": 7602,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17602
}
]

View File

@ -0,0 +1,14 @@
{
"open": 0,
"sndwnd": 128,
"rcvwnd": 128,
"nodelay": 2,
"interval": 10,
"resend": 2,
"nc": 1,
"rx_minrto": 10,
"fastresend": 1
}

View File

@ -0,0 +1,7 @@
[
{
"instance_id": 1,
"ip": "127.0.0.1",
"port": 7621
}
]

View File

@ -0,0 +1,16 @@
[
{
"instance_id" : 1,
"listen_ip": "127.0.0.1",
"listen_port": 7601,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17601
},
{
"instance_id" : 2,
"listen_ip": "127.0.0.1",
"listen_port": 7602,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17602
}
]

View File

@ -0,0 +1,14 @@
{
"open": 0,
"sndwnd": 128,
"rcvwnd": 128,
"nodelay": 2,
"interval": 10,
"resend": 2,
"nc": 1,
"rx_minrto": 10,
"fastresend": 1
}

View File

@ -0,0 +1,7 @@
[
{
"instance_id": 1,
"ip": "127.0.0.1",
"port": 7627
}
]

View File

@ -0,0 +1,9 @@
[
{
"instance_id" : 1,
"listen_ip": "127.0.0.1",
"listen_port": 7607,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17607
}
]

View File

@ -0,0 +1,14 @@
{
"open": 0,
"sndwnd": 128,
"rcvwnd": 128,
"nodelay": 2,
"interval": 10,
"resend": 2,
"nc": 1,
"rx_minrto": 10,
"fastresend": 1
}

View File

@ -0,0 +1,7 @@
[
{
"instance_id": 1,
"ip": "127.0.0.1",
"port": 7628
}
]

View File

@ -0,0 +1,9 @@
[
{
"instance_id" : 1,
"listen_ip": "127.0.0.1",
"listen_port": 7608,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17608
}
]

View File

@ -0,0 +1,14 @@
{
"open": 0,
"sndwnd": 128,
"rcvwnd": 128,
"nodelay": 2,
"interval": 10,
"resend": 2,
"nc": 1,
"rx_minrto": 10,
"fastresend": 1
}

View File

@ -0,0 +1,7 @@
[
{
"instance_id": 1,
"ip": "127.0.0.1",
"port": 7629
}
]

View File

@ -0,0 +1,9 @@
[
{
"instance_id" : 1,
"listen_ip": "127.0.0.1",
"listen_port": 7609,
"listen_udp_host": "192.144.200.110",
"listen_udp_port": 17609
}
]

View File

@ -0,0 +1 @@
wsproxy

View File

@ -0,0 +1 @@
wsproxy

View File

@ -0,0 +1 @@
wsproxy

View File

@ -0,0 +1 @@
wsproxy

View File

@ -9,6 +9,11 @@ enum SSMessageId_e
_SS_WSP_RequestTargetServer = 11; _SS_WSP_RequestTargetServer = 11;
_SS_MS_ResponseTargetServer = 12; _SS_MS_ResponseTargetServer = 12;
_SS_ForceCloseSocket = 13; _SS_ForceCloseSocket = 13;
_SS_WSP_HttpTunnelRequest = 14;
_SS_MS_HttpTunnelResponse = 15;
_SS_HttpTunnelRequest = 16;
_SS_HttpTunnelResponse = 17;
_SS_BindUpStreamSocket = 20;
_SS_CMKcpHandshake = 99; _SS_CMKcpHandshake = 99;
_SS_CMPing = 101; _SS_CMPing = 101;

View File

@ -78,6 +78,39 @@ message SS_MS_ResponseTargetServer
optional int32 port = 5; optional int32 port = 5;
} }
message SS_WSP_HttpTunnelRequest
{
optional int64 context_id = 1;
optional string url = 7;
optional string query_str = 8;
}
message SS_MS_HttpTunnelResponse
{
optional int32 error_code = 1;
optional string error_msg = 2;
optional int64 context_id = 3;
optional string host = 4;
optional int32 port = 5;
}
message SS_HttpTunnelRequest
{
optional int64 context_id = 1;
optional int32 socket_handle = 2;
optional string url = 3;
optional string query_str = 4;
}
message SS_HttpTunnelResponse
{
optional int32 error_code = 1;
optional string error_msg = 2;
optional int64 context_id = 3;
optional int32 socket_handle = 4;
optional string response = 5;
}
message SS_SMRpcError message SS_SMRpcError
{ {
optional int32 error_code = 1; optional int32 error_code = 1;
@ -99,3 +132,7 @@ message SS_Pong
message SS_ForceCloseSocket message SS_ForceCloseSocket
{ {
} }
message SS_BindUpStreamSocket
{
}

View File

@ -18,11 +18,12 @@ else()
message("debug mode") message("debug mode")
endif() endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DMMCHK=1 -DNDEBUG")
if (${ASAN}) if (${ASAN})
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DDEBUG -fsanitize=address -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DMMCHK=1 -DDEBUG -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address")
message("asan mode")
else() else()
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++1z -DGAME_ID=${GAME_ID} -DMMCHK=1 -DDEBUG -fsanitize-recover=address")
endif() endif()
include_directories( include_directories(
@ -74,11 +75,11 @@ aux_source_directory(.
) )
set(EXECUTABLE_OUTPUT_PATH set(EXECUTABLE_OUTPUT_PATH
${PROJECT_BINARY_DIR}/../bin ${PROJECT_BINARY_DIR}/../bin/wsproxy/bin
) )
add_executable( add_executable(
wsproxy${GAME_ID} ${SRC_LIST} wsproxy ${SRC_LIST}
) )
add_custom_target(script_pb_protocol ALL) add_custom_target(script_pb_protocol ALL)
@ -86,10 +87,10 @@ add_custom_command(TARGET script_pb_protocol
PRE_BUILD PRE_BUILD
COMMAND python ../tools/scripts/construct/build_pb.py COMMAND python ../tools/scripts/construct/build_pb.py
) )
add_dependencies(wsproxy${GAME_ID} script_pb_protocol) add_dependencies(wsproxy script_pb_protocol)
target_link_libraries( target_link_libraries(
wsproxy${GAME_ID} wsproxy
pthread pthread
mysqlclient mysqlclient
protobuf protobuf
@ -106,12 +107,12 @@ target_link_libraries(
if (CMAKE_BUILD_TYPE STREQUAL "Debug") if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_libraries( target_link_libraries(
wsproxy${GAME_ID} wsproxy
behaviac_gcc_debug behaviac_gcc_debug
) )
else() else()
target_link_libraries( target_link_libraries(
wsproxy${GAME_ID} wsproxy
tcmalloc tcmalloc
behaviac_gcc_release behaviac_gcc_release
) )

View File

@ -22,6 +22,9 @@ public:
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override
{ {
#if 1
is_activite = true;
#endif
//packagelen + msgid + magiccode + msgbody //packagelen + msgid + magiccode + msgbody
//2 + 2 + 4+ xx + \0 + xx //2 + 2 + 4+ xx + \0 + xx
bool warning = false; bool warning = false;
@ -31,14 +34,15 @@ public:
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) { if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
break; break;
} }
App::Instance()->AddSocketMsg(SF_Client, f8::App::Instance()->AddSocketMsg
socket_handle, (SF_Client,
saddr, socket_handle,
p->msgid, saddr,
p->seqid, p->msgid,
&buf[offset + sizeof(f8::PackHead)], p->seqid,
p->packlen, &buf[offset + sizeof(f8::PackHead)],
ST_Tcp); p->packlen,
ST_Tcp);
offset += sizeof(f8::PackHead) + p->packlen; offset += sizeof(f8::PackHead) + p->packlen;
} else { } else {
warning = true; warning = true;
@ -107,11 +111,6 @@ public:
}; };
static void CreateGameClientSocket(a8::TcpSession **p)
{
*p = new GCClientSession();
}
static void GSListeneron_error(a8::TcpListener*, int type, int errorid) static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
{ {
f8::UdpLog::Instance()->Debug("GCListeneron_error %d %d", {type, errorid}); f8::UdpLog::Instance()->Debug("GCListeneron_error %d %d", {type, errorid});
@ -119,13 +118,14 @@ static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
void GCListener::Init() void GCListener::Init()
{ {
tcp_listener_ = new a8::TcpListener(); tcp_listener_ = std::make_shared<a8::TcpListener>();
tcp_listener_->on_create_client_socket = CreateGameClientSocket; tcp_listener_->RegisterSessionClass<GCClientSession>(1024 * 64 * 2);
tcp_listener_->on_error = GSListeneron_error; tcp_listener_->on_error = GSListeneron_error;
tcp_listener_->bind_address = "0.0.0.0"; tcp_listener_->bind_address = "0.0.0.0";
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue(); tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue();
tcp_listener_->Open(); tcp_listener_->Open();
a8::XPrintf("listener_port:%d\n", {tcp_listener_->bind_port});
f8::MsgQueue::Instance()->RegisterCallBack f8::MsgQueue::Instance()->RegisterCallBack
( (
IM_HandleRedirect, IM_HandleRedirect,
@ -148,7 +148,6 @@ void GCListener::Init()
void GCListener::UnInit() void GCListener::UnInit()
{ {
delete tcp_listener_;
tcp_listener_ = nullptr; tcp_listener_ = nullptr;
} }

View File

@ -29,7 +29,7 @@ class GCListener : public a8::Singleton<GCListener>
template <typename T> template <typename T>
void SendMsgEx(unsigned short socket_handle, int msgid, T& msg) void SendMsgEx(unsigned short socket_handle, int msgid, T& msg)
{ {
f8::Net_SendMsg(tcp_listener_, socket_handle, 0, msgid, msg); f8::Net_SendMsg(tcp_listener_.get(), socket_handle, 0, msgid, msg);
} }
void SendBuf(unsigned short sockhandle, char* buf, int buflen); void SendBuf(unsigned short sockhandle, char* buf, int buflen);
@ -43,6 +43,6 @@ class GCListener : public a8::Singleton<GCListener>
int GetSocketCount(); int GetSocketCount();
private: private:
a8::TcpListener *tcp_listener_ = nullptr; std::shared_ptr<a8::TcpListener> tcp_listener_;
std::map<int, std::tuple<std::string, std::string>> websocket_url_hash_; std::map<int, std::tuple<std::string, std::string>> websocket_url_hash_;
}; };

View File

@ -1,10 +1,6 @@
#include "precompile.h" #include "precompile.h"
#include <signal.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <mutex>
#include <condition_variable>
#include <a8/xtimer.h> #include <a8/xtimer.h>
#include <a8/uuid.h> #include <a8/uuid.h>
@ -12,6 +8,7 @@
#include <f8/netmsghandler.h> #include <f8/netmsghandler.h>
#include <f8/udplog.h> #include <f8/udplog.h>
#include <f8/app.h>
#include <f8/msgqueue.h> #include <f8/msgqueue.h>
#include "app.h" #include "app.h"
@ -31,49 +28,34 @@
#include "ss_msgid.pb.h" #include "ss_msgid.pb.h"
#include "ss_proto.pb.h" #include "ss_proto.pb.h"
struct MsgNode
{
SocketFrom_e sockfrom;
int sockhandle;
unsigned short msgid;
unsigned int seqid;
long ip_saddr;
char* buf;
int buflen;
int tag;
MsgNode* next;
};
struct UdpMsgNode struct UdpMsgNode
{ {
a8::UdpPacket* pkt; a8::UdpPacket* pkt;
UdpMsgNode* next; UdpMsgNode* next;
}; };
const char* const PROJ_LOG_ROOT_FMT = "/data/logs/%s/logs";
const char* const PROJ_LOG_FILENAME_FMT = "log_$pid_%Y%m%d.log";
static void SavePerfLog() static void SavePerfLog()
{ {
f8::UdpLog::Instance()->Info("max_run_delay_time:%d max_timer_idle:%d " f8::UdpLog::Instance()->Info
"in_data_size:%d out_data_size:%d msgnode_size:%d udp_msgnode_size:%d " ("max_run_delay_time:%d max_timer_idle:%d "
"read_count:%d max_login_time:%d " "in_data_size:%d out_data_size:%d msgnode_size:%d udp_msgnode_size:%d "
"max_join_time:%d tcp_count:%d udp_count:%d down_stream_count:%d", "read_count:%d max_login_time:%d "
{ "max_join_time:%d tcp_count:%d udp_count:%d down_stream_count:%d",
App::Instance()->GetPerf().max_run_delay_time, {
App::Instance()->GetPerf().max_timer_idle, App::Instance()->GetPerf().max_run_delay_time,
App::Instance()->GetPerf().in_data_size, App::Instance()->GetPerf().max_timer_idle,
App::Instance()->GetPerf().out_data_size, App::Instance()->GetPerf().in_data_size,
App::Instance()->GetMsgNodeSize(), App::Instance()->GetPerf().out_data_size,
App::Instance()->GetUdpMsgNodeSize(), f8::App::Instance()->GetMsgNodeSize(),
App::Instance()->GetPerf().read_count, App::Instance()->GetUdpMsgNodeSize(),
App::Instance()->GetPerf().max_login_time, App::Instance()->GetPerf().read_count,
App::Instance()->GetPerf().max_join_time, App::Instance()->GetPerf().max_login_time,
GCListener::Instance()->GetSocketCount(), App::Instance()->GetPerf().max_join_time,
LongSessionMgr::Instance()->GetLongSessionCount(), GCListener::Instance()->GetSocketCount(),
DownStreamMgr::Instance()->GetDownStreamCount() LongSessionMgr::Instance()->GetLongSessionCount(),
}); DownStreamMgr::Instance()->GetDownStreamCount()
if (App::Instance()->HasFlag(2)) { });
if (f8::App::Instance()->HasFlag(2)) {
a8::XPrintf("mainloop_time:%d netmsg_time:%d send_node_num:%d sent_bytes_num:%d\n", a8::XPrintf("mainloop_time:%d netmsg_time:%d send_node_num:%d sent_bytes_num:%d\n",
{ {
App::Instance()->GetPerf().max_run_delay_time, App::Instance()->GetPerf().max_run_delay_time,
@ -88,45 +70,17 @@ static void SavePerfLog()
App::Instance()->GetPerf().max_join_time = 0; App::Instance()->GetPerf().max_join_time = 0;
} }
bool App::Init(int argc, char* argv[]) const std::string App::GetPkgName()
{ {
signal(SIGPIPE, SIG_IGN); return a8::Format("game%d_wsproxy", {App::Instance()->GetGameId()});
this->argc_ = argc; }
this->argv_ = argv;
if (!ParseOpt()) { void App::Init()
terminated_ = true; {
if (node_id_ <= 0) { udp_msg_mutex_ = std::make_shared<std::mutex>();
a8::XPrintf("gameserver启动失败,缺少-n参数\n", {});
} else if (node_id_ > MAX_NODE_ID) {
a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
} else if (instance_id_ <= 0) {
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
} else if (instance_id_ > MAX_INSTANCE_ID) {
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
}
return false;
}
a8::XPrintf("wsproxy starting node_id:%d instance_id:%d pid:%d\n",
{
node_id_,
instance_id_,
getpid()
});
uuid_ = std::make_shared<a8::uuid::SnowFlake>();
loop_mutex_ = new std::mutex();
loop_cond_ = new std::condition_variable();
msg_mutex_ = new std::mutex();
udp_msg_mutex_ = new std::mutex();
srand(time(nullptr));
InitLog();
f8::MsgQueue::Instance()->Init();
HandlerMgr::Instance()->Init(); HandlerMgr::Instance()->Init();
f8::Timer::Instance()->Init();
JsonDataMgr::Instance()->Init(); JsonDataMgr::Instance()->Init();
uuid_->SetMachineId((node_id_ - 1) * MAX_NODE_ID + instance_id_);
DownStreamMgr::Instance()->Init(); DownStreamMgr::Instance()->Init();
MasterMgr::Instance()->Init(); MasterMgr::Instance()->Init();
UpStreamMgr::Instance()->Init(); UpStreamMgr::Instance()->Init();
@ -135,8 +89,8 @@ bool App::Init(int argc, char* argv[])
f8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d", f8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d",
{ {
instance_id_, f8::App::Instance()->GetInstanceId(),
getpid(), f8::App::Instance()->GetPid(),
}); });
{ {
int perf_log_time = 1000 * 60 * 5; int perf_log_time = 1000 * 60 * 5;
@ -152,120 +106,49 @@ bool App::Init(int argc, char* argv[])
} }
}); });
} }
if (HasFlag(1)) { if (f8::App::Instance()->HasFlag(1)) {
f8::Timer::Instance()->SetTimeout f8::Timer::Instance()->SetTimeout
( (
1000 * 60, 1000 * 60,
[] (int event, const a8::Args* args) [] (int event, const a8::Args* args)
{ {
if (a8::TIMER_EXEC_EVENT == event) { if (a8::TIMER_EXEC_EVENT == event) {
App::Instance()->terminated_ = true; f8::App::Instance()->Terminated();
App::Instance()->NotifyLoopCond(); f8::App::Instance()->NotifyLoopCond();
} }
} }
); );
} }
if (HasFlag(4)) {
f8::Timer::Instance()->SetTimeout
(
1000 * 30,
[] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
App::Instance()->shutdowned_ = true;
a8::XPrintf("shutdowned\n", {});
}
}
);
}
return true;
} }
void App::UnInit() void App::UnInit()
{ {
a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id_, getpid()}); a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n",
{f8::App::Instance()->GetInstanceId(),
f8::App::Instance()->GetPid()});
GCListener::Instance()->UnInit(); GCListener::Instance()->UnInit();
LongSessionMgr::Instance()->UnInit(); LongSessionMgr::Instance()->UnInit();
MasterMgr::Instance()->UnInit(); MasterMgr::Instance()->UnInit();
UpStreamMgr::Instance()->UnInit(); UpStreamMgr::Instance()->UnInit();
DownStreamMgr::Instance()->UnInit(); DownStreamMgr::Instance()->UnInit();
JsonDataMgr::Instance()->UnInit(); JsonDataMgr::Instance()->UnInit();
f8::Timer::Instance()->UnInit();
f8::MsgQueue::Instance()->UnInit();
HandlerMgr::Instance()->UnInit(); HandlerMgr::Instance()->UnInit();
UnInitLog();
FreeSocketMsgQueue();
FreeUdpMsgQueue(); FreeUdpMsgQueue();
delete msg_mutex_;
msg_mutex_ = nullptr;
delete udp_msg_mutex_;
udp_msg_mutex_ = nullptr; udp_msg_mutex_ = nullptr;
delete loop_cond_; a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n",
loop_cond_ = nullptr; {f8::App::Instance()->GetInstanceId(),
delete loop_mutex_; f8::App::Instance()->GetPid()});
loop_mutex_ = nullptr;
a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id_, getpid()});
} }
int App::Run() void App::Update(int delta_time)
{ {
int ret = 0; QuickExecute();
f8::UdpLog::Instance()->Info("wsproxy running", {}); SlowerExecute();
while (!terminated_) {
a8::tick_t begin_tick = a8::XGetTickCount();
QuickExecute();
SlowerExecute();
a8::tick_t end_tick = a8::XGetTickCount();
if (end_tick - begin_tick > GetPerf().max_run_delay_time) {
GetPerf().max_run_delay_time = end_tick - begin_tick;
}
Schedule();
}
return ret;
}
void App::AddSocketMsg(SocketFrom_e sockfrom,
int sockhandle,
long ip_saddr,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen,
int tag)
{
MsgNode *p = (MsgNode*)malloc(sizeof(MsgNode));
memset(p, 0, sizeof(MsgNode));
p->sockfrom = sockfrom;
p->ip_saddr = ip_saddr;
p->sockhandle = sockhandle;
p->msgid = msgid;
p->seqid = seqid;
p->buf = nullptr;
p->buflen = bodylen;
p->tag = tag;
if (bodylen > 0) {
p->buf = (char*)malloc(bodylen);
memmove(p->buf, msgbody, bodylen);
}
msg_mutex_->lock();
if (bot_node_) {
bot_node_->next = p;
bot_node_ = p;
} else {
top_node_ = p;
bot_node_ = p;
}
++msgnode_size_;
msg_mutex_->unlock();
NotifyLoopCond();
} }
void App::QuickExecute() void App::QuickExecute()
{ {
f8::Timer::Instance()->Update();
f8::MsgQueue::Instance()->Update();
DispatchMsg();
DispatchUdpMsg(); DispatchUdpMsg();
LongSessionMgr::Instance()->Update(); LongSessionMgr::Instance()->Update();
} }
@ -274,45 +157,8 @@ void App::SlowerExecute()
{ {
} }
void App::NotifyLoopCond()
{
std::unique_lock<std::mutex> lk(*loop_mutex_);
loop_cond_->notify_all();
}
void App::Schedule()
{
std::unique_lock<std::mutex> lk(*loop_mutex_);
if (!HasTask()) {
#if 1
int sleep_time = 1;
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
#else
int sleep_time = f8::Timer::Instance()->GetIdleableMillSeconds();
loop_cond_->wait_for(lk, std::chrono::milliseconds(sleep_time));
if (sleep_time > perf.max_timer_idle) {
perf.max_timer_idle = sleep_time;
}
#endif
}
}
bool App::HasTask() bool App::HasTask()
{ {
{
if (!work_node_) {
msg_mutex_->lock();
if (!work_node_ && top_node_) {
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
}
msg_mutex_->unlock();
}
if (work_node_) {
return true;
}
}
{ {
if (!udp_work_node_) { if (!udp_work_node_) {
udp_msg_mutex_->lock(); udp_msg_mutex_->lock();
@ -330,73 +176,18 @@ bool App::HasTask()
return false; return false;
} }
void App::DispatchMsg() void App::ProcessClientMsg(f8::MsgHdr* hdr)
{ {
long long starttick = a8::XGetTickCount(); if (hdr->msgid == ss::_SS_CMLogin ||
if (!work_node_ && top_node_) { hdr->msgid == ss::_SS_CMReconnect ||
msg_mutex_->lock(); hdr->msgid == ss::_SS_CMKcpHandshake) {
work_node_ = top_node_; auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr->socket_handle);
top_node_ = nullptr;
bot_node_ = nullptr;
working_msgnode_size_ = msgnode_size_;
msg_mutex_->unlock();
}
f8::MsgHdr hdr;
while (work_node_) {
MsgNode *pdelnode = work_node_;
work_node_ = pdelnode->next;
hdr.msgid = pdelnode->msgid;
hdr.seqid = pdelnode->seqid;
hdr.socket_handle = pdelnode->sockhandle;
hdr.buf = pdelnode->buf;
hdr.buflen = pdelnode->buflen;
hdr.offset = 0;
hdr.ip_saddr = pdelnode->ip_saddr;
switch (pdelnode->sockfrom) {
case SF_Client:
{
ProcessClientMsg(hdr, pdelnode->tag);
}
break;
case SF_TargetServer:
{
ProcessTargetServerMsg(hdr, pdelnode->tag);
}
break;
case SF_MasterServer:
{
ProcessMasterServerMsg(hdr, pdelnode->tag);
}
break;
}
if (pdelnode->buf) {
free(pdelnode->buf);
}
free(pdelnode);
working_msgnode_size_--;
if (a8::XGetTickCount() - starttick > 200) {
break;
}
}//end while
if (!work_node_) {
working_msgnode_size_ = 0;
}
}
void App::ProcessClientMsg(f8::MsgHdr& hdr, int tag)
{
if (hdr.msgid == ss::_SS_CMLogin ||
hdr.msgid == ss::_SS_CMReconnect ||
hdr.msgid == ss::_SS_CMKcpHandshake) {
auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr.socket_handle);
if (down_wp.expired()) { if (down_wp.expired()) {
switch (hdr.msgid) { switch (hdr->msgid) {
case ss::_SS_CMLogin: case ss::_SS_CMLogin:
{ {
ss::SS_CMLogin msg; ss::SS_CMLogin msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset); bool ok = msg.ParseFromArray(hdr->buf + hdr->offset, hdr->buflen - hdr->offset);
if (ok) { if (ok) {
MasterMgr::Instance()->RequestTargetServer MasterMgr::Instance()->RequestTargetServer
(hdr, (hdr,
@ -412,7 +203,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr, int tag)
case ss::_SS_CMReconnect: case ss::_SS_CMReconnect:
{ {
ss::SS_CMReconnect msg; ss::SS_CMReconnect msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset); bool ok = msg.ParseFromArray(hdr->buf + hdr->offset, hdr->buflen - hdr->offset);
if (ok) { if (ok) {
MasterMgr::Instance()->RequestTargetServer MasterMgr::Instance()->RequestTargetServer
(hdr, (hdr,
@ -428,7 +219,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr, int tag)
case ss::_SS_CMKcpHandshake: case ss::_SS_CMKcpHandshake:
{ {
ss::SS_CMKcpHandshake msg; ss::SS_CMKcpHandshake msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset); bool ok = msg.ParseFromArray(hdr->buf + hdr->offset, hdr->buflen - hdr->offset);
if (ok) { if (ok) {
LongSessionMgr::Instance()->_SS_CMKcpHandshake(hdr, msg); LongSessionMgr::Instance()->_SS_CMKcpHandshake(hdr, msg);
} }
@ -442,17 +233,17 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr, int tag)
} }
} }
} else { } else {
auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr.socket_handle); auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr->socket_handle);
if (auto down = down_wp.lock(); !down_wp.expired()) { if (auto down = down_wp.lock(); !down_wp.expired()) {
down->ProcCMMsg(hdr, tag); down->ProcCMMsg(hdr);
} }
} }
} }
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag) void App::ProcessMasterServerMsg(f8::MsgHdr* hdr)
{ {
f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->msmsghandler, f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->msmsghandler,
hdr.msgid); hdr->msgid);
if (handler) { if (handler) {
switch (handler->handlerid) { switch (handler->handlerid) {
case HID_MasterMgr: case HID_MasterMgr:
@ -462,104 +253,32 @@ void App::ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag)
} }
} }
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr, int tag) void App::ProcessTargetServerMsg(f8::MsgHdr* hdr)
{ {
if (hdr.msgid == ss::_SS_ForceCloseSocket) { if (hdr->msgid == ss::_SS_ForceCloseSocket) {
GCListener::Instance()->ForceCloseClient(hdr.socket_handle); GCListener::Instance()->ForceCloseClient(hdr->socket_handle);
return; return;
} }
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReconnect) { if (hdr->msgid == ss::_SS_CMLogin ||
DownStreamMgr::Instance()->BindUpStream(hdr.socket_handle, hdr.ip_saddr); hdr->msgid == ss::_SS_CMReconnect ||
GCListener::Instance()->MarkClient(hdr.socket_handle, true); hdr->msgid == ss::_SS_BindUpStreamSocket) {
DownStreamMgr::Instance()->BindUpStream(hdr->socket_handle, hdr->ip_saddr);
GCListener::Instance()->MarkClient(hdr->socket_handle, true);
} }
auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr.socket_handle); if (hdr->msgid == ss::_SS_HttpTunnelResponse) {
ss::SS_HttpTunnelResponse msg;
bool ok = msg.ParseFromArray(hdr->buf + hdr->offset, hdr->buflen - hdr->offset);
if (ok) {
MasterMgr::Instance()->_SS_HttpTunnelResponse(hdr, msg);
}
return;
}
auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr->socket_handle);
if (!down_wp.expired()) { if (!down_wp.expired()) {
down_wp.lock()->ForwardUpStreamMsg(hdr); down_wp.lock()->ForwardUpStreamMsg(hdr);
} }
} }
void App::InitLog()
{
std::string filename_fmt = PROJ_LOG_FILENAME_FMT;
a8::ReplaceString(filename_fmt, "$pid", a8::XValue(getpid()));
std::string proj_root_dir = a8::Format(PROJ_ROOT_FMT, {a8::Format(PROJ_NAME_FMT,{GAME_ID})});
std::string proj_log_root_dir = a8::Format(PROJ_LOG_ROOT_FMT, {a8::Format(PROJ_NAME_FMT, {GAME_ID})});
std::string log_file_name = a8::Format(PROJ_LOG_ROOT_FMT,
{a8::Format(PROJ_NAME_FMT, {GAME_ID})}) + "/" + filename_fmt;
a8::MkDir(proj_root_dir);
a8::MkDir(proj_log_root_dir);
f8::UdpLog::Instance()->SetLogFileName(log_file_name);
f8::UdpLog::Instance()->Init();
f8::UdpLog::Instance()->Info("proj_root_dir:%s", {proj_root_dir});
f8::UdpLog::Instance()->Info("proj_log_root_dir:%s", {proj_log_root_dir});
f8::UdpLog::Instance()->Info("log_file_name:%s", {log_file_name});
}
void App::UnInitLog()
{
f8::UdpLog::Instance()->UnInit();
}
bool App::ParseOpt()
{
int ch = 0;
while ((ch = getopt(argc_, argv_, "n:i:f:")) != -1) {
switch (ch) {
case 'n':
{
node_id_ = a8::XValue(optarg);
}
break;
case 'i':
{
instance_id_ = a8::XValue(optarg);
}
break;
case 'f':
{
std::vector<std::string> strings;
a8::Split(optarg, strings, ',');
for (auto& str : strings) {
flags_.insert(a8::XValue(str).GetInt());
}
}
break;
}
}
return instance_id_ > 0 && node_id_ > 0;
}
bool App::HasFlag(int flag)
{
return flags_.find(flag) != flags_.end();
}
void App::FreeSocketMsgQueue()
{
msg_mutex_->lock();
if (!work_node_) {
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
}
while (work_node_) {
MsgNode* pdelnode = work_node_;
work_node_ = work_node_->next;
if (pdelnode->buf) {
free(pdelnode->buf);
}
free(pdelnode);
if (!work_node_) {
work_node_ = top_node_;
top_node_ = nullptr;
bot_node_ = nullptr;
}
}
msg_mutex_->unlock();
}
void App::FreeUdpMsgQueue() void App::FreeUdpMsgQueue()
{ {
udp_msg_mutex_->lock(); udp_msg_mutex_->lock();
@ -602,7 +321,7 @@ void App::AddUdpMsg(a8::UdpPacket* pkt)
} }
++udp_msgnode_size_; ++udp_msgnode_size_;
udp_msg_mutex_->unlock(); udp_msg_mutex_->unlock();
NotifyLoopCond(); f8::App::Instance()->NotifyLoopCond();
} }
void App::DispatchUdpMsg() void App::DispatchUdpMsg()
@ -639,7 +358,42 @@ void App::DispatchUdpMsg()
} }
} }
long long App::NewUuid() int App::GetGameId() const
{ {
return uuid_->Generate(); #ifdef DEBUG
std::string game_id = a8::XValue((f8::App::Instance()->GetArgv())[0]).GetString();
std::vector<std::string> strings;
a8::Split(game_id, strings, '/');
game_id = strings.at(strings.size() - 1);
a8::ReplaceString(game_id, "wsproxy", "");
return a8::XValue(game_id);
#else
return GAME_ID;
#endif
}
void App::DispatchSocketMsg(f8::MsgHdr* hdr)
{
switch (hdr->sockfrom) {
case SF_Client:
{
ProcessClientMsg(hdr);
}
break;
case SF_TargetServer:
{
ProcessTargetServerMsg(hdr);
}
break;
case SF_MasterServer:
{
ProcessMasterServerMsg(hdr);
}
break;
default:
{
A8_ABORT();
}
break;
}
} }

View File

@ -2,18 +2,16 @@
#include <a8/singleton.h> #include <a8/singleton.h>
#include <f8/app.h>
namespace a8 namespace a8
{ {
struct UdpPacket; struct UdpPacket;
namespace uuid
{
class SnowFlake;
}
} }
struct MsgNode; struct MsgNode;
struct UdpMsgNode; struct UdpMsgNode;
class App : public a8::Singleton<App> class App : public a8::Singleton<App>, public f8::UserApp
{ {
private: private:
App() {}; App() {};
@ -21,79 +19,41 @@ private:
public: public:
bool Init(int argc, char* argv[]); virtual const std::string GetPkgName() override;
void UnInit(); virtual void Init() override;
virtual void UnInit() override;
int Run(); virtual void Update(int delta_time) override;
virtual bool HasTask() override;
void AddSocketMsg(SocketFrom_e sockfrom, virtual void DispatchSocketMsg(f8::MsgHdr* hdr) override;
int sockhandle,
long ip_saddr,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen,
int tag = ST_Tcp);
void AddUdpMsg(a8::UdpPacket* pkt); void AddUdpMsg(a8::UdpPacket* pkt);
void NotifyLoopCond();
bool HasFlag(int flag);
long long NewUuid();
int GetNodeId() { return node_id_; }
int GetInstanceId() { return instance_id_; }
PerfMonitor& GetPerf() { return perf_; } PerfMonitor& GetPerf() { return perf_; }
int GetMsgNodeSize() { return msgnode_size_;}
int GetUdpMsgNodeSize() { return udp_msgnode_size_;} int GetUdpMsgNodeSize() { return udp_msgnode_size_;}
int GetGameId() const;
private: private:
void QuickExecute(); void QuickExecute();
void SlowerExecute(); void SlowerExecute();
void Schedule();
bool HasTask();
void DispatchMsg();
void DispatchUdpMsg(); void DispatchUdpMsg();
void ProcessClientMsg(f8::MsgHdr& hdr, int tag); void ProcessClientMsg(f8::MsgHdr* hdr);
void ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag); void ProcessMasterServerMsg(f8::MsgHdr* hdr);
void ProcessTargetServerMsg(f8::MsgHdr& hdr, int tag); void ProcessTargetServerMsg(f8::MsgHdr* hdr);
void InitLog();
void UnInitLog();
bool ParseOpt();
void FreeSocketMsgQueue();
void FreeUdpMsgQueue(); void FreeUdpMsgQueue();
private: private:
int argc_ = 0;
char** argv_ = nullptr;
PerfMonitor perf_; PerfMonitor perf_;
volatile bool terminated_ = false;
volatile bool shutdowned_ = false;
int node_id_ = 0; std::shared_ptr<std::mutex> udp_msg_mutex_;
int instance_id_ = 0;
std::set<int> flags_;
std::shared_ptr<a8::uuid::SnowFlake> uuid_;
std::mutex *loop_mutex_ = nullptr;
std::condition_variable *loop_cond_ = nullptr;
std::mutex* msg_mutex_ = nullptr;
MsgNode* top_node_ = nullptr;
MsgNode* bot_node_ = nullptr;
MsgNode* work_node_ = nullptr;
std::mutex* udp_msg_mutex_ = nullptr;
UdpMsgNode* udp_top_node_ = nullptr; UdpMsgNode* udp_top_node_ = nullptr;
UdpMsgNode* udp_bot_node_ = nullptr; UdpMsgNode* udp_bot_node_ = nullptr;
UdpMsgNode* udp_work_node_ = nullptr; UdpMsgNode* udp_work_node_ = nullptr;
int msgnode_size_ = 0 ;
int udp_msgnode_size_ = 0 ; int udp_msgnode_size_ = 0 ;
int working_msgnode_size_ = 0;
int udp_working_msgnode_size_ = 0; int udp_working_msgnode_size_ = 0;
}; };

View File

@ -20,7 +20,7 @@ enum InnerMesssage_e
IM_ExecGM, IM_ExecGM,
IM_UpStreamDisconnect, IM_UpStreamDisconnect,
IM_UpStreamConnect, IM_UpStreamConnect,
IM_HandleRedirect IM_HandleRedirect,
}; };
//网络处理对象 //网络处理对象

View File

@ -23,21 +23,21 @@ void DownStream::ReBindUpStream(std::weak_ptr<UpStream> up)
up_ = up; up_ = up;
} }
void DownStream::ForwardUpStreamMsg(f8::MsgHdr& hdr) void DownStream::ForwardUpStreamMsg(f8::MsgHdr* hdr)
{ {
char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen); char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr->buflen);
f8::PackHead* head = (f8::PackHead*)buff; f8::PackHead* head = (f8::PackHead*)buff;
head->packlen = hdr.buflen; head->packlen = hdr->buflen;
head->msgid = hdr.msgid; head->msgid = hdr->msgid;
head->seqid = hdr.seqid; head->seqid = hdr->seqid;
head->magic_code = f8::MAGIC_CODE; head->magic_code = f8::MAGIC_CODE;
head->ext_len = hdr.buflen >> 16; head->ext_len = hdr->buflen >> 16;
if (hdr.buflen > 0) { if (hdr->buflen > 0) {
memmove(buff + sizeof(f8::PackHead), hdr.buf, hdr.buflen); memmove(buff + sizeof(f8::PackHead), hdr->buf, hdr->buflen);
} }
if (auto long_session = long_session_wp_.lock(); !long_session_wp_.expired()) { if (auto long_session = long_session_wp_.lock(); !long_session_wp_.expired()) {
if (hdr.msgid == ss::_SS_CMPing) { if (hdr->msgid == ss::_SS_CMPing) {
ss::SS_SMPing msg; ss::SS_SMPing msg;
msg.set_source(1); msg.set_source(1);
{ {
@ -46,10 +46,10 @@ void DownStream::ForwardUpStreamMsg(f8::MsgHdr& hdr)
buff = (char*)malloc(sizeof(f8::PackHead) + msg.ByteSize()); buff = (char*)malloc(sizeof(f8::PackHead) + msg.ByteSize());
f8::PackHead* head = (f8::PackHead*)buff; f8::PackHead* head = (f8::PackHead*)buff;
head->packlen = msg.ByteSize(); head->packlen = msg.ByteSize();
head->msgid = hdr.msgid; head->msgid = hdr->msgid;
head->seqid = hdr.seqid; head->seqid = hdr->seqid;
head->magic_code = f8::MAGIC_CODE; head->magic_code = f8::MAGIC_CODE;
head->ext_len = hdr.buflen >> 16; head->ext_len = hdr->buflen >> 16;
msg.SerializeToArray(buff + sizeof(f8::PackHead), head->packlen); msg.SerializeToArray(buff + sizeof(f8::PackHead), head->packlen);
long_session->GetKcpSession()->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen); long_session->GetKcpSession()->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen);
} }
@ -57,7 +57,7 @@ void DownStream::ForwardUpStreamMsg(f8::MsgHdr& hdr)
long_session->GetKcpSession()->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen); long_session->GetKcpSession()->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen);
} }
} else { } else {
GCListener::Instance()->SendBuf(hdr.socket_handle, buff, sizeof(f8::PackHead) + head->packlen); GCListener::Instance()->SendBuf(hdr->socket_handle, buff, sizeof(f8::PackHead) + head->packlen);
} }
free(buff); free(buff);
} }
@ -73,9 +73,9 @@ void DownStream::OnClose()
} }
} }
void DownStream::ProcCMMsg(f8::MsgHdr& hdr, int tag) void DownStream::ProcCMMsg(f8::MsgHdr* hdr)
{ {
if (hdr.msgid == ss::_SS_CMPing && IsLongSession() && tag == ST_Tcp) { if (hdr->msgid == ss::_SS_CMPing && IsLongSession() && hdr->tag == ST_Tcp) {
ss::SS_SMPing msg; ss::SS_SMPing msg;
GCListener::Instance()->SendMsgEx(socket_handle_, ss::_SS_CMPing, msg); GCListener::Instance()->SendMsgEx(socket_handle_, ss::_SS_CMPing, msg);
if (!long_session_wp_.expired()) { if (!long_session_wp_.expired()) {

View File

@ -12,9 +12,9 @@ class DownStream
std::weak_ptr<UpStream> GetUpStream() const { return up_; } std::weak_ptr<UpStream> GetUpStream() const { return up_; }
void ReBindUpStream(std::weak_ptr<UpStream> up); void ReBindUpStream(std::weak_ptr<UpStream> up);
bool IsLongSession() { return is_long_session_; } bool IsLongSession() { return is_long_session_; }
void ProcCMMsg(f8::MsgHdr& hdr, int tag); void ProcCMMsg(f8::MsgHdr* hdr);
void ForwardUpStreamMsg(f8::MsgHdr& hdr); void ForwardUpStreamMsg(f8::MsgHdr* hdr);
void OnClose(); void OnClose();
private: private:

View File

@ -47,7 +47,7 @@ void DownStreamMgr::OnClientDisconnect(int socket_handle)
socket_hash_.erase(socket_handle); socket_hash_.erase(socket_handle);
} }
RemovePendingAccount(socket_handle); RemovePendingAccount(socket_handle);
MasterMgr::Instance()->RemoveRequest(socket_handle); MasterMgr::Instance()->OnDownStreamDisconnect(socket_handle);
} }
void DownStreamMgr::OnUpStreamDisconnect(int instance_id) void DownStreamMgr::OnUpStreamDisconnect(int instance_id)

View File

@ -3,6 +3,7 @@
#include <a8/mutable_xobject.h> #include <a8/mutable_xobject.h>
#include <f8/msgqueue.h> #include <f8/msgqueue.h>
#include <f8/jsonhttprequest.h> #include <f8/jsonhttprequest.h>
#include <f8/app.h>
#include "handlermgr.h" #include "handlermgr.h"
@ -13,36 +14,53 @@
#include "ss_proto.pb.h" #include "ss_proto.pb.h"
static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsSelfChecking(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
request->resp_xobj->SetVal("healthy", 1); request->GetResp()->SetVal("healthy", 1);
request->resp_xobj->SetVal("max_rundelay", 10); request->GetResp()->SetVal("max_rundelay", 10);
} }
static void _GMOpsGetNodeId(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsGetNodeId(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
request->resp_xobj->SetVal("node_id", App::Instance()->GetNodeId()); request->GetResp()->SetVal("node_id", f8::App::Instance()->GetNodeId());
} }
static void _GMOpsSetKcpSwitch(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsSetKcpSwitch(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
if (request->params->HasKey("open")) { if (request->GetParams()->HasKey("open")) {
JsonDataMgr::Instance()->SetKcpSwitch(request->params->At("open")->AsXValue().GetInt()); JsonDataMgr::Instance()->SetKcpSwitch(request->GetParams()->At("open")->AsXValue().GetInt());
} }
request->resp_xobj->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open); request->GetResp()->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open);
} }
static void _GMOpsGetKcpSwitch(std::shared_ptr<f8::JsonHttpRequest> request) static void _GMOpsGetKcpSwitch(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{ {
request->resp_xobj->SetVal("errcode", 0); request->GetResp()->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", ""); request->GetResp()->SetVal("errmsg", "");
request->resp_xobj->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open); request->GetResp()->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open);
}
static void _GMOpsTerminate(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{
request->GetResp()->SetVal("errcode", 0);
request->GetResp()->SetVal("errmsg", "");
f8::App::Instance()->Terminate();
}
static void _GMHttpTunnelTeamRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{
MasterMgr::Instance()->AddHttpTunnelRequest(socket_handle, request);
}
static void _GMHttpTunnelOnlineTeamRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{
MasterMgr::Instance()->AddHttpTunnelRequest(socket_handle, request);
} }
void HandlerMgr::Init() void HandlerMgr::Init()
@ -52,6 +70,9 @@ void HandlerMgr::Init()
RegisterGMMsgHandler("Ops$getNodeId", _GMOpsGetNodeId); RegisterGMMsgHandler("Ops$getNodeId", _GMOpsGetNodeId);
RegisterGMMsgHandler("Ops$setKcpSwitch", _GMOpsSetKcpSwitch); RegisterGMMsgHandler("Ops$setKcpSwitch", _GMOpsSetKcpSwitch);
RegisterGMMsgHandler("Ops$getKcpSwitch", _GMOpsGetKcpSwitch); RegisterGMMsgHandler("Ops$getKcpSwitch", _GMOpsGetKcpSwitch);
RegisterGMMsgHandler("Ops$terminate", _GMOpsTerminate);
RegisterGMMsgHandler("HttpTunnel$teamRequest", _GMHttpTunnelTeamRequest);
RegisterGMMsgHandler("HttpTunnel$onlineTeamRequest", _GMHttpTunnelOnlineTeamRequest);
f8::MsgQueue::Instance()->RegisterCallBack f8::MsgQueue::Instance()->RegisterCallBack
( (
IM_ExecGM, IM_ExecGM,
@ -72,6 +93,7 @@ void HandlerMgr::UnInit()
void HandlerMgr::RegisterNetMsgHandlers() void HandlerMgr::RegisterNetMsgHandlers()
{ {
RegisterNetMsgHandler(&msmsghandler, &MasterMgr::_SS_MS_ResponseTargetServer); RegisterNetMsgHandler(&msmsghandler, &MasterMgr::_SS_MS_ResponseTargetServer);
RegisterNetMsgHandler(&msmsghandler, &MasterMgr::_SS_MS_HttpTunnelResponse);
} }
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle, void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
@ -88,25 +110,24 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
std::string msgname = a8::Get(request, "c").GetString() + "$" + a8::Get(request, "a").GetString(); std::string msgname = a8::Get(request, "c").GetString() + "$" + a8::Get(request, "a").GetString();
auto itr = gmhandlers_.find(msgname); auto itr = gmhandlers_.find(msgname);
if (itr != gmhandlers_.end()) { if (itr != gmhandlers_.end()) {
auto request = std::make_shared<f8::JsonHttpRequest>(); auto request = std::make_shared<f8::JsonHttpRequest>
request->saddr = saddr; (
request->socket_handle = sockhandle; saddr,
request->query_str = querystr; url,
request->params->ReadFromUrlQueryString(querystr); querystr,
itr->second(request); [sockhandle] (const a8::Args& args)
{
if (!request->pending){ std::string data = args.Get<std::string>(0);
std::string response; GCListener::Instance()->SendText(sockhandle, data);
request->resp_xobj->ToJsonStr(response); });
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse(response)); itr->second(sockhandle, request);
}
} else { } else {
GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}")); GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
} }
} }
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname, void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
void (*handler)(std::shared_ptr<f8::JsonHttpRequest>)) void (*handler)(int, std::shared_ptr<f8::JsonHttpRequest>))
{ {
gmhandlers_[msgname] = handler; gmhandlers_[msgname] = handler;
} }

View File

@ -30,7 +30,7 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
private: private:
void RegisterNetMsgHandlers(); void RegisterNetMsgHandlers();
void RegisterGMMsgHandler(const std::string& msgname, void RegisterGMMsgHandler(const std::string& msgname,
void (*)(std::shared_ptr<f8::JsonHttpRequest>)); void (*)(int, std::shared_ptr<f8::JsonHttpRequest>));
std::map<std::string, void (*)(std::shared_ptr<f8::JsonHttpRequest>)> gmhandlers_; std::map<std::string, void (*)(int, std::shared_ptr<f8::JsonHttpRequest>)> gmhandlers_;
}; };

View File

@ -11,35 +11,36 @@
void JsonDataMgr::Init() void JsonDataMgr::Init()
{ {
if (!f8::IsOnlineEnv()) { if (!f8::IsOnlineEnv()) {
work_path_ = a8::Format if (f8::IsTestEnv()) {
("../../../conf_test/game%d/%s", work_path_ = a8::Format("../%d_test_config", {App::Instance()->GetGameId()});
{ } else {
GAME_ID, work_path_ = a8::Format("../%d_dev_config", {App::Instance()->GetGameId()});
f8::IsTestEnv() ? "wsproxy.test" : "wsproxy.dev" }
});
} }
std::string wsproxy_cluster_json_file; std::string wsproxy_cluster_json_file;
std::string master_cluster_json_file; std::string master_cluster_json_file;
std::string kcp_conf_json_file; std::string kcp_conf_json_file;
wsproxy_cluster_json_file = a8::Format wsproxy_cluster_json_file = a8::Format
("%s/node%d/game%d.wsproxy.cluster.json", ("%s/zone%d/node%d/wsproxy.cluster.json",
{ {
work_path_, work_path_,
App::Instance()->GetNodeId(), f8::App::Instance()->GetZoneId(),
GAME_ID f8::App::Instance()->GetNodeId()
}); });
master_cluster_json_file = a8::Format master_cluster_json_file = a8::Format
("%s/node%d/game%d.masterserver.cluster.json", ("%s/zone%d/node%d/masterserver.cluster.json",
{ {
work_path_, work_path_,
App::Instance()->GetNodeId(), f8::App::Instance()->GetZoneId(),
GAME_ID f8::App::Instance()->GetNodeId(),
}); });
kcp_conf_json_file = a8::Format kcp_conf_json_file = a8::Format
("%s/kcp_conf.json", ("%s/zone%d/node%d/kcp_conf.json",
{ {
work_path_, work_path_,
f8::App::Instance()->GetZoneId(),
f8::App::Instance()->GetNodeId(),
}); });
wsproxy_cluster_json_.ReadFromFile(wsproxy_cluster_json_file); wsproxy_cluster_json_.ReadFromFile(wsproxy_cluster_json_file);
@ -91,7 +92,7 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
{ {
for (int i = 0; i < wsproxy_cluster_json_.Size(); ++i) { for (int i = 0; i < wsproxy_cluster_json_.Size(); ++i) {
std::shared_ptr<a8::XObject> conf = wsproxy_cluster_json_.At(i); std::shared_ptr<a8::XObject> conf = wsproxy_cluster_json_.At(i);
if (conf->At("instance_id")->AsXValue().GetInt() == App::Instance()->GetInstanceId()) { if (conf->At("instance_id")->AsXValue().GetInt() == f8::App::Instance()->GetInstanceId()) {
return conf; return conf;
} }
} }

View File

@ -37,7 +37,7 @@ KcpSession::~KcpSession()
void KcpSession::Init(int socket_handle, int secret_key_place) void KcpSession::Init(int socket_handle, int secret_key_place)
{ {
socket_handle_ = socket_handle; socket_handle_ = socket_handle;
secret_key_ = App::Instance()->NewUuid(); secret_key_ = f8::App::Instance()->NewNodeUuid();
kcp_ = ikcp_create(socket_handle_, (void*)this); kcp_ = ikcp_create(socket_handle_, (void*)this);
const KcpConf& kcp_conf = JsonDataMgr::Instance()->GetKcpConf(); const KcpConf& kcp_conf = JsonDataMgr::Instance()->GetKcpConf();
ikcp_wndsize(kcp_, kcp_conf.sndwnd, kcp_conf.rcvwnd); ikcp_wndsize(kcp_, kcp_conf.sndwnd, kcp_conf.rcvwnd);
@ -131,15 +131,16 @@ void KcpSession::DecodeUserPacketOld(char* buf, int& offset, unsigned int buflen
if (buflen - offset < sizeof(f8::PackHead) + p->packlen + GetSecretKeyLen()) { if (buflen - offset < sizeof(f8::PackHead) + p->packlen + GetSecretKeyLen()) {
break; break;
} }
App::Instance()->AddSocketMsg(SF_Client, f8::App::Instance()->AddSocketMsg
socket_handle_, (SF_Client,
0, socket_handle_,
//saddr, 0,
p->msgid, //saddr,
p->seqid, p->msgid,
&buf[offset + sizeof(f8::PackHead) + GetSecretKeyLen()], p->seqid,
p->packlen, &buf[offset + sizeof(f8::PackHead) + GetSecretKeyLen()],
ST_Udp); p->packlen,
ST_Udp);
offset += sizeof(f8::PackHead) + p->packlen + GetSecretKeyLen(); offset += sizeof(f8::PackHead) + p->packlen + GetSecretKeyLen();
} else { } else {
warning = true; warning = true;
@ -162,15 +163,16 @@ void KcpSession::DecodeUserPacketNew(char* buf, int& offset, unsigned int buflen
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) { if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
break; break;
} }
App::Instance()->AddSocketMsg(SF_Client, f8::App::Instance()->AddSocketMsg
socket_handle_, (SF_Client,
0, socket_handle_,
//saddr, 0,
p->msgid, //saddr,
p->seqid, p->msgid,
&buf[offset + sizeof(f8::PackHead)], p->seqid,
p->packlen, &buf[offset + sizeof(f8::PackHead)],
ST_Udp); p->packlen,
ST_Udp);
offset += sizeof(f8::PackHead) + p->packlen; offset += sizeof(f8::PackHead) + p->packlen;
} else { } else {
warning = true; warning = true;

View File

@ -8,10 +8,10 @@
#include "ss_msgid.pb.h" #include "ss_msgid.pb.h"
#include "ss_proto.pb.h" #include "ss_proto.pb.h"
void LongSession::Init(f8::MsgHdr& hdr, const ss::SS_CMKcpHandshake& msg) void LongSession::Init(f8::MsgHdr* hdr, const ss::SS_CMKcpHandshake& msg)
{ {
kcp_session_ = std::make_shared<KcpSession>(); kcp_session_ = std::make_shared<KcpSession>();
kcp_session_->Init(hdr.socket_handle, msg.secret_key_place()); kcp_session_->Init(hdr->socket_handle, msg.secret_key_place());
} }
void LongSession::UnInit() void LongSession::UnInit()

View File

@ -11,7 +11,7 @@ class LongSession
public: public:
void Init(f8::MsgHdr& hdr, const ss::SS_CMKcpHandshake& msg); void Init(f8::MsgHdr* hdr, const ss::SS_CMKcpHandshake& msg);
void UnInit(); void UnInit();
void Update(long long tick); void Update(long long tick);

View File

@ -53,17 +53,17 @@ void LongSessionMgr::Update()
} }
} }
void LongSessionMgr::_SS_CMKcpHandshake(f8::MsgHdr& hdr, const ss::SS_CMKcpHandshake& msg) void LongSessionMgr::_SS_CMKcpHandshake(f8::MsgHdr* hdr, const ss::SS_CMKcpHandshake& msg)
{ {
ss::SS_SMKcpHandshake respmsg; ss::SS_SMKcpHandshake respmsg;
respmsg.set_errcode(0); respmsg.set_errcode(0);
if (!JsonDataMgr::Instance()->GetKcpConf().open) { if (!JsonDataMgr::Instance()->GetKcpConf().open) {
respmsg.set_errcode(1); respmsg.set_errcode(1);
respmsg.set_errmsg("not support kcp"); respmsg.set_errmsg("not support kcp");
GCListener::Instance()->SendMsgEx(hdr.socket_handle, ss::_SS_CMKcpHandshake, respmsg); GCListener::Instance()->SendMsgEx(hdr->socket_handle, ss::_SS_CMKcpHandshake, respmsg);
return; return;
} }
if (GetSession(hdr.socket_handle)) { if (GetSession(hdr->socket_handle)) {
#ifdef DEBUG #ifdef DEBUG
abort(); abort();
#endif #endif
@ -77,9 +77,9 @@ void LongSessionMgr::_SS_CMKcpHandshake(f8::MsgHdr& hdr, const ss::SS_CMKcpHands
respmsg.set_secret_key(session->GetKcpSession()->GetSecretKeyDataPtr(), KcpSession::GetSecretKeyLen()); respmsg.set_secret_key(session->GetKcpSession()->GetSecretKeyDataPtr(), KcpSession::GetSecretKeyLen());
respmsg.set_remote_host(JsonDataMgr::Instance()->GetUdpHost()); respmsg.set_remote_host(JsonDataMgr::Instance()->GetUdpHost());
respmsg.set_remote_port(JsonDataMgr::Instance()->GetUdpPort()); respmsg.set_remote_port(JsonDataMgr::Instance()->GetUdpPort());
GCListener::Instance()->SendMsgEx(hdr.socket_handle, ss::_SS_CMKcpHandshake, respmsg); GCListener::Instance()->SendMsgEx(hdr->socket_handle, ss::_SS_CMKcpHandshake, respmsg);
{ {
int socket_handle = hdr.socket_handle; int socket_handle = hdr->socket_handle;
f8::Timer::Instance()->SetTimeout f8::Timer::Instance()->SetTimeout
( (
1000 * 30, 1000 * 30,

View File

@ -26,7 +26,7 @@ class LongSessionMgr : public a8::Singleton<LongSessionMgr>
void UnInit(); void UnInit();
void Update(); void Update();
void _SS_CMKcpHandshake(f8::MsgHdr& hdr, const ss::SS_CMKcpHandshake& msg); void _SS_CMKcpHandshake(f8::MsgHdr* hdr, const ss::SS_CMKcpHandshake& msg);
void ProcUdpPacket(a8::UdpPacket* pkt); void ProcUdpPacket(a8::UdpPacket* pkt);
std::shared_ptr<LongSession> GetSession(int socket_handle); std::shared_ptr<LongSession> GetSession(int socket_handle);
std::shared_ptr<a8::UdpListener> GetUdpListener() { return udp_listener_; } std::shared_ptr<a8::UdpListener> GetUdpListener() { return udp_listener_; }

View File

@ -1,12 +1,10 @@
#include "precompile.h" #include "precompile.h"
#include <f8/app.h>
#include "app.h" #include "app.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
int exitcode = 0; return f8::App::Instance()->Run(argc, argv, App::Instance());
if (App::Instance()->Init(argc, argv)) {
exitcode = App::Instance()->Run();
App::Instance()->UnInit();
}
return exitcode;
} }

View File

@ -24,9 +24,7 @@ void Master::Init(int instance_id, const std::string& remote_ip, int remote_port
recv_bufflen_ = 0; recv_bufflen_ = 0;
last_pong_tick = a8::XGetTickCount(); last_pong_tick = a8::XGetTickCount();
recv_buff_ = (char*) malloc(PACK_MAX * 2); recv_buff_ = (char*) malloc(PACK_MAX * 2);
tcp_client_ = std::make_shared<a8::TcpClient>(); tcp_client_ = std::make_shared<a8::TcpClient>(remote_ip, remote_port);
tcp_client_->remote_address = remote_ip;
tcp_client_->remote_port = remote_port;
tcp_client_->on_error = std::bind(&Master::on_error, this, std::placeholders::_1, std::placeholders::_2); tcp_client_->on_error = std::bind(&Master::on_error, this, std::placeholders::_1, std::placeholders::_2);
tcp_client_->on_connect = std::bind(&Master::on_connect, this, std::placeholders::_1); tcp_client_->on_connect = std::bind(&Master::on_connect, this, std::placeholders::_1);
tcp_client_->on_disconnect = std::bind(&Master::on_disconnect, this, std::placeholders::_1); tcp_client_->on_disconnect = std::bind(&Master::on_disconnect, this, std::placeholders::_1);
@ -77,8 +75,8 @@ void Master::on_error(a8::TcpClient* sender, int errorId)
f8::UdpLog::Instance()->Error("Master errorid=%d remote_ip:%s remote_port:%d", f8::UdpLog::Instance()->Error("Master errorid=%d remote_ip:%s remote_port:%d",
{ {
errorId, errorId,
sender->remote_address, sender->GetRemoteAddress(),
sender->remote_port sender->GetRemotePort()
}); });
} }
@ -116,13 +114,15 @@ void Master::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
if (recv_bufflen_ - offset < sizeof(f8::PackHead) + p->packlen) { if (recv_bufflen_ - offset < sizeof(f8::PackHead) + p->packlen) {
break; break;
} }
App::Instance()->AddSocketMsg(SF_MasterServer, f8::App::Instance()->AddSocketMsg
0, (SF_MasterServer,
instance_id, 0,
p->msgid, instance_id,
p->seqid, p->msgid,
&recv_buff_[offset + sizeof(f8::PackHead)], p->seqid,
p->packlen); &recv_buff_[offset + sizeof(f8::PackHead)],
p->packlen,
0);
offset += sizeof(f8::PackHead) + p->packlen; offset += sizeof(f8::PackHead) + p->packlen;
} else { } else {
warning = true; warning = true;

View File

@ -3,10 +3,13 @@
#include <unistd.h> #include <unistd.h>
#include <a8/openssl.h> #include <a8/openssl.h>
#include <a8/mutable_xobject.h>
#include <f8/timer.h> #include <f8/timer.h>
#include <f8/netmsghandler.h> #include <f8/netmsghandler.h>
#include <f8/protoutils.h> #include <f8/protoutils.h>
#include <f8/jsonhttprequest.h>
#include <f8/utils.h>
#include "mastermgr.h" #include "mastermgr.h"
#include "master.h" #include "master.h"
@ -18,6 +21,14 @@
#include "downstreammgr.h" #include "downstreammgr.h"
#include "GCListener.h" #include "GCListener.h"
struct HttpTunnelRequest
{
int socket_handle = 0;
long long context_id = 0;
f8::TimerWp timer_wp;
std::shared_ptr<f8::JsonHttpRequest> request;
};
class RequestTarget class RequestTarget
{ {
public: public:
@ -54,10 +65,19 @@ void MasterMgr::UnInit()
mastersvr_hash_.clear(); mastersvr_hash_.clear();
} }
void MasterMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_ResponseTargetServer& msg) void MasterMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr* hdr, const ss::SS_MS_ResponseTargetServer& msg)
{ {
auto req = GetRequestByContextId(msg.context_id()); auto req = GetRequestByContextId(msg.context_id());
if (req) { if (req) {
#ifdef DEBUG
a8::XPrintf("error_code:%d error_msg:%s host:%s port:%d\n",
{
msg.error_code(),
msg.error_msg(),
msg.host(),
msg.port()
});
#endif
if (msg.error_code() == 0) { if (msg.error_code() == 0) {
std::weak_ptr<UpStream> conn = UpStreamMgr::Instance()->RecreateUpStream std::weak_ptr<UpStream> conn = UpStreamMgr::Instance()->RecreateUpStream
( (
@ -66,6 +86,7 @@ void MasterMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_Res
); );
if (!conn.expired()) { if (!conn.expired()) {
conn.lock()->ForwardClientMsgEx(req->hdr_copy); conn.lock()->ForwardClientMsgEx(req->hdr_copy);
f8::MsgHdr::Destroy(req->hdr_copy);
req->conn = conn; req->conn = conn;
req->hdr_copy = nullptr; req->hdr_copy = nullptr;
if (!req->timer_wp.expired()) { if (!req->timer_wp.expired()) {
@ -85,13 +106,70 @@ void MasterMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_Res
} }
} }
void MasterMgr::_SS_MS_HttpTunnelResponse(f8::MsgHdr* hdr, const ss::SS_MS_HttpTunnelResponse& msg)
{
#ifdef DEBUG
a8::XPrintf("SS_MS_HttpTunnelResponse %s\n" , {f8::PbToJson(&msg)});
#endif
auto req = GetHttpTunnelRequestByContextId(msg.context_id());
if (req) {
if (msg.error_code() == 0) {
std::weak_ptr<UpStream> conn = UpStreamMgr::Instance()->RecreateUpStream
(
msg.host(),
msg.port()
);
if (!conn.expired()) {
ss::SS_HttpTunnelRequest upmsg;
upmsg.set_context_id(msg.context_id());
upmsg.set_socket_handle(req->socket_handle);
upmsg.set_url(req->request->GetUrl());
std::string query_str;
req->request->GetParams()->ToUrlEncodeStr(query_str);
upmsg.set_query_str(query_str);
conn.lock()->SendMsg(req->socket_handle, upmsg);
return;
} else {
abort();
}
} else {
req->request->GetResp()->SetVal("errcode", 500);
req->request->GetResp()->SetVal("errmsg", "server internal error");
req->request->Response();
if (!req->timer_wp.expired()) {
f8::Timer::Instance()->Delete(req->timer_wp);
}
RemoveHttpTunnelRequest(req->socket_handle);
}
}
}
void MasterMgr::_SS_HttpTunnelResponse(f8::MsgHdr* hdr, const ss::SS_HttpTunnelResponse& msg)
{
#ifdef DEBUG
a8::XPrintf("SS_HttpTunnelResponse %s\n" , {f8::PbToJson(&msg)});
#endif
auto req = GetHttpTunnelRequestByContextId(msg.context_id());
if (req) {
#ifdef DEBUG
a8::XPrintf("SS_HttpTunnelResponse2 %s\n" , {f8::PbToJson(&msg)});
#endif
req->request->GetResp()->ReadFromJsonString(msg.response());
req->request->Response();
if (!req->timer_wp.expired()) {
f8::Timer::Instance()->Delete(req->timer_wp);
}
RemoveHttpTunnelRequest(req->socket_handle);
}
}
std::shared_ptr<Master> MasterMgr::GetConnById(int instance_id) std::shared_ptr<Master> MasterMgr::GetConnById(int instance_id)
{ {
auto itr = mastersvr_hash_.find(instance_id); auto itr = mastersvr_hash_.find(instance_id);
return itr != mastersvr_hash_.end() ? itr->second : nullptr; return itr != mastersvr_hash_.end() ? itr->second : nullptr;
} }
void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, void MasterMgr::RequestTargetServer(f8::MsgHdr* hdr,
const std::string& team_id, const std::string& team_id,
const std::string& account_id, const std::string& account_id,
const std::string& session_id, const std::string& session_id,
@ -99,7 +177,16 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
int is_reconnect, int is_reconnect,
int proto_version) int proto_version)
{ {
if (GetRequestBySocket(hdr.socket_handle)) { #ifdef DEBUG
a8::XPrintf("RequestTargetServer team_id:%s account_id:%s server_info:%s is_reconnect:%d\n",
{
team_id,
account_id,
server_info,
is_reconnect
});
#endif
if (GetRequestBySocket(hdr->socket_handle)) {
return; return;
} }
unsigned int code = 0; unsigned int code = 0;
@ -110,7 +197,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
std::string data = a8::Format("!%s_%s_%d_%d", std::string data = a8::Format("!%s_%s_%d_%d",
{ {
account_id, account_id,
App::Instance()->NewUuid(), f8::App::Instance()->NewNodeUuid(),
getpid(), getpid(),
rand() rand()
}); });
@ -122,10 +209,10 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
++curr_context_id_; ++curr_context_id_;
auto req = std::make_shared<RequestTarget>(); auto req = std::make_shared<RequestTarget>();
req->context_id = curr_context_id_; req->context_id = curr_context_id_;
req->socket_handle = hdr.socket_handle; req->socket_handle = hdr->socket_handle;
req->account_id = account_id; req->account_id = account_id;
req->req_tick = a8::XGetTickCount(); req->req_tick = a8::XGetTickCount();
req->hdr_copy = hdr.Clone(); req->hdr_copy = hdr->Clone();
ss::SS_WSP_RequestTargetServer msg; ss::SS_WSP_RequestTargetServer msg;
msg.set_context_id(curr_context_id_); msg.set_context_id(curr_context_id_);
@ -139,14 +226,14 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
std::string url; std::string url;
std::string query_str; std::string query_str;
{ {
GCListener::Instance()->GetWebSocketUrl(hdr.socket_handle, url, query_str); GCListener::Instance()->GetWebSocketUrl(hdr->socket_handle, url, query_str);
} }
msg.set_url(url); msg.set_url(url);
msg.set_query_str(query_str); msg.set_query_str(query_str);
#endif #endif
svr->SendMsg(msg); svr->SendMsg(msg);
pending_socket_hash_[hdr.socket_handle] = req; pending_socket_hash_[hdr->socket_handle] = req;
assert(pending_context_hash_.find(curr_context_id_) == pending_context_hash_.end()); assert(pending_context_hash_.find(curr_context_id_) == pending_context_hash_.end());
pending_context_hash_[curr_context_id_] = req; pending_context_hash_[curr_context_id_] = req;
req->timer_wp = f8::Timer::Instance()->SetTimeoutWp req->timer_wp = f8::Timer::Instance()->SetTimeoutWp
@ -154,37 +241,58 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
[req] (int event, const a8::Args* args) [req] (int event, const a8::Args* args)
{ {
if (a8::TIMER_EXEC_EVENT == event) { if (a8::TIMER_EXEC_EVENT == event) {
MasterMgr::Instance()->RemoveRequest MasterMgr::Instance()->RemoveRequest(req->socket_handle);
(
req->socket_handle
);
long long req_handle_time = a8::XGetTickCount() - req->req_tick; long long req_handle_time = a8::XGetTickCount() - req->req_tick;
if (req_handle_time > App::Instance()->GetPerf().max_login_time) { if (req_handle_time > App::Instance()->GetPerf().max_login_time) {
App::Instance()->GetPerf().max_login_time = req_handle_time; App::Instance()->GetPerf().max_login_time = req_handle_time;
} }
DownStreamMgr::Instance()->AddPendingAccount(req->account_id, req->socket_handle, req->req_tick); DownStreamMgr::Instance()->AddPendingAccount
(req->account_id,
req->socket_handle,
req->req_tick);
} else if (ALLOC_TARGET_SERVER_SUCCESS_TIMER_EVENT == event) { } else if (ALLOC_TARGET_SERVER_SUCCESS_TIMER_EVENT == event) {
long long req_handle_time = a8::XGetTickCount() - req->req_tick; long long req_handle_time = a8::XGetTickCount() - req->req_tick;
if (req_handle_time > App::Instance()->GetPerf().max_login_time) { if (req_handle_time > App::Instance()->GetPerf().max_login_time) {
App::Instance()->GetPerf().max_login_time = req_handle_time; App::Instance()->GetPerf().max_login_time = req_handle_time;
} }
DownStreamMgr::Instance()->AddPendingAccount(req->account_id, req->socket_handle, req->req_tick); DownStreamMgr::Instance()->AddPendingAccount
(req->account_id,
req->socket_handle,
req->req_tick);
} }
} }
); );
} }
} }
void MasterMgr::OnDownStreamDisconnect(int socket_handle)
{
{
auto req = GetHttpTunnelRequestBySocket(socket_handle);
if (req) {
if (!req->timer_wp.expired()) {
f8::Timer::Instance()->Delete(req->timer_wp);
}
}
}
RemoveRequest(socket_handle);
}
void MasterMgr::RemoveRequest(int socket_handle) void MasterMgr::RemoveRequest(int socket_handle)
{ {
auto req = GetRequestBySocket(socket_handle); {
if (req) { auto req = GetRequestBySocket(socket_handle);
if (req->hdr_copy) { if (req) {
f8::MsgHdr::Destroy(req->hdr_copy); if (req->hdr_copy) {
req->hdr_copy = nullptr; f8::MsgHdr::Destroy(req->hdr_copy);
req->hdr_copy = nullptr;
}
pending_context_hash_.erase(req->context_id);
pending_socket_hash_.erase(socket_handle);
} }
pending_context_hash_.erase(req->context_id); }
pending_socket_hash_.erase(socket_handle); {
RemoveHttpTunnelRequest(socket_handle);
} }
} }
@ -199,3 +307,66 @@ std::shared_ptr<RequestTarget> MasterMgr::GetRequestByContextId(long long contex
auto itr = pending_context_hash_.find(context_id); auto itr = pending_context_hash_.find(context_id);
return itr != pending_context_hash_.end() ? itr->second : nullptr; return itr != pending_context_hash_.end() ? itr->second : nullptr;
} }
void MasterMgr::AddHttpTunnelRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request)
{
if (!request->GetParams()->IsObject() ||
request->GetParams()->Get("team_uuid", "").GetString() == "") {
return;
}
std::string team_uuid = request->GetParams()->Get("team_uuid", "").GetString();
unsigned int code = a8::openssl::Crc32((unsigned char*)team_uuid.data(), team_uuid.size());
std::shared_ptr<Master> svr = GetConnById(code % mastersvr_hash_.size() + 1);
if (svr) {
++curr_context_id_;
ss::SS_WSP_HttpTunnelRequest msg;
msg.set_context_id(curr_context_id_);
msg.set_url(request->GetUrl());
std::string query_str;
request->GetParams()->ToUrlEncodeStr(query_str);
msg.set_query_str(query_str);
svr->SendMsg(msg);
auto req = std::make_shared<HttpTunnelRequest>();
req->socket_handle = socket_handle;
req->context_id = curr_context_id_;
req->request = request;
pending_http_tunnel_socket_hash_[socket_handle] = req;
pending_http_tunnel_context_hash_[curr_context_id_] = req;
req->timer_wp = f8::Timer::Instance()->SetTimeoutWp
(1000 * 10,
[req] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
req->request->GetResp()->SetVal("errcode", 0);
req->request->GetResp()->SetVal("errmsg", "");
req->request->Response();
MasterMgr::Instance()->RemoveHttpTunnelRequest(req->socket_handle);
}
}
);
}
}
void MasterMgr::RemoveHttpTunnelRequest(int socket_handle)
{
auto req = GetHttpTunnelRequestBySocket(socket_handle);
if (req) {
pending_http_tunnel_socket_hash_.erase(req->socket_handle);
pending_http_tunnel_context_hash_.erase(req->context_id);
}
}
std::shared_ptr<HttpTunnelRequest> MasterMgr::GetHttpTunnelRequestBySocket(int socket_handle)
{
auto itr = pending_http_tunnel_socket_hash_.find(socket_handle);
return itr != pending_http_tunnel_socket_hash_.end() ? itr->second : nullptr;
}
std::shared_ptr<HttpTunnelRequest> MasterMgr::GetHttpTunnelRequestByContextId(long long context_id)
{
auto itr = pending_http_tunnel_context_hash_.find(context_id);
return itr != pending_http_tunnel_context_hash_.end() ? itr->second : nullptr;
}

View File

@ -8,8 +8,11 @@ namespace f8
namespace ss namespace ss
{ {
class SS_MS_ResponseTargetServer; class SS_MS_ResponseTargetServer;
class SS_MS_HttpTunnelResponse;
class SS_HttpTunnelResponse;
} }
struct HttpTunnelRequest;
class RequestTarget; class RequestTarget;
class Master; class Master;
class MasterMgr : public a8::Singleton<MasterMgr> class MasterMgr : public a8::Singleton<MasterMgr>
@ -26,25 +29,35 @@ class MasterMgr : public a8::Singleton<MasterMgr>
void Init(); void Init();
void UnInit(); void UnInit();
void _SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_ResponseTargetServer& msg); void _SS_MS_ResponseTargetServer(f8::MsgHdr* hdr, const ss::SS_MS_ResponseTargetServer& msg);
void RequestTargetServer(f8::MsgHdr& hdr, void _SS_MS_HttpTunnelResponse(f8::MsgHdr* hdr, const ss::SS_MS_HttpTunnelResponse& msg);
void _SS_HttpTunnelResponse(f8::MsgHdr* hdr, const ss::SS_HttpTunnelResponse& msg);
void RequestTargetServer(f8::MsgHdr* hdr,
const std::string& team_id, const std::string& team_id,
const std::string& account_id, const std::string& account_id,
const std::string& session_id, const std::string& session_id,
const std::string& server_info, const std::string& server_info,
int is_reconnect, int is_reconnect,
int proto_version); int proto_version);
void RemoveRequest(int socket_handle); void OnDownStreamDisconnect(int socket_handle);
void AddHttpTunnelRequest(int socket_handle, std::shared_ptr<f8::JsonHttpRequest> request);
private: private:
void RemoveRequest(int socket_handle);
std::shared_ptr<HttpTunnelRequest> GetHttpTunnelRequestBySocket(int socket_handle);
std::shared_ptr<HttpTunnelRequest> GetHttpTunnelRequestByContextId(long long conext_id);
std::shared_ptr<RequestTarget> GetRequestBySocket(int socket_handle); std::shared_ptr<RequestTarget> GetRequestBySocket(int socket_handle);
std::shared_ptr<RequestTarget> GetRequestByContextId(long long context_id); std::shared_ptr<RequestTarget> GetRequestByContextId(long long context_id);
std::shared_ptr<Master> GetConnById(int instance_id); std::shared_ptr<Master> GetConnById(int instance_id);
void RemoveHttpTunnelRequest(int socket_handle);
private: private:
long long curr_context_id_ = 0; long long curr_context_id_ = 0;
std::map<int, std::shared_ptr<Master>> mastersvr_hash_; std::map<int, std::shared_ptr<Master>> mastersvr_hash_;
std::map<int, std::shared_ptr<RequestTarget>> pending_socket_hash_; std::map<int, std::shared_ptr<RequestTarget>> pending_socket_hash_;
std::map<long long, std::shared_ptr<RequestTarget>> pending_context_hash_; std::map<long long, std::shared_ptr<RequestTarget>> pending_context_hash_;
std::map<int, std::shared_ptr<HttpTunnelRequest>> pending_http_tunnel_socket_hash_;
std::map<long long, std::shared_ptr<HttpTunnelRequest>> pending_http_tunnel_context_hash_;
}; };

View File

@ -28,9 +28,7 @@ void UpStream::Init(int instance_id, const std::string& remote_ip, int remote_po
recv_bufflen_ = 0; recv_bufflen_ = 0;
last_pong_tick = a8::XGetTickCount(); last_pong_tick = a8::XGetTickCount();
recv_buff_ = (char*) malloc(PACK_MAX * 2); recv_buff_ = (char*) malloc(PACK_MAX * 2);
tcp_client_ = std::make_shared<a8::TcpClient>(); tcp_client_ = std::make_shared<a8::TcpClient>(remote_ip, remote_port);
tcp_client_->remote_address = remote_ip;
tcp_client_->remote_port = remote_port;
tcp_client_->on_error = std::bind(&UpStream::on_error, this, std::placeholders::_1, std::placeholders::_2); tcp_client_->on_error = std::bind(&UpStream::on_error, this, std::placeholders::_1, std::placeholders::_2);
tcp_client_->on_connect = std::bind(&UpStream::on_connect, this, std::placeholders::_1); tcp_client_->on_connect = std::bind(&UpStream::on_connect, this, std::placeholders::_1);
tcp_client_->on_disconnect = std::bind(&UpStream::on_disconnect, this, std::placeholders::_1); tcp_client_->on_disconnect = std::bind(&UpStream::on_disconnect, this, std::placeholders::_1);
@ -101,7 +99,7 @@ void UpStream::SendStockMsg()
delete pdelnode->msg; delete pdelnode->msg;
} }
if (pdelnode->hdr) { if (pdelnode->hdr) {
ForwardClientMsg(*pdelnode->hdr); ForwardClientMsg(pdelnode->hdr);
f8::MsgHdr::Destroy(pdelnode->hdr); f8::MsgHdr::Destroy(pdelnode->hdr);
pdelnode->hdr = nullptr; pdelnode->hdr = nullptr;
} }
@ -109,23 +107,23 @@ void UpStream::SendStockMsg()
} }
} }
void UpStream::ForwardClientMsg(f8::MsgHdr& hdr) void UpStream::ForwardClientMsg(f8::MsgHdr* hdr)
{ {
char* buff = (char*)malloc(sizeof(f8::WSProxyPackHead_C) + hdr.buflen); char* buff = (char*)malloc(sizeof(f8::WSProxyPackHead_C) + hdr->buflen);
memset(buff, 0, sizeof(f8::WSProxyPackHead_C)); memset(buff, 0, sizeof(f8::WSProxyPackHead_C));
f8::WSProxyPackHead_C* head = (f8::WSProxyPackHead_C*)buff; f8::WSProxyPackHead_C* head = (f8::WSProxyPackHead_C*)buff;
head->packlen = hdr.buflen; head->packlen = hdr->buflen;
head->msgid = hdr.msgid; head->msgid = hdr->msgid;
head->seqid = hdr.seqid; head->seqid = hdr->seqid;
head->magic_code = f8::MAGIC_CODE; head->magic_code = f8::MAGIC_CODE;
#if 0 #if 0
head->rpc_error_code = 0; head->rpc_error_code = 0;
#endif #endif
head->socket_handle = hdr.socket_handle; head->socket_handle = hdr->socket_handle;
head->ip_saddr = hdr.ip_saddr; head->ip_saddr = hdr->ip_saddr;
if (hdr.buflen > 0) { if (hdr->buflen > 0) {
memmove(buff + sizeof(f8::WSProxyPackHead_C), hdr.buf, hdr.buflen); memmove(buff + sizeof(f8::WSProxyPackHead_C), hdr->buf, hdr->buflen);
} }
tcp_client_->SendBuff(buff, sizeof(f8::WSProxyPackHead_C) + head->packlen); tcp_client_->SendBuff(buff, sizeof(f8::WSProxyPackHead_C) + head->packlen);
@ -138,11 +136,7 @@ void UpStream::ForwardClientMsgEx(f8::MsgHdr* hdr)
if (top_node_) { if (top_node_) {
SendStockMsg(); SendStockMsg();
} }
ForwardClientMsg(*hdr); ForwardClientMsg(hdr);
if (hdr->buf) {
free((char*)hdr->buf);
}
free(hdr);
} else { } else {
AddStockMsg(hdr->socket_handle, 0, nullptr, hdr); AddStockMsg(hdr->socket_handle, 0, nullptr, hdr);
} }
@ -153,8 +147,8 @@ void UpStream::on_error(a8::TcpClient* sender, int errorId)
f8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d", f8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d",
{ {
errorId, errorId,
sender->remote_address, sender->GetRemoteAddress(),
sender->remote_port sender->GetRemotePort()
}); });
} }
@ -163,8 +157,8 @@ void UpStream::on_connect(a8::TcpClient* sender)
recv_bufflen_ = 0; recv_bufflen_ = 0;
f8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d", f8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d",
{ {
sender->remote_address, sender->GetRemoteAddress(),
sender->remote_port sender->GetRemotePort()
}); });
f8::MsgQueue::Instance()->PostMsg f8::MsgQueue::Instance()->PostMsg
( (
@ -185,8 +179,8 @@ void UpStream::on_disconnect(a8::TcpClient* sender)
"remote_ip:%s remote_port:%d", "remote_ip:%s remote_port:%d",
{ {
instance_id, instance_id,
sender->remote_address, sender->GetRemoteAddress(),
sender->remote_port sender->GetRemotePort()
}); });
f8::MsgQueue::Instance()->PostMsg f8::MsgQueue::Instance()->PostMsg
( (
@ -223,13 +217,15 @@ void UpStream::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
if (recv_bufflen_ - offset < sizeof(f8::WSProxyPackHead_S) + real_len) { if (recv_bufflen_ - offset < sizeof(f8::WSProxyPackHead_S) + real_len) {
break; break;
} }
App::Instance()->AddSocketMsg(SF_TargetServer, f8::App::Instance()->AddSocketMsg
p->socket_handle, (SF_TargetServer,
instance_id, p->socket_handle,
p->msgid, instance_id,
p->seqid, p->msgid,
&recv_buff_[offset + sizeof(f8::WSProxyPackHead_S)], p->seqid,
real_len); &recv_buff_[offset + sizeof(f8::WSProxyPackHead_S)],
real_len,
0);
offset += sizeof(f8::WSProxyPackHead_S) + real_len; offset += sizeof(f8::WSProxyPackHead_S) + real_len;
} else { } else {
warning = true; warning = true;
@ -266,13 +262,17 @@ void UpStream::CheckAlive()
} }
void UpStream::AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg, void UpStream::AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg,
f8::MsgHdr* hdr) f8::MsgHdr* hdr)
{ {
UpStreamMsgNode* node = new UpStreamMsgNode(); UpStreamMsgNode* node = new UpStreamMsgNode();
node->socket_handle = socket_handle; node->socket_handle = socket_handle;
node->msgid = msgid; node->msgid = msgid;
node->msg = msg; node->msg = msg;
node->hdr = hdr; if (hdr) {
node->hdr = hdr->Clone();
} else {
node->hdr = nullptr;
}
if (bot_node_) { if (bot_node_) {
bot_node_->next_node = node; bot_node_->next_node = node;
bot_node_ = node; bot_node_ = node;

View File

@ -50,7 +50,7 @@ class UpStream
} }
void SendStockMsg(); void SendStockMsg();
void ForwardClientMsg(f8::MsgHdr& hdr); void ForwardClientMsg(f8::MsgHdr* hdr);
void ForwardClientMsgEx(f8::MsgHdr* hdr); void ForwardClientMsgEx(f8::MsgHdr* hdr);
private: private:

View File

@ -4,6 +4,7 @@
#include "upstreammgr.h" #include "upstreammgr.h"
#include "upstream.h" #include "upstream.h"
#include "downstreammgr.h"
void UpStreamMgr::Init() void UpStreamMgr::Init()
{ {
@ -23,6 +24,8 @@ void UpStreamMgr::Init()
IM_UpStreamDisconnect, IM_UpStreamDisconnect,
[this] (const a8::Args& args) [this] (const a8::Args& args)
{ {
int instance_id = args.Get<int>(0);
DownStreamMgr::Instance()->OnUpStreamDisconnect(instance_id);
}); });
} }

2
third_party/a8 vendored

@ -1 +1 @@
Subproject commit 1e577389c8a2870db9ddbf18577bfca24def049b Subproject commit c99c33e2e97058bd812dc4d9d931b94757d280bd

2
third_party/f8 vendored

@ -1 +1 @@
Subproject commit 243bbe515ef4a01089f9a6cf608c93d4097018de Subproject commit 9d627653179015b73f4f21c285b065a50e98a59e