Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jl777 committed Jun 21, 2016
1 parent 736dff0 commit 1b4d08f
Show file tree
Hide file tree
Showing 11 changed files with 1,274 additions and 135 deletions.
1,160 changes: 1,160 additions & 0 deletions basilisk/basilisk copy.c

Large diffs are not rendered by default.

150 changes: 45 additions & 105 deletions basilisk/basilisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "../iguana/iguana777.h"

typedef char *basilisk_coinfunc(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen);
//typedef char *basilisk_coinfunc(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen);
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);
typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,uint8_t *data,int32_t datalen);

Expand Down Expand Up @@ -561,25 +561,44 @@ char *basilisk_standardcmd(struct supernet_info *myinfo,char *CMD,char *activeco
} else return(retstr);
}

char *_basilisk_value(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen)
char *_basilisk_value(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_standardcmd(myinfo,"VAL",coin->symbol,remoteaddr,basilisktag,valsobj,coin->basilisk_value,coin->basilisk_valuemetric));
struct iguana_info *coin; char *symbol;
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 )
{
if ( (coin= iguana_coinfind(symbol)) != 0 )
return(basilisk_standardcmd(myinfo,"VAL",symbol,remoteaddr,basilisktag,valsobj,coin->basilisk_value,coin->basilisk_valuemetric));
}
return(clonestr("{\"error\":\"couldnt get coin\"}"));
}

char *_basilisk_balances(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen)
char *_basilisk_balances(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_standardcmd(myinfo,"BAL",coin->symbol,remoteaddr,basilisktag,valsobj,coin->basilisk_balances,coin->basilisk_balancesmetric));
struct iguana_info *coin; char *symbol;
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 )
{
if ( (coin= iguana_coinfind(symbol)) != 0 )
return(basilisk_standardcmd(myinfo,"BAL",symbol,remoteaddr,basilisktag,valsobj,coin->basilisk_balances,coin->basilisk_balancesmetric));
}
return(clonestr("{\"error\":\"couldnt get coin\"}"));
}

char *_basilisk_rawtx(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen)
char *_basilisk_rawtx(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)
{
char *retstr,strbuf[4096],*str = 0;
printf("remote rawtx.(%s)\n",jprint(valsobj,0));
basilisk_addhexstr(&str,valsobj,strbuf,sizeof(strbuf),data,datalen);
retstr = basilisk_rawtx(myinfo,coin,0,remoteaddr,basilisktag,valsobj,coin->symbol);
if ( str != 0 )
free(str);
return(retstr);
char *retstr,strbuf[4096],*symbol,*str = 0; struct iguana_info *coin;
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 )
{
if ( (coin= iguana_coinfind(symbol)) != 0 )
{
printf("remote rawtx.(%s)\n",jprint(valsobj,0));
basilisk_addhexstr(&str,valsobj,strbuf,sizeof(strbuf),data,datalen);
retstr = basilisk_rawtx(myinfo,coin,0,remoteaddr,basilisktag,valsobj,coin->symbol);
if ( str != 0 )
free(str);
return(retstr);
}
}
return(clonestr("{\"error\":\"couldnt get coin\"}"));
}

