From 2eaa72a378b88d652f3b837b5a4534ca7360a0f5 Mon Sep 17 00:00:00 2001 From: jarodruan Date: Wed, 12 Feb 2020 20:35:39 +0800 Subject: [PATCH] Transceiver add finishInvoke for auth --- servant/libservant/AdapterProxy.cpp | 46 ++++++++++++++--------------- servant/libservant/Transceiver.cpp | 45 +++++++++++++++++++++++----- servant/servant/Transceiver.h | 6 ++-- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/servant/libservant/AdapterProxy.cpp b/servant/libservant/AdapterProxy.cpp index 402c5b7..07d781d 100755 --- a/servant/libservant/AdapterProxy.cpp +++ b/servant/libservant/AdapterProxy.cpp @@ -489,29 +489,29 @@ void AdapterProxy::finishInvoke(shared_ptr & rsp) TLOGTARS("[TARS][AdapterProxy::finishInvoke(ResponsePacket) objname:" << _objectProxy->name() << ",desc:" << _endpoint.desc() << ",id:" << rsp->iRequestId << endl); - if (_trans->getAuthState() != AUTH_SUCC) - { - std::string ret(rsp->sBuffer.begin(), rsp->sBuffer.end()); - tars::AUTH_STATE tmp = AUTH_SUCC; - tars::stoe(ret, tmp); - int newstate = tmp; - - TLOGTARS("[TARS]AdapterProxy::finishInvoke from state " << _trans->getAuthState() << " to " << newstate << endl); - _trans->setAuthState(newstate); - - if (newstate == AUTH_SUCC) - { - // flush old buffered msg when auth is not complete - doInvoke(); - } - else - { - TLOGERROR("newstate is " << newstate << ", error close!\n"); - _trans->close(); - } - - return; - } +// if (_trans->getAuthState() != AUTH_SUCC) +// { +// std::string ret(rsp->sBuffer.begin(), rsp->sBuffer.end()); +// tars::AUTH_STATE tmp = AUTH_SUCC; +// tars::stoe(ret, tmp); +// int newstate = tmp; +// +// TLOGTARS("[TARS]AdapterProxy::finishInvoke from state " << _trans->getAuthState() << " to " << newstate << endl); +// _trans->setAuthState(newstate); +// +// if (newstate == AUTH_SUCC) +// { +// // flush old buffered msg when auth is not complete +// doInvoke(); +// } +// else +// { +// TLOGERROR("newstate is " << newstate << ", error close!\n"); +// _trans->close(); +// } +// +// return; +// } ReqMessage * msg = NULL; diff --git a/servant/libservant/Transceiver.cpp b/servant/libservant/Transceiver.cpp index b75979c..290be13 100755 --- a/servant/libservant/Transceiver.cpp +++ b/servant/libservant/Transceiver.cpp @@ -161,13 +161,13 @@ void Transceiver::setConnected() _adapterProxy->setConTimeout(false); _adapterProxy->addConnExc(false); - _onConnect(); + onConnect(); TLOGTARS("[TARS][tcp setConnected, " << _adapterProxy->getObjProxy()->name() << ",fd:" << _fd << "]" << endl); } -void Transceiver::_onConnect() +void Transceiver::onConnect() { #if TARS_SSL if (isSSL()) @@ -204,14 +204,14 @@ void Transceiver::_onConnect() } #endif - _doAuthReq(); + doAuthReq(); } -void Transceiver::_doAuthReq() +void Transceiver::doAuthReq() { ObjectProxy* obj = _adapterProxy->getObjProxy(); - TLOGTARS("[TARS][_onConnect:" << obj->name() << " auth type is " << _adapterProxy->endpoint().authType() << endl); + TLOGTARS("[TARS][onConnect:" << obj->name() << " auth type is " << _adapterProxy->endpoint().authType() << endl); if (_adapterProxy->endpoint().authType() == AUTH_TYPENONE) { @@ -229,6 +229,35 @@ void Transceiver::_doAuthReq() } } +void Transceiver::finishInvoke(shared_ptr &rsp) +{ + + if (_authState != AUTH_SUCC) + { + std::string ret(rsp->sBuffer.begin(), rsp->sBuffer.end()); + tars::AUTH_STATE tmp = AUTH_SUCC; + tars::stoe(ret, tmp); + int newstate = tmp; + + TLOGTARS("[TARS]AdapterProxy::finishInvoke from state " << _authState << " to " << newstate << endl); + setAuthState(newstate); + + if (newstate == AUTH_SUCC) + { + // flush old buffered msg when auth is not complete + _adapterProxy->doInvoke(); + } + else + { + TLOGERROR("newstate is " << newstate << ", error close!\n"); + close(); + } + + return; + } + _adapterProxy->finishInvoke(rsp); +} + bool Transceiver::sendAuthData(const BasicAuthInfo& info) { assert (_authState != AUTH_SUCC); @@ -474,7 +503,7 @@ int TcpTransceiver::doResponse() break; } else if (ret == TC_NetWorkBuffer::PACKET_FULL) { - _adapterProxy->finishInvoke(rsp); + finishInvoke(rsp); } else { break; @@ -585,7 +614,7 @@ int TcpTransceiver::doResponse() // return 0; // if (preNotHandshake) -// _doAuthReq(); +// doAuthReq(); // std::string* plainBuf = _openssl->RecvBuffer(); // data = plainBuf->data(); @@ -817,7 +846,7 @@ int UdpTransceiver::doResponse() } else { - _adapterProxy->finishInvoke(rsp); + finishInvoke(rsp); } } catch (exception &ex) diff --git a/servant/servant/Transceiver.h b/servant/servant/Transceiver.h index 3129e1c..2f4a168 100755 --- a/servant/servant/Transceiver.h +++ b/servant/servant/Transceiver.h @@ -210,6 +210,8 @@ public: _connStatus = eUnconnected; } + void finishInvoke(shared_ptr &rsp); + /** * 设置鉴权状态 */ @@ -232,12 +234,12 @@ protected: /** ** 物理连接成功回调 **/ - void _onConnect(); + void onConnect(); /** ** 鉴权初始化请求 **/ - void _doAuthReq(); + void doAuthReq(); /* * AdapterProxy