From 1e8d675fe8d17e79a20665409421f0774dc6face Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 28 Jun 2016 13:52:07 -0300 Subject: [PATCH] test --- basilisk/basilisk.h | 1 + basilisk/basilisk_DEX.c | 106 ++++++++++++++++++++++++++------------- iguana/iguana_bundles.c | 4 +- iguana/iguana_ramchain.c | 2 +- 4 files changed, 74 insertions(+), 39 deletions(-) diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index d4920bb4f..8a2fea17c 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -53,6 +53,7 @@ struct basilisk_request uint64_t srcamount,destamount; bits256 hash; char src[8],dest[8],message[48]; + uint32_t relaybits; } __attribute__((packed)); struct basilisk_relaystatus diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index ac212b97d..23cdbcf94 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -201,11 +201,14 @@ int32_t basilisk_ping_genDEX(struct supernet_info *myinfo,uint8_t *data,int32_t return(datalen); } -char *basilisk_respond_incoming(struct supernet_info *myinfo,bits256 hash,uint32_t requestid,uint32_t quoteid) +struct basilisk_request *_basilisk_requests_uniq(struct supernet_info *myinfo,int32_t *nump,uint8_t *space,int32_t spacesize) { - int32_t i,j,n,k,m; struct basilisk_relay *relay; cJSON *retjson,*array; struct basilisk_request requests[BASILISK_MAXRELAYS],*rp; - array = cJSON_CreateArray(); - portable_mutex_lock(&myinfo->DEX_reqmutex); + int32_t i,j,n,k,m; struct basilisk_relay *relay; struct basilisk_request *requests,*rp; + for (j=m=0; jnumrelays; j++) + m += myinfo->relays[j].numrequests; + if ( m*sizeof(*requests) <= spacesize ) + requests = (void *)space; + else requests = calloc(m,sizeof(*requests)); for (j=m=0; jnumrelays; j++) { relay = &myinfo->relays[j]; @@ -214,21 +217,38 @@ char *basilisk_respond_incoming(struct supernet_info *myinfo,bits256 hash,uint32 for (i=0; irequests[i]; - if ( (requestid == 0 || rp->requestid == requestid) && ((quoteid == 0 && rp->quoteid != 0) || quoteid == rp->quoteid) ) + for (k=0; kipbits,rp)); - } + requests[m].relaybits = relay->ipbits; + requests[m++] = *rp; } } } } + *nump = m; + return(requests); +} + +char *basilisk_respond_requests(struct supernet_info *myinfo,bits256 hash,uint32_t requestid,uint32_t quoteid) +{ + int32_t i,num=0; cJSON *retjson,*array; struct basilisk_request *requests,*rp; uint8_t space[16384]; + array = cJSON_CreateArray(); + portable_mutex_lock(&myinfo->DEX_reqmutex); + if ( (requests= _basilisk_requests_uniq(myinfo,&num,space,sizeof(space))) != 0 ) + { + for (i=0; irequestid == requestid) && ((quoteid == 0 && rp->quoteid != 0) || quoteid == rp->quoteid) ) + jaddi(array,basilisk_requestjson(rp->relaybits,rp)); + } + } portable_mutex_unlock(&myinfo->DEX_reqmutex); + if ( requests != (void *)space ) + free(requests); retjson = cJSON_CreateObject(); jadd(retjson,"result",array); return(jprint(retjson,1)); @@ -236,36 +256,33 @@ char *basilisk_respond_incoming(struct supernet_info *myinfo,bits256 hash,uint32 char *basilisk_respond_choose(struct supernet_info *myinfo,bits256 hash,uint32_t requestid,uint64_t destamount) { - int32_t i,n,j,alreadythere = 0; uint32_t quoteid; char *retstr; struct basilisk_relay *relay; struct basilisk_request *rp=0; + int32_t i,num=0,alreadythere = 0; uint32_t quoteid; char *retstr; struct basilisk_request *requests,*rp,*resprp=0; uint8_t space[16384]; quoteid = (requestid ^ hash.uints[0]); portable_mutex_lock(&myinfo->DEX_reqmutex); - for (j=0; jnumrelays; j++) + if ( (requests= _basilisk_requests_uniq(myinfo,&num,space,sizeof(space))) != 0 ) { - relay = &myinfo->relays[j]; - if ( (n= relay->numrequests) > 0 ) + for (i=0; irequestid == requestid ) { - if ( relay->requests[i].requestid == requestid ) + if ( rp->quoteid == 0 ) + resprp = rp; + else if ( rp->quoteid == quoteid ) { - if ( relay->requests[i].quoteid == 0 ) - rp = &relay->requests[i]; - else if ( relay->requests[i].quoteid == quoteid ) - { - alreadythere = 1; - break; - } + alreadythere = 1; + break; } } } - if ( alreadythere != 0 ) - break; } + if ( requests != (void *)space ) + free(requests); if ( alreadythere == 0 ) { - if ( rp == 0 ) + if ( resprp == 0 ) retstr = clonestr("{\"error\":\"couldnt find to requestid to choose\"}"); - else retstr = basilisk_choose(myinfo,hash,rp,destamount,quoteid); + else retstr = basilisk_choose(myinfo,hash,resprp,destamount,quoteid); } else retstr = clonestr("{\"result\":\"quoteid already there\"}"); portable_mutex_unlock(&myinfo->DEX_reqmutex); return(retstr); @@ -275,12 +292,12 @@ char *basilisk_respond_choose(struct supernet_info *myinfo,bits256 hash,uint32_t char *basilisk_respond_RID(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { - return(basilisk_respond_incoming(myinfo,hash,juint(valsobj,"requestid"),0)); + return(basilisk_respond_requests(myinfo,hash,juint(valsobj,"requestid"),0)); } char *basilisk_respond_QID(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { - return(basilisk_respond_incoming(myinfo,hash,juint(valsobj,"requestid"),juint(valsobj,"quoteid"))); + return(basilisk_respond_requests(myinfo,hash,juint(valsobj,"requestid"),juint(valsobj,"quoteid"))); } char *basilisk_respond_CHS(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) @@ -348,7 +365,7 @@ INT_ARG(InstantDEX,incoming,requestid) { cJSON *vals; char *retstr; if ( myinfo->RELAYID >= 0 ) - return(basilisk_respond_incoming(myinfo,myinfo->myaddr.persistent,requestid,0)); + return(basilisk_respond_requests(myinfo,myinfo->myaddr.persistent,requestid,0)); else { vals = cJSON_CreateObject(); @@ -364,7 +381,7 @@ TWO_INTS(InstantDEX,qstatus,requestid,quoteid) { cJSON *vals; char *retstr; if ( myinfo->RELAYID >= 0 ) - return(basilisk_respond_incoming(myinfo,myinfo->myaddr.persistent,requestid,quoteid)); + return(basilisk_respond_requests(myinfo,myinfo->myaddr.persistent,requestid,quoteid)); else { vals = cJSON_CreateObject(); @@ -403,10 +420,8 @@ INT_AND_DOUBLE(InstantDEX,choose,requestid,destamount) return(retstr); } } - #include "../includes/iguana_apiundefs.h" - int32_t basilisk_request_pending(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t requestid) { int32_t i,j,n,alreadystarted = 0; struct basilisk_relay *relay; uint32_t quoteid; @@ -447,3 +462,22 @@ void basilisk_request_check(struct supernet_info *myinfo,struct basilisk_request } } +void basilisk_requests_poll(struct supernet_info *myinfo) +{ + char *retstr; cJSON *retjson,*array,*item; int32_t i,n; + if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (array= jarray(&n,retjson,"result")) != 0 ) + { + for (i=0; ihdrsi,i); - iguana_blockunmark(coin,block,bp,i,0); + iguana_blockunmark(coin,block,bp,i,bp->queued != 0); if ( bp->queued != 0 ) { - printf("error getting block (%d:%d) %p\n",bp->hdrsi,i,block); + //printf("error getting block (%d:%d) %p\n",bp->hdrsi,i,block); return(-1); } } diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 2424a511e..32be16772 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -2561,7 +2561,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi } iguana_blockzcopyRO(coin->chain->zcash,destB,i,&block->RO,0); //destB[i] = block->RO; - } else printf("error getting block (%d:%d) %p vs %p\n",bp->hdrsi,i,block,bp->blocks[i]); + } else printf("bundlesave error getting block (%d:%d) %p vs %p\n",bp->hdrsi,i,block,bp->blocks[i]); } dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti; dest->externalind = dest->H.stacksize = 0;