uint32_t RuleSetPrivate::appendRule(const Rule& rule, uint32_t parent_id, bool lock) { std::unique_lock<std::mutex> op_lock(_op_mutex, std::defer_lock); if (lock) { op_lock.lock(); } auto rule_ptr = makePointer<Rule>(rule); /* * If the rule doesn't already have a sequence number * assigned, do it now. Otherwise update the sequence * number counter so that we don't generate a duplicit * one if assignID() gets called in the future. */ if (rule_ptr->getRuleID() == Rule::DefaultID) { assignID(rule_ptr); } else { _id_next = std::max(_id_next.load(), rule_ptr->getRuleID() + 1); } /* Initialize conditions */ rule_ptr->internal()->initConditions(_interface_ptr); /* Append the rule to the main rule table */ if (parent_id == Rule::LastID) { _rules.push_back(rule_ptr); } else if (parent_id == 0) { _rules.insert(_rules.begin(), rule_ptr); } else { bool parent_found = false; for (auto it = _rules.begin(); it != _rules.end(); ++it) { const Rule& rule = **it; if (rule.getRuleID() == parent_id) { _rules.insert(it+1, rule_ptr); parent_found = true; break; } } if (!parent_found) { throw Exception("Rule set append", "rule", "Invalid parent ID"); } } /* If the rule is timed, put it into the priority queue */ if (rule_ptr->getTimeoutSeconds() > 0) { _rules_timed.push(rule_ptr); } return rule_ptr->getRuleID(); }
bool TestCppBase::TestSatelliteServer() { IniSetting::Map ini = IniSetting::Map::object; Hdf hdf; hdf.fromString( "Satellites {\n" " rpc {\n" " Type = RPCServer\n" " Port = 9999\n" " RequestInitDocument = my/rpc/rpc.php\n" " RequestInitFunction = init_me\n" " Password = abcd0987\n" " Passwords {\n" " * = abcd0987\n" " }\n" " }\n" " ips {\n" " Type = InternalPageServer\n" " BlockMainServer = false\n" " }\n" "}\n" ); std::vector<std::shared_ptr<SatelliteServerInfo>> infos; RuntimeOption::ReadSatelliteInfo(ini, hdf, infos, RuntimeOption::XboxPassword, RuntimeOption::XboxPasswords); for (auto& info_ptr : infos) { auto info = info_ptr.get(); auto name = info->getName(); if (name == "rpc") { VERIFY(info->getType() == SatelliteServer::Type::KindOfRPCServer); VERIFY(info->getPort() == 9999); VERIFY(info->getThreadCount() == 5); VERIFY(info->getTimeoutSeconds() == std::chrono::seconds(RuntimeOption::RequestTimeoutSeconds)); VERIFY(info->getURLs().size() == 0); VERIFY(info->getMaxRequest() == 500); VERIFY(info->getMaxDuration() == 120); VERIFY(info->getReqInitFunc() == "init_me"); VERIFY(info->getReqInitDoc() == "my/rpc/rpc.php"); VERIFY(info->getPassword() == "abcd0987"); VERIFY(info->getPasswords().size() == 1); VERIFY(info->getPasswords().find("abcd0987") != info->getPasswords().end()); VERIFY(info->alwaysReset() == false); VERIFY(RuntimeOption::XboxPassword == "abcd0987"); } else if (name == "ips") { VERIFY(info->getType() == SatelliteServer::Type::KindOfInternalPageServer); VERIFY(info->getURLs().size() == 0); } } return Count(true); }
bool TestCppBase::TestSatelliteServerIni() { std::string iniStr = "hhvm.satellites[rpc][type] = RPCServer\n" "hhvm.satellites[rpc][port] = 9999\n" "hhvm.satellites[rpc][request_init_document] = my/rpc/rpc.php\n" "hhvm.satellites[rpc][request_init_function] = init_me\n" "hhvm.satellites[rpc][password] = abcd0987\n" "hhvm.satellites[rpc][passwords][] = abcd0987\n" "hhvm.satellites[ips][type] = InternalPageServer\n" "hhvm.satellites[ips][block_main_server] = false\n"; IniSettingMap ini = IniSetting::Map::object; Hdf empty; Config::ParseIniString(iniStr, ini); std::vector<std::shared_ptr<SatelliteServerInfo>> infos; RuntimeOption::ReadSatelliteInfo(ini, empty, infos, RuntimeOption::XboxPassword, RuntimeOption::XboxPasswords); for (auto& info_ptr : infos) { auto info = info_ptr.get(); auto name = info->getName(); if (name == "rpc") { VERIFY(info->getType() == SatelliteServer::Type::KindOfRPCServer); VERIFY(info->getPort() == 9999); VERIFY(info->getThreadCount() == 5); VERIFY(info->getTimeoutSeconds() == std::chrono::seconds(RuntimeOption::RequestTimeoutSeconds)); VERIFY(info->getURLs().size() == 0); VERIFY(info->getMaxRequest() == 500); VERIFY(info->getMaxDuration() == 120); VERIFY(info->getReqInitFunc() == "init_me"); VERIFY(info->getReqInitDoc() == "my/rpc/rpc.php"); VERIFY(info->getPassword() == "abcd0987"); VERIFY(info->getPasswords().size() == 1); VERIFY(info->getPasswords().find("abcd0987") != info->getPasswords().end()); VERIFY(info->alwaysReset() == false); VERIFY(RuntimeOption::XboxPassword == "abcd0987"); } else if (name == "ips") { VERIFY(info->getType() == SatelliteServer::Type::KindOfInternalPageServer); VERIFY(info->getURLs().size() == 0); } } return Count(true); }
uint32_t RuleSetPrivate::appendRule(const Rule& rule, uint32_t parent_seqn) { std::unique_lock<std::mutex> op_lock(_op_mutex); auto rule_ptr = makePointer<Rule>(rule); /* Assign a unique sequence number to the rule */ assignSeqn(rule_ptr); /* Set time */ rule_ptr->setTimePointAdded(std::chrono::steady_clock::now()); /* Append the rule to the main rule table */ if (parent_seqn == Rule::SeqnLast) { _rules.push_back(rule_ptr); } else if (parent_seqn == 0) { _rules.insert(_rules.begin(), rule_ptr); } else { bool parent_found = false; for (auto it = _rules.begin(); it != _rules.end(); ++it) { const Rule& rule = **it; if (rule.getSeqn() == parent_seqn) { _rules.insert(it+1, rule_ptr); parent_found = true; break; } } if (!parent_found) { throw std::runtime_error("Invalid parent_seqn"); } } /* If the rule is timed, put it into the priority queue */ if (rule_ptr->getTimeoutSeconds() > 0) { _rules_timed.push(rule_ptr); } return rule_ptr->getSeqn(); }