Browse Source

Add remote client details to Twistee structure

master
Lyndsay Roger 9 years ago
parent
commit
76e1f2d1a2
  1. 13
      crawler.go
  2. 34
      seeder.go
  3. 28
      twistee.go

13
crawler.go

@ -174,12 +174,19 @@ func crawlIP(tw *Twistee) ([]*wire.NetAddress, *CrawlError) {
if config.debug { if config.debug {
log.Printf("%s - Remote version: %v\n", ip, msg.ProtocolVersion) 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: default:
return nil, &CrawlError{"Did not receive expected Version message from remote client", errors.New("")} 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 // send verack command
msgverack := wire.NewMsgVerAck() msgverack := wire.NewMsgVerAck()
@ -222,7 +229,7 @@ func crawlIP(tw *Twistee) ([]*wire.NetAddress, *CrawlError) {
if msgaddr != nil { if msgaddr != nil {
switch msg := msgaddr.(type) { switch msg := msgaddr.(type) {
case *wire.MsgAddr: case *wire.MsgAddr:
// received the addrt message so return the result // received the addr message so return the result
if config.debug { if config.debug {
log.Printf("%s - received valid addr message\n", ip) log.Printf("%s - received valid addr message\n", ip)
} }

34
seeder.go

@ -47,24 +47,6 @@ type Seeder struct {
mtx sync.RWMutex 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 // initCrawlers needs to be run before the startCrawlers so it can get
// a list of current ip addresses from the other seeders and therefore // a list of current ip addresses from the other seeders and therefore
// start the crawl process // start the crawl process
@ -102,13 +84,11 @@ func (s *Seeder) startCrawlers() {
tcount := len(s.theList) tcount := len(s.theList)
if tcount == 0 { if tcount == 0 {
if config.debug { if config.debug {
log.Printf("debug - startCrawlers fail: no twistees available\n", tcount) log.Printf("debug - startCrawlers fail: no twistees available\n")
} }
return return
} }
// select the twistees to crawl up to max goroutines.
// struct to hold config options for each status // struct to hold config options for each status
var crawlers = []struct { var crawlers = []struct {
desc string desc string
@ -195,12 +175,12 @@ func (s *Seeder) addNa(nNa *wire.NetAddress) bool {
} }
nt := Twistee{ nt := Twistee{
na: nNa, na: nNa,
lastConnect: time.Now(), lastConnect: time.Now(),
clientVersion: 0, // FIXME - need to get from the crawl somehow version: 0,
status: statusRG, status: statusRG,
statusTime: time.Now(), statusTime: time.Now(),
dnsType: DNSV4STD, dnsType: DNSV4STD,
} }
// select the dns type based on the remote address type and port // select the dns type based on the remote address type and port

28
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
}
Loading…
Cancel
Save