Browse Source

Test

etomic
jl777 8 years ago
parent
commit
4e4028b643
  1. 2
      iguana/exchanges/LP_commands.c
  2. 13
      iguana/exchanges/LP_forwarding.c
  3. 10
      iguana/exchanges/LP_nativeDEX.c
  4. 6
      iguana/exchanges/LP_rpc.c

2
iguana/exchanges/LP_commands.c

@ -225,7 +225,7 @@ forwardhex(pubkey,hex)\n\
{ {
if ( strcmp(method,"register") == 0 ) 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:""); //printf("got (%s) from register\n",retstr!=0?retstr:"");
return(retstr); return(retstr);
} }

13
iguana/exchanges/LP_forwarding.c

@ -98,17 +98,18 @@ int32_t LP_pushsock_create(struct LP_forwardinfo *ptr,char *pushaddr)
} }
timeout = 1; timeout = 1;
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); 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 ) if ( ptr != 0 )
LP_hello(ptr); LP_hello(ptr);
return(pushsock); 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]; 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 ) if ( ipaddr == 0 || ipaddr[0] == 0 || is_ipaddr(ipaddr) == 0 || bits256_nonz(pubkey) == 0 )
return(clonestr("{\"error\":\"illegal ip_port or null pubkey\"}")); return(clonestr("{\"error\":\"illegal ipaddr or null pubkey\"}"));
sprintf(pushaddr,"ws://%s",ip_port); nanomsg_transportname(0,pushaddr,ipaddr,port);
char str[65]; printf("register.(%s) %s\n",pushaddr,bits256_str(str,pubkey)); char str[65]; printf("register.(%s) %s\n",pushaddr,bits256_str(str,pubkey));
if ( (ptr= LP_forwardfind(pubkey)) != 0 ) 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; 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 ) 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) HASH_ITER(hh,LP_peerinfos,peer,tmp)
{ {
//printf("register with (%s)\n",peer->ipaddr); //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); //printf("[%s] LP_register.(%s) returned.(%s)\n",pushaddr,peer->ipaddr,retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 ) if ( (retjson= cJSON_Parse(retstr)) != 0 )

10
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); 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; 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; 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); LP_myutxo_updates(pubsock,passphrase,profitmargin);
if ( lastforward < now-3600 ) if ( lastforward < now-3600 )
{ {
LP_forwarding_register(LP_mypubkey,pushaddr,10); LP_forwarding_register(LP_mypubkey,myipaddr,pushport,10);
lastforward = now; lastforward = now;
} }
} }
@ -285,7 +285,7 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso
return(nonz); 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; uint8_t r; int32_t i,n,j; cJSON *item;
if ( IAMLP != 0 ) 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 ) if ( 0 && (rand() % 100) == 0 )
printf("mainloop\n"); 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); usleep(100000);
} }
} }
@ -462,7 +462,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit
printf("couldnt get myipaddr\n"); printf("couldnt get myipaddr\n");
exit(-1); 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"));
} }

6
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; char url[512],str[65],*retstr;
if ( strncmp("tcp://",pushaddr,strlen("tcp://")) != 0 || strlen(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);
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://"));
retstr = issue_curlt(url,LP_HTTP_TIMEOUT); retstr = issue_curlt(url,LP_HTTP_TIMEOUT);
//printf("getutxo.(%s) -> (%s)\n",url,retstr!=0?retstr:""); //printf("getutxo.(%s) -> (%s)\n",url,retstr!=0?retstr:"");
return(retstr); return(retstr);

Loading…
Cancel
Save