|
|
@ -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); |
|
|
|
|
|
|
@ -561,19 +561,35 @@ 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],*symbol,*str = 0; struct iguana_info *coin; |
|
|
|
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 ) |
|
|
|
{ |
|
|
|
if ( (coin= iguana_coinfind(symbol)) != 0 ) |
|
|
|
{ |
|
|
|
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); |
|
|
@ -581,6 +597,9 @@ char *_basilisk_rawtx(struct supernet_info *myinfo,struct iguana_info *coin,stru |
|
|
|
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) |
|
|
|
{ |
|
|
@ -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++; |
|
|
@ -798,8 +817,8 @@ 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 ) |
|
|
|
{ |
|
|
@ -807,7 +826,8 @@ void basilisk_pending_result(struct supernet_info *myinfo,struct basilisk_item * |
|
|
|
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 ) |
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
@ -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
|
|
|
@ -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 ) |
|
|
@ -1029,17 +1041,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende |
|
|
|
flag = 1; |
|
|
|
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; |
|
|
|
} |
|
|
|
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; |
|
|
@ -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 ) |
|
|
@ -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 ) |
|
|
|