Browse Source

Merge remote-tracking branch 'refs/remotes/jl777/master'

release/v0.1
usamir 8 years ago
parent
commit
9f23c2f2c8
  1. 89
      iguana/example.js
  2. 46
      iguana/iguana777.c
  3. 2
      iguana/iguana_bundles.c
  4. 2
      iguana/iguana_json.c
  5. 8
      iguana/iguana_recv.c
  6. 10
      iguana/iguana_rpc.c
  7. 3
      iguana/iguana_spendvectors.c
  8. 2
      iguana/main.c
  9. 7
      iguana/manifest.json
  10. 2
      includes/iguana_structs.h

89
iguana/example.js

@ -46,23 +46,98 @@ function errorHandler(e,callback,name) {
}
var fileSystem=null;
var files={};
function onInitFs(fs) {
console.log('Opened file system: ' + fs.name);
fileSystem = fs;
function copyHelpFiles(callback) {
var helpFiles = [
'agent.md',
'bootstrap-theme.min.css',
'bootstrap.min.css',
'bootstrap.min.js',
'field.html',
'field.md',
'footer.html',
'footer.md',
'formfooter.html',
'formfooter.md',
'formheader.html',
'formheader.md',
'header.html',
'header.md',
'html5shiv.min.js',
'jquery-ui.css',
'jquery-ui.min.js',
'jquery.min.js',
'mime.json',
'respond.min.js'
];
var rootDir='help';
var $dfds = $.map(helpFiles,function(fname){
var $dfd=$.Deferred();
$.get(chrome.runtime.getURL(rootDir+'/'+fname))
.done(function(str){
fileSystem.root.getFile('/'+rootDir+'/'+fname, {
create: true
}, function(fileEntry) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function() {
console.log('Write completed.',fname,str.length);
$dfd.resolve(true);
};
fileWriter.onerror = function(e) {
console.log('Write failed: ',fname, e.toString());
$dfd.resolve(false);
};
// Create a new Blob and write it to log.txt.
var blob = new Blob([str], {
type: 'text/plain'
});
fileWriter.write(blob);
// $dfd.resolve(true);
}, function(createWriterErr){
console.log('createWriterErr for',fname,createWriterErr);
$dfd.resolve(false);
});
}, function(createFileErr){
console.log('createFileErr for',fname,createFileErr);
$dfd.resolve(false);
});
});
return $dfd;
});
return $.when.apply($,$dfds);
}
// Called by the common.js module.
function domContentLoaded(name, tc, config, width, height) {
navigator.webkitPersistentStorage.requestQuota(10000000000,
function(bytes){
window.requestFileSystem(PERSISTENT, bytes, onInitFs, errorHandler);
function(bytes) {
window.requestFileSystem(PERSISTENT, bytes, function(fs) {
console.log('Opened file system: ' + fs.name);
fileSystem = fs;
copyHelpFiles().done(function() {
common.updateStatus(
'Allocated ' + bytes + ' bytes of persistent storage. Running the first time will take 17 seconds to load');
common.attachDefaultListeners();
common.createNaClModule(name, tc, config, width, height);
}, function(e){
});
/*dirReader = fs.root.createReader();
dirReader.readEntries(function(results) {
console.log(results);
}, function(){
console.log('File IO error');
});*/
}, errorHandler);
},
function(e) {
console.log('Error', e);
});
});
}

46
iguana/iguana777.c

