diff --git a/server/wsproxy/jsondatamgr.cc b/server/wsproxy/jsondatamgr.cc index bab74b7..970e2b7 100644 --- a/server/wsproxy/jsondatamgr.cc +++ b/server/wsproxy/jsondatamgr.cc @@ -48,6 +48,8 @@ void JsonDataMgr::Init() udp_host_ = GetConf()->At("listen_udp_host")->AsXValue().GetString(); udp_port_ = GetConf()->At("listen_udp_port")->AsXValue(); { + kcp_conf_.open = kcp_conf_json_.At("open")->AsXValue(); + kcp_conf_.sndwnd = kcp_conf_json_.At("sndwnd")->AsXValue(); kcp_conf_.rcvwnd = kcp_conf_json_.At("rcvwnd")->AsXValue(); @@ -60,10 +62,12 @@ void JsonDataMgr::Init() kcp_conf_.fastresend = kcp_conf_json_.At("fastresend")->AsXValue(); f8::UdpLog::Instance()->Info - (" kcp_conf sndwnd:%d rcvwnd:%d " + (" kcp_conf open:%d sndwnd:%d rcvwnd:%d " "nodelay:%d interval:%d resend:%d nc:%d " "rx_minrto:%d fastresend:%d", { + kcp_conf_.open, + kcp_conf_.sndwnd, kcp_conf_.rcvwnd, diff --git a/server/wsproxy/jsondatamgr.h b/server/wsproxy/jsondatamgr.h index a71a73e..66bb92d 100644 --- a/server/wsproxy/jsondatamgr.h +++ b/server/wsproxy/jsondatamgr.h @@ -4,6 +4,8 @@ struct KcpConf { + int open = 0; + int sndwnd = 0; int rcvwnd = 0; diff --git a/server/wsproxy/longsessionmgr.cc b/server/wsproxy/longsessionmgr.cc index e26faee..3915a67 100644 --- a/server/wsproxy/longsessionmgr.cc +++ b/server/wsproxy/longsessionmgr.cc @@ -11,6 +11,7 @@ #include "longsession.h" #include "kcpsession.h" #include "GCListener.h" +#include "downstreammgr.h" #include "ss_msgid.pb.h" #include "ss_proto.pb.h" @@ -53,6 +54,12 @@ void LongSessionMgr::_SS_CMKcpHandshake(f8::MsgHdr& hdr, const ss::SS_CMKcpHands { ss::SS_SMKcpHandshake respmsg; respmsg.set_errcode(0); + if (!JsonDataMgr::Instance()->GetKcpConf().open) { + respmsg.set_errcode(1); + respmsg.set_errmsg("not support kcp"); + GCListener::Instance()->SendMsgEx(hdr.socket_handle, ss::_SS_CMKcpHandshake, respmsg); + return; + } if (GetSession(hdr.socket_handle)) { #ifdef DEBUG abort(); @@ -68,6 +75,21 @@ void LongSessionMgr::_SS_CMKcpHandshake(f8::MsgHdr& hdr, const ss::SS_CMKcpHands respmsg.set_remote_host(JsonDataMgr::Instance()->GetUdpHost()); respmsg.set_remote_port(JsonDataMgr::Instance()->GetUdpPort()); GCListener::Instance()->SendMsgEx(hdr.socket_handle, ss::_SS_CMKcpHandshake, respmsg); + { + int socket_handle = hdr.socket_handle; + f8::Timer::Instance()->SetTimeout + ( + 1000 * 30, + [this, socket_handle] (int event, const a8::Args* args) + { + if (a8::TIMER_EXEC_EVENT == event) { + if (DownStreamMgr::Instance()->GetDownStream(socket_handle).expired()) { + GCListener::Instance()->ForceCloseClient(socket_handle); + } + } + } + ); + } } std::shared_ptr LongSessionMgr::GetSession(int socket_handle)