Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
bbbf2ce5f9
  1. 2
      basilisk/basilisk.h
  2. 3
      basilisk/basilisk_MSG.c
  3. 36
      basilisk/basilisk_swap.c

2
basilisk/basilisk.h

@ -65,7 +65,7 @@ struct basilisk_swap
{
struct basilisk_request req;
struct supernet_info *myinfo; bits256 myhash,otherhash;
uint32_t statebits,started,expiration,finished,dead,reftime,locktime;
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,locktime;
struct iguana_info *bobcoin,*alicecoin; char bobstr[64],alicestr[64];
int32_t bobconfirms,aliceconfirms,iambob,reclaimed;
uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance;

3
basilisk/basilisk_MSG.c

@ -135,12 +135,13 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
{
int32_t keylen; uint8_t key[64];
keylen = basilisk_messagekey(key,hash,valsobj);
printf("channel.%d msgid.%d\n",juint(valsobj,"channel"),juint(valsobj,"msgid"));
char str[65]; printf("%s channel.%u msgid.%u\n",bits256_str(str,hash),juint(valsobj,"channel"),juint(valsobj,"msgid"));
return(basilisk_respond_getmessage(myinfo,key,keylen));
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
{
int32_t keylen; uint8_t key[64];

36
basilisk/basilisk_swap.c

@ -378,12 +378,19 @@ uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *sw
else return(0);
}
int32_t basilisk_verify_statebits(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
iguana_rwnum(0,data,sizeof(swap->otherstatebits),&swap->otherstatebits);
return(0);
}
int32_t basilisk_verify_choosei(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
int32_t otherchoosei;
iguana_rwnum(0,data,sizeof(otherchoosei),&otherchoosei);
if ( otherchoosei >= 0 && otherchoosei < INSTANTDEX_DECKSIZE )
{
printf("otherchoosei.%d\n",otherchoosei);
swap->otherchoosei = otherchoosei;
return(0);
}
@ -529,20 +536,31 @@ void basilisk_swaploop(void *_swap)
while ( time(NULL) < swap->expiration )
{
fprintf(stderr,"swapstate.%x\n",swap->statebits);
if ( (swap->statebits & 0x01) == 0 ) // wait for pubkeys
iguana_rwnum(1,data,sizeof(swap->statebits),&swap->statebits);
basilisk_swapsend(myinfo,swap,0,data,datalen,0);
if ( basilisk_swapget(myinfo,swap,0,data,maxlen,basilisk_verify_statebits) == 0 )
{
printf("got other statebits.%x\n",swap->otherstatebits);
if ( (swap->otherstatebits & 0x02) == 0 )
{
datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0);
}
if ( (swap->otherstatebits & 0x08) == 0 )
{
iguana_rwnum(1,data,sizeof(swap->choosei),&swap->choosei);
basilisk_swapsend(myinfo,swap,0x08,data,datalen,0);
}
}
if ( (swap->statebits & 0x01) == 0 ) // send pubkeys
{
printf("send deck\n");
datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen);
swap->statebits |= basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01);
}
else if ( (swap->statebits & 0x02) == 0 ) // send pubkeys
else if ( (swap->statebits & 0x02) == 0 ) // wait for pubkeys
{
//printf("send deck again\n");
datalen = basilisk_swapdata_deck(myinfo,swap,data,maxlen);
basilisk_swapsend(myinfo,swap,0x02,data,datalen,0x01);
if ( basilisk_swapget(myinfo,swap,0x02,data,maxlen,basilisk_verify_otherdeck) == 0 )
swap->statebits |= 0x02;
else printf("msg.2 not there\n");
}
else if ( (swap->statebits & 0x04) == 0 ) // send choosei
{
@ -551,12 +569,10 @@ void basilisk_swaploop(void *_swap)
}
else if ( (swap->statebits & 0x08) == 0 ) // wait for choosei
{
iguana_rwnum(1,data,sizeof(swap->choosei),&swap->choosei);
basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04);
if ( basilisk_swapget(myinfo,swap,0x08,data,maxlen,basilisk_verify_choosei) == 0 )
swap->statebits |= 0x08;
}
else if ( (swap->statebits & 0x10) == 0 ) // send all but one privkeys
else if ( (swap->statebits & 0x10) == 0 && swap->otherchoosei >= 0 && swap->otherchoosei < INSTANTDEX_DECKSIZE ) // send all but one privkeys
{
for (i=0; i<INSTANTDEX_DECKSIZE; i++)
{

Loading…
Cancel
Save