Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
5ec1c615b7
  1. 187
      deprecated/obsolete.h
  2. 64
      iguana/iguana_bundles.c
  3. 7
      iguana/iguana_peers.c
  4. 2
      iguana/iguana_recv.c

187
deprecated/obsolete.h

@ -11020,4 +11020,191 @@ void iguana_dedicatedrecv(void *arg)
free_json(json);
return(retstr);
}
void iguana_bundlestats(struct iguana_info *coin,char *str)
{
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++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
minrequests = 777;
bp->numhashes = 0;
numbundles++;
numrecv = datasize = numsaved = 0;
missing = -1;
lefti = -1;
if ( bp->numrecv >= bp->n )
numdone++;
else
{
for (bundlei=0; bundlei<bp->n; bundlei++)
{
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 ( (bp->minrequests= minrequests) == 100 )
{
for (i=0; i<bp->n; i++)
if ( (block= bp->blocks[i]) != 0 )
block->numrequests = 1;
}
//printf("(%d %d) ",bp->hdrsi,minrequests);
numhashes += bp->numhashes;
bp->numrecv = numrecv;
bp->datasize = datasize;
if ( bp->emitfinish != 0 )
{
numemit++;
if ( bp->emitfinish > coin->startutc && bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 )
{
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++)
{
if ( (ipbits= coin->peers.active[j].ipbits) != 0 )
{
if ( iguana_peerfname(coin,&hdrsi,"tmp",fname,ipbits,bp->hashes[0],zero,1) >= 0 )
{
if ( OS_removefile(fname,0) > 0 )
coin->peers.numfiles--, m++;
}
else printf("error removing.(%s)\n",fname);
}
}
//printf("purged hdrsi.%d m.%d\n",bp->hdrsi,m);
bp->purgetime = (uint32_t)time(NULL);
}
}
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 ( (rand() % 100) == 0 && bp->numrecv > bp->n-2 && lefti >= 0 && lefti < bp->n )
{
//printf("remainder issue %d:%d %s\n",bp->hdrsi,lefti,bits256_str(str,bp->hashes[lefti]));
//iguana_blockQ(coin,bp,lefti,bp->hashes[lefti],1);
}
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;
}
}
coin->blocksrecv = totalrecv;
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 )
p++;
diff = (int32_t)time(NULL) - coin->startutc;
difft.x = (t.x - coin->starttime.x), difft.millis = (t.millis - coin->starttime.millis);
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+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;
if ( 0 && queue_size(&coin->priorityQ) == 0 && coin->blocksrecv > coin->longestchain*.9 && coin->blocksrecv < coin->longestchain-1 )
{
n = 0;
for (i=coin->lastsweep; i<coin->longestchain-1; i++)
{
hash2 = iguana_blockhash(coin,i);
if ( bits256_nonz(hash2) > 0 && (block= iguana_blockfind(coin,hash2)) != 0 )
{
if ( iguana_bundlefind(coin,&bp,&bundlei,hash2) == 0 || block->fpipbits == 0 )
{
iguana_blockQ(coin,bp,bundlei,hash2,1);
n++;
printf("%d ",i);
if ( n > 1000 )
break;
else if ( n < 10 && bp != 0 )
iguana_bundleiclear(coin,bp,bundlei);
}
coin->lastsweep = i;
}
if ( i >= coin->longestchain-1 )
coin->lastsweep = 0;
}
if ( n > 0 )
printf(">>>>>>>>>>> issued.%d 90%% blocks\n",n);
}
else if ( 0 && strcmp(coin->symbol,"BTCD") == 0 && queue_size(&coin->blocksQ) == 0 )
{
for (i=n=0; i<coin->longestchain-1; i++)
{
hash2 = iguana_blockhash(coin,i);
if ( bits256_nonz(hash2) > 0 && (block= iguana_blockfind(coin,hash2)) != 0 && block->fpipbits == 0 )
iguana_blockQ(coin,coin->bundles[i/coin->chain->bundlesize],i%coin->chain->bundlesize,hash2,0);
}
}
}
#endif

64
iguana/iguana_bundles.c

