diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index bdc6a5593..38d2fc3d2 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -225,7 +225,7 @@ forwardhex(pubkey,hex)\n\ { if ( strcmp(method,"register") == 0 ) { - retstr = LP_register(jbits256(argjson,"client"),jstr(argjson,"pushaddr")); + retstr = LP_register(jbits256(argjson,"client"),jstr(argjson,"pushaddr"),juint(argjson,"pushport")); //printf("got (%s) from register\n",retstr!=0?retstr:""); return(retstr); } diff --git a/iguana/exchanges/LP_forwarding.c b/iguana/exchanges/LP_forwarding.c index 63e5fb4b8..36edbf176 100644 --- a/iguana/exchanges/LP_forwarding.c +++ b/iguana/exchanges/LP_forwarding.c @@ -98,17 +98,18 @@ int32_t LP_pushsock_create(struct LP_forwardinfo *ptr,char *pushaddr) } timeout = 1; nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); if ( ptr != 0 ) LP_hello(ptr); return(pushsock); } -char *LP_register(bits256 pubkey,char *ip_port) +char *LP_register(bits256 pubkey,char *ipaddr,uint16_t port) { struct LP_forwardinfo *ptr=0; int32_t pushsock; char pushaddr[64]; - if ( ip_port == 0 || ip_port[0] == 0 || is_ipaddr(ip_port) == 0 || bits256_nonz(pubkey) == 0 ) - return(clonestr("{\"error\":\"illegal ip_port or null pubkey\"}")); - sprintf(pushaddr,"ws://%s",ip_port); + if ( ipaddr == 0 || ipaddr[0] == 0 || is_ipaddr(ipaddr) == 0 || bits256_nonz(pubkey) == 0 ) + return(clonestr("{\"error\":\"illegal ipaddr or null pubkey\"}")); + nanomsg_transportname(0,pushaddr,ipaddr,port); char str[65]; printf("register.(%s) %s\n",pushaddr,bits256_str(str,pubkey)); if ( (ptr= LP_forwardfind(pubkey)) != 0 ) { @@ -140,7 +141,7 @@ char *LP_register(bits256 pubkey,char *ip_port) } } -void LP_forwarding_register(bits256 pubkey,char *pushaddr,int32_t max) +void LP_forwarding_register(bits256 pubkey,char *pushaddr,uint16_t pushport,int32_t max) { char *retstr; cJSON *retjson; struct LP_peerinfo *peer,*tmp; int32_t n=0,retval = -1; if ( pushaddr == 0 || pushaddr[0] == 0 || bits256_nonz(pubkey) == 0 ) @@ -151,7 +152,7 @@ void LP_forwarding_register(bits256 pubkey,char *pushaddr,int32_t max) HASH_ITER(hh,LP_peerinfos,peer,tmp) { //printf("register with (%s)\n",peer->ipaddr); - if ( (retstr= issue_LP_register(peer->ipaddr,peer->port,pubkey,pushaddr)) != 0 ) + if ( (retstr= issue_LP_register(peer->ipaddr,peer->port,pubkey,pushaddr,pushport)) != 0 ) { //printf("[%s] LP_register.(%s) returned.(%s)\n",pushaddr,peer->ipaddr,retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5742b3a65..5ed772c85 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -213,7 +213,7 @@ int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pu return(n); } -int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin) +int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t pushport,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin) { static uint32_t counter,lastforward,numpeers; struct LP_utxoinfo *utxo,*utmp; char *retstr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0,n=0,lastn=-1; @@ -253,7 +253,7 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso LP_myutxo_updates(pubsock,passphrase,profitmargin); if ( lastforward < now-3600 ) { - LP_forwarding_register(LP_mypubkey,pushaddr,10); + LP_forwarding_register(LP_mypubkey,myipaddr,pushport,10); lastforward = now; } } @@ -285,7 +285,7 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso return(nonz); } -void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,char *pushaddr,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin,cJSON *coins,char *seednode) +void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,char *pushaddr,uint16_t pushport,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin,cJSON *coins,char *seednode) { uint8_t r; int32_t i,n,j; cJSON *item; if ( IAMLP != 0 ) @@ -339,7 +339,7 @@ void LP_mainloop(char *myipaddr,struct LP_peerinfo *mypeer,uint16_t mypubport,in { if ( 0 && (rand() % 100) == 0 ) printf("mainloop\n"); - if ( LP_mainloop_iter(myipaddr,mypeer,pubsock,pushaddr,pullsock,myport,passphrase,profitmargin) == 0 ) + if ( LP_mainloop_iter(myipaddr,mypeer,pubsock,pushaddr,pushport,pullsock,myport,passphrase,profitmargin) == 0 ) usleep(100000); } } @@ -462,7 +462,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit printf("couldnt get myipaddr\n"); exit(-1); } -LP_mainloop(myipaddr,mypeer,mypubport,pubsock,pushaddr,pullsock,myport,passphrase,profitmargin,jobj(argjson,"coins"),jstr(argjson,"seednode")); +LP_mainloop(myipaddr,mypeer,mypubport,pubsock,pushaddr,mypullport,pullsock,myport,passphrase,profitmargin,jobj(argjson,"coins"),jstr(argjson,"seednode")); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index c624cd7ac..89e52a64b 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -106,12 +106,10 @@ 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 *pushaddr) +char *issue_LP_register(char *destip,uint16_t destport,bits256 pubkey,char *ipaddr,uint16_t pushport) { char url[512],str[65],*retstr; - if ( strncmp("tcp://",pushaddr,strlen("tcp://")) != 0 || strlen(pushaddr) <= strlen("tcp://") ) - return(clonestr("{\"error\":\"illegal pushaddr\"}")); - sprintf(url,"http://%s:%u/api/stats/register?client=%s&pushaddr=%s",destip,destport,bits256_str(str,pubkey),pushaddr+strlen("tcp://")); + sprintf(url,"http://%s:%u/api/stats/register?client=%s&pushaddr=%s&pushport=%u",destip,destport,bits256_str(str,pubkey),ipaddr,pushport); retstr = issue_curlt(url,LP_HTTP_TIMEOUT); //printf("getutxo.(%s) -> (%s)\n",url,retstr!=0?retstr:""); return(retstr);