Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
73262cc1fd
  1. 36
      basilisk/basilisk.c
  2. 24
      basilisk/basilisk.h
  3. 60
      basilisk/basilisk_CMD.c
  4. 12
      basilisk/basilisk_DEX.c
  5. 11
      basilisk/basilisk_MSG.c
  6. 8
      basilisk/basilisk_bitcoin.c
  7. 30
      basilisk/basilisk_ping.c
  8. 2
      datachain/datachain.c
  9. 2
      gecko/gecko_blocks.c
  10. 16
      gecko/gecko_mempool.c
  11. 2
      iguana/iguana777.c
  12. 2
      iguana/iguana777.h
  13. 10
      iguana/main.c
  14. 1
      iguana/tests/getmessage
  15. 3
      includes/iguana_globals.h
  16. 24
      includes/iguana_structs.h

36
basilisk/basilisk.c

@ -149,7 +149,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{
int32_t i,r,l,s,valid,val,n=0,retval = -1; char cmd[12]; struct iguana_info *coin,*tmp; struct iguana_peer *addr; bits256 hash; uint32_t *alreadysent;
if ( fanout <= 0 )
fanout = sqrt(myinfo->numrelays) + 2;
fanout = sqrt(NUMRELAYS) + 1;
else if ( fanout > BASILISK_MAXFANOUT )
fanout = BASILISK_MAXFANOUT;
if ( type == 0 )
@ -203,10 +203,10 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{
if ( basilisk_specialcmd(type) != 0 )
{
for (s=0; s<myinfo->numrelays; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->relays[s].ipbits == addr->ipbits )
for (s=0; s<NUMRELAYS; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && RELAYS[s].ipbits == addr->ipbits )
break;
if ( s == myinfo->numrelays )
if ( s == NUMRELAYS )
{
//printf("skip non-relay.(%s)\n",addr->ipaddr);
continue;
@ -358,7 +358,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc
numrequired = 1;
if ( (timeoutmillis= jint(valsobj,"timeout")) == 0 )
timeoutmillis = BASILISK_TIMEOUT;
minfanout = sqrt(myinfo->numrelays)+2;
minfanout = sqrt(NUMRELAYS)+1;
if ( jobj(valsobj,"fanout") == 0 )
fanout = minfanout;
else fanout = jint(valsobj,"fanout");
@ -384,7 +384,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc
char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_addr,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag) // client side
{
uint32_t nBits = 0; uint8_t space[4096],*allocptr=0,*data = 0; struct basilisk_item *ptr; int32_t datalen = 0; cJSON *retjson; char *retstr=0;
if ( myinfo->RELAYID >= 0 && basilisk_specialcmd(CMD) == 0 )
if ( RELAYID >= 0 && basilisk_specialcmd(CMD) == 0 )
return(clonestr("{\"error\":\"unsupported special relay command\"}"));
data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr);
ptr = basilisk_requestservice(myinfo,_addr,CMD,blockflag,valsobj,hash,data,datalen,nBits);
@ -415,8 +415,8 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits)
{
int32_t j;
for (j=0; j<myinfo->numrelays; j++)
if ( myinfo->relays[j].ipbits == ipbits )
for (j=0; j<NUMRELAYS; j++)
if ( RELAYS[j].ipbits == ipbits )
return(j);
return(-1);
}
@ -621,7 +621,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
cmd[i] = tolower((int32_t)CMD[i]);
}
//origcmd[0] = 0;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
{
if ( basilisk_specialcmd(CMD) == 0 )
return;
@ -694,7 +694,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{
if ( strcmp((char *)basilisk_services[i][0],type) == 0 )
{
if ( coin->FULLNODE != 0 || myinfo->RELAYID >= 0 ) // iguana node
if ( coin->FULLNODE != 0 || RELAYID >= 0 ) // iguana node
{
//printf("services %s\n",type);
if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 )
@ -734,7 +734,7 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
else ipbits = myinfo->myaddr.myipbits;
if ( type[0] == 'P' && type[1] == 'I' && type[2] == 'N' )
{
if ( strcmp(type,"PIN") == 0 && myinfo->RELAYID >= 0 )
if ( strcmp(type,"PIN") == 0 && RELAYID >= 0 )
{
basilisk_ping_process(myinfo,_addr,ipbits,data,datalen);
}
@ -744,7 +744,7 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag);
//int32_t i; for (i=0; i<datalen-len; i++)
// printf("%02x",data[len+i]);
if ( 0 && myinfo->RELAYID >= 0 )
if ( 0 && RELAYID >= 0 )
printf(" ->received.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag);
basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len);
}
@ -822,7 +822,7 @@ void basilisks_loop(void *arg)
}
}
//portable_mutex_unlock(&myinfo->allcoins_mutex);
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
{
basilisk_ping_send(myinfo,btcd);
}
@ -836,7 +836,7 @@ void basilisks_loop(void *arg)
coin->lastunspentsupdate = (uint32_t)time(NULL);
}
}
if ( myinfo->RELAYID < 0 )
if ( RELAYID < 0 )
basilisk_requests_poll(myinfo);
now = (uint32_t)time(NULL);
portable_mutex_lock(&myinfo->messagemutex);
@ -851,7 +851,7 @@ void basilisks_loop(void *arg)
}
}
portable_mutex_unlock(&myinfo->messagemutex);
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
usleep(100000);
else sleep(1);
}
@ -877,7 +877,7 @@ void basilisks_init(struct supernet_info *myinfo)
HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
if ( vals == 0 )
return(clonestr("{\"error\":\"need vals object\"}"));
@ -887,9 +887,9 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(myinfo->numrelays)+2);
jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",myinfo->numrelays);
jaddnum(vals,"numrequired",NUMRELAYS);
if ( coin != 0 )
{
if ( jobj(vals,"addresses") == 0 )

24
basilisk/basilisk.h

@ -41,18 +41,6 @@
#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu"
#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf"
struct basilisk_request
{
uint32_t requestid,timestamp,quoteid,quotetime; // 0 to 15
uint64_t srcamount,minamount; // 16 to 31
bits256 hash; // 32 to 63
bits256 desthash;
char src[8],dest[8];
//char volatile_start,message[43];
uint64_t destamount;
uint32_t relaybits;
} __attribute__((packed));
struct basilisk_rawtx
{
bits256 txid,signedtxid,actualtxid;
@ -110,18 +98,6 @@ struct basilisk_info
struct basilisk_value values[8192]; int32_t numvalues;
};
struct basilisk_relaystatus
{
uint8_t pingdelay;
};
struct basilisk_relay
{
bits256 pubkey; int32_t relayid,oldrelayid; uint32_t ipbits,lastping; uint8_t pubkey33[33];
struct basilisk_request *requests; int32_t maxrequests,numrequests;
struct basilisk_relaystatus direct,reported[BASILISK_MAXRELAYS];
};
void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen);
int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits); // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag)

