dsnet/types.go

71 lines
2.0 KiB
Go
Raw Normal View History

2020-02-10 20:58:13 +01:00
package dsnet
import (
"net"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
2020-02-20 20:08:07 +01:00
// keepalive for everything
const KeepaliveSeconds = 21;
const ExpiryDays = 28;
const DefaultListenPort = 51820;
2020-02-10 20:58:13 +01:00
// see https://github.com/WireGuard/wgctrl-go/blob/master/wgtypes/types.go for definitions
2020-02-20 20:08:07 +01:00
type PeerConfig struct {
// username of person running this host/router
2020-02-20 21:29:47 +01:00
Owner string `validate:"required,gte=1,lte=255"`
2020-02-20 20:08:07 +01:00
// Used to update DNS
2020-02-20 21:29:47 +01:00
Hostname string `validate:"required,gte=1,lte=255"`
2020-02-20 20:08:07 +01:00
// Description of what the host is and/or does
2020-02-20 21:29:47 +01:00
Description string `validate:"required,gte=1,lte=255"`
2020-02-20 20:08:07 +01:00
2020-02-20 21:29:47 +01:00
PublicKey wgtypes.Key `validate:"required,len=44"`
PresharedKey wgtypes.Key `validate:"required,len=44"`
Endpoint *net.UDPAddr `validate:"required,udp4_addr"`
AllowedIPs []net.IPNet `validate:"dive,required,cidr"`
2020-02-20 20:08:07 +01:00
}
2020-02-10 20:58:13 +01:00
type Peer struct {
2020-02-20 20:08:07 +01:00
// username of person running this host/router
Owner string
// Used to update DNS
Hostname string
// Description of what the host is and/or does
2020-02-10 20:58:13 +01:00
Description string
2020-02-20 20:08:07 +01:00
// whether last heartbeat/rxdata was received (50% margin)
Online bool
// if no data for x days, consider revoking access
Expired bool
2020-02-10 20:58:13 +01:00
PublicKey wgtypes.Key
PresharedKey wgtypes.Key
Endpoint *net.UDPAddr
LastHandshakeTime time.Time
ReceiveBytes int64
TransmitBytes int64
AllowedIPs []net.IPNet
}
2020-02-20 20:08:07 +01:00
type DsnetConfig struct {
2020-02-20 21:29:47 +01:00
PrivateKey *wgtypes.Key `validate:"required,len=44"`
ListenPort *int `validate:"gte=1024,lte=65535"`
2020-02-20 20:08:07 +01:00
FirewallMark *int
Peers []PeerConfig
2020-02-27 23:19:48 +01:00
// IP network from which to allocate automatic sequential addresses
//Network net.IPNet
// TODO: use ParseCIDR to parse config
Network string `validate:"required,cidr"`
// domain to append to hostnames. Relies on separate DNS server for
// resolution. Informational only.
Domain string `validate:"required,gte=1,lte=255"`
2020-02-20 20:08:07 +01:00
}
type Dsnet struct {
Name string
Type DeviceType
PrivateKey Key
PublicKey Key
ListenPort int
Peers []Peer
}