@ -3,7 +3,7 @@
# include "bitcoin.h"
# include "bitcoin.h"
# include "db.h"
# include "db.h"
# define NTHREADS 16
# define NTHREADS 32
using namespace std ;
using namespace std ;
@ -15,7 +15,6 @@ CAddrDb db;
extern " C " void * ThreadCrawler ( void * data ) {
extern " C " void * ThreadCrawler ( void * data ) {
do {
do {
db . Stats ( ) ;
CIPPort ip ;
CIPPort ip ;
int wait = 5 ;
int wait = 5 ;
if ( ! db . Get ( ip , wait ) ) {
if ( ! db . Get ( ip , wait ) ) {
@ -57,16 +56,18 @@ extern "C" int GetIPList(struct in_addr *addr, int max, int ipv4only) {
return n ;
return n ;
}
}
static dns_opt_t dns_opt ;
extern " C " void * ThreadDNS ( void * ) {
extern " C " void * ThreadDNS ( void * ) {
dns_opt_t opt ;
dns_opt . host = " seed.bitcoin.sipa.be " ;
opt . host = " seed.bitcoin .sipa.be " ;
dns_ opt. ns = " vp s.sipa.be" ;
opt . ns = " vps.sipa.be " ;
dns_ opt. mbox = " sipa.ulyssis.org " ;
opt . mbox = " sipa.ulyssis.org " ;
dns_ opt. datattl = 60 ;
opt . datattl = 6 0;
dns_ opt. nsttl = 4000 0;
opt . nsttl = 40000 ;
dns_ opt. cb = GetIPList ;
opt . cb = GetIPList ;
dns_ opt. port = 53 ;
opt . port = 53 ;
dns_ opt. nRequests = 0 ;
dnsserver ( & opt ) ;
dnsserver ( & dns_ opt) ;
}
}
extern " C " void * ThreadDumper ( void * ) {
extern " C " void * ThreadDumper ( void * ) {
@ -82,24 +83,45 @@ extern "C" void* ThreadDumper(void*) {
} while ( 1 ) ;
} while ( 1 ) ;
}
}
extern " C " void * ThreadStats ( void * ) {
do {
CAddrDbStats stats ;
db . GetStats ( stats ) ;
printf ( " *** %i available (%i tracked, %i new, %i active), %i banned; %i good; %llu DNS requests \n " , stats . nAvail , stats . nTracked , stats . nNew , stats . nAvail - stats . nTracked - stats . nNew , stats . nBanned , stats . nGood , ( unsigned long long ) dns_opt . nRequests ) ;
Sleep ( 10000 ) ;
} while ( 1 ) ;
}
static const string seeds [ ] = { " dnsseed.bluematt.me " , " bitseed.xf2.org " , " dnsseed.bitcoin.dashjr.org " , " seed.bitcoin.sipa.be " } ;
extern " C " void * ThreadSeeder ( void * ) {
do {
for ( int i = 0 ; i < sizeof ( seeds ) / sizeof ( seeds [ 0 ] ) ; i + + ) {
vector < CIP > ips ;
LookupHost ( seeds [ i ] . c_str ( ) , ips ) ;
for ( vector < CIP > : : iterator it = ips . begin ( ) ; it ! = ips . end ( ) ; it + + ) {
db . Add ( CIPPort ( * it , 8333 ) , true ) ;
}
}
Sleep ( 1800000 ) ;
} while ( 1 ) ;
}
int main ( void ) {
int main ( void ) {
FILE * f = fopen ( " dnsseed.dat " , " r " ) ;
FILE * f = fopen ( " dnsseed.dat " , " r " ) ;
if ( f ) {
if ( f ) {
CAutoFile cf ( f ) ;
CAutoFile cf ( f ) ;
cf > > db ;
cf > > db ;
}
}
vector < CIP > ips ;
pthread_t thread [ NTHREADS + 4 ] ;
LookupHost ( " dnsseed.bluematt.me " , ips ) ;
for ( vector < CIP > : : iterator it = ips . begin ( ) ; it ! = ips . end ( ) ; it + + ) {
db . Add ( CIPPort ( * it , 8333 ) ) ;
}
pthread_t thread [ NTHREADS + 2 ] ;
for ( int i = 0 ; i < NTHREADS ; i + + ) {
for ( int i = 0 ; i < NTHREADS ; i + + ) {
pthread_create ( & thread [ i ] , NULL , ThreadCrawler , NULL ) ;
pthread_create ( & thread [ i ] , NULL , ThreadCrawler , NULL ) ;
}
}
pthread_create ( & thread [ NTHREADS ] , NULL , ThreadDumper , NULL ) ;
pthread_create ( & thread [ NTHREADS + 0 ] , NULL , ThreadSeeder , NULL ) ;
pthread_create ( & thread [ NTHREADS + 1 ] , NULL , ThreadDNS , NULL ) ;
pthread_create ( & thread [ NTHREADS + 1 ] , NULL , ThreadDumper , NULL ) ;
for ( int i = 0 ; i < NTHREADS + 2 ; i + + ) {
pthread_create ( & thread [ NTHREADS + 2 ] , NULL , ThreadDNS , NULL ) ;
pthread_create ( & thread [ NTHREADS + 3 ] , NULL , ThreadStats , NULL ) ;
for ( int i = 0 ; i < NTHREADS + 4 ; i + + ) {
void * res ;
void * res ;
pthread_join ( thread [ i ] , & res ) ;
pthread_join ( thread [ i ] , & res ) ;
}
}