char *_basilisk_result(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen)
Expand Down Expand Up @@ -789,7 +808,7 @@ void basilisk_geckoresult(struct supernet_info *myinfo,struct basilisk_item *ptr

void basilisk_pending_result(struct supernet_info *myinfo,struct basilisk_item *ptr,struct basilisk_item *pending)
{
int32_t n; struct basilisk_item *parent; basilisk_metricfunc metricfunc; cJSON *retjson;
int32_t n; struct basilisk_item *parent; basilisk_metricfunc metricfunc;
if ( (n= pending->numresults) < sizeof(pending->results)/sizeof(*pending->results) )
{
pending->numresults++;
Expand All @@ -798,16 +817,17 @@ void basilisk_pending_result(struct supernet_info *myinfo,struct basilisk_item *
else if ( (pending->metrics[n]= (*metricfunc)(myinfo,pending,ptr->retstr)) != 0. )
pending->childrendone++;
printf("%s.%u Add results[%d] <- metric %f\n",pending->CMD,pending->basilisktag,n,pending->metrics[n]);
pending->results[n] = ptr->retstr;
if ( strcmp(ptr->CMD,"SEQ") == 0 )
pending->results[n] = ptr->retstr, ptr->retstr = 0;
/*if ( strcmp(ptr->CMD,"SEQ") == 0 )
{
if ( (retjson= cJSON_Parse(ptr->retstr)) != 0 )
{
gecko_seqresult(myinfo,ptr->retstr);
free_json(retjson);
}
}
else if ( strcmp(ptr->CMD,"RET") == 0 || strcmp(ptr->CMD,"GET") == 0 )
else*/
if ( strcmp(ptr->CMD,"RET") == 0 || strcmp(ptr->CMD,"GET") == 0 )
{
printf("got return for tag.%d parent.%p\n",pending->basilisktag,pending->parent);
if ( (parent= pending->parent) != 0 )
Expand Down Expand Up @@ -929,17 +949,11 @@ void basilisks_loop(void *arg)

void basilisks_init(struct supernet_info *myinfo)
{
//bits256 basiliskhash;
iguana_initQ(&myinfo->basilisks.submitQ,"submitQ");
iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ");
portable_mutex_init(&myinfo->allcoins_mutex);
portable_mutex_init(&myinfo->basilisk_mutex);
portable_mutex_init(&myinfo->gecko_mutex);
//basiliskhash = calc_categoryhashes(0,"basilisk",0);
//myinfo->basilisk_category = basiliskhash;
//category_subscribe(myinfo,basiliskhash,GENESIS_PUBKEY);
//category_processfunc(basiliskhash,GENESIS_PUBKEY,basilisk_hexmsg);
//category_processfunc(basiliskhash,myinfo->myaddr.persistent,basilisk_hexmsg);
myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD);
}

Expand Down Expand Up @@ -973,7 +987,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{ (void *)"BLK", &basilisk_respond_geckoblock }, // reports block
{ (void *)"MEM", &basilisk_respond_mempool }, // reports mempool
{ (void *)"GTX", &basilisk_respond_geckotx }, // reports tx
{ (void *)"SEQ", &basilisk_respond_hashstamps }, // BTCD and BTC recent hashes from timestamp
//{ (void *)"SEQ", &basilisk_respond_hashstamps }, // BTCD and BTC recent hashes from timestamp

// unencrypted low level functions, used by higher level protocols and virtual network funcs
{ (void *)"ADD", &basilisk_respond_addrelay }, // relays register with each other bus
Expand All @@ -991,12 +1005,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{ (void *)"SAY", &basilisk_respond_VPNbroadcast }, // broadcast
{ (void *)"EAR", &basilisk_respond_VPNreceive }, // network receive (via poll)
{ (void *)"END", &basilisk_respond_VPNlogout }, // logout
};
static basilisk_coinfunc *basilisk_coinservices[][2] =
{

// coin services
{ (void *)"RAW", &_basilisk_rawtx },
{ (void *)"VAL", &_basilisk_value },
{ (void *)"BAL", &_basilisk_balances },
};
symbol = "BTCD";
if ( (valsobj= cJSON_Parse((char *)data)) != 0 )
Expand Down Expand Up @@ -1030,16 +1042,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
break;
}
if ( flag == 0 )
{
for (i=0; i<sizeof(basilisk_coinservices)/sizeof(*basilisk_coinservices); i++) // iguana node
if ( strcmp((char *)basilisk_coinservices[i][0],type) == 0 )
{
flag = 1;
break;
}
if ( flag == 0 )
return;
}
return;
strncpy(CMD,type,3), CMD[3] = cmd[3] = 0;
if ( isupper((int32_t)CMD[0]) != 0 && isupper((int32_t)CMD[1]) != 0 && isupper((int32_t)CMD[2]) != 0 )
from_basilisk = 1;
Expand All @@ -1057,15 +1060,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{
jsonlen = (int32_t)strlen((char *)data) + 1;
if ( datalen > jsonlen )
{
data += jsonlen, datalen -= jsonlen;
if ( 0 && strcmp("BLK",CMD) == 0 )
{
for (i=0; i<datalen; i++)
printf("%02x",data[i]);
printf(" <-> got datalen.%d\n",datalen);
}
} else data = 0, datalen = 0;
else data = 0, datalen = 0;
if ( coin == 0 )
coin = iguana_coinfind("BTCD");
if ( coin != 0 )
Expand All @@ -1080,79 +1076,23 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
if ( senderipbits != 0 )
expand_ipbits(remoteaddr,senderipbits);
else remoteaddr[0] = 0;
if ( valsobj != 0 && remoteaddr != 0 )
{
if ( strcmp(CMD,"RLY") == 0 )
{
printf("add relay path\n");
if ( juint(valsobj,"iamrelay") != 0 )
{
retstr = basilisk_respond_relays(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk);
}
free_json(valsobj);
if ( coin != 0 )
coin->basilisk_busy = 0;
myinfo->basilisk_busy = 0;
return;
}
//else if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(remoteaddr),GENESIS_PUBKEY)) != 0 )
// free(retstr);
}
for (i=0; i<sizeof(basilisk_services)/sizeof(*basilisk_services); i++) // iguana node
{
if ( strcmp((char *)basilisk_services[i][0],type) == 0 )
{
if ( myinfo->IAMRELAY != 0 ) // iguana node
if ( coin->RELAYNODE != 0 ) // iguana node
{
/*if ( from_basilisk != 0 )
{
printf("echo to other relays\n");
basilisk_sendcmd(myinfo,0,cmd,&basilisktag,0,0,origdata,origlen,-1,0); // to other iguanas
}*/
if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 )
{
printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr);
if ( from_basilisk != 0 )
//printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr);
if ( from_basilisk != 0 || strcmp(CMD,"GET") == 0 )
basilisk_sendback(myinfo,CMD,symbol,remoteaddr,basilisktag,retstr);
if ( retstr != 0 )
free(retstr);
} //else printf("services null return\n");
} else printf("non-relay got unexpected.(%s)\n",type);
free_json(valsobj);
if ( coin != 0 )
coin->basilisk_busy = 0;
myinfo->basilisk_busy = 0;
return;
}
}
if ( coin != 0 )
{
if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) // iguana node
{
if ( from_basilisk != 0 )
{
printf("echo to other relays\n");
basilisk_sendcmd(myinfo,0,cmd,&basilisktag,0,0,origdata,origlen,-1,0); // to other iguanas
}
for (i=0; i<sizeof(basilisk_coinservices)/sizeof(*basilisk_coinservices); i++)
if ( strcmp((char *)basilisk_coinservices[i][0],type) == 0 )
{
retstr = (*basilisk_coinservices[i][1])(myinfo,coin,addr,remoteaddr,basilisktag,valsobj,data,datalen);
printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr);
if ( from_basilisk != 0 )
basilisk_sendback(myinfo,CMD,symbol,remoteaddr,basilisktag,retstr);
break;
}
}
else // basilisk node
{
if ( strcmp(type,"ADD") == 0 )
{
printf("new relay ADD.(%s) datalen.%d\n",jprint(valsobj,0),datalen);
basilisk_respond_addrelay(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk);
} else printf("basilisk node doenst handle.(%s)\n",type);
}
} else printf("basilisk_msgprocess no coin\n");
}
free_json(valsobj);
if ( retstr != 0 )
Expand Down
42 changes: 33 additions & 9 deletions datachain/datachain.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,53 @@

