diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5fc146210..639bde43c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1008,6 +1008,59 @@ void LP_tradesloop(void *ctx) { LP_millistats_update(&LP_tradesloop_stats); nonz = 0; + HASH_ITER(hh,LP_trades,tp,tmp) + { + if ( tp->negotiationdone != 0 ) + continue; + timeout = LP_AUTOTRADE_TIMEOUT; + if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 ) + timeout += LP_AUTOTRADE_TIMEOUT * .5; + if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 ) + timeout += LP_AUTOTRADE_TIMEOUT * .5; + now = (uint32_t)time(NULL); + if ( now > tp->lastprocessed ) + { + if ( tp->iambob == 0 ) + { + if ( tp->bestprice > 0. ) + { + if ( tp->connectsent == 0 ) + { + tp->negotiationdone = (uint32_t)time(NULL); + LP_Alicemaxprice = tp->bestprice; + LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT + tp->connectsent = now; + //printf("send LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice); + } + else if ( now < tp->firstprocessed+timeout && ((tp->firstprocessed - now) % 10) == 9 ) + { + //LP_Alicemaxprice = tp->bestprice; + //LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT + printf("mark slow LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice); + if ( (pubp= LP_pubkeyfind(tp->Qs[LP_CONNECT].srchash)) != 0 ) + pubp->slowresponse++; + } + } + } + } + } + now = (uint32_t)time(NULL); + HASH_ITER(hh,LP_trades,tp,tmp) + { + timeout = LP_AUTOTRADE_TIMEOUT; + if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 ) + timeout += LP_AUTOTRADE_TIMEOUT * .5; + if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 ) + timeout += LP_AUTOTRADE_TIMEOUT * .5; + if ( now > tp->firstprocessed+timeout*10 ) + { + //printf("purge swap aliceid.%llu\n",(long long)tp->aliceid); + portable_mutex_lock(&LP_tradesmutex); + HASH_DELETE(hh,LP_trades,tp); + portable_mutex_unlock(&LP_tradesmutex); + free(tp); + } + } DL_FOREACH_SAFE(LP_tradesQ,qtp,tmp) { now = (uint32_t)time(NULL); @@ -1089,59 +1142,6 @@ void LP_tradesloop(void *ctx) } } else printf("qtp->iambob.%d vs tp->iambob.%d\n",qtp->iambob,tp->iambob); } - HASH_ITER(hh,LP_trades,tp,tmp) - { - if ( tp->negotiationdone != 0 ) - continue; - timeout = LP_AUTOTRADE_TIMEOUT; - if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 ) - timeout += LP_AUTOTRADE_TIMEOUT * .5; - if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 ) - timeout += LP_AUTOTRADE_TIMEOUT * .5; - now = (uint32_t)time(NULL); - if ( now > tp->lastprocessed ) - { - if ( tp->iambob == 0 ) - { - if ( tp->bestprice > 0. ) - { - if ( tp->connectsent == 0 ) - { - tp->negotiationdone = (uint32_t)time(NULL); - LP_Alicemaxprice = tp->bestprice; - LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT - tp->connectsent = now; - //printf("send LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice); - } - else if ( now < tp->firstprocessed+timeout && ((tp->firstprocessed - now) % 10) == 9 ) - { - //LP_Alicemaxprice = tp->bestprice; - //LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT - printf("mark slow LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice); - if ( (pubp= LP_pubkeyfind(tp->Qs[LP_CONNECT].srchash)) != 0 ) - pubp->slowresponse++; - } - } - } - } - } - now = (uint32_t)time(NULL); - HASH_ITER(hh,LP_trades,tp,tmp) - { - timeout = LP_AUTOTRADE_TIMEOUT; - if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 ) - timeout += LP_AUTOTRADE_TIMEOUT * .5; - if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 ) - timeout += LP_AUTOTRADE_TIMEOUT * .5; - if ( now > tp->firstprocessed+timeout*10 ) - { - //printf("purge swap aliceid.%llu\n",(long long)tp->aliceid); - portable_mutex_lock(&LP_tradesmutex); - HASH_DELETE(hh,LP_trades,tp); - portable_mutex_unlock(&LP_tradesmutex); - free(tp); - } - } if ( nonz == 0 ) sleep(1); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index e62279232..be24f44ed 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -2491,7 +2491,7 @@ void basilisk_swaploop(void *_utxo) { uint8_t *data; uint32_t expiration,savestatebits=0,saveotherbits=0; uint32_t channel; int32_t iters,retval=0,j,datalen,maxlen; struct basilisk_swap *swap; struct LP_utxoinfo *utxo = _utxo; swap = utxo->swap; - fprintf(stderr,"start swap iambob.%d\n",swap->I.iambob); + //fprintf(stderr,"start swap iambob.%d\n",swap->I.iambob); maxlen = 1024*1024 + sizeof(*swap); data = malloc(maxlen); expiration = (uint32_t)time(NULL) + 300; diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index c0176d8d4..e422a47eb 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -995,8 +995,8 @@ int32_t instantdex_pubkeyargs(struct basilisk_swap *swap,int32_t numpubs,bits256 } n++; } - if ( n > 2 || m > 2 ) - printf("n.%d m.%d len.%d numpubs.%d\n",n,m,len,swap->I.numpubs); + //if ( n > 2 || m > 2 ) + // printf("n.%d m.%d len.%d numpubs.%d\n",n,m,len,swap->I.numpubs); return(n); }