forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
destination.go
69 lines (53 loc) · 1.49 KB
/
destination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package net
// Destination represents a network destination including address and protocol (tcp / udp).
type Destination interface {
Network() string // Protocol of communication (tcp / udp)
Address() Address // Address of destination
String() string // String representation of the destination
IsTCP() bool // True if destination is reachable via TCP
IsUDP() bool // True if destination is reachable via UDP
}
// NewTCPDestination creates a TCP destination with given address
func NewTCPDestination(address Address) Destination {
return TCPDestination{address: address}
}
// NewUDPDestination creates a UDP destination with given address
func NewUDPDestination(address Address) Destination {
return UDPDestination{address: address}
}
type TCPDestination struct {
address Address
}
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()
}
func (dest TCPDestination) IsTCP() bool {
return true
}
func (dest TCPDestination) IsUDP() bool {
return false
}
type UDPDestination struct {
address Address
}
func (dest UDPDestination) Network() string {
return "udp"
}
func (dest UDPDestination) Address() Address {
return dest.address
}
func (dest UDPDestination) String() string {
return "udp:" + dest.address.String()
}
func (dest UDPDestination) IsTCP() bool {
return false
}
func (dest UDPDestination) IsUDP() bool {
return true
}