@ -375,14 +375,6 @@ char *iguana_bundledisp(struct iguana_info *coin,struct iguana_bundle *prevbp,st
return(line);
}
void iguana_bundleiclear(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei)
{
//bp->ipbits[bundlei] = 0;
//bp->issued[bundlei] = 0;
//bp->requests[bundlei] = 0;
//CLEARBIT(bp->recv,bundlei);
}
void iguana_bundlestats(struct iguana_info *coin,char *str)
{
static bits256 zero;
@ -442,25 +434,9 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
}
if ( firstbundle < 0 || firstbundle == bp->hdrsi )
firstbundle = bp->hdrsi;
if ( 0 && issued < 3 && bp->emitfinish < coin->startutc && block != 0 && block->fpipbits == 0 && (addr1= coin->peers.ranked[1]) != 0 )
{
issued++;
iguana_sendblockreq(coin,addr1,bp,bundlei,bp->hashes[bundlei],1);
//iguana_blockQ(coin,bp,lefti,bp->hashes[lefti],1);
addr1->lastlefti = (bp->bundleheight + bundlei);
printf("addr1->lastlefti.%d\n",addr1->lastlefti);
if ( addr1->lastlefti >= bp->bundleheight+bundlei )
addr1->lastlefti = bp->bundleheight;
}
bp->numhashes++;
}
}
//printf("%d ",numsaved);
/*if ( bp->emitfinish < coin->startutc && (bp->bundleheight+lefti <= coin->blocks.hwmchain.height || bp->numhashes == bp->n-1) && lefti >= 0 && lefti < bp->n )
{
printf("ISSUE LAST ONE %d in %d vs %d\n",lefti,bp->bundleheight,coin->blocks.hwmchain.height);
iguana_blockQ(coin,bp,lefti,bp->hashes[lefti],1);
}*/
if ( (bp->minrequests= minrequests) == 100 )
{
for (i=0; i<bp->n; i++)
@ -505,11 +481,6 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
printf("(%d %d) ",i,bp->numrecv);
else printf("(%d -[%d]) ",i,lefti);
}
if ( (rand() % 100) == 0 && bp->numrecv > bp->n-2 && lefti >= 0 && lefti < bp->n )
{
//printf("remainder issue %d:%d %s\n",bp->hdrsi,lefti,bits256_str(str,bp->hashes[lefti]));
//iguana_blockQ(coin,bp,lefti,bp->hashes[lefti],1);
}
if ( numsaved >= bp->n && bp->emitfinish == 0 )
{
//printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT\n");
@ -547,39 +518,4 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
coin->activebundles = numactive;
coin->estsize = estsize;
coin->numrecv = totalrecv;
if ( 0 && queue_size(&coin->priorityQ) == 0 && coin->blocksrecv > coin->longestchain*.9 && coin->blocksrecv < coin->longestchain-1 )
{
n = 0;
for (i=coin->lastsweep; i<coin->longestchain-1; i++)
{
hash2 = iguana_blockhash(coin,i);
if ( bits256_nonz(hash2) > 0 && (block= iguana_blockfind(coin,hash2)) != 0 )
{
if ( iguana_bundlefind(coin,&bp,&bundlei,hash2) == 0 || block->fpipbits )
{
iguana_blockQ(coin,bp,bundlei,hash2,1);
n++;
printf("%d ",i);
if ( n > 1000 )
break;
else if ( n < 10 && bp != 0 )
iguana_bundleiclear(coin,bp,bundlei);
}
coin->lastsweep = i;
}
if ( i >= coin->longestchain-1 )
coin->lastsweep = 0;
}
if ( n > 0 )
printf(">>>>>>>>>>> issued.%d 90%% blocks\n",n);
}
else if ( 0 && strcmp(coin->symbol,"BTCD") == 0 && queue_size(&coin->blocksQ) == 0 )
{
for (i=n=0; i<coin->longestchain-1; i++)
{
hash2 = iguana_blockhash(coin,i);
if ( bits256_nonz(hash2) > 0 && (block= iguana_blockfind(coin,hash2)) != 0 && block->fpipbits == 0 )
iguana_blockQ(coin,coin->bundles[i/coin->chain->bundlesize],i%coin->chain->bundlesize,hash2,0);
}
}
}

7
iguana/iguana_peers.c

@ -299,7 +299,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
saddr.sin_port = htons(port);
memcpy(&saddr.sin_addr.s_addr,hostent->h_addr_list[0],hostent->h_length);
ipbits = (uint32_t)calc_ipbits(hostname);
printf("ipbits.%08x vs %08x\n",ipbits,saddr.sin_addr.s_addr);
//printf("ipbits.%08x vs %08x\n",ipbits,saddr.sin_addr.s_addr);
expand_ipbits(ipaddr,saddr.sin_addr.s_addr);
//if ( bindflag != 0 )
// printf("iguana_socket.(%s:%d) bind.%d\n",ipaddr,port,bindflag), getchar();
@ -319,12 +319,12 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
}
opt = 1;
slen = sizeof(opt);
printf("set keepalive.%d\n",setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,slen));
//printf("set keepalive.%d\n",setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,slen));
if ( 1 )//&& bindflag != 0 )
{
opt = 0;
getsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,(void *)&opt,&slen);
printf("keepalive.%d\n",opt);
//printf("keepalive.%d\n",opt);
}
setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(void *)&opt,sizeof(opt));
#ifdef __APPLE__
@ -335,7 +335,6 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
{
if ( errno != ECONNRESET && errno != ENOTCONN && errno != ECONNREFUSED && errno != ETIMEDOUT && errno != EHOSTUNREACH )
printf("connect(%s) port.%d failed: %s sock.%d. errno.%d\n",hostname,port,strerror(errno),sock,errno);
printf("connect(%s) port.%d failed: %s sock.%d. errno.%d\n",hostname,port,strerror(errno),sock,errno);
if ( sock >= 0 )
closesocket(sock);
return(-1);

2
iguana/iguana_recv.c

@ -716,7 +716,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
if ( (bp= coin->bundles[height/coin->chain->bundlesize]) != 0 && bp->emitfinish == 0 )
{
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]+3) )
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++;

Loading…
Cancel
Save