Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
172dec05eb
  1. 2
      iguana/exchanges777.h
  2. 17
      iguana/iguana_instantdex.c
  3. 2
      iguana/iguana_recv.c

2
iguana/exchanges777.h

@ -179,7 +179,7 @@ double fxcm_price(struct exchange_info *exchange,char *base,char *rel,struct exc
double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert);
char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer,int32_t queueflag,uint8_t minperc);
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,int32_t p2pflag);
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,struct iguana_peer *addr);
char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson); // Bob sending to network (Alice)
struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid,int32_t requeueflag);
char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json);

17
iguana/iguana_instantdex.c

@ -318,9 +318,9 @@ bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,stru
return(orderhash);
}
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen,int32_t p2pflag)
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen,struct iguana_peer *addr)
{
char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 orderhash; struct iguana_info *coin; struct iguana_peer *addr; int32_t i,j,r,olen,slen,datalen,max=-1; uint8_t serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t nxt64bits;
char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 orderhash; struct iguana_info *coin; int32_t i,olen,slen,datalen,max=-1; uint8_t serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t nxt64bits;
category_subscribe(myinfo,myinfo->instantdex_category,GENESIS_PUBKEY);
jaddstr(argjson,"cmd",cmdstr);
jaddstr(argjson,"agent","SuperNET");
@ -358,13 +358,14 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 )
{
printf(">>>>>>>>>>>> instantdex send.(%s) datalen.%d allocsize.%d crc.%x\n",cmdstr,datalen,msg->sig.allocsize,calc_crc32(0,(void *)((long)msg + 8),datalen-8));
if ( p2pflag != 0 )
if ( addr != 0 )
{
memset(serialized,0,sizeof(struct iguana_msghdr));
memcpy(&serialized[sizeof(struct iguana_msghdr)],(uint8_t *)msg,msg->sig.allocsize);
if ( (coin= iguana_coinfind("BTCD")) != 0 && (max= coin->peers.numranked) > 0 )
if ( (coin= iguana_coinfind("BTCD")) != 0 )//&& (max= coin->peers.numranked) > 0 )
{
r = (rand() % max);
iguana_queue_send(coin,addr,0,serialized,"InstantDEX",msg->sig.allocsize,0,0);
/*r = (rand() % max);
for (i=0; i<max; i++)
{
j = (i + r) % max;
@ -375,7 +376,7 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
if ( --hops <= 0 )
break;
} //else printf("skip.%d addr.%p (%s) max.%d hops.%d\n",j,addr,addr!=0?addr->ipaddr:"",max,hops);
}
}*/
} else printf("cant find coin.%p or no ranked.%d\n",coin,max);
}
else
@ -833,7 +834,7 @@ struct iguana_bundlereq *instantdex_recvquotes(struct iguana_info *coin,struct i
if ( req->addr == 0 )
return(0);
printf("received quotes.%d from (%s)\n",n,req->addr->ipaddr);
for (i=0; i<n; i++)
for (i=1; i<n; i++)
{
if ( instantdex_quotefind(0,coin,req->addr,quotes[i]) != 0 )
continue;
@ -1122,7 +1123,7 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )
return(clonestr("{\"error\":\"instantdex_checkoffer null newjson\"}"));
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),1));
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0));
} else printf("error creating statemachine\n");
}
return(retstr);

2
iguana/iguana_recv.c

@ -499,7 +499,7 @@ void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256
void iguana_gotquotesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *quotes,int32_t n)
{
struct iguana_bundlereq *req;
printf("got %d quotes from %s\n",n,addr->ipaddr);
//printf("got %d quotes from %s\n",n,addr->ipaddr);
req = iguana_bundlereq(coin,addr,'Q',0);
req->hashes = quotes, req->n = n;
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);

Loading…
Cancel
Save