diff --git a/crawler.go b/crawler.go index d3eab84..6ccb270 100644 --- a/crawler.go +++ b/crawler.go @@ -174,12 +174,19 @@ func crawlIP(tw *Twistee) ([]*wire.NetAddress, *CrawlError) { if config.debug { log.Printf("%s - Remote version: %v\n", ip, msg.ProtocolVersion) } + // fill the Twistee struct with the remote details + tw.version = msg.ProtocolVersion + tw.services = msg.Services + tw.lastBlock = msg.LastBlock + if tw.strVersion != msg.UserAgent { + // if the srtVersion is already the same then don't overwrite it. + // saves the GC having to cleanup a perfectly good string + tw.strVersion = msg.UserAgent + } default: return nil, &CrawlError{"Did not receive expected Version message from remote client", errors.New("")} } - // FIXME - update twistee client version with what they just said - // send verack command msgverack := wire.NewMsgVerAck() @@ -222,7 +229,7 @@ func crawlIP(tw *Twistee) ([]*wire.NetAddress, *CrawlError) { if msgaddr != nil { switch msg := msgaddr.(type) { case *wire.MsgAddr: - // received the addrt message so return the result + // received the addr message so return the result if config.debug { log.Printf("%s - received valid addr message\n", ip) } diff --git a/seeder.go b/seeder.go index 5434e2f..041d0cc 100644 --- a/seeder.go +++ b/seeder.go @@ -47,24 +47,6 @@ type Seeder struct { mtx sync.RWMutex } -// Twistee struct contains details on one twister client -type Twistee struct { - na *wire.NetAddress - lastConnect time.Time - lastTry time.Time - crawlStart time.Time - statusTime time.Time - crawlActive bool - connectFails uint32 - clientVersion int32 - clientSubVersion string - statusStr string - status uint32 // rg,cg,wg,ng - rating uint32 // if it reaches 100 then we ban them - nonstdIP net.IP - dnsType uint32 -} - // initCrawlers needs to be run before the startCrawlers so it can get // a list of current ip addresses from the other seeders and therefore // start the crawl process @@ -102,13 +84,11 @@ func (s *Seeder) startCrawlers() { tcount := len(s.theList) if tcount == 0 { if config.debug { - log.Printf("debug - startCrawlers fail: no twistees available\n", tcount) + log.Printf("debug - startCrawlers fail: no twistees available\n") } return } - // select the twistees to crawl up to max goroutines. - // struct to hold config options for each status var crawlers = []struct { desc string @@ -195,12 +175,12 @@ func (s *Seeder) addNa(nNa *wire.NetAddress) bool { } nt := Twistee{ - na: nNa, - lastConnect: time.Now(), - clientVersion: 0, // FIXME - need to get from the crawl somehow - status: statusRG, - statusTime: time.Now(), - dnsType: DNSV4STD, + na: nNa, + lastConnect: time.Now(), + version: 0, + status: statusRG, + statusTime: time.Now(), + dnsType: DNSV4STD, } // select the dns type based on the remote address type and port diff --git a/twistee.go b/twistee.go new file mode 100644 index 0000000..7ca2818 --- /dev/null +++ b/twistee.go @@ -0,0 +1,28 @@ +package main + +import ( + "net" + "time" + + "github.com/btcsuite/btcd/wire" +) + +// Twistee struct contains details on one twister client +type Twistee struct { + na *wire.NetAddress + lastConnect time.Time + lastTry time.Time + crawlStart time.Time + statusTime time.Time + crawlActive bool + connectFails uint32 + statusStr string // string with last error or OK details + version int32 // remote client protocol version + strVersion string // remote client user agent + services wire.ServiceFlag // remote client supported services + lastBlock int32 + status uint32 // rg,cg,wg,ng + rating uint32 // if it reaches 100 then we ban them + nonstdIP net.IP + dnsType uint32 +}