1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 18:06:15 -05:00
v2fly/common/net/destination.go

70 lines
1.5 KiB
Go
Raw Normal View History

package net
2015-09-21 06:15:25 -04:00
// Destination represents a network destination including address and protocol (tcp / udp).
2015-09-20 12:22:29 -04:00
type Destination interface {
2015-09-21 06:15:25 -04:00
Network() string // Protocol of communication (tcp / udp)
Address() Address // Address of destination
String() string // String representation of the destination
2015-09-21 06:15:25 -04:00
IsTCP() bool // True if destination is reachable via TCP
IsUDP() bool // True if destination is reachable via UDP
2015-09-20 12:22:29 -04:00
}
2015-09-21 06:15:25 -04:00
// NewTCPDestination creates a TCP destination with given address
2015-09-20 12:22:29 -04:00
func NewTCPDestination(address Address) Destination {
return TCPDestination{address: address}
}
2015-09-21 06:15:25 -04:00
// NewUDPDestination creates a UDP destination with given address
2015-09-20 12:22:29 -04:00
func NewUDPDestination(address Address) Destination {
return UDPDestination{address: address}
}
2015-09-20 12:22:29 -04:00
type TCPDestination struct {
address Address
}
2015-09-20 12:22:29 -04:00
func (dest TCPDestination) Network() string {
return "tcp"
}
func (dest TCPDestination) Address() Address {
return dest.address
}
func (dest TCPDestination) String() string {
return "tcp:" + dest.address.String()
}
2015-09-20 12:22:29 -04:00
func (dest TCPDestination) IsTCP() bool {
return true
}
2015-09-20 12:22:29 -04:00
func (dest TCPDestination) IsUDP() bool {
return false
}
2015-09-20 12:22:29 -04:00
type UDPDestination struct {
address Address
}
func (dest UDPDestination) Network() string {
return "udp"
}
func (dest UDPDestination) Address() Address {
return dest.address
}
2015-09-20 12:22:29 -04:00
func (dest UDPDestination) String() string {
return "udp:" + dest.address.String()
}
func (dest UDPDestination) IsTCP() bool {
return false
}
func (dest UDPDestination) IsUDP() bool {
return true
}