Browse Source

Merge branch 'master' into release/v0.1

release/v0.1
jl777 8 years ago
parent
commit
16178da4e6
  1. 12
      README.md
  2. 84
      basilisk/basilisk.c
  3. 9
      basilisk/basilisk_CMD.c
  4. 40
      basilisk/basilisk_DEX.c
  5. 17
      basilisk/basilisk_MSG.c
  6. 2
      basilisk/basilisk_bitcoin.c
  7. 36
      basilisk/basilisk_ping.c
  8. 2
      basilisk/basilisk_swap.c
  9. 5
      basilisk/basilisk_tradebot.c
  10. 35
      deprecated/obsolete.h
  11. 2
      iguana/coins/gennotary
  12. 1
      iguana/coins/notary
  13. 13
      iguana/iguana777.c
  14. 49
      iguana/iguana_init.c
  15. 9
      iguana/iguana_msg.c
  16. 10
      iguana/iguana_peers.c
  17. 2
      iguana/iguana_spendvectors.c
  18. 31
      iguana/iguana_txidfind.c
  19. 18
      iguana/iguana_wallet.c
  20. 10
      iguana/main.c
  21. 11
      iguana/tests/addnotarys
  22. 8
      iguana/tests/addnotarys_7776
  23. 8
      iguana/tests/addrelays
  24. 1
      iguana/tests/getinfoN
  25. 1
      iguana/tests/getinfoN_7776
  26. 9
      iguana/tests/notaryinit
  27. 1
      includes/iguana_funcs.h
  28. 2
      includes/iguana_structs.h

12
README.md

