diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 6cde2c6a9..edd529978 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -440,7 +440,7 @@ void iguana_coinloop(void *arg) { } coin = coins[0]; - iguana_possible_peer(coin,"127.0.0.1"); + iguana_launchpeer(coin,"127.0.0.1"); memset(zero.bytes,0,sizeof(zero)); if ( (bp= iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1)) != 0 ) bp->bundleheight = 0; @@ -494,15 +494,15 @@ void iguana_coinloop(void *arg) coin->lastpossible = iguana_possible_peer(coin,0); // tries to connect to new peers } } - if ( now > coin->peers.lastmetrics+6 ) + if ( now > coin->peers.lastmetrics+3 ) { //fprintf(stderr,"metrics\n"); coin->peers.lastmetrics = iguana_updatemetrics(coin); // ranks peers iguana_bundlestats(coin,str); } - flag += iguana_processrecv(coin); if ( coin->longestchain+10000 > coin->blocks.maxbits ) iguana_recvalloc(coin,coin->longestchain + 100000); + flag += iguana_processrecv(coin); } coin->idletime = (uint32_t)time(NULL); } diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 5a01c2852..96d2b5e3f 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -27,6 +27,7 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t //#define IGUANA_SERIALIZE_BALANCEGEN //#define IGUANA_DISABLEPEERS #define _IGUANA_MAXSTUCKTIME 300 +#define IGUANA_MAXITERATIONS 10000 #define IGUANA_MAXCOINS 64 #define IGUANA_MAXDELAY_MILLIS (3600 * 1000) @@ -827,6 +828,7 @@ void iguana_coinpurge(struct iguana_info *coin); int32_t iguana_setmaxbundles(struct iguana_info *coin); void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp); uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits256 txid,struct iguana_txid *T,uint32_t txidind,struct iguana_ramchain *ramchain); +void iguana_launchpeer(struct iguana_info *coin,char *ipaddr); extern int32_t HDRnet,netBLOCKS; diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index 4504292a3..00b898a6c 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -66,7 +66,14 @@ void iguana_acceptloop(void *args) struct pollfd pfd; int32_t sock; struct iguana_accept *ptr; uint16_t port = coin->chain->portp2p; socklen_t clilen; struct sockaddr_in cli_addr; char ipaddr[64]; uint32_t i,ipbits; while ( (coin->bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 ) + { + if ( coin->peers.localaddr != 0 ) + { + printf("another daemon running, no need to have iguana accept connections\n"); + return; + } sleep(5); + } printf(">>>>>>>>>>>>>>>> iguana_bindloop 127.0.0.1:%d bind sock.%d\n",port,coin->bindsock); printf("START ACCEPTING\n"); while ( coin->bindsock >= 0 ) diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index e270306de..8b314f806 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -929,7 +929,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru if ( coin->stucktime != 0 ) { lag = time(NULL)-coin->stucktime; - if ( lag/coin->MAXSTUCKTIME > coin->stuckiters ) + if ( ((lag/coin->MAXSTUCKTIME)>>1) > coin->stuckiters ) { coin->stuckiters = (int32_t)lag/60; while ( (breq= queue_dequeue(&coin->blocksQ,0)) != 0 ) diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 3c18bc218..a7071fa54 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -423,9 +423,9 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei coin->longestchain = 1; memset(&coin->blocks.hwmchain,0,sizeof(coin->blocks.hwmchain)); coin->blocks.hwmchain.height = 0; - if ( (coin->myservices & NODE_NETWORK) != 0 && coin->peers.acceptloop == 0 ) + printf("MYSERVICES.%llx\n",(long long)coin->myservices); + if ( (coin->myservices & NODE_NETWORK) != 0 && coin->peers.acceptloop == 0 && coin->peers.localaddr == 0 ) { - printf("MYSERVICES.%llx\n",(long long)coin->myservices); coin->peers.acceptloop = malloc(sizeof(pthread_t)); if ( OS_thread_create(coin->peers.acceptloop,NULL,(void *)iguana_acceptloop,(void *)coin) != 0 ) { diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 2b5aef7aa..b9f4ebb8e 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -607,6 +607,7 @@ void iguana_startconnection(void *arg) printf("iguana_startconnection.%s mismatched coin.%p (%s) vs (%s)\n",addr->ipaddr,coin,coin->symbol,addr->coinstr); return; } + printf("MYSERVICES.%llx\n",(long long)coin->myservices); if ( strcmp("127.0.0.1",addr->ipaddr) == 0 && (coin->myservices & NODE_NETWORK) != 0 ) { iguana_iAkill(coin,addr,0); @@ -699,6 +700,13 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int return(0); } +void iguana_launchpeer(struct iguana_info *coin,char *ipaddr) +{ + struct iguana_peer *addr; uint32_t ipbits = (uint32_t)calc_ipbits(ipaddr); + if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 ) + iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); +} + void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA) { struct iguana_peer *addr = 0; diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index d0d3a5d8a..6e911a834 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -903,7 +903,7 @@ int32_t iguana_blockreq(struct iguana_info *coin,int32_t height,int32_t priority int32_t iguana_reqblocks(struct iguana_info *coin) { - int32_t hdrsi,lflag,bundlei,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp; + int32_t hdrsi,lflag,bundlei,iters=0,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp; /*if ( 0 && (bp= coin->current) != 0 && bp->numsaved < bp->n ) { for (hdrsi=numissued=0; hdrsiMAXBUNDLES && coin->current->hdrsi+hdrsibundlescount && numissued<100; hdrsi++) @@ -973,8 +973,9 @@ int32_t iguana_reqblocks(struct iguana_info *coin) queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); }*/ lflag = 1; - while ( coin->active != 0 && lflag != 0 ) + while ( coin->active != 0 && iters < IGUANA_MAXITERATIONS ) { + iters++; lflag = 0; hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize; bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; @@ -1099,12 +1100,14 @@ int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single *newhwmp = 0; while ( coin->active != 0 && (req= queue_dequeue(&coin->recvQ,0)) != 0 ) { - //fprintf(stderr,"%s recvQ.%p type.%c n.%d\n",req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n); + if ( (flag % 100) == 50 ) + iguana_reqblocks(coin); + 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); if ( req->type == 'B' ) // one block with all txdata { netBLOCKS--; req = iguana_recvblock(coin,req->addr,req,&req->block,req->numtx,req->datalen,req->recvlen,newhwmp); - flag++; } else if ( req->type == 'H' ) // blockhdrs (doesnt have txn_count!) { @@ -1133,8 +1136,6 @@ int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single myfree(req,req->allocsize), req = 0; if ( flag >= IGUANA_BUNDLELOOP ) break; - if ( (flag % 100) == 0 ) - iguana_reqblocks(coin); } iguana_reqblocks(coin); return(flag); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index b890b6569..8facc95b1 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -247,7 +247,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl for (x=j=0; jbundleheight,bp->hdrsi); + //printf("BALANCEGEN.%d hdrs.%d\n",bp->bundleheight,bp->hdrsi); txidind = spendind = rdata->firsti; for (i=0; in; i++) { @@ -822,7 +822,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp,int3 printf("iguana_balancegen: emit %d != %d ramchain->numXspends\n",emit,ramchain->numXspends); errs++; } - printf(">>>>>>>> balances.%d done errs.%d spendind.%d\n",bp->hdrsi,errs,n); + //printf(">>>>>>>> balances.%d done errs.%d spendind.%d\n",bp->hdrsi,errs,n); return(-errs); } @@ -1402,7 +1402,7 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int { if ( bp->hdrsi >= coin->balanceswritten ) { - printf("balancecalc for %d when %d\n",bp->hdrsi,coin->balanceswritten); + //printf("balancecalc for %d when %d\n",bp->hdrsi,coin->balanceswritten); starttime = (uint32_t)time(NULL); for (j=0; j<=bp->hdrsi; j++) iguana_allocvolatile(coin,&coin->bundles[j]->ramchain);