From dbda4bac05bb95026c2b4d8b7ea107c18d8aa992 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 21:17:45 +0200 Subject: [PATCH 1/7] Test --- iguana/exchanges/LP_portfolio.c | 5 ++++- iguana/exchanges/stats.c | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 8e8dc23ca..c7ada04db 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -298,7 +298,7 @@ void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP if ( (minprice= basepp->minprices[relpp->ind]) == 0. || price >= minprice ) { LP_mypriceset(&changed,relpp->symbol,basepp->symbol,newprice); - //printf("autoprice changed.%d %s/%s <- %.8f\n",changed,basepp->symbol,relpp->symbol,price); + printf("autoprice changed.%d %s/%s <- %.8f\n",changed,basepp->symbol,relpp->symbol,price); if ( changed != 0 || time(NULL) > lasttime+LP_ORDERBOOK_DURATION*.777) { lasttime = (uint32_t)time(NULL); @@ -468,7 +468,10 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) basepp = LP_priceinfofind(LP_autorefs[i].base); relpp = LP_priceinfofind(LP_autorefs[i].rel); if ( basepp != 0 && relpp != 0 ) + { + printf("check ref-autoprice %s/%s\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel); LP_autopriceset(ctx,1,basepp,relpp,0,LP_autorefs[i].refbase,LP_autorefs[i].refrel); + } } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index e3ee8a3b5..aa2067e0b 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -780,11 +780,11 @@ void stats_rpcloop(void *args) printf("error launching rpc handler on port %d\n",port); // yes, small leak per command } - if ( 0 && IAMLP != 0 && ipbits != localhostbits ) + /*if ( 0 && IAMLP != 0 && ipbits != localhostbits ) { close(bindsock); bindsock = iguana_socket(1,"0.0.0.0",port); - } //else printf("skip close and rebind\n"); + } //else printf("skip close and rebind\n");*/ } } From dfa52e84d7f8494376175d5130bfafc0f60ef5b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 21:34:08 +0200 Subject: [PATCH 2/7] Test --- iguana/exchanges/stats.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index aa2067e0b..21558ce18 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -651,7 +651,7 @@ void LP_rpc_processreq(void *_ptr) else { usleep(10000); - //printf("got.(%s) %d remains.%d of total.%d\n",jsonbuf,recvlen,remains,len); + printf("got.(%s) %d remains.%d of total.%d\n",jsonbuf,recvlen,remains,len); //retstr = iguana_rpcparse(space,size,&postflag,jsonbuf); if ( flag == 0 ) break; @@ -662,11 +662,11 @@ void LP_rpc_processreq(void *_ptr) if ( recvlen > 0 ) { jsonflag = postflag = 0; - portable_mutex_lock(&LP_commandmutex); + //portable_mutex_lock(&LP_commandmutex); retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,RPC_port); //if ( strcmp("5.9.253.195",remoteaddr) == 0 ) // printf("RPC.(%s)%s\n",jsonbuf,retstr); - portable_mutex_unlock(&LP_commandmutex); + //portable_mutex_unlock(&LP_commandmutex); if ( filetype[0] != 0 ) { static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize; From 1c541ac34d3c2daa6a440f49a2d1c326e2cda429 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 21:45:43 +0200 Subject: [PATCH 3/7] Test --- iguana/exchanges/LP_portfolio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index c7ada04db..5c94b9695 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -293,12 +293,10 @@ void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP if ( dir > 0 ) newprice = (1. / price) * (1. + margin); else newprice = (price * (1. + margin)); - - //newprice = 1. / (price * (1. - margin)); if ( (minprice= basepp->minprices[relpp->ind]) == 0. || price >= minprice ) { LP_mypriceset(&changed,relpp->symbol,basepp->symbol,newprice); - printf("autoprice changed.%d %s/%s <- %.8f\n",changed,basepp->symbol,relpp->symbol,price); + //printf("autoprice changed.%d %s/%s <- %.8f\n",changed,basepp->symbol,relpp->symbol,price); if ( changed != 0 || time(NULL) > lasttime+LP_ORDERBOOK_DURATION*.777) { lasttime = (uint32_t)time(NULL); @@ -469,8 +467,8 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) relpp = LP_priceinfofind(LP_autorefs[i].rel); if ( basepp != 0 && relpp != 0 ) { - printf("check ref-autoprice %s/%s\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel); - LP_autopriceset(ctx,1,basepp,relpp,0,LP_autorefs[i].refbase,LP_autorefs[i].refrel); + //printf("check ref-autoprice %s/%s\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel); + LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel); } } } @@ -600,6 +598,7 @@ void prices_loop(void *ctx) LP_tradebots_timeslice(ctx); if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) { + printf("prices_loop BTC not in LP_priceinfofind\n"); sleep(60); continue; } From ac1f7c6eee02268949cdca9a3ee12b76732a1f2a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 21:47:45 +0200 Subject: [PATCH 4/7] Test --- iguana/exchanges/stats.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 21558ce18..9028beaab 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -662,11 +662,9 @@ void LP_rpc_processreq(void *_ptr) if ( recvlen > 0 ) { jsonflag = postflag = 0; - //portable_mutex_lock(&LP_commandmutex); + portable_mutex_lock(&LP_commandmutex); retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,RPC_port); - //if ( strcmp("5.9.253.195",remoteaddr) == 0 ) - // printf("RPC.(%s)%s\n",jsonbuf,retstr); - //portable_mutex_unlock(&LP_commandmutex); + portable_mutex_unlock(&LP_commandmutex); if ( filetype[0] != 0 ) { static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize; From 9c44f55fa742a439d1fe58f7a113d2bd5440d4ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 22:15:45 +0200 Subject: [PATCH 5/7] Test --- iguana/exchanges/stats.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 9028beaab..02dac05a6 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -590,17 +590,17 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) uint16_t RPC_port; extern portable_mutex_t LP_commandmutex; +struct rpcrequest_info { pthread_t T; int32_t sock; uint32_t ipbits; }; void LP_rpc_processreq(void *_ptr) { - uint64_t arg64 = *(uint64_t *)_ptr; char filetype[128],content_type[128]; int32_t recvlen,flag,postflag=0,contentlen,remains,sock,numsent,jsonflag=0,hdrsize,len; - char helpname[512],remoteaddr[64],*buf,*retstr,*space,*jsonbuf; + char helpname[512],remoteaddr[64],*buf,*retstr,*space,*jsonbuf; struct rpcrequest_info *req = _ptr; uint32_t ipbits,i,size = 32*IGUANA_MAXPACKETSIZE + 512; - ipbits = (arg64 >> 32); + ipbits = req->ipbits;; expand_ipbits(remoteaddr,ipbits); - sock = (arg64 & 0xffffffff); + sock = req->sock; recvlen = flag = 0; retstr = 0; space = calloc(1,size); @@ -652,7 +652,6 @@ void LP_rpc_processreq(void *_ptr) { usleep(10000); printf("got.(%s) %d remains.%d of total.%d\n",jsonbuf,recvlen,remains,len); - //retstr = iguana_rpcparse(space,size,&postflag,jsonbuf); if ( flag == 0 ) break; } @@ -726,13 +725,15 @@ void LP_rpc_processreq(void *_ptr) } free(space); free(jsonbuf); + closesocket(sock); + free(_ptr); } extern int32_t IAMLP; void stats_rpcloop(void *args) { static uint32_t counter; - uint16_t port; int32_t sock,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; uint64_t arg64; void *arg64ptr; + uint16_t port; int32_t sock,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req; if ( (port= *(uint16_t *)args) == 0 ) port = 7779; RPC_port = port; @@ -764,19 +765,18 @@ void stats_rpcloop(void *args) continue; } memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); - arg64 = ((uint64_t)ipbits << 32) | (sock & 0xffffffff); - arg64ptr = malloc(sizeof(arg64)); - memcpy(arg64ptr,&arg64,sizeof(arg64)); - if ( 1 ) + req = calloc(1,sizeof(*req)); + req->sock = sock; + req->ipbits = ipbits; + if ( 0 ) { - LP_rpc_processreq((void *)&arg64); - free(arg64ptr); - closesocket(sock); + //LP_rpc_processreq((void *)&arg64); + //free(arg64ptr); + //closesocket(sock); } - else if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_rpc_processreq,arg64ptr) != 0 ) + else if ( OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req) != 0 ) { printf("error launching rpc handler on port %d\n",port); - // yes, small leak per command } /*if ( 0 && IAMLP != 0 && ipbits != localhostbits ) { From 9b11cc612ef18a08fed73a40f1d71b3993681e8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 22:56:47 +0200 Subject: [PATCH 6/7] Test --- crypto777/OS_portable.h | 8 ++++++++ iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_network.c | 11 ++++++++++- iguana/exchanges/stats.c | 18 +++++++++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 77e6ec5bc..6c4a3ecbc 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -143,6 +143,14 @@ typedef struct queue char name[64],initflag; } queue_t; +struct rpcrequest_info +{ + struct rpcrequest_info *next,*prev; + pthread_t T; + int32_t sock; + uint32_t ipbits; +}; + struct OS_mappedptr { char fname[512]; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index aeb6c8801..1787e300d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -81,6 +81,7 @@ struct LP_peerinfo *LP_peerinfos,*LP_mypeer; struct LP_forwardinfo *LP_forwardinfos; struct iguana_info *LP_coins; struct LP_pubkeyinfo *LP_pubkeyinfos; +struct rpcrequest_info *LP_garbage_collector; #include "LP_network.c" diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index df8eab0f6..14cae1f3a 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -267,12 +267,21 @@ int32_t LP_peerindsock(int32_t *peerindp) void queue_loop(void *arg) { - struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; + struct rpcrequest_info *req,*rtmp; struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; strcpy(queue_loop_stats.name,"queue_loop"); queue_loop_stats.threshold = 500.; while ( 1 ) { LP_millistats_update(&queue_loop_stats); + portable_mutex_lock(&LP_networkmutex); + DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) + { + DL_DELETE(LP_garbage_collector,req); + printf("garbage collect ipbits.%x\n",req->ipbits); + free(req); + } + portable_mutex_unlock(&LP_networkmutex); + nonz = 0; //printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0); n = 0; diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 02dac05a6..ab82d9f53 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -589,11 +589,12 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) } uint16_t RPC_port; -extern portable_mutex_t LP_commandmutex; -struct rpcrequest_info { pthread_t T; int32_t sock; uint32_t ipbits; }; +extern portable_mutex_t LP_commandmutex,LP_networkmutex; +extern struct rpcrequest_info *LP_garbage_collector; void LP_rpc_processreq(void *_ptr) { + static uint32_t spawned,maxspawned; char filetype[128],content_type[128]; int32_t recvlen,flag,postflag=0,contentlen,remains,sock,numsent,jsonflag=0,hdrsize,len; char helpname[512],remoteaddr[64],*buf,*retstr,*space,*jsonbuf; struct rpcrequest_info *req = _ptr; @@ -607,6 +608,14 @@ void LP_rpc_processreq(void *_ptr) jsonbuf = calloc(1,size); remains = size-1; buf = jsonbuf; + portable_mutex_lock(&LP_networkmutex); + spawned++; + portable_mutex_unlock(&LP_networkmutex); + if ( spawned > maxspawned ) + { + printf("max rpc threads spawned and alive %d <- %d\n",maxspawned,spawned); + spawned = maxspawned; + } while ( remains > 0 ) { //printf("flag.%d remains.%d recvlen.%d\n",flag,remains,recvlen); @@ -726,7 +735,10 @@ void LP_rpc_processreq(void *_ptr) free(space); free(jsonbuf); closesocket(sock); - free(_ptr); + portable_mutex_lock(&LP_networkmutex); + DL_APPEND(LP_garbage_collector,req); + spawned--; + portable_mutex_unlock(&LP_networkmutex); } extern int32_t IAMLP; From be41509919035da700e9933b1cc18107b6dea1e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 22:58:32 +0200 Subject: [PATCH 7/7] Test --- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 14cae1f3a..f36b31749 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -277,7 +277,7 @@ void queue_loop(void *arg) DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) { DL_DELETE(LP_garbage_collector,req); - printf("garbage collect ipbits.%x\n",req->ipbits); + //printf("garbage collect ipbits.%x\n",req->ipbits); free(req); } portable_mutex_unlock(&LP_networkmutex); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index ab82d9f53..4eea97b8e 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -614,7 +614,7 @@ void LP_rpc_processreq(void *_ptr) if ( spawned > maxspawned ) { printf("max rpc threads spawned and alive %d <- %d\n",maxspawned,spawned); - spawned = maxspawned; + maxspawned = spawned; } while ( remains > 0 ) {