コード例 #1
0
ファイル: main.c プロジェクト: botvs/SuperNET
int
maingen(int argc, char** argv)
{
    uint8_t logs[256];
    uint8_t exps[255];
    unsigned int x;
    unsigned int i;
    
    x = 1;
    for( i = 0; i < 255; ++i ) {
        exps[i] = x;
        logs[x] = i;
        x <<= 1;
        if( x & 0x100 )
            x ^= 0x11d; /* Unset the 8th bit and mix in 0x1d */
    }
    logs[0] = 0; /* can't log(0) so just set it neatly to 0 */
    
    /* The above generation algorithm clearly demonstrates that
     * logs[exps[i]] == i for 0 <= i <= 254
     * exps[logs[i]] == i for 1 <= i <= 255
     */
    
    /* Spew out the tables */
    
    fprintf(stdout, "\
            /*\n\
            * This file is autogenerated by gfshare_maketable.\n\
            */\n\
            \n\
            static uint8_t logs[256] = {\n  ");
    for( i = 0; i < 256; ++i ) {
        fprintf(stdout, "0x%02x", logs[i]);
        if( i == 255 )
            fprintf(stdout, " };\n");
        else if( (i % 8) == 7 )
            fprintf(stdout, ",\n  ");
        else
            fprintf(stdout, ", ");
    }
    
    /* The exp table we output from 0 to 509 because that way when we
     * do the lagrange interpolation we don't have to be quite so strict
     * with staying inside the field which makes it quicker
     */
    
    fprintf(stdout, "\
            \n\
            static uint8_t exps[510] = {\n  ");
    for( i = 0; i < 510; ++i ) {
        fprintf(stdout, "0x%02x", exps[i % 255]); /* exps[255]==exps[0] */
        if( i == 509 )
            fprintf(stdout, " };\n");
        else if( (i % 8) == 7)
            fprintf(stdout, ",\n  ");
        else
            fprintf(stdout, ", ");
    }
    
    return 0;
}

void iguana_main(void *arg)
{
    int32_t usessl = 0, ismainnet = 1;
    struct supernet_info *myinfo; char *tmpstr,*helperargs,*coinargs,helperstr[512]; int32_t i;

    mycalloc(0,0,0);
    myinfo = SuperNET_MYINFO(0);
    FILE *fp; int32_t iter; void ztest(); ztest();
    strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7876/nxt");
    for (iter=0; iter<2; iter++)
    {
        if ( (fp= fopen(iter == 0 ? "nxtpasswords" : "fimpasswords","rb")) != 0 )
        {
            char line[4096],NXTaddr[64]; int32_t j; uint8_t pubkey[32];
            while ( fgets(line,sizeof(line),fp) > 0 )
            {
                j = (int32_t)strlen(line) - 1;
                line[j] = 0;
                calc_NXTaddr(NXTaddr,pubkey,(uint8_t *)line,j);
                printf("FORGING %s (%s)\n",NXTaddr,issue_startForging(myinfo,line));
            }
            fclose(fp);
        }
        strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:7886/nxt");
    }
    if ( usessl == 0 )
        strcpy(myinfo->NXTAPIURL,"http://127.0.0.1:");
    else strcpy(myinfo->NXTAPIURL,"https://127.0.0.1:");
    if ( ismainnet != 0 )
        strcat(myinfo->NXTAPIURL,"7876/nxt");
    else strcat(myinfo->NXTAPIURL,"6876/nxt");

    if ( 0 )
    {
#ifndef _WIN32
        signal(SIGINT,sigint_func);
        signal(SIGILL,sigillegal_func);
        signal(SIGHUP,sighangup_func);
        //signal(SIGKILL,sigkill_func);
        signal(SIGABRT,sigabort_func);
        signal(SIGQUIT,sigquit_func);
        signal(SIGCHLD,sigchild_func);
        signal(SIGALRM,sigalarm_func);
        signal(SIGCONT,sigcontinue_func);
#endif
    }
   //iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
    //iguana_chaingenesis(1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
    iguana_chaingenesis(1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC

    iguana_initQ(&helperQ,"helperQ");
    OS_ensure_directory("help");
    OS_ensure_directory("confs");
    OS_ensure_directory("DB"), OS_ensure_directory("DB/ECB");
    OS_ensure_directory("tmp");
    if ( (tmpstr= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"help\"}"),0)) != 0 )
    {
        if ( (API_json= cJSON_Parse(tmpstr)) != 0 && (API_json= jobj(API_json,"result")) != 0 )
            API_json = jobj(API_json,"API");
        free(tmpstr);
    }
    if ( IGUANA_NUMHELPERS == 0 )
        IGUANA_NUMHELPERS = 1;
    for (i=0; i<IGUANA_NUMHELPERS; i++)
    {
        sprintf(helperstr,"{\"name\":\"helper.%d\"}",i);
        helperargs = clonestr(helperstr);
        iguana_launch(iguana_coinadd("BTCD"),"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
    }
    iguana_launch(iguana_coinadd("BTCD"),"rpcloop",iguana_rpcloop,SuperNET_MYINFO(0),IGUANA_PERMTHREAD);
    category_init(&MYINFO);
    if ( (coinargs= SuperNET_keysinit(&MYINFO,arg)) != 0 )
        iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
    else if ( 1 )
    {
#ifdef __APPLE__
        sleep(1);
        char *str;
        strcpy(MYINFO.rpcsymbol,"BTC");
        iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}"));
        if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTC\",\"active\":0}"),0)) != 0 )
        {
            free(str);
            if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTCD\",\"active\":0}"),0)) != 0 )
            {
                free(str);
                if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0)) != 0 )
                {
                    free(str);
                    if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"bob\",\"password\":\"bob\",\"passphrase\":\"bob\"}"),0)) != 0 )
                        free(str);
                }
            }
        }
        sleep(1);
