int CFlowStatUserIdMap::start_stream(uint32_t user_id, uint16_t hw_id) { #ifdef __DEBUG_FUNC_ENTRY__ std::cout << __METHOD_NAME__ << " user id:" << user_id << " hw_id:" << hw_id << std::endl; #endif CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { throw TrexFStatEx("Internal error: Trying to associate non exist group id " + std::to_string(user_id) + " to hardware id " + std::to_string(hw_id) , TrexException::T_FLOW_STAT_ASSOC_NON_EXIST_ID); } if (c_user_id->is_hw_id()) { throw TrexFStatEx("Internal error: Trying to associate hw id " + std::to_string(hw_id) + " to user_id " + std::to_string(user_id) + ", but it is already associated to " + std::to_string(c_user_id->get_hw_id()) , TrexException::T_FLOW_STAT_ASSOC_OCC_ID); } c_user_id->set_hw_id(hw_id); c_user_id->add_started_stream(); return 0; }
uint16_t CFlowStatUserIdMap::get_hw_id(uint32_t user_id) { CFlowStatUserIdInfo *cf = find_user_id(user_id); if (cf == NULL) { return HW_ID_FREE; } else { return cf->get_hw_id(); } }
uint8_t CFlowStatUserIdMap::l4_proto(uint32_t user_id) { CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { return 0; } return c_user_id->get_proto(); }
bool CFlowStatUserIdMap::is_started(uint32_t user_id) { CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { return false; } return c_user_id->is_started(); }
// return: negative number in case of error. // Number of started streams attached to used_id otherwise. int CFlowStatUserIdMap::stop_stream(uint32_t user_id) { #ifdef __DEBUG_FUNC_ENTRY__ std::cout << __METHOD_NAME__ << " user id:" << user_id << std::endl; #endif CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { throw TrexFStatEx("Trying to stop stream with non exist packet group id" + std::to_string(user_id) , TrexException::T_FLOW_STAT_NON_EXIST_ID); } return c_user_id->stop_started_stream(); }
void CFlowStatUserIdMap::add_stream(uint32_t user_id, uint8_t proto) { #ifdef __DEBUG_FUNC_ENTRY__ std::cout << __METHOD_NAME__ << " user id:" << user_id << " proto:" << (uint16_t)proto << std::endl; #endif CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { c_user_id = add_user_id(user_id, proto); // throws exception on error } else { c_user_id->add_stream(proto); } }
uint16_t CFlowStatUserIdMap::unmap(uint32_t user_id) { #ifdef __DEBUG_FUNC_ENTRY__ std::cout << __METHOD_NAME__ << " user id:" << user_id << std::endl; #endif CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { return UINT16_MAX; } uint16_t old_hw_id = c_user_id->get_hw_id(); c_user_id->reset_hw_id(); return old_hw_id; }
int CFlowStatUserIdMap::del_stream(uint32_t user_id) { #ifdef __DEBUG_FUNC_ENTRY__ std::cout << __METHOD_NAME__ << " user id:" << user_id << std::endl; #endif CFlowStatUserIdInfo *c_user_id; c_user_id = find_user_id(user_id); if (! c_user_id) { throw TrexFStatEx("Trying to delete stream which does not exist" , TrexException::T_FLOW_STAT_DEL_NON_EXIST); } if (c_user_id->del_stream() == 0) { // ref count of this entry became 0. can release this entry. m_map.erase(user_id); delete c_user_id; } return 0; }
PGPPublicKey revoke_uid(PGPPublicKey & pub, PGPSecretKey & pri, const std::string passphrase, const uint8_t code, const std::string & reason){ if (pub.get_ASCII_Armor() != 1){ throw std::runtime_error("Error: A public key is required for the first argument."); } if (pri.get_ASCII_Armor() != 2){ throw std::runtime_error("Error: A private key is required for the second argument."); } Tag5::Ptr signer = find_signing_key(pri, 5); if (!signer){ throw std::runtime_error("Error: Private signing key not found"); } // find subkey Tag7::Ptr key = nullptr; std::vector <Packet::Ptr> packets = pri.get_packets(); for(Packet::Ptr const & p : packets){ if (p -> get_tag() == 7){ std::string data = p -> raw(); key = std::make_shared<Tag7>(data); break; } } if (!key){ throw std::runtime_error("Error: No Secret Subkey packet found."); } ID::Ptr uid = find_user_id(pri); if (!uid){ throw std::runtime_error("Error: No User ID packet found."); } Tag2::Ptr sig = create_sig_packet(0x30, signer); // add revocation subpacket std::vector <Tag2Subpacket::Ptr> hashed_subpackets = sig -> get_hashed_subpackets_clone(); Tag2Sub29::Ptr revoke = std::make_shared<Tag2Sub29>(); revoke -> set_code(code); revoke -> set_reason(reason); hashed_subpackets.push_back(revoke); sig -> set_hashed_subpackets(hashed_subpackets); // set signature data std::string hashed_data = to_sign_30(key, uid, sig); sig -> set_left16(hashed_data.substr(0, 2)); sig -> set_mpi(pka_sign(hashed_data, signer, passphrase, sig -> get_hash())); // Create output key PGPPublicKey revoked(pub); std::vector <Packet::Ptr> old_packets = pub.get_packets_clone(); std::vector <Packet::Ptr> new_packets; unsigned int i = 0; // push all packets up to and including revoked packet into new packets do{ new_packets.push_back(old_packets[i]); } while ((i < old_packets.size()) && (old_packets[i++] -> get_tag() != 13)); // append revocation signature to key new_packets.push_back(sig); // append rest of packets while (i < old_packets.size()){ new_packets.push_back(old_packets[i++]); } revoked.set_packets(new_packets); signer.reset(); key.reset(); uid.reset(); sig.reset(); return revoked; }