From 4f0446b564f1a4cdae63b297768aa6932fe2d2a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 00:28:37 +0200 Subject: [PATCH 01/14] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 45 +++++++++++++++++++++++---------- iguana/exchanges/LP_rpc.c | 8 ++++++ iguana/exchanges/LP_socket.c | 3 ++- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0e7ce20b1..843ace61b 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -255,7 +255,7 @@ struct iguana_info portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; int32_t numutxos,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; - uint32_t lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; + uint32_t electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; char symbol[16],smartaddr[64],userpass[1024],serverport[128]; // portfolio diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c461997b6..3190d9475 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -620,13 +620,6 @@ void LP_coinsloop(void *_coins) } } } - if ( time(NULL) > coin->lastunspent+30 ) - { - //printf("call electrum listunspent.%s\n",coin->symbol); - if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,coin->smartaddr,2)) != 0 ) - free_json(retjson); - coin->lastunspent = (uint32_t)time(NULL); - } while ( ep != 0 ) { if ( time(NULL) > ep->keepalive+LP_ELECTRUM_KEEPALIVE ) @@ -836,13 +829,23 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint void LP_pubkeysloop(void *ctx) { - static uint32_t lasttime; + static uint32_t lasttime; cJSON *retjson; struct iguana_info *coin,*tmp; strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop"); LP_pubkeysloop_stats.threshold = 5000.; sleep(10); while ( 1 ) { LP_millistats_update(&LP_pubkeysloop_stats); + HASH_ITER(hh,LP_coins,coin,tmp) // firstrefht,firstscanht,lastscanht + { + if ( coin->electrum != 0 && time(NULL) > coin->lastunspent+30 ) + { + //printf("call electrum listunspent.%s\n",coin->symbol); + if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,coin->smartaddr,2)) != 0 ) + free_json(retjson); + coin->lastunspent = (uint32_t)time(NULL); + } + } if ( time(NULL) > lasttime+60 ) { //printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); @@ -1179,13 +1182,27 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu usleep(1000); else if ( IAMLP == 0 ) usleep(1000); - /*if ( (rand() % 10000) == 0 ) + if ( (rand() % 10000) == 0 ) { - int32_t sock = LP_bindsock; - printf("bindsock reset test\n"); - LP_bindsock = -1; - closesocket(sock); - }*/ + char *hellostr,*retstr; cJSON *retjson; int32_t allgood,sock = LP_bindsock; + allgood = 0; + if ( (retstr= issue_hello(myport)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (hellostr= jstr(retjson,"status")) != 0 && strcmp(hellostr,"") == 0 ) + allgood = 1, printf("allgood.(%s)\n",retstr); + free_json(retjson); + } else printf("couldnt parse hello return.(%s)\n",retstr); + free(retstr); + } else printf("issue_hello NULL return\n"); + if ( allgood == 0 ) + { + printf("RPC port got stuck, kick it\n"); + LP_bindsock = -1; + closesocket(sock); + } + } } #endif } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 959000fee..535b93264 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -93,6 +93,14 @@ char *issue_LP_getprices(char *destip,uint16_t destport) //return(issue_curlt(url,LP_HTTP_TIMEOUT)); } +char *issue_hello(uint16_t port) +{ + char url[512]; + sprintf(url,"http://127.0.0.1:%u/api/stats/getprices",port); + //printf("getutxo.(%s)\n",url); + return(LP_issue_curl("hello","127.0.0.1",port,url)); +} + char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coinaddr) { char url[512],*retstr; diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 25ccc79c5..036ef0ed7 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -597,7 +597,8 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) { - //printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); + if ( electrumflag > 1 ) + printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) LP_postutxos(coin->symbol,addr), updatedflag = 1; From e744037026317ea01c559b15ede9d2b3b45282f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 00:36:07 +0200 Subject: [PATCH 02/14] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3190d9475..b54ba272f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1192,11 +1192,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu { if ( (hellostr= jstr(retjson,"status")) != 0 && strcmp(hellostr,"") == 0 ) allgood = 1, printf("allgood.(%s)\n",retstr); + else printf("strange return.(%s)\n",jprint(retjson,0)); free_json(retjson); } else printf("couldnt parse hello return.(%s)\n",retstr); free(retstr); } else printf("issue_hello NULL return\n"); - if ( allgood == 0 ) + if ( 0 && allgood == 0 ) { printf("RPC port got stuck, kick it\n"); LP_bindsock = -1; From 3dcde456c3642d3a4f7b22d73223e020b0ba35bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 00:44:24 +0200 Subject: [PATCH 03/14] Test --- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 535b93264..b76416c5a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -96,7 +96,7 @@ char *issue_LP_getprices(char *destip,uint16_t destport) char *issue_hello(uint16_t port) { char url[512]; - sprintf(url,"http://127.0.0.1:%u/api/stats/getprices",port); + sprintf(url,"http://127.0.0.1:%u/api/stats/hello",port); //printf("getutxo.(%s)\n",url); return(LP_issue_curl("hello","127.0.0.1",port,url)); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 036ef0ed7..30dd047b5 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -597,7 +597,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) { - if ( electrumflag > 1 ) + if ( 0 && electrumflag > 1 ) printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) From 37eaf4b54b9d3c8573595d3573f747de90d68617 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 00:50:21 +0200 Subject: [PATCH 04/14] Test --- iguana/exchanges/LP_nativeDEX.c | 12 +++++++++--- iguana/exchanges/stats.c | 9 +++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b54ba272f..803b1928c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1190,18 +1190,24 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (hellostr= jstr(retjson,"status")) != 0 && strcmp(hellostr,"") == 0 ) + if ( (hellostr= jstr(retjson,"status")) != 0 && strcmp(hellostr,"got hello") == 0 ) allgood = 1, printf("allgood.(%s)\n",retstr); else printf("strange return.(%s)\n",jprint(retjson,0)); free_json(retjson); } else printf("couldnt parse hello return.(%s)\n",retstr); free(retstr); } else printf("issue_hello NULL return\n"); - if ( 0 && allgood == 0 ) + if ( allgood == 0 ) { - printf("RPC port got stuck, kick it\n"); + printf("RPC port got stuck, start a new thread\n"); LP_bindsock = -1; closesocket(sock); + LP_bindsock_reset++; + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) + { + printf("error launching stats rpcloop for port.%u\n",myport); + exit(-1); + } } } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 1ebed2aec..436c0b32d 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -740,17 +740,17 @@ void LP_rpc_processreq(void *_ptr) } extern int32_t IAMLP; -int32_t LP_bindsock = -1; +int32_t LP_bindsock_reset,LP_bindsock = -1; void stats_rpcloop(void *args) { - static uint32_t counter; - uint16_t port; int32_t retval,sock; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req,*req2,*rtmp; + uint16_t port; int32_t retval,sock,initial_bindsock_reset; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits,counter=0; struct rpcrequest_info *req,*req2,*rtmp; if ( (port= *(uint16_t *)args) == 0 ) port = 7779; RPC_port = port; localhostbits = (uint32_t)calc_ipbits("127.0.0.1"); - while ( 1 ) + initial_bindsock_reset = LP_bindsock_reset; + while ( LP_bindsock_reset == initial_bindsock_reset ) { //printf("LP_bindsock.%d\n",LP_bindsock); if ( LP_bindsock < 0 ) @@ -776,6 +776,7 @@ void stats_rpcloop(void *args) req->ipbits = ipbits; LP_rpc_processreq(req); continue; + // this leads to cant open file errors if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 ) { printf("error launching rpc handler on port %d, retval.%d\n",port,retval); From 16cff05525a5ae5270884da18afba36004986c1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 00:57:41 +0200 Subject: [PATCH 05/14] Test --- iguana/exchanges/LP_nativeDEX.c | 9 +++++---- iguana/exchanges/stats.c | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 803b1928c..984d98705 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1166,7 +1166,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); } - int32_t nonz; + int32_t nonz; uint32_t lasthello = 0; while ( 1 ) { nonz = 0; @@ -1182,7 +1182,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu usleep(1000); else if ( IAMLP == 0 ) usleep(1000); - if ( (rand() % 10000) == 0 ) + if ( time(NULL) > lasthello+60 ) { char *hellostr,*retstr; cJSON *retjson; int32_t allgood,sock = LP_bindsock; allgood = 0; @@ -1191,13 +1191,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( (hellostr= jstr(retjson,"status")) != 0 && strcmp(hellostr,"got hello") == 0 ) - allgood = 1, printf("allgood.(%s)\n",retstr); + allgood = 1; else printf("strange return.(%s)\n",jprint(retjson,0)); free_json(retjson); } else printf("couldnt parse hello return.(%s)\n",retstr); free(retstr); } else printf("issue_hello NULL return\n"); - if ( allgood == 0 ) + lasthello = (uint32_t)time(NULL); + if ( 1 || allgood == 0 ) { printf("RPC port got stuck, start a new thread\n"); LP_bindsock = -1; diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 436c0b32d..3561773b9 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -796,6 +796,7 @@ continue; } } } + printf("i got killed\n"); } #ifndef FROM_MARKETMAKER From 0d869866ada72d8cd45e72b44378fda9c15cee6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:00:30 +0200 Subject: [PATCH 06/14] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_socket.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 843ace61b..444858583 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -39,7 +39,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) #define LP_AUTOTRADE_TIMEOUT 20 -#define ELECTRUM_TIMEOUT 20 +#define ELECTRUM_TIMEOUT 5 #define LP_ELECTRUM_KEEPALIVE 60 #define LP_ELECTRUM_MAXERRORS 777 #define LP_MEMPOOL_TIMEINCR 10 diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 30dd047b5..c459e725a 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -408,12 +408,12 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch sitem->expiration = timeout; sitem->DL.type = ep->stratumid++; sitem->retptrp = (void **)retjsonp;*/ - portable_mutex_lock(&ep->mutex); + //portable_mutex_lock(&ep->mutex); //queue_enqueue("sendQ",&ep->sendQ,&sitem->DL); expiration = (uint32_t)time(NULL) + timeout + 1; while ( *retjsonp == 0 && time(NULL) <= expiration ) usleep(5000); - portable_mutex_unlock(&ep->mutex); + //portable_mutex_unlock(&ep->mutex); if ( *retjsonp == 0 || jobj(*retjsonp,"error") != 0 ) { if ( ++ep->numerrors >= LP_ELECTRUM_MAXERRORS ) From c3105acf1d59f6a3dc59c7f063c0126ef79ec1bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:01:47 +0200 Subject: [PATCH 07/14] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 984d98705..f31e39421 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1198,7 +1198,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu free(retstr); } else printf("issue_hello NULL return\n"); lasthello = (uint32_t)time(NULL); - if ( 1 || allgood == 0 ) + if ( allgood == 0 ) { printf("RPC port got stuck, start a new thread\n"); LP_bindsock = -1; From bcff592f3a93b5ee17ab526fd6861f2e409378c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:16:04 +0200 Subject: [PATCH 08/14] Test --- iguana/exchanges/LP_nativeDEX.c | 6 ------ iguana/exchanges/stats.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f31e39421..394d422a2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1203,12 +1203,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("RPC port got stuck, start a new thread\n"); LP_bindsock = -1; closesocket(sock); - LP_bindsock_reset++; - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) - { - printf("error launching stats rpcloop for port.%u\n",myport); - exit(-1); - } } } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 3561773b9..896234485 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -23,6 +23,9 @@ #include #include +#include /* See NOTES */ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include #include "../../crypto777/OS_portable.h" #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define STATS_DESTDIR "/var/www/html" @@ -762,7 +765,20 @@ void stats_rpcloop(void *args) } //printf("after LP_bindsock.%d\n",LP_bindsock); clilen = sizeof(cli_addr); +#ifdef _WIN32 sock = accept(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen); +#else +#ifdef __APPLE__ + sock = accept(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen); +#else + sock = accept4(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen,SOCK_NONBLOCK); + if ( sock < 0 ) + { + usleep(50000); + continue; + } +#endif +#endif if ( sock < 0 ) { printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno)); From e4fee8e52bbfd9d6ae8baf669e60026d7d41b1fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:19:45 +0200 Subject: [PATCH 09/14] Test --- iguana/exchanges/stats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 896234485..9b6b47575 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -26,6 +26,7 @@ #include /* See NOTES */ #define _GNU_SOURCE /* See feature_test_macros(7) */ #include +int32_t accept4(int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size, int flags); #include "../../crypto777/OS_portable.h" #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define STATS_DESTDIR "/var/www/html" @@ -747,7 +748,7 @@ int32_t LP_bindsock_reset,LP_bindsock = -1; void stats_rpcloop(void *args) { - uint16_t port; int32_t retval,sock,initial_bindsock_reset; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits,counter=0; struct rpcrequest_info *req,*req2,*rtmp; + uint16_t port; int32_t retval,sock,initial_bindsock_reset; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req,*req2,*rtmp; if ( (port= *(uint16_t *)args) == 0 ) port = 7779; RPC_port = port; @@ -760,7 +761,7 @@ void stats_rpcloop(void *args) { while ( (LP_bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 ) usleep(10000); - if ( counter++ < 1 ) + //if ( counter++ < 1 ) printf(">>>>>>>>>> DEX stats 127.0.0.1:%d bind sock.%d DEX stats API enabled <<<<<<<<<\n",port,LP_bindsock); } //printf("after LP_bindsock.%d\n",LP_bindsock); @@ -774,6 +775,7 @@ void stats_rpcloop(void *args) sock = accept4(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen,SOCK_NONBLOCK); if ( sock < 0 ) { + fprintf(stderr,"."); usleep(50000); continue; } From 807e83acf2af6b616907b0f4d0e1bf2d007dc70e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:29:44 +0200 Subject: [PATCH 10/14] Test --- iguana/exchanges/stats.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 9b6b47575..1a73926f8 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -23,10 +23,6 @@ #include #include -#include /* See NOTES */ -#define _GNU_SOURCE /* See feature_test_macros(7) */ -#include -int32_t accept4(int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size, int flags); #include "../../crypto777/OS_portable.h" #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define STATS_DESTDIR "/var/www/html" @@ -761,26 +757,23 @@ void stats_rpcloop(void *args) { while ( (LP_bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 ) usleep(10000); +#ifndef _WIN32 + fcntl(LP_bindsock, F_SETFL, fcntl(LP_bindsock, F_GETFL, 0) | O_NONBLOCK); +#endif //if ( counter++ < 1 ) printf(">>>>>>>>>> DEX stats 127.0.0.1:%d bind sock.%d DEX stats API enabled <<<<<<<<<\n",port,LP_bindsock); } //printf("after LP_bindsock.%d\n",LP_bindsock); clilen = sizeof(cli_addr); -#ifdef _WIN32 - sock = accept(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen); -#else -#ifdef __APPLE__ sock = accept(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen); -#else - sock = accept4(LP_bindsock,(struct sockaddr *)&cli_addr,&clilen,SOCK_NONBLOCK); +#ifdef _WIN32 if ( sock < 0 ) { fprintf(stderr,"."); usleep(50000); continue; } -#endif -#endif +#else if ( sock < 0 ) { printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno)); @@ -788,6 +781,7 @@ void stats_rpcloop(void *args) LP_bindsock = -1; continue; } +#endif memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); req = calloc(1,sizeof(*req)); req->sock = sock; From 009f69ecf673593208b29a6039dbfaf99ac373d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:32:58 +0200 Subject: [PATCH 11/14] Test --- iguana/exchanges/stats.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 1a73926f8..c7edbfeda 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -769,16 +769,16 @@ void stats_rpcloop(void *args) #ifdef _WIN32 if ( sock < 0 ) { - fprintf(stderr,"."); - usleep(50000); + printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno)); + closesocket(LP_bindsock); + LP_bindsock = -1; continue; } #else if ( sock < 0 ) { - printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno)); - closesocket(LP_bindsock); - LP_bindsock = -1; + fprintf(stderr,"."); + usleep(50000); continue; } #endif From 2a05b019c2da1bfeb6571f675d6a9f73e4ed098e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:35:26 +0200 Subject: [PATCH 12/14] Test --- iguana/exchanges/stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index c7edbfeda..3b5c53248 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -777,7 +777,7 @@ void stats_rpcloop(void *args) #else if ( sock < 0 ) { - fprintf(stderr,"."); + //fprintf(stderr,"."); usleep(50000); continue; } From 0f8ad4504f04f2300a50c729c6f3df6babdd651c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:38:27 +0200 Subject: [PATCH 13/14] Test --- iguana/exchanges/stats.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 3b5c53248..872f7b332 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -778,7 +778,9 @@ void stats_rpcloop(void *args) if ( sock < 0 ) { //fprintf(stderr,"."); - usleep(50000); + if ( IAMLP == 0 ) + usleep(50000); + else usleep(2500); continue; } #endif From 6e93ea1e4100ad1ad9bd654c9cb3491eb14eba4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Nov 2017 01:47:34 +0200 Subject: [PATCH 14/14] Test --- iguana/exchanges/LP_nativeDEX.c | 6 ++---- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 394d422a2..27c15480b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -18,11 +18,9 @@ // LP_nativeDEX.c // marketmaker // -// selftest and fix rpc port -// verify portfolio, interest to KMD withdraw +// BCH signing // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs -// BCH signing #include struct LP_millistats @@ -1200,7 +1198,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu lasthello = (uint32_t)time(NULL); if ( allgood == 0 ) { - printf("RPC port got stuck, start a new thread\n"); + printf("RPC port got stuck, close bindsocket\n"); LP_bindsock = -1; closesocket(sock); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b76416c5a..343106e90 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -98,7 +98,7 @@ char *issue_hello(uint16_t port) char url[512]; sprintf(url,"http://127.0.0.1:%u/api/stats/hello",port); //printf("getutxo.(%s)\n",url); - return(LP_issue_curl("hello","127.0.0.1",port,url)); + return(issue_curlt(url,60)); // might be starting a trade } char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coinaddr)