Browse Source

golint cleanup

master
Lyndsay Roger 9 years ago
parent
commit
222ce63793
  1. 2
      main.go
  2. 17
      network.go
  3. 6
      seeder.go
  4. 20
      seeder_test.go

2
main.go

@ -18,7 +18,7 @@ import (
"github.com/miekg/dns" "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 { type NodeCounts struct {
NdStatus []uint32 // number of nodes at each of the 4 statuses - RG, CG, WG, NG NdStatus []uint32 // number of nodes at each of the 4 statuses - RG, CG, WG, NG
NdStarts []uint32 // number of crawles started last startcrawlers run NdStarts []uint32 // number of crawles started last startcrawlers run

17
network.go

@ -14,7 +14,7 @@ import (
type JNetwork struct { type JNetwork struct {
Name string Name string
Desc string Desc string
Id string ID string
Port uint16 Port uint16
Pver uint32 Pver uint32
DNSName string DNSName string
@ -30,7 +30,7 @@ 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,
@ -62,7 +62,7 @@ func createNetFile() {
func loadNetwork(fName string) (*dnsseeder, error) { func loadNetwork(fName string) (*dnsseeder, error) {
nwFile, err := os.Open(fName) nwFile, err := os.Open(fName)
if err != nil { 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() defer nwFile.Close()
@ -71,7 +71,7 @@ func loadNetwork(fName string) (*dnsseeder, error) {
jsonParser := json.NewDecoder(nwFile) jsonParser := json.NewDecoder(nwFile)
if err = jsonParser.Decode(&jnw); err != nil { 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) return initNetwork(jnw)
@ -80,11 +80,12 @@ func loadNetwork(fName string) (*dnsseeder, error) {
func initNetwork(jnw JNetwork) (*dnsseeder, error) { func initNetwork(jnw JNetwork) (*dnsseeder, error) {
if jnw.Port == 0 { 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 == "" { if jnw.DNSName == "" {
return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied")) return nil, fmt.Errorf("No DNS Hostname supplied")
} }
// init the seeder // init the seeder
@ -98,9 +99,9 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
seeder.dnsHost = jnw.DNSName seeder.dnsHost = jnw.DNSName
// 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)
if err != nil { 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) seeder.id = wire.BitcoinNet(t1)

6
seeder.go

@ -416,10 +416,10 @@ func isDuplicateSeeder(s *dnsseeder) (bool, error) {
// check for duplicate seeders with the same details // check for duplicate seeders with the same details
for _, v := range config.seeders { for _, v := range config.seeders {
if v.id == s.id { 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 { 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 return false, nil
@ -427,4 +427,4 @@ func isDuplicateSeeder(s *dnsseeder) (bool, error) {
/* /*
*/ */

20
seeder_test.go

@ -9,7 +9,7 @@ import (
func TestGetNonStdIP(t *testing.T) { func TestGetNonStdIP(t *testing.T) {
var ip_tests = []struct { var iptests = []struct {
rip string rip string
port uint16 port uint16
encip string encip string
@ -20,10 +20,10 @@ func TestGetNonStdIP(t *testing.T) {
{"123.213.132.231", 34, "12.91.0.34"}, {"123.213.132.231", 34, "12.91.0.34"},
} }
for _, x := range ip_tests { for _, atest := range iptests {
newip := getNonStdIP(net.ParseIP(x.rip), x.port) newip := getNonStdIP(net.ParseIP(atest.rip), atest.port)
if newip.String() != x.encip { if newip.String() != atest.encip {
t.Errorf("real-ip: %s real-port: %v encoded-ip: %v expected-ip: %s", x.rip, x.port, newip, x.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) s.theList = make(map[string]*node)
for _, x := range td { for _, atest := range td {
// Test NewNetAddress. // Test NewNetAddress.
tcpAddr := &net.TCPAddr{ tcpAddr := &net.TCPAddr{
IP: net.ParseIP(x.ip), IP: net.ParseIP(atest.ip),
Port: x.port, Port: atest.port,
} }
na, _ := wire.NewNetAddress(tcpAddr, 0) na, _ := wire.NewNetAddress(tcpAddr, 0)
ndName := net.JoinHostPort(na.IP.String(), strconv.Itoa(int(na.Port))) ndName := net.JoinHostPort(na.IP.String(), strconv.Itoa(int(na.Port)))
@ -59,8 +59,8 @@ func TestAddnNa(t *testing.T) {
if result != true { if result != true {
t.Errorf("failed to create new node: %s", ndName) t.Errorf("failed to create new node: %s", ndName)
} }
if 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, x.dnsType) t.Errorf("node: %s dnsType:%v expected: %v", ndName, s.theList[ndName].dnsType, atest.dnsType)
} }
} }

Loading…
Cancel
Save