@ -2,12 +2,12 @@
OS | Build Status
-------------|------
Unix (Ubuntu 14.04) | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=Unix-jl777)](https://jenkinsmaster.sprnt.pw/job/Unix-jl777)
Chrome | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=PNaCl-jl777)](https://jenkinsmaster.sprnt.pw/job/PNaCl-jl777/)
Android | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=Android)](https://jenkinsmaster.sprnt.pw/job/Android/)
iOS | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=iOS)](https://jenkinsmaster.sprnt.pw/job/iOS/)
Windows 32 Bit | [![Build Status](https://jenkinsmaster.sprnt.pw/job/Win32/badge/icon)](https://jenkinsmaster.sprnt.pw/job/Win32/)
Windows 64 Bit | [![Build Status](https://jenkinsmaster.sprnt.pw/job/Win64-jl777/badge/icon)](https://jenkinsmaster.sprnt.pw/job/Win64-jl777/)
Unix (Ubuntu 14.04) | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=iguana-unix-jl777-release-v0.1)](https://jenkinsmaster.sprnt.pw/job/iguana-unix-jl777-release-v0.1)
Chrome | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=iguana-pnacl-jl777-release-v0.1)](https://jenkinsmaster.sprnt.pw/job/iguana-pnacl-jl777-release-v0.1/)
Android | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=iguana-android-jl777-release-v0.1)](https://jenkinsmaster.sprnt.pw/job/iguana-android-jl777-release-v0.1/)
iOS | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=iguana-ios-jl777-release-v0.1)](https://jenkinsmaster.sprnt.pw/job/iguana-ios-jl777-release-v0.1/)
Windows 32 Bit | [![Build Status](https://jenkinsmaster.sprnt.pw/job/iguana-win32-jl777-release-v0.1/badge/icon)](https://jenkinsmaster.sprnt.pw/job/iguana-win32-jl777-release-v0.1/)
Windows 64 Bit | [![Build Status](https://jenkinsmaster.sprnt.pw/job/iguana-win64-jl777-release-v0.1/badge/icon)](https://jenkinsmaster.sprnt.pw/job/iguana-win64-jl777-release-v0.1/)
docs.supernet.org | [![Build Status](https://jenkinsmaster.sprnt.pw/buildStatus/icon?job=docs.supernet.org-updating)](https://jenkinsmaster.sprnt.pw/job/docs.supernet.org-updating/)
---

84
basilisk/basilisk.c

@ -20,7 +20,7 @@ typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,void *
int32_t basilisk_notarycmd(char *cmd)
{
//&& strcmp(cmd,"DEX") != 0 && strcmp(cmd,"ACC") != 0 && strcmp(cmd,"RID") != 0 &&
if ( strcmp(cmd,"PIN") != 0 && strcmp(cmd,"OUT") != 0 && strcmp(cmd,"MSG") != 0 )
if ( strcmp(cmd,"PIN") != 0 && strcmp(cmd,"OUT") != 0 && strcmp(cmd,"MSG") != 0 && strcmp(cmd,"VOT") != 0 )
return(0);
else return(1);
}
@ -147,13 +147,13 @@ struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD
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)
{
int32_t i,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,r,r2;
int32_t i,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,r;
if ( fanout <= 0 )
fanout = sqrt(myinfo->NOTARY.NUMRELAYS) + 1;
else if ( fanout > BASILISK_MAXFANOUT )
fanout = BASILISK_MAXFANOUT;
if ( type == 0 )
type = "BTCD";
type = "INF";
if ( strlen(type) > 3 )
{
printf("basilisk_sendcmd illegal type(%s)\n",type);
@ -213,6 +213,8 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{
if ( coin->peers == 0 )
continue;
//if ( basilisk_notarycmd(type) != 0 && strcmp(coin->symbol,"NOTARY") != 0 )
// continue;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 )
cmd[0] = 's';
else cmd[0] = 'S';
@ -228,21 +230,21 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{
s = 0;
valid = (addr->supernet != 0);
if ( basilisk_notarycmd(type) != 0 && myinfo->IAMNOTARY != 0 )
if ( basilisk_notarycmd(type) != 0 )
{
valid = 0;
OS_randombytes((void *)&r2,sizeof(r2));
/*OS_randombytes((void *)&r2,sizeof(r2));
if ( (r2 % myinfo->NOTARY.NUMRELAYS) >= sqrt(myinfo->NOTARY.NUMRELAYS) )
{
//printf("fanout.%d s.%d n.%d skip %s\n",fanout,s,n,addr->ipaddr);
printf("fanout.%d s.%d n.%d skip %s\n",fanout,s,n,addr->ipaddr);
continue;
}
}*/
for (s=0; s<myinfo->NOTARY.NUMRELAYS; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->NOTARY.RELAYS[s].ipbits == addr->ipbits )
break;
if ( s == myinfo->NOTARY.NUMRELAYS )
{
//printf("skip non-relay.(%s)\n",addr->ipaddr);
printf("skip non-relay.(%s)\n",addr->ipaddr);
continue;
}
valid = 1;
@ -256,7 +258,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
}
if ( s == n && valid == 1 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) )
{
//fprintf(stderr,"(%s) ",addr->ipaddr);
//fprintf(stderr,"(%s).%u ",addr->ipaddr,coin->chain->portp2p);
//printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 )
{
@ -424,7 +426,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->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 && basilisk_notarycmd(CMD) == 0 )
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 && (strcmp(CMD,"INF") != 0 && basilisk_notarycmd(CMD) == 0) )
return(clonestr("{\"error\":\"unsupported special relay command\"}"));
data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr);
//printf("request.(%s)\n",jprint(valsobj,0));
@ -672,11 +674,11 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
}
if ( myinfo->IAMNOTARY != 0 )//RELAYID >= 0 )
{
if ( basilisk_notarycmd(CMD) == 0 )
if ( basilisk_notarycmd(CMD) == 0 && strcmp(CMD,"INF") != 0 )
return;
} else if ( basilisk_notarycmd(CMD) != 0 )
return;
symbol = "BTCD";
symbol = "NOTARY";
if ( senderipbits == 0 )
expand_ipbits(remoteaddr,myinfo->myaddr.myipbits);
else expand_ipbits(remoteaddr,senderipbits);
@ -723,7 +725,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
data += jsonlen, datalen -= jsonlen;
else data = 0, datalen = 0;
if ( coin == 0 )
coin = iguana_coinfind("BTCD");
coin = iguana_coinfind(symbol);
if ( coin != 0 )
{
symbol = coin->symbol;
@ -790,7 +792,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 ( myinfo->NOTARY.RELAYID >= 0 )
if ( 0 && myinfo->NOTARY.RELAYID >= 0 )
printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag);
basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len);
}
@ -800,20 +802,19 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
void basilisk_requests_poll(struct supernet_info *myinfo)
{
char *retstr; cJSON *outerarray; int32_t i,n; struct basilisk_request issueR; double hwm = 0.;
char *retstr; cJSON *outerarray,*retjson; int32_t i,n; struct basilisk_request issueR; double hwm = 0.;
memset(&issueR,0,sizeof(issueR));
if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 )
{
//printf("poll.(%s)\n",retstr);
if ( (outerarray= cJSON_Parse(retstr)) != 0 )
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(outerarray) != 0 )
if ( (outerarray= jarray(&n,retjson,"responses")) != 0 )
{
n = cJSON_GetArraySize(outerarray);
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(outerarray);
} //else hwm = basilisk_process_results(myinfo,&issueR,outerarray,hwm);
free_json(retjson);
}
free(retstr);
} else printf("null incoming\n");
@ -840,7 +841,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
void basilisks_loop(void *arg)
{
struct iguana_info *virt,*tmpcoin,*coin,*btcd; struct basilisk_message *msg,*tmpmsg; struct basilisk_item *tmp,*pending; uint32_t now; int32_t iter,maxmillis,flag=0; struct supernet_info *myinfo = arg;
struct iguana_info *virt,*tmpcoin,*coin,*notary; struct basilisk_message *msg,*tmpmsg; struct basilisk_item *tmp,*pending; uint32_t now; int32_t iter,maxmillis,flag=0; struct supernet_info *myinfo = arg;
iter = 0;
while ( 1 )
{
@ -855,40 +856,41 @@ void basilisks_loop(void *arg)
free(pending);
}
}
notary = iguana_coinfind("NOTARY");
now = (uint32_t)time(NULL);
portable_mutex_unlock(&myinfo->basilisk_mutex);
if ( (btcd= iguana_coinfind("BTCD")) != 0 )
if ( myinfo->NOTARY.RELAYID >= 0 )
{
maxmillis = (1000 / (myinfo->allcoins_numvirts + 1)) + 1;
//portable_mutex_lock(&myinfo->allcoins_mutex);
HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin)
if ( notary != 0 )
{
if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 )
maxmillis = (1000 / (myinfo->allcoins_numvirts + 1)) + 1;
//portable_mutex_lock(&myinfo->allcoins_mutex);
HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin)
{
gecko_iteration(myinfo,btcd,virt,maxmillis), flag++;
if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 )
{
gecko_iteration(myinfo,notary,virt,maxmillis), flag++;
}
}
//portable_mutex_unlock(&myinfo->allcoins_mutex);
basilisk_ping_send(myinfo,notary);
}
//portable_mutex_unlock(&myinfo->allcoins_mutex);
if ( myinfo->NOTARY.RELAYID >= 0 )
{
basilisk_ping_send(myinfo,btcd);
}
}
if ( myinfo->expiration != 0 )
} // else printf("not notary %p %d\n",notary,myinfo->NOTARY.RELAYID);
else if ( myinfo->expiration != 0 )
{
HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin)
{
if ( myinfo->Cunspents == 0 || time(NULL) > coin->lastunspentsupdate+60 )
if ( strcmp(coin->symbol,"NOTARY") != 0 && (myinfo->Cunspents == 0 || time(NULL) > coin->lastunspentsupdate+60) )
{
//printf(">>>>>>>>>>>>> update %s\n",coin->symbol);
basilisk_unspents_update(myinfo,coin);
coin->lastunspentsupdate = (uint32_t)time(NULL);
coin->lastunspentsupdate = now;
//printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol);
}
}
if ( myinfo->IAMLP != 0 || myinfo->DEXactive > now )
basilisk_requests_poll(myinfo);
}
if ( myinfo->NOTARY.RELAYID < 0 && myinfo->expiration != 0 )
basilisk_requests_poll(myinfo);
now = (uint32_t)time(NULL);
portable_mutex_lock(&myinfo->messagemutex);
HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg)
{
@ -898,11 +900,11 @@ void basilisks_loop(void *arg)
HASH_DELETE(hh,myinfo->messagetable,msg);
QUEUEITEMS--;
free(msg);
}
} //else printf("remains.%d\n",msg->expiration - now);
}
portable_mutex_unlock(&myinfo->messagemutex);
if ( myinfo->NOTARY.RELAYID >= 0 )
usleep(100000);
usleep(500000);
else usleep(3000000);
}
}

