void BlockCacheConcurrencyTest::TestBlockCache(BBlockCache *theCache, bool isMallocTest) { BList cacheList; BList nonCacheList; thread_id theThread = find_thread(NULL); // Do everything eight times to ensure the test runs long // enough to check for concurrency problems. for (int j = 0; j < 8; j++) { // Perform a series of gets, saves and frees for (int i = 0; i < numBlocksInCache / 2; i++) { GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); SaveBlock(theCache, cacheList.ItemAt(cacheList.CountItems() / 2), sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); SaveBlock(theCache, nonCacheList.ItemAt(nonCacheList.CountItems() / 2), sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); FreeBlock(cacheList.ItemAt(cacheList.CountItems() / 2), sizeOfBlocksInCache, isMallocTest, theThread, &cacheList, &nonCacheList); FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 2), sizeOfNonCacheBlocks, isMallocTest, theThread, &cacheList, &nonCacheList); } bool performFree = false; // Free or save (every other block) for all "cache sized" blocks. while (!cacheList.IsEmpty()) { if (performFree) { FreeBlock(cacheList.LastItem(), sizeOfBlocksInCache, isMallocTest, theThread, &cacheList, &nonCacheList); } else { SaveBlock(theCache, cacheList.LastItem(), sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); } performFree = !performFree; } // Free or save (every other block) for all "non-cache sized" blocks. while (!nonCacheList.IsEmpty()) { if (performFree) { FreeBlock(nonCacheList.LastItem(), sizeOfNonCacheBlocks, isMallocTest, theThread, &cacheList, &nonCacheList); } else { SaveBlock(theCache, nonCacheList.LastItem(), sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); } performFree = !performFree; } } }
void saveBlock(const char *filename, int blocknum, int windownum){ struct Tracker_Windows *window; struct WBlocks *wblock; wblock=getWBlockFromNumA( windownum, &window, blocknum ); if(wblock==NULL) return; if (filename==NULL || !strcmp(filename, "")) filename = "/tmp/block.block"; if (Save_Initialize(STRING_create(filename), "RADIUM BLOCK")==false) return; SaveWBlock(wblock); SaveBlock(wblock->block); if( ! dc.success){ handleError("Problems writing to file.\n"); } DISK_close_and_delete(dc.file); }
void RemoteMinerClient::HandleMessage(const RemoteMinerMessage &message) { json_spirit::Value tval=json_spirit::find_value(message.GetValue().get_obj(),"type"); if(tval.type()==json_spirit::int_type) { std::cout << "Got message " << tval.get_int() << " from server." << std::endl; if(tval.get_int()==RemoteMinerMessage::MESSAGE_TYPE_SERVERHELLO) { m_gotserverhello=true; tval=json_spirit::find_value(message.GetValue().get_obj(),"metahashrate"); if(tval.type()==json_spirit::int_type) { m_minerthreads.SetMetaHashSize(tval.get_int()); m_metahashsize=tval.get_int(); } tval=json_spirit::find_value(message.GetValue().get_obj(),"serverversion"); if(tval.type()==json_spirit::str_type) { std::cout << "Server version " << tval.get_str() << std::endl; } tval=json_spirit::find_value(message.GetValue().get_obj(),"distributiontype"); if(tval.type()==json_spirit::str_type) { std::cout << "Distribution type : " << tval.get_str() << std::endl; } } else if(tval.get_int()==RemoteMinerMessage::MESSAGE_TYPE_SERVERSENDWORK) { int64 nextblockid=0; std::vector<unsigned char> nextblock; std::vector<unsigned char> nextmidstate; uint256 nexttarget; tval=json_spirit::find_value(message.GetValue().get_obj(),"blockid"); if(tval.type()==json_spirit::int_type) { nextblockid=tval.get_int(); } tval=json_spirit::find_value(message.GetValue().get_obj(),"block"); if(tval.type()==json_spirit::str_type) { DecodeBase64(tval.get_str(),nextblock); } tval=json_spirit::find_value(message.GetValue().get_obj(),"target"); if(tval.type()==json_spirit::str_type) { nexttarget.SetHex(tval.get_str()); } tval=json_spirit::find_value(message.GetValue().get_obj(),"midstate"); if(tval.type()==json_spirit::str_type) { DecodeBase64(tval.get_str(),nextmidstate); } tval=json_spirit::find_value(message.GetValue().get_obj(),"fullblock"); if(tval.type()==json_spirit::obj_type) { SaveBlock(tval.get_obj(),"block.txt"); if(m_address160!=0) { double amount=0; if(FindGenerationAddressInBlock(m_address160,tval.get_obj(),amount)) { std::cout << "Address " << Hash160ToAddress(m_address160) << " will receive " << amount << " BTC if this block is solved" << std::endl; } else { std::cout << "Address " << Hash160ToAddress(m_address160) << " not found in block being solved" << std::endl; } } } m_minerthreads.SetNextBlock(nextblockid,nexttarget,nextblock,nextmidstate); } else if(tval.get_int()==RemoteMinerMessage::MESSAGE_TYPE_SERVERSTATUS) { int64 clients=0; int64 khashmeta=0; int64 khashbest=0; int64 clientkhashmeta=0; time_t startuptime=0; struct tm startuptimetm; std::string startuptimestr(""); int64 blocksgenerated=0; tval=json_spirit::find_value(message.GetValue().get_obj(),"clients"); if(tval.type()==json_spirit::int_type) { clients=tval.get_int(); } tval=json_spirit::find_value(message.GetValue().get_obj(),"khashmeta"); if(tval.type()==json_spirit::int_type) { khashmeta=tval.get_int(); } tval=json_spirit::find_value(message.GetValue().get_obj(),"khashbest"); if(tval.type()==json_spirit::int_type) { khashbest=tval.get_int(); } tval=json_spirit::find_value(message.GetValue().get_obj(),"yourkhashmeta"); if(tval.type()==json_spirit::int_type) { clientkhashmeta=tval.get_int(); } tval=json_spirit::find_value(message.GetValue().get_obj(),"sessionstartuptime"); if(tval.type()==json_spirit::int_type) { startuptime=tval.get_int(); startuptimetm=*gmtime(&startuptime); std::vector<char> buff(128,0); int rval=strftime(&buff[0],buff.size()-1,"%Y-%m-%d %H:%M:%S",&startuptimetm); buff.resize(rval); startuptimestr=std::string(buff.begin(),buff.end()); } tval=json_spirit::find_value(message.GetValue().get_obj(),"sessionblocksgenerated"); if(tval.type()==json_spirit::int_type) { blocksgenerated=tval.get_int(); } std::cout << std::endl; std::cout << GetTimeStr(time(0)) << std::endl; std::cout << "Server Status : " << clients << " clients, " << khashmeta << " khash/s" << std::endl; std::cout << blocksgenerated << " blocks generated since " << startuptimestr << " UTC" << std::endl; std::cout << "Server reports my khash/s as " << clientkhashmeta << std::endl; } } else { std::cout << "Server sent invalid message. Disconnecting." << std::endl; } }
DWORD CMime::SaveToMem(LPBYTE buf, DWORD size) {_STT(); // Anything to save? if ( Size() == 0 ) return 0; if ( m_header == NULL ) return 0; DWORD i = 0; LPMIMEBLOCK pmb = NULL; // Do they just want to know the size? if ( buf == NULL ) size = MAXDWORD; // For each block while ( i < size && ( pmb = GetNext( pmb ) ) != NULL ) { RULIB_TRY { if ( size > i ) { // Get size if ( buf == NULL ) i += SaveBlock( pmb, 0, 0 ); // Save block information to buffer else if ( i < size ) i += SaveBlock( pmb, &buf[ i ], size - i ); } // end if } // end try // Ignore bad blocks RULIB_CATCH_ALL { ASSERT( 0 ); } // Will there be another block? // If so write out the boundry // if ( pmb->pNext != NULL && m_header != NULL ) { if ( buf != NULL ) strcpy( (char*)&buf[ i ], "\r\n\r\n--" ); i += 6; if ( buf != NULL ) strcpy( (char*)&buf[ i ], m_header->boundry ); i += strlen( m_header->boundry ); // Be like Outlook if ( pmb->pNext != NULL ) { if ( buf != NULL ) strcpy( (char*)&buf[ i ], "\r\n" ); i += 2; } // end if else { if ( buf != NULL ) strcpy( (char*)&buf[ i ], "--\r\n" ); i += 4; } // end else } // end if } // end while // NULL terminate if ( buf != NULL ) { if ( i < size ) buf[ i++ ] = 0; } else i++; return i; }