start creation of dsnet config

This commit is contained in:
Callan Bryant 2020-03-01 20:54:33 +00:00
parent fac130eea1
commit d7b0d77cf2
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
3 changed files with 22 additions and 7 deletions

View File

@ -7,6 +7,7 @@ const (
// these end up in the config file
DEFAULT_INTERFACE_NAME = "dsnet"
DEFAULT_REPORT_FILE = "/var/lib/dsnet-report.json"
DEFAULT_LISTEN_PORT = 51820;
// keepalive always configured for everything
KEEPALIVE_SECONDS = 21;
@ -14,6 +15,5 @@ const (
// when is a peer considered gone forever? (could remove)
EXPIRY_DAYS = 28;
LISTEN_PORT = 51820;
)

21
init.go
View File

@ -1,10 +1,27 @@
package dsnet
import (
"net"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
//"github.com/mikioh/ipaddr"
)
func Init() {
//conf := DsnetConfig {
//}
conf := DsnetConfig {
PrivateKey = wgtypes.GeneratePrivateKey(),
PresharedKey = wgtypes.GenerateKey(),
ListenPort = DEFAULT_LISTEN_PORT,
Network = getRandomNetwork(),
Domain = "dsnet"
}
}
// get a random /22 (1023 hosts) (or /24?)
// TODO implement
func getRandomNetwork() net.IPNet {
return net.IPNet {
IP{10,129,123,0},
Mask{255,255,255,240},
}
}

View File

@ -44,14 +44,12 @@ type Peer struct {
type DsnetConfig struct {
PrivateKey *wgtypes.Key `validate:"required,len=44"`
PresharedKey wgtypes.Key `validate:"required,len=44"`
ListenPort *int `validate:"gte=1024,lte=65535"`
FirewallMark *int
Peers []PeerConfig
// IP network from which to allocate automatic sequential addresses
//Network net.IPNet
// TODO: use ParseCIDR to parse config
// Network is chosen randomly when not specified
Network string `validate:"required,cidr"`
Network net.IPNet `validate:"required"`
// domain to append to hostnames. Relies on separate DNS server for
// resolution. Informational only.
Domain string `validate:"required,gte=1,lte=255"`