#endif
    }
    if ( arg != 0 )
        SuperNET_JSON(&MYINFO,cJSON_Parse(arg),0);
    mainloop(&MYINFO);
}
コード例 #2
0
ファイル: main.c プロジェクト: pfhchaos/cabrio
int main( int argc, char *arvg[] ) {
	int quit = 0;
	int config_status = 0;
	int event;

#ifdef __WIN32__
	freopen( "cabrio.out", "w", stdout );
	freopen( "cabrio.err", "w", stderr );
#endif

	config_status = config_open( NULL );
	if( config_status == -1 )
		return -1;

	if( sdl_init() != 0 )
		bail();

	if( ogl_init() != 0 )
		bail();
	
	/* Clear the screen as soon as we can. This avoids graphics
	 * glitches which can occur with some SDL implementations. */
	ogl_clear();
	sdl_swap();

	if( event_init() != 0 )
		bail();

	if( font_init() != 0 )
		bail();

	if( config_status == 1 ) {
		/* Config file didn't exist, so run the setup utility */
		if( setup() != 0 )
			return -1;
		config_update();
		if( config_create() != 0 )
			return -1;
	}

	location_init();

	/* If config or location results in a new font, it'll be loaded here. */
	font_free();
	font_init();

	/* Large game lists take a while to initialise,
	 * so show the background while we wait... */
	bg_init();
	bg_clear();
	bg_draw();
	sdl_swap();

	if( platform_init() != 0 )
		bail();

	if( category_init() != 0 )
		bail();

	if( game_sel_init() != 0 )
		bail();

	if( hint_init() != 0 )
		bail();

	if( snap_init() != 0 )
		bail();
	
	if( game_list_create() != 0 )
		bail();

	if( menu_init() != 0 )
		bail();

	if( submenu_init() != 0 )
		bail();

	sound_init();
	video_init();
	
	event_flush();

	if( !config_get()->iface.theme.menu.auto_hide )
		menu_show();
		
	focus_set( FOCUS_GAMESEL );

	while( !quit ) {
		ogl_clear();
		bg_draw();
		snap_draw();
		if (!config_get()->iface.hide_buttons)
			hint_draw();
		menu_draw();
		submenu_draw();
		game_sel_draw();
		sdl_swap();
		if (Mix_PlayingMusic() != 1 && config_get()->iface.theme_sound && reader_running == 0) 
			playmusic();
		if (( event = event_poll() )) {
			if( supress_wait == 0 ) {
				if( event == EVENT_QUIT ) {
					quit = 1;
				}
				else {
					supress();
					event_process( event );
				}
			}
		}
		if( supress_wait > 0 )
			supress_wait--;
		
		sdl_frame_delay();
	}
	clean_up();
	return 0;
}