@ -459,8 +459,8 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
return(0);
}
printf("helperid.%d start utxogen\n",helperid);
if ( (incr= IGUANA_NUMHELPERS) > 4 )
incr = 4;
if ( (incr= IGUANA_NUMHELPERS) > 8 )
incr = 8;
//if ( 1 || coin->PREFETCHLAG > 0 ) // data issues on slow systems
// incr = 1;
max = coin->bundlescount;
@ -514,42 +514,43 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
{
printf("validate.[%d] error. refresh page or restart iguana and it should regenerate\n",bp->hdrsi);
exit(-1);
} else printf("helperid.%d validated.[%d]\n",helperid,hdrsi);
} else printf("%s helperid.%d validated.[%d]\n",coin->symbol,helperid,hdrsi);
}
}
while ( iguana_validated(coin) < max || iguana_utxofinished(coin) < max || iguana_balancefinished(coin) < max )
{
printf("helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max);
printf("%s helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",coin->symbol,helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max);
sleep(IGUANA_NUMHELPERS+3);
}
if ( helperid == 0 )
{
coin->spendvectorsaved = (uint32_t)time(NULL);
printf("UTXOGEN spendvectorsaved <- %u\n",coin->spendvectorsaved);
coin->spendvalidated = 0;
printf("%s UTXOGEN spendvectorsaved <- %u\n",coin->symbol,coin->spendvectorsaved);
}
else
{
while ( coin->spendvectorsaved <= 1 )
sleep(IGUANA_NUMHELPERS+3);
}
printf("helper.%d helperdone\n",helperid);
printf("%s helper.%d helperdone\n",coin->symbol,helperid);
return(num);
}
void iguana_helper(void *arg)
{
static int32_t maxhelperid;
static uint64_t helperidbits;
cJSON *argjson=0; int32_t iter,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0;
struct iguana_helper *ptr; struct iguana_info *coin,*tmp; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; struct supernet_info *myinfo = SuperNET_MYINFO(0);
helperid %= 64;
if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 )
helperid = juint(argjson,"helperid");
if ( helperid > maxhelperid )
maxhelperid = helperid;
if ( helperid < maxhelperid )
if ( ((1 << helperid) & helperidbits) != 0 )
{
printf("SKIP duplicate helper.%d\n",helperid);
return;
}
helperidbits |= (1 << helperid);
if ( IGUANA_NUMHELPERS < 2 )
type = 3;
else type = (1 << (helperid % 2));
@ -561,6 +562,7 @@ void iguana_helper(void *arg)
sleep(2);
while ( 1 )
{
//printf("helperid.%d top of loop\n",helperid);
flag = 0;
//iguana_jsonQ(); cant do this here
allcurrent = 1;
@ -570,11 +572,14 @@ void iguana_helper(void *arg)
{
if ( coin->spendvectorsaved == 1 )
iguana_utxogen(myinfo,coin,helperid,0);
else if ( coin->spendvectorsaved > 1 )
else if ( coin->spendvectorsaved > 1 && (coin->spendvalidated & (1 << helperid)) == 0 )
{
//printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid);
for (j=helperid; j<coin->bundlescount-1; j+=IGUANA_NUMHELPERS)
if ( (bp= coin->bundles[j]) != 0 )
iguana_bundlevalidate(coin,bp,0);
coin->spendvalidated |= (1 << helperid);
//printf("DONE %s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid);
}
}
//portable_mutex_unlock(&myinfo->allcoins_mutex);
@ -660,8 +665,8 @@ void iguana_coinloop(void *arg)
myinfo = SuperNET_MYINFO(0);
n = (int32_t)(long)coins[0];
coins++;
printf("begin coinloop[%d]\n",n);
coin = coins[0];
printf("begin coinloop[%d] %s\n",n,coin->symbol);
memset(zero.bytes,0,sizeof(zero));
while ( 1 )
{
@ -670,7 +675,6 @@ void iguana_coinloop(void *arg)
{
if ( (coin= coins[i]) != 0 )
{
//printf("%s loop\n",coin->symbol);
if ( coin->peers == 0 )
{
printf("FATAL lack of peers struct\n");
@ -689,11 +693,14 @@ void iguana_coinloop(void *arg)
#endif
}
if ( coin->started == 0 && coin->active != 0 )
{
iguana_callcoinstart(myinfo,coin);
}
now = (uint32_t)time(NULL);
coin->idletime = 0;
if ( coin->started != 0 && coin->active != 0 )
{
// printf("%s numranked.%d isRT.%d numsaved.%d M.%d L.%d numverified.%d hdrsi.%d\n",coin->symbol,coin->peers->numranked,coin->isRT,coin->numsaved,coin->blocks.hwmchain.height,coin->longestchain,coin->numverified,coin->current!=0?coin->current->hdrsi:-1);
if ( coin->peers->numranked > 4 && coin->isRT == 0 && now > coin->startutc+77 && coin->numsaved >= (coin->longestchain/coin->chain->bundlesize)*coin->chain->bundlesize && coin->blocks.hwmchain.height >= coin->longestchain-30 )
{
fprintf(stderr,">>>>>>> %s isRT blockrecv.%d.%d\n",coin->symbol,coin->blocksrecv,coin->longestchain);
@ -703,12 +710,12 @@ void iguana_coinloop(void *arg)
if ( coin->MAXPEERS > IGUANA_MINPEERS )
coin->MAXPEERS = IGUANA_MINPEERS;
}
if ( coin->isRT != 0 && coin->current != 0 && coin->numverified >= coin->current->hdrsi )
/*if ( coin->isRT != 0 && coin->current != 0 && coin->numverified >= coin->current->hdrsi )
{
//static int32_t saved;
//if ( saved++ == 0 )
// iguana_coinflush(coin,1);
}
}*/
if ( coin->bindsock >= 0 )
{
if ( coin->MAXPEERS > 1 && coin->peers->numranked < IGUANA_MAXPEERS/2 && now > coin->lastpossible+10 )
@ -730,7 +737,6 @@ void iguana_coinloop(void *arg)
}
if ( coin->MAXPEERS > 1 && now > coin->peers->lastmetrics+10 )
{
//fprintf(stderr,"metrics\n");
coin->peers->lastmetrics = iguana_updatemetrics(myinfo,coin); // ranks peers
}
//if ( coin->longestchain+10000 > coin->blocks.maxbits )
@ -738,7 +744,7 @@ void iguana_coinloop(void *arg)
if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 || coin->MAXPEERS == 1 )
{
flag += iguana_processrecv(myinfo,coin);
if ( coin->RTheight > 0 && coin->RTheight > coin->chain->bundlesize )
if ( strcmp(coin->symbol,"BTCD") == 0 && coin->RTheight > 0 && coin->RTheight > coin->chain->bundlesize )
{
int32_t hdrsi,nonz,errs; struct iguana_pkhash *refP; struct iguana_bundle *bp;
hdrsi = (coin->RTheight / coin->chain->bundlesize) - 1;
@ -747,11 +753,13 @@ void iguana_coinloop(void *arg)
}
}
iguana_jsonQ();
}
} //else if ( strcmp(coin->symbol,"BTC") == 0 )
// printf("skip %s\n",coin->symbol);
coin->idletime = (uint32_t)time(NULL);
}
}
if ( flag == 0 && coin->isRT == 0 )
//printf("%s flag.%d isRT.%d polltimeout.%d numranked.%d\n",coin->symbol,flag,coin->isRT,coin->polltimeout,coin->peers->numranked);
if ( flag == 0 && coin->isRT == 0 && coin->peers != 0 )
usleep(coin->polltimeout*1000 + (coin->peers->numranked == 0)*1000000);
else if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize )
usleep(coin->polltimeout*1000 + 90000 + (coin->peers->numranked == 0)*1000000);