9
basilisk/basilisk_CMD.c

@ -95,7 +95,8 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint
rp->pubkey = pubkey;
if ( pubkey33 != 0 && pubkey33[0] != 0 )
memcpy(rp->pubkey33,pubkey33,33);
//printf("updated relay[%d] %x\n",i,ipbits);
basilisk_setmyid(myinfo);
//printf("updated relay[%d] %x vs mine.%x\n",i,ipbits,myinfo->myaddr.myipbits);
return(clonestr("{\"error\":\"relay already there\"}"));
}
}
@ -218,7 +219,7 @@ char *basilisk_respond_value(struct supernet_info *myinfo,char *CMD,void *addr,c
{
retstr = ptr->retstr;
ptr->finished = (uint32_t)time(NULL);
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoinrawtx\"}");
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoin value\"}");
return(retstr);
}
@ -232,7 +233,7 @@ char *basilisk_respond_balances(struct supernet_info *myinfo,char *CMD,void *add
{
retstr = ptr->retstr;
ptr->finished = (uint32_t)time(NULL);
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoinrawtx\"}");
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoin balances\"}");
return(retstr);
}
@ -247,7 +248,7 @@ char *basilisk_respond_getinfo(struct supernet_info *myinfo,char *CMD,void *addr
{
retstr = ptr->retstr;
ptr->finished = (uint32_t)time(NULL);
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoinrawtx\"}");
} else retstr = clonestr("{\"error\":\"no coin specified or error bitcoin getinfo\"}");
return(retstr);
}

40
basilisk/basilisk_DEX.c

@ -373,41 +373,6 @@ char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,ui
return(retstr);
}
// respond to incoming RID, ACC, DEX, QST
/*char *basilisk_respond_RID(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_respond_requests(myinfo,hash,juint(valsobj,"requestid"),0));
}
char *basilisk_respond_SWP(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_respond_swapstatus(myinfo,hash,juint(valsobj,"requestid"),juint(valsobj,"quoteid")));
}
char *basilisk_respond_ACC(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 requestid,quoteid;
if ( (requestid= juint(valsobj,"requestid")) != 0 && (quoteid= juint(valsobj,"quoteid")) != 0 )
return(basilisk_respond_accept(myinfo,requestid,quoteid));
else return(clonestr("{\"error\":\"need nonzero requestid and quoteid\"}"));
}
char *basilisk_respond_DEX(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=0,buf[256]; struct basilisk_request R;
if ( basilisk_request_create(&R,valsobj,hash,juint(valsobj,"timestamp")) == 0 )
{
char str[65]; printf("DEX.(%s %.8f) -> %s %s\n",R.src,dstr(R.srcamount),R.dest,bits256_str(str,hash));
if ( basilisk_request_enqueue(myinfo,&R) != 0 )
{
sprintf(buf,"{\"result\":\"DEX request added\",\"requestid\":%u}",R.requestid);
retstr = clonestr(buf);
} else retstr = clonestr("{\"error\":\"DEX quote couldnt be created\"}");
} else retstr = clonestr("{\"error\":\"missing or invalid fields\"}");
return(retstr);
}*/
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
@ -457,7 +422,7 @@ STRING_ARG(InstantDEX,available,source)
HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
{
uint8_t serialized[512]; struct basilisk_request R; cJSON *reqjson; uint32_t datalen=0,DEX_channel;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
myinfo->DEXactive = (uint32_t)time(NULL) + BASILISK_TIMEOUT;
jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN);
if ( jobj(vals,"desthash") == 0 )
jaddbits256(vals,"desthash",hash);
@ -516,13 +481,12 @@ INT_ARG(InstantDEX,incoming,requestid)
{
cJSON *retjson,*retarray; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192];
now = (uint32_t)time(NULL);
width = (now - myinfo->DEXpoll);
width = (now - myinfo->DEXpoll) + 2*drift;
if ( width < (drift+1) )
width = 2*drift+1;
else if ( width > 64 )
width = 64;
myinfo->DEXpoll = now;
myinfo->DEXactive = now + INSTANTDEX_LOCKTIME;
retjson = cJSON_CreateObject();
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
msgid = (uint32_t)time(NULL) + drift;

17
basilisk/basilisk_MSG.c

