Skip to content

Commit

Permalink
Merge pull request #16 from JeremyRand/json-array
Browse files Browse the repository at this point in the history
Use JSON arrays for seeders and initial IP's
  • Loading branch information
gombadi authored Apr 1, 2022
2 parents 1102677 + e601985 commit 693e279
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 66 deletions.
13 changes: 9 additions & 4 deletions configs/bitcoin-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
"Pver": 70001,
"DNSName": "btctseed.zagbot.com",
"TTL": 300,
"InitialIP": "0.0.0.0,0.0.0.0",
"Seeder1": "testnet-seed.alexykot.me",
"Seeder2": "testnet-seed.bitcoin.petertodd.org",
"Seeder3": "testnet-seed.bluematt.me"
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"testnet-seed.alexykot.me",
"testnet-seed.bitcoin.jonasschnelli.ch",
"testnet-seed.bitcoin.petertodd.org",
"seed.tbtc.petertodd.org",
"seed.testnet.bitcoin.sprovoost.nl",
"testnet-seed.bluematt.me"
]
}
17 changes: 13 additions & 4 deletions configs/bitcoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"Pver": 70001,
"DNSName": "btcseed.zagbot.com",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"Seeder1": "dnsseed.bluematt.me",
"Seeder2": "bitseed.xf2.org",
"Seeder3": "dnsseed.bitcoin.dashjr.org"
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"seed.bitcoin.sipa.be",
"dnsseed.bluematt.me",
"bitseed.xf2.org",
"dnsseed.bitcoin.dashjr.org",
"seed.bitcoinstats.com",
"seed.bitcoin.jonasschnelli.ch",
"seed.btc.petertodd.org",
"seed.bitcoin.sprovoost.nl",
"dnsseed.emzy.de",
"seed.bitcoin.wiz.biz"
]
}
10 changes: 6 additions & 4 deletions configs/dnsseeder.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"Pver": 70001,
"DNSName": "seeder.example.com",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"Seeder1": "seeder1.example.com",
"Seeder2": "seed1.bob.com",
"Seeder3": "seed2.example.com"
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"seeder1.example.com",
"seed1.bob.com",
"seed2.example.com"
]
}
12 changes: 9 additions & 3 deletions configs/namecoin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
"Pver": 70001,
"DNSName": "dnsseed.nmctest.net",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"Seeder1": "nmc.seed.quisquis.de",
"Seeder2": "seed.nmc.markasoftware.com"
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"nmc.seed.quisquis.de",
"seed.nmc.markasoftware.com",
"seed.namecoin.libreisp.se",
"dnsseed1.nmc.dotbit.zone",
"dnsseed2.nmc.dotbit.zone",
"dnsseed.nmc.testls.space"
]
}
10 changes: 6 additions & 4 deletions configs/twister.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"Pver": 60000,
"DNSName": "dnsseed.zagbot.com",
"TTL": 600,
"InitialIP": "0.0.0.0,0.0.0.0",
"Seeder1": "seed2.twister.net.co",
"Seeder2": "seed.twister.net.co",
"Seeder3": "seed3.twister.net.co"
"InitialIPs": ["0.0.0.0","0.0.0.0"],
"Seeders": [
"seed2.twister.net.co",
"seed.twister.net.co",
"seed3.twister.net.co"
]
}
54 changes: 27 additions & 27 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,38 @@ 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
Seeder1 string
Seeder2 string
Seeder3 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: "",
Seeder1: "seeder1.example.com",
Seeder2: "seed1.bob.com",
Seeder3: "seed2.example.com",
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",
},
}

f, err := os.Create("dnsseeder.json")
Expand Down Expand Up @@ -104,13 +107,10 @@ 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 = make([]string, 3)
seeder.seeders[0] = jnw.Seeder1
seeder.seeders[1] = jnw.Seeder2
seeder.seeders[2] = jnw.Seeder3
seeder.seeders = jnw.Seeders

// add some checks to the start & delay values to keep them sane
seeder.maxStart = []uint32{20, 20, 20, 30}
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 693e279

Please sign in to comment.