📄 provisionserver.cxx
字号:
result = _copy.sendDeleteItem(ACCOUNTS, userName); if (result != RedundancyManager::OK) { if (result == RedundancyManager::ERR) { _copy.connFailed(); return ; } if (result == RedundancyManager::FAIL) { _copy.badReturn(); setSyncTimer(); return ; } } } sendVPPOk(conn); } catch (VIoException& e) { // Failed to remove the item for whatever reason cpLog(LOG_ERR, "Caught exception when trying to delete user, reason %s", e.getDescription().c_str()); sendVPPFail(conn); } return;}voidProvisionServer::handleItemRegisterRequest(const string &group, const string &name, const string &hostPortPair){ // check all arguments exist and final one has a : (trivial check for // host port pair) if (group == "" || name == "" || hostPortPair == "" || (hostPortPair.find(":") == string::npos)) { cpLog(LOG_ERR, "Received malformed register request."); return ; } _registerManager.registerItem(group, name, hostPortPair); if (_copy.inUse() && _copy.isAlive()) { int result = _copy.sendRegisterItem(group, name, hostPortPair); if (result == RedundancyManager::ERR) { _copy.connFailed(); } }}voidProvisionServer::handleGroupRegisterRequest(const string &group, const string &hostPortPair){ // check all arguments exist and final one has a : (trivial check for // host port pair) if (group == "" || hostPortPair == "" || (hostPortPair.find(":") == string::npos)) { cpLog(LOG_ERR, "Received malformed register request."); return ; } _registerManager.registerGroup(group, hostPortPair); if (_copy.inUse() && _copy.isAlive()) { int result = _copy.sendRegisterGroup(group, hostPortPair); if (result == RedundancyManager::ERR) { _copy.connFailed(); } }}// not used for nowvoidProvisionServer::handleItemUnregisterRequest(const string &group, const string &name, const string &hostPortPair){ // check all arguments exist and final one has a : (trivial check for // host port pair) if (group == "" || name == "" || hostPortPair == "" || (hostPortPair.find(":") == string::npos)) { cpLog(LOG_ERR, "Received malformed unregister request."); return ; } _registerManager.unregisterItem(group, name, hostPortPair); //FIX! Send to copy}// not used for nowvoidProvisionServer::handleGroupUnregisterRequest(const string &group, const string &hostPortPair){ // check all arguments exist and final one has a : (trivial check for // host port pair) if (group == "" || hostPortPair == "" || (hostPortPair.find(":") == string::npos)) { cpLog(LOG_ERR, "Received malformed unregister request."); return ; } _registerManager.unregisterGroup(group, hostPortPair); // FIX! Send to copy}voidProvisionServer::sendVPPFail(LockedConnection &conn){ string retData = makeVPPHeader(vppFailGLBL, 0); try { conn.writeData(retData); cpLog(LOG_DEBUG, "Send Fail (400) Message"); } catch (VNetworkException& e) { cpLog(LOG_DEBUG, "Caught exception when writing data, reason %s", e.getDescription().c_str()); }}voidProvisionServer::sendVPPOk(LockedConnection &conn){ string retData = makeVPPHeader(vppOkGLBL, 0); try { conn.writeData(retData); cpLog(LOG_DEBUG, "Send Ok (200) Message"); } catch (VNetworkException& e) { cpLog(LOG_DEBUG, "Caught exception when writing data, reason %s", e.getDescription().c_str()); }}voidProvisionServer::handleSyncGetRListRequest(LockedConnection& conn){ cpLog(LOG_DEBUG, "Got into the handle sync"); if (!_copy.inUse()) { // We aren't syncing, so ignore this cpLog(LOG_ERR, "Sync request but not using sync"); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); return ; } int state = _copy.syncRegList(); if (state == RedundancyManager::ERR) { // this is bad cpLog(LOG_ERR, "Server went into ERROR sync state."); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); setSyncTimer(); return ; } if (state == RedundancyManager::FAIL) { //Bad VPP header string retData = makeVPPHeader(vppFailGLBL, 0); cpLog(LOG_DEBUG, "Got a SYNCGRLIST when not expecting it."); conn.writeData(retData); setSyncTimer(); return ; } string gData; try { _registerManager.getList(gData); //Success string retData = makeVPPHeader(vppOkGLBL, gData.size()); retData += gData; retData += "\n"; cpLog(LOG_DEBUG, retData.c_str()); conn.writeData(retData); } catch (VIoException& e) { //Failed to read the data string reason = e.getDescription(); string retData = makeVPPHeader(vppFailGLBL, reason.size()); retData += reason; cpLog(LOG_DEBUG, retData.c_str()); conn.writeData(retData); }}voidProvisionServer::handleSyncPutRListRequest(LockedConnection& conn){ if (!_copy.inUse()) { // We aren't syncing, so ignore this cpLog(LOG_ERR, "Sync request but not using sync"); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); return ; } int state = _copy.syncRegList(); if (state == RedundancyManager::ERR) { // this is bad cpLog(LOG_ERR, "Server went into ERROR sync state."); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); setSyncTimer(); return ; } if (state == RedundancyManager::FAIL) { //Bad VPP header string retData = makeVPPHeader(vppFailGLBL, 0); cpLog(LOG_DEBUG, "Got a SYNCPRLIST when not expecting it."); conn.writeData(retData); setSyncTimer(); return ; } //Get the content length char buf[MAXLINE]; int nread = 0; try { //Read content length nread = 0; if (conn.readLine(buf, sizeof(buf), nread) < 0) { //Bad VPP header string retData = makeVPPHeader(vppFailGLBL, 0); cpLog(LOG_DEBUG, retData.c_str()); conn.writeData(retData); return ; } char msg[256]; int len; // get content length sscanf(buf, "%s%d", msg, &len); char *bigbuf; LocalScopeAllocator lAllocator(&bigbuf, len+1); conn.readn((void*)bigbuf, len, nread); if (nread < len) { sendVPPFail(conn); cpLog(LOG_ERR, "Insufficent data on socket - closing"); return ; } bigbuf[len] = 0; char *token; char item[512], host[256]; int mode = 0; token = strtok(bigbuf, ","); if (token == NULL) { sendVPPFail(conn); cpLog(LOG_ERR, "Invalid data sent for list of reg."); return ; } sscanf(token, "%s", item); if (string(item) != "++ITEM++") { sendVPPFail(conn); cpLog(LOG_ERR, "Parse error on registration data."); return ; } while ((token = strtok(NULL, ",")) != NULL) { cpLog(LOG_DEBUG, "token (%s)", token); sscanf(token, "%s", item); if (string(item) == "++GROUP++") { mode = 1; continue; } token = strtok(NULL, ","); if (token == NULL) { sendVPPFail(conn); cpLog(LOG_ERR, "Parse error on socket - closing"); return ; } sscanf(token, "%s", host); if (mode == 0) { _registerManager.registerItemCat(item, host); } else { _registerManager.registerGroup(item, host); } } sendVPPOk(conn); } catch (VNetworkException &e) { cpLog(LOG_DEBUG, "Failed to parse incoming reg list."); }}voidProvisionServer::setSyncTimer(){ // see if a timer is pending _MutextimerLock.lock(); if (timerPending) { // yep, nothing to do _MutextimerLock.unlock(); return ; } // no. Set it to true and dispatch thread timerPending = true; _MutextimerLock.unlock(); VFunctor functor(ProvisionServer::timerFunc, NULL); _threadPool->addFunctor(functor);}voidProvisionServer::setSyncFailTimer(){ // see if a timer is pending _MutextimerLock.lock(); if (failTimerPending) { // yep, nothing to do _MutextimerLock.unlock(); return ; } // no. Set it to true and dispatch thread failTimerPending = true; _MutextimerLock.unlock(); VFunctor functor(ProvisionServer::timerFailFunc, NULL); _threadPool->addFunctor(functor);}voidProvisionServer::handleSyncGetRequest(LockedConnection& conn, const string& group, const string &name){ string gData; TimeStamp timestamp; int state; if (!_copy.inUse()) { // We aren't syncing, so ignore this cpLog(LOG_ERR, "Sync request but not using sync"); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); return ; } state = _copy.syncExchange(); if (state == RedundancyManager::ERR) { // this is bad cpLog(LOG_ERR, "Server went into ERROR sync state."); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); setSyncTimer(); return ; } if (state == RedundancyManager::FAIL) { //Bad VPP header string retData = makeVPPHeader(vppFailGLBL, 0); cpLog(LOG_DEBUG, "Got a SYNCGET when not expecting it."); conn.writeData(retData); setSyncTimer(); return ; } try { gData = _dataStore->getItem(group, name); timestamp = _dataStore->getItemTimeStamp(group, name); //Success string retData = makeVPPHeader(vppOkGLBL, gData.size(), timestamp); retData += gData; conn.writeData(retData); } catch (VIoException& e) { //Failed to read the item sendVPPFail(conn); string reason = e.getDescription(); cpLog(LOG_DEBUG, reason.c_str()); }}voidProvisionServer::handleSyncStartRequest(LockedConnection& conn){ if (!_copy.inUse()) { // We aren't syncing, so ignore this cpLog(LOG_ERR, "Sync request but not using sync"); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); return ; } cpLog(LOG_DEBUG, "ProvisionServer::handleSyncStartRequest"); string gData; int state; state = _copy.syncStart(); if (state == RedundancyManager::ERR) { // this is bad cpLog(LOG_ERR, "Server went into ERROR sync state."); string retData = makeVPPHeader(vppFailGLBL, 0); conn.writeData(retData); setSyncTimer(); return ; } if (state == RedundancyManager::FAIL) { //Bad VPP header string retData = makeVPPHeader(vppFailGLBL, 0); cpLog(LOG_DEBUG, "Got a SYNCSTART when not expecting it."); conn.writeData(retData); setSyncTimer(); return ; } try { map < string, TimeStamp > localMap; getLocalMap(localMap); string retData; string finalData; list < string > tosend;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -