start implementation of report

This commit is contained in:
Callan Bryant 2020-03-04 22:23:32 +00:00
parent f8eeda36f9
commit e7fe33fe76
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 32 additions and 0 deletions

View File

@ -29,6 +29,7 @@ func main() {
dsnet.Sync()
case "report":
dsnet.report()
case "down":
dsnet.Down()

19
report.go Normal file
View File

@ -0,0 +1,19 @@
package dsnet
import (
"net"
"github.com/vishvananda/netlink"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func Up() {
conf := MustLoadDsnetConfig()
dev, err := wgctrl.Device(conf.InterfaceName)
check(err)
report := Report(dev, conf)
report.MustSave()
}

View File

@ -3,6 +3,8 @@ package dsnet
import (
"net"
"time"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
type Status int
@ -52,6 +54,16 @@ type DsnetReport struct {
Peers []PeerReport
}
func Report(*wgtypes.Device, conf *DsnetConfig) DsnetReport {
}
func (report *DsnetReport) MustSave() {
_json, _ := json.MarshalIndent(report, "", " ")
err := ioutil.WriteFile(CONFIG_FILE, _json, 0644)
check(err)
}
type PeerReport struct {
// Used to update DNS
Hostname string