60
basilisk/basilisk_CMD.c

@ -18,8 +18,8 @@
/*int32_t basilisk_relayid(struct supernet_info *myinfo,char *ipaddr)
{
uint32_t i,ipbits = (uint32_t)calc_ipbits(ipaddr);
for (i=0; i<myinfo->numrelays; i++)
if ( ipbits == myinfo->relays[i].ipbits )
for (i=0; i<NUMRELAYS; i++)
if ( ipbits == RELAYS[i].ipbits )
return(i);
return(-1);
}*/
@ -35,11 +35,11 @@ struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct igu
{
printf("launch peer for relay\n");
addr->isrelay = 1;
myinfo->RELAYID = -1;
for (i=0; i<myinfo->numrelays; i++)
if ( myinfo->relays[i].ipbits == myinfo->myaddr.myipbits )
RELAYID = -1;
for (i=0; i<NUMRELAYS; i++)
if ( RELAYS[i].ipbits == myinfo->myaddr.myipbits )
{
myinfo->RELAYID = i;
RELAYID = i;
break;
}
iguana_launch(btcd,"addrelay",iguana_startconnection,addr,IGUANA_CONNTHREAD);
@ -65,30 +65,30 @@ void basilisk_relay_remap(struct supernet_info *myinfo,struct basilisk_relay *rp
{
int32_t i; struct basilisk_relaystatus tmp[BASILISK_MAXRELAYS];
// need to verify this works
for (i=0; i<myinfo->numrelays; i++)
for (i=0; i<NUMRELAYS; i++)
tmp[i] = rp->reported[i];
for (i=0; i<myinfo->numrelays; i++)
rp->reported[myinfo->relays[i].relayid] = tmp[myinfo->relays[i].oldrelayid];
for (i=0; i<NUMRELAYS; i++)
rp->reported[RELAYS[i].relayid] = tmp[RELAYS[i].oldrelayid];
}
void basilisk_setmyid(struct supernet_info *myinfo)
{
int32_t i; char ipaddr[64]; struct iguana_info *btcd = iguana_coinfind("BTCD");
for (i=0; i<myinfo->numrelays; i++)
for (i=0; i<NUMRELAYS; i++)
{
expand_ipbits(ipaddr,myinfo->relays[i].ipbits);
if ( myinfo->myaddr.myipbits == myinfo->relays[i].ipbits )
myinfo->RELAYID = i;
basilisk_ensurerelay(myinfo,btcd,myinfo->relays[i].ipbits);
expand_ipbits(ipaddr,RELAYS[i].ipbits);
if ( myinfo->myaddr.myipbits == RELAYS[i].ipbits )
RELAYID = i;
basilisk_ensurerelay(myinfo,btcd,RELAYS[i].ipbits);
}
}
char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint32_t ipbits,bits256 pubkey)
{
int32_t i; struct basilisk_relay *rp;
for (i=0; i<myinfo->numrelays; i++)
for (i=0; i<NUMRELAYS; i++)
{
rp = &myinfo->relays[i];
rp = &RELAYS[i];
if ( ipbits == rp->ipbits )
{
if ( bits256_cmp(GENESIS_PUBKEY,pubkey) != 0 && bits256_nonz(pubkey) != 0 )
@ -99,24 +99,24 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint
return(clonestr("{\"error\":\"relay already there\"}"));
}
}
if ( i >= sizeof(myinfo->relays)/sizeof(*myinfo->relays) )
i = (rand() % (sizeof(myinfo->relays)/sizeof(*myinfo->relays)));
if ( i >= sizeof(RELAYS)/sizeof(*RELAYS) )
i = (rand() % (sizeof(RELAYS)/sizeof(*RELAYS)));
printf("add relay[%d] <- %x\n",i,ipbits);
for (i=0; i<myinfo->numrelays; i++)
myinfo->relays[i].oldrelayid = i;
rp = &myinfo->relays[i];
for (i=0; i<NUMRELAYS; i++)
RELAYS[i].oldrelayid = i;
rp = &RELAYS[i];
rp->ipbits = ipbits;
rp->relayid = myinfo->numrelays;
rp->relayid = NUMRELAYS;
basilisk_ensurerelay(myinfo,iguana_coinfind("BTCD"),rp->ipbits);
if ( myinfo->numrelays < sizeof(myinfo->relays)/sizeof(*myinfo->relays) )
myinfo->numrelays++;
qsort(myinfo->relays,myinfo->numrelays,sizeof(myinfo->relays[0]),_increasing_ipbits);
for (i=0; i<myinfo->numrelays; i++)
myinfo->relays[i].relayid = i;
if ( NUMRELAYS < sizeof(RELAYS)/sizeof(*RELAYS) )
NUMRELAYS++;
qsort(RELAYS,NUMRELAYS,sizeof(RELAYS[0]),_increasing_ipbits);
for (i=0; i<NUMRELAYS; i++)
RELAYS[i].relayid = i;
basilisk_setmyid(myinfo);
printf("sorted MYRELAYID.%d\n",myinfo->RELAYID);
for (i=0; i<myinfo->numrelays; i++)
basilisk_relay_remap(myinfo,&myinfo->relays[i]);
printf("sorted MYRELAYID.%d\n",RELAYID);
for (i=0; i<NUMRELAYS; i++)
basilisk_relay_remap(myinfo,&RELAYS[i]);
return(clonestr("{\"result\":\"relay added\"}"));
}

12
basilisk/basilisk_DEX.c

@ -247,7 +247,7 @@ struct basilisk_relay *basilisk_request_ensure(struct supernet_info *myinfo,uint
int32_t j; struct basilisk_relay *relay = 0;
if ( (j= basilisk_relayid(myinfo,senderipbits)) >= 0 )
{
relay = &myinfo->relays[j];
relay = &RELAYS[j];
if ( numrequests > relay->maxrequests )
{
relay->maxrequests = numrequests;
@ -284,14 +284,14 @@ static int _cmp_requests(const void *a,const void *b)
struct basilisk_request *_basilisk_requests_uniq(struct supernet_info *myinfo,int32_t *nump,uint8_t *space,int32_t spacesize)
{
int32_t i,j,n,k,m; struct basilisk_relay *relay; struct basilisk_request *requests,*rp;
for (j=m=0; j<myinfo->numrelays; j++)
m += myinfo->relays[j].numrequests;
for (j=m=0; j<NUMRELAYS; j++)
m += RELAYS[j].numrequests;
if ( m*sizeof(*requests) <= spacesize )
requests = (void *)space;
else requests = calloc(m,sizeof(*requests));
for (j=m=0; j<myinfo->numrelays; j++)
for (j=m=0; j<NUMRELAYS; j++)
{
relay = &myinfo->relays[j];
relay = &RELAYS[j];
if ( (n= relay->numrequests) > 0 )
{
for (i=0; i<n; i++)
@ -471,7 +471,7 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 )
{
printf("R.requestid.%u vs calc %u, q.%u\n",R.requestid,basilisk_requestid(&R),R.quoteid);
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
R.relaybits = myinfo->myaddr.myipbits;
if ( (reqjson= basilisk_requestjson(&R)) != 0 )
free_json(reqjson);

11
basilisk/basilisk_MSG.c

@ -151,7 +151,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
{
uint32_t msgid,width,channel;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
{
channel = juint(vals,"channel");
msgid = juint(vals,"msgid");
@ -163,7 +163,7 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
{
int32_t keylen,datalen; uint8_t key[BASILISK_KEYSIZE],space[16384],*data,*ptr = 0; char *retstr=0;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash);
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 )
@ -173,8 +173,8 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
if ( retstr != 0 )
free(retstr);
}
if ( vals != 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(myinfo->numrelays));
if ( vals != 0 && juint(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS));
return(basilisk_standardservice("OUT",myinfo,0,hash,vals,hexstr,0));
}
#include "../includes/iguana_apiundefs.h"
@ -188,10 +188,11 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
jaddnum(valsobj,"channel",channel);
if ( msgid == 0 )
msgid = (uint32_t)time(NULL);
jaddnum(valsobj,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"duration",duration);
jaddbits256(valsobj,"sender",myinfo->myaddr.persistent);
char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s\n",datalen,channel,msgid,bits256_str(str,hash));
char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),NUMRELAYS,juint(valsobj,"fanout"));
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 )
free(retstr);
free_json(valsobj);

8
basilisk/basilisk_bitcoin.c

@ -375,7 +375,7 @@ double basilisk_bitcoin_valuemetric(struct supernet_info *myinfo,struct basilisk
void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64],str[64]; struct basilisk_value *v; uint64_t value = 0; bits256 txid;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
return(0);
txid = jbits256(valsobj,"txid");
vout = jint(valsobj,"vout");
@ -486,7 +486,7 @@ int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
vins = 0;
changeaddr = jstr(valsobj,"changeaddr");
@ -783,7 +783,7 @@ cJSON *BTC_makeclaimfunc(struct supernet_info *myinfo,struct exchange_info *exch
HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis;
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( coin == 0 )
{
@ -791,7 +791,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",(int32_t)sqrt(myinfo->numrelays));
jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+1);
if ( coin != 0 )
{
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )

30
basilisk/basilisk_ping.c

@ -60,13 +60,13 @@ int32_t basilisk_ping_processvirts(struct supernet_info *myinfo,struct iguana_in
memcpy(symbol,&data[len],6), len += 6;
len += iguana_rwvarint32(0,&data[len],&height);
//printf("(%s %d).%p ",symbol,height,addr);
if ( myinfo->numrelays > 0 && addr != 0 && (virt= iguana_coinfind(symbol)) != 0 )
if ( NUMRELAYS > 0 && addr != 0 && (virt= iguana_coinfind(symbol)) != 0 )
{
if ( height > virt->longestchain )
virt->longestchain = height;
if ( myinfo->numrelays > 0 && virt->blocks.hwmchain.height > height )
if ( NUMRELAYS > 0 && virt->blocks.hwmchain.height > height )
{
diff = ((height % myinfo->numrelays) - myinfo->RELAYID);
diff = ((height % NUMRELAYS) - myinfo->RELAYID);
diff *= diff;
diff++;
if ( (rand() % diff) == 0 )
@ -212,9 +212,9 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
int32_t diff,i,n,len = 0; struct iguana_info *btcd; char ipbuf[64]; struct basilisk_relay *rp; uint8_t numrelays; uint16_t sn; uint32_t now = (uint32_t)time(NULL);
expand_ipbits(ipbuf,senderipbits);
btcd = iguana_coinfind("BTCD");
for (i=0; i<myinfo->numrelays; i++)
for (i=0; i<NUMRELAYS; i++)
{
rp = &myinfo->relays[i];
rp = &RELAYS[i];
rp->direct.pingdelay = 0;
if ( rp->ipbits == senderipbits )
rp->lastping = now;
@ -252,10 +252,10 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen)
{
int32_t i,datalen = 0;
data[datalen++] = myinfo->numrelays;
data[datalen++] = NUMRELAYS;
//datalen += basilisk_ping_genvirts(myinfo,&data[datalen],maxlen - datalen);
for (i=0; i<myinfo->numrelays; i++)
datalen += basilisk_ping_genrelay(myinfo,&data[datalen],maxlen - datalen,&myinfo->relays[i]);
for (i=0; i<NUMRELAYS; i++)
datalen += basilisk_ping_genrelay(myinfo,&data[datalen],maxlen - datalen,&RELAYS[i]);
//datalen += basilisk_ping_genDEX(myinfo,&data[datalen],maxlen - datalen);
datalen += basilisk_ping_genMSG(myinfo,&data[datalen],maxlen - datalen);
//for (i=0; i<datalen; i++)
@ -270,25 +270,25 @@ int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t max
void basilisk_ping_send(struct supernet_info *myinfo,struct iguana_info *btcd)
{
struct iguana_peer *addr; char ipaddr[64]; struct basilisk_relay *rp; uint32_t r; int32_t i,j,incr,datalen=0; uint64_t alreadysent;
if ( btcd == 0 || myinfo->numrelays <= 0 )
if ( btcd == 0 || NUMRELAYS <= 0 )
return;
if ( myinfo->pingbuf == 0 )
myinfo->pingbuf = malloc(IGUANA_MAXPACKETSIZE);
datalen = basilisk_ping_gen(myinfo,&myinfo->pingbuf[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE-sizeof(struct iguana_msghdr));
incr = sqrt(myinfo->numrelays) + 1;
incr = sqrt(NUMRELAYS) + 1;
for (alreadysent=j=0; j<=incr; j++)
{
OS_randombytes((void *)&r,sizeof(r));
i = (j == 0) ? myinfo->RELAYID : (r % myinfo->numrelays);
if ( j != 0 && i == myinfo->RELAYID )
i = (myinfo->RELAYID + 1) % myinfo->numrelays;
i = (j == 0) ? RELAYID : (r % NUMRELAYS);
if ( j != 0 && i == RELAYID )
i = (RELAYID + 1) % NUMRELAYS;
if ( (((uint64_t)1 << i) & alreadysent) != 0 )
{
j--;
continue;
}
alreadysent |= ((uint64_t)1 << i);
rp = &myinfo->relays[i];
rp = &RELAYS[i];
addr = 0;
expand_ipbits(ipaddr,rp->ipbits);
if ( rp->ipbits == myinfo->myaddr.myipbits )
@ -301,6 +301,6 @@ void basilisk_ping_send(struct supernet_info *myinfo,struct iguana_info *btcd)
fprintf(stderr,"+(%s).%d ",ipaddr,i);
} //else fprintf(stderr,"-(%s).%d ",ipaddr,i);
}
//printf("my RELAYID.%d of %d\n",myinfo->RELAYID,myinfo->numrelays);
//printf("my RELAYID.%d of %d\n",myinfo->RELAYID,NUMRELAYS);
}

2
datachain/datachain.c

@ -20,7 +20,7 @@ uint32_t datachain_checkpoint(struct supernet_info *myinfo,struct iguana_info *c
{
char str[65],str2[65]; struct iguana_info *btc = iguana_coinfind("BTC");
printf("datachain_checkpoint.%s for %s.%u to %u lastheight.%d %s\n",bits256_str(str,merkle),coin->symbol,lastcheckpoint,timestamp,lastheight,bits256_str(str2,lasthash2));
if ( (lastheight % myinfo->numrelays) == myinfo->RELAYID )
if ( (lastheight % NUMRELAYS) == RELAYID )
{
// if designated relay, submit checkpoint -> add ip/relayid to opreturn
//

2
gecko/gecko_blocks.c

@ -341,7 +341,7 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *bt
if ( jobj(retjson,"error") == 0 )
{
valsobj = cJSON_CreateObject();
jaddnum(valsobj,"minresults",myinfo->numrelays - 1);
jaddnum(valsobj,"minresults",NUMRELAYS - 1);
jaddnum(valsobj,"timeout",3000);
jaddnum(valsobj,"fanout",-1);
jaddnum(valsobj,"height",height);

16
gecko/gecko_mempool.c

@ -21,7 +21,7 @@ struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct igua
int32_t j,firstz,numother; bits256 *othertxids; struct gecko_mempool *otherpool = 0;
othertxids = 0;
numother = firstz = 0;
for (j=0; j<myinfo->numrelays; j++)
for (j=0; j<NUMRELAYS; j++)
{
if ( (otherpool= virt->mempools[j]) != 0 )
{
@ -44,22 +44,22 @@ struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct igua
void gecko_mempool_sync(struct supernet_info *myinfo,struct iguana_info *virt,bits256 *reftxids,int32_t numtx)
{
int32_t i,j,k,n,num,numother; struct iguana_peer *addr; bits256 txid,*txids; struct gecko_mempool *pool,*otherpool; struct iguana_info *coin;
if ( (pool= virt->mempool) == 0 || myinfo->numrelays <= 0 )
if ( (pool= virt->mempool) == 0 || NUMRELAYS <= 0 )
return;
n = sqrt(myinfo->numrelays) + 2;
if ( n > myinfo->numrelays )
myinfo->numrelays = n;
n = sqrt(NUMRELAYS) + 2;
if ( n > NUMRELAYS )
NUMRELAYS = n;
i = (myinfo->myaddr.myipbits % n);
txids = calloc(pool->numtx,sizeof(bits256));
if ( virt->peers == 0 )
coin = iguana_coinfind("BTCD");
else coin = virt;
for (; i<myinfo->numrelays; i+=n)
for (; i<NUMRELAYS; i+=n)
{
printf("mempool_sync.%d\n",i);
if ( (addr= iguana_peerfindipbits(coin,myinfo->relays[i].ipbits,1)) != 0 )
if ( (addr= iguana_peerfindipbits(coin,RELAYS[i].ipbits,1)) != 0 )
{
if ( (otherpool= gecko_mempoolfind(myinfo,virt,&numother,myinfo->relays[i].ipbits)) != 0 )
if ( (otherpool= gecko_mempoolfind(myinfo,virt,&numother,RELAYS[i].ipbits)) != 0 )
{
for (j=num=0; j<pool->numtx; j++)
{

2
iguana/iguana777.c

@ -810,7 +810,7 @@ void iguana_coinloop(void *arg)
//if ( saved++ == 0 )
// iguana_coinflush(coin,1);
}*/
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
{
if ( coin->bindsock >= 0 )
{

2
iguana/iguana777.h

@ -78,9 +78,7 @@ struct supernet_info
void *ctx;
uint8_t *pingbuf;
struct delayedPoW_info dPoW;
struct basilisk_relay relays[BASILISK_MAXRELAYS];
struct basilisk_spend *spends; int32_t numspends;
int32_t numrelays,RELAYID;
struct peggy_info *PEGS;
struct liquidity_info linfos[64];
// compatibility

10
iguana/main.c

@ -80,7 +80,7 @@ struct supernet_info *SuperNET_MYINFO(char *passphrase)
OS_randombytes(MYINFO.privkey.bytes,sizeof(MYINFO.privkey));
MYINFO.myaddr.pubkey = curve25519(MYINFO.privkey,curve25519_basepoint9());
printf("SuperNET_MYINFO: generate session keypair\n");
MYINFO.RELAYID = -1;
RELAYID = -1;
}
if ( passphrase == 0 || passphrase[0] == 0 )
return(&MYINFO);
@ -1296,7 +1296,7 @@ STRING_ARG(SuperNET,priv2wif,priv)
STRING_ARG(SuperNET,myipaddr,ipaddr)
{
cJSON *retjson = cJSON_CreateObject();
myinfo->RELAYID = -1;
RELAYID = -1;
if ( myinfo->ipaddr[0] == 0 )
{
if ( is_ipaddr(ipaddr) != 0 )
@ -1307,10 +1307,10 @@ STRING_ARG(SuperNET,myipaddr,ipaddr)
}
}
jaddstr(retjson,"result",myinfo->ipaddr);
if ( myinfo->RELAYID >= 0 )
if ( RELAYID >= 0 )
{
jaddnum(retjson,"relayid",myinfo->RELAYID);
jaddnum(retjson,"numrelays",myinfo->numrelays);
jaddnum(retjson,"relayid",RELAYID);
jaddnum(retjson,"numrelays",NUMRELAYS);
}
return(jprint(retjson,1));
}

1
iguana/tests/getmessage

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"getmessage\",\"vals\":{\"channel\":5784900,\"width\":60}}"

3
includes/iguana_globals.h

@ -54,6 +54,9 @@ int32_t IGUANA_NUMHELPERS = 1;
// ALL globals must be here!
CONDEXTERN struct basilisk_relay RELAYS[BASILISK_MAXRELAYS];
CONDEXTERN int32_t NUMRELAYS,RELAYID;
CONDEXTERN char *COMMANDLINE_ARGFILE;
CONDEXTERN char *Iguana_validcommands[];
CONDEXTERN int32_t Showmode,Autofold,PANGEA_MAXTHREADS,QUEUEITEMS;

24
includes/iguana_structs.h

@ -509,5 +509,29 @@ struct _gfshare_ctx
uint32_t sharecount,threshold,size,buffersize,allocsize;
uint8_t sharenrs[255],buffer[];
};
struct basilisk_request
{
uint32_t requestid,timestamp,quoteid,quotetime; // 0 to 15
uint64_t srcamount,minamount; // 16 to 31
bits256 hash; // 32 to 63
bits256 desthash;
char src[8],dest[8];
//char volatile_start,message[43];
uint64_t destamount;
uint32_t relaybits;
} __attribute__((packed));
struct basilisk_relaystatus
{
uint8_t pingdelay;
};
struct basilisk_relay
{
bits256 pubkey; int32_t relayid,oldrelayid; uint32_t ipbits,lastping; uint8_t pubkey33[33];
struct basilisk_request *requests; int32_t maxrequests,numrequests;
struct basilisk_relaystatus direct,reported[BASILISK_MAXRELAYS];
};
#endif

Loading…
Cancel
Save