2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2018 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 "cypherpunks.ru/govpn"
33 RefreshRate = time.Minute
37 confs map[govpn.PeerID]*govpn.PeerConf
38 idsCache *govpn.MACCache
41 func confRead() (*map[govpn.PeerID]*govpn.PeerConf, error) {
42 data, err := ioutil.ReadFile(*confPath)
46 confsRaw := new(map[string]govpn.PeerConf)
47 err = yaml.Unmarshal(data, confsRaw)
52 confs := make(map[govpn.PeerID]*govpn.PeerConf, len(*confsRaw))
53 for name, pc := range *confsRaw {
54 verifier, err := govpn.VerifierFromString(pc.VerifierRaw)
56 return nil, errors.New("Unable to decode verifier: " + err.Error())
62 pc.MTU = govpn.MTUDefault
64 if pc.MTU > govpn.MTUMax {
65 govpn.Printf(`[mtu-high bind="%s" value="%d" overriden="%d"]`, *bindAddr, pc.MTU, govpn.MTUMax)
68 conf := govpn.PeerConf{
79 TimeSync: pc.TimeSync,
81 if pc.TimeoutInt <= 0 {
82 pc.TimeoutInt = govpn.TimeoutDefault
84 conf.Timeout = time.Second * time.Duration(pc.TimeoutInt)
85 confs[*verifier.ID] = &conf
90 func confRefresh() error {
91 newConfs, err := confRead()
93 govpn.Printf(`[conf-parse-failed bind="%s" err="%s"]`, *bindAddr, err)
97 idsCache.Update(newConfs)
102 idsCache = govpn.NewMACCache()
103 if err := confRefresh(); err != nil {
108 time.Sleep(RefreshRate)