Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
d023c5625c
  1. 12
      iguana/iguana777.h
  2. 239
      iguana/iguana_bundles.c
  3. 15
      iguana/iguana_msg.c
  4. 20
      iguana/iguana_peers.c
  5. 80
      iguana/iguana_recv.c
  6. 2
      iguana/main.c

12
iguana/iguana777.h

@ -33,7 +33,7 @@
#define _IGUANA_MAXBUNDLES 8
#define IGUANA_MAXACTIVEBUNDLES 32
#define IGUANA_MAXFILES 4096
#define IGUANA_BUNDLELOOP 1000
#define IGUANA_BUNDLELOOP 10
#define IGUANA_RPCPORT 7778
#define IGUANA_MAXRAMCHAINSIZE ((uint64_t)1024L * 1024L * 1024L * 16)
@ -252,8 +252,8 @@ struct iguana_block
{
struct iguana_blockRO RO;
double PoW; // NOT consensus safe, for estimation purposes only
int32_t height,fpos; uint32_t fpipbits;
uint16_t hdrsi,bundlei:12,mainchain:1,valid:1,queued:1,tbd:1,numrequests:8,extra:8;
int32_t height,fpos; uint32_t fpipbits,numrequests;
uint16_t hdrsi,bundlei:12,mainchain:1,valid:1,queued:1,tbd:1,extra:8;
UT_hash_handle hh;
} __attribute__((packed));
@ -388,7 +388,8 @@ struct iguana_bundle
struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp;
struct iguana_bloom16 bloom;
uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime;
int32_t minrequests,numhashes,numissued,numrecv,n,hdrsi,bundleheight,numtxids,numspends,numunspents;
int32_t numhashes,numrecv,numsaved,numcached;
int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents;
double avetime,threshold,metric; uint64_t datasize,estsize;
struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE]; uint32_t issued[IGUANA_MAXBUNDLESIZE];
bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash;
@ -437,7 +438,8 @@ struct iguana_info
double parsemillis,avetime; uint32_t Launched[8],Terminated[8];
portable_mutex_t peers_mutex,blocks_mutex;
struct iguana_bundle *bundles[IGUANA_MAXBUNDLES];
int32_t numpendings,zcount,recvcount,bcount,pcount,lastbundle; uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent;
double rankedbps[IGUANA_MAXBUNDLES][2];
int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle; uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent;
double backstopmillis; bits256 backstophash2;
int32_t initialheight,mapflags,minconfirms,numrecv,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids; bits256 reqtxids[64];
void *launched,*started;

239
iguana/iguana_bundles.c

