diff --git a/crawler.go b/crawler.go index 550b913..41d51be 100644 --- a/crawler.go +++ b/crawler.go @@ -30,7 +30,8 @@ func crawlNode(s *dnsseeder, nd *node) { defer crawlEnd(nd) if config.debug { - log.Printf("debug - start crawl: node %s status: %v:%v lastcrawl: %s\n", + log.Printf("%s - debug - start crawl: node %s status: %v:%v lastcrawl: %s\n", + s.name, net.JoinHostPort(nd.na.IP.String(), strconv.Itoa(int(nd.na.Port))), nd.status, @@ -39,7 +40,7 @@ func crawlNode(s *dnsseeder, nd *node) { } // connect to the remote ip and ask them for their addr list - rna, e := crawlIP(s.pver, s.id, nd, s.isFull()) + rna, e := s.crawlIP(nd) if e != nil { // update the fact that we have not connected to this node @@ -140,7 +141,7 @@ func crawlEnd(nd *node) { } // crawlIP retrievs a slice of ip addresses from a client -func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.NetAddress, *crawlError) { +func (s *dnsseeder) crawlIP(nd *node) ([]*wire.NetAddress, *crawlError) { ip := nd.na.IP.String() port := strconv.Itoa(int(nd.na.Port)) @@ -150,14 +151,14 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N conn, err := net.DialTimeout("tcp", dialString, time.Second*10) if err != nil { if config.debug { - log.Printf("debug - Could not connect to %s - %v\n", ip, err) + log.Printf("%s - debug - Could not connect to %s - %v\n", s.name, ip, err) } return nil, &crawlError{"", err} } defer conn.Close() if config.debug { - log.Printf("debug - Connected to remote address: %s Last connect was %v ago\n", ip, time.Since(nd.lastConnect).String()) + log.Printf("%s - debug - Connected to remote address: %s Last connect was %v ago\n", s.name, ip, time.Since(nd.lastConnect).String()) } // set a deadline for all comms to be done by. After this all i/o will error @@ -170,14 +171,14 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N return nil, &crawlError{"Create NewMsgVersionFromConn", err} } - err = wire.WriteMessage(conn, msgver, pver, netID) + err = wire.WriteMessage(conn, msgver, s.pver, s.id) if err != nil { // Log and handle the error return nil, &crawlError{"Write Version Message", err} } // first message received should be version - msg, _, err := wire.ReadMessage(conn, pver, netID) + msg, _, err := wire.ReadMessage(conn, s.pver, s.id) if err != nil { // Log and handle the error return nil, &crawlError{"Read message after sending Version", err} @@ -187,7 +188,7 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N case *wire.MsgVersion: // The message is a pointer to a MsgVersion struct. if config.debug { - log.Printf("%s - Remote version: %v\n", ip, msg.ProtocolVersion) + log.Printf("%s - debug - %s - Remote version: %v\n", s.name, ip, msg.ProtocolVersion) } // fill the node struct with the remote details nd.version = msg.ProtocolVersion @@ -205,13 +206,13 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N // send verack command msgverack := wire.NewMsgVerAck() - err = wire.WriteMessage(conn, msgverack, pver, netID) + err = wire.WriteMessage(conn, msgverack, s.pver, s.id) if err != nil { return nil, &crawlError{"writing message VerAck", err} } // second message received should be verack - msg, _, err = wire.ReadMessage(conn, pver, netID) + msg, _, err = wire.ReadMessage(conn, s.pver, s.id) if err != nil { return nil, &crawlError{"reading expected Ver Ack from remote client", err} } @@ -219,7 +220,7 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N switch msg.(type) { case *wire.MsgVerAck: if config.debug { - log.Printf("%s - received Version Ack\n", ip) + log.Printf("%s - debug - %s - received Version Ack\n", s.name, ip) } default: return nil, &crawlError{"Did not receive expected Ver Ack message from remote client", errors.New("")} @@ -227,13 +228,13 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N // if we get this far and if the seeder is full then don't ask for addresses. This will reduce bandwith usage while still // confirming that we can connect to the remote node - if full { + if s.isFull() { return nil, nil } // send getaddr command msgGetAddr := wire.NewMsgGetAddr() - err = wire.WriteMessage(conn, msgGetAddr, pver, netID) + err = wire.WriteMessage(conn, msgGetAddr, s.pver, s.id) if err != nil { return nil, &crawlError{"writing Addr message to remote client", err} } @@ -245,19 +246,19 @@ func crawlIP(pver uint32, netID wire.BitcoinNet, nd *node, full bool) ([]*wire.N // Using the Bitcoin lib for the some networks means it does not understand some // of the commands and will error. We can ignore these as we are only // interested in the addr message and its content. - msgaddr, _, _ := wire.ReadMessage(conn, pver, netID) + msgaddr, _, _ := wire.ReadMessage(conn, s.pver, s.id) if msgaddr != nil { switch msg := msgaddr.(type) { case *wire.MsgAddr: // received the addr message so return the result if config.debug { - log.Printf("%s - received valid addr message\n", ip) + log.Printf("%s - debug - %s - received valid addr message\n", s.name, ip) } dowhile = false return msg.AddrList, nil default: if config.debug { - log.Printf("%s - ignoring message - %v\n", ip, msg.Command()) + log.Printf("%s - debug - %s - ignoring message - %v\n", s.name, ip, msg.Command()) } } } diff --git a/dns.go b/dns.go index 3081e5d..905e89c 100644 --- a/dns.go +++ b/dns.go @@ -101,8 +101,19 @@ func updateDNS(s *dnsseeder) { config.dnsmtx.Unlock() - if config.debug { - log.Printf("debug - DNS update complete - rr4std: %v rr4non: %v rr6std: %v rr6non: %v\n", len(rr4std), len(rr4non), len(rr6std), len(rr6non)) + if config.stats { + s.counts.mtx.RLock() + log.Printf("%s - DNS available: v4std: %v v4non: %v v6std: %v v6non: %v\n", s.name, len(rr4std), len(rr4non), len(rr6std), len(rr6non)) + log.Printf("%s - DNS counts: v4std: %v v4non: %v v6std: %v v6non: %v total: %v\n", + s.name, + s.counts.DNSCounts[dnsV4Std], + s.counts.DNSCounts[dnsV4Non], + s.counts.DNSCounts[dnsV6Std], + s.counts.DNSCounts[dnsV6Non], + s.counts.DNSCounts[dnsV4Std]+s.counts.DNSCounts[dnsV4Non]+s.counts.DNSCounts[dnsV6Std]+s.counts.DNSCounts[dnsV6Non]) + + s.counts.mtx.RUnlock() + } } diff --git a/main.go b/main.go index 47b696d..65b62b3 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func main() { var j bool // FIXME - update with git hash during build - config.version = "0.6.0" + config.version = "0.8.0" config.uptime = time.Now() flag.StringVar(&netfile, "netfile", "", "List of json config files to load") @@ -101,12 +101,12 @@ func main() { config.stats = true } + for _, v := range config.seeders { + log.Printf("status - system is configured for network: %s\n", v.name) + } + if config.verbose == false { log.Printf("status - Running in quiet mode with limited output produced\n") - } else { - for _, v := range config.seeders { - log.Printf("status - system is configured for network: %s\n", v.name) - } } // start the web interface if we want it running diff --git a/seeder.go b/seeder.go index ab96f62..ec60392 100644 --- a/seeder.go +++ b/seeder.go @@ -117,7 +117,7 @@ func (s *dnsseeder) startCrawlers() { tcount := len(s.theList) if tcount == 0 { if config.debug { - log.Printf("debug - startCrawlers fail: no node ailable\n") + log.Printf("%s - debug - startCrawlers fail: no node ailable\n", s.name) } return } @@ -171,14 +171,18 @@ func (s *dnsseeder) startCrawlers() { c.started++ } - log.Printf("%s: started crawler: %s total: %v started: %v\n", s.name, c.desc, c.totalCount, c.started) + if config.stats { + log.Printf("%s: started crawler: %s total: %v started: %v\n", s.name, c.desc, c.totalCount, c.started) + } // update the global stats in another goroutine to free the main goroutine // for other work go updateNodeCounts(s, c.status, c.totalCount, c.started) } - log.Printf("%s: crawlers started. total clients: %d\n", s.name, tcount) + if config.stats { + log.Printf("%s: crawlers started. total clients: %d\n", s.name, tcount) + } // returns and read lock released }