char *init_NXTservices(char *JSON_or_fname,char *myipaddr) { static int32_t zero,one = 1; struct coin_info *cp; struct NXThandler_info *mp = Global_mp; // seems safest place to have main data structure if ( Debuglevel > 0 ) printf("init_NXTservices.(%s)\n",myipaddr); UV_loop = uv_default_loop(); myipaddr = init_MGWconf(JSON_or_fname,myipaddr); mp->udp = start_libuv_udpserver(4,SUPERNET_PORT,on_udprecv); if ( (cp= get_coin_info("BTCD")) != 0 && cp->bridgeport != 0 ) cp->bridgeudp = start_libuv_udpserver(4,cp->bridgeport,on_bridgerecv); if ( 0 ) { uint32_t before,after; int32_t numinputs; char *rawtx = clonestr("0100000074fc77540156a5b19aaada0496780b1fbce72f7647da5f940883da7ee5d5774f673c6703c401000000fdfd0000483045022100f0b26a43136af6c28d381f461a9fcd30309788456cb81784dbc68ee85ae4151d022036fc96c4edd7b87e762bb139d5d34838a88054c37173236236f72940b2e5309801473044022068ae115a397d9a6f462b78416d58582736fa38ecc4eab2c26759e1e58d6326bc02204e148ab84d49b0f1c8aab1033819ad90c536c604ce24dab419013a5914d39d8a014c695221035827b3c432eb5a528a21657d36a1b61dd85078a6ba5f328bed2d928c173a46c421024ae5e013fda966cf8544025534012156f84a40a5672a894c42e144b0664202502102acdb9c782d499de9b98e8b166fc22bd68895e2293cb49e4a2e071f1254d1a7aa53aeffffffff0340420f00000000001976a9148466f34f39c23547abf922d422e3e5322fdf156588ac20cd8800020000001976a914cd073e0a5d4225f2577113400c3abf9ac1ad2cc488ac60c791e50600000017a914194a1499c343beefe3127e041f480ee4aef058408700000000"); before = extract_sequenceid(&numinputs,get_coin_info("BTCD"),rawtx,0); replace_bitcoin_sequenceid(get_coin_info("BTCD"),rawtx,12345678); after = extract_sequenceid(&numinputs,get_coin_info("BTCD"),rawtx,0); printf("newtx.(%s) before.%u after.%u\n",rawtx,before,after); getchar(); } if ( myipaddr != 0 ) strcpy(mp->ipaddr,myipaddr); //#ifndef __APPLE__ // Coinloop(0); //#else if ( IS_LIBTEST > 1 && portable_thread_create((void *)Coinloop,0) == 0 ) printf("ERROR hist Coinloop SSL\n"); //#endif Finished_loading = 1; if ( Debuglevel > 0 ) printf("run_UVloop\n"); if ( portable_thread_create((void *)run_UVloop,Global_mp) == 0 ) printf("ERROR hist process_hashtablequeues\n"); if ( portable_thread_create((void *)run_libwebsockets,&one) == 0 ) printf("ERROR hist run_libwebsockets SSL\n"); while ( SSL_done == 0 ) usleep(100000); if ( portable_thread_create((void *)run_libwebsockets,&zero) == 0 ) printf("ERROR hist run_libwebsockets\n"); sleep(3); { struct coin_info *cp; while ( (cp= get_coin_info("BTCD")) == 0 ) sleep(1); parse_ipaddr(cp->myipaddr,myipaddr); bind_NXT_ipaddr(cp->srvpubnxtbits,myipaddr); } return(myipaddr); }
void *_launch_SuperNET(void *_myip) { char *myip = _myip; FILE *fp; char cmd[128]; int32_t retval; void *processptr = 0; system("rm horrible.hack"); sprintf(cmd,"./SuperNET %s &",myip); if ( system(cmd) != 0 ) printf("error launching (%s)\n",cmd); while ( (fp= fopen("horrible.hack","rb")) == 0 ) sleep(1); if ( fread(&retval,1,sizeof(retval),fp) != sizeof(retval) ) retval = -2; fclose(fp); switch ( retval ) { case 0: printf("SuperNET file found!\n"); break; case -1: printf("SuperNET file NOT found. It must be in the same directory as SuperNET\n"); break; case -2: printf("handshake file error\n"); break; } if ( retval == 0 ) { processptr = portable_thread_create(poll_for_broadcasts,0); did_SuperNET_init = 1; } SuperNET_retval = retval; return(processptr); }
void init_lws(void *core,void *p2p,void *rpc_server,void *upnp,char *secret) { static void *ptrs[5]; if ( strcmp(secret,"exchanges") == 0 ) { init_pNXT(0,0,0,0,secret); exit(0); } curl_global_init(CURL_GLOBAL_ALL); //init the curl session ptrs[0] = core; ptrs[1] = p2p; ptrs[2] = rpc_server; ptrs[3] = upnp; ptrs[4] = (void *)secret; printf("init_lws(%p %p %p %p)\n",core,p2p,rpc_server,upnp); if ( portable_thread_create(_init_lws2,secret) == 0 ) printf("ERROR launching _init_lws2\n"); printf("done init_lws2()\n"); if ( portable_thread_create(_init_lws,ptrs) == 0 ) printf("ERROR launching _init_lws\n"); printf("done init_lws()\n"); }
void *init_SuperNET_globals() { struct NXT_str *tp = 0; Global_mp = calloc(1,sizeof(*Global_mp)); curl_global_init(CURL_GLOBAL_ALL); //init the curl session if ( Global_pNXT == 0 ) { Global_pNXT = calloc(1,sizeof(*Global_pNXT)); orderbook_txids = hashtable_create("orderbook_txids",HASHTABLES_STARTSIZE,sizeof(struct NXT_str),((long)&tp->U.txid[0] - (long)tp),sizeof(tp->U.txid),((long)&tp->modified - (long)tp)); Global_pNXT->orderbook_txidsp = &orderbook_txids; Global_pNXT->msg_txids = hashtable_create("msg_txids",HASHTABLES_STARTSIZE,sizeof(struct NXT_str),((long)&tp->U.txid[0] - (long)tp),sizeof(tp->U.txid),((long)&tp->modified - (long)tp)); } portable_mutex_init(&Global_mp->hash_mutex); portable_mutex_init(&Global_mp->hashtable_queue[0].mutex); portable_mutex_init(&Global_mp->hashtable_queue[1].mutex); init_NXThashtables(Global_mp); Global_mp->upollseconds = 333333 * 0; Global_mp->pollseconds = POLL_SECONDS; if ( portable_thread_create((void *)process_hashtablequeues,Global_mp) == 0 ) printf("ERROR hist process_hashtablequeues\n"); return(Global_mp); }
void init_exchanges(cJSON *json) { cJSON *array; int32_t i,n; for (FIRST_EXTERNAL=0; FIRST_EXTERNAL<sizeof(Supported_exchanges)/sizeof(*Supported_exchanges); FIRST_EXTERNAL++) { find_exchange(0,Supported_exchanges[FIRST_EXTERNAL]); if ( strcmp(Supported_exchanges[FIRST_EXTERNAL],"peggy") == 0 ) { FIRST_EXTERNAL++; break; } } for (i=FIRST_EXTERNAL; i<sizeof(Supported_exchanges)/sizeof(*Supported_exchanges); i++) find_exchange(0,Supported_exchanges[i]); prices777_initpair(-1,0,0,0,0,0.,0,0,0,0); if ( (array= jarray(&n,json,"baskets")) != 0 ) { for (i=0; i<n; i++) prices777_makebasket(0,jitem(array,i),1,"basket",0,0); } void prices777_basketsloop(void *ptr); portable_thread_create((void *)prices777_basketsloop,0); //prices777_makebasket("{\"name\":\"NXT/BTC\",\"base\":\"NXT\",\"rel\":\"BTC\",\"basket\":[{\"exchange\":\"bittrex\"},{\"exchange\":\"poloniex\"},{\"exchange\":\"btc38\"}]}",0); }
int32_t PLUGNAME(_process_json)(char *forwarder,char *sender,int32_t valid,struct plugin_info *plugin,uint64_t tag,char *retbuf,int32_t maxlen,char *origjsonstr,cJSON *origjson,int32_t initflag,char *tokenstr) { char *resultstr,*retstr = 0,*methodstr,*jsonstr,*destplugin,*submethod; struct destbuf tagstr,endpoint; cJSON *retjson,*json,*tokenobj; uint32_t nonce; struct applicant_info apply; retbuf[0] = 0; if ( tokenstr == 0 ) tokenstr = ""; if ( is_cJSON_Array(origjson) != 0 && cJSON_GetArraySize(origjson) == 2 ) json = cJSON_GetArrayItem(origjson,0), jsonstr = cJSON_Print(json), _stripwhite(jsonstr,' '); else json = origjson, jsonstr = origjsonstr; if ( Debuglevel > 2 ) printf("<<<<<<<<<<<< INSIDE relays PLUGIN! process %s [(%s).(%s)]\n",plugin->name,jsonstr,tokenstr); if ( initflag > 0 ) { // configure settings RELAYS.readyflag = 1; plugin->allowremote = 1; strcpy(retbuf,"{\"result\":\"initflag > 0\"}"); } else { if ( plugin_result(retbuf,json,tag) > 0 ) return((int32_t)strlen(retbuf)); resultstr = cJSON_str(cJSON_GetObjectItem(json,"result")); methodstr = cJSON_str(cJSON_GetObjectItem(json,"method")); destplugin = cJSON_str(cJSON_GetObjectItem(json,"destplugin")); submethod = cJSON_str(cJSON_GetObjectItem(json,"submethod")); if ( methodstr == 0 || methodstr[0] == 0 ) { printf("(%s) has not method\n",jsonstr); return(0); } //fprintf(stderr,"RELAYS methodstr.(%s) (%s)\n",methodstr,jsonstr); if ( resultstr != 0 && strcmp(resultstr,"registered") == 0 ) { plugin->registered = 1; strcpy(retbuf,"{\"result\":\"activated\"}"); } #ifdef INSIDE_MGW else if ( strcmp(methodstr,"msigaddr") == 0 ) { char *devMGW_command(char *jsonstr,cJSON *json); if ( SUPERNET.gatewayid >= 0 ) retstr = devMGW_command(jsonstr,json); } #endif else { strcpy(retbuf,"{\"result\":\"relay command under construction\"}"); if ( strcmp(methodstr,"list") == 0 ) retstr = relays_jsonstr(jsonstr,json); else if ( strcmp(methodstr,"telepathy") == 0 ) { sprintf(retbuf,"%s",jsonstr); } else if ( strcmp(methodstr,"busdata") == 0 ) { retstr = busdata_sync(&nonce,jsonstr,cJSON_str(cJSON_GetObjectItem(json,"broadcast")),0); // {"plugin":"relay","method":"busdata","destplugin":"relay","submethod":"join","broadcast":"join","endpoint":""} } else if ( strcmp(methodstr,"allservices") == 0 ) { if ( (retjson= serviceprovider_json()) != 0 ) { retstr = cJSON_Print(retjson), _stripwhite(retstr,' '); free_json(retjson); //printf("got.(%s)\n",retstr); } else printf("null serviceprovider_json()\n"); } else if ( strcmp(methodstr,"protocol") == 0 || strcmp(methodstr,"allprotocols") == 0 ) { if ( strcmp(methodstr,"protocol") == 0 && valid > 0 ) protocols_register(sender,jstr(json,"protocol"),jstr(json,"endpoint"),jint(json,"disconnect")); if ( (retjson= protocols_json(jstr(json,"protocol"))) != 0 ) { retstr = cJSON_Print(retjson), _stripwhite(retstr,' '); free_json(retjson); } else printf("null protocols_json()\n"); } else if ( strcmp(methodstr,"join") == 0 ) { if ( SUPERNET.noncing == 0 ) { copy_cJSON(&tagstr,cJSON_GetObjectItem(json,"tag")); copy_cJSON(&endpoint,cJSON_GetObjectItem(json,"endpoint")); SUPERNET.noncing = 1; if ( SUPERNET.iamrelay != 0 ) { portable_thread_create((void *)calc_nonces,clonestr(endpoint.buf)); sprintf(retbuf,"{\"result\":\"noncing\",\"endpoint\":\"%s\"}",endpoint.buf); } //fprintf(stderr,"join or nonce.(%s)\n",retbuf); } } else if ( strcmp(methodstr,"nonce") == 0 ) { struct destbuf endpoint,sender,destpoint,relaypoint,globalpoint,noncestr; memset(&apply,0,sizeof(apply)); copy_cJSON(&destpoint,cJSON_GetObjectItem(json,"destpoint")); copy_cJSON(&endpoint,cJSON_GetObjectItem(json,"lbendpoint")); copy_cJSON(&relaypoint,cJSON_GetObjectItem(json,"relaypoint")); copy_cJSON(&globalpoint,cJSON_GetObjectItem(json,"globalpoint")); copy_cJSON(&sender,cJSON_GetObjectItem(json,"NXT")); if ( SUPERNET.noncing != 0 && strcmp(SUPERNET.lbendpoint,destpoint.buf) == 0 ) { if ( endpoint.buf[0] != 0 && tokenstr[0] != 0 && (tokenobj= cJSON_Parse(tokenstr)) != 0 ) { strcpy(apply.lbendpoint,endpoint.buf); strcpy(apply.relayendpoint,relaypoint.buf); strcpy(apply.globalendpoint,globalpoint.buf); apply.senderbits = calc_nxt64bits(sender.buf); copy_cJSON(&noncestr,cJSON_GetObjectItem(tokenobj,"nonce")); if ( noncestr.buf[0] != 0 ) apply.nonce = (uint32_t)calc_nxt64bits(noncestr.buf); //printf("tokenobj.(%s) -> nonce.%u\n",tokenstr,apply.nonce); free_json(tokenobj); recv_nonces(&apply); } } } } } return(plugin_copyretstr(retbuf,maxlen,retstr)); }
int32_t launch_SuperNET(char *myip) { void *processptr; processptr = portable_thread_create(_launch_SuperNET,myip); return(0); }