working (empty) report generation

This commit is contained in:
Callan Bryant 2020-03-04 22:49:27 +00:00
parent e7fe33fe76
commit 5a71debc59
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 18 additions and 13 deletions

View File

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

View File

@ -1,19 +1,22 @@
package dsnet
import (
"net"
"github.com/vishvananda/netlink"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func Up() {
func Report() {
conf := MustLoadDsnetConfig()
dev, err := wgctrl.Device(conf.InterfaceName)
wg, err := wgctrl.New()
check(err)
defer wg.Close()
report := Report(dev, conf)
report.MustSave()
dev, err := wg.Device(conf.InterfaceName)
if err != nil {
ExitFail("Could not retrieve device '%s' (%v)", conf.InterfaceName, err)
}
report := GenerateReport(dev, conf)
report.MustSave(conf.ReportFile)
}

View File

@ -1,6 +1,8 @@
package dsnet
import (
"encoding/json"
"io/ioutil"
"net"
"time"
@ -54,13 +56,13 @@ type DsnetReport struct {
Peers []PeerReport
}
func Report(*wgtypes.Device, conf *DsnetConfig) DsnetReport {
func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig) DsnetReport {
return DsnetReport{}
}
func (report *DsnetReport) MustSave() {
func (report *DsnetReport) MustSave(filename string) {
_json, _ := json.MarshalIndent(report, "", " ")
err := ioutil.WriteFile(CONFIG_FILE, _json, 0644)
err := ioutil.WriteFile(filename, _json, 0644)
check(err)
}