Browse Source

crcsend

dPoW2
jl777 8 years ago
parent
commit
17e2fa58f4
  1. 91
      basilisk/basilisk.c
  2. 4
      basilisk/basilisk.h
  3. 60
      basilisk/basilisk_DEX.c
  4. 63
      basilisk/basilisk_MSG.c
  5. 2
      basilisk/basilisk_bitcoin.c
  6. 133
      basilisk/basilisk_swap.c
  7. 1
      basilisk/basilisk_tradebot.c
  8. 2
      iguana/iguana_peers.c

91
basilisk/basilisk.c

@ -17,6 +17,48 @@
typedef char *basilisk_servicefunc(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);
uint32_t basilisk_majority32(int32_t *datalenp,uint32_t rawcrcs[64],int32_t datalens[64],int32_t numcrcs)
{
int32_t tally[64],candlens[64],i,j,mintally,numcandidates = 0; uint32_t candidates[64];
*datalenp = 0;
mintally = (numcrcs >> 1) + 1;
memset(tally,0,sizeof(tally));
memset(candlens,0,sizeof(candlens));
memset(candidates,0,sizeof(candidates));
if ( numcrcs > 0 )
{
for (i=0; i<numcrcs; i++)
{
for (j=0; j<numcandidates; j++)
{
if ( rawcrcs[i] == candidates[j] && datalens[i] == candlens[j] )
{
tally[j]++;
break;
}
}
if ( j == numcandidates )
{
tally[numcandidates] = 1;
candlens[numcandidates] = datalens[i];
candidates[numcandidates] = rawcrcs[i];
numcandidates++;
}
}
if ( numcandidates > 0 )
{
for (j=0; j<numcandidates; j++)
if ( tally[j] >= mintally )
{
*datalenp = candlens[j];
printf("tally[%d] >= mintally.%d numcrcs.%d crc %08x datalen.%d\n",j,mintally,numcrcs,candidates[j],*datalenp);
return(candidates[j]);
}
}
}
return(0);
}
int32_t basilisk_notarycmd(char *cmd)
{
//&& strcmp(cmd,"DEX") != 0 && strcmp(cmd,"ACC") != 0 && strcmp(cmd,"RID") != 0 &&
@ -835,55 +877,6 @@ void basilisk_p2p(struct supernet_info *myinfo,struct iguana_info *coin,struct i
queue_enqueue("p2pQ",&myinfo->p2pQ,ptr,0);
}
void basilisk_requests_poll(struct supernet_info *myinfo)
{
static uint32_t lastpoll;
char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.;
if ( time(NULL) < lastpoll+3 )
return;
lastpoll = (uint32_t)time(NULL);
memset(&issueR,0,sizeof(issueR));
//printf("Call incoming\n");
if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 )
{
//printf("poll.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (outerarray= jarray(&n,retjson,"responses")) != 0 )
{
for (i=0; i<n; i++)
hwm = basilisk_process_results(myinfo,&issueR,jitem(outerarray,i),hwm);
} //else hwm = basilisk_process_results(myinfo,&issueR,outerarray,hwm);
free_json(retjson);
}
free(retstr);
} else printf("null incoming\n");
if ( hwm > 0. )
{
printf("hwm %f\n",hwm);
if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request
{
printf("my req hwm %f\n",hwm);
if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
free(retstr);
if ( (retstr= basilisk_start(myinfo,&issueR,1)) != 0 )
free(retstr);
}
else //if ( issueR.quoteid == 0 )
{
printf("other req hwm %f >>>>>>>>>>> send response (%llx -> %llx)\n",hwm,(long long)issueR.desthash.txid,(long long)issueR.srchash.txid);
issueR.quoteid = basilisk_quoteid(&issueR);
issueR.desthash = myinfo->myaddr.persistent;
datalen = basilisk_rwDEXquote(1,data,&issueR);
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16),(uint32_t)time(NULL),data,datalen,0);
sleep(60);
printf("start swap\n");
if ( (retstr= basilisk_start(myinfo,&issueR,0)) != 0 )
free(retstr);
} //else printf("basilisk_requests_poll unexpected hwm issueR\n");
}
}
int32_t basilisk_issued_purge(struct supernet_info *myinfo,int32_t timepad)
{
struct basilisk_item *tmp,*pending; cJSON *item; int32_t i,n = 0; double startmilli = OS_milliseconds();

4
basilisk/basilisk.h

@ -48,7 +48,7 @@ struct basilisk_rawtx
struct iguana_info *coin;
uint64_t amount,change,inputsum;
int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys;
uint32_t locktime;
uint32_t locktime,crcs[2];
char destaddr[64],name[32];
uint8_t addrtype,pubkey33[33],spendscript[512],redeemscript[1024],rmd160[20];
uint8_t *txbytes,extraspace[1024];
@ -65,10 +65,12 @@ struct basilisk_swap
bits256 privkeys[INSTANTDEX_DECKSIZE],myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint32_t crcs_mypub[2],crcs_mychoosei[2],crcs_myprivs[2],crcs_mypriv[2];
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate;
uint8_t secretAm[20],secretBn[20];
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
uint8_t verifybuf[65536];
};
struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; };