2
iguana/iguana_bundles.c

@ -1421,6 +1421,8 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
if ( coin->stucktime != 0 && time(NULL)-coin->stucktime > coin->maxstuck )
coin->maxstuck = (uint32_t)time(NULL) - coin->stucktime;
sprintf(str,"%s.RT%d u.%d+c.%d b.%d v.%d (%d+%d/%d 1st.%d).s%d to %d N[%d] h.%d r.%d c.%d s.%d d.%d E.%d maxB.%d peers.%d/%d Q.(%d %d) (L.%d %d:%d) M.%d %s",coin->symbol,coin->RTheight,numutxo,numconverted,numbalances,iguana_validated(coin),firstgap!=0?firstgap->numcached:-1,firstgap!=0?firstgap->numsaved:-1,firstgap!=0?firstgap->numhashes:-1,firstgap!=0?firstgap->hdrsi:-1,firstgap!=0?firstgap->numspec:-1,coin->lastpending!=0?coin->lastpending->hdrsi:0,count,numhashes,coin->blocksrecv,numcached,numsaved,done,numemit,coin->MAXBUNDLES,p,coin->MAXPEERS,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ),coin->longestchain,coin->longestchain/coin->chain->bundlesize,coin->longestchain%coin->chain->bundlesize,coin->blocks.hwmchain.height,bits256_str(str5,coin->blocks.hwmchain.RO.hash2));
if( strcmp("BTC",coin->symbol) == 0 )
printf("%s\n",str);
if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize && numemit == coin->current->hdrsi && numutxo == coin->bundlescount-1 )
{
//printf("have all utxo, generate balances\n");

2
iguana/iguana_json.c

@ -480,7 +480,7 @@ char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr)
int32_t i,n,len,size = 0; long filesize; cJSON *helpjson,*item,*array; char *str; FILE *fp = 0;
htmlstr[0] = 0;
pretty_forms(fname,agentstr,"html");
printf("autocreate %s\n","autoAPI.md");
//printf("autocreate %s\n","autoAPI.md");
pretty_forms("autoAPI.md",0,"md");
return(OS_filestr(&filesize,"index7778.html"));
sprintf(htmlstr,"<!DOCTYPE HTML><html> <head><title>SuperUGLY GUI></title></head> <body> ");

8
iguana/iguana_recv.c

