jl777 7 years ago
parent
commit
4a42ad4cc2
  1. 1
      iguana/exchanges/LP_include.h
  2. 46
      iguana/exchanges/LP_nativeDEX.c
  3. 1
      iguana/exchanges/LP_network.c
  4. 8
      iguana/exchanges/LP_portfolio.c

1
iguana/exchanges/LP_include.h

@ -311,7 +311,6 @@ uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport); int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx); int32_t LP_nanomsg_recvs(void *ctx);
int32_t LP_reserved_msgs();
uint64_t LP_smartbalance(struct iguana_info *coin); uint64_t LP_smartbalance(struct iguana_info *coin);
int32_t LP_getheight(struct iguana_info *coin); int32_t LP_getheight(struct iguana_info *coin);
int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg); int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg);

46
iguana/exchanges/LP_nativeDEX.c

@ -380,6 +380,15 @@ void command_rpcloop(void *myipaddr)
} }
} }
void utxosQ_loop(void *myipaddr)
{
while ( 1 )
{
if ( LP_utxosQ_process() == 0 )
usleep(10000);
}
}
int32_t LP_utxos_sync(struct LP_peerinfo *peer) int32_t LP_utxos_sync(struct LP_peerinfo *peer)
{ {
int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr; int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr;
@ -570,7 +579,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
myipaddr = "127.0.0.1"; myipaddr = "127.0.0.1";
numpeers = LP_numpeers(); numpeers = LP_numpeers();
needpings = 0; needpings = 0;
fprintf(stderr,"P");
HASH_ITER(hh,LP_peerinfos,peer,tmp) HASH_ITER(hh,LP_peerinfos,peer,tmp)
{ {
if ( peer->errors >= LP_MAXPEER_ERRORS ) if ( peer->errors >= LP_MAXPEER_ERRORS )
@ -589,12 +597,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
if ( strcmp(peer->ipaddr,myipaddr) != 0 ) if ( strcmp(peer->ipaddr,myipaddr) != 0 )
{ {
nonz++; nonz++;
fprintf(stderr,"q");
LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport);
peer->diduquery = 0; peer->diduquery = 0;
fprintf(stderr,"p");
LP_peer_pricesquery(peer); LP_peer_pricesquery(peer);
fprintf(stderr,"u");
//LP_utxos_sync(peer); //LP_utxos_sync(peer);
needpings++; needpings++;
} }
@ -602,11 +607,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
} }
if ( peer->needping != 0 ) if ( peer->needping != 0 )
{ {
fprintf(stderr,"u");
LP_utxos_sync(peer); LP_utxos_sync(peer);
peer->diduquery = now; peer->diduquery = now;
nonz++; nonz++;
fprintf(stderr,"n");
if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 )
free(retstr); free(retstr);
peer->needping = 0; peer->needping = 0;
@ -617,29 +620,24 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
{ {
nonz++; nonz++;
//printf("needpings.%d send notify\n",needpings); //printf("needpings.%d send notify\n",needpings);
fprintf(stderr,"p");
LP_notify_pubkeys(ctx,pubsock); LP_notify_pubkeys(ctx,pubsock);
} }
if ( (counter % 6000) == 10 ) if ( (counter % 6000) == 10 )
{ {
fprintf(stderr,"K");
nonz++; nonz++;
LP_privkey_updates(ctx,pubsock,0); LP_privkey_updates(ctx,pubsock,0);
} }
fprintf(stderr,"C");
HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
{ {
if ( coin->addr_listunspent_requested != 0 ) if ( coin->addr_listunspent_requested != 0 )
{ {
//printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested); //printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested);
fprintf(stderr,">");
LP_smartutxos_push(coin); LP_smartutxos_push(coin);
coin->addr_listunspent_requested = 0; coin->addr_listunspent_requested = 0;
} }
if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR )
{ {
nonz++; nonz++;
fprintf(stderr,"X");
if ( (height= LP_getheight(coin)) > coin->longestchain ) if ( (height= LP_getheight(coin)) > coin->longestchain )
{ {
coin->longestchain = height; coin->longestchain = height;
@ -651,7 +649,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
} }
if ( (counter % 100000) == 90000 ) if ( (counter % 100000) == 90000 )
{ {
fprintf(stderr,"S");
if ( (retstr= basilisk_swapentry(0,0)) != 0 ) if ( (retstr= basilisk_swapentry(0,0)) != 0 )
{ {
//printf("SWAPS.(%s)\n",retstr); //printf("SWAPS.(%s)\n",retstr);
@ -659,7 +656,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
free(retstr); free(retstr);
} }
} }
fprintf(stderr,".");
counter++; counter++;
return(nonz); return(nonz);
} }
@ -726,9 +722,9 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
} }
} }
int32_t LP_reserved_msgs() void LP_reserved_msgs(void *ignore)
{ {
bits256 zero; int32_t flag,n = 0; struct nn_pollfd pfd; bits256 zero; int32_t flag; struct nn_pollfd pfd;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
while ( 1 ) while ( 1 )
{ {
@ -751,13 +747,10 @@ int32_t LP_reserved_msgs()
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]);
Reserved_msgs[num_Reserved_msgs] = 0; Reserved_msgs[num_Reserved_msgs] = 0;
portable_mutex_unlock(&LP_reservedmutex); portable_mutex_unlock(&LP_reservedmutex);
usleep(3000); }
} else break; }
} else break; usleep(3000);
if ( ++n > 1 )
break;
} }
return(n);
} }
int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg) int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg)
@ -911,6 +904,16 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_psockloop for (%s)\n",myipaddr); printf("error launching LP_psockloop for (%s)\n",myipaddr);
exit(-1); exit(-1);
} }
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 )
{
printf("error launching LP_reserved_msgs for (%s)\n",myipaddr);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 )
{
printf("error launching utxosQ_loop for (%s)\n",myipaddr);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{ {
printf("error launching stats rpcloop for port.%u\n",myport); printf("error launching stats rpcloop for port.%u\n",myport);
@ -951,7 +954,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
} }
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 )
nonz++; nonz++;
fprintf(stderr," nonz.%d\n",nonz);
if ( nonz == 0 ) if ( nonz == 0 )
usleep(1000); usleep(1000);
else if ( IAMLP == 0 ) else if ( IAMLP == 0 )

1
iguana/exchanges/LP_network.c

@ -144,7 +144,6 @@ void queue_loop(void *ignore)
struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0;
while ( 1 ) while ( 1 )
{ {
LP_reserved_msgs();
nonz = 0; nonz = 0;
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0); //printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
n = 0; n = 0;

8
iguana/exchanges/LP_portfolio.c

@ -596,7 +596,7 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a
void prices_loop(void *ignore) void prices_loop(void *ignore)
{ {
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; uint32_t expiration; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx(); char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx();
while ( 1 ) while ( 1 )
{ {
if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
@ -634,12 +634,6 @@ void prices_loop(void *ignore)
} }
free(retstr); free(retstr);
} }
expiration = (uint32_t)time(NULL) + 60;
while ( time(NULL) < expiration )
{
if ( LP_utxosQ_process() == 0 )
usleep(10000);
}
} }
} }

Loading…
Cancel
Save