#include "../iguana/iguana777.h"

int32_t datachain_events_rewind(struct supernet_info *myinfo,struct datachain_event *events,int32_t numevents,int32_t height,uint32_t hdrsi,uint32_t unspentind)
{
return(numevents);
}

void datachain_BTC_clock(struct supernet_info *myinfo,struct iguana_info *btc,int32_t height,uint32_t hdrsi,uint32_t unspentind)
{
if ( hdrsi < myinfo->dPOW.lastbtc_hdrsi || (hdrsi == myinfo->dPOW.lastbtc_hdrsi && unspentind < myinfo->dPOW.lastbtc_unspentind) )
if ( hdrsi < myinfo->dPOW.BTC.lasthdrsi || (hdrsi == myinfo->dPOW.BTC.lasthdrsi && unspentind < myinfo->dPOW.BTC.lastunspentind) )
{
// rewind BTC
myinfo->dPOW.BTC.numevents = datachain_events_rewind(myinfo,myinfo->dPOW.BTC.events,myinfo->dPOW.BTC.numevents,height,hdrsi,unspentind);
}
myinfo->dPOW.lastbtc_hdrsi = hdrsi;
myinfo->dPOW.lastbtc_unspentind = unspentind;
else
{
printf("NEWBLOCK.%s ht.%d\n",btc->symbol,height);
}
myinfo->dPOW.BTC.lasthdrsi = hdrsi;
myinfo->dPOW.BTC.lastunspentind = unspentind;
}

void datachain_BTCD_newblock(struct supernet_info *myinfo,struct iguana_info *btcd,int32_t height,uint32_t hdrsi,uint32_t unspentind)
{
if ( hdrsi < myinfo->dPOW.lastbtcd_hdrsi || (hdrsi == myinfo->dPOW.lastbtcd_hdrsi && unspentind < myinfo->dPOW.lastbtcd_unspentind) )
if ( hdrsi < myinfo->dPOW.BTCD.lasthdrsi || (hdrsi == myinfo->dPOW.BTCD.lasthdrsi && unspentind < myinfo->dPOW.BTCD.lastunspentind) )
{
datachain_events_rewind(myinfo,myinfo->dPOW.BTCD.events,myinfo->dPOW.BTCD.numevents,height,hdrsi,unspentind);
}
else
{
// rewind BTCD
// new BTCD block actions
printf("NEWBLOCK.%s ht.%d\n",btcd->symbol,height);
}
myinfo->dPOW.lastbtcd_hdrsi = hdrsi;
myinfo->dPOW.lastbtcd_unspentind = unspentind;
myinfo->dPOW.BTCD.lasthdrsi = hdrsi;
myinfo->dPOW.BTCD.lastunspentind = unspentind;
}

