-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
823cbf1
commit cb16047
Showing
12 changed files
with
84 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,66 @@ | ||
package net | ||
|
||
import ( | ||
"github.com/v2ray/v2ray-core/common/log" | ||
) | ||
type Destination interface { | ||
Network() string | ||
Address() Address | ||
String() string | ||
|
||
const ( | ||
NetTCP = byte(0x01) | ||
NetUDP = byte(0x02) | ||
) | ||
IsTCP() bool | ||
IsUDP() bool | ||
} | ||
|
||
func NewTCPDestination(address Address) Destination { | ||
return TCPDestination{address: address} | ||
} | ||
|
||
func NewUDPDestination(address Address) Destination { | ||
return UDPDestination{address: address} | ||
} | ||
|
||
type Destination struct { | ||
network byte | ||
type TCPDestination struct { | ||
address Address | ||
} | ||
|
||
func NewDestination(network byte, address Address) *Destination { | ||
return &Destination{ | ||
network: network, | ||
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 *Destination) Network() string { | ||
switch dest.network { | ||
case NetTCP: | ||
return "tcp" | ||
case NetUDP: | ||
return "udp" | ||
default: | ||
log.Warning("Unknown network %d", dest.network) | ||
return "tcp" | ||
} | ||
func (dest TCPDestination) IsTCP() bool { | ||
return true | ||
} | ||
|
||
func (dest *Destination) NetworkByte() byte { | ||
return dest.network | ||
func (dest TCPDestination) IsUDP() bool { | ||
return false | ||
} | ||
|
||
func (dest *Destination) Address() Address { | ||
type UDPDestination struct { | ||
address Address | ||
} | ||
|
||
func (dest UDPDestination) Network() string { | ||
return "udp" | ||
} | ||
|
||
func (dest UDPDestination) Address() Address { | ||
return dest.address | ||
} | ||
|
||
func (dest *Destination) String() string { | ||
return dest.address.String() + " (" + dest.Network() + ")" | ||
func (dest UDPDestination) String() string { | ||
return "udp:" + dest.address.String() | ||
} | ||
|
||
func (dest UDPDestination) IsTCP() bool { | ||
return false | ||
} | ||
|
||
func (dest UDPDestination) IsUDP() bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters