mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-03 00:22:05 +00:00
Add network type to destination to be ready for UDP connection
This commit is contained in:
1 parent
5d5102de4c
commit
b319704282
14 files changed
+94
-34
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
)
|
||||
|
||||
const (
|
||||
NetTCP = byte(0x01)
|
||||
NetUDP = byte(0x02)
|
||||
)
|
||||
|
||||
type Destination struct {
|
||||
network byte
|
||||
address Address
|
||||
}
|
||||
|
||||
func NewDestination(network byte, address Address) *Destination {
|
||||
return &Destination{
|
||||
network: network,
|
||||
address: address,
|
||||
}
|
||||
}
|
||||
|
||||
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 *Destination) NetworkByte() byte {
|
||||
return dest.network
|
||||
}
|
||||
|
||||
func (dest *Destination) Address() Address {
|
||||
return dest.address
|
||||
}
|
||||
|
||||
func (dest *Destination) String() string {
|
||||
return dest.address.String() + " (" + dest.Network() + ")"
|
||||
}
|
||||
Reference in new issue
Block a user