@ -205,7 +205,7 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo
printf("bp->n.%d is too big\n",bp->n);
return(0);
}
if ( bundlei >= bp->n )
if ( bundlei >= bp->n && bundlei < coin->chain->bundlesize )
bp->n = bundlesize;//(bundlei < bundlesize-1) ? bundlesize : (bundlei + 1);
if ( (setval= iguana_hash2set(coin,"blockadd",bp,bundlei,hash2)) == 0 )
{
@ -375,132 +375,163 @@ char *iguana_bundledisp(struct iguana_info *coin,struct iguana_bundle *prevbp,st
return(line);
}
void iguana_bundlestats(struct iguana_info *coin,char *str)
void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp)
{
static bits256 zero;
int32_t i,n,issued,dispflag,bundlei,lefti,minrequests,missing,numbundles,numdone,numrecv,totalsaved,numhashes,numcached,numsaved,numemit,numactive,firstbundle,totalrecv = 0; struct iguana_peer *addr1;
bits256 hash2; struct iguana_bundle *bp; struct iguana_block *block; int64_t datasize,estsize = 0;
//iguana_chainextend(coin,iguana_blockfind(coin,coin->blocks.hwmchain));
//if ( queue_size(&coin->blocksQ) == 0 )
// iguana_blockQ(coin,0,-1,coin->blocks.hwmchain.hash2,0);
if ( 0 && queue_size(&coin->blocksQ) == 0 && queue_size(&coin->priorityQ) == 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
coin->peers.active[i].pending = 0;
}
dispflag = (rand() % 1000) == 0;
numbundles = numdone = numrecv = numhashes = numcached = totalsaved = numemit = numactive = 0;
firstbundle = -1;
issued = 0;
for (i=0; i<coin->bundlescount; i++)
char fname[1024]; int32_t hdrsi,m,j; uint32_t ipbits;
if ( bp->emitfinish > coin->startutc && bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 )
{
if ( (bp= coin->bundles[i]) != 0 )
for (j=m=0; j<sizeof(coin->peers.active)/sizeof(*coin->peers.active); j++)
{
minrequests = 777;
bp->numhashes = 0;
numbundles++;
numrecv = datasize = numsaved = 0;
missing = -1;
lefti = -1;
if ( bp->numrecv >= bp->n )
numdone++;
else
if ( (ipbits= coin->peers.active[j].ipbits) != 0 )
{
for (bundlei=0; bundlei<bp->n; bundlei++)
if ( iguana_peerfname(coin,&hdrsi,"tmp",fname,ipbits,bp->hashes[0],zero,1) >= 0 )
{
if ( bits256_nonz(bp->hashes[bundlei]) == 0 )
{
lefti = bundlei;
if ( missing < 0 )
missing = bundlei;
continue;
}
if ( (block= bp->blocks[bundlei]) != 0 || (block= iguana_blockfind(coin,bp->hashes[bundlei])) != 0 )
{
bp->blocks[bundlei] = block;
if ( block->numrequests < minrequests )
minrequests = block->numrequests;
if ( block->fpipbits != 0 )
numsaved++;
if ( block->RO.recvlen != 0 )
{
datasize += block->RO.recvlen;
if ( block->queued != 0 )
numcached++;
numrecv++;
}
if ( block->queued == 0 && block->fpipbits == 0 )
lefti = bundlei;
}
if ( firstbundle < 0 || firstbundle == bp->hdrsi )
firstbundle = bp->hdrsi;
bp->numhashes++;
if ( OS_removefile(fname,0) > 0 )
coin->peers.numfiles--, m++;
}
else printf("error removing.(%s)\n",fname);
}
if ( (bp->minrequests= minrequests) == 100 )
}
//printf("purged hdrsi.%d m.%d\n",bp->hdrsi,m);
bp->purgetime = (uint32_t)time(NULL);
}
}
int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp)
{
int32_t bundlei; struct iguana_block *block;
if ( bp->emitfinish > coin->startutc )
{
bp->numhashes = bp->numsaved = bp->numcached = bp->numrecv = bp->n;
return(bp->datasize);
}
bp->datasize = bp->numhashes = bp->numsaved = bp->numcached = bp->numrecv = bp->minrequests = 0;
for (bundlei=0; bundlei<bp->n; bundlei++)
{
if ( bits256_nonz(bp->hashes[bundlei]) > 0 )
{
if ( (block= bp->blocks[bundlei]) != 0 || (block= iguana_blockfind(coin,bp->hashes[bundlei])) != 0 )
{
for (i=0; i<bp->n; i++)
if ( (block= bp->blocks[i]) != 0 )
block->numrequests = 1;
bp->blocks[bundlei] = block;
if ( bp->minrequests == 0 || (block->numrequests > 0 && block->numrequests < bp->minrequests) )
bp->minrequests = block->numrequests;
if ( block->fpipbits != 0 )
bp->numsaved++;
if ( block->RO.recvlen != 0 )
{
bp->numrecv++;
bp->datasize += block->RO.recvlen;
if ( block->queued != 0 )
bp->numcached++;
}
}
//printf("(%d %d) ",bp->hdrsi,minrequests);
bp->numhashes++;
}
}
bp->metric = 0.;
if ( bp->numsaved > 0 )
{
bp->estsize = ((uint64_t)bp->datasize * bp->n) / (bp->numrecv+1);
if ( bp->numsaved >= bp->n && bp->emitfinish == 0 )
{
//printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT\n");
bp->emitfinish = 1;
iguana_emitQ(coin,bp);
}
else bp->metric = sqrt((sqrt(fabs(bp->estsize - bp->datasize)) * (bp->n - bp->numsaved)) * (bp->hdrsi + 1));
}
return(bp->estsize);
}
static int _increasing_double(const void *a,const void *b)
{
#define double_a (*(double *)a)
#define double_b (*(double *)b)
if ( double_b > double_a )
return(-1);
else if ( double_b < double_a )
return(1);
return(0);
#undef double_a
#undef double_b
}
int32_t sortds(double *buf,uint32_t num,int32_t size)
{
qsort(buf,num,size,_increasing_double);
return(0);
}
void iguana_bundlestats(struct iguana_info *coin,char *str)
{
int32_t i,n,dispflag,numrecv,numhashes,numcached,numsaved,numemit; int64_t estsize = 0;
struct iguana_bundle *bp;
dispflag = (rand() % 1000) == 0;
numrecv = numhashes = numcached = numsaved = numemit = 0;
memset(coin->rankedbps,0,sizeof(coin->rankedbps));
for (i=n=0; i<coin->bundlescount; i++)
{
coin->rankedbps[n][1] = i;
if ( (bp= coin->bundles[i]) != 0 )
{
estsize += iguana_bundlecalcs(coin,bp);
numhashes += bp->numhashes;
bp->numrecv = numrecv;
bp->datasize = datasize;
numcached += bp->numcached;
numrecv += bp->numrecv;
numsaved += bp->numsaved;
if ( bp->emitfinish != 0 )
{
numemit++;
if ( bp->emitfinish > coin->startutc && bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 )
iguana_bundlepurge(coin,bp);
}
else if ( bp->metric > 0. )
coin->rankedbps[n++][0] = bp->metric;
}
}
if ( n > 0 )
{
struct iguana_peer *addr; uint32_t now; struct iguana_block *block; int32_t origissue,j,issue,pend = 0;
sortds(&coin->rankedbps[0][0],n,sizeof(coin->rankedbps[0]));
for (i=0; i<coin->peers.numranked; i++)
{
if ( (addr= coin->peers.ranked[i]) != 0 )
pend += addr->pendblocks;
}
origissue = issue = (_IGUANA_MAXPENDING*coin->peers.numranked - pend);
while ( issue > 0 )
{
now = (uint32_t)time(NULL);
for (i=0; i<n; i++)
{
if ( (bp= coin->bundles[(int32_t)coin->rankedbps[i][1]]) != 0 )
{
char fname[1024]; int32_t hdrsi,m,j; uint32_t ipbits;
for (j=m=0; j<sizeof(coin->peers.active)/sizeof(*coin->peers.active); j++)
for (j=0; j<bp->n; j++)
{
if ( (ipbits= coin->peers.active[j].ipbits) != 0 )
if ( bits256_nonz(bp->hashes[j]) > 0 && (block= bp->blocks[j]) != 0 )
{
if ( iguana_peerfname(coin,&hdrsi,"tmp",fname,ipbits,bp->hashes[0],zero,1) >= 0 )
//printf("j.%d bp.%d %d %x lag.%d\n",j,bp->minrequests,block->numrequests,block->fpipbits,now - bp->issued[j]);
if ( block->numrequests <= bp->minrequests && block->fpipbits == 0 && (bp->issued[j] == 0 || now > bp->issued[j]+60) )
{
if ( OS_removefile(fname,0) > 0 )
coin->peers.numfiles--, m++;
printf("%d:%d.%d ",bp->hdrsi,j,block->numrequests);
bp->issued[j] = now;
iguana_blockQ(coin,bp,j,bp->hashes[j],0);
if ( --issue < 0 )
break;
}
else printf("error removing.(%s)\n",fname);
}
}
//printf("purged hdrsi.%d m.%d\n",bp->hdrsi,m);
bp->purgetime = (uint32_t)time(NULL);
}
if ( issue <= 0 )
break;
}
else if ( numsaved > 0 )
{
bp->estsize = ((uint64_t)datasize * bp->n) / (numrecv+1);
estsize += bp->estsize;
if ( bp->numhashes == bp->n )
numactive++;
if ( 0 && dispflag != 0 )
{
if ( bp->numrecv < bp->n-1 )
printf("(%d %d) ",i,bp->numrecv);
else printf("(%d -[%d]) ",i,lefti);
}
if ( numsaved >= bp->n && bp->emitfinish == 0 )
{
//printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT\n");
bp->emitfinish = 1;
iguana_emitQ(coin,bp);
}
/*if ( numrecv > bp->n*.98 )
{
if ( numrecv > bp->n-3 )
bp->threshold = bp->avetime;
else bp->threshold = bp->avetime * 2;
} else*/
bp->threshold = bp->avetime;
bp->metric = (bp->n - numsaved) / (bp->hdrsi + 1);//sqrt(abs((bp->n - bp->numrecv)) * sqrt(bp->estsize - bp->datasize)) / coin->chain->bundlesize;
} else bp->threshold = 10000., bp->metric = 0.;
totalrecv += numrecv;
totalsaved += numsaved;
}
/*for (i=0; i<n&&i<3; i++)
printf("(%.5f %.0f).%d ",coin->rankedbps[i][0],coin->rankedbps[i][1],coin->bundles[(int32_t)coin->rankedbps[i][1]]->numrecv);*/
printf("rem.%d issue.%d pend.%d | numranked.%d\n",n,origissue,pend,coin->peers.numranked);
}
coin->blocksrecv = totalrecv;
coin->numremain = n;
coin->blocksrecv = numrecv;
char str2[65]; uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now();
for (i=0; i<IGUANA_MAXPEERS; i++)
if ( coin->peers.active[i].usock >= 0 )
@ -510,12 +541,10 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
tmp = (difft.millis * 1000000);
tmp %= 1000000000;
difft.millis = ((double)tmp / 1000000.);
sprintf(str,"N[%d] d.%d p.%d g.%d A.%d h.%d r.%d c.%d:%d s.%d E.%d:%d M.%d L.%d est.%d %s %d:%02d:%02d %03.3f peers.%d/%d",coin->bundlescount,numdone,coin->numpendings,numbundles,numactive,numhashes,coin->blocksrecv,coin->numcached,coin->cachefreed,totalsaved,coin->numemitted,coin->numreqsent,coin->blocks.hwmchain.height,coin->longestchain,coin->MAXBUNDLES,mbstr(str2,estsize),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,difft.millis,p,coin->MAXPEERS);
sprintf(str,"N[%d] h.%d r.%d c.%d:%d:%d s.%d E.%d:%d M.%d L.%d est.%d %s %d:%02d:%02d %03.3f peers.%d/%d",coin->bundlescount,numhashes,coin->blocksrecv,coin->numcached,numcached,coin->cachefreed,numsaved,numemit,coin->numreqsent,coin->blocks.hwmchain.height,coin->longestchain,coin->MAXBUNDLES,mbstr(str2,estsize),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,difft.millis,p,coin->MAXPEERS);
//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 ( (rand() % 100) == 0 )
printf("%s\n",str);
strcpy(coin->statusstr,str);
coin->activebundles = numactive;
coin->estsize = estsize;
coin->numrecv = totalrecv;
}

