Browse Source

Test

etomic
jl777 7 years ago
parent
commit
60b88cd1dd
  1. 2
      iguana/exchanges/LP_RTmetrics.c
  2. 8
      iguana/exchanges/LP_include.h
  3. 24
      iguana/exchanges/LP_network.c
  4. 13
      iguana/exchanges/LP_prices.c

2
iguana/exchanges/LP_RTmetrics.c

@ -123,7 +123,7 @@ void LP_RTmetrics_swapsinfo(char *refbase,char *refrel,cJSON *swaps,int32_t nums
quoteid = juint(item,"quoteid"); quoteid = juint(item,"quoteid");
LP_RTmetrics_pendingswap(srcpub); LP_RTmetrics_pendingswap(srcpub);
LP_RTmetrics_pendingswap(destpub); LP_RTmetrics_pendingswap(destpub);
if ( (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) // no need for this
{ {
if ( (swapjson= cJSON_Parse(retstr)) != 0 ) if ( (swapjson= cJSON_Parse(retstr)) != 0 )
{ {

8
iguana/exchanges/LP_include.h

@ -34,7 +34,7 @@ void emscripten_usleep(int32_t x);
#endif #endif
//#define LP_STRICTPEERS //#define LP_STRICTPEERS
#define LP_BARTERDEX_VERSION 100 #define LP_BARTERDEX_VERSION 0
#define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL)
#define LP_AUTOTRADE_TIMEOUT 10 #define LP_AUTOTRADE_TIMEOUT 10
@ -313,13 +313,13 @@ struct basilisk_swap
}; };
#define LP_MAXPRICEINFOS 1024 #define LP_MAXPRICEINFOS 256
struct LP_pubkeyinfo struct LP_pubkeyinfo
{ {
UT_hash_handle hh; UT_hash_handle hh;
bits256 pubkey; bits256 pubkey;
double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; float matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
uint32_t timestamp,numerrors; uint32_t timestamps[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS],timestamp,numerrors;
int32_t istrusted; int32_t istrusted;
uint8_t rmd160[20],sig[65],pubsecp[33],siglen; uint8_t rmd160[20],sig[65],pubsecp[33],siglen;
}; };

24
iguana/exchanges/LP_network.c

@ -147,17 +147,32 @@ int32_t LP_Qenqueued,LP_Qerrors,LP_Qfound;
void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,int32_t peerind) void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,int32_t peerind)
{ {
struct LP_queue *ptr; struct LP_queue *ptr;
ptr = calloc(1,sizeof(*ptr) + msglen); ptr = calloc(1,sizeof(*ptr) + msglen + sizeof(bits256));
ptr->crc32 = crc32; ptr->crc32 = crc32;
ptr->sock = sock; ptr->sock = sock;
ptr->peerind = peerind; ptr->peerind = peerind;
ptr->msglen = msglen; ptr->msglen = (int32_t)(msglen + sizeof(bits256));
memcpy(ptr->msg,msg,msglen); memcpy(ptr->msg,msg,msglen); // sizeof(bits256) at the end all zeroes
DL_APPEND(LP_Q,ptr); DL_APPEND(LP_Q,ptr);
LP_Qenqueued++; LP_Qenqueued++;
//printf("Q.%p: peerind.%d msglen.%d\n",ptr,peerind,msglen); //printf("Q.%p: peerind.%d msglen.%d\n",ptr,peerind,msglen);
} }
bits256 LP_calc_magic(uint8_t *msg,int32_t len)
{
bits256 magic,hash,pubkey,shared;
vcalc_sha256(0,hash.bytes,msg,len);
while ( 1 )
{
magic = rand256(1);
pubkey = curve25519(magic,curve25519_basepoint9());
shared = curve25519(magic,pubkey);
if ( shared.bytes[1] == LP_BARTERDEX_VERSION )
break;
}
return(magic);
}
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32)
{ {
static uint32_t crcs[1024]; static unsigned long dup,total; static uint32_t crcs[1024]; static unsigned long dup,total;
@ -228,6 +243,9 @@ void queue_loop(void *arg)
{ {
if ( LP_sockcheck(ptr->sock) > 0 ) if ( LP_sockcheck(ptr->sock) > 0 )
{ {
bits256 magic;
magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256)));
memcpy(&ptr->msg[ptr->msglen - sizeof(bits256)],&magic,sizeof(magic));
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen )
printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen);
ptr->sock = -1; ptr->sock = -1;

13
iguana/exchanges/LP_prices.c

@ -343,8 +343,9 @@ void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj)
{ {
if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 )
{ {
//char str[65]; printf("gotprice %s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); char str[65]; printf("gotprice %s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice);
pubp->matrix[basepp->ind][relid] = askprice; pubp->matrix[basepp->ind][relid] = askprice;
pubp->timestamps[basepp->ind][relid] = timestamp;
if ( (relpp= LP_priceinfofind(rel)) != 0 ) if ( (relpp= LP_priceinfofind(rel)) != 0 )
{ {
dxblend(&basepp->relvals[relpp->ind],askprice,0.9); dxblend(&basepp->relvals[relpp->ind],askprice,0.9);
@ -494,9 +495,10 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
//relpp->myprices[basepp->ind] = (1. / price); // bid //relpp->myprices[basepp->ind] = (1. / price); // bid
if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 )
{ {
pubp->timestamp = (uint32_t)time(NULL);
pubp->matrix[basepp->ind][relpp->ind] = price; pubp->matrix[basepp->ind][relpp->ind] = price;
pubp->timestamps[basepp->ind][relpp->ind] = pubp->timestamp;
//pubp->matrix[relpp->ind][basepp->ind] = (1. / price); //pubp->matrix[relpp->ind][basepp->ind] = (1. / price);
pubp->timestamp = (uint32_t)time(NULL);
} }
return(0); return(0);
} else return(-1); } else return(-1);
@ -739,7 +741,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *
bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160));
minsatoshis = maxsatoshis = n = 0; minsatoshis = maxsatoshis = n = 0;
ap = 0; ap = 0;
if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL ) if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL && pubp->timestamps[baseid][relid] >= oldest )
{ {
balance = 0; balance = 0;
if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 )
@ -1063,14 +1065,15 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{ {
if ( (rand() % 100) == 0 ) if ( (rand() % 100) == 0 )
printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price);
pubp->timestamp = (uint32_t)time(NULL);
if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL )
{ {
pubp->matrix[basepp->ind][relpp->ind] = price; pubp->matrix[basepp->ind][relpp->ind] = price;
pubp->timestamps[basepp->ind][relpp->ind] = pubp->timestamp;
dxblend(&basepp->relvals[relpp->ind],price,0.9); dxblend(&basepp->relvals[relpp->ind],price,0.9);
dxblend(&relpp->relvals[basepp->ind],1. / price,0.9); dxblend(&relpp->relvals[basepp->ind],1. / price,0.9);
} }
pubp->timestamp = (uint32_t)time(NULL);
} else printf("error finding pubkey entry %s, ok if rare\n",bits256_str(str,pubkey)); } else printf("error finding pubkey entry %s, ok if rare\n",bits256_str(str,pubkey));
} }
//else if ( (rand() % 100) == 0 ) //else if ( (rand() % 100) == 0 )

Loading…
Cancel
Save