@ -36,7 +36,7 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg);
for (i=0; i<BASILISK_KEYSIZE; i++)
printf("%02x",key[i]);
printf(" <- ADDMSG.[%d]\n",QUEUEITEMS);
printf(" <- ADDMSG.[%d] exp %u\n",QUEUEITEMS,msg->expiration);
QUEUEITEMS++;
portable_mutex_unlock(&myinfo->messagemutex);
if ( sendping != 0 )
@ -107,30 +107,34 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
width = 3600;
else if ( width < 1 )
width = 1;
//printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid);
for (i=0; i<width; i++)
{
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash);
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);
jaddi(array,item);//, printf("gotmsg0.(%s)\n",jprint(item,0));
if ( origwidth > 0 )
{
if ( bits256_nonz(srchash) != 0 )
{
keylen = basilisk_messagekey(key,channel,msgid,zero,desthash);
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);
jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0));
}
if ( bits256_nonz(desthash) != 0 )
{
keylen = basilisk_messagekey(key,channel,msgid,srchash,zero);
//int32_t j; for (j=0; j<keylen; j++)
// printf("%02x",key[j]);
//printf(" <- key\n");
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);
jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0));
}
if ( bits256_nonz(srchash) != 0 || bits256_nonz(desthash) != 0 )
{
keylen = basilisk_messagekey(key,channel,msgid,zero,zero);
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);
jaddi(array,item);//, printf("gotmsg3.(%s)\n",jprint(item,0));
}
}
msgid--;
@ -140,6 +144,7 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jadd(retjson,"messages",array);
//printf("MESSAGES.(%s)\n",jprint(array,0));
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no messages\"}"));
}
@ -207,7 +212,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
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 numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),NUMRELAYS,juint(valsobj,"fanout"));
//char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout"));
if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 )
free(retstr);
free_json(valsobj);

2
basilisk/basilisk_bitcoin.c

@ -424,7 +424,7 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
struct basilisk_item *ptr; cJSON *infojson; int32_t numsent,fanout,numrequired;
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
if ( (myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0) && strcmp(coin->symbol,"NOTARY") != 0 )
return(0);
if ( coin->VALIDATENODE != 0 || coin->FULLNODE != 0 )
{

36
basilisk/basilisk_ping.c

@ -16,7 +16,7 @@
// included from basilisk.c
#ifdef ENABLE_VIRTPING
int32_t basilisk_blocksend(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,struct iguana_peer *addr,int32_t height)
int32_t basilisk_blocksend(struct supernet_info *myinfo,struct iguana_info *notary,struct iguana_info *virt,struct iguana_peer *addr,int32_t height)
{
int32_t blocklen; bits256 hash2; uint8_t *data = 0; char str[65],strbuf[4096],*blockstr,*allocptr = 0; struct iguana_block *block;
hash2 = iguana_blockhash(virt,height);
@ -42,7 +42,7 @@ int32_t basilisk_blocksend(struct supernet_info *myinfo,struct iguana_info *btcd
{
blockstr = basilisk_addhexstr(&allocptr,0,strbuf,sizeof(strbuf),data,blocklen);
printf("RELAYID.%d send block.%d %s -> (%s) %s\n",myinfo->RELAYID,height,blockstr,addr->ipaddr,bits256_str(str,hash2));
basilisk_blocksubmit(myinfo,btcd,virt,addr,blockstr,hash2,height);
basilisk_blocksubmit(myinfo,notary,virt,addr,blockstr,hash2,height);
if ( allocptr != 0 )
free(allocptr);
return(0);
@ -50,7 +50,7 @@ int32_t basilisk_blocksend(struct supernet_info *myinfo,struct iguana_info *btcd
return(-1);
}
int32_t basilisk_ping_processvirts(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_peer *addr,uint8_t *data,int32_t datalen)
int32_t basilisk_ping_processvirts(struct supernet_info *myinfo,struct iguana_info *notary,struct iguana_peer *addr,uint8_t *data,int32_t datalen)
{
int32_t diff,i,j,len = 0; struct iguana_info *virt; char symbol[7]; uint32_t numvirts,height;
len += iguana_rwvarint32(0,&data[len],&numvirts);
@ -72,7 +72,7 @@ int32_t basilisk_ping_processvirts(struct supernet_info *myinfo,struct iguana_in
if ( (rand() % diff) == 0 )
{
for (j=1; height+j<virt->blocks.hwmchain.height && j<3; j++)
basilisk_blocksend(myinfo,btcd,virt,addr,height+j);
basilisk_blocksend(myinfo,notary,virt,addr,height+j);
}
}
}
@ -188,7 +188,7 @@ int32_t baslisk_relay_report(struct supernet_info *myinfo,uint8_t *data,int32_t
int32_t basilisk_ping_processrelay(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen,struct basilisk_relay *rp,int32_t i)
{
uint8_t pingdelay; int32_t j,datalen = 0; uint32_t ipbits;
uint8_t pingdelay; int32_t j,datalen = 0; uint32_t ipbits; char ipaddr[64];
ipbits = rp->ipbits;
if ( maxlen < sizeof(ipbits)+1 )
{
@ -202,16 +202,18 @@ int32_t basilisk_ping_processrelay(struct supernet_info *myinfo,uint8_t *data,in
datalen += baslisk_relay_report(myinfo,&data[datalen],maxlen-datalen,&rp->reported[j],pingdelay);
return(datalen);
}
printf("notified about unknown relay\n"); // parse it to match bytes sent
datalen += baslisk_relay_report(myinfo,&data[datalen],maxlen-datalen,0,pingdelay);
expand_ipbits(ipaddr,ipbits);
printf("notified about unknown relay (%s)\n",ipaddr); // parse it to match bytes sent
basilisk_addrelay_info(myinfo,0,ipbits,GENESIS_PUBKEY);
return(datalen);
}
void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr,uint32_t senderipbits,uint8_t *data,int32_t datalen)
{
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);
int32_t diff,i,n,len = 0; struct iguana_info *notary; 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");
notary = iguana_coinfind("NOTARY");
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
{
rp = &myinfo->NOTARY.RELAYS[i];
@ -228,7 +230,7 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
}
}
numrelays = data[len++];
//len += basilisk_ping_processvirts(myinfo,btcd,addr,&data[len],datalen - len);
//len += basilisk_ping_processvirts(myinfo,notary,addr,&data[len],datalen - len);
for (i=0; i<numrelays; i++)
{
rp = &myinfo->NOTARY.RELAYS[i];
@ -247,7 +249,7 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
//else printf("\n");
//for (i=0; i<datalen; i++)
// printf("%02x",data[i]);
//printf("<<<<<<<<<<< input ping from.(%s) rel.%d numrelays.%d datalen.%d relay.%d Q.%d\n",ipbuf,basilisk_relayid(myinfo,(uint32_t)calc_ipbits(ipbuf)),numrelays,datalen,myinfo->RELAYID,QUEUEITEMS);
//printf("<<<<<<<<<<< input ping from.(%s) rel.%d numrelays.%d datalen.%d relay.%d Q.%d\n",ipbuf,basilisk_relayid(myinfo,(uint32_t)calc_ipbits(ipbuf)),numrelays,datalen,myinfo->NOTARY.RELAYID,QUEUEITEMS);
}
int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen)
@ -268,11 +270,14 @@ int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t max
// encapsulate other messages inside msgQ for onetime ping
// filter out duplicates
void basilisk_ping_send(struct supernet_info *myinfo,struct iguana_info *btcd)
void basilisk_ping_send(struct supernet_info *myinfo,struct iguana_info *notary)
{
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->NOTARY.NUMRELAYS <= 0 || myinfo->IAMNOTARY == 0 )
if ( notary == 0 || myinfo->NOTARY.NUMRELAYS <= 0 || myinfo->IAMNOTARY == 0 )
{
printf("skip ping send %p %d %d\n",notary,myinfo->NOTARY.NUMRELAYS,myinfo->IAMNOTARY);
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));
@ -294,14 +299,15 @@ void basilisk_ping_send(struct supernet_info *myinfo,struct iguana_info *btcd)
expand_ipbits(ipaddr,rp->ipbits);
if ( rp->ipbits == myinfo->myaddr.myipbits )
basilisk_ping_process(myinfo,0,myinfo->myaddr.myipbits,&myinfo->pingbuf[sizeof(struct iguana_msghdr)],datalen);
else if ( (addr= iguana_peerfindipbits(btcd,rp->ipbits,1)) != 0 && addr->usock >= 0 )
else if ( (addr= iguana_peerfindipbits(notary,rp->ipbits,1)) != 0 && addr->usock >= 0 )
{
if ( iguana_queue_send(addr,0,myinfo->pingbuf,"SuperNETPIN",datalen) <= 0 )
printf("error sending %d to (%s)\n",datalen,addr->ipaddr);
else if ( 0 && datalen > 200 )
else if ( datalen > 200 )
fprintf(stderr,"+(%s).%d ",ipaddr,i);
} //else fprintf(stderr,"-(%s).%d ",ipaddr,i);
}
//printf("my RELAYID.%d of %d\n",myinfo->RELAYID,NUMRELAYS);
if ( datalen > 200 )
printf("my RELAYID.%d of %d\n",myinfo->NOTARY.RELAYID,myinfo->NOTARY.NUMRELAYS);
}

