Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
11c5874a88
  1. 42
      iguana/iguana777.c
  2. 5
      iguana/iguana777.h
  3. 21
      iguana/iguana_bundles.c
  4. 23
      iguana/iguana_init.c
  5. 37
      iguana/iguana_ramchain.c
  6. 4
      iguana/iguana_recv.c
  7. 19
      iguana/iguana_unspents.c
  8. 49
      iguana/main.c
  9. 27
      pnacl_main.h

42
iguana/iguana777.c

@ -208,14 +208,11 @@ void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct
uint32_t iguana_updatemetrics(struct iguana_info *coin)
{
char fname[512],tmpfname[512],oldfname[512],ipaddr[64],*prefix = ""; int32_t i,j; struct iguana_peer *addr,*tmpaddr; FILE *fp;
#ifdef __PNACL__
prefix = "";
#endif
char fname[512],tmpfname[512],oldfname[512],ipaddr[64]; int32_t i,j; struct iguana_peer *addr,*tmpaddr; FILE *fp;
iguana_peermetrics(coin);
sprintf(fname,"%sconfs/%s_peers.txt",prefix,coin->symbol), OS_compatible_path(fname);
sprintf(oldfname,"%sconfs/%s_oldpeers.txt",prefix,coin->symbol), OS_compatible_path(oldfname);
sprintf(tmpfname,"%s%s/%s/peers.txt",prefix,GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname);
sprintf(fname,"%s/%s_peers.txt",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname);
sprintf(oldfname,"%s/%s_oldpeers.txt",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(oldfname);
sprintf(tmpfname,"%s/%s/peers.txt",GLOBAL_TMPDIR,coin->symbol), OS_compatible_path(tmpfname);
if ( (fp= fopen(tmpfname,"w")) != 0 )
{
for (i=0; i<coin->peers.numranked; i++)
@ -236,7 +233,7 @@ uint32_t iguana_updatemetrics(struct iguana_info *coin)
}
if ( ftell(fp) > OS_filesize(fname) )
{
printf("new peers.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)OS_filesize(fname));
printf("new peers.txt %ld vs (%s) %ld (%s)\n",ftell(fp),fname,(long)OS_filesize(fname),GLOBAL_CONFSDIR);
fclose(fp);
OS_renamefile(fname,oldfname);
OS_copyfile(tmpfname,fname,1);
@ -524,7 +521,7 @@ void iguana_helper(void *arg)
myfree(ptr,ptr->allocsize);
flag++;
}*/
if ( queue_size(&bundlesQ) > 1 || queue_size(&validateQ) > 0 )
if ( queue_size(&bundlesQ) > 1 )
allcurrent = 0;
if ( flag != 0 )
usleep(polltimeout * 100 + 1);
@ -582,11 +579,10 @@ void iguana_coinloop(void *arg)
char *ipaddrs[] = { "5.9.102.210", "89.248.160.236", "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", "89.248.160.245", "78.47.58.62", "67.212.70.88", "94.102.50.69", "50.179.58.158", "194.135.94.30", "109.236.85.42", "104.236.127.154", "68.45.147.145", "37.59.14.7", "78.47.115.250", "188.40.138.8", "62.75.143.120", "82.241.71.230", "217.23.6.2", "73.28.172.128", "45.55.149.34", "192.0.242.54", "81.181.155.53", "91.66.185.97", "85.25.217.233", "144.76.239.66", "95.80.9.112", "80.162.193.118", "173.65.129.85", "2.26.173.58", "78.14.250.69", "188.226.253.77", "58.107.67.39", "124.191.37.212", "176.226.137.238", "69.145.25.85", "24.168.14.28", "73.201.180.47", "76.188.171.53", "63.247.147.166", "121.108.241.247", "36.74.36.125", "106.186.119.171", "188.166.91.37", "223.134.228.208", "89.248.160.244", "178.33.209.212", "71.53.156.38", "88.198.10.165", "24.117.221.0", "74.14.104.57", "158.69.27.82", "110.174.129.213", "75.130.163.51" };
for (j=0; j<sizeof(ipaddrs)/sizeof(*ipaddrs); j++)
{
printf("%s ",ipaddrs[j]);
//if ( j < IGUANA_MINPEERS )
// iguana_launchpeer(coin,ipaddrs[j]);
//else
iguana_possible_peer(coin,ipaddrs[j]);
//printf("%s ",ipaddrs[j]);
if ( j < IGUANA_MINPEERS )
iguana_launchpeer(coin,ipaddrs[j]);
else iguana_possible_peer(coin,ipaddrs[j]);
}
printf("possible peers\n");
}
@ -717,16 +713,16 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
if ( (coin->minconfirms = minconfirms) == 0 )
coin->minconfirms = (strcmp(symbol,"BTC") == 0) ? 3 : 10;
printf("ensure directories maxval.%d mult.%d start.%d end.%d\n",maxval,mult,coin->startPEND,coin->endPEND);
sprintf(dirname,"%sDB/ro/%s",prefix,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/ro",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/%s",prefix,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/%s/validated",prefix,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/%s/accounts",prefix,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/%s/spends",prefix,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/%s/vouts",prefix,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/ro/%s",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/ro",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/validated",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/accounts",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/spends",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/vouts",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
if ( coin->VALIDATEDIR[0] != 0 )
sprintf(dirname,"%s%s/%s",prefix,coin->VALIDATEDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s%s/%s",prefix,GLOBALTMPDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s",coin->VALIDATEDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,symbol), OS_ensure_directory(dirname);
if ( coin->chain == 0 && (coin->chain= iguana_createchain(json)) == 0 )
{
printf("cant initialize chain.(%s)\n",jstr(json,0));

5
iguana/iguana777.h

@ -888,8 +888,9 @@ int32_t iguana_validated(struct iguana_info *coin);
extern int32_t HDRnet,netBLOCKS;
extern queue_t bundlesQ,validateQ,emitQ,TerminateQ;
extern char GLOBALTMPDIR[];
extern queue_t bundlesQ,emitQ,TerminateQ;
extern char GLOBAL_TMPDIR[],GLOBAL_VALIDATEDIR[],GLOBAL_HELPDIR[],GLOBAL_DBDIR[],GLOBAL_CONFSDIR[];
#include "../includes/iguana_api.h"

21
iguana/iguana_bundles.c

@ -349,7 +349,7 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund
}
*bundleip = 0;
bits256_str(str,bundlehash2);
char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname);
char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname);
//sprintf(dirname,"DB/%s/%d",coin->symbol,bp->bundleheight), OS_ensure_directory(dirname);
//printf("ht.%d alloc.[%d] new hdrs.%s\n",bp->bundleheight,coin->bundlescount,bits256_str(str,bp->hashes[0]));
iguana_bundlehash2add(coin,0,bp,0,bundlehash2);
@ -422,10 +422,7 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl
void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
{
static const bits256 zero;
char fname[1024],dirname[1024],*prefix = ""; FILE *fp; int32_t hdrsi,m,j; uint32_t ipbits;
#ifdef __PNACL__
prefix = "";
#endif
char fname[1024],dirname[1024]; FILE *fp; int32_t hdrsi,m,j; uint32_t ipbits;
if ( bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 )
{
//printf("purged hdrsi.[%d] lag.%ld\n",bp->hdrsi,time(NULL) - bp->emitfinish);
@ -433,7 +430,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
{
if ( (ipbits= (uint32_t)coin->peers.active[j].ipbits) != 0 )
{
if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,bp->hashes[0],zero,1,1) >= 0 )
if ( iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,ipbits,bp->hashes[0],zero,1,1) >= 0 )
{
if ( (fp= fopen(fname,"rb")) != 0 )
{
@ -446,7 +443,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
else printf("error removing.(%s)\n",fname);
}
}
sprintf(dirname,"%s%s/%s/%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_remove_directory(dirname);
sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight), OS_remove_directory(dirname);
bp->purgetime = (uint32_t)time(NULL);
}
}
@ -738,10 +735,10 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
}
else
{
#ifndef __PNACL__
//#ifndef __PNACL__
int32_t checki,hdrsi; FILE *fp;
fname[0] = 0;
checki = iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1,0);
checki = iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,block->RO.hash2,zero,1,0);
if ( hdrsi == bp->hdrsi && checki == i && (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,0,SEEK_END);
@ -753,7 +750,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
fclose(fp);
}
else
#endif
//#endif
iguana_blockunmark(coin,block,bp,i,0);
}
}
@ -939,7 +936,7 @@ int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp,
/*if ( bp->hdrsi == 0 && iguana_peerblockrequest(coin,coin->blockspace,sizeof(coin->blockspace),0,bp->hashes[0],1) > 0 )
printf("GENESIS block validated\n");
else printf("GENESIS didnt validate bp.%p\n",bp);*/
//iguana_bundlevalidate(coin,bp,1);
iguana_bundlevalidate(coin,bp,1);
}
else
{
@ -1337,7 +1334,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
//sprintf(str+strlen(str),"%s.%-2d %s time %.2f files.%d Q.%d %d\n",coin->symbol,flag,str,(double)(time(NULL)-coin->starttime)/60.,coin->peers.numfiles,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ));
if ( time(NULL) > coin->lastdisp+3 && (strcmp(str,coin->lastdispstr) != 0 || time(NULL) > coin->lastdisp+60) )
{
printf("\n%s bQ.%d vQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),queue_size(&validateQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
printf("\n%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck);
strcpy(coin->lastdispstr,str);
if ( (rand() % 100) == 0 )
myallocated(0,0);

23
iguana/iguana_init.c

@ -53,12 +53,8 @@ void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t
void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
{
int32_t i; char dirname[1024],*prefix = "";
#ifdef __PNACL__
prefix = "";
#endif
sprintf(dirname,"%s%s/%s",prefix,GLOBALTMPDIR,coin->symbol), OS_portable_path(dirname);
sprintf(dirname,"%stmp/%s",prefix,coin->symbol), OS_portable_path(dirname);
int32_t i; char dirname[1024];
sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,coin->symbol), OS_portable_path(dirname);
portable_mutex_init(&coin->peers_mutex);
portable_mutex_init(&coin->blocks_mutex);
iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,sizeof(coin->blockspace),0);
@ -131,16 +127,13 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
int32_t iguana_savehdrs(struct iguana_info *coin)
{
char fname[512],shastr[65],tmpfname[512],tmpfname2[512],str2[65],str[65],oldfname[512],*prefix="";
char fname[512],shastr[65],tmpfname[512],tmpfname2[512],str2[65],str[65],oldfname[512];
bits256 sha256all; FILE *fp,*fp2; struct iguana_bundle *bp; int32_t hdrsi,n,retval = 0;
n = coin->blocks.hwmchain.height + 1;
#ifdef __PNACL__
prefix = "";
#endif
sprintf(tmpfname,"%s%s/%s/hdrs.txt",prefix,GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname);
sprintf(tmpfname2,"%s%s/%s/hdrs.h",prefix,GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname);
sprintf(oldfname,"%sconfs/%s_oldhdrs.txt",prefix,coin->symbol), OS_compatible_path(oldfname);
sprintf(fname,"%sconfs/%s_hdrs.txt",prefix,coin->symbol), OS_compatible_path(fname);
sprintf(tmpfname,"%s/%s/hdrs.txt",GLOBAL_TMPDIR,coin->symbol), OS_compatible_path(tmpfname);
sprintf(tmpfname2,"%s/%s/hdrs.h",GLOBAL_TMPDIR,coin->symbol), OS_compatible_path(tmpfname);
sprintf(oldfname,"%s/%s_oldhdrs.txt",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(oldfname);
sprintf(fname,"%s/%s_hdrs.txt",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname);
if ( (fp= fopen(tmpfname,"w")) != 0 )
{
if ( (fp2= fopen(tmpfname2,"w")) != 0 )
@ -497,7 +490,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
}
}
#endif
sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
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");

37
iguana/iguana_ramchain.c

@ -982,7 +982,7 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
printf("ramchainsave no data ptr\n");
return(-1);
}
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?"DB":GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,ramchain->numblocks,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?GLOBAL_DBDIR:GLOBAL_TMPDIR,fname,ipbits,hash2,prevhash2,ramchain->numblocks,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf(" wont save.(%s) bundlei.%d != checki.%d\n",fname,bundlei,checki);
return(-1);
@ -1011,10 +1011,10 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
return(-1);
}
}*/
#ifdef __PNACL__
/*#ifdef __PNACL__
static portable_mutex_t mutex;
portable_mutex_lock(&mutex);
#endif
#endif*/
if ( (fp= fopen(fname,"wb")) == 0 )
printf("iguana_ramchain_save: couldnt create.(%s) errno.%d\n",fname,errno);
else coin->peers.numfiles++;
@ -1032,9 +1032,9 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
*rdata = tmp;
fclose(fp);
}
#ifdef __PNACL__
portable_mutex_unlock(&mutex);
#endif
//#ifdef __PNACL__
// portable_mutex_unlock(&mutex);
//#endif
return(fpos);
}
@ -1316,7 +1316,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded)
{
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi;
char str[65],str2[65],*dirstr; long filesize; void *ptr; struct iguana_block *block;
char str[65],str2[65],dirstr[64]; long filesize; void *ptr; struct iguana_block *block;
/*if ( ramchain->expanded != 0 && (ramchain->sigsfileptr == 0 || ramchain->sigsfilesize == 0) )
{
sprintf(sigsfname,"sigs/%s/%s",coin->symbol,bits256_str(str,hash2));
@ -1330,8 +1330,10 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname
{
for (iter=0; iter<2; iter++)
{
dirstr = (iter == 0) ? "DB/ro" : "DB";
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?dirstr:GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,numblocks,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
strcpy(dirstr,GLOBAL_DBDIR);
if ( iter == 0 )
strcat(dirstr,"/ro");
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?dirstr:GLOBAL_TMPDIR,fname,ipbits,hash2,prevhash2,numblocks,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf("iguana_ramchain_map.(%s) illegal hdrsi.%d bundlei.%d %s\n",fname,hdrsi,bundlei,bits256_str(str,hash2));
continue;
@ -1811,7 +1813,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
block->fpos = fpos = -1;
iguana_ramchain_link(ramchain,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0);
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data);
char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname);
char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname);
//printf("Kspace.%p bp.[%d:%d] <- scriptspace.%d expanded.%d\n",Kspace,bp->hdrsi,bundlei,scriptspace,ramchain->expanded);
if ( T == 0 || U == 0 || S == 0 || B == 0 )
{
@ -1984,7 +1986,7 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru
}
if ( deletefile != 0 )
{
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1,1)) != i )
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,block->RO.hash2,zero,1,1)) != i )
{
printf("checki.%d vs %d mismatch? %s\n",checki,i,fname);
}
@ -2015,7 +2017,7 @@ int32_t iguana_oldbundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **p
if ( j == num )
{
ipbits[num] = fpipbits;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,fpipbits,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,fpipbits,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf("B iguana_ramchain_map.(%s) illegal hdrsi.%d bundlei.%d checki.%d\n",fname,hdrsi,bundlei,checki);
return(0);
@ -2038,7 +2040,7 @@ void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,str
int32_t checki,hdrsi; void *ptr = 0; FILE *fp; static const bits256 zero;
*filesizep = 0;
fname[0] = 0;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf("B iguana_ramchain_map.(%s) illegal hdrsi.%d bundlei.%d checki.%d\n",fname,hdrsi,bundlei,checki);
return(0);
@ -2493,20 +2495,17 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str
iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi);
if ( retval == 0 )//|| bp->generrs > 3 )
{
char dirname[1024],*prefix = "";
#ifdef __PNACL__
prefix = "";
#endif
char dirname[1024];
//printf("delete %d files hdrs.%d retval.%d\n",num,bp->hdrsi,retval);
if ( bp_n == bp->n && bp->n == coin->chain->bundlesize && bp->hdrsi < coin->bundlescount-3 )
{
for (j=starti; j<=endi; j++)
{
if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,1,bp->hashes[j],zero,1,1) >= 0 ) // ipbits[j]
if ( iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,1,bp->hashes[j],zero,1,1) >= 0 ) // ipbits[j]
coin->peers.numfiles -= OS_removefile(fname,0);
else printf("error removing.(%s)\n",fname);
}
sprintf(dirname,"%s%s/%s/%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_portable_rmdir(dirname,1);
sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight), OS_portable_rmdir(dirname,1);
}
sleep(1);
iguana_bundleload(coin,&newchain,bp,0);

4
iguana/iguana_recv.c

@ -166,7 +166,7 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl
{
int32_t bundlei,datalen,checki,hdrsi,fpos; char str[65],str2[65]; FILE *fp;
bits256 checkhash2; struct iguana_txblock *txdata = 0; static const bits256 zero;
if ( (bundlei= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,hash2,zero,1)) >= 0 )
if ( (bundlei= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,ipbits,hash2,zero,1)) >= 0 )
//if ( (bundlei= iguana_peerfname(coin,&hdrsi,fname,ipbits,hash2)) >= 0 )
{
if ( (fp= fopen(fname,"rb")) != 0 )
@ -637,7 +637,7 @@ int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,i
}
else if ( bp->hdrsi == coin->longestchain/bp->n )
{
checki = iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1,0);
checki = iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,block->RO.hash2,zero,1,0);
if ( (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,0,SEEK_END);

19
iguana/iguana_unspents.c

@ -1372,11 +1372,8 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle)
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
{
int32_t hdrsi,numpkinds,iter,numhdrsi,i,numunspents,err; struct iguana_bundle *bp;
char fname[1024],fname2[1024],destfname[1024],*prefix=""; bits256 balancehash,allbundles; FILE *fp,*fp2;
char fname[1024],fname2[1024],destfname[1024]; bits256 balancehash,allbundles; FILE *fp,*fp2;
struct iguana_utxo *Uptr; struct iguana_account *Aptr; struct sha256_vstate vstate,bstate;
#ifdef __PNACL__
prefix = "";
#endif
vupdate_sha256(balancehash.bytes,&vstate,0,0);
/*for (hdrsi=0; hdrsi<coin->bundlescount; hdrsi++)
if ( (bp= coin->bundles[hdrsi]) == 0 || bp->balancefinish <= 1 || bp->ramchain.H.data == 0 || bp->ramchain.A == 0 || bp->ramchain.Uextras == 0 )
@ -1395,8 +1392,8 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
numunspents = numpkinds = 0;
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (numunspents= bp->ramchain.H.data->numunspents) > 0 && (Aptr= bp->ramchain.A) != 0 && (Uptr= bp->ramchain.Uextras) != 0 )
{
sprintf(fname,"%s%s/%s/%d/debits.N%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight,numhdrsi);
sprintf(fname2,"%s%s/%s/%d/lastspends.N%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight,numhdrsi);
sprintf(fname,"%s/%s/%d/debits.N%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight,numhdrsi);
sprintf(fname2,"%s/%s/%d/lastspends.N%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight,numhdrsi);
if ( iter == 0 )
{
vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr)*numpkinds);
@ -1437,13 +1434,13 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
}
else if ( iter == 2 )
{
sprintf(destfname,"DB/%s/accounts/debits.%d",coin->symbol,bp->bundleheight);
sprintf(destfname,"%s/%s/accounts/debits.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
if ( OS_copyfile(fname,destfname,1) < 0 )
{
printf("balances error copying (%s) -> (%s)\n",fname,destfname);
return(-1);
}
sprintf(destfname,"DB/%s/accounts/lastspends.%d",coin->symbol,bp->bundleheight);
sprintf(destfname,"%s/%s/accounts/lastspends.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
if ( OS_copyfile(fname2,destfname,1) < 0 )
{
printf("balances error copying (%s) -> (%s)\n",fname2,destfname);
@ -1482,17 +1479,17 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
coin->peers.active[i].dead = (uint32_t)time(NULL);
#ifdef __linux__
char cmd[1024];
sprintf(cmd,"mksquashfs DB/%s %s.%d -comp xz",coin->symbol,coin->symbol,coin->balanceswritten);
sprintf(cmd,"mksquashfs %s/%s %s.%d -comp xz",GLOBAL_DBDIR,coin->symbol,coin->symbol,coin->balanceswritten);
if ( system(cmd) != 0 )
printf("error system(%s)\n",cmd);
else
{
sprintf(cmd,"sudo umount DB/ro/%s",coin->symbol);
sprintf(cmd,"sudo umount %s/ro/%s",GLOBAL_DBDIR,coin->symbol);
if ( system(cmd) != 0 )
printf("error system(%s)\n",cmd);
else
{
sprintf(cmd,"sudo mount %s.%d DB/ro/%s -t squashfs -o loop",coin->symbol,coin->balanceswritten,coin->symbol);
sprintf(cmd,"sudo mount %s.%d %s/ro/%s -t squashfs -o loop",coin->symbol,coin->balanceswritten,GLOBAL_DBDIR,coin->symbol);
if ( system(cmd) != 0 )
printf("error system(%s)\n",cmd);
}

49
iguana/main.c

@ -61,23 +61,28 @@ struct iguana_info *Coins[IGUANA_MAXCOINS];
char Userhome[512];
int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,BIGENDIAN;
uint32_t prices777_NXTBLOCK,MAX_DEPTH = 100;
queue_t helperQ,jsonQ,finishedQ,bundlesQ,validateQ,emitQ,TerminateQ;
queue_t helperQ,jsonQ,finishedQ,bundlesQ,emitQ,TerminateQ;
struct supernet_info MYINFO,**MYINFOS;
static int32_t initflag;
int32_t HDRnet,netBLOCKS;
cJSON *API_json;
#ifdef __linux__
char GLOBALTMPDIR[512] = "tmp";
int32_t IGUANA_NUMHELPERS = 8;
#else
#ifdef __PNACL__
char GLOBALTMPDIR[512] = "/tmp";
char GLOBAL_VALIDATEDIR[512] = "/DB/purgeable";
char GLOBAL_HELPDIR[512] = "/DB/help";
char GLOBAL_DBDIR[512] = "/DB";
char GLOBAL_CONFSDIR[512] = "/DB/confs";
char GLOBAL_TMPDIR[512] = "/tmp";
int32_t IGUANA_NUMHELPERS = 2;
#else
char GLOBALTMPDIR[512] = "tmp";
char GLOBAL_VALIDATEDIR[512] = "purgeable";
char GLOBAL_HELPDIR[512] = "help";
char GLOBAL_DBDIR[512] = "DB";
char GLOBAL_TMPDIR[512] = "tmp";
char GLOBAL_CONFSDIR[512] = "confs";
int32_t IGUANA_NUMHELPERS = 4;
#endif
#endif
struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char **retjsonstrp; char remoteaddr[64]; uint16_t port; char jsonstr[]; };
uint16_t SuperNET_API2num(char *agent,char *method)
@ -1186,8 +1191,8 @@ void iguana_commandline(struct supernet_info *myinfo,char *arg)
safecopy(Userhome,jstr(argjson,"userhome"),sizeof(Userhome));
if ( jstr(argjson,"tmpdir") != 0 )
{
safecopy(GLOBALTMPDIR,jstr(argjson,"tmpdir"),sizeof(GLOBALTMPDIR));
printf("GLOBAL tmpdir.(%s)\n",GLOBALTMPDIR);
safecopy(GLOBAL_TMPDIR,jstr(argjson,"tmpdir"),sizeof(GLOBAL_TMPDIR));
printf("GLOBAL tmpdir.(%s)\n",GLOBAL_TMPDIR);
}
printf("call argv JSON.(%s)\n",(char *)arg);
SuperNET_JSON(myinfo,argjson,0,myinfo->rpcport);
@ -1200,19 +1205,16 @@ void iguana_commandline(struct supernet_info *myinfo,char *arg)
void iguana_ensuredirs()
{
char dirname[512],*prefix = "";
#ifdef __PNACL__
prefix = "";
#endif
sprintf(dirname,"%shelp",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%sconfs",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%sDB/ECB",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%stmp",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%spurgeable",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%spurgeable/BTC",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%spurgeable/BTCD",prefix), OS_ensure_directory(dirname);
sprintf(dirname,"%s%s",prefix,GLOBALTMPDIR), OS_ensure_directory(dirname);
char dirname[512];
sprintf(dirname,"%s",GLOBAL_HELPDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_CONFSDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/ECB",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_TMPDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/BTC",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/BTCD",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_TMPDIR), OS_ensure_directory(dirname);
}
void iguana_Qinit()
@ -1221,7 +1223,6 @@ void iguana_Qinit()
iguana_initQ(&jsonQ,"jsonQ");
iguana_initQ(&finishedQ,"finishedQ");
iguana_initQ(&bundlesQ,"bundlesQ");
iguana_initQ(&validateQ,"validateQ");
iguana_initQ(&emitQ,"emitQ");
iguana_initQ(&TerminateQ,"TerminateQ");
}

27
pnacl_main.h

@ -348,30 +348,27 @@ void *HandleMessageThread(void *user_data)
static PP_Bool Instance_DidCreate(PP_Instance instance,uint32_t argc,const char* argn[],const char* argv[])
{
int nacl_io_init_ppapi(PP_Instance instance, PPB_GetInterface get_interface);
static pthread_t g_handle_message_thread;
static pthread_t chromeapp_thread;
static pthread_t g_handle_message_thread,chromeapp_thread;
long allocsize;
g_instance = instance;
// By default, nacl_io mounts / to pass through to the original NaCl
// filesystem (which doesn't do much). Let's remount it to a memfs
// filesystem.
// filesystem (which doesn't do much). Let's remount it to a memfs filesystem.
OS_init();
InitializeMessageQueue();
pthread_create(&g_handle_message_thread, NULL, &HandleMessageThread, NULL);
pthread_create(&chromeapp_thread,NULL,&CHROMEAPP_NAME,OS_filestr(&allocsize,CHROMEAPP_CONF));
nacl_io_init_ppapi(instance,g_get_browser_interface);
umount("/");
mount("", "/tmp", "memfs", 0, "");
mount("", /* source */
"/", /* target */
"html5fs", /* filesystemtype */
0, /* mountflags */
"type=PERSISTENT,expected_size=10000000000"); /* data */
mount("", /* source. Use relative URL */
"/http", /* target */
"httpfs", /* filesystemtype */
0, /* mountflags */
""); /* data */
mount("", "/", "memfs", 0, "");
mkdir("/tmp",0755);
mkdir("/DB",0755);
mount("","/tmp","html5fs",0,"type=TEMPORARY,expected_size=2000000000");
mount("confs","/DB","html5fs",0,"type=PERSISTENT,expected_size=10000000000");
/*mount("", // source. Use relative URL
"/http", // target
"httpfs", // filesystemtype
0, // mountflags
""); // data*/
PNACL_message("finished DidCreate %s\n",CHROMEAPP_STR);
initflag = 1;
return PP_TRUE;

Loading…
Cancel
Save