Browse Source

Test

etomic
jl777 7 years ago
parent
commit
b6c5a83771
  1. 2
      iguana/exchanges/LP_include.h
  2. 37
      iguana/exchanges/LP_nativeDEX.c
  3. 16
      iguana/exchanges/LP_ordermatch.c
  4. 2
      iguana/exchanges/LP_peers.c
  5. 2
      iguana/exchanges/LP_prices.c
  6. 6
      iguana/exchanges/LP_remember.c
  7. 10
      iguana/exchanges/LP_signatures.c

2
iguana/exchanges/LP_include.h

@ -387,7 +387,7 @@ int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);
uint64_t LP_RTsmartbalance(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(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg);
struct iguana_info *LP_coinfind(char *symbol);
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32);
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price);

37
iguana/exchanges/LP_nativeDEX.c

@ -27,8 +27,8 @@
#include "LP_include.h"
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex;
int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[1000];
int32_t num_Reserved_msgs,max_Reserved_msgs;
char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
struct LP_peerinfo *LP_peerinfos,*LP_mypeer;
struct LP_forwardinfo *LP_forwardinfos;
struct iguana_info *LP_coins;
@ -237,7 +237,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
memset(zero.bytes,0,sizeof(zero));
/*if ( (method= jstr(reqjson,"method")) != 0 && (strcmp(method,"request") == 0 || strcmp(method,"requested") == 0 || strcmp(method,"connect") == 0 || strcmp(method,"connected") == 0) )
printf("broadcast.(%s)\n",Broadcaststr);*/
LP_reserved_msg("","",zero,jprint(reqjson,0));
LP_reserved_msg(0,"","",zero,jprint(reqjson,0));
}
retstr = clonestr("{\"result\":\"success\"}");
free_json(reqjson);
@ -809,7 +809,7 @@ void LP_reserved_msgs(void *ignore)
memset(zero.bytes,0,sizeof(zero));
while ( 1 )
{
if ( num_Reserved_msgs > 0 )
if ( num_Reserved_msgs[0] > 0 || num_Reserved_msgs[1] > 0 )
{
flag = 0;
if ( LP_mypubsock >= 0 )
@ -823,9 +823,18 @@ void LP_reserved_msgs(void *ignore)
if ( flag == 1 )
{
portable_mutex_lock(&LP_reservedmutex);
num_Reserved_msgs--;
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]);
Reserved_msgs[num_Reserved_msgs] = 0;
if ( num_Reserved_msgs[1] > 0 )
{
num_Reserved_msgs[1]--;
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[1][num_Reserved_msgs[1]]);
Reserved_msgs[1][num_Reserved_msgs[1]] = 0;
}
else if ( num_Reserved_msgs[0] > 0 )
{
num_Reserved_msgs[0]--;
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]);
Reserved_msgs[0][num_Reserved_msgs[0]] = 0;
}
portable_mutex_unlock(&LP_reservedmutex);
}
}
@ -835,20 +844,20 @@ void LP_reserved_msgs(void *ignore)
}
}
int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg)
int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg)
{
int32_t n = 0;
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs < sizeof(Reserved_msgs)/sizeof(*Reserved_msgs) )
if ( num_Reserved_msgs[priority] < sizeof(Reserved_msgs[priority])/sizeof(*Reserved_msgs[priority]) )
{
Reserved_msgs[num_Reserved_msgs++] = msg;
n = num_Reserved_msgs;
Reserved_msgs[priority][num_Reserved_msgs[priority]++] = msg;
n = num_Reserved_msgs[priority];
} else LP_broadcast_message(LP_mypubsock,base,rel,pubkey,msg);
portable_mutex_unlock(&LP_reservedmutex);
if ( num_Reserved_msgs > max_Reserved_msgs )
if ( num_Reserved_msgs[priority] > max_Reserved_msgs[priority] )
{
max_Reserved_msgs = num_Reserved_msgs;
printf("New max_Reserved_msgs.%d\n",max_Reserved_msgs);
max_Reserved_msgs[priority] = num_Reserved_msgs[priority];
printf("New priority.%d max_Reserved_msgs.%d\n",priority,max_Reserved_msgs[priority]);
}
return(n);
}

16
iguana/exchanges/LP_ordermatch.c

