add documentation

This commit is contained in:
octeep 2022-04-01 00:47:14 +01:00
parent f93e047f64
commit 0048d87cad
No known key found for this signature in database
GPG key ID: D8251F73BE242851
4 changed files with 72 additions and 31 deletions

View file

@ -9,6 +9,7 @@ import (
"golang.zx2c4.com/wireguard/tun/netstack"
)
// DeviceSetting contains the parameters for setting up a tun interface
type DeviceSetting struct {
ipcRequest string
dns []netip.Addr
@ -16,6 +17,7 @@ type DeviceSetting struct {
mtu int
}
// serialize the config into an IPC request and DeviceSetting
func createIPCRequest(conf *DeviceConfig) (*DeviceSetting, error) {
request := fmt.Sprintf(`private_key=%s
public_key=%s
@ -28,6 +30,7 @@ allowed_ip=0.0.0.0/0`, conf.SelfSecretKey, conf.PeerPublicKey, conf.PeerEndpoint
return setting, nil
}
// StartWireguard creates a tun interface on netstack given a configuration
func StartWireguard(conf *DeviceConfig) (*VirtualTun, error) {
setting, err := createIPCRequest(conf)
if err != nil {