From 3f7f0a5a36322bde252d83244e2ae7f20340bbad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 4 Jul 2017 20:11:16 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_forwarding.c | 20 +++++++++++++++++--- iguana/exchanges/LP_rpc.c | 4 ++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e438838e7..465a0852f 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -264,7 +264,7 @@ forwardhex(pubkey,hex)\n\ if ( strcmp(method,"register") == 0 ) { retstr = LP_register(jbits256(argjson,"client"),jstr(argjson,"pushaddr"),juint(argjson,"pushport")); - printf("got (%s) from register\n",retstr!=0?retstr:""); + //printf("got (%s) from register\n",retstr!=0?retstr:""); return(retstr); } else if ( strcmp(method,"lookup") == 0 ) diff --git a/iguana/exchanges/LP_forwarding.c b/iguana/exchanges/LP_forwarding.c index 66dd213fd..e1838ed03 100644 --- a/iguana/exchanges/LP_forwarding.c +++ b/iguana/exchanges/LP_forwarding.c @@ -151,7 +151,7 @@ char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port) int32_t LP_forwarding_register(bits256 pubkey,char *publicaddr,uint16_t publicport,int32_t max) { - char *retstr,ipaddr[64]; cJSON *retjson; struct LP_peerinfo *peer,*tmp; int32_t j,n=0,retval = -1; + char *argstr,ipaddr[64]; cJSON *argjson; struct LP_peerinfo *peer,*tmp; int32_t j,n=0,arglen; if ( publicaddr == 0 || publicaddr[0] == 0 || bits256_nonz(pubkey) == 0 ) { char str[65]; printf("LP_forwarding_register illegal publicaddr.(%s):%u or null pubkey (%s)\n",publicaddr,publicport,bits256_str(str,pubkey)); @@ -161,10 +161,23 @@ int32_t LP_forwarding_register(bits256 pubkey,char *publicaddr,uint16_t publicpo if ( publicaddr[j] >= '0' && publicaddr[j] <= '9' ) break; parse_ipaddr(ipaddr,publicaddr+j); + argjson = cJSON_CreateObject(); + jaddstr(argjson,"agent","stats"); + jaddstr(argjson,"method","register"); + jaddbits256(argjson,"client",pubkey); + jaddstr(argjson,"pushaddr",ipaddr); + jaddnum(argjson,"pushport",publicport); + argstr = jprint(argjson,1); + arglen = (int32_t)strlen(argstr) + 1; HASH_ITER(hh,LP_peerinfos,peer,tmp) { + if ( peer->pushsock >= 0 ) + { + LP_send(peer->pushsock,argstr,arglen,0); + n++; + } //printf("register.(%s) %s %u with (%s)\n",publicaddr,ipaddr,publicport,peer->ipaddr); - if ( (retstr= issue_LP_register(peer->ipaddr,peer->port,pubkey,ipaddr,publicport)) != 0 ) + /*if ( (retstr= issue_LP_register(peer->ipaddr,peer->port,pubkey,ipaddr,publicport)) != 0 ) { //printf("[%s] LP_register.(%s) returned.(%s)\n",publicaddr,peer->ipaddr,retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) @@ -176,8 +189,9 @@ int32_t LP_forwarding_register(bits256 pubkey,char *publicaddr,uint16_t publicpo free(retstr); } else printf("timeout registering with %s errs.%d good.%d\n",peer->ipaddr,peer->errors,peer->good); if ( retval == 0 ) - break; + break;*/ } + free(argstr); return(n); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index a3d0b7523..89e97f8f3 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -115,7 +115,7 @@ char *issue_LP_notifyutxo(char *destip,uint16_t destport,struct LP_utxoinfo *utx } } -char *issue_LP_register(char *destip,uint16_t destport,bits256 pubkey,char *ipaddr,uint16_t pushport) +/*char *issue_LP_register(char *destip,uint16_t destport,bits256 pubkey,char *ipaddr,uint16_t pushport) { char url[512],str[65],*retstr; sprintf(url,"http://%s:%u/api/stats/register?client=%s&pushaddr=%s&pushport=%u",destip,destport,bits256_str(str,pubkey),ipaddr,pushport); @@ -123,7 +123,7 @@ char *issue_LP_register(char *destip,uint16_t destport,bits256 pubkey,char *ipad retstr = issue_curlt(url,LP_HTTP_TIMEOUT); //printf("register.(%s) -> (%s)\n",url,retstr!=0?retstr:""); return(retstr); -} +}*/ char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired) {