move sync fn to sync.go
This commit is contained in:
parent
5a71debc59
commit
b6bd2d33e1
24
sync.go
24
sync.go
@ -1,7 +1,31 @@
|
|||||||
package dsnet
|
package dsnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
)
|
||||||
|
|
||||||
func Sync() {
|
func Sync() {
|
||||||
// TODO check device settings first
|
// TODO check device settings first
|
||||||
conf := MustLoadDsnetConfig()
|
conf := MustLoadDsnetConfig()
|
||||||
ConfigureDevice(conf)
|
ConfigureDevice(conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
21
up.go
21
up.go
@ -4,8 +4,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Up() {
|
func Up() {
|
||||||
@ -47,22 +45,3 @@ func CreateLink(conf *DsnetConfig) {
|
|||||||
ExitFail("Could not bring up device '%s' (%v)", conf.InterfaceName, err)
|
ExitFail("Could not bring up device '%s' (%v)", conf.InterfaceName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user