Browse Source

Improve importing json config files

master
Lyndsay Roger 9 years ago
parent
commit
f6a55213dd
  1. 15
      network.go
  2. 19
      seeder.go

15
network.go

@ -87,10 +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"))
} }
if _, ok := config.seeders[jnw.Name]; ok {
return nil, errors.New(fmt.Sprintf("Name already exists from previous file - %s", jnw.Name))
}
// init the seeder // init the seeder
seeder := &dnsseeder{} seeder := &dnsseeder{}
seeder.theList = make(map[string]*node) seeder.theList = make(map[string]*node)
@ -130,14 +126,9 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
if seeder.ttl < 60 { if seeder.ttl < 60 {
seeder.ttl = 60 seeder.ttl = 60
} }
// check for duplicates
for _, v := range config.seeders { if dup, err := isDuplicateSeeder(seeder); dup == true {
if v.id == seeder.id { return nil, err
return nil, errors.New(fmt.Sprintf("Duplicate Magic id. Already loaded for %s so can not be used for %s", v.id, v.name, seeder.name))
}
if v.dnsHost == seeder.dnsHost {
return nil, errors.New(fmt.Sprintf("Duplicate DNS names. Already loaded %s for %s so can not be used for %s", v.dnsHost, v.name, seeder.name))
}
} }
return seeder, nil return seeder, nil

19
seeder.go

@ -1,6 +1,8 @@
package main package main
import ( import (
"errors"
"fmt"
"log" "log"
"net" "net"
"strconv" "strconv"
@ -408,6 +410,21 @@ func getSeederByName(name string) *dnsseeder {
return nil return nil
} }
// isDuplicateSeeder returns true if the seeder details already exist in the application
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))
}
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 false, nil
}
/* /*
*/ */

Loading…
Cancel
Save