From ee3c92f8b8ab66b3e58ee88cc3c486bf8832780f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 13:04:42 +0400 Subject: [PATCH] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 47 +++++++++++++++++---------------- iguana/exchanges/mm.c | 43 +++++++++++++++++++----------- iguana/exchanges/stats.c | 2 +- 4 files changed, 53 insertions(+), 40 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index f3fd53d92..07271aa55 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -518,6 +518,7 @@ int64_t LP_myzcredits(); void test_validate(struct iguana_info *coin,char *signedtx); void LP_instantdex_depositadd(char *coinaddr,bits256 txid); int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr); +void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid); int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fedceb60e..673b0ba66 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -135,7 +135,7 @@ uint32_t LP_rand() char *activecoins[] = { "BTC", "KMD" }; char GLOBAL_DBDIR[] = { "DB" }; -char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; +char LP_myipaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", @@ -669,7 +669,7 @@ void LP_coinsloop(void *_coins) } } -int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) +int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock) { static uint32_t counter;//,didinstantdex; struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t notarized,height,nonz = 0; @@ -849,9 +849,10 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) printf("privkey updates\n"); } -void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,char *seednode,uint16_t pushport,uint16_t subport) +void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode) { - int32_t i,j; uint32_t r; + int32_t i,j; uint32_t r; uint16_t pushport,subport,busport; + LP_ports(&pushport,&subport,&busport,netid); if ( IAMLP != 0 ) { LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,pushport,subport,1,G.LP_sessionid); @@ -1149,7 +1150,7 @@ extern int32_t bitcoind_RPC_inittime; void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) { - char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); + char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request)); bitcoind_RPC_inittime = 1; printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); @@ -1246,29 +1247,29 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu #endif if ( IAMLP != 0 ) { - pubsock = -1; + LP_mypubsock = -1; nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); valid = 0; - if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) + if ( (LP_mypubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { valid = 0; - if ( nn_bind(pubsock,bindaddr) >= 0 ) + if ( nn_bind(LP_mypubsock,bindaddr) >= 0 ) valid++; if ( valid > 0 ) { timeout = 1; - nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(LP_mypubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); } else { - printf("error binding to (%s).%d\n",subaddr,pubsock); - if ( pubsock >= 0 ) - nn_close(pubsock), pubsock = -1; + printf("error binding to (%s).%d\n",subaddr,LP_mypubsock); + if ( LP_mypubsock >= 0 ) + nn_close(LP_mypubsock), LP_mypubsock = -1; } - } else printf("error getting pubsock %d\n",pubsock); - printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,pubsock); - LP_mypubsock = pubsock; + } else printf("error getting pubsock %d\n",LP_mypubsock); + printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,LP_mypubsock); + LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); } if ( (coinsjson= jobj(argjson,"coins")) == 0 ) { @@ -1286,15 +1287,15 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("no coins object or coins.json file, must abort\n"); exit(-1); } - LP_initcoins(ctx,pubsock,coinsjson); + LP_initcoins(ctx,LP_mypubsock,coinsjson); RPC_port = myport; G.waiting = 1; - LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); - LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); - strcpy(LP_publicaddr,pushaddr); + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,juint(argjson,"netid"),jstr(argjson,"seednode")); + //LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); + //strcpy(LP_publicaddr,pushaddr); //LP_publicport = mypullport; //LP_mybussock = LP_coinbus(mybusport); - printf("got %s, initpeers. LP_mypubsock.%d/%d pullsock.%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,LP_mypullsock,myport,mypullport,mypubport,pushaddr); + printf("got %s, initpeers. LP_mypubsock.%d pullsock.%d RPC_port.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,LP_mypullsock,RPC_port,mypullport,mypubport,pushaddr); LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) @@ -1374,12 +1375,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); sleep(3); } - if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) + if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 ) nonz++; if ( didremote == 0 && LP_cmdcount > 0 ) { didremote = 1; - uint16_t myport2 = myport-1; + uint16_t myport2 = RPC_port-1; printf("start remote port\n"); if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { @@ -1450,7 +1451,7 @@ void LP_fromjs_iter() //LP_pubkeys_query(); //LP_utxosQ_process(); //LP_nanomsg_recvs(ctx); - LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock,LP_publicaddr,LP_RPCPORT); + LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock); //queue_loop(0); if ( 0 ) // 10 seconds { diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 379fb763d..db8bc57b7 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -69,11 +69,35 @@ void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveas #endif #endif + #include "LP_nativeDEX.c" +void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid) +{ + int32_t netmod,netdiv; uint16_t otherports; + *pullportp = *pubportp = *busportp = 0; + if ( netid < 0 ) + netid = 0; + else if ( netid > (65535-40-LP_RPCPORT)/4 ) + { + printf("netid.%d overflow vs max netid.%d 14420?\n",netid,(65535-40-LP_RPCPORT)/4); + exit(-1); + } + if ( netid != 0 ) + { + netmod = (netid % 10); + netdiv = (netid / 10); + otherports = (netdiv * 40) + (LP_RPCPORT + netmod); + } else otherports = LP_RPCPORT; + *pullportp = otherports + 10; + *pubportp = otherports + 20; + *busportp = otherports + 30; + printf("RPCport.%d remoteport.%d, nanoports %d %d %d\n",RPC_port,RPC_port-1,*pullportp,*pubportp,*busportp); +} + void LP_main(void *ptr) { - char *passphrase; double profitmargin; int32_t netmod,netdiv,netid=0; uint16_t port,otherports; cJSON *argjson = ptr; + char *passphrase; double profitmargin; uint16_t netid=0,port,pullport,pubport,busport; cJSON *argjson = ptr; if ( (passphrase= jstr(argjson,"passphrase")) != 0 ) { profitmargin = jdouble(argjson,"profitmargin"); @@ -82,21 +106,8 @@ void LP_main(void *ptr) port = LP_RPCPORT; if ( jobj(argjson,"netid") != 0 ) netid = juint(argjson,"netid"); - if ( netid < 0 ) - netid = 0; - else if ( netid > (65535-40-LP_RPCPORT)/4 ) - { - printf("netid.%d overflow vs max netid.%d 14420?\n",netid,(65535-40-LP_RPCPORT)/4); - exit(-1); - } - if ( netid != 0 ) - { - netmod = (netid % 10); - netdiv = (netid / 10); - otherports = (netdiv * 40) + (LP_RPCPORT + netmod); - } else otherports = LP_RPCPORT; - printf("RPCport.%d remoteport.%d, nanoports %d %d %d\n",port,port-1,otherports+10,otherports+20,otherports+30); - LPinit(port,otherports+10,otherports+20,otherports+30,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); + LP_ports(&pullport,&pubport,&busport,netid); + LPinit(port,pullport,pubport,busport,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 6625d3f75..c1fdbe2ff 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -861,7 +861,7 @@ continue; #ifndef FROM_MARKETMAKER portable_mutex_t LP_commandmutex; -uint16_t LP_RPCPORT; +uint16_t LP_RPCPORT = 7763; void stats_kvjson(FILE *logfp,int32_t height,int32_t savedheight,uint32_t timestamp,char *key,cJSON *kvjson,bits256 pubkey,bits256 sigprev) {