コード例 #1
0
ファイル: main.c プロジェクト: botvs/SuperNET
char *iguana_JSON(char *jsonstr)
{
    char *retstr=0; cJSON *json;
    if ( (json= cJSON_Parse(jsonstr)) != 0 )
    {
        retstr = SuperNET_JSON(0,json,"127.0.0.1");
        free_json(json);
    }
    if ( retstr == 0 )
        retstr = clonestr("{\"error\":\"cant parse jsonstr from pnacl\"}");
    return(retstr);
}
コード例 #2
0
ファイル: handlers.c プロジェクト: jonesnxt/SuperNET_API
int HandleSuperNET(struct PP_Var params,struct PP_Var *output,const char **out_error)
{
    char *SuperNET_JSON(char *);
    char *retstr;
    //PostMessage("inside handle SuperNET\n");
    CHECK_PARAM_COUNT(SuperNET, 1);
    PARAM_STRING(0,jsonstr);
    retstr = SuperNET_JSON(jsonstr);
    CREATE_RESPONSE(SuperNET);
    //RESPONSE_INT(0);
    RESPONSE_STRING(retstr);
    return 0;
}
コード例 #3
0
ファイル: console777.c プロジェクト: apitests/libjl777
void process_userinput(char *_line)
{
    static char *line,*line2,*match = "./BitcoinDarkd SuperNET '";
    char plugin[512],ipaddr[1024],method[512],*cmdstr,*retstr; cJSON *json; int len,timeout,broadcastflag = 0;
    len = (int32_t)strlen(match);
    if ( _line[strlen(_line)-1] == '\'' && strncmp(_line,match,len) == 0 )
    {
        _line[strlen(_line)-1] = 0;
        _line += len;
    }
    if ( (json= cJSON_Parse(_line)) != 0 )
    {
        char *process_nn_message(int32_t sock,char *jsonstr);
        free_json(json);
        char *SuperNET_JSON(char *jsonstr);
        retstr = SuperNET_JSON(_line);
        //retstr = process_nn_message(-1,line);
        //retstr = nn_loadbalanced((uint8_t *)line,(int32_t)strlen(line)+1);
        fprintf(stderr,"console.(%s) -> (%s)\n",_line,retstr);
        return;
    } else printf("cant parse.(%s)\n",line);
    printf("[%s]\n",_line);
    if ( line == 0 )
        line = calloc(1,65536), line2 = calloc(1,65536);
    expand_aliases(line,line2,65536,_line);
    if ( (line= localcommand(line)) == 0 )
        return;
    if ( line[0] == '!' )
        broadcastflag = 1, line++;
    settoken(ipaddr,line);
    printf("expands to: %s [%s] %s\n",broadcastflag != 0 ? "broadcast": "",line,ipaddr);
    if ( is_ipaddr(ipaddr) != 0 )
    {
        line += strlen(ipaddr) + 1;
        if ( (cmdstr = parse_expandedline(plugin,sizeof(plugin),method,&timeout,line,broadcastflag)) != 0 )
        {
            printf("ipaddr.(%s) (%s)\n",ipaddr,line);
            //retstr = nn_direct(ipaddr,(uint8_t *)line,(int32_t)strlen(line)+1);
            printf("deprecated (%s) -> (%s)\n",line,cmdstr);
            free(cmdstr);
        }
        return;
    }
    if ( (cmdstr= parse_expandedline(plugin,sizeof(plugin),method,&timeout,line,broadcastflag)) != 0 )
    {
        retstr = process_user_json(plugin,method,cmdstr,broadcastflag,timeout != 0 ? timeout : SUPERNET.PLUGINTIMEOUT);
        printf("CONSOLE (%s) -> (%s) -> (%s)\n",line,cmdstr,retstr);
        free(cmdstr);
    }
}
コード例 #4
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);
}