From 1838c22cca47f1380326376affa3fa8c2c7e1fec Mon Sep 17 00:00:00 2001 From: kivenchen Date: Tue, 18 Jul 2023 18:46:25 +0800 Subject: [PATCH] update conf && doc --- conf/GatwayServer.conf | 5 +- doc/Gateway.md | 6 +- src/CMakeLists.txt | 6 +- src/Verify.h | 166 +++++++++++++++++++---------------------- 4 files changed, 88 insertions(+), 95 deletions(-) diff --git a/conf/GatwayServer.conf b/conf/GatwayServer.conf index 232de1e..7ddab2a 100755 --- a/conf/GatwayServer.conf +++ b/conf/GatwayServer.conf @@ -63,9 +63,10 @@ # 接口级别 Test3.TestServer.TestObj:func1|func2|funcn Test3.HelloServer.HelloObj:test1 - # 支持proxy中配置servant别名进行配置 + # proxy 中配置的服务servant别名 hello - + # obj 别名 + funcName + demo:callTest|getInfo # 支持服务级别、接口级别 # 服务级别 diff --git a/doc/Gateway.md b/doc/Gateway.md index 7bee090..abc617e 100644 --- a/doc/Gateway.md +++ b/doc/Gateway.md @@ -274,7 +274,7 @@ IP 黑名单和流控策略, 同时支持 TarsGateway 的三种协议,所以 auth_http_header=X-Token # 默认不鉴权,匹配上了才鉴权,在匹配上了之后,如果在exclude部分有配置,则不鉴权 - # 支持应用级别、服务级别、接口级别 + # 支持应用级别、服务级别、接口级别,其中服务可以是具体的 App.Server, 也可以是 proxy 中配置的servant别名 # 应用级别 Test1.* # 服务obj级别 @@ -283,6 +283,10 @@ IP 黑名单和流控策略, 同时支持 TarsGateway 的三种协议,所以 Test3.TestServer.TestObj:func1|func2|funcn Test3.HelloServer.HelloObj:test1 TestApp.HelloServer.HelloObj + # proxy 中配置的服务servant别名 + hello + # obj 别名 + funcName + demo:callTest|getInfo # 以下情况不需要鉴权 # 支持服务级别、接口级别 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 781fc3a..3e092f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,6 @@ gen_server("Base" "GatewayServer") target_link_libraries(GatewayServer mysqlclient dl) -if(UNIX AND NOT APPLE) - target_link_libraries(GatewayServer -static-libgcc -static-libstdc++) -endif() +# if(UNIX AND NOT APPLE) +# target_link_libraries(GatewayServer -static-libgcc -static-libstdc++) +# endif() diff --git a/src/Verify.h b/src/Verify.h index 56241e7..bf51f39 100644 --- a/src/Verify.h +++ b/src/Verify.h @@ -1,6 +1,6 @@ // ********************************************************************** // This file was generated by a TARS parser! -// TARS version 3.0.12. +// TARS version 3.0.4. // ********************************************************************** #ifndef __VERIFY_H_ @@ -301,38 +301,37 @@ namespace Base } public: - virtual int onDispatch(tars::ReqMessagePtr _msg_) + virtual int onDispatch(tars::ReqMessagePtr msg) { static ::std::string __Verify_all[]= { "verify" }; - auto it = _msg_->response->status.find("TARS_FUNC"); - pair r = equal_range(__Verify_all, __Verify_all+1, (it==_msg_->response->status.end())?_msg_->request.sFuncName:it->second); + pair r = equal_range(__Verify_all, __Verify_all+1, string(msg->request.sFuncName)); if(r.first == r.second) return tars::TARSSERVERNOFUNCERR; switch(r.first - __Verify_all) { case 0: { - if (_msg_->response->iRet != tars::TARSSERVERSUCCESS) + if (msg->response->iRet != tars::TARSSERVERSUCCESS) { - callback_verify_exception(_msg_->response->iRet); + callback_verify_exception(msg->response->iRet); - return _msg_->response->iRet; + return msg->response->iRet; } tars::TarsInputStream _is; - _is.setBuffer(_msg_->response->sBuffer); + _is.setBuffer(msg->response->sBuffer); tars::Int32 _ret; _is.read(_ret, 0, true); Base::VerifyRsp rsp; _is.read(rsp, 2, true); - ServantProxyThreadData *_pSptd_ = ServantProxyThreadData::getData(); - if (_pSptd_ && _pSptd_->_traceCall) + ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); + if (pSptd && pSptd->_traceCall) { string _trace_param_; - int _trace_param_flag_ = _pSptd_->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR, _is.size()); + int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR, _is.size()); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -344,13 +343,13 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); + TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); } CallbackThreadData * pCbtd = CallbackThreadData::getData(); assert(pCbtd != NULL); - pCbtd->setResponseContext(_msg_->response->context); + pCbtd->setResponseContext(msg->response->context); callback_verify(_ret, rsp); @@ -402,28 +401,28 @@ namespace Base tars::Promise< VerifyPrxCallbackPromise::PromiseverifyPtr > _promise_verify; public: - virtual int onDispatch(tars::ReqMessagePtr _msg_) + virtual int onDispatch(tars::ReqMessagePtr msg) { static ::std::string __Verify_all[]= { "verify" }; - pair r = equal_range(__Verify_all, __Verify_all+1, string(_msg_->request.sFuncName)); + pair r = equal_range(__Verify_all, __Verify_all+1, string(msg->request.sFuncName)); if(r.first == r.second) return tars::TARSSERVERNOFUNCERR; switch(r.first - __Verify_all) { case 0: { - if (_msg_->response->iRet != tars::TARSSERVERSUCCESS) + if (msg->response->iRet != tars::TARSSERVERSUCCESS) { - callback_verify_exception(_msg_->response->iRet); + callback_verify_exception(msg->response->iRet); - return _msg_->response->iRet; + return msg->response->iRet; } tars::TarsInputStream _is; - _is.setBuffer(_msg_->response->sBuffer); + _is.setBuffer(msg->response->sBuffer); VerifyPrxCallbackPromise::PromiseverifyPtr ptr = new VerifyPrxCallbackPromise::Promiseverify(); @@ -446,7 +445,7 @@ namespace Base return tars::TARSCLIENTDECODEERR; } - ptr->_mRspContext = _msg_->response->context; + ptr->_mRspContext = msg->response->context; callback_verify(ptr); @@ -471,28 +470,28 @@ namespace Base virtual void setResponseContext(const map &mContext) { _mRspContext = mContext; } public: - int onDispatch(tars::ReqMessagePtr _msg_) + int onDispatch(tars::ReqMessagePtr msg) { static ::std::string __Verify_all[]= { "verify" }; - pair r = equal_range(__Verify_all, __Verify_all+1, string(_msg_->request.sFuncName)); + pair r = equal_range(__Verify_all, __Verify_all+1, string(msg->request.sFuncName)); if(r.first == r.second) return tars::TARSSERVERNOFUNCERR; switch(r.first - __Verify_all) { case 0: { - if (_msg_->response->iRet != tars::TARSSERVERSUCCESS) + if (msg->response->iRet != tars::TARSSERVERSUCCESS) { - callback_verify_exception(_msg_->response->iRet); + callback_verify_exception(msg->response->iRet); - return _msg_->response->iRet; + return msg->response->iRet; } tars::TarsInputStream _is; - _is.setBuffer(_msg_->response->sBuffer); + _is.setBuffer(msg->response->sBuffer); try { tars::Int32 _ret; @@ -500,7 +499,7 @@ namespace Base Base::VerifyRsp rsp; _is.read(rsp, 2, true); - setResponseContext(_msg_->response->context); + setResponseContext(msg->response->context); callback_verify(_ret, rsp); @@ -540,12 +539,12 @@ namespace Base tars::TarsOutputStream _os; _os.write(req, 1); _os.write(rsp, 2); - ServantProxyThreadData *_pSptd_ = ServantProxyThreadData::getData(); - if (_pSptd_ && _pSptd_->_traceCall) + ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); + if (pSptd && pSptd->_traceCall) { - _pSptd_->newSpan(); + pSptd->newSpan(); string _trace_param_; - int _trace_param_flag_ = _pSptd_->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS, _os.getLength()); + int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS, _os.getLength()); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -556,7 +555,7 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "verify", 0, _trace_param_, ""); + TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "verify", 0, _trace_param_, ""); } std::map _mStatus; @@ -571,10 +570,10 @@ namespace Base tars::Int32 _ret; _is.read(_ret, 0, true); _is.read(rsp, 2, true); - if (_pSptd_ && _pSptd_->_traceCall) + if (pSptd && pSptd->_traceCall) { string _trace_param_; - int _trace_param_flag_ = _pSptd_->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR, _is.size()); + int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR, _is.size()); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -586,7 +585,7 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "verify", 0, _trace_param_, ""); + TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "verify", 0, _trace_param_, ""); } return _ret; @@ -597,12 +596,12 @@ namespace Base tars::TarsOutputStream _os; _os.write(req, 1); std::map _mStatus; - ServantProxyThreadData *_pSptd_ = ServantProxyThreadData::getData(); - if (_pSptd_ && _pSptd_->_traceCall) + ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); + if (pSptd && pSptd->_traceCall) { - _pSptd_->newSpan(); + pSptd->newSpan(); string _trace_param_; - int _trace_param_flag_ = _pSptd_->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS, _os.getLength()); + int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS, _os.getLength()); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -613,7 +612,7 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "verify", 0, _trace_param_, ""); + TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + "." + ServerConfig::ServerName, tars_name(), "verify", 0, _trace_param_, ""); } tars_invoke_async(tars::TARSNORMAL,"verify", _os, context, _mStatus, callback); } @@ -639,12 +638,12 @@ namespace Base tars_invoke_async(tars::TARSNORMAL,"verify", _os, context, _mStatus, callback, true); } - VerifyProxy* tars_hash(uint32_t key) + VerifyProxy* tars_hash(int64_t key) { return (VerifyProxy*)ServantProxy::tars_hash(key); } - VerifyProxy* tars_consistent_hash(uint32_t key) + VerifyProxy* tars_consistent_hash(int64_t key) { return (VerifyProxy*)ServantProxy::tars_consistent_hash(key); } @@ -668,31 +667,31 @@ namespace Base { public: virtual ~Verify(){} - virtual tars::Int32 verify(const Base::VerifyReq & req,Base::VerifyRsp &rsp,tars::TarsCurrentPtr _current_) = 0; - static void async_response_verify(tars::TarsCurrentPtr _current_, tars::Int32 _ret, const Base::VerifyRsp &rsp) + virtual tars::Int32 verify(const Base::VerifyReq & req,Base::VerifyRsp &rsp,tars::TarsCurrentPtr current) = 0; + static void async_response_verify(tars::TarsCurrentPtr current, tars::Int32 _ret, const Base::VerifyRsp &rsp) { size_t _rsp_len_ = 0; - if (_current_->getRequestVersion() == TUPVERSION ) + if (current->getRequestVersion() == TUPVERSION ) { - UniAttribute _tarsAttr_; - _tarsAttr_.setVersion(_current_->getRequestVersion()); - _tarsAttr_.put("", _ret); - _tarsAttr_.put("tars_ret", _ret); - _tarsAttr_.put("rsp", rsp); + UniAttribute tarsAttr; + tarsAttr.setVersion(current->getRequestVersion()); + tarsAttr.put("", _ret); + tarsAttr.put("tars_ret", _ret); + tarsAttr.put("rsp", rsp); vector sTupResponseBuffer; - _tarsAttr_.encode(sTupResponseBuffer); - _current_->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer); + tarsAttr.encode(sTupResponseBuffer); + current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer); _rsp_len_ = sTupResponseBuffer.size(); } - else if (_current_->getRequestVersion() == JSONVERSION) + else if (current->getRequestVersion() == JSONVERSION) { tars::JsonValueObjPtr _p = new tars::JsonValueObj(); _p->value["rsp"] = tars::JsonOutput::writeJson(rsp); _p->value["tars_ret"] = tars::JsonOutput::writeJson(_ret); vector sJsonResponseBuffer; tars::TC_Json::writeValue(_p, sJsonResponseBuffer); - _current_->sendResponse(tars::TARSSERVERSUCCESS, sJsonResponseBuffer); + current->sendResponse(tars::TARSSERVERSUCCESS, sJsonResponseBuffer); _rsp_len_ = sJsonResponseBuffer.size(); } else @@ -702,13 +701,13 @@ namespace Base _os.write(rsp, 2); + current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer()); _rsp_len_ = _os.getLength(); - _current_->sendResponse(tars::TARSSERVERSUCCESS, _os); } - if (_current_->isTraced()) + if (current->isTraced()) { string _trace_param_; - int _trace_param_flag_ = ServantProxyThreadData::needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, _current_->getTraceKey(), _rsp_len_); + int _trace_param_flag_ = ServantProxyThreadData::needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, current->getTraceKey(), _rsp_len_); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -720,21 +719,10 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); + TARS_TRACE(current->getTraceKey(), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); } } - static void async_response_push_verify(tars::CurrentPtr _current_, tars::Int32 _ret, const Base::VerifyRsp &rsp, const map &_context = tars::Current::TARS_STATUS()) - { - { - tars::TarsOutputStream _os; - _os.write(_ret, 0); - - _os.write(rsp, 2); - - _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"verify", _os, _context); - } - } public: int onDispatch(tars::TarsCurrentPtr _current, vector &_sResponseBuffer) @@ -756,11 +744,11 @@ namespace Base Base::VerifyRsp rsp; if (_current->getRequestVersion() == TUPVERSION) { - UniAttribute _tarsAttr_; - _tarsAttr_.setVersion(_current->getRequestVersion()); - _tarsAttr_.decode(_current->getRequestBuffer()); - _tarsAttr_.get("req", req); - _tarsAttr_.getByDefault("rsp", rsp, rsp); + UniAttribute tarsAttr; + tarsAttr.setVersion(_current->getRequestVersion()); + tarsAttr.decode(_current->getRequestBuffer()); + tarsAttr.get("req", req); + tarsAttr.getByDefault("rsp", rsp, rsp); } else if (_current->getRequestVersion() == JSONVERSION) { @@ -773,11 +761,11 @@ namespace Base _is.read(req, 1, true); _is.read(rsp, 2, false); } - ServantProxyThreadData *_pSptd_ = ServantProxyThreadData::getData(); - if (_pSptd_ && _pSptd_->_traceCall) + ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); + if (pSptd && pSptd->_traceCall) { string _trace_param_; - int _trace_param_flag_ = _pSptd_->needTraceParam(ServantProxyThreadData::TraceContext::EST_SR, _is.size()); + int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_SR, _is.size()); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -788,7 +776,7 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); + TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); } tars::Int32 _ret = verify(req,rsp, _current); @@ -796,12 +784,12 @@ namespace Base { if (_current->getRequestVersion() == TUPVERSION) { - UniAttribute _tarsAttr_; - _tarsAttr_.setVersion(_current->getRequestVersion()); - _tarsAttr_.put("", _ret); - _tarsAttr_.put("tars_ret", _ret); - _tarsAttr_.put("rsp", rsp); - _tarsAttr_.encode(_sResponseBuffer); + UniAttribute tarsAttr; + tarsAttr.setVersion(_current->getRequestVersion()); + tarsAttr.put("", _ret); + tarsAttr.put("tars_ret", _ret); + tarsAttr.put("rsp", rsp); + tarsAttr.encode(_sResponseBuffer); } else if (_current->getRequestVersion() == JSONVERSION) { @@ -817,10 +805,10 @@ namespace Base _os.write(rsp, 2); _os.swap(_sResponseBuffer); } - if (_pSptd_ && _pSptd_->_traceCall) + if (pSptd && pSptd->_traceCall) { string _trace_param_; - int _trace_param_flag_ = _pSptd_->needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, _sResponseBuffer.size()); + int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, _sResponseBuffer.size()); if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_) { tars::JsonValueObjPtr _p_ = new tars::JsonValueObj(); @@ -832,13 +820,13 @@ namespace Base { _trace_param_ = "{\"trace_param_over_max_len\":true}"; } - TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); + TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, "", ServerConfig::Application + "." + ServerConfig::ServerName, "verify", 0, _trace_param_, ""); } } - else if(_pSptd_ && _pSptd_->_traceCall) + else if(pSptd && pSptd->_traceCall) { - _current->setTrace(_pSptd_->_traceCall, _pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS)); + _current->setTrace(pSptd->_traceCall, pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS)); } return tars::TARSSERVERSUCCESS;