Skip to content

Commit

Permalink
Use JSON array for InitialIP list
Browse files Browse the repository at this point in the history
More semantically correct.
  • Loading branch information
JeremyRand committed Mar 7, 2022
1 parent af43696 commit 2419aed
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion configs/bitcoin-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Pver": 70001,
"DNSName": "btctseed.zagbot.com",
"TTL": 300,
"InitialIP": "0.0.0.0,0.0.0.0",
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"testnet-seed.alexykot.me",
"testnet-seed.bitcoin.petertodd.org",
Expand Down
2 changes: 1 addition & 1 deletion configs/bitcoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Pver": 70001,
"DNSName": "btcseed.zagbot.com",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"dnsseed.bluematt.me",
"bitseed.xf2.org",
Expand Down
2 changes: 1 addition & 1 deletion configs/dnsseeder.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Pver": 70001,
"DNSName": "seeder.example.com",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"seeder1.example.com",
"seed1.bob.com",
Expand Down
2 changes: 1 addition & 1 deletion configs/namecoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Pver": 70001,
"DNSName": "dnsseed.nmctest.net",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"nmc.seed.quisquis.de",
"seed.nmc.markasoftware.com"
Expand Down
2 changes: 1 addition & 1 deletion configs/twister.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Pver": 60000,
"DNSName": "dnsseed.zagbot.com",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"seed2.twister.net.co",
"seed.twister.net.co",
Expand Down
41 changes: 22 additions & 19 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,34 @@ import (

// JNetwork is the exported struct that is read from the network file
type JNetwork struct {
Name string
Desc string
ID string
Port uint16
Pver uint32
DNSName string
TTL uint32
InitialIP string
Seeders []string
Name string
Desc string
ID string
Port uint16
Pver uint32
DNSName string
TTL uint32
InitialIPs []string
Seeders []string
}

func createNetFile() {
// create a standard json template file that can be loaded into the app

// create a struct to encode with json
jnw := &JNetwork{
ID: "0xabcdef01",
Port: 1234,
Pver: 70001,
TTL: 600,
DNSName: "seeder.example.com",
Name: "SeederNet",
Desc: "Description of SeederNet",
InitialIP: "",
Seeders: []string{
ID: "0xabcdef01",
Port: 1234,
Pver: 70001,
TTL: 600,
DNSName: "seeder.example.com",
Name: "SeederNet",
Desc: "Description of SeederNet",
InitialIPs: []string{
"0.0.0.0",
"0.0.0.0",
},
Seeders: []string{
"seeder1.example.com",
"seed1.bob.com",
"seed2.example.com",
Expand Down Expand Up @@ -104,7 +107,7 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
}
seeder.id = wire.BitcoinNet(t1)

seeder.initialIP = jnw.InitialIP
seeder.initialIPs = jnw.InitialIPs

// load the seeder dns
seeder.seeders = jnw.Seeders
Expand Down
41 changes: 21 additions & 20 deletions seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"net"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -48,21 +47,21 @@ const (
)

type dnsseeder struct {
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
mtx sync.RWMutex // protect thelist
dnsHost string // dns host we will serve results for this domain
name string // Short name for the network
desc string // Long description for the network
initialIP string // Initial ip address to connect to and ask for addresses if we have no seeders
seeders []string // slice of seeders to pull ip addresses when starting this seeder
maxStart []uint32 // max number of goroutines to start each run for each status type
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
pver uint32 // minimum block height for the seeder
ttl uint32 // DNS TTL to use for this seeder
maxSize int // max number of clients before we start restricting new entries
port uint16 // default network port this seeder uses
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
mtx sync.RWMutex // protect thelist
dnsHost string // dns host we will serve results for this domain
name string // Short name for the network
desc string // Long description for the network
initialIPs []string // Initial ip addresses to connect to and ask for addresses if we have no seeders
seeders []string // slice of seeders to pull ip addresses when starting this seeder
maxStart []uint32 // max number of goroutines to start each run for each status type
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
pver uint32 // minimum block height for the seeder
ttl uint32 // DNS TTL to use for this seeder
maxSize int // max number of clients before we start restricting new entries
port uint16 // default network port this seeder uses
}

type result struct {
Expand Down Expand Up @@ -107,12 +106,12 @@ func (s *dnsseeder) initSeeder() {
}

// load ip addresses into system and start crawling from them
if len(s.theList) == 0 && s.initialIP != "" {
for _, initialIP := range strings.Split(s.initialIP, ",") {
if len(s.theList) == 0 && len(s.initialIPs) > 0 {
for _, initialIP := range s.initialIPs {
if newIP := net.ParseIP(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)
log.Printf("%s: crawling with initial IP %s \n", s.name, initialIP)
}
}
}
Expand All @@ -123,7 +122,9 @@ func (s *dnsseeder) initSeeder() {
for _, v := range s.seeders {
log.Printf("%s: Seeder: %s\n", s.name, v)
}
log.Printf("%s: Initial IP: %s\n", s.name, s.initialIP)
for _, v := range s.initialIPs {
log.Printf("%s: Initial IP: %s\n", s.name, v)
}
}
}

Expand Down

0 comments on commit 2419aed

Please sign in to comment.