dsnet/sync.go

32 lines
638 B
Go
Raw Normal View History

2020-03-04 23:06:15 +01:00
package dsnet
2020-03-04 23:50:44 +01:00
import (
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func Sync() {
2020-03-04 23:06:15 +01:00
// TODO check device settings first
conf := MustLoadDsnetConfig()
ConfigureDevice(conf)
}
2020-03-04 23:50:44 +01:00
func ConfigureDevice(conf *DsnetConfig) {
wgConfig := wgtypes.Config{
PrivateKey: &conf.PrivateKey.Key,
ListenPort: &conf.ListenPort,
ReplacePeers: true,
Peers: conf.GetWgPeerConfigs(),
}
wg, err := wgctrl.New()
check(err)
defer wg.Close()
err = wg.ConfigureDevice(conf.InterfaceName, wgConfig)
if err != nil {
ExitFail("Could not configure device '%s' (%v)", conf.InterfaceName, err)
}
}