From 20afaac094400638b5e50ffdb4d6c54c46ffe036 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 11 Feb 2016 21:29:05 -0300 Subject: [PATCH] test --- iguana/SuperNET.c | 8 ++++---- iguana/SuperNET_hexmsg.c | 2 +- iguana/exchanges/bitcoin.c | 3 +-- iguana/iguana_exchanges.c | 23 ++++++++++++++--------- iguana/iguana_instantdex.c | 35 +++++++++++++++++++++-------------- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c index 8cd770729..6d0274ac0 100644 --- a/iguana/SuperNET.c +++ b/iguana/SuperNET.c @@ -566,8 +566,7 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,uint64_t destipbits,bits256 { char str[65]; printf("duplicate hex.(%s) for %s\n",hexmsg,bits256_str(str,categoryhash)); return(clonestr("{\"error\":\"duplicate packet rejected\"}")); - } - else SuperNET_hexmsgadd(myinfo,categoryhash,subhash,hexmsg,tai_now(),0); + } else SuperNET_hexmsgadd(myinfo,categoryhash,subhash,hexmsg,tai_now(),0); jsonstr = jprint(json,1); if ( broadcastflag != 0 || destipbits == 0 ) { @@ -643,7 +642,7 @@ int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp, char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr) { char hexbuf[8192]; bits256 category,subhash; - int32_t hexlen,destflag,maxdelay,flag=0; uint32_t destipbits,timestamp; cJSON *retjson; + int32_t hexlen,destflag,maxdelay,flag=0,newflag=0; uint32_t destipbits,timestamp; cJSON *retjson; char *forwardstr=0,*retstr=0,*agent=0,*method=0,*message,*hexmsg=0,*jsonstr=0; uint64_t tag; //printf("SuperNET_JSON.(%s)\n",jprint(json,0)); if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 ) @@ -684,9 +683,10 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr) { if ( hexmsg != 0 ) { - //printf("check.(%s)\n",hexmsg); if ( SuperNET_hexmsgfind(myinfo,category,subhash,hexmsg,0) < 0 ) { + //printf("add.(%s)\n",hexmsg); + newflag = 1; SuperNET_hexmsgadd(myinfo,category,subhash,hexmsg,tai_now(),remoteaddr); forwardstr = SuperNET_forward(myinfo,hexmsg,destipbits,category,subhash,maxdelay,juint(json,"broadcast"),juint(json,"plaintext")!=0); } diff --git a/iguana/SuperNET_hexmsg.c b/iguana/SuperNET_hexmsg.c index cfe2108c9..cb9c280f0 100644 --- a/iguana/SuperNET_hexmsg.c +++ b/iguana/SuperNET_hexmsg.c @@ -26,7 +26,7 @@ int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits25 if ( bits256_nonz(subhash) == 0 ) subhash = GENESIS_PUBKEY; packethash = curve25519(category,packethash); - //printf("addflag.%d packethash.%llx dest.%llx\n",addflag,(long long)packethash.txid,(long long)category.txid); + printf("addflag.%d packethash.%llx dest.%llx\n",addflag,(long long)packethash.txid,(long long)category.txid); for (i=0; i exchange->lastpoll+exchange->pollgap ) { + if ( strcmp(exchange->name,"bitcoin") == 0 ) + { + instantdex_update(SuperNET_MYINFO(0)); + //printf("InstantDEX call update\n"); + } if ( (req= queue_dequeue(&exchange->pricesQ,0)) != 0 ) { //printf("check %s pricesQ (%s %s)\n",exchange->name,req->base,req->rel); @@ -962,7 +967,7 @@ THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfie struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qprices(ptr,base,rel,juint(json,"maxseconds"),allfields,depth,json,0,ptr->commission)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -974,7 +979,7 @@ THREE_STRINGS_AND_THREE_DOUBLES(InstantDEX,buy,exchange,base,rel,price,volume,do struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qtrade(ptr,base,rel,juint(json,"maxseconds"),dotrade,1,price,volume,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -986,7 +991,7 @@ THREE_STRINGS_AND_THREE_DOUBLES(InstantDEX,sell,exchange,base,rel,price,volume,d struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qtrade(ptr,base,rel,juint(json,"maxseconds"),dotrade,-1,price,volume,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -998,7 +1003,7 @@ THREE_STRINGS_AND_DOUBLE(InstantDEX,withdraw,exchange,base,destaddr,amount) struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qrequest(ptr,'W',base,0,juint(json,"maxseconds"),0,destaddr,amount,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -1010,7 +1015,7 @@ TWO_STRINGS(InstantDEX,balance,exchange,base) struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qrequest(ptr,'B',base,0,juint(json,"maxseconds"),0,0,0,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -1022,7 +1027,7 @@ TWO_STRINGS(InstantDEX,orderstatus,exchange,orderid) struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qrequest(ptr,'P',0,0,juint(json,"maxseconds"),calc_nxt64bits(orderid),0,0,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -1034,7 +1039,7 @@ TWO_STRINGS(InstantDEX,cancelorder,exchange,orderid) struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qrequest(ptr,'C',0,0,juint(json,"maxseconds"),calc_nxt64bits(orderid),0,0,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -1046,7 +1051,7 @@ STRING_ARG(InstantDEX,openorders,exchange) struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qrequest(ptr,'O',0,0,juint(json,"maxseconds"),0,0,0,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); @@ -1058,7 +1063,7 @@ STRING_ARG(InstantDEX,tradehistory,exchange) struct exchange_info *ptr; if ( remoteaddr == 0 ) { - instantdex_update(myinfo); + //instantdex_update(myinfo); if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 ) return(exchanges777_Qrequest(ptr,'H',0,0,juint(json,"maxseconds"),0,0,0,json)); else return(clonestr("{\"error\":\"cant find or create exchange\"}")); diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index ca0df96a3..159f11e79 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -59,6 +59,7 @@ struct instantdex_msghdr *instantdex_msgcreate(struct supernet_info *myinfo,stru otherpubkey = acct777_msgpubkey(data,datalen); timestamp = (uint32_t)time(NULL); acct777_sign(&msg->sig,myinfo->privkey,otherpubkey,timestamp,data,datalen); + printf("signed datalen.%d allocsize.%d\n",datalen,msg->sig.allocsize); if ( (signerbits= acct777_validate(&msg->sig,acct777_msgprivkey(data,datalen),msg->sig.pubkey)) != 0 ) { //int32_t i; @@ -539,13 +540,15 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char *remoteaddr) { - struct instantdex_msghdr *msg = ptr; cJSON *argjson; int32_t i,olen,slen,num,datalen,newlen,flag = 0; - uint8_t *serdata; struct supernet_info *myinfos[64]; struct instantdex_offer rawoffer; bits256 orderhash; - uint64_t signerbits; uint8_t tmp[sizeof(msg->sig)]; char *retstr = 0; cJSON *retjson,*item; + struct instantdex_msghdr *msg = ptr; int32_t i,olen,slen,num,datalen,newlen,flag = 0; + uint8_t *serdata; struct supernet_info *myinfos[64]; struct instantdex_offer rawoffer; + bits256 orderhash; uint64_t signerbits; uint8_t tmp[sizeof(msg->sig)]; char *retstr = 0; + cJSON *retjson,*item,*argjson = 0; acct777_rwsig(0,(void *)&msg->sig,(void *)tmp); memcpy(&msg->sig,tmp,sizeof(msg->sig)); datalen = len - (int32_t)sizeof(msg->sig); serdata = (void *)((long)msg + sizeof(msg->sig)); + //printf("datalen.%d len.%d\n",datalen,len); if ( remoteaddr != 0 && remoteaddr[0] == 0 && strcmp("127.0.0.1",remoteaddr) == 0 && ((uint8_t *)msg)[len-1] == 0 && (argjson= cJSON_Parse((char *)msg)) != 0 ) { printf("string instantdex_hexmsg RESULT.(%s)\n",jprint(argjson,0)); @@ -557,7 +560,7 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char else if ( (signerbits= acct777_validate(&msg->sig,acct777_msgprivkey(serdata,datalen),msg->sig.pubkey)) != 0 ) { flag++; - //printf("InstantDEX_hexmsg <<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(msg->sig),(long)data-(long)msg,datalen,msg->sig.timestamp,msg->sig.allocsize,(char *)msg->serialized,data[datalen-1]); + printf("InstantDEX_hexmsg <<<<<<<<<<<<< sigsize.%ld VALIDATED [%ld] len.%d t%u allocsize.%d (%s) [%d]\n",sizeof(msg->sig),(long)serdata-(long)msg,datalen,msg->sig.timestamp,msg->sig.allocsize,(char *)msg->serialized,serdata[datalen-1]); newlen = (int32_t)(msg->sig.allocsize - sizeof(*msg)); serdata = msg->serialized; if ( (argjson= cJSON_Parse((char *)serdata)) != 0 ) @@ -599,7 +602,7 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char } retstr = jprint(retjson,1); } - } + } else printf("sig err datalen.%d\n",datalen); if ( argjson != 0 ) free_json(argjson); return(retstr); @@ -629,17 +632,21 @@ char *instantdex_queueaccept(struct supernet_info *myinfo,struct exchange_info * void instantdex_update(struct supernet_info *myinfo) { - struct instantdex_msghdr *pm; struct category_msg *m; bits256 instantdexhash; char *str,remote[64]; + struct instantdex_msghdr *pm; struct category_msg *m; int32_t iter; bits256 instantdexhash; char *str,remote[64]; instantdexhash = calc_categoryhashes(0,"InstantDEX",0); - while ( (m= category_gethexmsg(myinfo,instantdexhash,GENESIS_PUBKEY)) != 0 ) + for (iter=0; iter<2; iter++) { - pm = (struct instantdex_msghdr *)m->msg; - if ( m->remoteipbits != 0 ) - expand_ipbits(remote,m->remoteipbits); - else remote[0] = 0; - if ( (str= InstantDEX_hexmsg(myinfo,pm,m->len,remote)) != 0 ) - free(str); - free(m); + while ( (m= category_gethexmsg(myinfo,instantdexhash,iter == 0 ? GENESIS_PUBKEY : myinfo->myaddr.persistent)) != 0 ) + { + printf("gothexmsg len.%d\n",m->len); + pm = (struct instantdex_msghdr *)m->msg; + if ( m->remoteipbits != 0 ) + expand_ipbits(remote,m->remoteipbits); + else remote[0] = 0; + if ( (str= InstantDEX_hexmsg(myinfo,pm,m->len,remote)) != 0 ) + free(str); + free(m); + } } }