destination.go 764 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package net
  2. import (
  3. "github.com/v2ray/v2ray-core/common/log"
  4. )
  5. const (
  6. NetTCP = byte(0x01)
  7. NetUDP = byte(0x02)
  8. )
  9. type Destination struct {
  10. network byte
  11. address Address
  12. }
  13. func NewDestination(network byte, address Address) *Destination {
  14. return &Destination{
  15. network: network,
  16. address: address,
  17. }
  18. }
  19. func (dest *Destination) Network() string {
  20. switch dest.network {
  21. case NetTCP:
  22. return "tcp"
  23. case NetUDP:
  24. return "udp"
  25. default:
  26. log.Warning("Unknown network %d", dest.network)
  27. return "tcp"
  28. }
  29. }
  30. func (dest *Destination) NetworkByte() byte {
  31. return dest.network
  32. }
  33. func (dest *Destination) Address() Address {
  34. return dest.address
  35. }
  36. func (dest *Destination) String() string {
  37. return dest.address.String() + " (" + dest.Network() + ")"
  38. }