From 633aa63e86d6e7398184970553bf61ea3a30772d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Apr 2016 03:11:36 -0600 Subject: [PATCH] test --- iguana/iguana777.c | 5 +++++ iguana/iguana777.h | 2 +- iguana/iguana_init.c | 11 ++++++++++- iguana/iguana_peers.c | 32 +++++++++++++++++++++++++------- iguana/iguana_ramchain.c | 11 ++++++++++- iguana/iguana_unspents.c | 12 +++++++++++- 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index c445960b1..6168d001a 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -240,6 +240,11 @@ uint32_t iguana_updatemetrics(struct iguana_info *coin) OS_copyfile(tmpfname,fname,1); } else fclose(fp); } + else + { + printf("iguana_updatemetrics: couldnt create.(%s)\n",tmpfname); + return(0); + } return((uint32_t)time(NULL)); } diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 52696f5ff..e5e834390 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -836,7 +836,7 @@ uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits2 void iguana_launchpeer(struct iguana_info *coin,char *ipaddr); void iguana_spendvectorsQ(struct iguana_info *coin,struct iguana_bundle *bp); int8_t iguana_blockstatus(struct iguana_info *coin,struct iguana_block *block); -void iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits); +int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits); void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile); int32_t iguana_reqblocks(struct iguana_info *coin); void iguana_walletlock(struct supernet_info *myinfo); diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index a5dab49a0..fecb4d666 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -180,6 +180,11 @@ int32_t iguana_savehdrs(struct iguana_info *coin) OS_copyfile(tmpfname,fname,1); } else fclose(fp); } + else + { + printf("iguana_savehdrs: couldnt create.(%s)\n",tmpfname); + return(-1); + } myfree(hashes,coin->chain->bundlesize * sizeof(*hashes)); return(retval); } @@ -430,7 +435,11 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei FILE *fp; char fname[512],*symbol; int32_t iter; coin->sleeptime = 10000; symbol = coin->symbol; - iguana_peerslotinit(coin,&coin->internaladdr,IGUANA_MAXPEERS,calc_ipbits("127.0.0.1:7777")); + if ( iguana_peerslotinit(coin,&coin->internaladdr,IGUANA_MAXPEERS,calc_ipbits("127.0.0.1:7777")) < 0 ) + { + printf("iguana_coinstart: error creating peerslot\n"); + return(0); + } if ( initialheight < coin->chain->bundlesize*10 ) initialheight = coin->chain->bundlesize*10; iguana_recvalloc(coin,initialheight); diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 6e5315dd1..f5518e3ed 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -184,7 +184,13 @@ uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana else { if ( (fp= fopen(fname,"rb+")) == 0 ) - fp = fopen(fname,"wb"); + { + if ( (fp= fopen(fname,"wb")) == 0 ) + { + printf("iguana_rwAddrind: couldnt create.(%s)\n",fname); + return(-1); + } + } if ( fp != 0 ) { ipbits = (uint32_t)iA->ipbits; @@ -212,7 +218,12 @@ uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana } } else printf("iAddr: error seeking.[%d] %ld vs %ld\n",ind,ftell(fp),ind * sizeof(*iA)); fclose(fp); - } else printf("error creating.(%s)\n",fname); + } + else + { + printf("iguana_rwAddrind: couldnt create.(%s)\n",fname); + return(-1); + } } return(retval); } @@ -964,7 +975,7 @@ int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr) } #endif -void iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits) +int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32_t slotid,uint64_t ipbits) { char fname[1024]; addr->ipbits = ipbits; @@ -972,14 +983,17 @@ void iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,int32 sprintf(fname,"DB/%s/vouts/%04d.vouts",coin->symbol,addr->addrind); if ( (addr->voutsfp= fopen(fname,"rb+")) != 0 ) fseek(addr->voutsfp,0,SEEK_END); - else addr->voutsfp = fopen(fname,"wb+"); + else if ( (addr->voutsfp= fopen(fname,"wb+")) == 0 ) + return(-1); if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 ) { sprintf(fname,"purgeable/%s/%04d.vins",coin->symbol,addr->addrind); if ( (addr->vinsfp= fopen(fname,"rb+")) != 0 ) fseek(addr->vinsfp,0,SEEK_END); - else addr->vinsfp = fopen(fname,"wb+"); + else if ( (addr->vinsfp= fopen(fname,"wb+")) == 0 ) + return(-1); } + return(0); } void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr) @@ -987,6 +1001,11 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr) static uint32_t lastping; struct pollfd fds; struct iguana_bundlereq *req; uint8_t *buf; uint32_t ipbits; int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout; + if ( iguana_peerslotinit(coin,addr,(int32_t)(((long)addr - (long)&coin->peers.active[0]) / sizeof(*addr)),calc_ipbits(addr->ipaddr)) < 0 ) + { + printf("error creating peer's files\n"); + return; + } #ifdef IGUANA_PEERALLOC int32_t i; int64_t remaining; struct OS_memspace *mem[sizeof(addr->SEROUT)/sizeof(*addr->SEROUT)]; for (i=0; iSEROUT)/sizeof(*addr->SEROUT); i++) @@ -1001,8 +1020,7 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr) iguana_memreset(mem[i]); } #endif - iguana_peerslotinit(coin,addr,(int32_t)(((long)addr - (long)&coin->peers.active[0]) / sizeof(*addr)),calc_ipbits(addr->ipaddr)); - //addr->pubkey = GENESIS_PUBKEY; + //addr->pubkey = GENESIS_PUBKEY; ipbits = (uint32_t)addr->ipbits; vcalc_sha256(0,addr->iphash.bytes,(uint8_t *)&ipbits,sizeof(ipbits)); //char str[65]; printf("start dedicatedloop.%s addrind.%d %s\n",addr->ipaddr,addr->addrind,bits256_str(str,addr->iphash)); diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 9cbb94987..0b876bb66 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -945,6 +945,11 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits { if ( (fp= fopen(fname,"wb")) != 0 ) coin->peers.numfiles++; + else + { + printf("iguana_ramchain_save: couldnt create.(%s)\n",fname); + return(-1); + } } else if ( ipbits != 0 ) { @@ -953,7 +958,11 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits else { fclose(fp); - fp = fopen(fname,"wb"); + if ( (fp= fopen(fname,"wb")) != 0 ) + { + printf("iguana_ramchain_save b: couldnt create.(%s)\n",fname); + return(-1); + } } if ( fp != 0 ) { diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 649d19163..07000b2e4 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -823,7 +823,12 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp) //int32_t i; for (i=0; inumXspends; i++) // printf("(%d u%d) ",ramchain->Xspendinds[i].hdrsi,ramchain->Xspendinds[i].ind); //printf("filesize %ld Xspendptr.%p %p num.%d\n",fsize,ramchain->Xspendptr,ramchain->Xspendinds,ramchain->numXspends); - } else printf("Error creating.(%s)\n",fname); + } + else + { + printf("iguana_spendvectors: Error creating.(%s)\n",fname); + retval = -1; + } } if ( ptr != 0 ) myfree(ptr,sizeof(*ptr) * n); @@ -1215,6 +1220,11 @@ int32_t iguana_volatileinit(struct iguana_info *coin) printf("error writing.(%s)\n",crcfname); fclose(fp); } + else + { + printf("volatileinit: cant create.(%s)\n",crcfname); + return(-1); + } } } coin->RTheight = coin->balanceswritten * coin->chain->bundlesize;