diff --git a/main.go b/main.go index 65b62b3..963f723 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( "github.com/miekg/dns" ) -// ndCounts holds various statistics about the running system +// NodeCounts holds various statistics about the running system for use in html templates type NodeCounts struct { NdStatus []uint32 // number of nodes at each of the 4 statuses - RG, CG, WG, NG NdStarts []uint32 // number of crawles started last startcrawlers run diff --git a/network.go b/network.go index 39eaa4f..c3c275b 100644 --- a/network.go +++ b/network.go @@ -14,7 +14,7 @@ import ( type JNetwork struct { Name string Desc string - Id string + ID string Port uint16 Pver uint32 DNSName string @@ -30,7 +30,7 @@ func createNetFile() { // create a struct to encode with json jnw := &JNetwork{ - Id: "0xabcdef01", + ID: "0xabcdef01", Port: 1234, Pver: 70001, TTL: 600, @@ -62,7 +62,7 @@ func createNetFile() { func loadNetwork(fName string) (*dnsseeder, error) { nwFile, err := os.Open(fName) if err != nil { - return nil, errors.New(fmt.Sprintf("Error reading network file: %v", err)) + return nil, fmt.Errorf("Error reading network file: %v", err) } defer nwFile.Close() @@ -71,7 +71,7 @@ func loadNetwork(fName string) (*dnsseeder, error) { jsonParser := json.NewDecoder(nwFile) if err = jsonParser.Decode(&jnw); err != nil { - return nil, errors.New(fmt.Sprintf("Error decoding network file: %v", err)) + return nil, fmt.Errorf("Error decoding network file: %v", err) } return initNetwork(jnw) @@ -80,11 +80,12 @@ func loadNetwork(fName string) (*dnsseeder, error) { func initNetwork(jnw JNetwork) (*dnsseeder, error) { if jnw.Port == 0 { - return nil, errors.New(fmt.Sprintf("Invalid port supplied: %v", jnw.Port)) + return nil, fmt.Errorf("Invalid port supplied: %v", jnw.Port) + } if jnw.DNSName == "" { - return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied")) + return nil, fmt.Errorf("No DNS Hostname supplied") } // init the seeder @@ -98,9 +99,9 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) { seeder.dnsHost = jnw.DNSName // conver the network magic number to a Uint32 - t1, err := strconv.ParseUint(jnw.Id, 0, 32) + t1, err := strconv.ParseUint(jnw.ID, 0, 32) if err != nil { - return nil, errors.New(fmt.Sprintf("Error converting Network Magic number: %v", err)) + return nil, fmt.Errorf("Error converting Network Magic number: %v", err) } seeder.id = wire.BitcoinNet(t1) diff --git a/seeder.go b/seeder.go index ac9ce5b..df4f600 100644 --- a/seeder.go +++ b/seeder.go @@ -416,10 +416,10 @@ func isDuplicateSeeder(s *dnsseeder) (bool, error) { // check for duplicate seeders with the same details for _, v := range config.seeders { if v.id == s.id { - return true, errors.New(fmt.Sprintf("Duplicate Magic id. Already loaded for %s so can not be used for %s", v.id, v.name, s.name)) + return true, fmt.Errorf("Duplicate Magic id. Already loaded for %s so can not be used for %s", v.id, v.name, s.name) } if v.dnsHost == s.dnsHost { - return true, errors.New(fmt.Sprintf("Duplicate DNS names. Already loaded %s for %s so can not be used for %s", v.dnsHost, v.name, s.name)) + return true, fmt.Errorf("Duplicate DNS names. Already loaded %s for %s so can not be used for %s", v.dnsHost, v.name, s.name) } } return false, nil @@ -427,4 +427,4 @@ func isDuplicateSeeder(s *dnsseeder) (bool, error) { /* -*/ + */ diff --git a/seeder_test.go b/seeder_test.go index 65950c3..82f80f8 100644 --- a/seeder_test.go +++ b/seeder_test.go @@ -9,7 +9,7 @@ import ( func TestGetNonStdIP(t *testing.T) { - var ip_tests = []struct { + var iptests = []struct { rip string port uint16 encip string @@ -20,10 +20,10 @@ func TestGetNonStdIP(t *testing.T) { {"123.213.132.231", 34, "12.91.0.34"}, } - for _, x := range ip_tests { - newip := getNonStdIP(net.ParseIP(x.rip), x.port) - if newip.String() != x.encip { - t.Errorf("real-ip: %s real-port: %v encoded-ip: %v expected-ip: %s", x.rip, x.port, newip, x.encip) + for _, atest := range iptests { + newip := getNonStdIP(net.ParseIP(atest.rip), atest.port) + if newip.String() != atest.encip { + t.Errorf("real-ip: %s real-port: %v encoded-ip: %v expected-ip: %s", atest.rip, atest.port, newip, atest.encip) } } } @@ -46,11 +46,11 @@ func TestAddnNa(t *testing.T) { } s.theList = make(map[string]*node) - for _, x := range td { + for _, atest := range td { // Test NewNetAddress. tcpAddr := &net.TCPAddr{ - IP: net.ParseIP(x.ip), - Port: x.port, + IP: net.ParseIP(atest.ip), + Port: atest.port, } na, _ := wire.NewNetAddress(tcpAddr, 0) ndName := net.JoinHostPort(na.IP.String(), strconv.Itoa(int(na.Port))) @@ -59,8 +59,8 @@ func TestAddnNa(t *testing.T) { if result != true { t.Errorf("failed to create new node: %s", ndName) } - if s.theList[ndName].dnsType != x.dnsType { - t.Errorf("node: %s dnsType:%v expected: %v", ndName, s.theList[ndName].dnsType, x.dnsType) + if s.theList[ndName].dnsType != atest.dnsType { + t.Errorf("node: %s dnsType:%v expected: %v", ndName, s.theList[ndName].dnsType, atest.dnsType) } }