void datachain_virt_newblock(struct supernet_info *myinfo,struct iguana_info *virt,int32_t height,uint32_t hdrsi,uint32_t unspentind)
{

if ( hdrsi < virt->dPOW.lasthdrsi || (hdrsi == virt->dPOW.lasthdrsi && unspentind < virt->dPOW.lastunspentind) )
{
datachain_events_rewind(myinfo,virt->dPOW.events,virt->dPOW.numevents,height,hdrsi,unspentind);
}
else
{
// new virt block actions
printf("NEWBLOCK.%s ht.%d\n",virt->symbol,height);
}
virt->dPOW.lasthdrsi = hdrsi;
virt->dPOW.lastunspentind = unspentind;
}

void datachain_opreturn(struct supernet_info *myinfo,struct iguana_info *coin,int32_t btc_or_btcd,int64_t crypto777_payment,int64_t burned,int32_t height,uint64_t hdrsi_unspentind,uint8_t *data,int32_t datalen)
Expand Down
13 changes: 13 additions & 0 deletions datachain/datachain.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,21 @@ struct datachain_item
uint8_t itemdata[];
};

struct datachain_event
{

};

struct datachain_info
{
uint32_t lasthdrsi,lastunspentind,numevents,maxevents;
struct datachain_event *events;
};

struct delayedPoW_info
{
//struct gecko_sequences SEQ;
struct datachain_info BTC,BTCD;
};


Expand Down
6 changes: 3 additions & 3 deletions gecko/gecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struc
char mineraddr[64]; int32_t hwmhdrsi,longesthdrsi;
hwmhdrsi = virt->blocks.hwmchain.height / virt->chain->bundlesize;
longesthdrsi = virt->longestchain / virt->chain->bundlesize;
if ( 0 && hwmhdrsi <= longesthdrsi && virt->blocks.hwmchain.height < virt->longestchain-1 )
if ( hwmhdrsi <= longesthdrsi && virt->blocks.hwmchain.height < virt->longestchain-1 )
{
if ( time(NULL) > virt->hdrstime+3 )
{
Expand Down Expand Up @@ -162,7 +162,7 @@ struct gecko_chain *gecko_chain(struct supernet_info *myinfo,char chainname[GECK
return(chain);
}

int32_t gecko_chainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj)
/*int32_t gecko_chainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj)
{
struct iguana_info *virt; struct gecko_chain *chain; bits256 hash,prevhash; struct iguana_block *block; char chainname[GECKO_MAXNAMELEN];
if ( strcmp(CMD,"SET") == 0 || strcmp(CMD,"GET") == 0 )
Expand All @@ -188,7 +188,7 @@ int32_t gecko_chainvals(struct supernet_info *myinfo,char *CMD,cJSON *valsobj)
return(0);
}
return(-1);
}
}*/

cJSON *gecko_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr,char *pubval,char *p2shval,char *wifval,uint32_t isPoS)
{
Expand Down
4 changes: 2 additions & 2 deletions gecko/gecko.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

struct iguana_peer;

struct hashstamp { bits256 hash2; uint32_t timestamp; int32_t height; };
/*struct hashstamp { bits256 hash2; uint32_t timestamp; int32_t height; };
struct gecko_sequence { struct hashstamp *stamps; int32_t lastupdate,maxstamps,numstamps,lasti,longestchain; };
struct gecko_sequences { struct gecko_sequence BTC,BTCD; };
struct gecko_sequences { struct gecko_sequence BTC,BTCD; };*/

struct gecko_memtx
{
Expand Down
4 changes: 2 additions & 2 deletions gecko/gecko_delayedPoW.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// included from gecko.c

int32_t gecko_hashstampsfind(struct hashstamp *stamps,int32_t max,struct gecko_sequence *seq,bits256 hash,uint32_t reftimestamp)
/*int32_t gecko_hashstampsfind(struct hashstamp *stamps,int32_t max,struct gecko_sequence *seq,bits256 hash,uint32_t reftimestamp)
{
int32_t j,i = 0,foundflag = -1,gap = -1; uint32_t timestamp;
if ( seq->stamps == 0 )
Expand Down Expand Up @@ -230,7 +230,7 @@ char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,void *a
jadd(retjson,"BTC",gecko_sequencejson(btcd->chain->zcash,&myinfo->dPOW.SEQ.BTC,startheight,GECKO_FIRSTPOSSIBLEBTC));
}
return(jprint(retjson,1));
}
}*/

/*
done = 3;
Expand Down
Loading

0 comments on commit 1b4d08f

Please sign in to comment.