Browse Source

Test

etomic
jl777 8 years ago
parent
commit
d750b1bfc3
  1. 4
      iguana/exchanges/LP_ordermatch.c
  2. 32
      iguana/exchanges/LP_swap.c

4
iguana/exchanges/LP_ordermatch.c

@ -349,7 +349,7 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L
int32_t LP_nanobind(void *ctx,char *pairstr)
{
int32_t i,timeout,r,pairsock = -1; uint16_t mypullport; char bindaddr[128];
int32_t i,r,pairsock = -1; uint16_t mypullport; char bindaddr[128];
if ( LP_canbind != 0 )
{
if ( (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 )
@ -428,7 +428,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ
char *LP_connectedalice(cJSON *argjson) // alice
{
cJSON *retjson; double bid,ask,price,qprice; int32_t timeout,pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin;
cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin;
if ( LP_quoteparse(&Q,argjson) < 0 )
clonestr("{\"error\":\"cant parse quote\"}");
if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 )

32
iguana/exchanges/LP_swap.c

@ -400,18 +400,24 @@ int32_t LP_mostprivs_verify(struct basilisk_swap *swap,uint8_t *data,int32_t dat
int32_t LP_waitfor(int32_t pairsock,struct basilisk_swap *swap,int32_t timeout,int32_t (*verify)(struct basilisk_swap *swap,uint8_t *data,int32_t datalen))
{
void *data; int32_t datalen,retval = -1; uint32_t expiration = (uint32_t)time(NULL) + timeout;
struct nn_pollfd pfd; void *data; int32_t datalen,retval = -1; uint32_t expiration = (uint32_t)time(NULL) + timeout;
while ( time(NULL) < expiration )
{
//printf("start wait\n");
if ( (datalen= nn_recv(pairsock,&data,NN_MSG,0)) >= 0 )
memset(&pfd,0,sizeof(pfd));
pfd.fd = pairsock;
pfd.events = NN_POLLIN;
if ( nn_poll(&pfd,1,1) > 0 )
{
//printf("wait for got.%d\n",datalen);
retval = (*verify)(swap,data,datalen);
nn_freemsg(data);
//printf("retval.%d\n",retval);
return(retval);
} // else printf("error nn_recv\n");
//printf("start wait\n");
if ( (datalen= nn_recv(pairsock,&data,NN_MSG,0)) >= 0 )
{
//printf("wait for got.%d\n",datalen);
retval = (*verify)(swap,data,datalen);
nn_freemsg(data);
//printf("retval.%d\n",retval);
return(retval);
} // else printf("error nn_recv\n");
}
}
printf("waitfor timedout\n");
return(retval);
@ -419,13 +425,13 @@ int32_t LP_waitfor(int32_t pairsock,struct basilisk_swap *swap,int32_t timeout,i
int32_t swap_nn_send(int32_t sock,uint8_t *data,int32_t datalen,uint32_t flags,int32_t timeout)
{
struct nn_pollfd pfd; //int32_t i;
//for (i=0; i<timeout*1000; i++)
struct nn_pollfd pfd; int32_t i;
for (i=0; i<timeout*1000; i++)
{
memset(&pfd,0,sizeof(pfd));
pfd.fd = sock;
pfd.events = NN_POLLIN;
//if ( nn_poll(&pfd,1,1) > 0 )
pfd.events = NN_POLLOUT;
if ( nn_poll(&pfd,1,1) > 0 )
return(nn_send(sock,data,datalen,flags));
usleep(1000);
}

Loading…
Cancel
Save