2
basilisk/basilisk_swap.c

@ -1098,6 +1098,7 @@ void basilisk_swaploop(void *_swap)
maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + 300;
myinfo->DEXactive = expiration;
while ( time(NULL) < expiration )
{
printf("A r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits);
@ -1123,6 +1124,7 @@ void basilisk_swaploop(void *_swap)
}
if ( time(NULL) >= expiration )
retval = -1;
myinfo->DEXactive = swap->expiration;
printf("C r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits);
if ( retval == 0 && (swap->statebits & 0x40) == 0 ) // send fee
{

5
basilisk/basilisk_tradebot.c

@ -230,7 +230,8 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
{
cJSON *array,*item; int32_t i,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.;
memset(&refR,0,sizeof(refR));
if ( (array= jarray(&n,retjson,"result")) != 0 )
//printf("process.(%s)\n",jprint(retjson,0));
if ( (array= jarray(&n,retjson,"messages")) != 0 )
{
for (i=nonz=m=0; i<n; i++)
{
@ -258,7 +259,7 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
basilisk_parsejson(&list[m++],item);
}
}
printf("process_results n.%d m.%d nonz.%d\n",n,m,nonz);
//printf("process_results n.%d m.%d nonz.%d\n",n,m,nonz);
if ( m > 0 && m < sizeof(list)/sizeof(*list) )
if ( (metric= basilisk_request_listprocess(myinfo,&tmpR,list,m)) > hwm )
*issueR = tmpR, hwm = metric;

35
deprecated/obsolete.h

@ -19152,5 +19152,40 @@ len = 0;
//s->hdrsi = hdrsi;
//s->bundlei = bundlei;
//char str[65]; printf("%s set prevout.%d -> %d\n",bits256_str(str,prev_hash),prev_vout,s->prevout);
//if ( pkind != 0 )
// s->prevspendind = A[pkind].lastspendind;
// respond to incoming RID, ACC, DEX, QST
/*char *basilisk_respond_RID(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_respond_requests(myinfo,hash,juint(valsobj,"requestid"),0));
}
char *basilisk_respond_SWP(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_respond_swapstatus(myinfo,hash,juint(valsobj,"requestid"),juint(valsobj,"quoteid")));
}
char *basilisk_respond_ACC(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 requestid,quoteid;
if ( (requestid= juint(valsobj,"requestid")) != 0 && (quoteid= juint(valsobj,"quoteid")) != 0 )
return(basilisk_respond_accept(myinfo,requestid,quoteid));
else return(clonestr("{\"error\":\"need nonzero requestid and quoteid\"}"));
}
char *basilisk_respond_DEX(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=0,buf[256]; struct basilisk_request R;
if ( basilisk_request_create(&R,valsobj,hash,juint(valsobj,"timestamp")) == 0 )
{
char str[65]; printf("DEX.(%s %.8f) -> %s %s\n",R.src,dstr(R.srcamount),R.dest,bits256_str(str,hash));
if ( basilisk_request_enqueue(myinfo,&R) != 0 )
{
sprintf(buf,"{\"result\":\"DEX request added\",\"requestid\":%u}",R.requestid);
retstr = clonestr(buf);
} else retstr = clonestr("{\"error\":\"DEX quote couldnt be created\"}");
} else retstr = clonestr("{\"error\":\"missing or invalid fields\"}");
return(retstr);
}*/

2
iguana/coins/gennotary

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"NOTARY\",\"services\":128,\"maxpeers\":2048,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":7776,\"rpc\":0}"
curl --url "http://127.0.0.1:7776" --data "{\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"NOTARY\",\"services\":128,\"maxpeers\":2048,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":7775,\"rpc\":0}"

1
iguana/coins/notary

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"NOTARY\",\"services\":128,\"maxpeers\":2048,\"RELAY\":0,\"VALIDATE\":0,\"portp2p\":7775,\"rpc\":0}"

13
iguana/iguana777.c

@ -619,15 +619,24 @@ int32_t iguana_coin_mainiter(struct supernet_info *myinfo,struct iguana_info *co
//printf("%s n.%d emitfinished.%d coin->spendvectorsaved %d\n",coin->symbol,n,iguana_emitfinished(myinfo,coin,1),coin->spendvectorsaved);
if ( iguana_emitfinished(myinfo,coin,1) >= n )
{
if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 )
/*if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 )
{
for (j=0; j<n; j++)
if ( coin->bundles[j] != 0 )
iguana_alloctxbits(coin,&coin->bundles[j]->ramchain);
sleep(3);
}
}*/
if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n )
{
iguana_fastfindreset(coin);
iguana_fastfindcreate(coin);
if ( coin->fastfind == 0 )
{
for (j=0; j<n; j++)
if ( coin->bundles[j] != 0 )
iguana_alloctxbits(coin,&coin->bundles[j]->ramchain);
sleep(3);
}
coin->spendvectorsaved = 1;
printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin));
}

49
iguana/iguana_init.c

@ -400,14 +400,18 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
long iguana_bundlesload(struct supernet_info *myinfo,struct iguana_info *coin)
{
char fname[1024]; int32_t iter = 1; FILE *fp; long fpos = -1;
sprintf(fname,"%s/%s_%s.txt",GLOBAL_CONFSDIR,coin->symbol,(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
if ( (fp= fopen(fname,"r")) != 0 )
char fname[1024]; int32_t iter; FILE *fp; long fpos = -1;
for (iter=0; iter<2; iter++)
{
iguana_parseline(myinfo,coin,iter,fp);
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
fpos = ftell(fp);
fclose(fp);
sprintf(fname,"%s/%s_%s.txt",GLOBAL_CONFSDIR,coin->symbol,(iter == 0) ? "hdrs" : "oldhdrs"), OS_compatible_path(fname);
if ( (fp= fopen(fname,"r")) != 0 )
{
iguana_parseline(myinfo,coin,1,fp);
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
fpos = ftell(fp);
fclose(fp);
break;
}
}
return(fpos);
}
@ -511,7 +515,7 @@ void iguana_coinpurge(struct iguana_info *coin)
struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_info *coin,int32_t initialheight,int32_t mapflags)
{
FILE *fp; char fname[512],*symbol; int32_t iter; long fpos; bits256 lastbundle;
FILE *fp; char fname[512],*symbol; int32_t j,iter; long fpos; bits256 lastbundle;
/*if ( coin->peers == 0 )
{
printf("cant start privatechain directly\n");
@ -604,21 +608,26 @@ struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_
{
}
#endif
sprintf(fname,"%s/%s_%s.txt",GLOBAL_CONFSDIR,coin->symbol,(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
//sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
//sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
OS_compatible_path(fname);
if ( (fp= fopen(fname,"r")) != 0 )
fpos = -1;
for (j=0; j<2; j++)
{
if ( coin->virtualchain == 0 || iter > 0 )
sprintf(fname,"%s/%s_%s%s.txt",GLOBAL_CONFSDIR,coin->symbol,j==0?"":"old",(iter == 0) ? "peers" : "hdrs"), OS_compatible_path(fname);
//sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
//sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
OS_compatible_path(fname);
if ( (fp= fopen(fname,"r")) != 0 )
{
printf("parsefile.%d %s\n",iter,fname);
iguana_parseline(myinfo,coin,iter,fp);
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
if ( coin->virtualchain == 0 || iter > 0 )
{
printf("parsefile.%d %s\n",iter,fname);
iguana_parseline(myinfo,coin,iter,fp);
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
}
fpos = ftell(fp);
fclose(fp);
break;
}
fpos = ftell(fp);
fclose(fp);
} else fpos = -1;
}
}
#ifndef IGUANA_DEDICATED_THREADS
coin->peers->peersloop = iguana_launch("peersloop",iguana_peersloop,coin,IGUANA_PERMTHREAD);

9
iguana/iguana_msg.c

@ -474,8 +474,11 @@ int32_t iguana_send_ping(struct supernet_info *myinfo,struct iguana_info *coin,s
int32_t len; uint64_t nonce; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(nonce)];
if ( addr->msgcounts.verack == 0 )
{
printf("%s send version instead of ping to %s\n",coin->symbol,addr->ipaddr);
return(iguana_send_version(coin,addr,coin->myservices));
if ( strcmp(addr->ipaddr,myinfo->ipaddr) != 0 )
{
printf("%s send version instead of ping to %s\n",coin->symbol,addr->ipaddr);
return(iguana_send_version(coin,addr,coin->myservices));
}
}
if ( (nonce= addr->pingnonce) == 0 )
{
@ -1007,7 +1010,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
{
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblocks; uint32_t tmp,n=0;
len = 0;
if ( addr != 0 && recvlen >= sizeof(bits256) && strcmp("BTCD",coin->symbol) != 0 )
if ( addr != 0 && recvlen >= sizeof(bits256) && strcmp("NOTARY",coin->symbol) != 0 )
{
if ( ishost == 0 )
{

10
iguana/iguana_peers.c

@ -557,7 +557,7 @@ int32_t iguana_queue_send(struct iguana_peer *addr,int32_t delay,uint8_t *serial
packet->embargo.millis += delay;
}
memcpy(packet->serialized,serialized,datalen);
if ( 0 && addr->basilisk != 0 )
if ( 0 && addr->supernet != 0 )
printf("%p queue send.(%s) %d to (%s)\n",packet,serialized+4,datalen,addr->ipaddr);
queue_enqueue("sendQ",&addr->sendQ,&packet->DL,0);
return(datalen);
@ -584,7 +584,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len)
remains -= recvlen;
//int32_t i; for (i=0; i<recvlen; i++)
// printf("%02x",recvbuf[i]);
//printf("got %d remains.%d of total.%d from (%s)\n",recvlen,remains,len,ipaddr);
//printf("got %d remains.%d of total.%d from (%s)\n",recvlen,remains,len,ipaddr);
recvbuf = &recvbuf[recvlen];
} else usleep(10000);
}
@ -666,7 +666,11 @@ void _iguana_processmsg(struct supernet_info *myinfo,struct iguana_info *coin,in
printf("%s recv error on (%s) len.%d errno.%d (%s)\n",addr->ipaddr,H.command,len,-recvlen,strerror(-recvlen));
if ( buf != _buf )
myfree(buf,len);
//addr->dead = (uint32_t)time(NULL);
if ( addr->numrecverrs++ > 10 )
{
addr->dead = (uint32_t)time(NULL);
addr->numrecverrs = 0;
}
return;
}
}

2
iguana/iguana_spendvectors.c

@ -56,7 +56,7 @@ int32_t iguana_spendvectorsave(struct iguana_info *coin,struct iguana_bundle *bp
int32_t i,retval = -1; FILE *fp; char fname[1024],str[65]; long fsize; bits256 zero,sha256;
if ( ptr == 0 || (bp->hdrsi != 0 && ptr == bp->ramchain.Xspendinds) )
{
printf("iguana_spendvectorsave.[%d] ptr.%p Xspendinds\n",bp->hdrsi,ptr);
//printf("iguana_spendvectorsave.[%d] ptr.%p Xspendinds\n",bp->hdrsi,ptr);
return(0);
}
memset(zero.bytes,0,sizeof(zero));

31
iguana/iguana_txidfind.c

@ -452,9 +452,26 @@ static int _bignum_cmp(const void *a,const void *b)
return(0);
}
int32_t iguana_fastfindreset(struct iguana_info *coin)
{
int32_t i,n = 0;
for (i=0; i<0x100; i++)
{
if ( coin->fast[i] != 0 )
munmap(coin->fast[i],coin->fastsizes[i]), n++;
if( coin->fasttables[i] != 0 )
free(coin->fasttables[i]);
coin->fast[i] = 0;
coin->fastsizes[i] = 0;
coin->fasttables[i] = 0;
}
coin->fastfind = 0;
return(n);
}
uint32_t iguana_fastfindinit(struct iguana_info *coin)
{
int32_t i,j,iter,num,tablesize,*hashtable; uint8_t *sorted; char fname[1024];
int32_t i,iter,num,tablesize,*hashtable; uint8_t *sorted; char fname[1024];
//if ( strcmp("BTC",coin->symbol) != 0 )
// return(0);
if ( coin->fastfind != 0 )
@ -500,17 +517,7 @@ uint32_t iguana_fastfindinit(struct iguana_info *coin)
coin->fastfind = (uint32_t)time(NULL);
printf("initialized fastfind.%s iter.%d\n",coin->symbol,iter);
return(coin->fastfind);
}
else
{
for (j=0; j<i; j++)
{
munmap(coin->fast[i],coin->fastsizes[i]);
free(coin->fasttables[i]);
coin->fast[i] = 0;
coin->fastsizes[i] = 0;
}
}
} else iguana_fastfindreset(coin);
}
return(0);
}

18
iguana/iguana_wallet.c

@ -1126,7 +1126,11 @@ cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
{
addr = &coin->peers->active[i];
if ( addr->usock >= 0 && addr->supernet != 0 && addr->ipaddr[0] != 0 )
{
jaddistr(array,addr->ipaddr);
if ( strcmp(coin->symbol,"NOTARY") == 0 )
basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(addr->ipaddr),GENESIS_PUBKEY);
}
}
jadd(retjson,"supernet",array);
jaddnum(retjson,"connections",coin->peers->numranked);
@ -1140,7 +1144,7 @@ cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
ZERO_ARGS(bitcoinrpc,getinfo)
{
struct basilisk_item Lptr,*ptr; int32_t i,j,m,n,longest; cJSON *valsobj,*getinfoobj=0,*array,*item,*fullnodes;
struct basilisk_item Lptr,*ptr; int32_t incr,i,j,m,n,longest; cJSON *valsobj,*getinfoobj=0,*array,*item,*fullnodes;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
@ -1174,7 +1178,17 @@ ZERO_ARGS(bitcoinrpc,getinfo)
}
if ( (fullnodes= jarray(&m,item,"supernet")) != 0 )
{
for (j=0; j<m; j++)
incr = 1;
if ( strcmp(coin->symbol,"NOTARY") == 0 )
{
for (j=0; j<m; j++)
basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(jstri(fullnodes,j)),GENESIS_PUBKEY);
incr = sqrt(m);
if ( incr < 1 )
incr = 1, j = 0;
else j = (myinfo->myaddr.pubkey.uints[0] % incr);
} else j = 0;
for (; j<m; j+=incr)
{
//fprintf(stderr,"[%s] ",jstri(fullnodes,j));
iguana_launchpeer(coin,jstri(fullnodes,j),1);

10
iguana/main.c

@ -210,7 +210,7 @@ int32_t iguana_jsonQ(struct supernet_info *myinfo,struct iguana_info *coin)
{
if ( (ptr->retjsonstr= SuperNET_jsonstr(ptr->myinfo,ptr->jsonstr,ptr->remoteaddr,ptr->port)) == 0 )
ptr->retjsonstr = clonestr("{\"error\":\"null return from iguana_jsonstr\"}");
printf("finished.(%s) -> (%s) %.0f\n",ptr->jsonstr,ptr->retjsonstr!=0?ptr->retjsonstr:"null return",OS_milliseconds());
//printf("finished.(%s) -> (%s) %.0f\n",ptr->jsonstr,ptr->retjsonstr!=0?ptr->retjsonstr:"null return",OS_milliseconds());
queue_enqueue("finishedQ",finishedQ,&ptr->DL,0);
return(1);
}
@ -1408,6 +1408,10 @@ ZERO_ARGS(SuperNET,activehandle)
retjson = SuperNET_rosettajson(myinfo,myinfo->persistent_priv,0);
jaddstr(retjson,"result","success");
jaddstr(retjson,"handle",myinfo->handle);
if ( myinfo->ipaddr[0] != 0 )
jaddstr(retjson,"myip",myinfo->ipaddr);
if ( myinfo->IAMRELAY != 0 )
jaddnum(retjson,"notary",myinfo->NOTARY.RELAYID);
jaddbits256(retjson,"persistent",myinfo->myaddr.persistent);
if ( myinfo->expiration != 0 )
{
@ -1549,14 +1553,14 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
#include "../includes/iguana_apiundefs.h"
void iguana_relays_init(struct supernet_info *myinfo)
/*void iguana_relays_init(struct supernet_info *myinfo)
{
static char *ipaddrs[] = { "78.47.196.146", "5.9.102.210" };//"89.248.160.237", "89.248.160.238", "89.248.160.239", "89.248.160.240", "89.248.160.241", "89.248.160.242", "89.248.160.243", "89.248.160.244" };
char *str; int32_t i;
for (i=0; i<sizeof(ipaddrs)/sizeof(*ipaddrs); i++)
if ( (str= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddrs[i]),GENESIS_PUBKEY)) != 0 )
free(str);
}
}*/
void iguana_main(void *arg)
{

11
iguana/tests/addnotarys

@ -0,0 +1,11 @@
../coins/notary
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.237\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.238\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.239\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.240\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.241\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.242\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.243\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.244\"}"
sleep 3
./getinfoN

8
iguana/tests/addnotarys_7776

@ -0,0 +1,8 @@
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.237\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.238\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.239\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.240\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.241\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.242\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.243\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"NOTARY\",\"ipaddr\":\"89.248.160.244\"}"

8
iguana/tests/addrelays

@ -1,8 +0,0 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.237\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.238\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.239\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.240\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.241\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.242\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.243\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addnode\",\"activecoin\":\"BTCD\",\"ipaddr\":\"89.248.160.244\"}"

1
iguana/tests/getinfoN

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"NOTARY\",\"method\":\"getinfo\",\"params\":[]}"

1
iguana/tests/getinfoN_7776

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7776" --data "{\"coin\":\"NOTARY\",\"method\":\"getinfo\",\"params\":[]}"

9
iguana/tests/notaryinit

@ -0,0 +1,9 @@
myip=`cat myip.txt`
pkill iguana
../agents/iguana notary &
sleep 3
coins/gennotary
tests/addnotarys_7776
tests/getinfoN_7776
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"SuperNET\",\"method\":\"myipaddr\",\"ipaddr\":\"$myip\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"SuperNET\",\"method\":\"activehandle\"}"

1
includes/iguana_funcs.h

@ -451,6 +451,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
void iguana_utxoaddrs_purge(struct iguana_info *coin);
int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight,uint8_t *rmd160);
int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr);
int32_t iguana_fastfindreset(struct iguana_info *coin);
int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin);
int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t lasthdrsi);
uint8_t iguana_addrtype(struct iguana_info *coin,uint8_t script_type);

2
includes/iguana_structs.h

@ -341,7 +341,7 @@ struct iguana_peer
struct iguana_msgaddress A;
char ipaddr[64],lastcommand[16],coinname[64],symbol[64];
uint64_t pingnonce,totalsent,totalrecv,ipbits; double pingtime,sendmillis,pingsum,getdatamillis;
uint32_t lastcontact,sendtime,ready,startsend,startrecv,pending,lastgotaddr,lastblockrecv,pendtime,lastflush,lastpoll,myipbits,persistent_peer,protover;
uint32_t lastcontact,sendtime,ready,startsend,startrecv,pending,lastgotaddr,lastblockrecv,pendtime,lastflush,lastpoll,myipbits,persistent_peer,protover,numrecverrs;
int32_t supernet,basilisk,dead,addrind,usock,lastheight,relayflag,numpackets,numpings,ipv6,height,rank,pendhdrs,pendblocks,recvhdrs,lastlefti,validpub,othervalid,dirty[2],laggard,headerserror,lastsent,isrelay;
double recvblocks,recvtotal;
int64_t allocated,freed;

Loading…
Cancel
Save