func confRead() map[govpn.PeerId]*govpn.PeerConf { data, err := ioutil.ReadFile(*confPath) if err != nil { log.Fatalln("Unable to read configuration:", err) } confsRaw := new(map[string]govpn.PeerConf) err = json.Unmarshal(data, confsRaw) if err != nil { log.Fatalln("Unable to parse configuration:", err) } confs := make(map[govpn.PeerId]*govpn.PeerConf, len(*confsRaw)) for name, pc := range *confsRaw { verifier, err := govpn.VerifierFromString(pc.VerifierRaw) if err != nil { log.Fatalln("Unable to decode the key:", err.Error(), pc.VerifierRaw) } conf := govpn.PeerConf{ Verifier: verifier, Id: verifier.Id, Name: name, Up: pc.Up, Down: pc.Down, Noise: pc.Noise, CPR: pc.CPR, } if pc.TimeoutInt <= 0 { pc.TimeoutInt = govpn.TimeoutDefault } conf.Timeout = time.Second * time.Duration(pc.TimeoutInt) confs[*verifier.Id] = &conf } return confs }
func confRead() map[govpn.PeerId]*govpn.PeerConf { data, err := ioutil.ReadFile(*confPath) if err != nil { log.Fatalln("Unable to read configuration:", err) } confsRaw := new(map[string]govpn.PeerConf) err = json.Unmarshal(data, confsRaw) if err != nil { log.Fatalln("Unable to parse configuration:", err) } confs := make(map[govpn.PeerId]*govpn.PeerConf, len(*confsRaw)) for peerIdRaw, pc := range *confsRaw { peerId, err := govpn.IDDecode(peerIdRaw) if err != nil { log.Fatalln("Invalid peer ID:", peerIdRaw, err) } conf := govpn.PeerConf{ Id: peerId, Name: pc.Name, Up: pc.Up, Down: pc.Down, Noise: pc.Noise, CPR: pc.CPR, } if pc.TimeoutInt <= 0 { pc.TimeoutInt = govpn.TimeoutDefault } conf.Timeout = time.Second * time.Duration(pc.TimeoutInt) if len(pc.Verifier) != ed25519.PublicKeySize*2 { log.Fatalln("Verifier must be 64 hex characters long") } keyDecoded, err := hex.DecodeString(string(pc.Verifier)) if err != nil { log.Fatalln("Unable to decode the key:", err.Error(), pc.Verifier) } conf.DSAPub = new([ed25519.PublicKeySize]byte) copy(conf.DSAPub[:], keyDecoded) confs[*peerId] = &conf } return confs }