jl777 8 years ago
parent
commit
91f2ddc0e9
  1. 18
      basilisk/basilisk_DEX.c
  2. 11
      basilisk/basilisk_swap.c

18
basilisk/basilisk_DEX.c

@ -271,6 +271,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
} }
free(retstr); free(retstr);
} else printf("null incoming\n"); } else printf("null incoming\n");
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
if ( hwm > 0. ) if ( hwm > 0. )
{ {
printf("hwm %f\n",hwm); printf("hwm %f\n",hwm);
@ -279,8 +280,20 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
printf("my req hwm %f\n",hwm); printf("my req hwm %f\n",hwm);
if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 ) if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
free(retstr); free(retstr);
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 ) basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
free(retstr); numiters = 0;
while ( numiters < 10 && (crc= basilisk_swapcrcsend(myinfo,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");
sleep(3);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
numiters++;
}
if ( crc != 0 )
{
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
} else printf("couldnt accept offer\n");
} }
else //if ( issueR.quoteid == 0 ) else //if ( issueR.quoteid == 0 )
{ {
@ -289,7 +302,6 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
issueR.desthash = myinfo->myaddr.persistent; issueR.desthash = myinfo->myaddr.persistent;
datalen = basilisk_rwDEXquote(1,data,&issueR); datalen = basilisk_rwDEXquote(1,data,&issueR);
msgid = (uint32_t)time(NULL); msgid = (uint32_t)time(NULL);
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
crcs[0] = crcs[1] = 0; crcs[0] = crcs[1] = 0;
numiters = 0; numiters = 0;
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2); basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);

11
basilisk/basilisk_swap.c

@ -1806,10 +1806,10 @@ void basilisk_swaploop(void *_swap)
data = malloc(maxlen); data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + 600; expiration = (uint32_t)time(NULL) + 600;
myinfo->DEXactive = expiration; myinfo->DEXactive = expiration;
basilisk_sendstate(myinfo,swap,data,maxlen);
while ( (swap->I.statebits & (0x08|0x02)) != (0x08|0x02) && time(NULL) < expiration ) while ( (swap->I.statebits & (0x08|0x02)) != (0x08|0x02) && time(NULL) < expiration )
{ {
printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits);
basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys
if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02 if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02
basilisk_sendchoosei(myinfo,swap,data,maxlen); basilisk_sendchoosei(myinfo,swap,data,maxlen);
@ -1924,7 +1924,7 @@ void basilisk_swaploop(void *_swap)
struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration) struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration)
{ {
int32_t i; uint8_t data[64]; struct basilisk_swap *swap = 0; int32_t i; uint32_t channel; cJSON *retarray; struct basilisk_swap *swap = 0;
portable_mutex_lock(&myinfo->DEX_swapmutex); portable_mutex_lock(&myinfo->DEX_swapmutex);
for (i=0; i<myinfo->numswaps; i++) for (i=0; i<myinfo->numswaps; i++)
if ( myinfo->swaps[i]->I.req.requestid == rp->requestid ) if ( myinfo->swaps[i]->I.req.requestid == rp->requestid )
@ -1945,8 +1945,11 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct
{ {
printf("waiting for offer to be accepted\n"); printf("waiting for offer to be accepted\n");
sleep(3); sleep(3);
if ( basilisk_swapget(myinfo,swap,0,data,sizeof(data),basilisk_verify_otherstatebits) == sizeof(statebits) ) channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
statebits = swap->I.otherstatebits; if ( (retarray= basilisk_channelget(myinfo,rp->srchash,rp->desthash,channel,0x4000000,30)) != 0 )
{
printf("RETARRAY.(%s)\n",jprint(retarray,0));
}
} }
fprintf(stderr,"launch.%d %d\n",myinfo->numswaps,(int32_t)(sizeof(myinfo->swaps)/sizeof(*myinfo->swaps))); fprintf(stderr,"launch.%d %d\n",myinfo->numswaps,(int32_t)(sizeof(myinfo->swaps)/sizeof(*myinfo->swaps)));
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 )

Loading…
Cancel
Save