2021-08-19 14:09:41 +00:00
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Connection struct {
|
|
|
|
|
// Type is the connection type and can be "openvpn"
|
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
// IP is the VPN server IP address.
|
|
|
|
|
IP net.IP `json:"ip"`
|
|
|
|
|
// Port is the VPN server port.
|
|
|
|
|
Port uint16 `json:"port"`
|
|
|
|
|
// Protocol can be "tcp" or "udp".
|
|
|
|
|
Protocol string `json:"protocol"`
|
|
|
|
|
// Hostname is used for IPVanish, IVPN, Privado
|
|
|
|
|
// and Windscribe for TLS verification
|
|
|
|
|
Hostname string `json:"hostname"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *Connection) Equal(other Connection) bool {
|
|
|
|
|
return c.IP.Equal(other.IP) && c.Port == other.Port &&
|
|
|
|
|
c.Protocol == other.Protocol && c.Hostname == other.Hostname
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c Connection) OpenVPNRemoteLine() (line string) {
|
|
|
|
|
return "remote " + c.IP.String() + " " + fmt.Sprint(c.Port)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c Connection) OpenVPNProtoLine() (line string) {
|
|
|
|
|
return "proto " + c.Protocol
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateEmptyWith updates each field of the connection where the
|
2021-08-19 23:22:55 +00:00
|
|
|
// value is not set using the value given as arguments.
|
|
|
|
|
func (c *Connection) UpdateEmptyWith(ip net.IP, port uint16, protocol string) {
|
2021-08-19 14:09:41 +00:00
|
|
|
if c.IP == nil {
|
2021-08-19 23:22:55 +00:00
|
|
|
c.IP = ip
|
2021-08-19 14:09:41 +00:00
|
|
|
}
|
|
|
|
|
if c.Port == 0 {
|
2021-08-19 23:22:55 +00:00
|
|
|
c.Port = port
|
2021-08-19 14:09:41 +00:00
|
|
|
}
|
|
|
|
|
if c.Protocol == "" {
|
2021-08-19 23:22:55 +00:00
|
|
|
c.Protocol = protocol
|
2021-08-19 14:09:41 +00:00
|
|
|
}
|
|
|
|
|
}
|