bool PeerAuthServerOp::CallbackHook(AsyncOp *theOp, int theType) { if(!theOp->Succeeded()) { Finish(theOp->GetStatus()); return true; } if(theType==PeerAuth_Track_Recv) { RecvMsgOp *aRecvOp = dynamic_cast<RecvMsgOp*>(theOp); if(aRecvOp==NULL) return true; ByteBufferPtr aSendMsg; ByteBufferPtr aRecvMsg = aRecvOp->GetMsg(); WONStatus aStatus = mPeerAuthServer.HandleRecvMsg(aRecvMsg->data(),aRecvMsg->length(),aSendMsg); int aSendType = 0; if(aStatus==WS_Success && mPeerAuthServer.GetState()==PeerAuthServer::STATE_NOT_STARTED) // --> finished aSendType = PeerAuth_Track_LastSend; if(aSendMsg.get()!=NULL) mSocket->QueueOp((SocketOp*)Track(new SendMsgOp(aSendMsg),aSendType), SendTime()); // send reply if(aStatus!=WS_Success) Finish(aStatus); else if(aSendType!=PeerAuth_Track_LastSend) // need to recv a reply mSocket->QueueOp((SocketOp*)Track(new RecvMsgOp,PeerAuth_Track_Recv), RecvTime()); // get ready for challenge2 } else if(theType==PeerAuth_Track_LastSend) Success(); return true; }
void ServerConnection::StaticMsgCallback(AsyncOpPtr theOp, RefCountPtr theParam) { RecvMsgOp *anOp = (RecvMsgOp*)theOp.get(); ServerConnection *thisConnection = (ServerConnection*)theParam.get(); if(anOp->GetStatus()==WS_Success) thisConnection->MsgCallback(anOp->GetMsg()); }
bool ServerRequestOp::CallbackHook(AsyncOp *theOp, int theParam) { if(theOp->Killed()) { Kill(); return true; } if(!theOp->Succeeded()) { if(theParam==ServerReq_Track_PeerAuth && theOp->GetStatus()==WS_PeerAuth_GetCertFailure) { mGetCertStatus = ((PeerAuthOp*)theOp)->GetGetCertStatus(); Finish(WS_ServerReq_GetCertFailure); return true; } SetLastServerError(theOp->GetStatus()); TryNextServer(); return true; } switch(theParam) { case ServerReq_Track_PeerAuth: { PeerAuthOp *aPeerAuthOp = (PeerAuthOp*)theOp; mCurSession = aPeerAuthOp->GetSession(); Send(); } break; case ServerReq_Track_Socket: { RecvMsgOp *aRecvOp = dynamic_cast<RecvMsgOp*>(theOp); if(aRecvOp==NULL) break; mResponse = aRecvOp->GetMsg(); if(CheckExpiredSession()) { TryNextServer(); break; } try { WONStatus aStatus = CheckResponse(); if(aStatus==WS_ServerReq_TryNextServer) // error, try next server TryNextServer(); else if(aStatus==WS_ServerReq_Send) // more data to send Send(); else if(aStatus==WS_ServerReq_Recv) // more data to receive QueueSocketOp(new RecvMsgOp, RecvTime()); else if(aStatus==WS_ServerReq_ExitCommunicationLoop) return true; else // done FinishSaveSession(aStatus); } catch(ReadBufferException&) { SetLastServerError(WS_ServerReq_UnpackFailure); TryNextServer(); } } break; default: return false; } return true; }
bool PeerAuthOp::CallbackHook(AsyncOp *theOp, int theParam) { switch(theParam) { case PeerAuth_Track_Socket: { if(!theOp->Succeeded()) { Finish(theOp->GetStatus()); break; } if(mAuthType==AUTH_TYPE_NONE) // just connecting { Finish(WS_Success); break; } RecvMsgOp *aRecvOp = dynamic_cast<RecvMsgOp*>(theOp); if(aRecvOp==NULL) break; ByteBufferPtr aSendMsg; ByteBufferPtr aRecvMsg = aRecvOp->GetMsg(); WONStatus aStatus = mPeerAuthClient.HandleRecvMsg(aRecvMsg->data(),aRecvMsg->length(),aSendMsg); if(aStatus==WS_CommServ_InvalidParameters || aStatus==WS_CommServ_ExpiredPeerCertificate) // expired certificate { mPeerAuthClient.Reset(); switch(mGetCertStatus) { case WS_None: AsyncRefreshCert(); break; case WS_Pending: break; case WS_Success: AsyncRetry(); break; default: Finish(WS_PeerAuth_GetCertFailure); } break; } else if(CheckStatus(aStatus)) break; if(aSendMsg.get()==NULL) Success(); // done else AsyncSend(aSendMsg); // Need to send more stuff } break; case PeerAuth_Track_GetCert: { LightGetCertOp *aGetCert = (LightGetCertOp*)theOp; mGetCertStatus = aGetCert->GetStatus(); mPeerData = aGetCert->GetPeerData(); if(mPeerAuthClient.GetState()==PeerAuthClient::STATE_NOT_STARTED) { if(mGetCertStatus!=WS_Success) { Finish(WS_PeerAuth_GetCertFailure); break; } else AsyncRetry(); } } break; default: return false; } return true; }