@ -375,8 +375,12 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ
//jaddnum(retjson,"quoteid",qp->R.quoteid);
// LP_addsig
char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,utxo->S.otherpubkey));
LP_reserved_msg(base,rel,utxo->S.otherpubkey,jprint(retjson,0));
LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->desthash,jprint(retjson,0));
LP_reserved_msg(1,base,rel,utxo->S.otherpubkey,jprint(retjson,0));
sleep(1);
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,base,rel,zero,jprint(retjson,0));
//LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->desthash,jprint(retjson,0));
free_json(retjson);
retval = 0;
} else printf("error launching swaploop\n");
@ -734,8 +738,12 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
printf("return after queued RESERVED: set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg);
// LP_addsig
//msg2 = clonestr(msg);
LP_reserved_msg(Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg);
LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0));
LP_reserved_msg(1,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg);
sleep(1);
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,msg);
//LP_broadcast_message(LP_mypubsock,Q.srccoin,Q.destcoin,Q.desthash,jprint(retjson,0));
free_json(retjson);
return(retval);
} else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap);

2
iguana/exchanges/LP_peers.c

@ -153,7 +153,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
struct iguana_info *coin,*ctmp; bits256 zero; char busaddr[64];
memset(zero.bytes,0,sizeof(zero));
//LP_send(mypubsock,msg,(int32_t)strlen(msg)+1,1);
LP_reserved_msg("","",zero,jprint(LP_peerjson(peer),1));
LP_reserved_msg(0,"","",zero,jprint(LP_peerjson(peer),1));
if ( 0 )
{
HASH_ITER(hh,LP_coins,coin,ctmp)

2
iguana/exchanges/LP_prices.c

@ -713,7 +713,7 @@ void LP_pubkeys_query()
jaddstr(reqjson,"method","wantnotify");
jaddbits256(reqjson,"pub",pubp->pubkey);
//printf("LP_pubkeys_query %s\n",jprint(reqjson,0));
LP_reserved_msg("","",zero,jprint(reqjson,1));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
}
}

6
iguana/exchanges/LP_remember.c

@ -1118,8 +1118,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
itemstr = jprint(item,0);
fprintf(fp,"%s\n",itemstr);
LP_tradecommand_log(item);
LP_reserved_msg(rswap.src,rswap.dest,zero,clonestr(itemstr));
LP_broadcast_message(LP_mypubsock,rswap.src,rswap.dest,zero,itemstr);
LP_reserved_msg(1,rswap.src,rswap.dest,zero,clonestr(itemstr));
sleep(1);
LP_reserved_msg(0,rswap.src,rswap.dest,zero,clonestr(itemstr));
//LP_broadcast_message(LP_mypubsock,rswap.src,rswap.dest,zero,itemstr);
fclose(fp);
}
}

10
iguana/exchanges/LP_signatures.c

@ -348,7 +348,7 @@ void LP_postutxos(char *symbol,char *coinaddr)
//char str[65]; printf("utxoshash add %s\n",bits256_str(str,utxoshash));
LP_utxos_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,utxoshash);
//printf("post (%s) -> %d\n",msg,LP_mypubsock);
LP_reserved_msg(symbol,symbol,zero,jprint(reqjson,1));
LP_reserved_msg(0,symbol,symbol,zero,jprint(reqjson,1));
}
}
}
@ -463,7 +463,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33);
jaddstr(reqjson,"pubsecp",pubsecpstr);
LP_price_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,base,rel,price64);
LP_reserved_msg(base,rel,zero,jprint(reqjson,1));
LP_reserved_msg(0,base,rel,zero,jprint(reqjson,1));
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"electrum node cant post bob asks\"}"));
}
@ -569,7 +569,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock)
timestamp = (uint32_t)time(NULL);
jaddnum(reqjson,"timestamp",timestamp);
LP_pubkey_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp);
LP_reserved_msg("","",zero,jprint(reqjson,1));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
char *LP_notify_recv(cJSON *argjson)
@ -624,7 +624,7 @@ void LP_smartutxos_push(struct iguana_info *coin)
jaddnum(req,"ht",height);
jadd64bits(req,"value",value);
//printf("ADDR_UNSPENTS[] <- %s\n",jprint(req,0));
LP_reserved_msg("","",zero,jprint(req,1));
LP_reserved_msg(0,"","",zero,jprint(req,1));
#endif
}
}
@ -657,7 +657,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr)
jaddstr(reqjson,"method","addr_unspents");
jaddstr(reqjson,"coin",symbol);
jaddstr(reqjson,"address",coinaddr);
LP_reserved_msg("","",zero,jprint(reqjson,1));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp)

Loading…
Cancel
Save