60
basilisk/basilisk_DEX.c

@ -244,6 +244,66 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,ui
} else return(clonestr("{\"error\":\"unexpected basilisk_start not mine and amrelay\"}"));
}
void basilisk_requests_poll(struct supernet_info *myinfo)
{
static uint32_t lastpoll;
char *retstr; uint8_t data[32768],buf[4096]; cJSON *outerarray,*retjson; uint32_t msgid,crcs[2],crc,channel; int32_t datalen,i,n,numiters; struct basilisk_request issueR; double hwm = 0.;
if ( time(NULL) < lastpoll+3 )
return;
lastpoll = (uint32_t)time(NULL);
memset(&issueR,0,sizeof(issueR));
//printf("Call incoming\n");
if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 )
{
//printf("poll.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (outerarray= jarray(&n,retjson,"responses")) != 0 )
{
for (i=0; i<n; i++)
hwm = basilisk_process_results(myinfo,&issueR,jitem(outerarray,i),hwm);
} //else hwm = basilisk_process_results(myinfo,&issueR,outerarray,hwm);
free_json(retjson);
}
free(retstr);
} else printf("null incoming\n");
if ( hwm > 0. )
{
printf("hwm %f\n",hwm);
if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request
{
printf("my req hwm %f\n",hwm);
if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
free(retstr);
if ( (retstr= basilisk_start(myinfo,&issueR,1)) != 0 )
free(retstr);
}
else //if ( issueR.quoteid == 0 )
{
printf("other req hwm %f >>>>>>>>>>> send response (%llx -> %llx)\n",hwm,(long long)issueR.desthash.txid,(long long)issueR.srchash.txid);
issueR.quoteid = basilisk_quoteid(&issueR);
issueR.desthash = myinfo->myaddr.persistent;
datalen = basilisk_rwDEXquote(1,data,&issueR);
msgid = (uint32_t)time(NULL);
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
crcs[0] = crcs[1] = 0;
numiters = 0;
while ( numiters < 10 && (crc= basilisk_swapcrcsend(myinfo,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 )
{
printf("didnt get back what was sent\n");
sleep(3);
numiters++;
}
if ( crc != 0 )
{
printf("crc.%08x -> basilisk_start\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,0)) != 0 )
free(retstr);
}
} //else printf("basilisk_requests_poll unexpected hwm issueR\n");
}
}
struct basilisk_relay *basilisk_request_ensure(struct supernet_info *myinfo,uint32_t senderipbits,int32_t numrequests)
{
int32_t j; struct basilisk_relay *relay = 0;

63
basilisk/basilisk_MSG.c

@ -184,33 +184,43 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
duration = INSTANTDEX_LOCKTIME*2;
portable_mutex_lock(&myinfo->messagemutex);
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg);
if ( msg == 0 )//|| msg->datalen != datalen )
if ( msg != 0 )
{
if ( msg != 0 )
if ( msg->datalen != datalen )
{
printf("overwrite delete of msg.[%d]\n",msg->datalen);
HASH_DELETE(hh,myinfo->messagetable,msg);
QUEUEITEMS--;
free(msg);
msg = 0;
}
msg = calloc(1,sizeof(*msg) + datalen);
msg->keylen = keylen;
memcpy(msg->key,key,keylen);
msg->datalen = datalen;
memcpy(msg->data,data,datalen);
memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash));
if ( bits256_nonz(desthash) == 0 )
msg->broadcast = 1;
msg->duration = duration;
msg->expiration = (uint32_t)time(NULL) + duration;
HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg);
QUEUEITEMS++;
for (i=0; i<BASILISK_KEYSIZE; i++)
printf("%02x",key[i]);
printf(" <- ADDMSG.[%d] exp %u %p (%p %p)\n",QUEUEITEMS,msg->expiration,msg,msg->hh.next,msg->hh.prev);
if ( sendping != 0 )
queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0);
} //else memcpy(msg->data,data,datalen);
else
{
printf("overwrite update of msg.[%d]\n",msg->datalen);
memcpy(msg->data,data,datalen);
if ( sendping != 0 )
queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0);
portable_mutex_unlock(&myinfo->messagemutex);
return(clonestr("{\"result\":\"message updated\"}"));
}
}
msg = calloc(1,sizeof(*msg) + datalen);
msg->keylen = keylen;
memcpy(msg->key,key,keylen);
msg->datalen = datalen;
memcpy(msg->data,data,datalen);
memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash));
if ( bits256_nonz(desthash) == 0 )
msg->broadcast = 1;
msg->duration = duration;
msg->expiration = (uint32_t)time(NULL) + duration;
HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg);
QUEUEITEMS++;
for (i=0; i<BASILISK_KEYSIZE; i++)
printf("%02x",key[i]);
printf(" <- ADDMSG.[%d] exp %u %p (%p %p)\n",QUEUEITEMS,msg->expiration,msg,msg->hh.next,msg->hh.prev);
if ( sendping != 0 )
queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0);
portable_mutex_unlock(&myinfo->messagemutex);
return(clonestr("{\"result\":\"message added to hashtable\"}"));
}
@ -377,12 +387,14 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256
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; char *retstr; uint8_t key[BASILISK_KEYSIZE]; 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,havedata = 0,errs = 0;
if ( (n= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(retarray,i);
if ( jobj(item,"error") != 0 )
continue;
//printf("(%s).%d ",jprint(item,0),i);
if ( (datalen= basilisk_message_returned(key,data,maxlen,item)) > 0 )
{
@ -392,13 +404,16 @@ int32_t basilisk_process_retarray(struct supernet_info *myinfo,void *ptr,int32_t
{
if ( (*process_func)(myinfo,ptr,internal_func,channel,msgid,data,datalen,expiration,duration) < 0 )
errs++;
free(retstr);
else havedata++;
free(retstr);
} // else printf("duplicate.%d skipped\n",datalen);
}
}
//printf("n.%d maxlen.%d\n",n,maxlen);
}
if ( errs > 0 )
if ( havedata == 0 )
return(-1);
else if ( errs > 0 )
return(-errs);
else return(n);
else return(havedata);
}

