diff --git a/server/wsproxy/handlermgr.cc b/server/wsproxy/handlermgr.cc index 80b4cda..4633e65 100644 --- a/server/wsproxy/handlermgr.cc +++ b/server/wsproxy/handlermgr.cc @@ -14,7 +14,7 @@ #include "ss_proto.pb.h" -static void _GMOpsSelfChecking(std::shared_ptr request) +static void _GMOpsSelfChecking(int socket_handle, std::shared_ptr request) { request->GetResp()->SetVal("errcode", 0); request->GetResp()->SetVal("errmsg", ""); @@ -22,14 +22,14 @@ static void _GMOpsSelfChecking(std::shared_ptr request) request->GetResp()->SetVal("max_rundelay", 10); } -static void _GMOpsGetNodeId(std::shared_ptr request) +static void _GMOpsGetNodeId(int socket_handle, std::shared_ptr request) { request->GetResp()->SetVal("errcode", 0); request->GetResp()->SetVal("errmsg", ""); request->GetResp()->SetVal("node_id", f8::App::Instance()->GetNodeId()); } -static void _GMOpsSetKcpSwitch(std::shared_ptr request) +static void _GMOpsSetKcpSwitch(int socket_handle, std::shared_ptr request) { request->GetResp()->SetVal("errcode", 0); request->GetResp()->SetVal("errmsg", ""); @@ -39,13 +39,23 @@ static void _GMOpsSetKcpSwitch(std::shared_ptr request) request->GetResp()->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open); } -static void _GMOpsGetKcpSwitch(std::shared_ptr request) +static void _GMOpsGetKcpSwitch(int socket_handle, std::shared_ptr request) { request->GetResp()->SetVal("errcode", 0); request->GetResp()->SetVal("errmsg", ""); request->GetResp()->SetVal("is_open", JsonDataMgr::Instance()->GetKcpConf().open); } +static void _GMHttpTunnelTeamRequest(int socket_handle, std::shared_ptr request) +{ + MasterMgr::Instance()->AddHttpTunnelRequest(socket_handle, request); +} + +static void _GMHttpTunnelOnlineTeamRequest(int socket_handle, std::shared_ptr request) +{ + MasterMgr::Instance()->AddHttpTunnelRequest(socket_handle, request); +} + void HandlerMgr::Init() { RegisterNetMsgHandlers(); @@ -53,6 +63,8 @@ void HandlerMgr::Init() RegisterGMMsgHandler("Ops$getNodeId", _GMOpsGetNodeId); RegisterGMMsgHandler("Ops$setKcpSwitch", _GMOpsSetKcpSwitch); RegisterGMMsgHandler("Ops$getKcpSwitch", _GMOpsGetKcpSwitch); + RegisterGMMsgHandler("HttpTunnel$teamRequest", _GMHttpTunnelTeamRequest); + RegisterGMMsgHandler("HttpTunnel$onlineTeamRequest", _GMHttpTunnelOnlineTeamRequest); f8::MsgQueue::Instance()->RegisterCallBack ( IM_ExecGM, @@ -99,14 +111,14 @@ void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle, std::string data = args.Get(0); GCListener::Instance()->SendText(sockhandle, data); }); - itr->second(request); + itr->second(sockhandle, request); } else { GCListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}")); } } void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname, - void (*handler)(std::shared_ptr)) + void (*handler)(int, std::shared_ptr)) { gmhandlers_[msgname] = handler; } diff --git a/server/wsproxy/handlermgr.h b/server/wsproxy/handlermgr.h index 3208ac4..93af588 100644 --- a/server/wsproxy/handlermgr.h +++ b/server/wsproxy/handlermgr.h @@ -30,7 +30,7 @@ class HandlerMgr : public a8::Singleton private: void RegisterNetMsgHandlers(); void RegisterGMMsgHandler(const std::string& msgname, - void (*)(std::shared_ptr)); + void (*)(int, std::shared_ptr)); - std::map)> gmhandlers_; + std::map)> gmhandlers_; }; diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index 5c4756a..fa0dfea 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -199,14 +199,19 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr* hdr, void MasterMgr::RemoveRequest(int socket_handle) { - auto req = GetRequestBySocket(socket_handle); - if (req) { - if (req->hdr_copy) { - f8::MsgHdr::Destroy(req->hdr_copy); - req->hdr_copy = nullptr; + { + auto req = GetRequestBySocket(socket_handle); + if (req) { + if (req->hdr_copy) { + 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); } } @@ -221,3 +226,22 @@ std::shared_ptr MasterMgr::GetRequestByContextId(long long contex auto itr = pending_context_hash_.find(context_id); return itr != pending_context_hash_.end() ? itr->second : nullptr; } + +void MasterMgr::AddHttpTunnelRequest(int socket_handle, std::shared_ptr request) +{ + pending_http_tunnel_hash_[socket_handle] = request; +} + +void MasterMgr::RemoveHttpTunnelRequest(int socket_handle) +{ + auto req = GetHttpTunnelRequest(socket_handle); + if (req) { + pending_http_tunnel_hash_.end(); + } +} + +std::shared_ptr MasterMgr::GetHttpTunnelRequest(int socket_handle) +{ + auto itr = pending_http_tunnel_hash_.find(socket_handle); + return itr != pending_http_tunnel_hash_.end() ? itr->second : nullptr; +} diff --git a/server/wsproxy/mastermgr.h b/server/wsproxy/mastermgr.h index 562351c..7446e3d 100644 --- a/server/wsproxy/mastermgr.h +++ b/server/wsproxy/mastermgr.h @@ -35,8 +35,11 @@ class MasterMgr : public a8::Singleton int is_reconnect, int proto_version); void RemoveRequest(int socket_handle); + void AddHttpTunnelRequest(int socket_handle, std::shared_ptr request); + void RemoveHttpTunnelRequest(int socket_handle); private: + std::shared_ptr GetHttpTunnelRequest(int socket_handle); std::shared_ptr GetRequestBySocket(int socket_handle); std::shared_ptr GetRequestByContextId(long long context_id); std::shared_ptr GetConnById(int instance_id); @@ -46,5 +49,5 @@ class MasterMgr : public a8::Singleton std::map> mastersvr_hash_; std::map> pending_socket_hash_; std::map> pending_context_hash_; - + std::map> pending_http_tunnel_hash_; };