@ -1342,7 +1342,7 @@ int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single
while ( flag < IGUANA_MAXITERATIONS && coin->active != 0 && (req= queue_dequeue(&coin->recvQ,0)) != 0 )
{
flag++;
//fprintf(stderr,"flag.%d %s recvQ.%p type.%c n.%d\n",flag,req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n);
//fprintf(stderr,"%s flag.%d %s recvQ.%p type.%c n.%d\n",coin->symbol,flag,req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n);
if ( req->type == 'B' ) // one block with all txdata
{
netBLOCKS--;
@ -1644,21 +1644,19 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin
coin->RTramchain_busy = 1;
if ( coin->balanceflush != 0 )
{
fprintf(stderr,"%s call balanceflush\n",coin->symbol);
if ( iguana_balanceflush(coin,coin->balanceflush) > 0 )
printf("balanceswritten.%d flushed coin->balanceflush %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,coin->balanceflush,coin->longestchain/coin->chain->bundlesize);
fprintf(stderr,"%s back balanceflush\n",coin->symbol);
coin->balanceflush = 0;
}
//printf("recvQ\n");
flag += iguana_processrecvQ(coin,&newhwm);
//printf("reqhdrs\n");
flag += iguana_reqhdrs(coin);
//if ( coin->spendvectorsaved > 1 )
{
if ( time(NULL) > coin->laststats+5 )
{
//printf("reqblocks\n");
flag += iguana_reqblocks(coin);
//printf("bundlestats\n");
iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG);
coin->laststats = (uint32_t)time(NULL);
}

10
iguana/iguana_rpc.c

@ -822,7 +822,7 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{
cJSON *tokens,*argjson,*origargjson,*json = 0; long filesize;
char symbol[16],buf[4096],urlmethod[16],*data,url[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
char symbol[16],buf[4096],urlmethod[16],*data,url[1024],furl[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
//printf("rpcparse.(%s)\n",urlstr);
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
@ -837,6 +837,12 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
j = i = 0;
filetype[0] = 0;
//printf("url.(%s) method.(%s)\n",&url[i],urlmethod);
#ifdef __PNACL__
char *prefix="DB/";
snprintf(furl, sizeof furl, "%s%s", prefix,url+1);
#else
snprintf(furl, sizeof furl, "%s", url+1);
#endif
if ( strcmp(&url[i],"/") == 0 && strcmp(urlmethod,"GET") == 0 )
{
static int counter;
@ -852,7 +858,7 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
return(filestr);
else return(clonestr("{\"error\":\"cant find index7778\"}"));
}
else if ( (filestr= OS_filestr(&filesize,url+1)) != 0 )
else if ( (filestr= OS_filestr(&filesize,furl)) != 0 )
{
*jsonflagp = 1;
for (i=(int32_t)strlen(url)-1; i>0; i--)

3
iguana/iguana_spendvectors.c

@ -725,7 +725,7 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle)
if ( i == 0 )
bp->utxofinish = bp->startutxo = (uint32_t)time(NULL);
}
if ( 1 || i < coin->bundlescount-1 )
if ( i < coin->bundlescount-1 )
{
printf("spendvectors.[%d] max.%d missing, will regen all of them\n",i,coin->bundlescount-1);
for (i=0; i<coin->bundlescount-1; i++)
@ -970,6 +970,7 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin)
}
}
coin->spendvectorsaved = (uint32_t)time(NULL);
coin->spendvalidated = 0;
return(0);
}

2
iguana/main.c

@ -701,7 +701,7 @@ void iguana_launchdaemons(struct supernet_info *myinfo)
{
sprintf(helperstr,"{\"helperid\":%d}",i);
helperargs = clonestr(helperstr);
printf("launch[%d] of %d (%s)\n",i,IGUANA_NUMHELPERS,helperstr);
printf("helper launch[%d] of %d (%s)\n",i,IGUANA_NUMHELPERS,helperstr);
iguana_launch(0,"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
}
iguana_launch(0,"rpcloop",iguana_rpcloop,myinfo,IGUANA_PERMTHREAD);

7
iguana/manifest.json

@ -16,6 +16,9 @@
"128": "icon128.png"
},
"minimum_chrome_version": "36",
"web_accessible_resources":[
"help/*"
],
"permissions": [
{ "socket": [
"tcp-listen:*:*",
@ -26,7 +29,9 @@
]
},
"unlimitedStorage",
{"fileSystem": ["write"]},
{"fileSystem": ["write",
"retainEntries",
"directory"]},
"storage",
"system.storage",
"system.display",

2
includes/iguana_structs.h

@ -391,7 +391,7 @@ struct iguana_info
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles;
int32_t MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,origbalanceswritten,balanceswritten,RTheight,RTdatabad;
bits256 balancehash,allbundles;
uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog,spendvectorsaved,laststats,lastinv2,symbolcrc; char VALIDATEDIR[512];
uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog,spendvectorsaved,laststats,lastinv2,symbolcrc,spendvalidated; char VALIDATEDIR[512];
int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy,emitbusy,stuckiters,virtualchain;
struct tai starttime; double startmillis;
struct iguana_chain *chain;

Loading…
Cancel
Save