diff --git a/const.go b/const.go index 21bf8b1..0eddd6e 100644 --- a/const.go +++ b/const.go @@ -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; ) diff --git a/init.go b/init.go index ab43661..c662f65 100644 --- a/init.go +++ b/init.go @@ -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}, + } } diff --git a/types.go b/types.go index 44718cf..97554c3 100644 --- a/types.go +++ b/types.go @@ -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"`