From 29c1ea07f204512453d6a5f65d1bdc5f420b7972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 3 Sep 2016 08:49:41 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 2 +- basilisk/basilisk_DEX.c | 23 +++++++++++---- basilisk/basilisk_MSG.c | 62 ++++++++++++++++++++++++++--------------- iguana/iguana777.h | 2 +- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 6211bd77f..43c30a9df 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -561,7 +561,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi jaddi(pending->retarray,item); if ( jobj(item,"error") == 0 ) { - printf("numresults.%d (%s)\n",pending->numresults,jprint(item,0)); + //printf("numresults.%d (%s)\n",pending->numresults,jprint(item,0)); pending->numresults++; } } else printf("couldnt parse.(%s)\n",retstr); diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index cb42ebfb2..d09a550b5 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -514,19 +514,32 @@ int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int INT_ARG(InstantDEX,incoming,requestid) { - cJSON *retjson,*retarray; uint32_t DEX_channel,msgid; int32_t retval; uint8_t data[8192]; - myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; + cJSON *retjson,*retarray; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192]; + now = (uint32_t)time(NULL); + width = (now - myinfo->DEXpoll); + //if ( width < (drift+1) ) + // width = 2*drift+1; + //else if ( width > 64 ) + width = 64; + myinfo->DEXpoll = now; + myinfo->DEXactive = now + INSTANTDEX_LOCKTIME; retjson = cJSON_CreateObject(); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); - msgid = (uint32_t)time(NULL) + 3; - if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,DEX_channel,msgid,64)) != 0 ) + msgid = (uint32_t)time(NULL) + drift; + if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 ) { + //printf("GOT.(%s)\n",jprint(retarray,0)); if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 ) { jaddstr(retjson,"result","success"); } else jaddstr(retjson,"error","cant process InstantDEX retarray"); jadd(retjson,"responses",retarray); - } else jaddstr(retjson,"error","cant do InstantDEX channelget"); + } + else + { + jaddstr(retjson,"error","cant do InstantDEX channelget"); + printf("error channelget\n"); + } return(jprint(retjson,1)); } diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 5af6d53a5..5424e47ca 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -57,14 +57,21 @@ cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int msgjson = cJSON_CreateObject(); if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) { - jaddnum(msgjson,"expiration",msg->expiration); - jaddnum(msgjson,"duration",msg->duration); - {int32_t i; for (i=0; idatalen,strbuf); } + if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),key,keylen) != 0 ) + { + jaddnum(msgjson,"expiration",msg->expiration); + jaddnum(msgjson,"duration",msg->duration); + } + else + { + printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr key\n"); + free_json(msgjson); + msgjson = 0; + } } else { - printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr\n"); + printf("basilisk_respond_getmessage: couldnt basilisk_addhexstr data.[%d]\n",msg->datalen); free_json(msgjson); msgjson = 0; } @@ -150,7 +157,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha width = juint(valsobj,"width"); msgid = juint(valsobj,"msgid"); channel = juint(valsobj,"channel"); - char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,hash),juint(valsobj,"channel"),msgid,width); + //char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,hash),juint(valsobj,"channel"),msgid,width); return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"sender"),hash,width)); } @@ -218,22 +225,27 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t return(retval); } -int32_t basilisk_message_returned(uint8_t *data,int32_t maxlen,cJSON *item) +int32_t basilisk_message_returned(uint8_t *key,uint8_t *data,int32_t maxlen,cJSON *json) { - char *hexstr=0; cJSON *msgobj; int32_t datalen=0,retval = -1; - if ( (msgobj= jobj(item,"message")) != 0 ) + char *keystr=0,*hexstr=0; int32_t i,n,datalen=0,retval = -1; cJSON *item,*msgobj; + if ( (msgobj= jarray(&n,json,"messages")) != 0 ) { - if ( (hexstr= jstr(msgobj,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 ) + for (i=0; i>= 1; - if ( datalen < maxlen ) + item = jitem(msgobj,i); + if ( (keystr= jstr(item,"key")) != 0 && is_hexstr(keystr,0) == BASILISK_KEYSIZE && (hexstr= jstr(item,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 ) { - decode_hex(data,datalen,hexstr); - //printf("decoded hexstr.[%d]\n",datalen); - retval = datalen; - } else printf("datalen.%d < maxlen.%d\n",datalen,maxlen); - } else printf("no hexstr.%p or datalen.%d\n",hexstr,datalen); - } //else printf("no msgobj\n"); + decode_hex(key,BASILISK_KEYSIZE,keystr); + datalen >>= 1; + if ( datalen < maxlen ) + { + decode_hex(data,datalen,hexstr); + //printf("decoded hexstr.[%d]\n",datalen); + retval = datalen; + } else printf("datalen.%d < maxlen.%d\n",datalen,maxlen); + } + } + }else printf("no hexstr.%p or datalen.%d (%s)\n",hexstr,datalen,jprint(json,0)); return(retval); } @@ -269,20 +281,26 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t (*process_func)(struct supernet_info *myinfo,void *ptr,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen),uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t expiration,uint32_t duration),uint8_t *data,int32_t maxlen,uint32_t channel,uint32_t msgid,cJSON *retarray,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)) { - cJSON *item; uint32_t duration,expiration; int32_t i,n,datalen,errs = 0; + cJSON *item; uint32_t duration,expiration; char *retstr; uint8_t key[BASILISK_KEYSIZE]; int32_t i,n,datalen,errs = 0; if ( (n= cJSON_GetArraySize(retarray)) > 0 ) { for (i=0; i 0 ) + //printf("(%s).%d ",jprint(item,0),i); + if ( (datalen= basilisk_message_returned(key,data,maxlen,item)) > 0 ) { duration = juint(item,"duration"); expiration = juint(item,"expiration"); - if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) - errs++; + if ( (retstr= basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,data,datalen,0,duration)) != 0 ) + { + if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 ) + errs++; + free(retstr); + } } } + //printf("n.%d maxlen.%d\n",n,maxlen); } if ( errs > 0 ) return(-errs); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 7768f23ef..37f45c013 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -65,7 +65,7 @@ struct supernet_info char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; char *decryptstr; int32_t maxdelay,IAMRELAY,IAMLP,publicRPC,basilisk_busy,genesisresults; - uint32_t expiration,dirty,DEXactive; + uint32_t expiration,dirty,DEXactive,DEXpoll; uint16_t argport,rpcport; struct basilisk_info basilisks; struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges;