From 9be726148e96f829a9b6e065ea75b5e8685b840f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 30 Oct 2017 14:47:15 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_include.h | 2 + iguana/exchanges/LP_network.c | 58 ++--------------------- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 4 +- iguana/exchanges/LP_statemachine.c | 76 +++++++++++++++++++++++++++++- 5 files changed, 86 insertions(+), 56 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 48d38e15a..65f7171ae 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -34,6 +34,8 @@ void emscripten_usleep(int32_t x); #endif //#define LP_STRICTPEERS +#define LP_BARTERDEX_VERSION 100 + #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) #define LP_AUTOTRADE_TIMEOUT 10 #define ELECTRUM_TIMEOUT 10 diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index a27fa7fc3..56f5456b5 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -107,7 +107,7 @@ char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t po return(str); } -int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) +/*int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) { int32_t sentbytes; if ( sock < 0 ) @@ -123,7 +123,7 @@ int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) if ( freeflag != 0 ) free(msg); return(sentbytes); -} +}*/ int32_t LP_sockcheck(int32_t sock) { @@ -282,32 +282,7 @@ void queue_loop(void *arg) void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32_t msglen,int32_t needack) { int32_t maxind,peerind = 0; //sentbytes, - if ( sock0 >= 0 || sock1 >= 0 ) - { -/* if ( sock0 >= 0 && LP_sockcheck(sock0) > 0 ) - { - if ( (sentbytes= nn_send(sock0,msg,msglen,0)) != msglen ) - printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); - else - { -printf("Q sent %u msglen.%d (%s)\n",crc32,msglen,msg); - sock0 = -1; - } - } - if ( sock1 >= 0 && LP_sockcheck(sock1) > 0 ) - { - if ( (sentbytes= nn_send(sock1,msg,msglen,0)) != msglen ) - printf("_LP_queuesend1 sent %d instead of %d\n",sentbytes,msglen); - else - { -printf("Q sent1 %u msglen.%d (%s)\n",crc32,msglen,msg); - sock1 = -1; - } - } - if ( sock0 < 0 && sock1 < 0 ) - return;*/ - } - else + if ( sock0 < 0 && sock1 < 0 ) { if ( (maxind= LP_numpeers()) > 0 ) peerind = (rand() % maxind) + 1; @@ -326,19 +301,10 @@ printf("Q sent1 %u msglen.%d (%s)\n",crc32,msglen,msg); void LP_queuesend(uint32_t crc32,int32_t pubsock,char *base,char *rel,uint8_t *msg,int32_t msglen) { - //struct iguana_info *coin; int32_t flag=0,socks[2]; portable_mutex_lock(&LP_networkmutex); if ( pubsock >= 0 ) - { - //socks[0] = socks[1] = -1; - //if ( rel != 0 && rel[0] != 0 && (coin= LP_coinfind(rel)) != 0 && coin->bussock >= 0 ) - // socks[flag++] = coin->bussock; - //if ( base != 0 && base[0] != 0 && (coin= LP_coinfind(base)) != 0 && coin->bussock >= 0 ) - // socks[flag++] = coin->bussock; - //if ( flag == 0 && pubsock >= 0 ) - _LP_queuesend(crc32,pubsock,-1,msg,msglen,0); - //else _LP_queuesend(socks[0],socks[1],msg,msglen,0); - } else _LP_queuesend(crc32,-1,-1,msg,msglen,1); + _LP_queuesend(crc32,pubsock,-1,msg,msglen,0); + else _LP_queuesend(crc32,-1,-1,msg,msglen,1); portable_mutex_unlock(&LP_networkmutex); } @@ -362,21 +328,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON // add signature here msg = (void *)jprint(argjson,0); msglen = (int32_t)strlen((char *)msg) + 1; -#ifdef FROM_JS - int32_t sentbytes,sock,peerind,maxind; - if ( (maxind= LP_numpeers()) > 0 ) - peerind = (rand() % maxind) + 1; - else peerind = 1; - sock = LP_peerindsock(&peerind); - if ( sock >= 0 ) - { - if ( (sentbytes= nn_send(sock,msg,msglen,0)) != msglen ) - printf("LP_send sent %d instead of %d\n",sentbytes,msglen); - else printf("sent %d bytes of %d to sock.%d\n",sentbytes,msglen,sock); - } else printf("couldnt get valid sock\n"); -#else LP_queuesend(crc32,-1,base,rel,msg,msglen); -#endif } else LP_queuesend(crc32,pubsock,base,rel,msg,msglen); free(msg); } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d33c757d0..1ed257db0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -852,7 +852,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i free(utxos); if ( *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) return(0); - int32_t changed; + //int32_t changed; //LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep); return(bestutxo); } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 6228e6e9a..fca6902a2 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -698,13 +698,15 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d void LP_pubkeys_query() { + static uint32_t lasttime; uint8_t zeroes[20]; bits256 zero; cJSON *reqjson; struct LP_pubkeyinfo *pubp=0,*tmp; memset(zero.bytes,0,sizeof(zero)); memset(zeroes,0,sizeof(zeroes)); HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp) { - if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) + if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 && time(NULL) > lasttime+30 ) { + lasttime = (uint32_t)time(NULL); reqjson = cJSON_CreateObject(); jaddstr(reqjson,"method","wantnotify"); jaddbits256(reqjson,"pub",pubp->pubkey); diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index ae640364e..35b01f1cc 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -2245,13 +2245,87 @@ void LP_price_broadcastloop(void *ctx) sleep(LP_ORDERBOOK_DURATION * .9); } } +#ifdef FROM_JS +int32_t sentbytes,sock,peerind,maxind; +if ( (maxind= LP_numpeers()) > 0 ) +peerind = (rand() % maxind) + 1; +else peerind = 1; +sock = LP_peerindsock(&peerind); +if ( sock >= 0 ) +{ + if ( (sentbytes= nn_send(sock,msg,msglen,0)) != msglen ) + printf("LP_send sent %d instead of %d\n",sentbytes,msglen); + else printf("sent %d bytes of %d to sock.%d\n",sentbytes,msglen,sock); + } else printf("couldnt get valid sock\n"); +#else + +void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32_t msglen,int32_t needack) +{ + int32_t maxind,peerind = 0; //sentbytes, + if ( sock0 >= 0 || sock1 >= 0 ) + { + /* if ( sock0 >= 0 && LP_sockcheck(sock0) > 0 ) + { + if ( (sentbytes= nn_send(sock0,msg,msglen,0)) != msglen ) + printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); + else + { + printf("Q sent %u msglen.%d (%s)\n",crc32,msglen,msg); + sock0 = -1; + } + } + if ( sock1 >= 0 && LP_sockcheck(sock1) > 0 ) + { + if ( (sentbytes= nn_send(sock1,msg,msglen,0)) != msglen ) + printf("_LP_queuesend1 sent %d instead of %d\n",sentbytes,msglen); + else + { + printf("Q sent1 %u msglen.%d (%s)\n",crc32,msglen,msg); + sock1 = -1; + } + } + if ( sock0 < 0 && sock1 < 0 ) + return;*/ + } + else + { + if ( (maxind= LP_numpeers()) > 0 ) + peerind = (rand() % maxind) + 1; + else peerind = 1; + sock0 = LP_peerindsock(&peerind); + if ( (maxind= LP_numpeers()) > 0 ) + peerind = (rand() % maxind) + 1; + else peerind = 1; + sock1 = LP_peerindsock(&peerind); + } + if ( sock0 >= 0 ) + _LP_sendqueueadd(crc32,sock0,msg,msglen,needack * peerind); + if ( sock1 >= 0 ) + _LP_sendqueueadd(crc32,sock1,msg,msglen,needack); +} if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_price_broadcastloop,(void *)ctx) != 0 ) { printf("error launching LP_swapsloop for port.%u\n",myport); exit(-1); } - +void LP_queuesend(uint32_t crc32,int32_t pubsock,char *base,char *rel,uint8_t *msg,int32_t msglen) +{ + //struct iguana_info *coin; int32_t flag=0,socks[2]; + portable_mutex_lock(&LP_networkmutex); + if ( pubsock >= 0 ) + { + //socks[0] = socks[1] = -1; + //if ( rel != 0 && rel[0] != 0 && (coin= LP_coinfind(rel)) != 0 && coin->bussock >= 0 ) + // socks[flag++] = coin->bussock; + //if ( base != 0 && base[0] != 0 && (coin= LP_coinfind(base)) != 0 && coin->bussock >= 0 ) + // socks[flag++] = coin->bussock; + //if ( flag == 0 && pubsock >= 0 ) + _LP_queuesend(crc32,pubsock,-1,msg,msglen,0); + //else _LP_queuesend(socks[0],socks[1],msg,msglen,0); + } else _LP_queuesend(crc32,-1,-1,msg,msglen,1); + portable_mutex_unlock(&LP_networkmutex); +} #ifdef oldway struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,uint64_t maxdestsatoshis) {