dsnet/sync.go

34 lines
655 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) {
peers := conf.GetWgPeerConfigs()
2020-03-04 23:50:44 +01:00
wgConfig := wgtypes.Config{
2020-03-08 15:10:38 +01:00
PrivateKey: &conf.PrivateKey.Key,
ListenPort: &conf.ListenPort,
ReplacePeers: true,
Peers: peers,
2020-03-04 23:50:44 +01:00
}
2020-03-08 15:10:38 +01:00
wg, err := wgctrl.New()
check(err)
defer wg.Close()
2020-03-04 23:50:44 +01:00
err = wg.ConfigureDevice(conf.InterfaceName, wgConfig)
if err != nil {
ExitFail("Could not configure device '%s' (%v)", conf.InterfaceName, err)
}
}