uint64_t BlockchainDB::add_block( const block& blk , const size_t& block_size , const difficulty_type& cumulative_difficulty , const uint64_t& coins_generated , const std::vector<transaction>& txs ) { // sanity if (blk.tx_hashes.size() != txs.size()) throw std::runtime_error("Inconsistent tx/hashes sizes"); block_txn_start(false); TIME_MEASURE_START(time1); crypto::hash blk_hash = get_block_hash(blk); TIME_MEASURE_FINISH(time1); time_blk_hash += time1; uint64_t prev_height = height(); // call out to add the transactions time1 = epee::misc_utils::get_tick_count(); add_transaction(blk_hash, blk.miner_tx); int tx_i = 0; crypto::hash tx_hash = crypto::null_hash; for (const transaction& tx : txs) { tx_hash = blk.tx_hashes[tx_i]; add_transaction(blk_hash, tx, &tx_hash); ++tx_i; } TIME_MEASURE_FINISH(time1); time_add_transaction += time1; // call out to subclass implementation to add the block & metadata time1 = epee::misc_utils::get_tick_count(); add_block(blk, block_size, cumulative_difficulty, coins_generated, blk_hash); TIME_MEASURE_FINISH(time1); time_add_block1 += time1; m_hardfork->add(blk, prev_height); block_txn_stop(); ++num_calls; return prev_height; }
CDiscoverTags(PCNODE_KEY node, PCGROUP_KEY grp, __uint timeout) { RTK_ADDR dest; ONLINE_CONFIG oc; oc.d_tags.ack_guid = Guid; oc.d_tags.group = *grp; c_items = 0; add_transaction(vbus_config, this); node_to_host(node, &dest.host ); dest.port = PORT_ALL_SERVER; gk = *grp; nk = *node; hint = std::string("正在接收 ") + (char*)CNodeName(nk) + "." + (char*)CGroupName(gk) + " 上的数据库标签信息..."; send_rtk_data( vbus_config, &dest, PT_DiscoverTags, &oc.d_tags, sizeof(oc.d_tags) ); Wait(timeout, TRUE); if(!c_items){ OnTimeout(); } }
void schedule_new_transaction(int chan_id) { int transaction_index; int next_slot_id; /* Then if the command bus(ses) are still open and idle, and something *could* be scheduled, * but isn't, then we can look to create a new transaction by looking in the biu for pending requests * FBDIMM : You check the up_bus * If Refresh enabled you check if you have a refresh waiting ... */ if(dram_system.dram_controller[chan_id].transaction_queue.transaction_count >= (dram_system.config.max_tq_size)){ if (get_transaction_debug()) fprintf(stdout,"[%llu] Transaction queue [%d] full. Cannot start new transaction.\n",dram_system.current_dram_time,chan_id); return ; } if((next_slot_id = get_next_request_from_biu(global_biu)) != MEM_STATE_INVALID){ /* If command bus is idle, see if there is another request in BIU that needs to be serviced. * We start by finding the request we want to service. * Specifically, we want the slot_id of the request * and either move it from VALID to MEM_STATE_SCHEDULED or from MEM_STATE_SCHEDULED to COMPLETED */ transaction_index = add_transaction(dram_system.current_dram_time, get_access_type(global_biu, next_slot_id), next_slot_id,&chan_id); if(transaction_index != MEM_STATE_INVALID){ set_last_transaction_type(global_biu, get_access_type(global_biu, next_slot_id)); set_biu_slot_status(global_biu, next_slot_id, MEM_STATE_SCHEDULED); if(get_transaction_debug()){ fprintf(stdout,"Start @ [%llu]: ",dram_system.current_dram_time); print_transaction(dram_system.current_dram_time,chan_id,dram_system.dram_controller[chan_id].transaction_queue.entry[transaction_index].transaction_id); } } else if (get_transaction_debug()){ fprintf(stdout,"Transaction queue full. Cannot start new transaction.\n"); } } }
uint64_t BlockchainDB::add_block( const block& blk , const size_t& block_size , const difficulty_type& cumulative_difficulty , const uint64_t& coins_generated , const std::vector<transaction>& txs ) { block_txn_start(false); TIME_MEASURE_START(time1); crypto::hash blk_hash = get_block_hash(blk); TIME_MEASURE_FINISH(time1); time_blk_hash += time1; // call out to subclass implementation to add the block & metadata time1 = epee::misc_utils::get_tick_count(); add_block(blk, block_size, cumulative_difficulty, coins_generated, blk_hash); TIME_MEASURE_FINISH(time1); time_add_block1 += time1; // call out to add the transactions time1 = epee::misc_utils::get_tick_count(); add_transaction(blk_hash, blk.miner_tx); int tx_i = 0; crypto::hash tx_hash = null_hash; for (const transaction& tx : txs) { tx_hash = blk.tx_hashes[tx_i]; add_transaction(blk_hash, tx, &tx_hash); ++tx_i; } TIME_MEASURE_FINISH(time1); time_add_transaction += time1; // DB's new height based on this added block is only incremented after this // function returns, so height() here returns the new previous height. uint64_t prev_height = height(); m_hardfork->add(blk, prev_height); block_txn_stop(); ++num_calls; return prev_height; }
CDiscoverNodes(__uint timeout) { c_nodes = 0; add_transaction(vbus_config, this); broadcast_rtk_data( vbus_config, PORT_ALL_SERVER, PT_DiscoverNodes, (void *)&this->Guid, sizeof(this->Guid) ); Wait(timeout); }
int main(void) { struct dictionary *constants = dict_create(); while(1) { printf("Please enter what you want to record. And enter the accoutning name first\n"); char *s = readline(); int num; scanf("%d", &num); if (s == NULL) break; add_transaction(s, num, constants); free(s); } dict_destroy(constants); }
CDiscoverPictures(PCNODE_KEY node, __uint timeout) { RTK_ADDR dest; c_items = 0; add_transaction(vbus_config, this); node_to_host(node, &dest.host); dest.port = PORT_ALL_SERVER; send_rtk_data_with_guid( vbus_config, &dest, &Guid, PT_DiscoverPictures ); Wait(timeout); }
CAddDevice( PCNODE_KEY node, PCDEVICE_KEY key, PCVENDOR_KEY v, PCDEVTYPE_KEY t, const char * addr, const char * init_string, __uint timeout ) { RTK_ADDR dest; node_to_host(node, &dest.host); dest.port = PORT_ALL_SERVER; ok = false; __uint size; if(!init_string){ init_string = ""; } size = strlen(addr) + 1 + strlen(init_string) + 1 + sizeof(*v) + sizeof(*t) + sizeof(*key); void *buf; buf = alloc_buffer_v( key, sizeof(*key), v, sizeof(*v), t, sizeof(*t), addr, strlen(addr) + 1, init_string, strlen(init_string)+1, 0 ); if(!buf){ return; } add_transaction(vbus_config, this); send_rtk_data_with_guid( vbus_config, &dest, &Guid, PT_AddDevice, buf, size); free_buffer(buf); Wait(timeout); }
CDiscoverGroups(PCNODE_KEY node, __uint timeout) { RTK_ADDR dest; c_items = 0; add_transaction(vbus_config, this); node_to_host(node, &dest.host); dest.port = PORT_ALL_SERVER; send_rtk_data( vbus_config, &dest, PT_DiscoverGroups, (void *)&this->Guid, sizeof(this->Guid) ); Wait(timeout); }
CDiscoverConfigFiles(PCNODE_KEY node, char * b, __uint s, __uint timeout) { RTK_ADDR dest; ok = false; bufsize = s; buf = b; *buf = '\0'; add_transaction(vbus_config, this); node_to_host(node, &dest.host); dest.port = PORT_ALL_SERVER; send_rtk_data_with_guid( vbus_config, &dest, &Guid, PT_DiscoverConfigFiles ); Wait(timeout); }
int StoreServer::dispath_cmd(const std::string &cmd, TcpConnection::Pointer conn, std::string &retmsg) { ConnData& data = conns_[conn]; int err = 0; if (cmd[POS_TYPE] == REQ_TYPE_LOGIN) { //输入密码登陆 return execute_cmd_login(cmd, conn, retmsg); } if (!data.login && config_.need_password()) { retmsg = "please enter password"; LOG_DEBUG<<"用户未登录"; return -1; } if (cmd[POS_TYPE] == REQ_TYPE_MULT) { //mult return execute_cmd_mult(cmd, conn, retmsg); } if (cmd[POS_TYPE] == REQ_TYPE_WATCH) { //watch return execute_cmd_watch(cmd, conn, retmsg); } if (cmd[POS_TYPE] == REQ_TYPE_EXEC) { //exec return execute_cmd_exec(cmd, conn, retmsg); } if (cmd[POS_TYPE] == REQ_TYPE_DISCARD) { //discard return execute_cmd_discard(cmd, conn, retmsg); } if (data.transaction.mult()) { //在输入了mult之后,get put del clear会进入这,加入事务 return add_transaction(cmd, conn, retmsg); } if (cmd[POS_TYPE] == REQ_TYPE_USE) { //切换db return execute_cmd_use(cmd, conn, retmsg); } //get put del clear err = execute_db_cmd(cmd, data.db, retmsg); return err; }
CBringupBackups(__uint timeout) { RTK_ADDR dest; char * msg = "switch primary"; dest.host = g_ThisNode->key; dest.port = PORT_ALL_SLAVE; m_bOk = false; m_bTimeout = true; add_transaction(vbus_system, this); send_rtk_data_with_guid( vbus_system, &dest, &Guid, PT_System, msg, strlen(msg) + 1 ); Wait(timeout); }
CDropTagsTransaction(__uint count, PCTAG_NAME names, __uint timeout) { void *buf; left = count; buf = alloc_buffer_v(names, sizeof(names[0])*count, 0); if(!buf) { return; } add_transaction(vbus_config, this); broadcast_rtk_data_with_guid( vbus_config, PORT_ALL_SERVER, &Guid, PT_DropTag, buf, sizeof(names[0])*count ); free_buffer(buf); Wait(timeout); }
CDelDevice( PCNODE_KEY node, PCDEVICE_KEY key, __uint timeout ) { RTK_ADDR dest; node_to_host(node, &dest.host); dest.port = PORT_ALL_SERVER; ok = false; add_transaction(vbus_config, this); send_rtk_data_with_guid( vbus_config, &dest, &Guid, PT_DelDevice, key, sizeof(*key) ); Wait(timeout); }
CAddEditGroupsTransaction( __uint count, PCNODE_KEY nodes, PCRTK_GROUP groups, __uint timeout, __bool bEdit=false ) { void *buf; left = count; m_bEdit = bEdit; /*将nodes和groups中的字符串复制给buf buf中的存储的顺序为:[nodes..groups..] */ buf = alloc_buffer_v( //librtk.dll nodes, sizeof(nodes[0])*count, groups, sizeof(groups[0])*count, 0 ); if(!buf){ return; } add_transaction(vbus_config, this);//将vbus_config强转为CRtkVBus*, 然后把this插入链表tList中 list<CTransaction*> //客户端发出的数据报,当在pmc.exe中添加一个组程序将执行到这里 broadcast_rtk_data_with_guid( vbus_config, //链表g_buses <VBUS_ID, CRtkVbus*>的一个键值对的值 PORT_ALL_SERVER, //用于赋给数据包头RTK_PACKET的成员dest.port &Guid, //链表s_lst <RTK_GUID, RTK_LIST_ENTRY>的键,在类CTransaction的构造函数中创建 bEdit? PT_EditGroup : PT_AddGroup, //用于赋给数据包头RTK_PACKET的成员packet_type buf, //将要发送的数据包内容(除了数据包头,注意data[1]) (sizeof(nodes[0]) + sizeof(groups[0]))*count //将要发送的数据包内容的大小 ); free_buffer(buf); Wait(timeout); }
CWriteTagTransaction2() { add_transaction(vbus_operation, this); }
int detach_from_network( uint64_t datapath_id, uint32_t vni, overlay_operation_completed_handler callback, void *user_data ) { debug( "Detaching a switch %#" PRIx64 " from an overlay network ( vni = %#x, callback = %p, user_data = %p ).", datapath_id, vni, callback, user_data ); char *local_address = NULL; char *broadcast_address = NULL; uint16_t local_port = 0; uint16_t broadcast_port = 0; if ( !valid_vni( vni ) ) { return OVERLAY_NETWORK_OPERATION_FAILED; } transaction_entry *entry = lookup_transaction( datapath_id, vni ); if ( entry != NULL ) { if ( entry->datapath_id == datapath_id && entry->vni == vni && entry->operation == OPERATION_DETACH ) { debug( "Same operation is in progress ( datapath_id = %#" PRIx64 ", vni = %#x, operation = %#x ).", entry->datapath_id, entry->vni, entry->operation ); return OVERLAY_NETWORK_OPERATION_IN_PROGRESS; } error( "Another operation is in progress ( datapath_id = %#" PRIx64 ", vni = %#x, operation = %#x ).", entry->datapath_id, entry->vni, entry->operation ); return OVERLAY_NETWORK_OPERATION_FAILED; } bool ret = add_transaction( datapath_id, vni, OPERATION_DETACH, callback, user_data ); if ( !ret ) { error( "Failed to add a transaction for detaching from a network " "( datapath_id = %" PRIx64 ", vni = %#x, callback = %p, user_data = %p ).", datapath_id, vni, callback, user_data ); return OVERLAY_NETWORK_OPERATION_FAILED; } ret = get_overlay_info( vni, datapath_id, &local_address, &local_port, &broadcast_address, &broadcast_port ); if ( !ret ) { error( "Failed to retrieve overlay network information ( datapath_id = %#" PRIx64 ", vni = %#x ).", datapath_id, vni ); goto error; } entry = lookup_transaction( datapath_id, vni ); if ( entry == NULL ) { error( "Failed to retrieve transaction entry ( datapath_id = %#" PRIx64 ", vni = %#x ).", datapath_id, vni ); goto error; } ret = delete_tunnel_from_tep( entry, vni, datapath_id ); if ( !ret ) { if ( entry->n_ongoing_http_requests == 0 ) { error( "Failed to delete a tunnel." ); goto error; } error( "Failed to delete a tunnel, but http request to delete a tunnel is ongoing." ); } if ( !valid_multicast_address( broadcast_address ) ) { if ( ret ) { ret = delete_tep_from_packet_reflectors( entry, vni, local_address ); if ( !ret ) { if ( entry->n_ongoing_http_requests == 0 ) { error( "Failed to delete TEP from all Packet Reflectors." ); goto error; } error( "Failed to delete TEP from some Packet Reflectors." ); } } } xfree( broadcast_address ); xfree( local_address ); debug( "A HTTP request is sent to HTTP client thread ( datapath_id = %" PRIx64 ", vni = %#x, callback = %p, user_data = %p ).", datapath_id, vni, callback, user_data ); return OVERLAY_NETWORK_OPERATION_SUCCEEDED; error: delete_transaction( datapath_id, vni ); if ( broadcast_address != NULL ) { xfree( broadcast_address ); } if ( local_address != NULL ) { xfree( local_address ); } return OVERLAY_NETWORK_OPERATION_FAILED; }