Browse Source

Improve importing json config files

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

15
network.go

@ -87,10 +87,6 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) { @@ -87,10 +87,6 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
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
seeder := &dnsseeder{}
seeder.theList = make(map[string]*node)
@ -130,14 +126,9 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) { @@ -130,14 +126,9 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
if seeder.ttl < 60 {
seeder.ttl = 60
}
// check for duplicates
for _, v := range config.seeders {
if v.id == seeder.id {
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))
}
if dup, err := isDuplicateSeeder(seeder); dup == true {
return nil, err
}
return seeder, nil

17
seeder.go

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
package main
import (
"errors"
"fmt"
"log"
"net"
"strconv"
@ -408,6 +410,21 @@ func getSeederByName(name string) *dnsseeder { @@ -408,6 +410,21 @@ func getSeederByName(name string) *dnsseeder {
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