2020-03-03 23:08:52 +01:00
|
|
|
package dsnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-03-04 00:32:07 +01:00
|
|
|
type Status int
|
|
|
|
|
|
|
|
const (
|
2020-03-04 00:37:58 +01:00
|
|
|
// Host has not been loaded into wireguard yet
|
2020-03-04 00:32:07 +01:00
|
|
|
Pending = iota
|
2020-03-04 00:37:58 +01:00
|
|
|
// Host has not transferred anything (not even a keepalive) for 30 seconds
|
2020-03-04 00:32:07 +01:00
|
|
|
Offline
|
2020-03-04 00:37:58 +01:00
|
|
|
// Host has transferred something in the last 30 seconds, keepalive counts
|
2020-03-04 00:32:07 +01:00
|
|
|
Online
|
2020-03-04 00:37:58 +01:00
|
|
|
// Host has not connected for 28 days and may be removed
|
2020-03-04 00:32:07 +01:00
|
|
|
Expired
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s Status) String() string {
|
|
|
|
switch s {
|
2020-03-04 00:41:55 +01:00
|
|
|
case Pending:
|
|
|
|
return "pending"
|
|
|
|
case Offline:
|
|
|
|
return "offline"
|
|
|
|
case Online:
|
|
|
|
return "online"
|
|
|
|
case Expired:
|
|
|
|
return "expired"
|
|
|
|
default:
|
|
|
|
return "unknown"
|
2020-03-04 00:32:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// note unmarshal not required
|
|
|
|
func (s Status) MarshalJSON() ([]byte, error) {
|
|
|
|
return []byte("\"" + s.String() + "\""), nil
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:08:52 +01:00
|
|
|
type DsnetReport struct {
|
2020-03-03 22:06:36 +01:00
|
|
|
// domain to append to hostnames. Relies on separate DNS server for
|
|
|
|
// resolution. Informational only.
|
2020-03-04 00:09:54 +01:00
|
|
|
ExternalIP net.IP
|
|
|
|
ListenPort int
|
|
|
|
Domain string
|
2020-03-03 22:06:36 +01:00
|
|
|
// IP network from which to allocate automatic sequential addresses
|
|
|
|
// Network is chosen randomly when not specified
|
2020-03-04 00:09:54 +01:00
|
|
|
Network JSONIPNet
|
|
|
|
IP net.IP
|
|
|
|
DNS net.IP
|
2020-03-03 22:06:36 +01:00
|
|
|
Peers []PeerReport
|
2020-03-03 23:08:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PeerReport struct {
|
|
|
|
// Used to update DNS
|
2020-03-04 00:09:54 +01:00
|
|
|
Hostname string
|
2020-03-03 22:06:36 +01:00
|
|
|
// username of person running this host/router
|
2020-03-04 00:09:54 +01:00
|
|
|
Owner string
|
2020-03-03 23:08:52 +01:00
|
|
|
// Description of what the host is and/or does
|
2020-03-04 00:09:54 +01:00
|
|
|
Description string
|
2020-03-03 22:06:36 +01:00
|
|
|
// Internal VPN IP address. Added to AllowedIPs in server config as a /32
|
2020-03-04 20:38:48 +01:00
|
|
|
IP net.IP
|
2020-03-04 00:43:55 +01:00
|
|
|
Status Status
|
2020-03-03 22:06:36 +01:00
|
|
|
// TODO ExternalIP support (Endpoint)
|
|
|
|
//ExternalIP net.UDPAddr `validate:"required,udp4_addr"`
|
|
|
|
// TODO support routing additional networks (AllowedIPs)
|
2020-03-04 00:09:54 +01:00
|
|
|
Networks []JSONIPNet
|
2020-03-03 23:08:52 +01:00
|
|
|
LastHandshakeTime time.Time
|
|
|
|
ReceiveBytes int64
|
|
|
|
TransmitBytes int64
|
|
|
|
}
|