2
basilisk/basilisk_bitcoin.c

@ -624,7 +624,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
*/
#ifdef later
#ifdef oldway
int32_t instantdex_feetxverify(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_swap *swap,cJSON *argjson)
{

133
basilisk/basilisk_swap.c

@ -459,26 +459,112 @@ int32_t basilisk_verify_privi(struct supernet_info *myinfo,void *ptr,uint8_t *da
return(-1);
}
int32_t basilisk_process_swapget(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)
uint32_t basilisk_swaprecv(struct supernet_info *myinfo,uint8_t *verifybuf,int32_t maxlen,int32_t *datalenp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits)
{
cJSON *retarray,*obj,*item,*msgarray; char *hexstr,*keystr,*retstr; uint32_t rawcrcs[64],crc=0; int32_t numcrcs=0,i,j,m,n,datalen,datalens[64];; uint8_t key[BASILISK_KEYSIZE];
*datalenp = 0;
memset(rawcrcs,0,sizeof(rawcrcs));
memset(datalens,0,sizeof(datalens));
if ( (retarray= basilisk_channelget(myinfo,srchash,desthash,channel,msgbits,0)) != 0 )
{
if ( (n= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<n; i++)
{
obj = jitem(retarray,i);
if ( jobj(obj,"error") != 0 )
continue;
if ( (msgarray= jarray(&m,obj,"messages")) != 0 )
{
for (j=0; j<m; j++)
{
item = jitem(msgarray,j);
keystr = hexstr = 0;
datalen = 0;
if ( (keystr= jstr(item,"key")) != 0 && is_hexstr(keystr,0) == BASILISK_KEYSIZE*2 && (hexstr= jstr(item,"data")) != 0 && (datalen= is_hexstr(hexstr,0)) > 0 )
{
decode_hex(key,BASILISK_KEYSIZE,keystr);
datalen >>= 1;
if ( datalen < maxlen )
{
decode_hex(verifybuf,datalen,hexstr);
if ( (retstr= basilisk_respond_addmessage(myinfo,key,BASILISK_KEYSIZE,verifybuf,datalen,juint(item,"expiration"),juint(item,"duration"))) != 0 )
{
if ( numcrcs < sizeof(rawcrcs)/sizeof(*rawcrcs) )
{
rawcrcs[numcrcs] = calc_crc32(0,verifybuf,datalen);
datalens[numcrcs] = datalen;
numcrcs++;
}
free(retstr);
}
} else printf("datalen.%d >= maxlen.%d\n",datalen,maxlen);
} else printf("not keystr.%p or no data.%p or bad datalen.%d\n",keystr,hexstr,datalen);
}
}
//printf("(%s).%d ",jprint(item,0),i);
}
//printf("n.%d maxlen.%d\n",n,maxlen);
}
free_json(retarray);
if ( (crc= basilisk_majority32(datalenp,rawcrcs,datalens,numcrcs)) != 0 )
printf("majority crc.%08x\n",crc);
else printf("no majority from rawcrcs.%d\n",numcrcs);
}
return(crc);
}
int32_t basilisk_process_swapverify(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)
{
struct basilisk_swap *swap = ptr;
return((*internal_func)(myinfo,swap,data,datalen));
if ( internal_func != 0 )
return((*internal_func)(myinfo,swap,data,datalen));
else return(0);
}
int32_t basilisk_swapget(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,int32_t (*basilisk_verify_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen))
{
int32_t retval; cJSON *retarray;
if ( (retarray= basilisk_channelget(myinfo,swap->otherhash,swap->myhash,swap->req.quoteid,msgbits,0)) != 0 )
int32_t datalen; uint32_t crc;
if ( (crc= basilisk_swaprecv(myinfo,swap->verifybuf,sizeof(swap->verifybuf),&datalen,swap->otherhash,swap->myhash,swap->req.quoteid,msgbits)) != 0 )
{
printf("got.(%s) msgbits.%08x\n",jprint(retarray,0),msgbits);
retval = basilisk_process_retarray(myinfo,swap,basilisk_process_swapget,data,maxlen,swap->req.quoteid,msgbits,retarray,basilisk_verify_func);
if ( retval > 0 )
return(0);
//return((*basilisk_verify_func)(myinfo,swap,data,datalen));
if ( datalen > 0 && datalen < maxlen )
{
memcpy(data,swap->verifybuf,datalen);
return((*basilisk_verify_func)(myinfo,swap,data,datalen));
}
}
return(-1);
}
uint32_t basilisk_swapcrcsend(struct supernet_info *myinfo,uint8_t *verifybuf,int32_t maxlen,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t crcs[2])
{
uint32_t crc; int32_t recvlen;
if ( crcs != 0 )
{
crc = calc_crc32(0,data,datalen);
if ( crcs[0] != crc )
crcs[0] = crc, crcs[1] = 0;
else
{
if ( crcs[1] == 0 )
crcs[1] = basilisk_swaprecv(myinfo,verifybuf,maxlen,&recvlen,srchash,desthash,channel,msgbits);
if ( crcs[0] == crcs[1] && datalen == recvlen )
return(crcs[0]);
}
}
return(0);
}
uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits,uint32_t crcs[2])
{
if ( basilisk_swapcrcsend(myinfo,swap->verifybuf,sizeof(swap->verifybuf),swap->myhash,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,crcs) != 0 )
return(nextbits);
if ( basilisk_channelsend(myinfo,swap->myhash,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2) == 0 )
return(nextbits);
printf("ERROR basilisk_channelsend\n");
return(0);
}
int32_t basilisk_privBn_extract(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
// need to scan blockchain for bobrefund
@ -954,14 +1040,6 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t
return(errs);
}
uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits)
{
if ( basilisk_channelsend(myinfo,swap->myhash,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2) == 0 )
return(nextbits);
printf("ERROR basilisk_channelsend\n");
return(0);
}
uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx,uint32_t nextbits)
{
if ( basilisk_swapdata_rawtx(myinfo,swap,data,maxlen,rawtx) != 0 )
@ -969,7 +1047,7 @@ uint32_t basilisk_swapdata_rawtxsend(struct supernet_info *myinfo,struct basilis
rawtx->actualtxid = basilisk_swap_broadcast(rawtx->name,myinfo,swap,rawtx->coin,rawtx->txbytes,rawtx->datalen);
char str[65],str2[65]; printf("rawtxsend %s vs %s\n",bits256_str(str,rawtx->signedtxid),bits256_str(str2,rawtx->actualtxid));
if ( bits256_nonz(rawtx->actualtxid) != 0 && msgbits != 0 )
return(basilisk_swapsend(myinfo,swap,msgbits,rawtx->txbytes,rawtx->datalen,nextbits));
return(basilisk_swapsend(myinfo,swap,msgbits,rawtx->txbytes,rawtx->datalen,nextbits,rawtx->crcs));
else return(nextbits);
} else printf("error from basilisk_swapdata_rawtx %p len.%d\n",rawtx->txbytes,rawtx->datalen);
return(0);
@ -980,24 +1058,26 @@ void basilisk_sendpubkeys(struct supernet_info *myinfo,struct basilisk_swap *swa
int32_t datalen;
datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen);
printf("send deck.%d\n",datalen);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01,swap->crcs_mypub);
}
void basilisk_checkdeck(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
int32_t basilisk_checkdeck(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
if ( (swap->statebits & 0x02) == 0 )
{
printf("check for other deck\n");
if ( basilisk_swapget(myinfo,swap,0x02,data,maxlen,basilisk_verify_otherdeck) == 0 )
swap->statebits |= 0x02;
else return(-1);
}
return(0);
}
void basilisk_sendstate(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
int32_t datalen;
datalen = iguana_rwnum(1,data,sizeof(swap->statebits),&swap->statebits);
basilisk_swapsend(myinfo,swap,0x80000000,data,datalen,0);
basilisk_swapsend(myinfo,swap,0x80000000,data,datalen,0,0);
}
void basilisk_sendchoosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
@ -1020,7 +1100,7 @@ void basilisk_sendchoosei(struct supernet_info *myinfo,struct basilisk_swap *swa
data[datalen++] = swap->pubA1.bytes[i];
printf("SEND pubA0/1 %s\n",bits256_str(str,swap->pubA0));
}
swap->statebits |= basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04,swap->crcs_mychoosei);
}
void basilisk_waitchoosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
@ -1079,7 +1159,7 @@ void basilisk_sendmostprivs(struct supernet_info *myinfo,struct basilisk_swap *s
data[datalen++] = swap->secretAm[i];
}
printf("send privkeys.%d\n",datalen);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x20,data,datalen,0x10);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x20,data,datalen,0x10,swap->crcs_myprivs);
}
void basilisk_alicepayment(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn)
@ -1104,8 +1184,7 @@ void basilisk_swaploop(void *_swap)
{
printf("A r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits);
basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys
basilisk_checkdeck(myinfo,swap,data,maxlen); // check for other deck 0x02
//if ( (swap->statebits & 0x02) != 0 )
if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02
basilisk_sendchoosei(myinfo,swap,data,maxlen);
basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08
if ( (swap->statebits & (0x08|0x02)) == (0x08|0x02) )
@ -1357,7 +1436,7 @@ void basilisk_swaploop(void *_swap)
for (j=datalen=0; j<32; j++)
data[datalen++] = swap->privAm.bytes[j];
printf("send privAm\n");
swap->statebits |= basilisk_swapsend(myinfo,swap,0x40000,data,datalen,0x20000);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x40000,data,datalen,0x20000,swap->crcs_mypriv);
basilisk_swap_balancingtrade(myinfo,swap,0);
}
}
@ -1405,7 +1484,7 @@ void basilisk_swaploop(void *_swap)
// maybe wait for bobrefund to be confirmed
for (j=datalen=0; j<32; j++)
data[datalen++] = swap->privBn.bytes[j];
basilisk_swapsend(myinfo,swap,0x40000000,data,datalen,0x40000000);
basilisk_swapsend(myinfo,swap,0x40000000,data,datalen,0x40000000,swap->crcs_mypriv);
}
printf("%s swap finished statebits %x\n",swap->iambob!=0?"BOB":"ALICE",swap->statebits);
basilisk_swap_purge(myinfo,swap);

1
basilisk/basilisk_tradebot.c

@ -285,3 +285,4 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
}
return(hwm);
}

2
iguana/iguana_peers.c

@ -507,7 +507,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
#else
if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 )
#endif
{
{
if ( errno == EAGAIN || errno == EWOULDBLOCK )
{
//addr->persistent_peer = 1;

Loading…
Cancel
Save