15
iguana/iguana_msg.c

@ -152,11 +152,7 @@ void iguana_gotversion(struct iguana_info *coin,struct iguana_peer *addr,struct
}
else printf("nServices.%lld nonce.%llu non-relay node.(%s)\n",(long long)vers->nServices,(long long)vers->nonce,addr->ipaddr);
if ( (vers->nServices & (1<<7)) == (1<<7) )
{
addr->supernet = 1;
printf("send getpeers to %s\n",addr->ipaddr);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
}
if ( vers->nStartingHeight > coin->longestchain )
coin->longestchain = vers->nStartingHeight;
iguana_queue_send(coin,addr,0,serialized,"getaddr",0,0,0);
@ -185,6 +181,11 @@ void iguana_gotverack(struct iguana_info *coin,struct iguana_peer *addr)
printf("gotverack from %s\n",addr->ipaddr);
addr->A.nTime = (uint32_t)time(NULL);
iguana_queue_send(coin,addr,0,serialized,"getaddr",0,0,0);
if ( addr->supernet != 0 )
{
printf("send getpeers to %s\n",addr->ipaddr);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
}
}
}
@ -204,7 +205,11 @@ void iguana_gotping(struct iguana_info *coin,struct iguana_peer *addr,uint64_t n
if ( memcmp(data,&serialized[sizeof(struct iguana_msghdr)],sizeof(nonce)) != 0 )
printf("ping ser error %llx != %llx\n",(long long)nonce,*(long long *)data);
iguana_queue_send(coin,addr,0,serialized,"pong",len,0,0);
iguana_queue_send(coin,addr,0,serialized,"getaddr",0,0,0);
if ( addr->supernet != 0 )
{
printf("send getpeers to %s\n",addr->ipaddr);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
}
}
int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr)

