Browse Source

Test

etomic
jl777 8 years ago
parent
commit
c28f94520a
  1. 21
      iguana/exchanges/LP_nativeDEX.c
  2. 3
      iguana/exchanges/LP_rpc.c
  3. 9
      iguana/exchanges/LP_utxos.c

21
iguana/exchanges/LP_nativeDEX.c

@ -198,9 +198,9 @@ void LP_myutxo_updates(int32_t pubsock,char *passphrase,double profitmargin)
LP_privkey_updates(pubsock,passphrase,0); LP_privkey_updates(pubsock,passphrase,0);
} }
void LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,double profitmargin,int32_t interval) int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,double profitmargin,int32_t interval)
{ {
int32_t lastn; int32_t lastn,n = -1;
if ( peer->lastutxos < now-interval ) if ( peer->lastutxos < now-interval )
{ {
//lastn = peer->numutxos - mypeer->numutxos + LP_PROPAGATION_SLACK; //lastn = peer->numutxos - mypeer->numutxos + LP_PROPAGATION_SLACK;
@ -210,25 +210,24 @@ void LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubso
{ {
peer->lastutxos = now; peer->lastutxos = now;
printf("query utxos from %s\n",peer->ipaddr); printf("query utxos from %s\n",peer->ipaddr);
LP_utxosquery(mypeer,pubsock,peer->ipaddr,peer->port,"",lastn,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,profitmargin); n = LP_utxosquery(mypeer,pubsock,peer->ipaddr,peer->port,"",lastn,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,profitmargin);
} }
} //else printf("LP_peer_utxosquery skip.(%s) %u\n",peer->ipaddr,peer->lastutxos); } //else printf("LP_peer_utxosquery skip.(%s) %u\n",peer->ipaddr,peer->lastutxos);
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,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; struct LP_utxoinfo *utxo,*utmp; char *retstr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0,n=0,lastn=-1;
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
if ( mypeer == 0 ) if ( mypeer == 0 )
myipaddr = "127.0.0.1"; myipaddr = "127.0.0.1";
printf("start peers updates\n");
numpeers = 0; numpeers = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp) HASH_ITER(hh,LP_peerinfos,peer,tmp)
{ {
numpeers++; numpeers++;
} }
printf("counter.%d numpeers %d\n",counter,numpeers);
HASH_ITER(hh,LP_peerinfos,peer,tmp) HASH_ITER(hh,LP_peerinfos,peer,tmp)
{ {
if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) ) if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) )
@ -242,13 +241,15 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso
} }
if ( peer->diduquery == 0 ) if ( peer->diduquery == 0 )
{ {
printf("do initial queries\n"); if ( lastn != n || n < 20 )
LP_peer_utxosquery(mypeer,myport,pubsock,peer,now,profitmargin,60); {
lastn = n;
n = LP_peer_utxosquery(mypeer,myport,pubsock,peer,now,profitmargin,60);
}
LP_peer_pricesquery(peer->ipaddr,peer->port); LP_peer_pricesquery(peer->ipaddr,peer->port);
peer->diduquery = now; peer->diduquery = now;
} }
} }
printf("counter.%d numpeers %d\n",counter,numpeers);
if ( (counter % 600) == 60 ) if ( (counter % 600) == 60 )
{ {
LP_myutxo_updates(pubsock,passphrase,profitmargin); LP_myutxo_updates(pubsock,passphrase,profitmargin);
@ -280,11 +281,9 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso
free(retstr); free(retstr);
} }
} }
printf("check pullsock\n");
nonz += LP_pullsock_check(myipaddr,pubsock,pullsock,profitmargin); nonz += LP_pullsock_check(myipaddr,pubsock,pullsock,profitmargin);
if ( IAMLP != 0 && (counter % 600) == 42 ) if ( IAMLP != 0 && (counter % 600) == 42 )
LP_hellos(); LP_hellos();
printf("done pullsock\n");
counter++; counter++;
return(nonz); return(nonz);
} }

3
iguana/exchanges/LP_rpc.c

@ -62,8 +62,7 @@ char *issue_LP_clientgetutxos(char *destip,uint16_t destport,char *coin,int32_t
char url[512],*retstr; char url[512],*retstr;
sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=127.0.0.1&port=0",destip,destport,coin,lastn); sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=127.0.0.1&port=0",destip,destport,coin,lastn);
retstr = issue_curlt(url,LP_HTTP_TIMEOUT); retstr = issue_curlt(url,LP_HTTP_TIMEOUT);
//printf("%s clientgetutxos.(%s)\n",url,retstr);
printf("%s clientgetutxos.(%s)\n",url,retstr);
return(retstr); return(retstr);
} }

9
iguana/exchanges/LP_utxos.c

@ -554,9 +554,9 @@ int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t n
return(n); return(n);
} }
void LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,double myprofit) int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,double myprofit)
{ {
char *retstr; struct LP_peerinfo *peer; uint32_t now; char *retstr; struct LP_peerinfo *peer; uint32_t now; int32_t retval = -1;
peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport);
if ( coin == 0 ) if ( coin == 0 )
coin = ""; coin = "";
@ -567,7 +567,7 @@ void LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr
if ( retstr != 0 ) if ( retstr != 0 )
{ {
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
LP_utxosparse(destipaddr,destport,retstr,now); retval = LP_utxosparse(destipaddr,destport,retstr,now);
//printf("got.(%s)\n",retstr); //printf("got.(%s)\n",retstr);
free(retstr); free(retstr);
/*i = 0; /*i = 0;
@ -588,7 +588,8 @@ void LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr
} }
if ( flag != 0 ) if ( flag != 0 )
printf(" <- missing utxos\n");*/ printf(" <- missing utxos\n");*/
} }
return(retval);
} }
cJSON *LP_inventory(char *symbol,int32_t iambob) cJSON *LP_inventory(char *symbol,int32_t iambob)

Loading…
Cancel
Save