mirror of
https://gitee.com/TarsCloud/TarsCpp.git
synced 2024-12-22 22:16:38 +08:00
Transceiver add finishInvoke for auth
This commit is contained in:
parent
5229509b66
commit
2eaa72a378
@ -489,29 +489,29 @@ void AdapterProxy::finishInvoke(shared_ptr<ResponsePacket> & 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;
|
||||
|
||||
|
@ -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<ResponsePacket> &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)
|
||||
|
@ -210,6 +210,8 @@ public:
|
||||
_connStatus = eUnconnected;
|
||||
}
|
||||
|
||||
void finishInvoke(shared_ptr<ResponsePacket> &rsp);
|
||||
|
||||
/**
|
||||
* 设置鉴权状态
|
||||
*/
|
||||
@ -232,12 +234,12 @@ protected:
|
||||
/**
|
||||
** 物理连接成功回调
|
||||
**/
|
||||
void _onConnect();
|
||||
void onConnect();
|
||||
|
||||
/**
|
||||
** 鉴权初始化请求
|
||||
**/
|
||||
void _doAuthReq();
|
||||
void doAuthReq();
|
||||
|
||||
/*
|
||||
* AdapterProxy
|
||||
|
Loading…
Reference in New Issue
Block a user