20
iguana/iguana_peers.c

@ -366,10 +366,10 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
{
printf(" >>>>>>> send.(%s) %d bytes to %s supernet.%d\n",(char *)&serialized[4],len,addr->ipaddr,addr->supernet);// getchar();
}
else
else if ( addr->msgcounts.verack == 0 && (strcmp((char *)&serialized[4],"version") != 0 && strcmp((char *)&serialized[4],"verack") != 0) != 0 )
{
//if ( addr->relayflag == 0 )
// return(-1);
printf("skip.(%s) since no verack yet\n",(char *)&serialized[4]);
return(-1);
}
if ( strcmp((char *)&serialized[4],"ping") == 0 )
addr->sendmillis = OS_milliseconds();
@ -588,7 +588,7 @@ void iguana_startconnection(void *arg)
printf("avoid self-loopback\n");
return;
}
printf("startconnection.(%s) pending.%u usock.%d addrind.%d\n",addr->ipaddr,addr->pending,addr->usock,addr->addrind);
//printf("startconnection.(%s) pending.%u usock.%d addrind.%d\n",addr->ipaddr,addr->pending,addr->usock,addr->addrind);
addr->pending = (uint32_t)time(NULL);
if ( addr->usock < 0 )
addr->usock = iguana_socket(0,addr->ipaddr,coin->chain->portp2p);
@ -663,14 +663,14 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
//portable_mutex_unlock(&coin->peers_mutex);
if ( (addr= iguana_peerslot(coin,iA->ipbits)) != 0 )//i < coin->MAXPEERS && i < IGUANA_MAXPEERS && addr != 0 )
{
printf("pend.%d status.%d possible peer.(%s).%x threads %d %d %d %d\n",addr->pending,iA->status,addr->ipaddr,addr->ipbits,iguana_numthreads(coin,0),iguana_numthreads(coin,1),iguana_numthreads(coin,2),iguana_numthreads(coin,3));
//printf("pend.%d status.%d possible peer.(%s).%x threads %d %d %d %d\n",addr->pending,iA->status,addr->ipaddr,addr->ipbits,iguana_numthreads(coin,0),iguana_numthreads(coin,1),iguana_numthreads(coin,2),iguana_numthreads(coin,3));
if ( addr->pending == 0 && iA->status != IGUANA_PEER_CONNECTING )
{
iA->status = IGUANA_PEER_CONNECTING;
addr->pending = (uint32_t)time(NULL);
if ( iguana_rwiAddrind(coin,1,iA,iA->hh.itemind) > 0 )
{
printf("iA.%p iguana_startconnection.(%s) status.%d pending.%d\n",iA,addr->ipaddr,iA->status,addr->pending);
//printf("iA.%p iguana_startconnection.(%s) status.%d pending.%d\n",iA,addr->ipaddr,iA->status,addr->pending);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
} else printf("error rwiAddrind.%d\n",iA->hh.itemind);
}
@ -700,7 +700,7 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
return((uint32_t)time(NULL));
}
#endif
printf("check possible peer.(%s)\n",ipaddr);
//printf("check possible peer.(%s)\n",ipaddr);
for (i=n=0; i<coin->MAXPEERS; i++)
{
if ( strcmp(ipaddr,coin->peers.active[i].ipaddr) == 0 )
@ -721,7 +721,7 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
expand_ipbits(checkaddr,ipbits);
if ( strcmp(checkaddr,ipaddr) == 0 )
{
printf("valid ipaddr.(%s) MAXPEERS.%d\n",ipaddr,coin->MAXPEERS);
//printf("valid ipaddr.(%s) MAXPEERS.%d\n",ipaddr,coin->MAXPEERS);
if ( (iA= iguana_iAddrhashfind(coin,ipbits,1)) != 0 )
{
if ( iA->status != IGUANA_PEER_CONNECTING && iA->status != IGUANA_PEER_READY && iA->status != IGUANA_PEER_ELIGIBLE )
@ -970,14 +970,14 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
}
if ( flag == 0 )
{
if ( 0 && time(NULL) > addr->pendtime+30 )
/*if ( 0 && time(NULL) > addr->pendtime+30 )
{
if ( addr->pendblocks > 0 )
addr->pendblocks--;
if ( addr->pendhdrs > 0 )
addr->pendhdrs--;
addr->pendtime = 0;
}
}*/
if ( coin->active != 0 && (fds.revents & POLLOUT) != 0 )
{
if ( iguana_pollQsPT(coin,addr) > 0 )

80
iguana/iguana_recv.c

@ -40,7 +40,6 @@ struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana
if ( block != 0 )
{
//block->issued = now;
if ( block->numrequests < 100 )
block->numrequests++;
}
return(block);
@ -311,10 +310,10 @@ int32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bits
{
if ( (err= iguana_bundlehash2add(coin,0,bp,i,blockhashes[i])) < 0 )
return(err);
if ( 0 && bp->emitfinish == 0 && (block= bp->blocks[i]) != 0 && (block->queued == 0 && block->fpipbits == 0) && block->numrequests < 3 )
if ( 1 && bp->emitfinish == 0 && (block= bp->blocks[i]) != 0 && (block->queued == 0 && block->fpipbits == 0) && block->numrequests == 0 )
iguana_blockQ(coin,bp,i,block->RO.hash2,0), n++;
}
//printf("ALLHASHES FOUND! %d requested.%d\n",bp->bundleheight,n);
printf("ALLHASHES FOUND! %d requested.%d\n",bp->bundleheight,n);
return(i);
}
}
@ -367,7 +366,15 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
}
}
else if ( bundlei < coin->chain->bundlesize-1 )
{
iguana_bundlehash2add(coin,0,bp,bundlei+1,block->RO.hash2);
if ( bundlei == 0 )
{
char str[65]; bits256_str(str,block->RO.prev_block);
//printf("Afound block -> hdr.%s\n",str);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
}
}
}
//char str[65]; printf("iguana_recvblock (%s) %d %d[%d] %p\n",bits256_str(str,block->hash2),block->havebundle,block->hdrsi,bundlei,bp);
@ -383,6 +390,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig
printf("iguana_recvblockhdrs null blocks?\n");
return(req);
}
//printf("GOT HDRS[%d]\n",n);
if ( blocks != 0 && n > 0 )
{
for (i=0; i<n; i++)
@ -390,8 +398,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig
//fprintf(stderr,"i.%d of %d bundleset\n",i,n);
if ( (bp= iguana_bundleset(coin,&block,&bundlei,&blocks[i])) != 0 && bp->hdrsi < IGUANA_MAXACTIVEBUNDLES )
{
//if ( 0 && i < bp->n && bp->requests[i] == 0 )
// iguana_blockQ(coin,bp,bundlei,blocks[i].RO.hash2,0);
iguana_blockQ(coin,bp,bundlei,blocks[i].RO.hash2,0);
}
}
}
@ -419,12 +426,12 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
n++;
}
}
//printf("got [%d] num.%d matched hashes\n",n,num);
printf("got [%d] num.%d matched hashes\n",n,num);
}
else
{
//char str[65]; printf("blockhashes[%d] %s\n",num,bits256_str(str,blockhashes[1]));
iguana_blockQ(coin,0,-1,blockhashes[1],0);
char str[65]; printf("blockhashes[%d] %s\n",num,bits256_str(str,blockhashes[1]));
iguana_blockQ(coin,0,-1,blockhashes[1],1);
for (i=coin->chain->bundlesize; i<num; i++)
{
if ( i >= coin->chain->bundlesize && (i % coin->chain->bundlesize) < 2 )
@ -453,15 +460,37 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundlereq *req,struct iguana_block *origblock,int32_t numtx,int32_t datalen,int32_t recvlen,int32_t *newhwmp)
{
//static int total;
struct iguana_bundle *prevbp=0,*bp=0; int32_t prevbundlei=-2,bundlei = -2; struct iguana_block *prevblock,*block;
bp = iguana_bundleset(coin,&block,&bundlei,origblock);
//char str[65]; printf("RECV %s [%d:%d] block.%08x | %d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,total++);
//static int total; char str[65]; printf("RECV %s [%d:%d] block.%08x | %d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,total++);
iguana_bundlefind(coin,&prevbp,&prevbundlei,origblock->RO.prev_block);
if ( prevbp != 0 && prevbundlei >= 0 && prevbp->blocks[prevbundlei] == 0 && (prevblock= iguana_blockfind(coin,origblock->RO.prev_block)) != 0 )
if ( prevbp != 0 && prevbundlei >= 0 && (prevblock= iguana_blockfind(coin,origblock->RO.prev_block)) != 0 )
{
static bits256 zero;
prevbp->blocks[prevbundlei] = prevblock;
//printf("PREV %s prevbp.%p[%d]\n",bits256_str(str,origblock->RO.prev_block),prevbp,prevbundlei);
if ( prevbundlei < coin->chain->bundlesize )
{
if ( prevbundlei == coin->chain->bundlesize-1 )
{
//if ( coin->bundlescount < bp->hdrsi+1 )
{
//char str[65]; printf("autoextend CREATE.%d new bundle.%s\n",bp->bundleheight + coin->chain->bundlesize,bits256_str(str,block->RO.hash2));
iguana_bundlecreate(coin,&prevbundlei,prevbp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,1);
}
}
else
{
iguana_bundlehash2add(coin,0,prevbp,prevbundlei+1,block->RO.hash2);
}
}
if ( prevbp->numhashes < prevbp->n && prevbundlei == 0 )
{
char str[65]; bits256_str(str,prevbp->hashes[0]);
//printf("found block -> %d hdr.%s\n",prevbp->bundleheight,str);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
//char str[65]; printf("PREV %s prevbp.%p[%d] h.%d\n",bits256_str(str,origblock->RO.prev_block),prevbp,prevbundlei,prevbp->numhashes);
}
if ( block != 0 )
{
@ -562,11 +591,11 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
if ( i == coin->bundlescount-1 )
lag = 5;
else lag = 30 + (rand() % 30);
if ( i < coin->bundlescount-1 && (bp->numhashes >= (rand() % bp->n) || time(NULL) < bp->hdrtime+lag) )
continue;
//if ( i < coin->bundlescount-1 && (bp->numhashes >= (rand() % bp->n) || time(NULL) < bp->hdrtime+lag) )
// continue;
if ( bp->numhashes < bp->n && bp->bundleheight+bp->numhashes < coin->longestchain && time(NULL) > bp->issuetime+lag )
{
//printf("LAG.%ld hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",time(NULL)-bp->hdrtime,i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
printf("LAG.%ld hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",time(NULL)-bp->hdrtime,i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
if ( bp->issuetime == 0 )
coin->numpendings++;
char str[65];
@ -613,6 +642,7 @@ int32_t iguana_blockQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
{
if ( block->fpipbits != 0 || block->queued != 0 )
return(0);
block->numrequests++;
/*if ( block->rawdata != 0 && block->RO.recvlen != 0 )
{
printf("free cached copy recvlen.%d need to process it here\n",block->RO.recvlen);
@ -632,14 +662,14 @@ int32_t iguana_blockQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
req->bundlei = bundlei;
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
{
//bp->issued[bundlei] = (uint32_t)time(NULL);
bp->issued[bundlei] = (uint32_t)time(NULL);
if ( bp->bundleheight >= 0 )
req->height = (bp->bundleheight + bundlei);
}
char str[65];
bits256_str(str,hash2);
if ( 0 && (bundlei % 250) == 0 )
printf("%s %d %s recv.%d numranked.%d qsize.%d\n",str,req->height,str,coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q));
printf("%s %d %s blockQ.%d numranked.%d qsize.%d\n",str,req->height,str,coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q));
queue_enqueue(str,Q,&req->DL,0);
return(1);
} else printf("null Q\n");
@ -654,7 +684,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
int32_t i,r,diff,j,k,n,m; double metric,bestmetric = -1.; struct iguana_bundle *bp,*bestbp = 0;
int32_t limit,refbundlei,height=-1,incr,datalen,flag = 0; double val;
now = (uint32_t)time(NULL);
if ( iguana_needhdrs(coin) != 0 && addr->pendhdrs < IGUANA_MAXPENDHDRS )
if ( iguana_needhdrs(coin) != 0 )//&& addr->pendhdrs < IGUANA_MAXPENDHDRS )
{
//printf("%s check hdrsQ\n",addr->ipaddr);
if ( (hashstr= queue_dequeue(&coin->hdrsQ,1)) != 0 )
@ -685,7 +715,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
//if ( addr->pendblocks >= limit )
// printf("%s %d overlimit.%d\n",addr->ipaddr,addr->pendblocks,limit);
req = queue_dequeue(&coin->priorityQ,0);
if ( addr->msgcounts.verack > 0 && coin->bundlescount > 0 && req == 0 && addr->pendblocks < limit )//&& now > addr->lastpoll )
if ( 0 && addr->msgcounts.verack > 0 && coin->bundlescount > 0 && req == 0 && addr->pendblocks < limit )//&& now > addr->lastpoll )
{
if ( 1 )//strcmp("BTC",coin->symbol) != 0 )
{
@ -718,10 +748,9 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
bundlei = (height % coin->chain->bundlesize);
if ( bundlei < bp->n && bits256_nonz(bp->hashes[bundlei]) > 0 && (block= bp->blocks[bundlei]) != 0 && block->numrequests <= bp->minrequests && block->fpipbits == 0 && (bp->issued[bundlei] == 0 || now > bp->issued[bundlei]+13) )
{
if ( block->numrequests < 100 )
block->numrequests++;
block->numrequests++;
bp->issued[bundlei] = (uint32_t)time(NULL);;
if ( 0 && (rand() % 100) == 0 )
//if ( 0 && (rand() % 100) == 0 )
printf("%s Send auto blockreq.%d [%d] minreq.%d\n",addr->ipaddr,bp->bundleheight+bundlei,block->numrequests,bp->minrequests);
iguana_sendblockreq(coin,addr,bp,bundlei,bp->hashes[bundlei],0);
return(1);
@ -785,8 +814,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
j = 0;
if ( (block= bp->blocks[j]) != 0 && block->fpipbits == 0 && block->queued == 0 && block->numrequests <= bp->minrequests )
{
if ( block->numrequests < 100 )
block->numrequests++;
block->numrequests++;
//block->issued = (uint32_t)time(NULL);;
//printf("%s Send auto blockreq.%d\n",addr->ipaddr,bp->bundleheight+j);
iguana_sendblockreq(coin,addr,bp,j,hash2,0);
@ -818,7 +846,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
//char str[65];
//if ( 0 && priority != 0 )
// printf(" issue.%s\n",bits256_str(str,hash2));
if ( block != 0 && block->numrequests < 100 )
if ( block != 0 )
block->numrequests++;
iguana_sendblockreq(coin,addr,req->bp,req->bundlei,hash2,0);
}
@ -877,7 +905,7 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded
if ( bp != 0 )
{
coin->backstopmillis = OS_milliseconds();
iguana_blockQ(coin,bp,bundlei,iguana_blockhash(coin,coin->backstop),0);
iguana_blockQ(coin,bp,bundlei,iguana_blockhash(coin,coin->backstop),1);
//if ( (rand() % 100) == 0 )
printf("MAINCHAIN.%d threshold %.3f %.3f lag %.3f\n",coin->blocks.hwmchain.height+1,threshold,coin->backstopmillis,lag);
}

2
iguana/main.c

@ -318,7 +318,7 @@ void iguana_main(void *arg)
#ifdef __APPLE__
sleep(1);
char *str;
if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":16,\"coin\":\"BTCD\",\"active\":1}"),0)) != 0 )
if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":16,\"coin\":\"BTC\",\"active\":1}"),0)) != 0 )
{
printf("got.(%s)\n",str);
free(str);

Loading…
Cancel
Save