2020-05-22 10:41:24 +00:00
|
|
|
package telebit
|
2020-05-16 09:09:47 +00:00
|
|
|
|
2020-06-09 08:42:56 +00:00
|
|
|
import "fmt"
|
2020-05-16 09:09:47 +00:00
|
|
|
|
|
|
|
type Scheme string
|
|
|
|
|
|
|
|
const (
|
|
|
|
HTTPS = Scheme("https")
|
|
|
|
HTTP = Scheme("http")
|
|
|
|
SSH = Scheme("ssh")
|
|
|
|
OpenVPN = Scheme("openvpn")
|
|
|
|
)
|
|
|
|
|
|
|
|
type Termination string
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCP = Termination("none")
|
|
|
|
TLS = Termination("tls")
|
|
|
|
)
|
|
|
|
|
|
|
|
type Addr struct {
|
|
|
|
scheme Scheme
|
|
|
|
termination Termination
|
2020-05-18 08:43:06 +00:00
|
|
|
family string // TODO what should be the format? "tcpv6"?
|
2020-05-16 09:09:47 +00:00
|
|
|
addr string
|
|
|
|
port int
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAddr(s Scheme, t Termination, a string, p int) *Addr {
|
|
|
|
return &Addr{
|
|
|
|
scheme: s,
|
|
|
|
termination: t,
|
|
|
|
addr: a,
|
|
|
|
port: p,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Addr) String() string {
|
2020-06-09 08:42:56 +00:00
|
|
|
//return a.addr + ":" + strconv.Itoa(a.port)
|
|
|
|
return fmt.Sprintf("%s+%s:%s:%d", a.family, a.Scheme(), a.addr, a.port)
|
2020-05-16 09:09:47 +00:00
|
|
|
}
|
|
|
|
|
2020-06-09 08:42:56 +00:00
|
|
|
// Network s typically network "family", such as "tcp" or "ip",
|
|
|
|
// but in this case will be "tun", which is a cue to do a `switch`
|
|
|
|
// to actually use the specific features of a telebit.Addr
|
2020-05-16 09:09:47 +00:00
|
|
|
func (a *Addr) Network() string {
|
2020-06-09 08:42:56 +00:00
|
|
|
return "tun"
|
2020-05-16 09:09:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 07:49:08 +00:00
|
|
|
func (a *Addr) Port() int {
|
|
|
|
return a.port
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Addr) Hostname() string {
|
|
|
|
return a.addr
|
|
|
|
}
|
|
|
|
|
2020-05-16 09:09:47 +00:00
|
|
|
func (a *Addr) Scheme() Scheme {
|
|
|
|
return a.scheme
|
|
|
|
}
|