Browse Source

Add support to start crawling from one initial ip address

master
Lyndsay Roger 9 years ago
parent
commit
75767b0eeb
  1. 78
      network.go
  2. 52
      seeder.go

78
network.go

@ -12,19 +12,17 @@ import (
// JNetwork is the exported struct that is read from the network file // JNetwork is the exported struct that is read from the network file
type JNetwork struct { type JNetwork struct {
Name string Name string
Desc string Desc string
SeederType string Id string
Secret string Port uint16
Remote string Pver uint32
Id string DNSName string
Port uint16 TTL uint32
Pver uint32 InitialIP string
DNSName string Seeder1 string
TTL uint32 Seeder2 string
Seeder1 string Seeder3 string
Seeder2 string
Seeder3 string
} }
func createNetFile() { func createNetFile() {
@ -32,19 +30,17 @@ func createNetFile() {
// create a struct to encode with json // create a struct to encode with json
jnw := &JNetwork{ jnw := &JNetwork{
Id: "0xabcdef01", Id: "0xabcdef01",
Port: 1234, Port: 1234,
Pver: 70001, Pver: 70001,
TTL: 600, TTL: 600,
DNSName: "seeder.example.com", DNSName: "seeder.example.com",
Name: "SeederNet", Name: "SeederNet",
Desc: "Description of SeederNet", Desc: "Description of SeederNet",
SeederType: "Combined", InitialIP: "",
Secret: "32bYTesoFSECretThAtiSASecrET!!", Seeder1: "seeder1.example.com",
Remote: "http://dnsserver.example.com:1234/updatedns", Seeder2: "seed1.bob.com",
Seeder1: "seeder1.example.com", Seeder3: "seed2.example.com",
Seeder2: "seed1.bob.com",
Seeder3: "seed2.example.com",
} }
f, err := os.Create("dnsseeder.json") f, err := os.Create("dnsseeder.json")
@ -91,12 +87,6 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied")) return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied"))
} }
// we only need a secret if we are a crawler or dns type
if needSecret := convertSeederType(jnw.SeederType); needSecret != typeCombined {
if ok := checkBlockSize(jnw.Secret); ok != true {
return nil, errors.New(fmt.Sprintf("shared secret must be either 16, 24 or 32 bytes long. currently: %v", len(jnw.Secret)))
}
}
if _, ok := config.seeders[jnw.Name]; ok { if _, ok := config.seeders[jnw.Name]; ok {
return nil, errors.New(fmt.Sprintf("Name already exists from previous file - %s", jnw.Name)) return nil, errors.New(fmt.Sprintf("Name already exists from previous file - %s", jnw.Name))
} }
@ -110,9 +100,6 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
seeder.name = jnw.Name seeder.name = jnw.Name
seeder.desc = jnw.Desc seeder.desc = jnw.Desc
seeder.dnsHost = jnw.DNSName seeder.dnsHost = jnw.DNSName
seeder.seederType = convertSeederType(jnw.SeederType)
seeder.secret = jnw.Secret
seeder.remote = jnw.Remote
// conver the network magic number to a Uint32 // conver the network magic number to a Uint32
t1, err := strconv.ParseUint(jnw.Id, 0, 32) t1, err := strconv.ParseUint(jnw.Id, 0, 32)
@ -121,6 +108,8 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
} }
seeder.id = wire.BitcoinNet(t1) seeder.id = wire.BitcoinNet(t1)
seeder.initialIP = jnw.InitialIP
// load the seeder dns // load the seeder dns
seeder.seeders = make([]string, 3) seeder.seeders = make([]string, 3)
seeder.seeders[0] = jnw.Seeder1 seeder.seeders[0] = jnw.Seeder1
@ -154,25 +143,6 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
return seeder, nil return seeder, nil
} }
func convertSeederType(seederType string) uint32 {
switch seederType {
case "Crawl":
return typeCrawl
case "DNS":
return typeDNS
default:
return typeCombined
}
}
func checkBlockSize(secret string) bool {
s := len(secret)
if s == 16 || s == 24 || s == 32 {
return true
}
return false
}
/* /*
*/ */

52
seeder.go

@ -45,31 +45,22 @@ const (
maxStatusTypes // used in main to allocate slice maxStatusTypes // used in main to allocate slice
) )
const (
// seederType
typeCombined = iota // This seeder both crawls and provides dns responses
typeCrawl // this seeder just crawls the network and sends ip info to a remote dns server
typeDNS // this seeder just provides dns data to clients and does no crawling itself
)
type dnsseeder struct { type dnsseeder struct {
id wire.BitcoinNet // Magic number - Unique ID for this network. Sent in header of all messages id wire.BitcoinNet // Magic number - Unique ID for this network. Sent in header of all messages
theList map[string]*node // the list of current nodes theList map[string]*node // the list of current nodes
mtx sync.RWMutex // protect thelist mtx sync.RWMutex // protect thelist
maxSize int // max number of clients before we start restricting new entries maxSize int // max number of clients before we start restricting new entries
port uint16 // default network port this seeder uses port uint16 // default network port this seeder uses
pver uint32 // minimum block height for the seeder pver uint32 // minimum block height for the seeder
ttl uint32 // DNS TTL to use for this seeder ttl uint32 // DNS TTL to use for this seeder
dnsHost string // dns host we will serve results for this domain dnsHost string // dns host we will serve results for this domain
name string // Short name for the network name string // Short name for the network
desc string // Long description for the network desc string // Long description for the network
seederType uint32 // Combined, crawl or DNS only initialIP string // Initial ip address to connect to and ask for addresses if we have no seeders
secret string // Shared secret with remote seeder to encrypt messages seeders []string // slice of seeders to pull ip addresses when starting this seeder
remote string // Remote host and port to send dns info if we are a crawler maxStart []uint32 // max number of goroutines to start each run for each status type
seeders []string // slice of seeders to pull ip addresses when starting this seeder delay []int64 // number of seconds to wait before we connect to a known client for each status
maxStart []uint32 // max number of goroutines to start each run for each status type counts NodeCounts // structure to hold stats for this seeder
delay []int64 // number of seconds to wait before we connect to a known client for each status
counts NodeCounts // structure to hold stats for this seeder
} }
// initCrawlers needs to be run before the startCrawlers so it can get // initCrawlers needs to be run before the startCrawlers so it can get
@ -101,12 +92,23 @@ func (s *dnsseeder) initCrawlers() {
log.Printf("%s: completed import of %v addresses from %s\n", s.name, c, aseeder) log.Printf("%s: completed import of %v addresses from %s\n", s.name, c, aseeder)
} }
} }
// load one ip address into system and start crawling from it
if len(s.theList) == 0 && s.initialIP != "" {
if newIP := net.ParseIP(s.initialIP); newIP != nil {
// 1 at the end is the services flag
if x := s.addNa(wire.NewNetAddressIPPort(newIP, s.port, 1)); x == true {
log.Printf("%s: crawling with initial IP %s \n", s.name, s.initialIP)
}
}
}
if len(s.theList) == 0 { if len(s.theList) == 0 {
log.Printf("%s: Error: No ip addresses from seeders so I have nothing to crawl.\n", s.name) log.Printf("%s: Error: No ip addresses from seeders so I have nothing to crawl.\n", s.name)
for _, v := range s.seeders { for _, v := range s.seeders {
log.Printf("%s: Seeder: %s\n", s.name, v) log.Printf("%s: Seeder: %s\n", s.name, v)
} }
log.Printf("%s: Initial IP: %s\n", s.name, s.initialIP)
} }
} }

Loading…
Cancel
Save