diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 78167aa58..e993d42c6 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -231,18 +231,32 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2 char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) { - cJSON *retjson; struct basilisk_request *rp; + cJSON *retjson; struct basilisk_request *rp=0; int32_t i; if ( (bits256_cmp(_rp->srchash,myinfo->myaddr.persistent) == 0 || bits256_cmp(_rp->desthash,myinfo->myaddr.persistent) == 0) ) { - rp = calloc(1,sizeof(*rp)); - *rp = *_rp; - printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); - if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) + for (i=0; inumswaps; i++) + if ( myinfo->swaps[i]->I.req.requestid == _rp->requestid ) + { + printf("basilisk_thread_start error trying to start requestid.%u which is already started\n",rp->requestid); + break; + } + if ( i == myinfo->numswaps ) + { + rp = calloc(1,sizeof(*rp)); + *rp = *_rp; + printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); + if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) + { + basilisk_request_enqueue(myinfo,rp); + return(clonestr("{\"result\":\"started atomic swap thread\"}")); + } + else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); + } + else { - basilisk_request_enqueue(myinfo,rp); - return(clonestr("{\"result\":\"started atomic swap thread\"}")); + printf("trying to start already pending swap.r%u\n",rp->requestid); + return(clonestr("{\"error\":\"cant start pending swap\"}")); } - else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); } else if ( myinfo->IAMLP != 0 ) { @@ -296,7 +310,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) free(retstr); printf("my req hwm %f -> %u\n",hwm,issueR.requestid); basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60); - numiters = 0; + numiters = crc = 0; /*while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 ) { printf("didnt get back what was sent\n"); @@ -306,7 +320,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) } if ( crc != 0 )*/ { - //printf("crc.%08x -> basilisk_starta\n",crc); + printf("crc.%08x -> basilisk_starta\n",crc); if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 ) free(retstr); } // else printf("couldnt accept offer\n"); diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index f483d8afe..56f7cd592 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -329,15 +329,16 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits25 jaddnum(valsobj,"channel",channel); if ( msgid == 0 ) msgid = (uint32_t)time(NULL); - jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); + jaddnum(valsobj,"fanout",1);//MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"duration",duration); jaddnum(valsobj,"timeout",1000); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); - //char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS); + char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS); if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,desthash,valsobj,hexstr)) != 0 ) free(retstr); + printf("message sent\n"); free_json(valsobj); if ( ptr != 0 ) free(ptr); @@ -380,7 +381,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"width",width); jaddnum(valsobj,"timeout",BASILISK_TIMEOUT); - jaddnum(valsobj,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(valsobj,"fanout",1);//MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); jaddnum(valsobj,"numrequired",1); jaddbits256(valsobj,"srchash",srchash); jaddbits256(valsobj,"desthash",desthash); diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 1930091e3..597f1f576 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -1874,7 +1874,7 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct } if ( i == myinfo->numswaps && i < sizeof(myinfo->swaps)/sizeof(*myinfo->swaps) ) { - printf("basilisk_thread_start request.%u\n",rp->requestid); + printf("basilisk_thread_start request.%u statebits.%d\n",rp->requestid,statebits); swap = calloc(1,sizeof(*swap)); vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); swap->I.req = *rp; @@ -1909,7 +1909,7 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct } } else printf("no retarray\n"); } - if ( statebits != 0 || m > n/2 ) + if ( statebits != 0 || m > 0 )//n/2 ) { //for (i=0; iI.req); i++) // fprintf(stderr,"%02x",((uint8_t *)&swap->I.req)[i]); @@ -1919,7 +1919,7 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct } myinfo->swaps[myinfo->numswaps++] = swap; - } else printf("%u/%u offer wasnt accepted\n",rp->requestid,rp->quoteid); + } else printf("%u/%u offer wasnt accepted statebits.%d m.%d n.%d\n",rp->requestid,rp->quoteid,statebits,m,n); } } portable_mutex_unlock(&myinfo->DEX_swapmutex); diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 095b28b18..b285c4565 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -355,7 +355,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 // printf("%02x",((uint8_t *)data)[i]); if ( (recvbytes= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->reqsock,&retptr)) >= 0 ) { - //printf("req returned.[%d]\n",recvbytes); + printf("req returned.[%d]\n",recvbytes); portable_mutex_lock(&myinfo->dexmutex); ipbits = 0; if ( strcmp(handler,"DEX") == 0 ) @@ -394,7 +394,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); } } - if ( (rand() % 100) < 4 ) + if ( (rand() % 100) < 0 ) { nanomsg_tcpname(0,str,ipaddr,REP_SOCK); nn_connect(myinfo->reqsock,str);