From 8b819f579007599a52d388cd11a5c629c018a43c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 14 Jun 2017 18:48:38 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_forwarding.c | 6 ++++-- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/mm.c | 2 +- iguana/exchanges/stats.c | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 7b1e564c5..c489ac0ce 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -231,7 +231,7 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d return(retval); } -char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port +char *stats_JSON(int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport,pushport,subport; int32_t otherpeers,othernumutxos; struct LP_peerinfo *peer; cJSON *retjson; struct iguana_info *ptr; if ( (method= jstr(argjson,"method")) == 0 ) @@ -422,7 +422,7 @@ forwardhex(pubkey,hex)\n\ else if ( strcmp(method,"lookup") == 0 ) retstr = LP_lookup(jbits256(argjson,"client")); else if ( strcmp(method,"forwardhex") == 0 ) - retstr = LP_forwardhex(jbits256(argjson,"pubkey"),jstr(argjson,"hex")); + retstr = LP_forwardhex(pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex")); else if ( strcmp(method,"notify") == 0 ) retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); else if ( strcmp(method,"notified") == 0 ) diff --git a/iguana/exchanges/LP_forwarding.c b/iguana/exchanges/LP_forwarding.c index 839756d4d..11c64e84e 100644 --- a/iguana/exchanges/LP_forwarding.c +++ b/iguana/exchanges/LP_forwarding.c @@ -123,7 +123,7 @@ cJSON *LP_dereference(cJSON *argjson,char *excludemethod) return(reqjson); } -char *LP_forwardhex(bits256 pubkey,char *hexstr) +char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr) { struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *retstr=0; cJSON *retjson,*argjson,*reqjson; if ( hexstr == 0 || hexstr[0] == 0 ) @@ -136,7 +136,9 @@ char *LP_forwardhex(bits256 pubkey,char *hexstr) if ( (argjson= cJSON_Parse((char *)data)) != 0 ) { reqjson = LP_dereference(argjson,"forward"); - retstr = LP_command_process(LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.); + if ( pubsock < 0 || bits256_cmp(pubkey,LP_mypubkey) == 0 ) + retstr = LP_command_process(LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.); + else LP_send(pubsock,jprint(reqjson,0),1); free_json(reqjson); free_json(argjson); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 57cdaaf5c..f857747e9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -84,7 +84,7 @@ char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t * char *retstr=0; if ( LP_tradecommand(myipaddr,pubsock,argjson,data,datalen,profitmargin) <= 0 ) { - if ( (retstr= stats_JSON(argjson,"127.0.0.1",0)) != 0 ) + if ( (retstr= stats_JSON(pubsock,argjson,"127.0.0.1",0)) != 0 ) { printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); if ( pubsock >= 0 ) @@ -114,7 +114,7 @@ int32_t LP_pullsock_check(char *myipaddr,int32_t pubsock,int32_t pullsock,double portable_mutex_lock(&LP_commandmutex); if ( jstr(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"forwardhex") == 0 ) { - if ( (retstr= LP_forwardhex(jbits256(argjson,"pubkey"),jstr(argjson,"hex"))) != 0 ) + if ( (retstr= LP_forwardhex(pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex"))) != 0 ) free(retstr); } else if ( jstr(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"publish") == 0 ) @@ -147,7 +147,7 @@ int32_t LP_subsock_check(struct LP_peerinfo *peer) if ( (argjson= cJSON_Parse((char *)ptr)) != 0 ) { portable_mutex_lock(&LP_commandmutex); - if ( (retstr= stats_JSON(argjson,"127.0.0.1",0)) != 0 ) + if ( (retstr= stats_JSON(-1,argjson,"127.0.0.1",0)) != 0 ) { //printf("%s SUB.[%d] %s\n",peer->ipaddr,recvsize,(char *)ptr); free(retstr); diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 6fcfda6ca..41bbd2e2e 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -24,7 +24,7 @@ #include #include "OS_portable.h" #define MAX(a,b) ((a) > (b) ? (a) : (b)) -char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port); +char *stats_JSON(int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); #include "stats.c" void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 8af29db0e..06d1cfeb7 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -489,7 +489,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( userpass != 0 && jstr(argjson,"userpass") == 0 ) jaddstr(argjson,"userpass",userpass); //printf("after urlconv.(%s) argjson.(%s)\n",jprint(json,0),jprint(argjson,0)); - if ( (retstr= stats_JSON(argjson,remoteaddr,port)) != 0 ) + if ( (retstr= stats_JSON(-1,argjson,remoteaddr,port)) != 0 ) { if ( (retitem= cJSON_Parse(retstr)) != 0 ) jaddi(retarray,retitem); @@ -512,7 +512,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po //printf("ARGJSON.(%s)\n",jprint(arg,0)); if ( userpass != 0 && jstr(arg,"userpass") == 0 ) jaddstr(arg,"userpass",userpass); - retstr = stats_JSON(arg,remoteaddr,port); + retstr = stats_JSON(-1,arg,remoteaddr,port); } free_json(argjson); free_json(json);